fetch: treat --tags like refs/tags/*:refs/tags/* when pruning
If --tags is specified, add that refspec to the list given to prune_refs so it knows to treat it as a filter on what refs to should consider for prunning. This way git fetch --prune --tags origin only prunes tags and doesn't delete the branch refs. Signed-off-by: Carlos Martín Nieto <cmn@elego.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Carlos Martín Nieto committed
Oct 15, 2011 at 07:04 UTC
e8c1e6c796c1b96b6b208bbd4bc8cfd9acb481b5
2 files changed
+23
-4
builtin/fetch.c
+21
-2
@@ -735,10 +735,29 @@ static int do_fetch(struct transport *transport,
735
return 1;
736
}
737
if (prune) {
738
- if (ref_count)
738
+ /* If --tags was specified, pretend the user gave us the canonical tags refspec */
739
+ if (tags == TAGS_SET) {
740
+ const char *tags_str = "refs/tags/*:refs/tags/*";
741
+ struct refspec *tags_refspec, *refspec;
742
+
743
+ /* Copy the refspec and add the tags to it */
744
+ refspec = xcalloc(ref_count + 1, sizeof(struct refspec));
745
+ tags_refspec = parse_fetch_refspec(1, &tags_str);
746
+ memcpy(refspec, refs, ref_count * sizeof(struct refspec));
747
+ memcpy(&refspec[ref_count], tags_refspec, sizeof(struct refspec));
748
+ ref_count++;
749
+
750
+ prune_refs(refspec, ref_count, ref_map);
751
+
752
+ ref_count--;
753
+ /* The rest of the strings belong to fetch_one */
754
+ free_refspec(1, tags_refspec);
755
+ free(refspec);
756
+ } else if (ref_count) {
757
prune_refs(refs, ref_count, ref_map);
740
- else
758
+ } else {
759
prune_refs(transport->remote->fetch, transport->remote->fetch_refspec_nr, ref_map);
760
+ }
761
}
762
free_refs(ref_map);
763
t/t5510-fetch.sh
+2
-2
@@ -105,7 +105,7 @@ test_expect_success 'fetch --prune with a namespace keeps other namespaces' '
105
git rev-parse origin/master
106
'
107
108
-test_expect_failure 'fetch --prune --tags does not delete the remote-tracking branches' '
108
+test_expect_success 'fetch --prune --tags does not delete the remote-tracking branches' '
109
cd "$D" &&
110
git clone . prune-tags &&
111
cd prune-tags &&
@@ -116,7 +116,7 @@ test_expect_failure 'fetch --prune --tags does not delete the remote-tracking br
116
test_must_fail git rev-parse somebranch
117
'
118
119
-test_expect_failure 'fetch --prune --tags with branch does not delete other remote-tracking branches' '
119
+test_expect_success 'fetch --prune --tags with branch does not delete other remote-tracking branches' '
120
cd "$D" &&
121
git clone . prune-tags-branch &&
122
cd prune-tags-branch &&