git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 5/6] config: select .git/common/config with --repo

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Jan 26, 2016, 11:44 UTC
Message-ID
<1453808685-21235-6-git-send-email-pclouds@gmail.com>
In-Reply-To
<1453808685-21235-1-git-send-email-pclouds@gmail.com>

This new option allows the user to write to or read from .git/common/config in worktree v1. In worktree v0, --repo is an alias of --local.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 Documentation/git-config.txt           | 14 +++++++++++++-
 Documentation/git-worktree.txt         |  4 ++++
 Documentation/gitrepository-layout.txt | 10 +++++-----
 builtin/config.c                       | 19 ++++++++++++++-----
 t/t2028-worktree-config.sh             | 23 ++++++++++++++++++++++-
 5 files changed, 58 insertions(+), 12 deletions(-)
diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt
index 2608ca7..79fd453 100644
--- a/Documentation/git-config.txt
+++ b/Documentation/git-config.txt
@@ -47,7 +47,7 @@ checks or transformations are performed on the value.
 
 When reading, the values are read from the system, global and
 repository local configuration files by default, and options
-'--system', '--global', '--local' and '--file <filename>' can be
+'--system', '--global', '--repo', '--local' and '--file <filename>' can be
 used to tell the command to read from only that location (see <<FILES>>).
 
 When writing, the new value is written to the repository local
@@ -125,6 +125,18 @@ rather than from all available files.
 +
 See also <<FILES>>.
 
+--repo::
+
+	For writing options: write to the repository file
+	`.git/config` if the configuration variable extensions.worktree
+	is not specified or has the value zero, `.git/worktrees/config`
+	otherwise.
++
+For reading options: read only from the same file rather than from all
+available files.
++
+See also <<FILES>>.
+
 --local::
 	For writing options: write to the repository `.git/config` file.
 	This is	the default behavior.
diff --git a/Documentation/git-worktree.txt b/Documentation/git-worktree.txt
index 0846f2a..6082d4d 100644
--- a/Documentation/git-worktree.txt
+++ b/Documentation/git-worktree.txt
@@ -119,6 +119,10 @@ In this version, the repository config file `.git/config` is not
 shared anymore. A new file, `.git/common/config`, read for all
 worktrees. Shared configuration should be stored here.
 
+Use "git config --repo" to store shared configuration variables. Use
+"git config --local" to store per-worktree ones. This works even in
+single-worktree mode.
+
 Version 0
 ~~~~~~~~~
 This is the first release. Version 0 is implied if extensions.worktree
diff --git a/Documentation/gitrepository-layout.txt b/Documentation/gitrepository-layout.txt
index d65345d..56175f0 100644
--- a/Documentation/gitrepository-layout.txt
+++ b/Documentation/gitrepository-layout.txt
@@ -254,6 +254,11 @@ common::
 	This directory is seen from all working directories. It is
 	meant to share files that all working directories can see.
 
+common/config::
+	Repository specific configuration file. Note that if this file
+	is present, it must contain the variable extensions.worktree
+	whose value must be one or above.
+
 worktrees::
 	Contains administrative data for linked
 	working trees. Each subdirectory contains the working tree-related
@@ -261,11 +266,6 @@ worktrees::
 	$GIT_COMMON_DIR is set, in which case
 	"$GIT_COMMON_DIR/worktrees" will be used instead.
 
-common/config::
-	Repository specific configuration file. Note that if this file
-	is present, it must contain the variable extensions.worktree
-	whose value must be one or above.
-
 worktrees/<id>/gitdir::
 	A text file containing the absolute path back to the .git file
 	that points to here. This is used to check if the linked
diff --git a/builtin/config.c b/builtin/config.c
index adc7727..6aecd13 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -21,7 +21,7 @@ static char delim = '=';
 static char key_delim = ' ';
 static char term = '\n';
 
-static int use_global_config, use_system_config, use_local_config;
+static int use_global_config, use_system_config, use_local_config, use_repo_config;
 static struct git_config_source given_config_source;
 static int actions, types;
 static const char *get_color_slot, *get_colorbool_slot;
@@ -54,7 +54,8 @@ static struct option builtin_config_options[] = {
 	OPT_GROUP(N_("Config file location")),
 	OPT_BOOL(0, "global", &use_global_config, N_("use global config file")),
 	OPT_BOOL(0, "system", &use_system_config, N_("use system config file")),
-	OPT_BOOL(0, "local", &use_local_config, N_("use repository config file")),
+	OPT_BOOL(0, "repo", &use_repo_config, N_("use per-repository config file")),
+	OPT_BOOL(0, "local", &use_local_config, N_("use per-worktree config file")),
 	OPT_STRING('f', "file", &given_config_source.file, N_("file"), N_("use given config file")),
 	OPT_STRING(0, "blob", &given_config_source.blob, N_("blob-id"), N_("read config from given blob object")),
 	OPT_GROUP(N_("Action")),
@@ -460,7 +461,8 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 			     PARSE_OPT_STOP_AT_NON_OPTION);
 
 	if (use_global_config + use_system_config + use_local_config +
-	    !!given_config_source.file + !!given_config_source.blob > 1) {
+	    !!given_config_source.file + !!given_config_source.blob > 1 +
+	    use_repo_config) {
 		error("only one config file at a time.");
 		usage_with_options(builtin_config_usage, builtin_config_options);
 	}
@@ -492,9 +494,16 @@ int cmd_config(int argc, const char **argv, const char *prefix)
 	}
 	else if (use_system_config)
 		given_config_source.file = git_etc_gitconfig();
-	else if (use_local_config)
+	else if (use_local_config ||
+		 (use_repo_config &&
+		  repository_format_worktree_version == 0))
 		given_config_source.file = git_pathdup("config");
-	else if (given_config_source.file) {
+	else if (use_repo_config) {
+		struct strbuf sb = STRBUF_INIT;
+
+		strbuf_addf(&sb, "%s/common/config", get_git_common_dir());
+		given_config_source.file = strbuf_detach(&sb, NULL);
+	} else if (given_config_source.file) {
 		if (!is_absolute_path(given_config_source.file) && prefix)
 			given_config_source.file =
 				xstrdup(prefix_filename(prefix,
diff --git a/t/t2028-worktree-config.sh b/t/t2028-worktree-config.sh
index 5561788..d11b2ce 100755
--- a/t/t2028-worktree-config.sh
+++ b/t/t2028-worktree-config.sh
@@ -19,6 +19,15 @@ test_expect_success 'main config is shared in version 0' '
 	test_cmp expected actual
 '
 
+test_expect_success 'config --repo on v0' '
+	git config --global new.var old-value &&
+	git config --repo new.var new-value &&
+	test_path_is_missing .git/common/config &&
+	git config --repo new.var >actual &&
+	echo new-value >expected &&
+	test_cmp expected actual
+'
+
 test_expect_success 'main config is for main worktree only (v1)' '
 	mkdir .git/common &&
 	git config -f .git/common/config extensions.worktree 1 &&
@@ -28,7 +37,7 @@ test_expect_success 'main config is for main worktree only (v1)' '
 	test_must_fail git -C wt1 config wt.name
 '
 
-test_expect_success 'worktrees/config is shared (v1)' '
+test_expect_success 'common/config is shared (v1)' '
 	git config -f .git/common/config some.thing is-shared &&
 	echo is-shared >expected &&
 	git config some.thing >actual &&
@@ -37,4 +46,16 @@ test_expect_success 'worktrees/config is shared (v1)' '
 	test_cmp expected actual
 '
 
+test_expect_success 'config --repo on v1' '
+	git config --global new.var1 old-value &&
+	git config --repo new.var1 new-value &&
+	grep var1 .git/common/config >/dev/null &&
+	git config --repo new.var1 >actual &&
+	echo new-value >expected &&
+	test_cmp expected actual &&
+	git -C wt2 config --repo new.var1 >actual &&
+	echo new-value >expected &&
+	test_cmp expected actual
+'
+
 test_done
-- 
2.7.0.288.g1d8ad15
Previous: Duy NguyenNext: Max Kirillov
Message 46 of 53 in “Split .git/config in multiple worktree setup”
  1. 0/5 Split .git/config in multiple worktree setupNguyễn Thái Ngọc Duy, Dec 2, 2015
  2. 1/5 dir.c: clean the entire struct in clear_exclude_list()Nguyễn Thái Ngọc Duy, Dec 2, 2015
  3. 2/5 config.c: move worktree-specific variables to .git/worktrees/...Nguyễn Thái Ngọc Duy, Dec 2, 2015
  4. Eric SunshineDec 6, 2015
  5. Duy NguyenDec 6, 2015
  6. 3/5 setup.c: remove special case of core.worktree and core.bareNguyễn Thái Ngọc Duy, Dec 2, 2015
  7. 4/5 worktree: make core.sparseCheckout and core.ignoreStat per-worktreeNguyễn Thái Ngọc Duy, Dec 2, 2015
  8. 5/5 git-worktree.txt: mention about the config file splitNguyễn Thái Ngọc Duy, Dec 2, 2015
  9. Eric SunshineDec 6, 2015
  10. Max KirillovDec 3, 2015
  11. Duy NguyenDec 3, 2015
  12. Junio C HamanoDec 3, 2015
  13. Max KirillovDec 3, 2015
  14. Max KirillovDec 3, 2015
  15. Duy NguyenDec 4, 2015
  16. 0/6 Split .git/config in multiple worktree setupNguyễn Thái Ngọc Duy, Dec 27, 2015
  17. 1/6 Define new repo extension to manage multiple worktree behaviorsNguyễn Thái Ngọc Duy, Dec 27, 2015
  18. 2/6 config.c: move worktree-specific variables to .git/worktrees/...Nguyễn Thái Ngọc Duy, Dec 27, 2015
  19. 3/6 setup.c: remove special case of core.worktree and core.bareNguyễn Thái Ngọc Duy, Dec 27, 2015
  20. 4/6 worktree: make core.sparseCheckout and core.ignoreStat per-worktreeNguyễn Thái Ngọc Duy, Dec 27, 2015
  21. 5/6 config.c: allow to un-share certain config in multi-worktree setupNguyễn Thái Ngọc Duy, Dec 27, 2015
  22. 6/6 worktree: bump worktree version to 1 on "worktree add"Nguyễn Thái Ngọc Duy, Dec 27, 2015
  23. Max KirillovJan 11, 2016
  24. 0/6 Split .git/config in multiple worktree setupNguyễn Thái Ngọc Duy, Jan 26, 2016
  25. 1/6 worktree: new repo extension to manage worktree behaviorsNguyễn Thái Ngọc Duy, Jan 26, 2016
  26. Junio C HamanoJan 27, 2016
  27. Duy NguyenJan 28, 2016
  28. Max KirillovJan 30, 2016
  29. Junio C HamanoJan 31, 2016
  30. Stefan MonnierFeb 1, 2016
  31. Stefan MonnierFeb 1, 2016
  32. Duy NguyenFeb 1, 2016
  33. Junio C HamanoFeb 1, 2016
  34. git worktree (was: [PATCH v3 1/6] worktree: new repo extension to manage worktree behaviors)Stefan Monnier, Feb 4, 2016
  35. Dennis KaarsemakerFeb 1, 2016
  36. Max KirillovJan 30, 2016
  37. 2/6 path.c: new (identical) list for worktree v1Nguyễn Thái Ngọc Duy, Jan 26, 2016
  38. Junio C HamanoJan 27, 2016
  39. Max KirillovJan 30, 2016
  40. 3/6 worktree: share .git/common in v1Nguyễn Thái Ngọc Duy, Jan 26, 2016
  41. 4/6 worktree: new config file hierarchyNguyễn Thái Ngọc Duy, Jan 26, 2016
  42. Junio C HamanoJan 27, 2016
  43. Duy NguyenJan 28, 2016
  44. Junio C HamanoJan 28, 2016
  45. Duy NguyenFeb 1, 2016
  46. 5/6 config: select .git/common/config with --repoNguyễn Thái Ngọc Duy, Jan 26, 2016
  47. Max KirillovJan 30, 2016
  48. Duy NguyenFeb 1, 2016
  49. 6/6 worktree add: switch to worktree version 1Nguyễn Thái Ngọc Duy, Jan 26, 2016
  50. Max KirillovFeb 1, 2016
  51. Duy NguyenFeb 1, 2016
  52. Max KirillovFeb 2, 2016
  53. Junio C HamanoJan 27, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.