Message ID | 48b87cccedb3d7920a3184ca86ca9eec77c0fd01.1726692381.git.gitgitgadget@gmail.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | pack-objects: create new name-hash algorithm | expand |
"Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com> writes: > The existing test_subcommand method requires an exact list of arguments > for the subcommand. This is too rigid for our needs here, so create a > new method, test_subcommand_flex. Use it to check that the > --full-name-hash option is passing through. This is something I found need for in the past at least a few times. > +# Check that the given subcommand was run with the given set of > +# arguments in order (but with possible extra arguments). > +# > +# test_subcommand_flex [!] <command> <args>... < <trace> > +# > +# If the first parameter passed is !, this instead checks that > +# the given command was not called. > +# > +test_subcommand_flex () { > + local negate= > + if test "$1" = "!" > + then > + negate=t > + shift > + fi > + > + local expr="$(printf '"%s".*' "$@")" OK, so it works exactly like the comment said. You allow arbigrary garbage in between the given parameters that come in the order given. As long as this is used to make sure that the flags are passed through, by somebody who knows how the code constructs the command line, this should be fine, as we won't be permuting the command line parameters. Looking good. > + if test -n "$negate" > + then > + ! grep "\[$expr\]" > + else > + grep "\[$expr\]" > + fi > +} > + > # Check that the given command was invoked as part of the > # trace2-format trace on stdin. > #
diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index be1188e7365..1feb6643e69 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -776,6 +776,13 @@ test_expect_success 'repack -ad cleans up old .tmp-* packs' ' test_must_be_empty tmpfiles ' +test_expect_success '--full-name-hash option passes through to pack-objects' ' + GIT_TRACE2_EVENT="$(pwd)/full-trace.txt" \ + git repack -a --full-name-hash && + test_subcommand_flex git pack-objects --full-name-hash <full-trace.txt +' + + test_expect_success 'setup for update-server-info' ' git init update-server-info && test_commit -C update-server-info message diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index fde9bf54fc3..0d94730924a 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -1885,6 +1885,33 @@ test_subcommand () { fi } + +# Check that the given subcommand was run with the given set of +# arguments in order (but with possible extra arguments). +# +# test_subcommand_flex [!] <command> <args>... < <trace> +# +# If the first parameter passed is !, this instead checks that +# the given command was not called. +# +test_subcommand_flex () { + local negate= + if test "$1" = "!" + then + negate=t + shift + fi + + local expr="$(printf '"%s".*' "$@")" + + if test -n "$negate" + then + ! grep "\[$expr\]" + else + grep "\[$expr\]" + fi +} + # Check that the given command was invoked as part of the # trace2-format trace on stdin. #