Repository navigation
gh pr checkout defies negative refspec in remote.*.<name> #10254
Copy link
Copy link
Closed
Labels
enhancementa request to improve CLIa request to improve CLIgh-prrelating to the gh pr commandrelating to the gh pr commandhelp wantedContributions welcomeContributions welcome
Description
Describe the bug
We have some release Actions that push artefacts to v123-deploy when v123 tag is created. I never need the *-deploy tags, so to avoid fetching them, in my .git/config:
[remote "origin"]
url = [email protected]:org/repo.git
fetch = +refs/heads/*:refs/remotes/origin/*
fetch = ^refs/heads/*-deploy
fetch = ^refs/tags/*-deployHowever if I do a gh pr checkout 123456, it'll fetch all those *-deploy tags.
$ gh --version
gh version 2.65.0-11-g0006091d7 (2025-01-07)
https://github.com/cli/cli/releases/latestSteps to reproduce the behavior
- Set up negative fetch refspecs (doc: https://git-scm.com/docs/git-fetch#Documentation/git-fetch.txt-ltrefspecgt)
- Run
gh pr checkout 123456 - It'll start fetching all the ignored tags
Expected vs actual behavior
gh respects my remote.*.<name> configs.
Logs
Paste the activity from your command line. Redact if needed.
$ GH_DEBUG=true gh pr checkout 123456
[git remote -v]
[git config --get-regexp ^remote\..*\.gh-resolved$]
* Request at 2025-01-16 15:24:11.714671 +1100 AEDT m=+0.135416674
* Request to https://api.github.com/graphql
* Request took 611.486474ms
⣾* Request at 2025-01-16 15:24:12.327912 +1100 AEDT m=+0.748639651
* Request to https://api.github.com/graphql
⢿* Request took 382.392664ms
[git remote -v]
[git config --get-regexp ^remote\..*\.gh-resolved$]
[git show-ref --verify -- refs/heads/feat-branch]
[git -c credential.helper= -c credential.helper=!"/usr/local/bin/gh" auth git-credential fetch origin +refs/heads/feat-branch:refs/remotes/origin/feat-branch]
From github.com:org/repo
* [new tag] v782-deploy -> v782-deploy
* [new tag] v783-deploy -> v783-deploy
* [new tag] v784-deploy -> v784-deploy
* [new tag] v785-deploy -> v785-deploy
* [new tag] v786-deploy -> v786-deploy
* [new tag] v787-deploy -> v787-deploy
* [new tag] v788-deploy -> v788-deploy
* [new tag] v789-deploy -> v789-deploy
* [new tag] v790-deploy -> v790-deploy
* [new tag] v791-deploy -> v791-deploy
[git checkout -b feat-branch --track origin/feat-branch]
branch 'feat-branch' set up to track 'origin/feat-branch'.
Switched to a new branch 'feat-branch'
# delete all *-deploy tags
$ git tag -l | rg -- '-deploy$' | xargs -I{} -- git tag -d {}
# the command I use to fetch
# perhaps we just need to add --tags into gh too?
$ git fetch --all --prune --tags --jobs=10Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementa request to improve CLIa request to improve CLIgh-prrelating to the gh pr commandrelating to the gh pr commandhelp wantedContributions welcomeContributions welcome
Activity
BagToad commentedon Jan 17, 2025
👋 Hey @Frederick888, thanks for this issue ✨
I started digging into this, and what may be happening is that when you provide a command line refspec to
git fetchthe refspec(s) in your Git config are ignored:Since we need to provide a refspec on the command line to checkout the PR, I am not sure what options are available to us in
gh. Perhaps getting the config and appending it to the command line refspec?I saw that you could configure the default tag fetch policy, which may help preventing tags from being fetched generally - though I recognize that's not exactly what you're looking for:
💭 All this in mind, I think this is intended behavior.
Please let me know if I understood correctly and if you have any other ideas or feedback 😁❤
Frederick888 commentedon Jan 20, 2025
@BagToad Git's behaviour is a bit confusing. With my config, somehow
So I think when a PR is from an existing remote in
.git/config, we can add--tags+ process the output ofgit config --get-all remote.origin.fetchto append the additional negative refspecs.williammartin commentedon Jan 23, 2025
@Frederick888,
I can't think of a reason we would need tags for
pr checkoutsince PRs are based entirely around branches.Can you think of a reason we shouldn't just provide
--no-tagsto thegit fetchcommand here?Frederick888 commentedon Jan 23, 2025
@williammartin Yup that works for me too!
I wasn't sure about how the code was structured and whether the
git fetchcommand was reused in any way. But in terms ofgh pr checkout,--no-tagssounds good to me 👍BagToad commentedon Feb 5, 2025
Acceptance Criteria
Given I have a repository with Git tags
When I run
gh pr checkoutThen the branch is fetched with
--no-tags