Skip to content

Commit 111fb85

Browse files
samueltardieugitster
authored andcommitted
remote add: add a --[no-]tags option
Add '--[no-]tags' options to 'git remote add' which add the 'remote.REMOTE.tagopt = --[no-]tags' to the configuration file. This mimics the "--tags" and "--no-tags" options of "git fetch". Signed-off-by: Samuel Tardieu <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 944163a commit 111fb85

File tree

3 files changed

+90
-2
lines changed

3 files changed

+90
-2
lines changed

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

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)