git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Brandon Williams" <bmwill@google.com>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
	"Jonathan Nieder" <jrnieder@gmail.com>,
	"Stefan Beller" <sbeller@google.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
Subject: [RFC/PATCH v3 5/5] WIP clone: add a --[no-]recommend-tags & submodule.NAME.tags config
Date: Wed, 26 Apr 2017 23:12:36 +0000	[thread overview]
Message-ID: <20170426231236.27219-6-avarab@gmail.com> (raw)
In-Reply-To: <20170426231236.27219-1-avarab@gmail.com>

Add a --no-recommend-tags option & support for
submodule.NAME.tags=[true|false] config facility. This does for
--no-tags what --no-recommend-shallow & submodule.NAME.shallow does
for --shallow-submodules.

This is almost exactly the same code change as in Stefan Beller's
commit abed000aca ("submodule update: learn `--[no-]recommend-shallow`
option", 2016-05-26) & 37f52e9344 ("submodule-config: keep shallow
recommendation around", 2016-05-26).

The difference in the configuration facility is that setting
submodule.NAME.tags=false will turn on --no-tags, i.e. "false" means
"don't give me tags", with "true" being the default.

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 Documentation/git-submodule.txt        |  8 +++++++-
 builtin/submodule--helper.c            |  7 +++++--
 contrib/completion/git-completion.bash |  1 +
 git-submodule.sh                       |  9 ++++++++-
 submodule-config.c                     |  8 ++++++++
 submodule-config.h                     |  1 +
 t/t5616-clone-submodules-tags.sh       | 34 ++++++++++++++++++++++++++++++++++
 7 files changed, 64 insertions(+), 4 deletions(-)

diff --git a/Documentation/git-submodule.txt b/Documentation/git-submodule.txt
index 74bc6200d5..9a431a833d 100644
--- a/Documentation/git-submodule.txt
+++ b/Documentation/git-submodule.txt
@@ -159,7 +159,7 @@ instead of deinit-ing everything, to prevent mistakes.
 If `--force` is specified, the submodule's working tree will
 be removed even if it contains local modifications.
 
-update [--init] [--remote] [-N|--no-fetch] [--[no-]recommend-shallow] [-f|--force] [--checkout|--rebase|--merge] [--reference <repository>] [--depth <depth>] [--recursive] [--jobs <n>] [--] [<path>...]::
+update [--init] [--remote] [-N|--no-fetch] [--[no-]recommend-shallow] [--[no-]recommend-tags] [-f|--force] [--checkout|--rebase|--merge] [--reference <repository>] [--depth <depth>] [--recursive] [--jobs <n>] [--] [<path>...]::
 +
 --
 Update the registered submodules to match what the superproject
@@ -416,6 +416,12 @@ for linkgit:git-clone[1]'s `--reference` and `--shared` options carefully.
 	`submodule.<name>.shallow` as provided by the .gitmodules file
 	by default. To ignore the suggestions use `--no-recommend-shallow`.
 
+--[no-]recommend-tags::
+	This option is only valid for the update command.
+	The initial clone of a submodule will use the recommended
+	`submodule.<name>.tags` as provided by the .gitmodules file
+	by default. To ignore the suggestions use `--no-recommend-tags`.
+
 -j <n>::
 --jobs <n>::
 	This option is only valid for the update command.
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index caa4d252ee..424ea7a680 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -736,6 +736,7 @@ struct submodule_update_clone {
 	int progress;
 	int quiet;
 	int recommend_shallow;
+	int recommend_tags;
 	struct string_list references;
 	const char *depth;
 	const char *recursive_prefix;
@@ -753,7 +754,7 @@ struct submodule_update_clone {
 	int no_tags;
 };
 #define SUBMODULE_UPDATE_CLONE_INIT {0, MODULE_LIST_INIT, 0, \
-	SUBMODULE_UPDATE_STRATEGY_INIT, 0, 0, -1, STRING_LIST_INIT_DUP, \
+	SUBMODULE_UPDATE_STRATEGY_INIT, 0, 0, -1, -1, STRING_LIST_INIT_DUP, \
 	NULL, NULL, NULL, \
 	STRING_LIST_INIT_DUP, 0, NULL, 0, 0, 0}
 
@@ -855,7 +856,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
 		argv_array_pushl(&child->args, "--prefix", suc->prefix, NULL);
 	if (suc->recommend_shallow && sub->recommend_shallow == 1)
 		argv_array_push(&child->args, "--depth=1");
-	if (suc->no_tags)
+	if (suc->no_tags || suc->recommend_tags == 0)
 		argv_array_push(&child->args, "--no-tags");
 	argv_array_pushl(&child->args, "--path", sub->path, NULL);
 	argv_array_pushl(&child->args, "--name", sub->name, NULL);
@@ -996,6 +997,8 @@ static int update_clone(int argc, const char **argv, const char *prefix)
 			    N_("parallel jobs")),
 		OPT_BOOL(0, "recommend-shallow", &suc.recommend_shallow,
 			    N_("whether the initial clone should follow the shallow recommendation")),
+		OPT_BOOL(0, "recommend-tags", &suc.recommend_tags,
+			    N_("whether the initial clone should follow the tags recommendation")),
 		OPT_BOOL(0, "no-tags", &suc.no_tags,
 			 N_("don't clone any tags, and make later fetches not to follow them")),
 		OPT__QUIET(&suc.quiet, N_("don't print cloning progress")),
diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 08fb1319c3..8eb32032a8 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -2878,6 +2878,7 @@ _git_submodule ()
 		__gitcomp "
 			--init --remote --no-fetch
 			--recommend-shallow --no-recommend-shallow
+			--recommend-tags --no-recommend-tags
 			--force --rebase --merge --reference --depth --recursive --jobs
 		"
 		;;
diff --git a/git-submodule.sh b/git-submodule.sh
index 3371775b0b..5b204a9679 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -9,7 +9,7 @@ USAGE="[--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <re
    or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]
    or: $dashless [--quiet] init [--] [<path>...]
    or: $dashless [--quiet] deinit [-f|--force] (--all| [--] <path>...)
-   or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--reference <repository>] [--recursive] [--] [<path>...]
+   or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--[no-]recommend-tags] [--reference <repository>] [--recursive] [--] [<path>...]
    or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
    or: $dashless [--quiet] foreach [--recursive] <command>
    or: $dashless [--quiet] sync [--recursive] [--] [<path>...]
@@ -557,6 +557,12 @@ cmd_update()
 		--no-recommend-shallow)
 			recommend_shallow="--no-recommend-shallow"
 			;;
+		--recommend-tags)
+			recommend_tags="--recommend-tags"
+			;;
+		--no-recommend-tags)
+			recommend_tags="--no-recommend-tags"
+			;;
 		--depth)
 			case "$2" in '') usage ;; esac
 			depth="--depth=$2"
@@ -604,6 +610,7 @@ cmd_update()
 		${reference:+"$reference"} \
 		${depth:+--depth "$depth"} \
 		${recommend_shallow:+"$recommend_shallow"} \
+		${recommend_tags:+"$recommend_tags"} \
 		${no_tags:+--no-tags} \
 		${jobs:+$jobs} \
 		"$@" || echo "#unmatched" $?
diff --git a/submodule-config.c b/submodule-config.c
index 4f58491ddb..68fbd9d1f0 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -202,6 +202,7 @@ static struct submodule *lookup_or_create_by_name(struct submodule_cache *cache,
 	submodule->ignore = NULL;
 	submodule->branch = NULL;
 	submodule->recommend_shallow = -1;
+	submodule->recommend_tags = -1;
 
 	hashcpy(submodule->gitmodules_sha1, gitmodules_sha1);
 
@@ -385,6 +386,13 @@ static int parse_config(const char *var, const char *value, void *data)
 		else
 			submodule->recommend_shallow =
 				git_config_bool(var, value);
+	} else if (!strcmp(item.buf, "tags")) {
+		if (!me->overwrite && submodule->recommend_tags != -1)
+			warn_multiple_config(me->treeish_name, submodule->name,
+					     "tags");
+		else
+			submodule->recommend_tags =
+				git_config_bool(var, value);
 	} else if (!strcmp(item.buf, "branch")) {
 		if (!me->overwrite && submodule->branch)
 			warn_multiple_config(me->treeish_name, submodule->name,
diff --git a/submodule-config.h b/submodule-config.h
index d434ecdb45..be3c567803 100644
--- a/submodule-config.h
+++ b/submodule-config.h
@@ -20,6 +20,7 @@ struct submodule {
 	/* the sha1 blob id of the responsible .gitmodules file */
 	unsigned char gitmodules_sha1[20];
 	int recommend_shallow;
+	int recommend_tags;
 };
 
 extern int parse_fetch_recurse_submodules_arg(const char *opt, const char *arg);
diff --git a/t/t5616-clone-submodules-tags.sh b/t/t5616-clone-submodules-tags.sh
index 3c88265352..caded2fb24 100755
--- a/t/t5616-clone-submodules-tags.sh
+++ b/t/t5616-clone-submodules-tags.sh
@@ -69,4 +69,38 @@ test_expect_success 'tags clone with no-tags submodule' '
 	test_line_count = 0 tags
 '
 
+test_expect_success 'clone follows tags=false recommendation' '
+	test_when_finished "rm -rf super_clone" &&
+	git config -f .gitmodules submodule.sub.tags false &&
+	git add .gitmodules &&
+	git commit -m "recommed no-tags for sub" &&
+	git clone --recurse-submodules --no-local "file://$pwd/." super_clone &&
+	git -C super_clone for-each-ref --format="%(refname:strip=2)" refs/tags/ >tags &&
+	test_line_count = 3 tags &&
+	git -C super_clone/sub for-each-ref --format="%(refname:strip=2)" refs/tags/ >tags &&
+	test_line_count = 0 tags
+'
+
+test_expect_success 'get tags recommended no-tags submodule' '
+	test_when_finished "rm -rf super_clone" &&
+	git clone --no-local "file://$pwd/." super_clone &&
+	git -C super_clone submodule update --init --no-recommend-tags &&
+	git -C super_clone for-each-ref --format="%(refname:strip=2)" refs/tags/ >tags &&
+	test_line_count = 3 tags &&
+	git -C super_clone/sub for-each-ref --format="%(refname:strip=2)" refs/tags/ >tags &&
+	test_line_count = 3 tags
+'
+
+test_expect_success 'clone follows tags=true recommendation' '
+	test_when_finished "rm -rf super_clone" &&
+	git config -f .gitmodules submodule.sub.tags true &&
+	git add .gitmodules &&
+	git commit -m "recommed tags for sub" &&
+	git clone --recurse-submodules --no-local "file://$pwd/." super_clone &&
+	git -C super_clone for-each-ref --format="%(refname:strip=2)" refs/tags/ >tags &&
+	test_line_count = 3 tags &&
+	git -C super_clone/sub for-each-ref --format="%(refname:strip=2)" refs/tags/ >tags &&
+	test_line_count = 3 tags
+'
+
 test_done
-- 
2.11.0


  parent reply	other threads:[~2017-04-26 23:13 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-26 23:12 [PATCH v3 0/5] clone: --no-tags option Ævar Arnfjörð Bjarmason
2017-04-26 23:12 ` [PATCH v3 1/5] tests: change "cd ... && git fetch" to "cd &&\n\tgit fetch" Ævar Arnfjörð Bjarmason
2017-04-26 23:12 ` [PATCH v3 2/5] clone: add a --no-tags option to clone without tags Ævar Arnfjörð Bjarmason
2017-04-27 17:54   ` Stefan Beller
2017-04-27 22:12     ` Brandon Williams
2017-04-28 14:44     ` Ævar Arnfjörð Bjarmason
2017-04-26 23:12 ` [PATCH v3 3/5] tests: rename a test having to do with shallow submodules Ævar Arnfjörð Bjarmason
2017-04-27 17:58   ` Stefan Beller
2017-04-27 22:13     ` Brandon Williams
2017-04-28  8:59       ` Ævar Arnfjörð Bjarmason
2017-04-28 17:50         ` Stefan Beller
2017-04-26 23:12 ` [PATCH v3 4/5] clone: add a --no-tags-submodules to pass --no-tags to submodules Ævar Arnfjörð Bjarmason
2017-04-27  2:34   ` Junio C Hamano
2017-04-27 16:33     ` Brandon Williams
2017-04-27 18:27   ` Stefan Beller
2017-04-27 22:19     ` Brandon Williams
2017-04-26 23:12 ` Ævar Arnfjörð Bjarmason [this message]
2017-04-27 19:36   ` [RFC/PATCH v3 5/5] WIP clone: add a --[no-]recommend-tags & submodule.NAME.tags config Stefan Beller
2017-04-27 22:27 ` [PATCH v3 0/5] clone: --no-tags option Brandon Williams
2017-04-28  8:57   ` Ævar Arnfjörð Bjarmason
2017-04-28 19:11 ` Ævar Arnfjörð Bjarmason
2017-04-28 19:16   ` Stefan Beller
2017-05-01  1:31   ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170426231236.27219-6-avarab@gmail.com \
    --to=avarab@gmail.com \
    --cc=bmwill@google.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=jrnieder@gmail.com \
    --cc=pclouds@gmail.com \
    --cc=sbeller@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).