By default, the [git remote show
]https://github.com/git/git/blob/33f448b5fc916e6be266b857617a3b27a467da81/Documentation/git-remote.txt#L168-L187)(man) command will query data from remotes to show data about what might be done on a future git fetch
.
This process currently does not handle negative refspecs.
This can be confusing, because the show
command will list refs as if they would be fetched.
For example if the fetch refspec "^refs/heads/pr/*
", it still displays the following:
* remote jdk19
Fetch URL: git@github.com:openjdk/jdk19.git
Push URL: git@github.com:openjdk/jdk19.git
HEAD branch: master
Remote branches:
master tracked
pr/1 new (next fetch will store in remotes/jdk19)
pr/2 new (next fetch will store in remotes/jdk19)
pr/3 new (next fetch will store in remotes/jdk19)
Local ref configured for 'git push':
master pushes to master (fast-forwardable)
Fix this by adding an additional check inside of get_ref_states
.
If a ref matches one of the negative refspecs, mark it as skipped instead of marking it as new or tracked.
With this change, we now report remote branches that are skipped due to negative refspecs properly:
* remote jdk19
Fetch URL: git@github.com:openjdk/jdk19.git
Push URL: git@github.com:openjdk/jdk19.git
HEAD branch: master
Remote branches:
master tracked
pr/1 skipped <=====
pr/2 skipped <=====
pr/3 skipped <=====
Local ref configured for 'git push':
master pushes to master (fast-forwardable)
By showing the refs as skipped
, it helps clarify that these references won't actually be fetched.
This does not properly handle refs going stale due to a newly added negative refspec.
In addition, 'git remote
' prune doesnt handle that negative refspec case either.
Fixing that requires digging into get_stale_heads
and handling the case of a ref which exists on the remote but is omitted due to a negative refspec locally.
git config --add remote.origin.fetch '^refs/heads/dependabot/*'
。 - Yasushi Shoji.git/config
的[remote "origin"]
部分添加了fetch = ^refs/heads/boring-branch
。 - vladis