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 <jackerran@gmail.com> Tested-by: Thomas Rast <tr@thomasrast.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Tom Miller committed Jan 2, 2014 at 20:28 UTC 10a6cc8890ec1e5459c05ddeb28a671acdc37d60
2 files changed +19 -5
builtin/fetch.c
+5 -5
@@ -863,11 +863,6 @@ static int do_fetch(struct transport *transport,
863
864 if (tags == TAGS_DEFAULT && autotags)
865 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 - }
866 if (prune) {
867 /*
868 * We only prune based on refspecs specified
@@ -883,6 +878,11 @@ static int do_fetch(struct transport *transport,
878 transport->url);
879 }
880 }
881 + if (fetch_refs(transport, ref_map)) {
882 + free_refs(ref_map);
883 + retcode = 1;
884 + goto cleanup;
885 + }
886 free_refs(ref_map);
887
888 /* if neither --no-tags nor --tags was specified, do automated tag
t/t5510-fetch.sh
+14
@@ -626,4 +626,18 @@ test_expect_success 'fetch --prune prints the remotes url' '
626 test_cmp expect actual
627 '
628
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 +
643 test_done