summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@elego.de>2011-10-15 05:04:26 (GMT)
committerJunio C Hamano <gitster@pobox.com>2011-10-16 05:00:37 (GMT)
commite8c1e6c796c1b96b6b208bbd4bc8cfd9acb481b5 (patch)
tree6de4732d4833f40e31b11dd50097a638fd3c5c90 /builtin
parented43de6ec35dfd4c4bd33ae9b5f2ebe38282209f (diff)
downloadgit-e8c1e6c796c1b96b6b208bbd4bc8cfd9acb481b5.zip
git-e8c1e6c796c1b96b6b208bbd4bc8cfd9acb481b5.tar.gz
git-e8c1e6c796c1b96b6b208bbd4bc8cfd9acb481b5.tar.bz2
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>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/fetch.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/builtin/fetch.c b/builtin/fetch.c
index e295d97..9d481f8 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -735,10 +735,29 @@ static int do_fetch(struct transport *transport,
return 1;
}
if (prune) {
- if (ref_count)
+ /* If --tags was specified, pretend the user gave us the canonical tags refspec */
+ if (tags == TAGS_SET) {
+ const char *tags_str = "refs/tags/*:refs/tags/*";
+ struct refspec *tags_refspec, *refspec;
+
+ /* Copy the refspec and add the tags to it */
+ refspec = xcalloc(ref_count + 1, sizeof(struct refspec));
+ tags_refspec = parse_fetch_refspec(1, &tags_str);
+ memcpy(refspec, refs, ref_count * sizeof(struct refspec));
+ memcpy(&refspec[ref_count], tags_refspec, sizeof(struct refspec));
+ ref_count++;
+
+ prune_refs(refspec, ref_count, ref_map);
+
+ ref_count--;
+ /* The rest of the strings belong to fetch_one */
+ free_refspec(1, tags_refspec);
+ free(refspec);
+ } else if (ref_count) {
prune_refs(refs, ref_count, ref_map);
- else
+ } else {
prune_refs(transport->remote->fetch, transport->remote->fetch_refspec_nr, ref_map);
+ }
}
free_refs(ref_map);