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

[PATCH v4 0/6] config: allow user to know scope of config options

From
MGMatthew Rogers via GitGitGadget <gitgitgadget@gmail.com>
Date
Jan 24, 2020, 00:21 UTC
Message-ID
<pull.478.v4.git.1579825267.gitgitgadget@gmail.com>
In-Reply-To
<pull.478.v3.git.1579275102.gitgitgadget@gmail.com>

This was originally a pull request to the git-for-windows repository [https://github.com/git-for-windows/git/pull/2399]. It adds a new option --show-scope which would allow a user to see what scope a given configuration value has (sytem, local, global, etc.).

changes since v3:
 * Cleaned up t1300
 * Expanded test coverage for t1300 to not rely as much on !MINGW by using a
   simpler filename for most tests
 * config_scope_name is now exposed in config.h
 * cleaned up commit messages for clarity/content (again)
Matthew Rogers (6):
  config: fix typo in variable name
  t1300: fix over-indented HERE-DOCs
  t1300: create custom config file without special characters
  config: split repo scope to local and worktree
  config: clarify meaning of command line scoping
  config: add '--show-scope' to print the scope of a config value
 Documentation/git-config.txt |  15 ++-
 builtin/config.c             |  46 +++++--
 config.c                     |  35 ++++-
 config.h                     |  20 +--
 remote.c                     |   3 +-
 submodule-config.c           |   4 +-
 t/helper/test-config.c       |  17 +--
 t/t1300-config.sh            | 240 ++++++++++++++++++++++-------------
 t/t1308-config-set.sh        |   4 +-
 upload-pack.c                |   3 +-
 10 files changed, 248 insertions(+), 139 deletions(-)
base-commit: 232378479ee6c66206d47a9be175e3a39682aea6
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-478%2FROGERSM94%2Fadd-config-flags-v4
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-478/ROGERSM94/add-config-flags-v4
Pull-Request: https://github.com/gitgitgadget/git/pull/478
Range-diff vs v3:
 1:  f5a81a4d25 = 1:  f5a81a4d25 config: fix typo in variable name
 -:  ---------- > 2:  1b42f85399 t1300: fix over-indented HERE-DOCs
 -:  ---------- > 3:  9d19794dfd t1300: create custom config file without special characters
 2:  f06f9291b7 ! 4:  9f160e281a config: refine config scope enum
     @@ -1,6 +1,6 @@
      Author: Matthew Rogers <mattr94@gmail.com>
      
     -    config: refine config scope enum
     +    config: split repo scope to local and worktree
      
          Previously when iterating through git config variables, worktree config
          and local config were both considered "CONFIG_SCOPE_REPO".  This was
     @@ -93,14 +93,14 @@
       --- a/t/t1308-config-set.sh
       +++ b/t/t1308-config-set.sh
      @@
     + 	value=from-repo
     + 	origin=file
     + 	name=.git/config
     +-	scope=repo
     ++	scope=local
     + 
     + 	key=foo.bar
       	value=from-cmdline
     - 	origin=command line
     - 	name=
     --	scope=cmdline
     -+	scope=command
     - 	EOF
     - 	GIT_CONFIG_PARAMETERS=$cmdline_config test-tool config iterate >actual &&
     - 	test_cmp expect actual
      
       diff --git a/upload-pack.c b/upload-pack.c
       --- a/upload-pack.c
 3:  97b8a7641d ! 5:  7f00f8559d config: clarify meaning of command line scoping
     @@ -53,3 +53,16 @@
       	default:
       		return "unknown";
       	}
     +
     + diff --git a/t/t1308-config-set.sh b/t/t1308-config-set.sh
     + --- a/t/t1308-config-set.sh
     + +++ b/t/t1308-config-set.sh
     +@@
     + 	value=from-cmdline
     + 	origin=command line
     + 	name=
     +-	scope=cmdline
     ++	scope=command
     + 	EOF
     + 	GIT_CONFIG_PARAMETERS=$cmdline_config test-tool config iterate >actual &&
     + 	test_cmp expect actual
 4:  61ff3c64b5 ! 6:  5549db7e39 config: add '--show-scope' to print the scope of a config value
     @@ -76,26 +76,6 @@
       	strbuf_addch(buf, term);
       }
       
     -+static const char *scope_to_string(enum config_scope scope)
     -+{
     -+	switch (scope) {
     -+	case CONFIG_SCOPE_LOCAL:
     -+		return "local";
     -+	case CONFIG_SCOPE_GLOBAL:
     -+		return "global";
     -+	case CONFIG_SCOPE_SYSTEM:
     -+		return "system";
     -+	case CONFIG_SCOPE_WORKTREE:
     -+		return "worktree";
     -+	case CONFIG_SCOPE_COMMAND:
     -+		return "command";
     -+	case CONFIG_SCOPE_SUBMODULE:
     -+		return "submodule";
     -+	default:
     -+		return "unknown";
     -+	}
     -+}
     -+
      +static void show_config_scope(struct strbuf *buf)
      +{
      +	const char term = end_nul ? '\0' : '\t';
     @@ -211,6 +191,33 @@
       	/*
       	 * If we have a specific filename, use it. Otherwise, follow the
       	 * regular lookup sequence.
     +@@
     + 	}
     + }
     + 
     ++const char *scope_to_string(enum config_scope scope)
     ++{
     ++	switch (scope) {
     ++	case CONFIG_SCOPE_SYSTEM:
     ++		return "system";
     ++	case CONFIG_SCOPE_GLOBAL:
     ++		return "global";
     ++	case CONFIG_SCOPE_LOCAL:
     ++		return "local";
     ++	case CONFIG_SCOPE_WORKTREE:
     ++		return "worktree";
     ++	case CONFIG_SCOPE_COMMAND:
     ++		return "command";
     ++	case CONFIG_SCOPE_SUBMODULE:
     ++		return "submodule";
     ++	default:
     ++		return "unknown";
     ++	}
     ++}
     ++
     + const char *current_config_name(void)
     + {
     + 	const char *name;
      
       diff --git a/config.h b/config.h
       --- a/config.h
     @@ -228,6 +235,7 @@
      +	CONFIG_SCOPE_COMMAND,
      +	CONFIG_SCOPE_SUBMODULE,
      +};
     ++const char *scope_to_string(enum config_scope scope);
      +
       struct git_config_source {
       	unsigned int use_stdin:1;
     @@ -273,14 +281,38 @@
       --- a/t/helper/test-config.c
       +++ b/t/helper/test-config.c
      @@
     - 		return "repo";
     - 	case CONFIG_SCOPE_WORKTREE:
     - 		return "worktree";
     -+	case CONFIG_SCOPE_SUBMODULE:
     -+		return "submodule";
     - 	case CONFIG_SCOPE_COMMAND:
     - 		return "command";
     - 	default:
     +  *
     +  */
     + 
     +-static const char *scope_name(enum config_scope scope)
     +-{
     +-	switch (scope) {
     +-	case CONFIG_SCOPE_SYSTEM:
     +-		return "system";
     +-	case CONFIG_SCOPE_GLOBAL:
     +-		return "global";
     +-	case CONFIG_SCOPE_LOCAL:
     +-		return "repo";
     +-	case CONFIG_SCOPE_WORKTREE:
     +-		return "worktree";
     +-	case CONFIG_SCOPE_COMMAND:
     +-		return "command";
     +-	default:
     +-		return "unknown";
     +-	}
     +-}
     + static int iterate_cb(const char *var, const char *value, void *data)
     + {
     + 	static int nr;
     +@@
     + 	printf("value=%s\n", value ? value : "(null)");
     + 	printf("origin=%s\n", current_config_origin_type());
     + 	printf("name=%s\n", current_config_name());
     +-	printf("scope=%s\n", scope_name(current_config_scope()));
     ++	printf("scope=%s\n", scope_to_string(current_config_scope()));
     + 
     + 	return 0;
     + }
      
       diff --git a/t/t1300-config.sh b/t/t1300-config.sh
       --- a/t/t1300-config.sh
     @@ -313,6 +345,7 @@
      +	git config --blob=$blob --show-scope --list >output &&
      +	test_cmp expect output
      +'
     ++
      +test_expect_success '--show-scope with --local' '
      +	cat >expect <<-\EOF &&
      +		local	user.local=true
-- 
gitgitgadget
Previous: Junio C HamanoNext: Matthew Rogers via GitGitGadget
Message 40 of 98 in “config: allow user to know scope of config options”
  1. 0/1 config: allow user to know scope of config optionsMatthew Rogers via GitGitGadget, Dec 18, 2019
  2. 1/1 config: allow user to know scope of config optionsMatthew Rogers via GitGitGadget, Dec 18, 2019
  3. Junio C HamanoDec 18, 2019
  4. Jeff KingDec 19, 2019
  5. Junio C HamanoDec 19, 2019
  6. Philip OakleyDec 18, 2019
  7. mattr94@gmail.comDec 19, 2019
  8. Junio C HamanoDec 19, 2019
  9. Matt RogersDec 20, 2019
  10. Junio C HamanoDec 21, 2019
  11. Matt RogersDec 21, 2019
  12. Junio C HamanoDec 21, 2019
  13. 0/4 config: allow user to know scope of config optionsMatthew Rogers via GitGitGadget, Jan 9, 2020
  14. 1/4 config: fix typo in variable nameMatthew Rogers via GitGitGadget, Jan 9, 2020
  15. Junio C HamanoJan 9, 2020
  16. Matt RogersJan 9, 2020
  17. Jeff KingJan 10, 2020
  18. 2/4 config: fix config scope enumMatthew Rogers via GitGitGadget, Jan 9, 2020
  19. Junio C HamanoJan 9, 2020
  20. Matt RogersJan 9, 2020
  21. 3/4 config: clarify meaning of command line scopingMatthew Rogers via GitGitGadget, Jan 9, 2020
  22. Junio C HamanoJan 9, 2020
  23. Matt RogersJan 9, 2020
  24. 4/4 config: add '--show-scope' to print the scope of a config valueMatthew Rogers via GitGitGadget, Jan 9, 2020
  25. Junio C HamanoJan 9, 2020
  26. Matt RogersJan 9, 2020
  27. 0/4 config: allow user to know scope of config optionsMatthew Rogers via GitGitGadget, Jan 17, 2020
  28. 1/4 config: fix typo in variable nameMatthew Rogers via GitGitGadget, Jan 17, 2020
  29. 3/4 config: clarify meaning of command line scopingMatthew Rogers via GitGitGadget, Jan 17, 2020
  30. Junio C HamanoJan 17, 2020
  31. Matt RogersJan 18, 2020
  32. 4/4 config: add '--show-scope' to print the scope of a config valueMatthew Rogers via GitGitGadget, Jan 17, 2020
  33. Junio C HamanoJan 17, 2020
  34. Bert WesargJan 17, 2020
  35. Matt RogersJan 18, 2020
  36. 2/4 config: refine config scope enumMatthew Rogers via GitGitGadget, Jan 17, 2020
  37. Junio C HamanoJan 17, 2020
  38. Matt RogersJan 18, 2020
  39. Junio C HamanoJan 18, 2020
  40. 0/6 config: allow user to know scope of config optionsMatthew Rogers via GitGitGadget, Jan 24, 2020
  41. 1/6 config: fix typo in variable nameMatthew Rogers via GitGitGadget, Jan 24, 2020
  42. 2/6 t1300: fix over-indented HERE-DOCsMatthew Rogers via GitGitGadget, Jan 24, 2020
  43. Junio C HamanoJan 24, 2020
  44. 3/6 t1300: create custom config file without special charactersMatthew Rogers via GitGitGadget, Jan 24, 2020
  45. Junio C HamanoJan 24, 2020
  46. 5/6 config: clarify meaning of command line scopingMatthew Rogers via GitGitGadget, Jan 24, 2020
  47. 4/6 config: split repo scope to local and worktreeMatthew Rogers via GitGitGadget, Jan 24, 2020
  48. Junio C HamanoJan 24, 2020
  49. Junio C HamanoJan 24, 2020
  50. 6/6 config: add '--show-scope' to print the scope of a config valueMatthew Rogers via GitGitGadget, Jan 24, 2020
  51. Junio C HamanoJan 24, 2020
  52. Junio C HamanoJan 24, 2020
  53. Matt RogersJan 24, 2020
  54. Junio C HamanoJan 25, 2020
  55. Junio C HamanoJan 24, 2020
  56. 0/6 config: allow user to know scope of config optionsMatthew Rogers via GitGitGadget, Jan 25, 2020
  57. 1/6 config: fix typo in variable nameMatthew Rogers via GitGitGadget, Jan 25, 2020
  58. 3/6 t1300: create custom config file without special charactersMatthew Rogers via GitGitGadget, Jan 25, 2020
  59. 2/6 t1300: fix over-indented HERE-DOCsMatthew Rogers via GitGitGadget, Jan 25, 2020
  60. 5/6 config: clarify meaning of command line scopingMatthew Rogers via GitGitGadget, Jan 25, 2020
  61. 4/6 config: split repo scope to local and worktreeMatthew Rogers via GitGitGadget, Jan 25, 2020
  62. Junio C HamanoJan 27, 2020
  63. 6/6 config: add '--show-scope' to print the scope of a config valueMatthew Rogers via GitGitGadget, Jan 25, 2020
  64. Junio C HamanoJan 27, 2020
  65. Matt RogersJan 28, 2020
  66. 0/6 config: allow user to know scope of config optionsMatthew Rogers via GitGitGadget, Jan 29, 2020
  67. 1/6 config: fix typo in variable nameMatthew Rogers via GitGitGadget, Jan 29, 2020
  68. 3/6 t1300: create custom config file without special charactersMatthew Rogers via GitGitGadget, Jan 29, 2020
  69. 2/6 t1300: fix over-indented HERE-DOCsMatthew Rogers via GitGitGadget, Jan 29, 2020
  70. 5/6 config: clarify meaning of command line scopingMatthew Rogers via GitGitGadget, Jan 29, 2020
  71. 4/6 config: split repo scope to local and worktreeMatthew Rogers via GitGitGadget, Jan 29, 2020
  72. 6/6 config: add '--show-scope' to print the scope of a config valueMatthew Rogers via GitGitGadget, Jan 29, 2020
  73. Bert WesargJan 29, 2020
  74. Matt RogersJan 29, 2020
  75. Junio C HamanoFeb 5, 2020
  76. Junio C HamanoJan 29, 2020
  77. 00/10 config: allow user to know scope of config optionsMatthew Rogers via GitGitGadget, Feb 10, 2020
  78. 01/10 config: fix typo in variable nameMatthew Rogers via GitGitGadget, Feb 10, 2020
  79. 03/10 t1300: create custom config file without special charactersMatthew Rogers via GitGitGadget, Feb 10, 2020
  80. 05/10 config: split repo scope to local and worktreeMatthew Rogers via GitGitGadget, Feb 10, 2020
  81. Junio C HamanoFeb 10, 2020
  82. 02/10 t1300: fix over-indented HERE-DOCsMatthew Rogers via GitGitGadget, Feb 10, 2020
  83. 07/10 config: preserve scope in do_git_config_sequenceMatthew Rogers via GitGitGadget, Feb 10, 2020
  84. Junio C HamanoFeb 10, 2020
  85. 06/10 config: clarify meaning of command line scopingMatthew Rogers via GitGitGadget, Feb 10, 2020
  86. Junio C HamanoFeb 10, 2020
  87. 10/10 config: add '--show-scope' to print the scope of a config valueMatthew Rogers via GitGitGadget, Feb 10, 2020
  88. 09/10 submodule-config: add subomdule config scopeMatthew Rogers via GitGitGadget, Feb 10, 2020
  89. Junio C HamanoFeb 10, 2020
  90. 08/10 config: teach git_config_source to remember its scopeMatthew Rogers via GitGitGadget, Feb 10, 2020
  91. Junio C HamanoFeb 10, 2020
  92. 04/10 config: make scope_name non-static and rename itMatthew Rogers via GitGitGadget, Feb 10, 2020
  93. Junio C HamanoFeb 10, 2020
  94. Junio C HamanoFeb 10, 2020
  95. Matt RogersFeb 11, 2020
  96. Emily ShafferFeb 11, 2020
  97. Junio C HamanoFeb 11, 2020
  98. Matt RogersFeb 11, 2020

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.