[v2,3/4] bug: denyCurrentBranch and unborn branch with ref namespace
diff mbox series

Message ID b3e573d44a99a828e710f06b723942107189afeb.1582410908.git.gitgitgadget@gmail.com
State New
Headers show
Series
  • receive.denyCurrentBranch: respect all worktrees
Related show

Commit Message

Garima Singh via GitGitGadget Feb. 22, 2020, 10:35 p.m. UTC
From: Hariom Verma <hariom18599@gmail.com>

git supports an interesting feature 'Git namespaces' that allows
dividing the refs of a single repository into multiple namespaces, each
of which has its own branches, tags, and HEAD. But unfortunately, there
exists a bug in `denyCurrentBranch` which allows pushing into a non-bare
repository using a ref namespace even if it does not have any commits

Here is a nice and short demonstration of that bug.

Helped-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Hariom Verma <hariom18599@gmail.com>
---
 t/t5509-fetch-push-namespaces.sh | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Junio C Hamano Feb. 23, 2020, 6:10 a.m. UTC | #1
"Hariom Verma via GitGitGadget" <gitgitgadget@gmail.com> writes:

> +test_expect_failure 'denyCurrentBranch and unborn branch with ref namespace' '

Please do not chdir around in the test script.  The next person who
adds new test after this test will be surprised that his/her test
does not start at the top-level of the test/trash directory, but in
the "original" subdirectory.

And no, adding "&& cd .." at the end of this &&-cascade is *not* a
fix---when any of the steps chained with && fails, such a "we have
moved the process to a wrong place, so let's move back with 'cd ..'"
will not get executed.

> +	cd original &&
> +	git init unborn &&
> +	git remote add unborn-namespaced "ext::git --namespace=namespace %s unborn" &&
> +	test_must_fail git push unborn-namespaced HEAD:master &&
> +	test_config -C unborn receive.denyCurrentBranch updateInstead &&
> +	git push unborn-namespaced HEAD:master
> +'

What is often done to fix is to execute what you need to run in a
subshell, e.g.

	test_expect_success 'demonstration' '
		(
			cd original &&
			git init unborn &&
			...
			test_must_fail git push ... &&
			git -C unborn config ... &&
			git push ...
		)
	'

The use of "git config" instead of "test_config" in the above
illustration is deliberate---the latter does not work and should not
be used inside a subshell.

> +
>  test_done

Patch
diff mbox series

diff --git a/t/t5509-fetch-push-namespaces.sh b/t/t5509-fetch-push-namespaces.sh
index e3975bd21de..c89483fdba2 100755
--- a/t/t5509-fetch-push-namespaces.sh
+++ b/t/t5509-fetch-push-namespaces.sh
@@ -152,4 +152,13 @@  test_expect_success 'clone chooses correct HEAD (v2)' '
 	test_cmp expect actual
 '
 
+test_expect_failure 'denyCurrentBranch and unborn branch with ref namespace' '
+	cd original &&
+	git init unborn &&
+	git remote add unborn-namespaced "ext::git --namespace=namespace %s unborn" &&
+	test_must_fail git push unborn-namespaced HEAD:master &&
+	test_config -C unborn receive.denyCurrentBranch updateInstead &&
+	git push unborn-namespaced HEAD:master
+'
+
 test_done