test-lib-functions.sh: teach test_commit -C <dir>

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 <dir>" similar to gits -C parameter that will perform the operation in the given directory. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed Dec 8, 2016 at 13:03 UTC 6f94351b0a4dd107623a35dc9081bf31c7ddac88
1 file changed +15 -5
t/test-lib-functions.sh
+15 -5
@@ -157,16 +157,21 @@ debug () {
157 GIT_TEST_GDB=1 "$@"
158 }
159
160 -# Call test_commit with the arguments "<message> [<file> [<contents> [<tag>]]]"
160 +# Call test_commit with the arguments
161 +# [-C <directory>] <message> [<file> [<contents> [<tag>]]]"
162 #
163 # This will commit a file with the given contents and the given commit
164 # message, and tag the resulting commit with the given tag name.
165 #
166 # <file>, <contents>, and <tag> all default to <message>.
167 +#
168 +# If the first argument is "-C", the second argument is used as a path for
169 +# the git invocations.
170
171 test_commit () {
172 notick= &&
173 signoff= &&
174 + indir= &&
175 while test $# != 0
176 do
177 case "$1" in
@@ -176,21 +181,26 @@ test_commit () {
181 --signoff)
182 signoff="$1"
183 ;;
184 + -C)
185 + indir="$2"
186 + shift
187 + ;;
188 *)
189 break
190 ;;
191 esac
192 shift
193 done &&
194 + indir=${indir:+"$indir"/} &&
195 file=${2:-"$1.t"} &&
186 - echo "${3-$1}" > "$file" &&
187 - git add "$file" &&
196 + echo "${3-$1}" > "$indir$file" &&
197 + git ${indir:+ -C "$indir"} add "$file" &&
198 if test -z "$notick"
199 then
200 test_tick
201 fi &&
192 - git commit $signoff -m "$1" &&
193 - git tag "${4:-$1}"
202 + git ${indir:+ -C "$indir"} commit $signoff -m "$1" &&
203 + git ${indir:+ -C "$indir"} tag "${4:-$1}"
204 }
205
206 # Call test_merge with the arguments "<message> <commit>", where <commit>