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

Re: [RFC PATCH] checkout: Force matching mtime between files

From
Duy Nguyen <pclouds@gmail.com>
Date
Apr 26, 2018, 17:15 UTC
Message-ID
<20180426171540.GA2037@duynguyen.home>
In-Reply-To
<871sf3el01.fsf@evledraar.gmail.com>
On Wed, Apr 25, 2018 at 10:41:18AM +0200, Ævar Arnfjörð Bjarmason wrote:
>  2. Add some config so we can have hook search paths, and ship with a
>     default search path for hooks shipped with git.

I would go for something like this instead of search paths. This allows you to specify a path to any specific hook in hooks.* config group. This is basically "$GIT_DIR/hooks directory in config file" but with lower priority than those in $GIT_DIR/hooks.

Now we can do something like
    git -c hooks.post-checkout=/path/to/some/script clone ...

but of course I would need to fix the FIXME or this hook config is only effective just this one time. (And of course you could put it in ~/.gitconfig)

-- 8< --
diff --git a/builtin/clone.c b/builtin/clone.c
index 7df5932b85..143413ed2d 100644
--- a/builtin/clone.c
+++ b/builtin/clone.c
@@ -1063,6 +1063,11 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
 		strbuf_addf(&branch_top, "refs/remotes/%s/", option_origin);
 	}
 
+	/*
+	 * FIXME: we should keep all custom config settings via
+	 * "git  -c ..." in $GIT_DIR/config.
+	 */
+
 	strbuf_addf(&value, "+%s*:%s*", src_ref_prefix, branch_top.buf);
 	strbuf_addf(&key, "remote.%s.url", option_origin);
 	git_config_set(key.buf, repo);
diff --git a/run-command.c b/run-command.c
index 84899e423f..ee5b6ea329 100644
--- a/run-command.c
+++ b/run-command.c
@@ -7,6 +7,7 @@
 #include "strbuf.h"
 #include "string-list.h"
 #include "quote.h"
+#include "config.h"
 
 void child_process_init(struct child_process *child)
 {
@@ -1256,6 +1257,8 @@ const char *find_hook(const char *name)
 	strbuf_reset(&path);
 	strbuf_git_path(&path, "hooks/%s", name);
 	if (access(path.buf, X_OK) < 0) {
+		const char *cfg_hook;
+		struct strbuf cfg_key = STRBUF_INIT;
 		int err = errno;
 
 #ifdef STRIP_EXTENSION
@@ -1278,9 +1281,14 @@ const char *find_hook(const char *name)
 				       path.buf);
 			}
 		}
-		return NULL;
+
+		strbuf_reset(&path);
+		strbuf_addf(&cfg_key, "hooks.%s", name);
+		if (!git_config_get_pathname(cfg_key.buf, &cfg_hook))
+			strbuf_addstr(&path, cfg_hook);
+		strbuf_release(&cfg_key);
 	}
-	return path.buf;
+	return path.len ? path.buf : NULL;
 }
 
 int run_hook_ve(const char *const *env, const char *name, va_list args)
-- 8< --
--
Duy
Previous: Ævar Arnfjörð BjarmasonNext: Robin H. Johnson
Message 27 of 35 in “checkout: Force matching mtime between files”
  1. checkout: Force matching mtime between filesMichał Górny, Apr 13, 2018
  2. Robin H. JohnsonApr 23, 2018
  3. Junio C HamanoApr 23, 2018
  4. Robin H. JohnsonApr 25, 2018
  5. Junio C HamanoApr 25, 2018
  6. Marc BranchaudApr 25, 2018
  7. Robin H. JohnsonApr 25, 2018
  8. Junio C HamanoApr 26, 2018
  9. Marc BranchaudApr 26, 2018
  10. Michał GórnyApr 26, 2018
  11. Duy NguyenApr 28, 2018
  12. Michał GórnyApr 28, 2018
  13. Duy NguyenApr 26, 2018
  14. Robin H. JohnsonApr 26, 2018
  15. Duy NguyenApr 26, 2018
  16. Junio C HamanoApr 29, 2018
  17. Duy NguyenApr 30, 2018
  18. Duy NguyenApr 27, 2018
  19. Elijah NewrenApr 27, 2018
  20. Duy NguyenApr 28, 2018
  21. Junio C HamanoApr 29, 2018
  22. Marc BranchaudApr 27, 2018
  23. Duy NguyenApr 28, 2018
  24. Michał GórnyApr 27, 2018
  25. Ævar Arnfjörð BjarmasonApr 27, 2018
  26. Ævar Arnfjörð BjarmasonApr 25, 2018
  27. Duy NguyenApr 26, 2018
  28. Robin H. JohnsonApr 26, 2018
  29. SZEDER GáborApr 26, 2018
  30. Duy NguyenApr 26, 2018
  31. Marc BranchaudApr 24, 2018
  32. Robin H. JohnsonApr 25, 2018
  33. Michał GórnyApr 25, 2018
  34. Jeff KingMay 5, 2018
  35. Junio C HamanoMay 6, 2018

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.