Skip to content

Commit 6f94351

Browse files
stefanbellergitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 89c8626 commit 6f94351

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

t/test-lib-functions.sh

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,21 @@ debug () {
157157
GIT_TEST_GDB=1 "$@"
158158
}
159159

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>]]]"
161162
#
162163
# This will commit a file with the given contents and the given commit
163164
# message, and tag the resulting commit with the given tag name.
164165
#
165166
# <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.
166170

167171
test_commit () {
168172
notick= &&
169173
signoff= &&
174+
indir= &&
170175
while test $# != 0
171176
do
172177
case "$1" in
@@ -176,21 +181,26 @@ test_commit () {
176181
--signoff)
177182
signoff="$1"
178183
;;
184+
-C)
185+
indir="$2"
186+
shift
187+
;;
179188
*)
180189
break
181190
;;
182191
esac
183192
shift
184193
done &&
194+
indir=${indir:+"$indir"/} &&
185195
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" &&
188198
if test -z "$notick"
189199
then
190200
test_tick
191201
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}"
194204
}
195205

196206
# Call test_merge with the arguments "<message> <commit>", where <commit>

0 commit comments

Comments
 (0)