Re: Git 2.45.1 - What is the right way to clone with global hooks disabled?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Brooke,

On Wed, 15 May 2024, Brooke Kuhlmann wrote:

> With the release of Git 2.45.1, I can no longer do this when cloning
> trusted repositories (my own) for build and deployment purposes:
>
> git clone --config core.hooksPath=/dev/null https://github.com/bkuhlmann/infusible

Ah, that's a clever trick. The clone protections try to prevent overriding
the `core.hooksPath` with a valid (but not intended by the user) path.
What you are doing is to specifically turn hooks off *1*.

I plan on sending out a patch series later either today or tomorrow to
address a couple of regressions introduced by v2.45.1, and this patch
would address your specific scenario:

-- snip --
diff --git a/config.c b/config.c
index 85b37f2ee09..380f7777a6e 100644
--- a/config.c
+++ b/config.c
@@ -1527,6 +1527,7 @@ static int git_default_core_config(const char *var, const char *value, void *cb)

 	if (!strcmp(var, "core.hookspath")) {
 		if (current_config_scope() == CONFIG_SCOPE_LOCAL &&
+		    (!value || (*value && strcmp(value, "/dev/null"))) &&
 		    git_env_bool("GIT_CLONE_PROTECTION_ACTIVE", 0))
 			die(_("active `core.hooksPath` found in the local "
 			      "repository config:\n\t%s\nFor security "
diff --git a/t/t1350-config-hooks-path.sh b/t/t1350-config-hooks-path.sh
index f6dc83e2aab..1eae346a6e3 100755
--- a/t/t1350-config-hooks-path.sh
+++ b/t/t1350-config-hooks-path.sh
@@ -41,4 +41,8 @@ test_expect_success 'git rev-parse --git-path hooks' '
 	test .git/custom-hooks/abc = "$(cat actual)"
 '

+test_expect_success 'core.hooksPath=/dev/null' '
+	git clone -c core.hooksPath=/dev/null . no-templates
+'
+
 test_done

> I have automation in place where I want my global Git Hooks to be
> ignored when cloning like this. The solution is to do this:
>
> GIT_CLONE_PROTECTION_ACTIVE=false git clone --config core.hooksPath=/dev/null https://github.com/bkuhlmann/infusible
>
> ...but is there a better, more secure, way to clone a repository while
> ignoring any global Git Hooks from firing without a lot of effort?

That is certainly a good work-around for now. Thank you for the report! I
hope that we can address your use case in v2.45.2, hopefully soon.

Thanks,
Johannes





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux