diff mbox series

[v2,1/4] t7400-submodule-basic: modernize inspect() helper

Message ID 20210616004508.87186-2-emilyshaffer@google.com (mailing list archive)
State New, archived
Headers show
Series cache parent project's gitdir in submodules | expand

Commit Message

Emily Shaffer June 16, 2021, 12:45 a.m. UTC
Since the inspect() helper in the submodule-basic test suite was
written, 'git -C <dir>' was added. By using -C, we no longer need a
reference to the base directory for the test. This simplifies callsites,
and will make the addition of other arguments in later patches more
readable.

Signed-off-by: Emily Shaffer <emilyshaffer@google.com>
---
 t/t7400-submodule-basic.sh | 37 +++++++++++++++----------------------
 1 file changed, 15 insertions(+), 22 deletions(-)

Comments

Jonathan Tan July 27, 2021, 5:12 p.m. UTC | #1
> diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
> index a924fdb7a6..f5dc051a6e 100755
> --- a/t/t7400-submodule-basic.sh
> +++ b/t/t7400-submodule-basic.sh
> @@ -107,25 +107,18 @@ test_expect_success 'setup - repository to add submodules to' '
>  # generates, which will expand symbolic links.
>  submodurl=$(pwd -P)
>  
> -listbranches() {
> -	git for-each-ref --format='%(refname)' 'refs/heads/*'
> -}
> -
>  inspect() {
>  	dir=$1 &&
> -	dotdot="${2:-..}" &&
>  
> -	(
> -		cd "$dir" &&
> -		listbranches >"$dotdot/heads" &&
> -		{ git symbolic-ref HEAD || :; } >"$dotdot/head" &&
> -		git rev-parse HEAD >"$dotdot/head-sha1" &&
> -		git update-index --refresh &&
> -		git diff-files --exit-code &&
> -		git clean -n -d -x >"$dotdot/untracked"
> -	)
> +	git -C "$dir" for-each-ref --format='%(refname)' 'refs/heads/*' >heads &&
> +	{ git -C "$dir" symbolic-ref HEAD || :; } >head &&
> +	git -C "$dir" rev-parse HEAD >head-sha1 &&
> +	git -C "$dir" update-index --refresh &&
> +	git -C "$dir" diff-files --exit-code &&
> +	git -C "$dir" clean -n -d -x >untracked
>  }
>  
> +

Stray extra line.

Other than that, this is definitely a good simplification.
Emily Shaffer Aug. 19, 2021, 5:46 p.m. UTC | #2
On Tue, Jul 27, 2021 at 10:12:25AM -0700, Jonathan Tan wrote:
> 
> > diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
> > index a924fdb7a6..f5dc051a6e 100755
> > --- a/t/t7400-submodule-basic.sh
> > +++ b/t/t7400-submodule-basic.sh
> > @@ -107,25 +107,18 @@ test_expect_success 'setup - repository to add submodules to' '
> >  # generates, which will expand symbolic links.
> >  submodurl=$(pwd -P)
> >  
> > -listbranches() {
> > -	git for-each-ref --format='%(refname)' 'refs/heads/*'
> > -}
> > -
> >  inspect() {
> >  	dir=$1 &&
> > -	dotdot="${2:-..}" &&
> >  
> > -	(
> > -		cd "$dir" &&
> > -		listbranches >"$dotdot/heads" &&
> > -		{ git symbolic-ref HEAD || :; } >"$dotdot/head" &&
> > -		git rev-parse HEAD >"$dotdot/head-sha1" &&
> > -		git update-index --refresh &&
> > -		git diff-files --exit-code &&
> > -		git clean -n -d -x >"$dotdot/untracked"
> > -	)
> > +	git -C "$dir" for-each-ref --format='%(refname)' 'refs/heads/*' >heads &&
> > +	{ git -C "$dir" symbolic-ref HEAD || :; } >head &&
> > +	git -C "$dir" rev-parse HEAD >head-sha1 &&
> > +	git -C "$dir" update-index --refresh &&
> > +	git -C "$dir" diff-files --exit-code &&
> > +	git -C "$dir" clean -n -d -x >untracked
> >  }
> >  
> > +
> 
> Stray extra line.
> 
> Other than that, this is definitely a good simplification.

Ack, fixed locally. Thanks.

 - Emily
diff mbox series

Patch

diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh
index a924fdb7a6..f5dc051a6e 100755
--- a/t/t7400-submodule-basic.sh
+++ b/t/t7400-submodule-basic.sh
@@ -107,25 +107,18 @@  test_expect_success 'setup - repository to add submodules to' '
 # generates, which will expand symbolic links.
 submodurl=$(pwd -P)
 
-listbranches() {
-	git for-each-ref --format='%(refname)' 'refs/heads/*'
-}
-
 inspect() {
 	dir=$1 &&
-	dotdot="${2:-..}" &&
 
-	(
-		cd "$dir" &&
-		listbranches >"$dotdot/heads" &&
-		{ git symbolic-ref HEAD || :; } >"$dotdot/head" &&
-		git rev-parse HEAD >"$dotdot/head-sha1" &&
-		git update-index --refresh &&
-		git diff-files --exit-code &&
-		git clean -n -d -x >"$dotdot/untracked"
-	)
+	git -C "$dir" for-each-ref --format='%(refname)' 'refs/heads/*' >heads &&
+	{ git -C "$dir" symbolic-ref HEAD || :; } >head &&
+	git -C "$dir" rev-parse HEAD >head-sha1 &&
+	git -C "$dir" update-index --refresh &&
+	git -C "$dir" diff-files --exit-code &&
+	git -C "$dir" clean -n -d -x >untracked
 }
 
+
 test_expect_success 'submodule add' '
 	echo "refs/heads/main" >expect &&
 
@@ -146,7 +139,7 @@  test_expect_success 'submodule add' '
 	) &&
 
 	rm -f heads head untracked &&
-	inspect addtest/submod ../.. &&
+	inspect addtest/submod &&
 	test_cmp expect heads &&
 	test_cmp expect head &&
 	test_must_be_empty untracked
@@ -237,7 +230,7 @@  test_expect_success 'submodule add --branch' '
 	) &&
 
 	rm -f heads head untracked &&
-	inspect addtest/submod-branch ../.. &&
+	inspect addtest/submod-branch &&
 	test_cmp expect-heads heads &&
 	test_cmp expect-head head &&
 	test_must_be_empty untracked
@@ -253,7 +246,7 @@  test_expect_success 'submodule add with ./ in path' '
 	) &&
 
 	rm -f heads head untracked &&
-	inspect addtest/dotsubmod/frotz ../../.. &&
+	inspect addtest/dotsubmod/frotz &&
 	test_cmp expect heads &&
 	test_cmp expect head &&
 	test_must_be_empty untracked
@@ -269,7 +262,7 @@  test_expect_success 'submodule add with /././ in path' '
 	) &&
 
 	rm -f heads head untracked &&
-	inspect addtest/dotslashdotsubmod/frotz ../../.. &&
+	inspect addtest/dotslashdotsubmod/frotz &&
 	test_cmp expect heads &&
 	test_cmp expect head &&
 	test_must_be_empty untracked
@@ -285,7 +278,7 @@  test_expect_success 'submodule add with // in path' '
 	) &&
 
 	rm -f heads head untracked &&
-	inspect addtest/slashslashsubmod/frotz ../../.. &&
+	inspect addtest/slashslashsubmod/frotz &&
 	test_cmp expect heads &&
 	test_cmp expect head &&
 	test_must_be_empty untracked
@@ -301,7 +294,7 @@  test_expect_success 'submodule add with /.. in path' '
 	) &&
 
 	rm -f heads head untracked &&
-	inspect addtest/realsubmod ../.. &&
+	inspect addtest/realsubmod &&
 	test_cmp expect heads &&
 	test_cmp expect head &&
 	test_must_be_empty untracked
@@ -317,7 +310,7 @@  test_expect_success 'submodule add with ./, /.. and // in path' '
 	) &&
 
 	rm -f heads head untracked &&
-	inspect addtest/realsubmod2 ../.. &&
+	inspect addtest/realsubmod2 &&
 	test_cmp expect heads &&
 	test_cmp expect head &&
 	test_must_be_empty untracked
@@ -348,7 +341,7 @@  test_expect_success 'submodule add in subdirectory' '
 	) &&
 
 	rm -f heads head untracked &&
-	inspect addtest/realsubmod3 ../.. &&
+	inspect addtest/realsubmod3 &&
 	test_cmp expect heads &&
 	test_cmp expect head &&
 	test_must_be_empty untracked