Skip to contentSkip to conversation

Add --tags/--no-tags options to "git add remote"

PATCH New Samuel Tardieu 1 participant 3 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

v3 cover Add --tags/--no-tags options to "git add remote"

The following series adds the "--[no-]tags" option to "git add remote". Since "-t" was already taken for "--track", I only let the long "--tags" and "--no-tags" options.

In order to implement the "--tags" behaviour, I first had to add correct handling of "tagopt = --tags" in remote configuration options.

---

Samuel Tardieu (2):
Honor "tagopt = --tags" configuration option remote add: add a --no-tags (-n) option

 Documentation/git-remote.txt |    8 +++++
 builtin/remote.c             |   21 +++++++++++++-
 remote.c                     |    2 +
 t/t5505-remote.sh            |   63 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 92 insertions(+), 2 deletions(-)
#1 lore raw

PATCH v3 1/2 Honor "tagopt = --tags" configuration option

If the "tagopt = --tags" option of a remote is set, all tags will be fetched as in "git fetch --tags".

---
 Documentation/config.txt      |    4 +++-
 contrib/examples/git-fetch.sh |    4 +++-
 remote.c                      |    2 ++
 3 files changed, 8 insertions(+), 2 deletions(-)
Documentation/config.txt +3 -1
index f45ae9c..8e7fd88 100644
@@ -1587,7 +1587,9 @@ remote.<name>.uploadpack::
 
 remote.<name>.tagopt::
 	Setting this value to \--no-tags disables automatic tag following when
-	fetching from remote <name>
+	fetching from remote <name>. Setting it to \--tags will fetch every
+	tag from remote <name>, even if they are not reachable from remote
+	branch heads.
 
 remote.<name>.vcs::
 	Setting this to a value <vcs> will cause git to interact with
contrib/examples/git-fetch.sh +3 -1
index e44af2c..a314273 100755
@@ -127,10 +127,12 @@ then
 	orig_head=$(git rev-parse --verify HEAD 2>/dev/null)
 fi
 
-# Allow --notags from remote.$1.tagopt
+# Allow --tags/--notags from remote.$1.tagopt
 case "$tags$no_tags" in
 '')
 	case "$(git config --get "remote.$1.tagopt")" in
+	--tags)
+		tags=t ;;
 	--no-tags)
 		no_tags=t ;;
 	esac
remote.c +2 -0
index c70181c..0f073e0 100644
@@ -443,6 +443,8 @@ static int handle_config(const char *key, const char *value, void *cb)
 	} else if (!strcmp(subkey, ".tagopt")) {
 		if (!strcmp(value, "--no-tags"))
 			remote->fetch_tags = -1;
+		else if (!strcmp(value, "--tags"))
+			remote->fetch_tags = 2;
 	} else if (!strcmp(subkey, ".proxy")) {
 		return git_config_string((const char **)&remote->http_proxy,
 					 key, value);
#2 lore raw

PATCH v3 2/2 remote add: add a --no-tags (-n) option

In reply to Samuel Tardieu

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".

---
 Documentation/git-remote.txt |    8 +++++
 builtin/remote.c             |   21 +++++++++++++-
 t/t5505-remote.sh            |   63 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 90 insertions(+), 2 deletions(-)
Documentation/git-remote.txt +7 -1
index 3fc599c..ebaaadc 100644
@@ -10,7 +10,7 @@ SYNOPSIS
 --------
 [verse]
 'git remote' [-v | --verbose]
-'git remote add' [-t <branch>] [-m <master>] [-f] [--mirror] <name> <url>
+'git remote add' [-t <branch>] [-m <master>] [-f] [--tags|--no-tags] [--mirror] <name> <url>
 'git remote rename' <old> <new>
 'git remote rm' <name>
 'git remote set-head' <name> (-a | -d | <branch>)
@@ -51,6 +51,12 @@ update remote-tracking branches <name>/<branch>.
 With `-f` option, `git fetch <name>` is run immediately after
 the remote information is set up.
 +
+With `--tags` option, `git fetch <name>` imports every tag from the
+remote repository.
++
+With `--no-tags` option, `git fetch <name>` does not import tags from
+the remote repository.
++
 With `-t <branch>` option, instead of the default glob
 refspec for the remote to track all branches under
 `$GIT_DIR/remotes/<name>/`, a refspec to track only `<branch>`
builtin/remote.c +20 -1
index 277765b..0e99a99 100644
@@ -104,9 +104,15 @@ static int fetch_remote(const char *name)
 	return 0;
 }
 
+enum {
+	TAGS_UNSET = 0,
+	TAGS_DEFAULT = 1,
+	TAGS_SET = 2
+};
+
 static int add(int argc, const char **argv)
 {
-	int fetch = 0, mirror = 0;
+	int fetch = 0, mirror = 0, fetch_tags = TAGS_DEFAULT;
 	struct string_list track = { NULL, 0, 0 };
 	const char *master = NULL;
 	struct remote *remote;
@@ -116,6 +122,11 @@ static int add(int argc, const char **argv)
 
 	struct option options[] = {
 		OPT_BOOLEAN('f', "fetch", &fetch, "fetch the remote branches"),
+		OPT_SET_INT(0, "tags", &fetch_tags,
+			    "import all tags and associated objects when fetching",
+			    TAGS_SET),
+		OPT_SET_INT(0, NULL, &fetch_tags,
+			    "or do not fetch any tag at all (--no-tags)", TAGS_UNSET),
 		OPT_CALLBACK('t', "track", &track, "branch",
 			"branch(es) to track", opt_parse_track),
 		OPT_STRING('m', "master", &master, "branch", "master branch"),
@@ -172,6 +183,14 @@ static int add(int argc, const char **argv)
 			return 1;
 	}
 
+	if (fetch_tags != TAGS_DEFAULT) {
+		strbuf_reset(&buf);
+		strbuf_addf(&buf, "remote.%s.tagopt", name);
+		if (git_config_set(buf.buf,
+			fetch_tags == TAGS_SET ? "--tags" : "--no-tags"))
+			return 1;
+	}
+
 	if (fetch && fetch_remote(name))
 		return 1;
 
t/t5505-remote.sh +63 -0

69 lines not on this page · raw message