Skip to content

gstack-brain-init defaults to SSH remote, fails for HTTPS-configured gh #1348

@simonkhc

Description

@simonkhc

Environment

  • gstack 1.26.4.0
  • gh configured with git_protocol = https (the gh auth login default)
$ gh config get git_protocol
https
$ gh auth status | grep -i protocol
  - Git operations protocol: https

Reproducer

gstack-brain-init with default settings (let gh repo create make the repo) followed by the first push fails for users whose gh auth is HTTPS-only — the script asks gh for sshUrl regardless of the user's git_protocol setting, so the remote ends up as git@github.com:user/gstack-brain-user.git and git push then prompts for SSH credentials the user does not have.

User has to manually re-run with --remote https://github.com/user/gstack-brain-user.git to recover.

Expected

gstack-brain-init honors gh config get git_protocol. If it returns https, register the HTTPS clone URL; if ssh, register the SSH URL.

Actual

bin/gstack-brain-init:91 and :98 hardcode sshUrl:

# line 89-99
if ! gh repo create "\$DEFAULT_NAME" --private --description "gstack session memory" 2>/dev/null; then
  # Maybe the repo already exists; try to fetch its URL.
  REMOTE_URL=\$(gh repo view "\$DEFAULT_NAME" --json sshUrl -q .sshUrl 2>/dev/null || echo "")
  ...
else
  REMOTE_URL=\$(gh repo view "\$DEFAULT_NAME" --json sshUrl -q .sshUrl 2>/dev/null || echo "")
fi

Both branches request sshUrl unconditionally.

Suggested fix

Pick the URL field based on gh config get git_protocol:

PROTOCOL=\$(gh config get git_protocol 2>/dev/null || echo "https")
if [ "\$PROTOCOL" = "ssh" ]; then
  URL_FIELD=sshUrl
else
  URL_FIELD=url   # HTTPS clone URL
fi
REMOTE_URL=\$(gh repo view "\$DEFAULT_NAME" --json "\$URL_FIELD" -q ".\$URL_FIELD" 2>/dev/null || echo "")

Defaulting to HTTPS when git_protocol is unset matches gh auth login's own default.

The interactive prompt at bin/gstack-brain-init:105 ("Paste a private git URL (e.g. git@github.com:you/gstack-brain.git)") could similarly show the user's preferred protocol in the example, but the auto-create path is where the silent failure happens.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions