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>
This commit is contained in:
committed by
Junio C Hamano
parent
8cfe386b78
commit
47c88d16ba
@ -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"
|
||||
|
||||
Reference in New Issue
Block a user