Skip to content

Commit b40a502

Browse files
derrickstoleegitster
authored andcommitted
fetch: document and test --refmap=""
To prevent long blocking time during a 'git fetch' call, a user may want to set up a schedule for background 'git fetch' processes. However, these runs will update the refs/remotes branches due to the default refspec set in the config when Git adds a remote. Hence the user will not notice when remote refs are updated during their foreground fetches. In fact, they may _want_ those refs to stay put so they can work with the refs from their last foreground fetch call. This can be accomplished by overriding the configured refspec using '--refmap=' along with a custom refspec: git fetch --refmap='' <remote> +refs/heads/*:refs/hidden/<remote>/* to populate a custom ref space and download a pack of the new reachable objects. This kind of call allows a few things to happen: 1. We download a new pack if refs have updated. 2. Since the refs/hidden branches exist, GC will not remove the newly-downloaded data. 3. With fetch.writeCommitGraph enabled, the refs/hidden refs are used to update the commit-graph file. To avoid the refs/hidden directory from filling without bound, the --prune option can be included. When providing a refspec like this, the --prune option does not delete remote refs and instead only deletes refs in the target refspace. Update the documentation to clarify how '--refmap=""' works and create tests to guarantee this behavior remains in the future. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent b6d4d82 commit b40a502

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

Documentation/fetch-options.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,10 @@ ifndef::git-pull[]
135135
specified refspec (can be given more than once) to map the
136136
refs to remote-tracking branches, instead of the values of
137137
`remote.*.fetch` configuration variables for the remote
138-
repository. See section on "Configured Remote-tracking
138+
repository. Providing an empty `<refspec>` to the
139+
`--refmap` option causes Git to ignore the configured
140+
refspecs and rely entirely on the refspecs supplied as
141+
command-line arguments. See section on "Configured Remote-tracking
139142
Branches" for details.
140143

141144
-t::

t/t5510-fetch.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,30 @@ test_expect_success 'fetch --prune --tags with refspec prunes based on refspec'
174174
git rev-parse sometag
175175
'
176176

177+
test_expect_success '--refmap="" ignores configured refspec' '
178+
cd "$TRASH_DIRECTORY" &&
179+
git clone "$D" remote-refs &&
180+
git -C remote-refs rev-parse remotes/origin/master >old &&
181+
git -C remote-refs update-ref refs/remotes/origin/master master~1 &&
182+
git -C remote-refs rev-parse remotes/origin/master >new &&
183+
git -C remote-refs fetch --refmap= origin "+refs/heads/*:refs/hidden/origin/*" &&
184+
git -C remote-refs rev-parse remotes/origin/master >actual &&
185+
test_cmp new actual &&
186+
git -C remote-refs fetch origin &&
187+
git -C remote-refs rev-parse remotes/origin/master >actual &&
188+
test_cmp old actual
189+
'
190+
191+
test_expect_success '--refmap="" and --prune' '
192+
git -C remote-refs update-ref refs/remotes/origin/foo/otherbranch master &&
193+
git -C remote-refs update-ref refs/hidden/foo/otherbranch master &&
194+
git -C remote-refs fetch --prune --refmap="" origin +refs/heads/*:refs/hidden/* &&
195+
git -C remote-refs rev-parse remotes/origin/foo/otherbranch &&
196+
test_must_fail git -C remote-refs rev-parse refs/hidden/foo/otherbranch &&
197+
git -C remote-refs fetch --prune origin &&
198+
test_must_fail git -C remote-refs rev-parse remotes/origin/foo/otherbranch
199+
'
200+
177201
test_expect_success 'fetch tags when there is no tags' '
178202
179203
cd "$D" &&

0 commit comments

Comments
 (0)