Skip to content

Commit

Permalink
builtin-remote: prune remotes correctly that were added with --mirror
Browse files Browse the repository at this point in the history
This adds special handling for mirror remotes.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Johannes Schindelin authored and Junio C Hamano committed Mar 1, 2008
1 parent 211c896 commit 4ebc914
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
16 changes: 13 additions & 3 deletions builtin-remote.c
Original file line number Diff line number Diff line change
Expand Up @@ -396,12 +396,22 @@ static int show_or_prune(int argc, const char **argv, int prune)

if (prune) {
struct strbuf buf;
int prefix_len;

strbuf_init(&buf, 0);
if (states.remote->fetch_refspec_nr == 1 &&
states.remote->fetch->pattern &&
!strcmp(states.remote->fetch->src,
states.remote->fetch->dst))
/* handle --mirror remote */
strbuf_addstr(&buf, "refs/heads/");
else
strbuf_addf(&buf, "refs/remotes/%s/", *argv);
prefix_len = buf.len;

for (i = 0; i < states.stale.nr; i++) {
strbuf_reset(&buf);
strbuf_addf(&buf, "refs/remotes/%s/%s", *argv,
states.stale.items[i].path);
strbuf_setlen(&buf, prefix_len);
strbuf_addstr(&buf, states.stale.items[i].path);
result |= delete_ref(buf.buf, NULL);
}

Expand Down
16 changes: 16 additions & 0 deletions t/t5505-remote.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,20 @@ test_expect_success 'prune' '
! git rev-parse refs/remotes/origin/side)
'

test_expect_success 'add --mirror && prune' '
(mkdir mirror &&
cd mirror &&
git init &&
git remote add --mirror -f origin ../one) &&
(cd one &&
git branch -m side2 side) &&
(cd mirror &&
git rev-parse --verify refs/heads/side2 &&
! git rev-parse --verify refs/heads/side &&
git fetch origin &&
git remote prune origin &&
! git rev-parse --verify refs/heads/side2 &&
git rev-parse --verify refs/heads/side)
'

test_done

0 comments on commit 4ebc914

Please sign in to comment.