Skip to content

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

Closed

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.

Activity

  1. 0xDevNinja commented on May 13, 2026

    @0xDevNinja
    Contributor

    Taking this. Plan: honor gh config get git_protocol (and glab config get git_protocol for the gitlab branch) when deriving the push URL in gstack-artifacts-init — defaulting to HTTPS when the user's CLI is configured for HTTPS, SSH otherwise. Add a --push-protocol https|ssh|auto override flag for explicit pinning. (Script was renamed bin/gstack-brain-init → bin/gstack-artifacts-init in v1.27.0.0; bug still lives at line 184.) PR shortly.

  2. hexorcist404 commented on Jul 3, 2026

    @hexorcist404

    Still present in 1.58.5.0, and it's gotten stricter than described here: the original recovery path in this issue (--remote https://...) no longer works. gstack-artifacts-init (the renamed script) now canonicalizes any input URL and unconditionally re-derives the SSH form before verifying:

    # bin/gstack-artifacts-init:184 @ 1.58.5.0
    PUSH_URL=$("$URL_BIN" --to ssh "$CANONICAL_HTTPS" 2>/dev/null || echo "$CANONICAL_HTTPS")
    # :188 — hard exit 1 when git ls-remote over SSH fails

    So on an HTTPS-only machine (gh git_protocol = https, no SSH key on the account — my case, Windows 11 + Git Credential Manager) there is no CLI escape hatch at all: even an explicit HTTPS --remote gets converted to git@github.com:... and the script exits at the ls-remote gate.

    Data point supporting the protocol-honoring fix @0xDevNinja described: I patched PUSH_URL="$CANONICAL_HTTPS" locally and everything downstream works over HTTPS — init, initial push, and ongoing gstack-brain-sync (which just runs git push origin HEAD against whatever origin is configured, so it's protocol-agnostic by construction). A --push-protocol override flag would also have unblocked this without the local patch.

  3. added a commit that references this issue on Jul 14, 2026
    c1866d8
  4. time-attack commented on Jul 15, 2026

    @time-attack
    Contributor

    @16francej — recommend closing this issue only after #2225 lands following its remaining composition check. The issue is handled there because the current setup rewrites explicitly configured HTTPS remotes to SSH. Please retain the explicit-HTTPS reproducer and its attribution in #2225.

  5. added 2 commits that reference this issue on Jul 16, 2026
    78aaa20
    c454e2a
  6. added a commit that references this issue on Aug 15, 2026
    008dd65
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions