Skip to content

Commit c175a7a

Browse files
spearcegitster
authored andcommitted
Make "git-remote prune" delete refs according to fetch specs
A remote may be configured to fetch into tracking branches that do not match the remote name. For example a user may have created extra remotes that will fetch to the same tracking branch namespace, but from different URLs: [remote "origin"] url = git://git.kernel.org/pub/scm/git/git.git fetch = refs/heads/*:refs/remotes/origin/* [remote "alt"] url = git://repo.or.cz/alt-git.git fetch = refs/heads/*:refs/remotes/origin/* When running `git remote prune alt` we expect stale branches to be removed from "refs/remotes/origin/*" and not from the unused namespace of "refs/remotes/alt/*". Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 6a15bc0 commit c175a7a

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

builtin-remote.c

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -419,27 +419,10 @@ static int show_or_prune(int argc, const char **argv, int prune)
419419
states.remote->name);
420420

421421
if (prune) {
422-
struct strbuf buf;
423-
int prefix_len;
424-
425-
strbuf_init(&buf, 0);
426-
if (states.remote->fetch_refspec_nr == 1 &&
427-
states.remote->fetch->pattern &&
428-
!strcmp(states.remote->fetch->src,
429-
states.remote->fetch->dst))
430-
/* handle --mirror remote */
431-
strbuf_addstr(&buf, "refs/heads/");
432-
else
433-
strbuf_addf(&buf, "refs/remotes/%s/", *argv);
434-
prefix_len = buf.len;
435-
436422
for (i = 0; i < states.stale.nr; i++) {
437-
strbuf_setlen(&buf, prefix_len);
438-
strbuf_addstr(&buf, states.stale.items[i].path);
439-
result |= delete_ref(buf.buf, NULL);
423+
const char *refname = states.stale.items[i].util;
424+
result |= delete_ref(refname, NULL);
440425
}
441-
442-
strbuf_release(&buf);
443426
goto cleanup_states;
444427
}
445428

t/t5505-remote.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,24 @@ test_expect_success 'add --mirror && prune' '
164164
git rev-parse --verify refs/heads/side)
165165
'
166166

167+
test_expect_success 'add alt && prune' '
168+
(mkdir alttst &&
169+
cd alttst &&
170+
git init &&
171+
git remote add -f origin ../one &&
172+
git config remote.alt.url ../one &&
173+
git config remote.alt.fetch "+refs/heads/*:refs/remotes/origin/*") &&
174+
(cd one &&
175+
git branch -m side side2) &&
176+
(cd alttst &&
177+
git rev-parse --verify refs/remotes/origin/side &&
178+
! git rev-parse --verify refs/remotes/origin/side2 &&
179+
git fetch alt &&
180+
git remote prune alt &&
181+
! git rev-parse --verify refs/remotes/origin/side &&
182+
git rev-parse --verify refs/remotes/origin/side2)
183+
'
184+
167185
cat > one/expect << EOF
168186
apis/master
169187
apis/side

0 commit comments

Comments
 (0)