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 <sam@rfc1149.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Samuel Tardieu committed
Apr 20, 2010 at 01:31 UTC
111fb858654b95355da05772b4dcdf91decc4721
3 files changed
+90
-2
Documentation/git-remote.txt
+7
-1
@@ -10,7 +10,7 @@ SYNOPSIS
10
--------
11
[verse]
12
'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>
14
'git remote rename' <old> <new>
15
'git remote rm' <name>
16
'git remote set-head' <name> (-a | -d | <branch>)
@@ -51,6 +51,12 @@ update remote-tracking branches <name>/<branch>.
51
With `-f` option, `git fetch <name>` is run immediately after
52
the remote information is set up.
53
+
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
++
60
With `-t <branch>` option, instead of the default glob
61
refspec for the remote to track all branches under
62
`$GIT_DIR/remotes/<name>/`, a refspec to track only `<branch>`
builtin/remote.c
+20
-1
@@ -104,9 +104,15 @@ static int fetch_remote(const char *name)
104
return 0;
105
}
106
107
+enum {
108
+ TAGS_UNSET = 0,
109
+ TAGS_DEFAULT = 1,
110
+ TAGS_SET = 2
111
+};
112
+
113
static int add(int argc, const char **argv)
114
{
109
- int fetch = 0, mirror = 0;
115
+ int fetch = 0, mirror = 0, fetch_tags = TAGS_DEFAULT;
116
struct string_list track = { NULL, 0, 0 };
117
const char *master = NULL;
118
struct remote *remote;
@@ -116,6 +122,11 @@ static int add(int argc, const char **argv)
122
123
struct option options[] = {
124
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),
130
OPT_CALLBACK('t', "track", &track, "branch",
131
"branch(es) to track", opt_parse_track),
132
OPT_STRING('m', "master", &master, "branch", "master branch"),
@@ -172,6 +183,14 @@ static int add(int argc, const char **argv)
183
return 1;
184
}
185
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
+
194
if (fetch && fetch_remote(name))
195
return 1;
196
t/t5505-remote.sh
+63
@@ -320,6 +320,69 @@ test_expect_success 'add alt && prune' '
320
git rev-parse --verify refs/remotes/origin/side2)
321
'
322
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
+
386
cat > one/expect << EOF
387
apis/master
388
apis/side