Thread (12 messages) 12 messages, 4 authors, 2019-06-06

Re: [PATCH v2] config: learn the "onbranch:" includeIf condition

From: Johannes Schindelin <hidden>
Date: 2019-06-05 08:02:51

Hi Denton,

On Fri, 31 May 2019, Johannes Schindelin wrote:
On Fri, 31 May 2019, Denton Liu wrote:
quoted
Currently, if a user wishes to have individual settings per branch,
they are required to manually keep track of the settings in their head
and manually set the options on the command-line or change the config
at each branch.

Teach config the "onbranch:" includeIf condition so that it can
conditionally include configuration files if the branch that is
checked out in the current worktree matches the pattern given.
This looks good to me.
... actually...
quoted
diff --git a/t/t1305-config-include.sh b/t/t1305-config-include.sh
index 579a86b7f8..05c7def1f2 100755
--- a/t/t1305-config-include.sh
+++ b/t/t1305-config-include.sh
@@ -309,6 +309,39 @@ test_expect_success SYMLINKS 'conditional include, gitdir matching symlink, icas
 	)
 '

+test_expect_success 'conditional include, onbranch' '
+	(
+		cd bar &&
This `bar` is a side effect of an earlier test case. To be precise, of
this test case:

test_expect_success SYMLINKS 'conditional include, gitdir matching symlink' '
	ln -s foo bar &&
	(
		cd bar &&
		echo "[includeIf \"gitdir:bar/\"]path=bar7" >>.git/config
&&
		echo "[test]seven=7" >.git/bar7 &&
		echo 7 >expect &&
		git config test.seven >actual &&
		test_cmp expect actual
	)
'

As you can see, this test case is marked with the `SYMLINKS` prerequisite,
and hence can be skipped.

I got a crazy idea, though: how about `cd foo` instead of `cd bar`? It
should still work, as `bar` is just a symbolic link (unless that test case
has been skipped, in which case `bar` does not even exist) to `foo`.

And while this still relies on a side effect of an earlier test case
('conditional include, both unanchored', to be precise), at least that
test case cannot be skipped because of a missing prerequisite.

The same `s/cd bar/cd foo` applies to the second test case in this patch,
too, of course.

Thanks,
Dscho
quoted
+		echo "[includeIf \"onbranch:foo-branch\"]path=bar9" >>.git/config &&
+		echo "[test]nine=9" >.git/bar9 &&
+		git checkout -b master &&
+		test_must_fail git config test.nine &&
+		git checkout -b foo-branch &&
+		echo 9 >expect &&
+		git config test.nine >actual &&
+		test_cmp expect actual
+	)
+'
+
+test_expect_success 'conditional include, onbranch, wildcard' '
+	(
+		cd bar &&
+		echo "[includeIf \"onbranch:?oo-*/**\"]path=bar10" >>.git/config &&
+		echo "[test]ten=10" >.git/bar10 &&
+		git checkout -b not-foo-branch/a &&
+		test_must_fail git config test.ten &&
+
+		echo 10 >expect &&
+		git checkout -b foo-branch/a/b/c &&
+		git config test.ten >actual &&
+		test_cmp expect actual &&
+
+		git checkout -b moo-bar/a &&
+		git config test.ten >actual &&
+		test_cmp expect actual
+	)
+'
+
 test_expect_success 'include cycles are detected' '
 	cat >.gitconfig <<-\EOF &&
 	[test]value = gitconfig
--
2.22.0.rc1.169.g49223abbf8
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help