diff mbox series

[2/3] commit-graph tests: fix another graph_git_two_modes() helper

Message ID patch-2.3-d6934031882-20211014T233343Z-avarab@gmail.com (mailing list archive)
State New, archived
Headers show
Series commit-graph: make "verify" work with replace refs | expand

Commit Message

Ævar Arnfjörð Bjarmason Oct. 14, 2021, 11:37 p.m. UTC
In 135a7123755 (commit-graph: add --split option to builtin,
2019-06-18) this function was copy/pasted to the split commit-graph
tests, as in the preceding commit we need to fix this to use
&&-chaining, so it won't be hiding errors.

Unlike its sister function in "t5318-commit-graph.sh", which we got
lucky with, this one was hiding a real test failure. A tests added in
c523035cbd8 (commit-graph: allow cross-alternate chains, 2019-06-18)
has never worked as intended. Unlike most other graph_git_behavior
uses in this file it clones the repository into a sub-directory, so
we'll need to refer to "commits/6" as "origin/commits/6".

It's not easy to simply move the "graph_git_behavior" to the test
above it, since it itself spawns a "test_expect_success". Let's
instead add support to "graph_git_behavior()" and
"graph_git_two_modes()" to pass a "-C" argument to git.

We also need to add a "test -d fork" here, because otherwise we'll
fail on e.g.:

    GIT_SKIP_TESTS=t5324.13 ./t5324-split-commit-graph.sh

Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
---
 t/t5324-split-commit-graph.sh | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

Comments

Junio C Hamano Oct. 15, 2021, 4:15 p.m. UTC | #1
Ævar Arnfjörð Bjarmason  <avarab@gmail.com> writes:

> In 135a7123755 (commit-graph: add --split option to builtin,
> 2019-06-18) this function was copy/pasted to the split commit-graph
> tests, as in the preceding commit we need to fix this to use
> &&-chaining, so it won't be hiding errors.
>
> Unlike its sister function in "t5318-commit-graph.sh", which we got
> lucky with, this one was hiding a real test failure. A tests added in
> c523035cbd8 (commit-graph: allow cross-alternate chains, 2019-06-18)
> has never worked as intended. Unlike most other graph_git_behavior
> uses in this file it clones the repository into a sub-directory, so
> we'll need to refer to "commits/6" as "origin/commits/6".

Interesting.  The original created "fork" prepared the alternates
structure in the preceding test, but tested the "behavour" of the
commands outside the "fork" it just prepared?

>  graph_git_two_modes() {
> -	git -c core.commitGraph=true $1 >output
> -	git -c core.commitGraph=false $1 >expect
> +	git ${2:+ -C "$2"} -c core.commitGraph=true $1 >output &&
> +	git ${2:+ -C "$2"} -c core.commitGraph=false $1 >expect &&

OK, it was a bit curious to see :+ (instead of just +), but the
caller unconditionally passes "$DIR" (with double quotes), so it is
understandable.  Much more concise than having the caller to repeat
${4+"$4"} where it says "$DIR".

>  	test_cmp expect output
>  }
>  
> @@ -64,12 +64,13 @@ graph_git_behavior() {
>  	MSG=$1
>  	BRANCH=$2
>  	COMPARE=$3
> +	DIR=$4
>  	test_expect_success "check normal git operations: $MSG" '
> -		graph_git_two_modes "log --oneline $BRANCH" &&
> -		graph_git_two_modes "log --topo-order $BRANCH" &&
> -		graph_git_two_modes "log --graph $COMPARE..$BRANCH" &&
> -		graph_git_two_modes "branch -vv" &&
> -		graph_git_two_modes "merge-base -a $BRANCH $COMPARE"
> +		graph_git_two_modes "log --oneline $BRANCH" "$DIR" &&
> +		graph_git_two_modes "log --topo-order $BRANCH" "$DIR" &&
> +		graph_git_two_modes "log --graph $COMPARE..$BRANCH" "$DIR" &&
> +		graph_git_two_modes "branch -vv" "$DIR" &&
> +		graph_git_two_modes "merge-base -a $BRANCH $COMPARE" "$DIR"
>  	'
>  }
>  
> @@ -187,7 +188,10 @@ test_expect_success 'create fork and chain across alternate' '
>  	)
>  '
>  
> -graph_git_behavior 'alternate: commit 13 vs 6' commits/13 commits/6
> +if test -d fork
> +then
> +	graph_git_behavior 'alternate: commit 13 vs 6' commits/13 origin/commits/6 "fork"
> +fi
>  
>  test_expect_success 'test merge stragety constants' '
>  	git clone . merge-2 &&
diff mbox series

Patch

diff --git a/t/t5324-split-commit-graph.sh b/t/t5324-split-commit-graph.sh
index 587226ed103..847b8097109 100755
--- a/t/t5324-split-commit-graph.sh
+++ b/t/t5324-split-commit-graph.sh
@@ -55,8 +55,8 @@  test_expect_success 'create commits and write commit-graph' '
 '
 
 graph_git_two_modes() {
-	git -c core.commitGraph=true $1 >output
-	git -c core.commitGraph=false $1 >expect
+	git ${2:+ -C "$2"} -c core.commitGraph=true $1 >output &&
+	git ${2:+ -C "$2"} -c core.commitGraph=false $1 >expect &&
 	test_cmp expect output
 }
 
@@ -64,12 +64,13 @@  graph_git_behavior() {
 	MSG=$1
 	BRANCH=$2
 	COMPARE=$3
+	DIR=$4
 	test_expect_success "check normal git operations: $MSG" '
-		graph_git_two_modes "log --oneline $BRANCH" &&
-		graph_git_two_modes "log --topo-order $BRANCH" &&
-		graph_git_two_modes "log --graph $COMPARE..$BRANCH" &&
-		graph_git_two_modes "branch -vv" &&
-		graph_git_two_modes "merge-base -a $BRANCH $COMPARE"
+		graph_git_two_modes "log --oneline $BRANCH" "$DIR" &&
+		graph_git_two_modes "log --topo-order $BRANCH" "$DIR" &&
+		graph_git_two_modes "log --graph $COMPARE..$BRANCH" "$DIR" &&
+		graph_git_two_modes "branch -vv" "$DIR" &&
+		graph_git_two_modes "merge-base -a $BRANCH $COMPARE" "$DIR"
 	'
 }
 
@@ -187,7 +188,10 @@  test_expect_success 'create fork and chain across alternate' '
 	)
 '
 
-graph_git_behavior 'alternate: commit 13 vs 6' commits/13 commits/6
+if test -d fork
+then
+	graph_git_behavior 'alternate: commit 13 vs 6' commits/13 origin/commits/6 "fork"
+fi
 
 test_expect_success 'test merge stragety constants' '
 	git clone . merge-2 &&