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

[PATCH 03/16] patch-id: use RUN_SETUP_GENTLY

From
Jeff King <peff@peff.net>
Date
Sep 13, 2016, 03:23 UTC
Message-ID
<20160913032321.cv6732hyzv3d4z57@sigill.intra.peff.net>
In-Reply-To
<20160913032242.coyuhyhn6uklewuk@sigill.intra.peff.net>

Patch-id does not require a repository because it is just processing the incoming diff on stdin, but it may look at git config for keys like patchid.stable.

Even though we do not setup_git_directory(), this works from the top-level of a repository because we blindly look at ".git/config" in this case. But as the included test demonstrates, it does not work from a subdirectory.

We can fix it by using RUN_SETUP_GENTLY. We do not take any filenames from the user on the command line, so there's no need to adjust them via prefix_filename().

Signed-off-by: Jeff King <peff@peff.net>
---
 git.c               |  2 +-
 t/t4204-patch-id.sh | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/git.c b/git.c
index 1c61151..ab5c99c 100644
--- a/git.c
+++ b/git.c
@@ -444,7 +444,7 @@ static struct cmd_struct commands[] = {
 	{ "pack-objects", cmd_pack_objects, RUN_SETUP },
 	{ "pack-redundant", cmd_pack_redundant, RUN_SETUP },
 	{ "pack-refs", cmd_pack_refs, RUN_SETUP },
-	{ "patch-id", cmd_patch_id },
+	{ "patch-id", cmd_patch_id, RUN_SETUP_GENTLY },
 	{ "pickaxe", cmd_blame, RUN_SETUP },
 	{ "prune", cmd_prune, RUN_SETUP },
 	{ "prune-packed", cmd_prune_packed, RUN_SETUP },
diff --git a/t/t4204-patch-id.sh b/t/t4204-patch-id.sh
index 84a8096..0288c17 100755
--- a/t/t4204-patch-id.sh
+++ b/t/t4204-patch-id.sh
@@ -143,6 +143,20 @@ test_expect_success 'patch-id supports git-format-patch MIME output' '
 	test_cmp patch-id_master patch-id_same
 '
 
+test_expect_success 'patch-id respects config from subdir' '
+	test_config patchid.stable true &&
+	mkdir subdir &&
+
+	# copy these because test_patch_id() looks for them in
+	# the current directory
+	cp bar-then-foo foo-then-bar subdir &&
+
+	(
+		cd subdir &&
+		test_patch_id irrelevant patchid.stable=true
+	)
+'
+
 cat >nonl <<\EOF
 diff --git i/a w/a
 index e69de29..2e65efe 100644
-- 
2.10.0.230.g6f8d04b
Previous: Jeff KingNext: Jeff King
Message 10 of 23 in “fix config-reading in non-repos”
  1. 0/16 fix config-reading in non-reposJeff King, Sep 13, 2016
  2. 01/16 t1007: factor out repeated setupJeff King, Sep 13, 2016
  3. Stefan BellerSep 13, 2016
  4. 02/16 hash-object: always try to set up the git repositoryJeff King, Sep 13, 2016
  5. 06/16 diff: always try to set up the repositoryJeff King, Sep 13, 2016
  6. Stefan BellerSep 13, 2016
  7. Jeff KingSep 13, 2016
  8. 04/16 diff: skip implicit no-index check when given --no-indexJeff King, Sep 13, 2016
  9. 07/16 pager: remove obsolete commentJeff King, Sep 13, 2016
  10. 03/16 patch-id: use RUN_SETUP_GENTLYJeff King, Sep 13, 2016
  11. 05/16 diff: handle --no-index prefixes consistentlyJeff King, Sep 13, 2016
  12. 08/16 pager: stop loading git_default_config()Jeff King, Sep 13, 2016
  13. 09/16 pager: make pager_program a file-local staticJeff King, Sep 13, 2016
  14. 10/16 pager: use callbacks instead of configsetJeff King, Sep 13, 2016
  15. 11/16 pager: handle early configJeff King, Sep 13, 2016
  16. 12/16 t1302: use "git -C"Jeff King, Sep 13, 2016
  17. 13/16 test-config: setup git directoryJeff King, Sep 13, 2016
  18. 14/16 config: only read .git/config from configured reposJeff King, Sep 13, 2016
  19. 15/16 init: expand comments explaining config trickeryJeff King, Sep 13, 2016
  20. 16/16 init: reset cached config when entering new repoJeff King, Sep 13, 2016
  21. Stefan BellerSep 13, 2016
  22. Dennis KaarsemakerSep 14, 2016
  23. Jeff KingSep 14, 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.