You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
gh secret subcommands don't work anymore if called outside of Git repository #10525
After upgrading to GitHub CLI 2.67.0 all gh secret set commands that are run outside of git repository fails with this message:
failed to run git: fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
Actions like this are now failing if they are run without using actions/checkout.
Run GH_REPO=AnimMouse/test-repo gh secret set test_secret
See error:
failed to run git: fatal: not a git repository (or any parent up to mount point /)
Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).
Expected vs actual behavior
Earlier version of gh secret worked without checking out the repository.
GH_REPO=AnimMouse/test-repo gh secret set test_secret
? Paste your secret:
Other commands such as gh variable list, gh pr list, gh issue list, and gh release list are working fine with GH_REPO in a non-git directory.
The only affected command seems to be gh secret.
# ./gh is a symlink here
$ ./gh --version
gh version 2.66.1-227-g817eeb26 (2025-03-02)
https://github.com/cli/cli/releases/latest
$ ./gh secret list
failed to run git: fatal: not a git repository (or any of the parent directories): .git
$ GH_REPO=iamazeem/test ./gh secret set S1 --body "123"
✓ Set Actions secret S1 for iamazeem/test
$ GH_REPO=iamazeem/test ./gh secret delete S1
✓ Deleted Actions secret S1 from iamazeem/test
@iamazeem's (thanks) implementation is functionally correct, but I'd really like it if there were an approach that was little less coupled. I'll think about it, but we're going to release today or tomorrow so if I don't have a solution before then, I'll accept the current approach to ensure this is fixed asap.
Given my cwd is not a git repo And I have GH_REPO set to a repo I have permissions on When I run any of the gh secret commands Then I am able to interact with secrets on that repo
Activity
iamazeem commentedon Mar 2, 2025
Verified. 👍
GH_REPOis working fine up to v2.65.0 forgh secret.The
--repoflag is working fine.It may be used as an alternative (or a workaround):
gh secret set test_secret --repo AnimMouse/test-repo ghAnd, in https://github.com/AnimMouse/setup-rclone/blob/main/update-config/action.yaml:
- name: Update Rclone config for Unix-like if: runner.os == 'Linux' || runner.os == 'macOS' shell: bash - run: base64 < ~/.config/rclone/rclone.conf | gh secret set "$rclone_config_secret_name" + run: base64 < ~/.config/rclone/rclone.conf | gh secret set "$rclone_config_secret_name" --repo '${{ github.repository }}' env: rclone_config_secret_name: ${{ inputs.rclone_config_secret_name }} GITHUB_TOKEN: ${{ inputs.token }} - GH_REPO: ${{ github.repository }}Other commands such as
gh variable list,gh pr list,gh issue list, andgh release listare working fine withGH_REPOin a non-git directory.The only affected command seems to be
gh secret.iamazeem commentedon Mar 2, 2025
Related to #10209:
cli/pkg/cmd/secret/set/set.go
Lines 107 to 118 in 817eeb2
cli/pkg/cmd/secret/list/list.go
Lines 70 to 82 in 817eeb2
cli/pkg/cmd/secret/delete/delete.go
Lines 49 to 61 in 817eeb2
Checking for
GH_REPOin addition to--repoflag works fine (need to importospackage):Here's the branch with this fix: https://github.com/iamazeem/cli/tree/10525-gh-secret-gh-repo-env-var
Local test runs:
williammartin commentedon Mar 3, 2025
🤮 Sorry for the regression @AnimMouse
I introduced this in #10209. This behaviour is shared across all
secretcommands.The fundamental issue here is that the logic we use to inject the
--repoflag to various commands is also aware ofGH_REPObut the checkcmd.Flags().Changed("repo")is not.@iamazeem's (thanks) implementation is functionally correct, but I'd really like it if there were an approach that was little less coupled. I'll think about it, but we're going to release today or tomorrow so if I don't have a solution before then, I'll accept the current approach to ensure this is fixed asap.
andyfeller commentedon Mar 3, 2025
Where is
clicode already coupled withGH_REPO?Agree with @williammartin. For perspective, here are the other places in GitHub CLI code that looks at
GH_REPOenvironment variable.I feel like we should be able to do something for
cmd-level logic to make this cleaner. 🤔Source:
org:cli "GH_REPO" -path:**/*_test.go language:Gocli/pkg/cmd/browse/browse.go
Lines 145 to 148 in 817eeb2
cli/pkg/cmd/pr/create/create.go
Lines 150 to 155 in 817eeb2
cli/pkg/cmdutil/repo_override.go
Lines 60 to 70 in 817eeb2
cli/pkg/cmd/api/api.go
Lines 563 to 574 in 817eeb2
https://github.com/cli/go-gh/blob/13104ed7b2db4b8c1a83de4248ddfaaab7682916/pkg/repository/repository.go#L117-L125
williammartin commentedon Mar 4, 2025
Acceptance Criteria
Given my cwd is not a git repo
And I have
GH_REPOset to a repo I have permissions onWhen I run any of the
gh secretcommandsThen I am able to interact with secrets on that repo
AnimMouse commentedon Mar 6, 2025
Thank you @iamazeem, @williammartin, and @andyfeller for the speedy bug fix!
Fork repository CI does not fail when exiting early. (#19307)