Skip to content

Commit 4277912

Browse files
committed
Merge branch 'st/remote-tags-no-tags'
* st/remote-tags-no-tags: remote add: add a --[no-]tags option Honor "tagopt = --tags" configuration option
2 parents 4cbf42e + 111fb85 commit 4277912

File tree

6 files changed

+98
-4
lines changed

6 files changed

+98
-4
lines changed

Documentation/config.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1593,7 +1593,9 @@ remote.<name>.uploadpack::
15931593

15941594
remote.<name>.tagopt::
15951595
Setting this value to \--no-tags disables automatic tag following when
1596-
fetching from remote <name>
1596+
fetching from remote <name>. Setting it to \--tags will fetch every
1597+
tag from remote <name>, even if they are not reachable from remote
1598+
branch heads.
15971599

15981600
remote.<name>.vcs::
15991601
Setting this to a value <vcs> will cause git to interact with

Documentation/git-remote.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ SYNOPSIS
1010
--------
1111
[verse]
1212
'git remote' [-v | --verbose]
13-
'git remote add' [-t <branch>] [-m <master>] [-f] [--mirror] <name> <url>
13+
'git remote add' [-t <branch>] [-m <master>] [-f] [--tags|--no-tags] [--mirror] <name> <url>
1414
'git remote rename' <old> <new>
1515
'git remote rm' <name>
1616
'git remote set-head' <name> (-a | -d | <branch>)
@@ -51,6 +51,12 @@ update remote-tracking branches <name>/<branch>.
5151
With `-f` option, `git fetch <name>` is run immediately after
5252
the remote information is set up.
5353
+
54+
With `--tags` option, `git fetch <name>` imports every tag from the
55+
remote repository.
56+
+
57+
With `--no-tags` option, `git fetch <name>` does not import tags from
58+
the remote repository.
59+
+
5460
With `-t <branch>` option, instead of the default glob
5561
refspec for the remote to track all branches under
5662
`$GIT_DIR/remotes/<name>/`, a refspec to track only `<branch>`

builtin/remote.c

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,15 @@ static int fetch_remote(const char *name)
104104
return 0;
105105
}
106106

107+
enum {
108+
TAGS_UNSET = 0,
109+
TAGS_DEFAULT = 1,
110+
TAGS_SET = 2
111+
};
112+
107113
static int add(int argc, const char **argv)
108114
{
109-
int fetch = 0, mirror = 0;
115+
int fetch = 0, mirror = 0, fetch_tags = TAGS_DEFAULT;
110116
struct string_list track = { NULL, 0, 0 };
111117
const char *master = NULL;
112118
struct remote *remote;
@@ -116,6 +122,11 @@ static int add(int argc, const char **argv)
116122

117123
struct option options[] = {
118124
OPT_BOOLEAN('f', "fetch", &fetch, "fetch the remote branches"),
125+
OPT_SET_INT(0, "tags", &fetch_tags,
126+
"import all tags and associated objects when fetching",
127+
TAGS_SET),
128+
OPT_SET_INT(0, NULL, &fetch_tags,
129+
"or do not fetch any tag at all (--no-tags)", TAGS_UNSET),
119130
OPT_CALLBACK('t', "track", &track, "branch",
120131
"branch(es) to track", opt_parse_track),
121132
OPT_STRING('m', "master", &master, "branch", "master branch"),
@@ -172,6 +183,14 @@ static int add(int argc, const char **argv)
172183
return 1;
173184
}
174185

186+
if (fetch_tags != TAGS_DEFAULT) {
187+
strbuf_reset(&buf);
188+
strbuf_addf(&buf, "remote.%s.tagopt", name);
189+
if (git_config_set(buf.buf,
190+
fetch_tags == TAGS_SET ? "--tags" : "--no-tags"))
191+
return 1;
192+
}
193+
175194
if (fetch && fetch_remote(name))
176195
return 1;
177196

contrib/examples/git-fetch.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,12 @@ then
127127
orig_head=$(git rev-parse --verify HEAD 2>/dev/null)
128128
fi
129129

130-
# Allow --notags from remote.$1.tagopt
130+
# Allow --tags/--notags from remote.$1.tagopt
131131
case "$tags$no_tags" in
132132
'')
133133
case "$(git config --get "remote.$1.tagopt")" in
134+
--tags)
135+
tags=t ;;
134136
--no-tags)
135137
no_tags=t ;;
136138
esac

remote.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,8 @@ static int handle_config(const char *key, const char *value, void *cb)
443443
} else if (!strcmp(subkey, ".tagopt")) {
444444
if (!strcmp(value, "--no-tags"))
445445
remote->fetch_tags = -1;
446+
else if (!strcmp(value, "--tags"))
447+
remote->fetch_tags = 2;
446448
} else if (!strcmp(subkey, ".proxy")) {
447449
return git_config_string((const char **)&remote->http_proxy,
448450
key, value);

t/t5505-remote.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,69 @@ test_expect_success 'add alt && prune' '
320320
git rev-parse --verify refs/remotes/origin/side2)
321321
'
322322

323+
cat >test/expect <<\EOF
324+
some-tag
325+
EOF
326+
327+
test_expect_success 'add with reachable tags (default)' '
328+
(cd one &&
329+
>foobar &&
330+
git add foobar &&
331+
git commit -m "Foobar" &&
332+
git tag -a -m "Foobar tag" foobar-tag &&
333+
git reset --hard HEAD~1 &&
334+
git tag -a -m "Some tag" some-tag) &&
335+
(mkdir add-tags &&
336+
cd add-tags &&
337+
git init &&
338+
git remote add -f origin ../one &&
339+
git tag -l some-tag >../test/output &&
340+
git tag -l foobar-tag >>../test/output &&
341+
test_must_fail git config remote.origin.tagopt) &&
342+
test_cmp test/expect test/output
343+
'
344+
345+
cat >test/expect <<\EOF
346+
some-tag
347+
foobar-tag
348+
--tags
349+
EOF
350+
351+
test_expect_success 'add --tags' '
352+
(rm -rf add-tags &&
353+
mkdir add-tags &&
354+
cd add-tags &&
355+
git init &&
356+
git remote add -f --tags origin ../one &&
357+
git tag -l some-tag >../test/output &&
358+
git tag -l foobar-tag >>../test/output &&
359+
git config remote.origin.tagopt >>../test/output) &&
360+
test_cmp test/expect test/output
361+
'
362+
363+
cat >test/expect <<\EOF
364+
--no-tags
365+
EOF
366+
367+
test_expect_success 'add --no-tags' '
368+
(rm -rf add-tags &&
369+
mkdir add-no-tags &&
370+
cd add-no-tags &&
371+
git init &&
372+
git remote add -f --no-tags origin ../one &&
373+
git tag -l some-tag >../test/output &&
374+
git tag -l foobar-tag >../test/output &&
375+
git config remote.origin.tagopt >>../test/output) &&
376+
(cd one &&
377+
git tag -d some-tag foobar-tag) &&
378+
test_cmp test/expect test/output
379+
'
380+
381+
test_expect_success 'reject --no-no-tags' '
382+
(cd add-no-tags &&
383+
test_must_fail git remote add -f --no-no-tags neworigin ../one)
384+
'
385+
323386
cat > one/expect << EOF
324387
apis/master
325388
apis/side

0 commit comments

Comments
 (0)