From: Junio C Hamano Date: Mon, 21 Nov 2016 21:04:55 GMT Subject: Re: [PATCH 2/3] test-lib-functions.sh: teach test_commit -C Message-ID: In-Reply-To: <20161121204146.13665-3-sbeller@google.com> Stefan Beller writes: > Specifically when setting up submodule tests, it comes in handy if > we can create commits in repositories that are not at the root of > the tested trash dir. Add "-C " similar to gits -C parameter > that will perform the operation in the given directory. > > Signed-off-by: Stefan Beller > --- Looks useful. > t/test-lib-functions.sh | 20 +++++++++++++++----- > 1 file changed, 15 insertions(+), 5 deletions(-) > > diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh > index fdaeb3a96b..579e812506 100644 > --- a/t/test-lib-functions.sh > +++ b/t/test-lib-functions.sh > @@ -157,16 +157,21 @@ debug () { > GIT_TEST_GDB=1 "$@" > } > > -# Call test_commit with the arguments " [ [ []]]" > +# Call test_commit with the arguments > +# [-C ] [ [ []]]" > # > # This will commit a file with the given contents and the given commit > # message, and tag the resulting commit with the given tag name. > # > # , , and all default to . > +# > +# If the first argument is "-C", the second argument is used as a path for > +# the git invocations. > > test_commit () { > notick= && > signoff= && > + indir= && > while test $# != 0 > do > case "$1" in > @@ -176,21 +181,26 @@ test_commit () { > --signoff) > signoff="$1" > ;; > + -C) > + indir="$2" > + shift > + ;; > *) > break > ;; > esac > shift > done && > + indir=${indir:+"$indir"/} && > file=${2:-"$1.t"} && > - echo "${3-$1}" > "$file" && > - git add "$file" && > + echo "${3-$1}" > "$indir$file" && > + git ${indir:+ -C "$indir"} add "$file" && > if test -z "$notick" > then > test_tick > fi && > - git commit $signoff -m "$1" && > - git tag "${4:-$1}" > + git ${indir:+ -C "$indir"} commit $signoff -m "$1" && > + git ${indir:+ -C "$indir"} tag "${4:-$1}" > } > > # Call test_merge with the arguments " ", where