Skip to content
This repository was archived by the owner on Jul 2, 2019. It is now read-only.

Commit 10a6cc8

Browse files
Tom Millergitster
Tom Miller
authored andcommitted
fetch --prune: Run prune before fetching
When we have a remote-tracking branch named "frotz/nitfol" from a previous fetch, and the upstream now has a branch named "frotz", fetch would fail to remove "frotz/nitfol" with a "git fetch --prune" from the upstream. git would inform the user to use "git remote prune" to fix the problem. Change the way "fetch --prune" works by moving the pruning operation before the fetching operation. This way, instead of warning the user of a conflict, it autmatically fixes it. Signed-off-by: Tom Miller <[email protected]> Tested-by: Thomas Rast <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4b3b33a commit 10a6cc8

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

builtin/fetch.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -863,11 +863,6 @@ static int do_fetch(struct transport *transport,
863863

864864
if (tags == TAGS_DEFAULT && autotags)
865865
transport_set_option(transport, TRANS_OPT_FOLLOWTAGS, "1");
866-
if (fetch_refs(transport, ref_map)) {
867-
free_refs(ref_map);
868-
retcode = 1;
869-
goto cleanup;
870-
}
871866
if (prune) {
872867
/*
873868
* We only prune based on refspecs specified
@@ -883,6 +878,11 @@ static int do_fetch(struct transport *transport,
883878
transport->url);
884879
}
885880
}
881+
if (fetch_refs(transport, ref_map)) {
882+
free_refs(ref_map);
883+
retcode = 1;
884+
goto cleanup;
885+
}
886886
free_refs(ref_map);
887887

888888
/* if neither --no-tags nor --tags was specified, do automated tag

t/t5510-fetch.sh

+14
Original file line numberDiff line numberDiff line change
@@ -626,4 +626,18 @@ test_expect_success 'fetch --prune prints the remotes url' '
626626
test_cmp expect actual
627627
'
628628

629+
test_expect_success 'branchname D/F conflict resolved by --prune' '
630+
git branch dir/file &&
631+
git clone . prune-df-conflict &&
632+
git branch -D dir/file &&
633+
git branch dir &&
634+
(
635+
cd prune-df-conflict &&
636+
git fetch --prune &&
637+
git rev-parse origin/dir >../actual
638+
) &&
639+
git rev-parse dir >expect &&
640+
test_cmp expect actual
641+
'
642+
629643
test_done

0 commit comments

Comments
 (0)