git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCHv8 3/6] test-lib-functions.sh: teach test_commit -C <dir>

From
Stefan Beller <sbeller@google.com>
Date
Dec 12, 2016, 19:04 UTC
Message-ID
<20161212190435.10358-4-sbeller@google.com>
In-Reply-To
<20161212190435.10358-1-sbeller@google.com>

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>
---
 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 "<message> [<file> [<contents> [<tag>]]]"
+# Call test_commit with the arguments
+# [-C <directory>] <message> [<file> [<contents> [<tag>]]]"
 #
 # This will commit a file with the given contents and the given commit
 # message, and tag the resulting commit with the given tag name.
 #
 # <file>, <contents>, and <tag> all default to <message>.
+#
+# 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 "<message> <commit>", where <commit>
-- 
2.11.0.rc2.49.ge1f3b0c.dirty
Previous: Stefan BellerNext: Stefan Beller
Message 6 of 12 in “[PATCHv7 0/6] submodule absorbgitdirs”
  1. Stefan BellerDec 12, 2016
  2. 1/6 submodule: use absolute path for computing relative path connectingStefan Beller, Dec 12, 2016
  3. 2/6 submodule helper: support super prefixStefan Beller, Dec 12, 2016
  4. 4/6 worktree: check if a submodule uses worktreesStefan Beller, Dec 12, 2016
  5. 5/6 move connect_work_tree_and_git_dir to dir.hStefan Beller, Dec 12, 2016
  6. 3/6 test-lib-functions.sh: teach test_commit -C <dir>Stefan Beller, Dec 12, 2016
  7. 6/6 submodule: add absorb-git-dir functionStefan Beller, Dec 12, 2016
  8. Duy NguyenDec 19, 2016
  9. Stefan BellerDec 19, 2016
  10. Duy NguyenDec 20, 2016
  11. Brandon WilliamsDec 12, 2016
  12. Stefan BellerDec 12, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.