Re: [RFC PATCH 1/4] t7400-submodule-basic: modernize inspect() helper
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Jun 14, 2021, 04:52 UTC
- Message-ID
- <xmqq5yyhyrmr.fsf@gitster.g>
- In-Reply-To
- <20210611225428.1208973-2-emilyshaffer@google.com>
Emily Shaffer <emilyshaffer@google.com> writes:
Show 43 quoted lines
> 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(-)
>
> 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
> }Quite straight-forward.
> - inspect addtest/submod ../.. && > + inspect addtest/submod &&
And specifically the losing ../.. is pleasing to the eye, especially because the old "dotdot" thing was mechanically computable from "dir".
Nicely done.