Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2021-05-10 17:19:06 +0300
committerJunio C Hamano <gitster@pobox.com>2021-05-11 06:45:18 +0300
commit47c88d16ba6c5c0237238ac600ee8b74a522e41c (patch)
treefece7ae67a32ccf52950137bd8b536ce2d0cb1e9
parent8cfe386b78c15eff38388479aa2f9fae00a9cf53 (diff)
test-lib functions: add --printf option to test_commit
Add a --printf option to test_commit to allow writing to the file with "printf" instead of "echo". This is useful for writing "\n", "\0" etc., in particular in combination with the --append option added in 3373518cc8 (test-lib functions: add an --append option to test_commit, 2021-01-12). I'm converting a few tests to use the new option rather than a manual printf/add/commit combination to demonstrate its usefulness. While I'm at it use "test_create_repo" where appropriate, and give the first/second commit a meaningful/more conventional log message in cases where no test cared about that message. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rwxr-xr-xt/t1307-config-blob.sh4
-rwxr-xr-xt/t2030-unresolve-info.sh3
-rwxr-xr-xt/t4006-diff-mode.sh6
-rwxr-xr-xt/t4030-diff-textconv.sh8
-rwxr-xr-xt/t5520-pull.sh10
-rw-r--r--t/test-lib-functions.sh14
6 files changed, 20 insertions, 25 deletions
diff --git a/t/t1307-config-blob.sh b/t/t1307-config-blob.sh
index 002e6d3388..930dce06f0 100755
--- a/t/t1307-config-blob.sh
+++ b/t/t1307-config-blob.sh
@@ -65,9 +65,7 @@ test_expect_success 'parse errors in blobs are properly attributed' '
'
test_expect_success 'can parse blob ending with CR' '
- printf "[some]key = value\\r" >config &&
- git add config &&
- git commit -m CR &&
+ test_commit --printf CR config "[some]key = value\\r" &&
echo value >expect &&
git config --blob=HEAD:config some.key >actual &&
test_cmp expect actual
diff --git a/t/t2030-unresolve-info.sh b/t/t2030-unresolve-info.sh
index be6c84c52a..f691e6d903 100755
--- a/t/t2030-unresolve-info.sh
+++ b/t/t2030-unresolve-info.sh
@@ -179,8 +179,7 @@ test_expect_success 'rerere and rerere forget (subdirectory)' '
test_expect_success 'rerere forget (binary)' '
git checkout -f side &&
- printf "a\0c" >binary &&
- git commit -a -m binary &&
+ test_commit --printf binary binary "a\0c" &&
test_must_fail git merge second &&
git rerere forget binary
'
diff --git a/t/t4006-diff-mode.sh b/t/t4006-diff-mode.sh
index 275ce5fa15..6cdee2a216 100755
--- a/t/t4006-diff-mode.sh
+++ b/t/t4006-diff-mode.sh
@@ -26,10 +26,8 @@ test_expect_success 'chmod' '
'
test_expect_success 'prepare binary file' '
- git commit -m rezrov &&
- printf "\00\01\02\03\04\05\06" >binbin &&
- git add binbin &&
- git commit -m binbin
+ git commit -m one &&
+ test_commit --printf two binbin "\00\01\02\03\04\05\06"
'
test_expect_success '--stat output after text chmod' '
diff --git a/t/t4030-diff-textconv.sh b/t/t4030-diff-textconv.sh
index c906320b60..a39a626664 100755
--- a/t/t4030-diff-textconv.sh
+++ b/t/t4030-diff-textconv.sh
@@ -26,12 +26,8 @@ EOF
chmod +x hexdump
test_expect_success 'setup binary file with history' '
- printf "\\0\\n" >file &&
- git add file &&
- git commit -m one &&
- printf "\\01\\n" >>file &&
- git add file &&
- git commit -m two
+ test_commit --printf one file "\\0\\n" &&
+ test_commit --printf --append two file "\\01\\n"
'
test_expect_success 'file is considered binary by porcelain' '
diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh
index a09411327f..e2c0c51022 100755
--- a/t/t5520-pull.sh
+++ b/t/t5520-pull.sh
@@ -746,14 +746,8 @@ test_expect_success 'pull --rebase fails on corrupt HEAD' '
'
test_expect_success 'setup for detecting upstreamed changes' '
- mkdir src &&
- (
- cd src &&
- git init &&
- printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" > stuff &&
- git add stuff &&
- git commit -m "Initial revision"
- ) &&
+ test_create_repo src &&
+ test_commit -C src --printf one stuff "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" &&
git clone src dst &&
(
cd src &&
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index 6e2332a324..6f9199a65b 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -173,6 +173,12 @@ debug () {
# Do not call test_tick before making a commit
# --append
# Use ">>" instead of ">" when writing "<contents>" to "<file>"
+# --printf
+# Use "printf" instead of "echo" when writing "<contents>" to
+# "<file>", use this to write escape sequences such as "\0", a
+# trailing "\n" won't be added automatically. This option
+# supports nothing but the FORMAT of printf(1), i.e. no custom
+# ARGUMENT(s).
# --signoff
# Invoke "git commit" with --signoff
# --author <author>
@@ -191,6 +197,7 @@ debug () {
test_commit () {
notick= &&
+ echo=echo &&
append= &&
author= &&
signoff= &&
@@ -202,6 +209,9 @@ test_commit () {
--notick)
notick=yes
;;
+ --printf)
+ echo=printf
+ ;;
--append)
append=yes
;;
@@ -238,9 +248,9 @@ test_commit () {
file=${2:-"$1.t"} &&
if test -n "$append"
then
- echo "${3-$1}" >>"$indir$file"
+ $echo "${3-$1}" >>"$indir$file"
else
- echo "${3-$1}" >"$indir$file"
+ $echo "${3-$1}" >"$indir$file"
fi &&
git ${indir:+ -C "$indir"} add "$file" &&
if test -z "$notick"