diff options
Diffstat (limited to 't')
244 files changed, 1985 insertions, 1176 deletions
diff --git a/t/Makefile b/t/Makefile index 882d26eee3..46cd5fc527 100644 --- a/t/Makefile +++ b/t/Makefile @@ -71,12 +71,10 @@ clean-chainlint: check-chainlint: @mkdir -p '$(CHAINLINTTMP_SQ)' && \ - err=0 && \ - for i in $(CHAINLINTTESTS); do \ - $(CHAINLINT) <chainlint/$$i.test | \ - sed -e '/^# LINT: /d' >'$(CHAINLINTTMP_SQ)'/$$i.actual && \ - diff -u chainlint/$$i.expect '$(CHAINLINTTMP_SQ)'/$$i.actual || err=1; \ - done && exit $$err + sed -e '/^# LINT: /d' $(patsubst %,chainlint/%.test,$(CHAINLINTTESTS)) >'$(CHAINLINTTMP_SQ)'/tests && \ + sed -e '/^[ ]*$$/d' $(patsubst %,chainlint/%.expect,$(CHAINLINTTESTS)) >'$(CHAINLINTTMP_SQ)'/expect && \ + $(CHAINLINT) '$(CHAINLINTTMP_SQ)'/tests | grep -v '^[ ]*$$' >'$(CHAINLINTTMP_SQ)'/actual && \ + diff -u '$(CHAINLINTTMP_SQ)'/expect '$(CHAINLINTTMP_SQ)'/actual test-lint: test-lint-duplicates test-lint-executable test-lint-shell-syntax \ test-lint-filenames diff --git a/t/annotate-tests.sh b/t/annotate-tests.sh index d3b299e75c..09e86f9ba0 100644 --- a/t/annotate-tests.sh +++ b/t/annotate-tests.sh @@ -161,7 +161,7 @@ test_expect_success 'blame huge graft' ' GIT_AUTHOR_NAME=$i$j GIT_AUTHOR_EMAIL=$i$j@test.git \ git commit -a -m "$i$j" && commit=$(git rev-parse --verify HEAD) && - graft="$graft$commit " + graft="$graft$commit " || return 1 done done && printf "%s " $graft >.git/info/grafts && diff --git a/t/chainlint.sed b/t/chainlint.sed index 8a25c5b855..dc4ce37cb5 100644 --- a/t/chainlint.sed +++ b/t/chainlint.sed @@ -24,9 +24,9 @@ # in order to avoid misinterpreting the ")" in constructs such as "x=$(...)" # and "case $x in *)" as ending the subshell. # -# Lines missing a final "&&" are flagged with "?!AMP?!", and lines which chain -# commands with ";" internally rather than "&&" are flagged "?!SEMI?!". A line -# may be flagged for both violations. +# Lines missing a final "&&" are flagged with "?!AMP?!", as are lines which +# chain commands with ";" internally rather than "&&". A line may be flagged +# for both violations. # # Detection of a missing &&-link in a multi-line subshell is complicated by the # fact that the last statement before the closing ")" must not end with "&&". @@ -47,8 +47,8 @@ # "?!AMP?!" violation is removed from the "bar" line (retrieved from the "hold" # area) since the final statement of a subshell must not end with "&&". The # final line of a subshell may still break the &&-chain by using ";" internally -# to chain commands together rather than "&&", so "?!SEMI?!" is never removed -# from a line (even though "?!AMP?!" might be). +# to chain commands together rather than "&&", but an internal "?!AMP?!" is +# never removed from a line even though a line-ending "?!AMP?!" might be. # # Care is taken to recognize the last _statement_ of a multi-line subshell, not # necessarily the last textual _line_ within the subshell, since &&-chaining @@ -62,26 +62,20 @@ # receives similar treatment. # # Swallowing here-docs with arbitrary tags requires a bit of finesse. When a -# line such as "cat <<EOF >out" is seen, the here-doc tag is moved to the front -# of the line enclosed in angle brackets as a sentinel, giving "<EOF>cat >out". +# line such as "cat <<EOF" is seen, the here-doc tag is copied to the front of +# the line enclosed in angle brackets as a sentinel, giving "<EOF>cat <<EOF". # As each subsequent line is read, it is appended to the target line and a # (whitespace-loose) back-reference match /^<(.*)>\n\1$/ is attempted to see if # the content inside "<...>" matches the entirety of the newly-read line. For # instance, if the next line read is "some data", when concatenated with the -# target line, it becomes "<EOF>cat >out\nsome data", and a match is attempted +# target line, it becomes "<EOF>cat <<EOF\nsome data", and a match is attempted # to see if "EOF" matches "some data". Since it doesn't, the next line is # attempted. When a line consisting of only "EOF" (and possible whitespace) is -# encountered, it is appended to the target line giving "<EOF>cat >out\nEOF", +# encountered, it is appended to the target line giving "<EOF>cat <<EOF\nEOF", # in which case the "EOF" inside "<...>" does match the text following the # newline, thus the closing here-doc tag has been found. The closing tag line # and the "<...>" prefix on the target line are then discarded, leaving just -# the target line "cat >out". -# -# To facilitate regression testing (and manual debugging), a ">" annotation is -# applied to the line containing ")" which closes a subshell, ">>" to a line -# closing a nested subshell, and ">>>" to a line closing both at once. This -# makes it easy to detect whether the heuristics correctly identify -# end-of-subshell. +# the target line "cat <<EOF". #------------------------------------------------------------------------------ # incomplete line -- slurp up next line @@ -94,9 +88,9 @@ # here-doc -- swallow it to avoid false hits within its body (but keep the # command to which it was attached) -/<<[ ]*[-\\'"]*[A-Za-z0-9_]/ { - s/^\(.*\)<<[ ]*[-\\'"]*\([A-Za-z0-9_][A-Za-z0-9_]*\)['"]*/<\2>\1<</ - s/[ ]*<<// +/<<-*[ ]*[\\'"]*[A-Za-z0-9_]/ { + /"[^"]*<<[^"]*"/bnotdoc + s/^\(.*<<-*[ ]*\)[\\'"]*\([A-Za-z0-9_][A-Za-z0-9_]*\)['"]*/<\2>\1\2/ :hered N /^<\([^>]*\)>.*\n[ ]*\1[ ]*$/!{ @@ -106,6 +100,7 @@ s/^<[^>]*>// s/\n.*$// } +:notdoc # one-liner "(...) &&" /^[ ]*!*[ ]*(..*)[ ]*&&[ ]*$/boneline @@ -126,7 +121,7 @@ b # "&&" (but not ";" in a string) :oneline /;/{ - /"[^"]*;[^"]*"/!s/^/?!SEMI?!/ + /"[^"]*;[^"]*"/!s/;/; ?!AMP?!/ } b @@ -136,11 +131,15 @@ b h bnextln } -# "(..." line -- split off and stash "(", then process "..." as its own line +# "(..." line -- "(" opening subshell cuddled with command; temporarily replace +# "(" with sentinel "^" and process the line as if "(" had been seen solo on +# the preceding line; this temporary replacement prevents several rules from +# accidentally thinking "(" introduces a nested subshell; "^" is changed back +# to "(" at output time x -s/.*/(/ +s/.*// x -s/(// +s/(/^/ bslurp :nextln @@ -157,8 +156,10 @@ s/.*\n// /"[^'"]*'[^'"]*"/!bsqstr } :folded -# here-doc -- swallow it -/<<[ ]*[-\\'"]*[A-Za-z0-9_]/bheredoc +# here-doc -- swallow it (but not "<<" in a string) +/<<-*[ ]*[\\'"]*[A-Za-z0-9_]/{ + /"[^"]*<<[^"]*"/!bheredoc +} # comment or empty line -- discard since final non-comment, non-empty line # before closing ")", "done", "elsif", "else", or "fi" will need to be # re-visited to drop "suspect" marking since final line of those constructs @@ -171,12 +172,12 @@ s/.*\n// /"[^"]*#[^"]*"/!s/[ ]#.*$// } # one-liner "case ... esac" -/^[ ]*case[ ]*..*esac/bchkchn +/^[ ^]*case[ ]*..*esac/bchkchn # multi-line "case ... esac" -/^[ ]*case[ ]..*[ ]in/bcase +/^[ ^]*case[ ]..*[ ]in/bcase # multi-line "for ... done" or "while ... done" -/^[ ]*for[ ]..*[ ]in/bcont -/^[ ]*while[ ]/bcont +/^[ ^]*for[ ]..*[ ]in/bcont +/^[ ^]*while[ ]/bcont /^[ ]*do[ ]/bcont /^[ ]*do[ ]*$/bcont /;[ ]*do/bcont @@ -187,7 +188,7 @@ s/.*\n// /||[ ]*exit[ ]/bcont /||[ ]*exit[ ]*$/bcont # multi-line "if...elsif...else...fi" -/^[ ]*if[ ]/bcont +/^[ ^]*if[ ]/bcont /^[ ]*then[ ]/bcont /^[ ]*then[ ]*$/bcont /;[ ]*then/bcont @@ -200,15 +201,15 @@ s/.*\n// /^[ ]*fi[ ]*[<>|]/bdone /^[ ]*fi[ ]*)/bdone # nested one-liner "(...) &&" -/^[ ]*(.*)[ ]*&&[ ]*$/bchkchn +/^[ ^]*(.*)[ ]*&&[ ]*$/bchkchn # nested one-liner "(...)" -/^[ ]*(.*)[ ]*$/bchkchn +/^[ ^]*(.*)[ ]*$/bchkchn # nested one-liner "(...) >x" (or "2>x" or "<x" or "|x") -/^[ ]*(.*)[ ]*[0-9]*[<>|]/bchkchn +/^[ ^]*(.*)[ ]*[0-9]*[<>|]/bchkchn # nested multi-line "(...\n...)" -/^[ ]*(/bnest +/^[ ^]*(/bnest # multi-line "{...\n...}" -/^[ ]*{/bblock +/^[ ^]*{/bblock # closing ")" on own line -- exit subshell /^[ ]*)/bclssolo # "$((...))" -- arithmetic expansion; not closing ")" @@ -230,16 +231,18 @@ s/.*\n// # string and not ";;" in one-liner "case...esac") /;/{ /;;/!{ - /"[^"]*;[^"]*"/!s/^/?!SEMI?!/ + /"[^"]*;[^"]*"/!s/;/; ?!AMP?!/ } } # line ends with pipe "...|" -- valid; not missing "&&" /|[ ]*$/bcont # missing end-of-line "&&" -- mark suspect -/&&[ ]*$/!s/^/?!AMP?!/ +/&&[ ]*$/!s/$/ ?!AMP?!/ :cont # retrieve and print previous line x +s/^\([ ]*\)^/\1(/ +s/?!HERE?!/<</g n bslurp @@ -280,8 +283,7 @@ bfolded # found here-doc -- swallow it to avoid false hits within its body (but keep # the command to which it was attached) :heredoc -s/^\(.*\)<<[ ]*[-\\'"]*\([A-Za-z0-9_][A-Za-z0-9_]*\)['"]*/<\2>\1<</ -s/[ ]*<<// +s/^\(.*\)<<\(-*[ ]*\)[\\'"]*\([A-Za-z0-9_][A-Za-z0-9_]*\)['"]*/<\3>\1?!HERE?!\2\3/ :hdocsub N /^<\([^>]*\)>.*\n[ ]*\1[ ]*$/!{ @@ -295,7 +297,15 @@ bfolded # found "case ... in" -- pass through untouched :case x +s/^\([ ]*\)^/\1(/ +s/?!HERE?!/<</g n +:cascom +/^[ ]*#/{ + N + s/.*\n// + bcascom +} /^[ ]*esac/bslurp bcase @@ -303,7 +313,7 @@ bcase # that line legitimately lacks "&&" :else x -s/?!AMP?!// +s/\( ?!AMP?!\)* ?!AMP?!$// x bcont @@ -311,7 +321,7 @@ bcont # "suspect" from final contained line since that line legitimately lacks "&&" :done x -s/?!AMP?!// +s/\( ?!AMP?!\)* ?!AMP?!$// x # is 'done' or 'fi' cuddled with ")" to close subshell? /done.*)/bclose @@ -322,11 +332,18 @@ bchkchn :nest x :nstslrp +s/^\([ ]*\)^/\1(/ +s/?!HERE?!/<</g n +:nstcom +# comment -- not closing ")" if in comment +/^[ ]*#/{ + N + s/.*\n// + bnstcom +} # closing ")" on own line -- stop nested slurp /^[ ]*)/bnstcl -# comment -- not closing ")" if in comment -/^[ ]*#/bnstcnt # "$((...))" -- arithmetic expansion; not closing ")" /\$(([^)][^)]*))[^)]*$/bnstcnt # "$(...)" -- command substitution; not closing ")" @@ -337,7 +354,6 @@ n x bnstslrp :nstcl -s/^/>>/ # is it "))" which closes nested and parent subshells? /)[ ]*)/bslurp bchkchn @@ -345,7 +361,15 @@ bchkchn # found multi-line "{...\n...}" block -- pass through untouched :block x +s/^\([ ]*\)^/\1(/ +s/?!HERE?!/<</g n +:blkcom +/^[ ]*#/{ + N + s/.*\n// + bblkcom +} # closing "}" -- stop block slurp /}/bchkchn bblock @@ -354,16 +378,22 @@ bblock # since that line legitimately lacks "&&" and exit subshell loop :clssolo x -s/?!AMP?!// +s/\( ?!AMP?!\)* ?!AMP?!$// +s/^\([ ]*\)^/\1(/ +s/?!HERE?!/<</g p x -s/^/>/ +s/^\([ ]*\)^/\1(/ +s/?!HERE?!/<</g b # found closing "...)" -- exit subshell loop :close x +s/^\([ ]*\)^/\1(/ +s/?!HERE?!/<</g p x -s/^/>/ +s/^\([ ]*\)^/\1(/ +s/?!HERE?!/<</g b diff --git a/t/chainlint/arithmetic-expansion.expect b/t/chainlint/arithmetic-expansion.expect index 09457d3196..46ee1046af 100644 --- a/t/chainlint/arithmetic-expansion.expect +++ b/t/chainlint/arithmetic-expansion.expect @@ -2,8 +2,8 @@ foo && bar=$((42 + 1)) && baz ->) && +) && ( -?!AMP?! bar=$((42 + 1)) + bar=$((42 + 1)) ?!AMP?! baz ->) +) diff --git a/t/chainlint/bash-array.expect b/t/chainlint/bash-array.expect index c4a830d1c1..4c34eaee45 100644 --- a/t/chainlint/bash-array.expect +++ b/t/chainlint/bash-array.expect @@ -2,9 +2,9 @@ foo && bar=(gumbo stumbo wumbo) && baz ->) && +) && ( foo && bar=${#bar[@]} && baz ->) +) diff --git a/t/chainlint/blank-line.expect b/t/chainlint/blank-line.expect index 3be939ed38..f76fde1ffb 100644 --- a/t/chainlint/blank-line.expect +++ b/t/chainlint/blank-line.expect @@ -1,4 +1,4 @@ ( nothing && something ->) +) diff --git a/t/chainlint/blank-line.test b/t/chainlint/blank-line.test index f6dd14302b..0fdf15b3e1 100644 --- a/t/chainlint/blank-line.test +++ b/t/chainlint/blank-line.test @@ -3,7 +3,7 @@ nothing && something -# LINT: swallow blank lines since final _statement_ before subshell end is +# LINT: ignore blank lines since final _statement_ before subshell end is # LINT: significant to "&&"-check, not final _line_ (which might be blank) diff --git a/t/chainlint/block-comment.expect b/t/chainlint/block-comment.expect new file mode 100644 index 0000000000..d10b2eeaf2 --- /dev/null +++ b/t/chainlint/block-comment.expect @@ -0,0 +1,6 @@ +( + { + echo a && + echo b + } +) diff --git a/t/chainlint/block-comment.test b/t/chainlint/block-comment.test new file mode 100644 index 0000000000..df2beea888 --- /dev/null +++ b/t/chainlint/block-comment.test @@ -0,0 +1,8 @@ +( + { + # show a + echo a && + # show b + echo b + } +) diff --git a/t/chainlint/block.expect b/t/chainlint/block.expect index fed7e89ae8..da60257ebc 100644 --- a/t/chainlint/block.expect +++ b/t/chainlint/block.expect @@ -7,6 +7,6 @@ bar && { echo c -?!AMP?! } + } ?!AMP?! baz ->) +) diff --git a/t/chainlint/block.test b/t/chainlint/block.test index d859151af1..0a82fd579f 100644 --- a/t/chainlint/block.test +++ b/t/chainlint/block.test @@ -1,6 +1,5 @@ ( -# LINT: missing "&&" in block not currently detected (for consistency with -# LINT: --chain-lint at top level and to provide escape hatch if needed) +# LINT: missing "&&" after first "echo" foo && { echo a diff --git a/t/chainlint/broken-chain.expect b/t/chainlint/broken-chain.expect index 55b0f42a53..cfb58fb6b9 100644 --- a/t/chainlint/broken-chain.expect +++ b/t/chainlint/broken-chain.expect @@ -1,6 +1,6 @@ ( foo && -?!AMP?! bar + bar ?!AMP?! baz && wop ->) +) diff --git a/t/chainlint/broken-chain.test b/t/chainlint/broken-chain.test index 3cc67b65d0..2a44aa73b7 100644 --- a/t/chainlint/broken-chain.test +++ b/t/chainlint/broken-chain.test @@ -1,6 +1,6 @@ ( foo && -# LINT: missing "&&" from 'bar' +# LINT: missing "&&" from "bar" bar baz && # LINT: final statement before closing ")" legitimately lacks "&&" diff --git a/t/chainlint/case-comment.expect b/t/chainlint/case-comment.expect new file mode 100644 index 0000000000..1e4b054bda --- /dev/null +++ b/t/chainlint/case-comment.expect @@ -0,0 +1,8 @@ +( + case "$x" in + x) foo ;; + *) + bar + ;; + esac +) diff --git a/t/chainlint/case-comment.test b/t/chainlint/case-comment.test new file mode 100644 index 0000000000..641c157b98 --- /dev/null +++ b/t/chainlint/case-comment.test @@ -0,0 +1,11 @@ +( + case "$x" in + # found foo + x) foo ;; + # found other + *) + # treat it as bar + bar + ;; + esac +) diff --git a/t/chainlint/case.expect b/t/chainlint/case.expect index 41f121fbbf..31f280d8ce 100644 --- a/t/chainlint/case.expect +++ b/t/chainlint/case.expect @@ -4,16 +4,16 @@ *) bar ;; esac && foobar ->) && +) && ( case "$x" in x) foo ;; *) bar ;; -?!AMP?! esac + esac ?!AMP?! foobar ->) && +) && ( case "$x" in 1) true;; esac && -?!AMP?! case "$y" in 2) false;; esac + case "$y" in 2) false;; esac ?!AMP?! foobar ->) +) diff --git a/t/chainlint/case.test b/t/chainlint/case.test index 5ef6ff7db5..4cb086bf87 100644 --- a/t/chainlint/case.test +++ b/t/chainlint/case.test @@ -1,5 +1,5 @@ ( -# LINT: "...)" arms in 'case' not misinterpreted as subshell-closing ")" +# LINT: "...)" arms in "case" not misinterpreted as subshell-closing ")" case "$x" in x) foo ;; *) bar ;; @@ -7,7 +7,7 @@ foobar ) && ( -# LINT: missing "&&" on 'esac' +# LINT: missing "&&" on "esac" case "$x" in x) foo ;; *) bar ;; @@ -15,7 +15,7 @@ foobar ) && ( -# LINT: "...)" arm in one-liner 'case' not misinterpreted as closing ")" +# LINT: "...)" arm in one-liner "case" not misinterpreted as closing ")" case "$x" in 1) true;; esac && # LINT: same but missing "&&" case "$y" in 2) false;; esac diff --git a/t/chainlint/close-nested-and-parent-together.expect b/t/chainlint/close-nested-and-parent-together.expect index 2a910f9d66..72d482f76d 100644 --- a/t/chainlint/close-nested-and-parent-together.expect +++ b/t/chainlint/close-nested-and-parent-together.expect @@ -1,4 +1,3 @@ -( -cd foo && +(cd foo && (bar && ->>> baz)) + baz)) diff --git a/t/chainlint/close-subshell.expect b/t/chainlint/close-subshell.expect index 184688718a..0f87db9ae6 100644 --- a/t/chainlint/close-subshell.expect +++ b/t/chainlint/close-subshell.expect @@ -1,25 +1,25 @@ ( foo ->) && +) && ( bar ->) >out && +) >out && ( baz ->) 2>err && +) 2>err && ( boo ->) <input && +) <input && ( bip ->) | wuzzle && +) | wuzzle && ( bop ->) | fazz fozz && +) | fazz fozz && ( bup ->) | +) | fuzzle && ( yop ->) +) diff --git a/t/chainlint/command-substitution.expect b/t/chainlint/command-substitution.expect index ad4118e537..c72e4df9e7 100644 --- a/t/chainlint/command-substitution.expect +++ b/t/chainlint/command-substitution.expect @@ -2,8 +2,8 @@ foo && bar=$(gobble) && baz ->) && +) && ( -?!AMP?! bar=$(gobble blocks) + bar=$(gobble blocks) ?!AMP?! baz ->) +) diff --git a/t/chainlint/comment.expect b/t/chainlint/comment.expect index 3be939ed38..f76fde1ffb 100644 --- a/t/chainlint/comment.expect +++ b/t/chainlint/comment.expect @@ -1,4 +1,4 @@ ( nothing && something ->) +) diff --git a/t/chainlint/complex-if-in-cuddled-loop.expect b/t/chainlint/complex-if-in-cuddled-loop.expect index 9674b88cf2..2fca183409 100644 --- a/t/chainlint/complex-if-in-cuddled-loop.expect +++ b/t/chainlint/complex-if-in-cuddled-loop.expect @@ -1,10 +1,9 @@ -( -for i in a b c; do +(for i in a b c; do if test "$(echo $(waffle bat))" = "eleventeen" && test "$x" = "$y"; then : else echo >file fi -> done) && + done) && test ! -f file diff --git a/t/chainlint/complex-if-in-cuddled-loop.test b/t/chainlint/complex-if-in-cuddled-loop.test index 571bbd85cd..5efeda58b2 100644 --- a/t/chainlint/complex-if-in-cuddled-loop.test +++ b/t/chainlint/complex-if-in-cuddled-loop.test @@ -1,4 +1,4 @@ -# LINT: 'for' loop cuddled with "(" and ")" and nested 'if' with complex +# LINT: "for" loop cuddled with "(" and ")" and nested "if" with complex # LINT: multi-line condition; indented with spaces, not tabs (for i in a b c; do if test "$(echo $(waffle bat))" = "eleventeen" && diff --git a/t/chainlint/cuddled-if-then-else.expect b/t/chainlint/cuddled-if-then-else.expect index ab2a026fbc..1d8ed58c49 100644 --- a/t/chainlint/cuddled-if-then-else.expect +++ b/t/chainlint/cuddled-if-then-else.expect @@ -1,7 +1,6 @@ -( -if test -z ""; then +(if test -z ""; then echo empty else echo bizzy -> fi) && + fi) && echo foobar diff --git a/t/chainlint/cuddled-if-then-else.test b/t/chainlint/cuddled-if-then-else.test index eed774a9d6..7c53f4efe3 100644 --- a/t/chainlint/cuddled-if-then-else.test +++ b/t/chainlint/cuddled-if-then-else.test @@ -1,4 +1,4 @@ -# LINT: 'if' cuddled with "(" and ")"; indented with spaces, not tabs +# LINT: "if" cuddled with "(" and ")"; indented with spaces, not tabs (if test -z ""; then echo empty else diff --git a/t/chainlint/cuddled-loop.expect b/t/chainlint/cuddled-loop.expect index 8c0260d7f1..9cf260708e 100644 --- a/t/chainlint/cuddled-loop.expect +++ b/t/chainlint/cuddled-loop.expect @@ -1,5 +1,4 @@ -( - while read x +( while read x do foobar bop || exit 1 -> done <file ) && + done <file ) && outside subshell diff --git a/t/chainlint/cuddled-loop.test b/t/chainlint/cuddled-loop.test index a841d781f0..3c2a62f751 100644 --- a/t/chainlint/cuddled-loop.test +++ b/t/chainlint/cuddled-loop.test @@ -1,4 +1,4 @@ -# LINT: 'while' loop cuddled with "(" and ")", with embedded (allowed) +# LINT: "while" loop cuddled with "(" and ")", with embedded (allowed) # LINT: "|| exit {n}" to exit loop early, and using redirection "<" to feed # LINT: loop; indented with spaces, not tabs ( while read x diff --git a/t/chainlint/cuddled.expect b/t/chainlint/cuddled.expect index b506d46221..c3e0be4047 100644 --- a/t/chainlint/cuddled.expect +++ b/t/chainlint/cuddled.expect @@ -1,21 +1,17 @@ -( -cd foo && +(cd foo && bar ->) && +) && -( -?!AMP?!cd foo +(cd foo ?!AMP?! bar ->) && +) && ( cd foo && -> bar) && + bar) && -( -cd foo && -> bar) && +(cd foo && + bar) && -( -?!AMP?!cd foo -> bar) +(cd foo ?!AMP?! + bar) diff --git a/t/chainlint/cuddled.test b/t/chainlint/cuddled.test index 0499fa4180..257b5b5eed 100644 --- a/t/chainlint/cuddled.test +++ b/t/chainlint/cuddled.test @@ -1,5 +1,4 @@ -# LINT: first subshell statement cuddled with opening "("; for implementation -# LINT: simplicity, "(..." is split into two lines, "(" and "..." +# LINT: first subshell statement cuddled with opening "(" (cd foo && bar ) && diff --git a/t/chainlint/exit-loop.expect b/t/chainlint/exit-loop.expect index 84d8bdebc0..f76aa60466 100644 --- a/t/chainlint/exit-loop.expect +++ b/t/chainlint/exit-loop.expect @@ -5,7 +5,7 @@ bar && baz done ->) && +) && ( while true do @@ -13,7 +13,7 @@ bar && baz done ->) && +) && ( i=0 && while test $i -lt 10 @@ -21,4 +21,4 @@ echo $i || exit i=$(($i + 1)) done ->) +) diff --git a/t/chainlint/exit-subshell.expect b/t/chainlint/exit-subshell.expect index bf78454f74..da80339f78 100644 --- a/t/chainlint/exit-subshell.expect +++ b/t/chainlint/exit-subshell.expect @@ -2,4 +2,4 @@ foo || exit 1 bar && baz ->) +) diff --git a/t/chainlint/for-loop.expect b/t/chainlint/for-loop.expect index c33cf56ee7..6671b8cd84 100644 --- a/t/chainlint/for-loop.expect +++ b/t/chainlint/for-loop.expect @@ -1,11 +1,11 @@ ( for i in a b c do -?!AMP?! echo $i - cat -?!AMP?! done + echo $i ?!AMP?! + cat <<-EOF + done ?!AMP?! for i in a b c; do echo $i && cat $i done ->) +) diff --git a/t/chainlint/for-loop.test b/t/chainlint/for-loop.test index 7db76262bc..6cb3428158 100644 --- a/t/chainlint/for-loop.test +++ b/t/chainlint/for-loop.test @@ -1,17 +1,17 @@ ( -# LINT: 'for', 'do', 'done' do not need "&&" +# LINT: "for", "do", "done" do not need "&&" for i in a b c do -# LINT: missing "&&" on 'echo' +# LINT: missing "&&" on "echo" echo $i # LINT: last statement of while does not need "&&" cat <<-\EOF bar EOF -# LINT: missing "&&" on 'done' +# LINT: missing "&&" on "done" done -# LINT: 'do' on same line as 'for' +# LINT: "do" on same line as "for" for i in a b c; do echo $i && cat $i diff --git a/t/chainlint/here-doc-close-subshell.expect b/t/chainlint/here-doc-close-subshell.expect index f011e335e5..2af9ced71c 100644 --- a/t/chainlint/here-doc-close-subshell.expect +++ b/t/chainlint/here-doc-close-subshell.expect @@ -1,2 +1,2 @@ ( -> cat) + cat <<-INPUT) diff --git a/t/chainlint/here-doc-multi-line-command-subst.expect b/t/chainlint/here-doc-multi-line-command-subst.expect index e5fb752d2f..f8b3aa73c4 100644 --- a/t/chainlint/here-doc-multi-line-command-subst.expect +++ b/t/chainlint/here-doc-multi-line-command-subst.expect @@ -1,5 +1,5 @@ ( - x=$(bobble && -?!AMP?!>> wiffle) + x=$(bobble <<-END && + wiffle) ?!AMP?! echo $x ->) +) diff --git a/t/chainlint/here-doc-multi-line-string.expect b/t/chainlint/here-doc-multi-line-string.expect index 32038a070c..2578191ca8 100644 --- a/t/chainlint/here-doc-multi-line-string.expect +++ b/t/chainlint/here-doc-multi-line-string.expect @@ -1,4 +1,4 @@ ( -?!AMP?! cat && echo "multi-line string" + cat <<-TXT && echo "multi-line string" ?!AMP?! bap ->) +) diff --git a/t/chainlint/here-doc.expect b/t/chainlint/here-doc.expect index 534b065e38..110059ba58 100644 --- a/t/chainlint/here-doc.expect +++ b/t/chainlint/here-doc.expect @@ -1,9 +1,7 @@ -boodle wobba gorgo snoot wafta snurb && +boodle wobba gorgo snoot wafta snurb <<EOF && -cat >foo && +cat <<-Arbitrary_Tag_42 >foo && -cat >bar && +cat <<zump >boo && -cat >boo && - -horticulture +horticulture <<EOF diff --git a/t/chainlint/here-doc.test b/t/chainlint/here-doc.test index ad4ce8afd9..3f5f92cad3 100644 --- a/t/chainlint/here-doc.test +++ b/t/chainlint/here-doc.test @@ -14,13 +14,6 @@ boz woz Arbitrary_Tag_42 -# LINT: swallow 'quoted' here-doc -cat <<'FUMP' >bar && -snoz -boz -woz -FUMP - # LINT: swallow "quoted" here-doc cat <<"zump" >boo && snoz diff --git a/t/chainlint/if-in-loop.expect b/t/chainlint/if-in-loop.expect index 03d3ceb22d..03b82a3e58 100644 --- a/t/chainlint/if-in-loop.expect +++ b/t/chainlint/if-in-loop.expect @@ -3,10 +3,10 @@ do if false then -?!AMP?! echo "err" + echo "err" ?!AMP?! exit 1 -?!AMP?! fi + fi ?!AMP?! foo -?!AMP?! done + done ?!AMP?! bar ->) +) diff --git a/t/chainlint/if-in-loop.test b/t/chainlint/if-in-loop.test index daf22da164..f0cf19cfad 100644 --- a/t/chainlint/if-in-loop.test +++ b/t/chainlint/if-in-loop.test @@ -3,13 +3,13 @@ do if false then -# LINT: missing "&&" on 'echo' +# LINT: missing "&&" on "echo" echo "err" exit 1 -# LINT: missing "&&" on 'fi' +# LINT: missing "&&" on "fi" fi foo -# LINT: missing "&&" on 'done' +# LINT: missing "&&" on "done" done bar ) diff --git a/t/chainlint/if-then-else.expect b/t/chainlint/if-then-else.expect index 5953c7bfbc..44d86c3597 100644 --- a/t/chainlint/if-then-else.expect +++ b/t/chainlint/if-then-else.expect @@ -1,19 +1,20 @@ ( if test -n "" then -?!AMP?! echo very + echo very ?!AMP?! echo empty elif test -z "" + then echo foo else echo foo && - cat -?!AMP?! fi + cat <<-EOF + fi ?!AMP?! echo poodle ->) && +) && ( if test -n ""; then echo very && -?!AMP?! echo empty - if ->) + echo empty + fi +) diff --git a/t/chainlint/if-then-else.test b/t/chainlint/if-then-else.test index 9bd8e9a4c6..2055336c2b 100644 --- a/t/chainlint/if-then-else.test +++ b/t/chainlint/if-then-else.test @@ -1,28 +1,29 @@ ( -# LINT: 'if', 'then', 'elif', 'else', 'fi' do not need "&&" +# LINT: "if", "then", "elif", "else", "fi" do not need "&&" if test -n "" then -# LINT: missing "&&" on 'echo' +# LINT: missing "&&" on "echo" echo very -# LINT: last statement before 'elif' does not need "&&" +# LINT: last statement before "elif" does not need "&&" echo empty elif test -z "" -# LINT: last statement before 'else' does not need "&&" + then +# LINT: last statement before "else" does not need "&&" echo foo else echo foo && -# LINT: last statement before 'fi' does not need "&&" +# LINT: last statement before "fi" does not need "&&" cat <<-\EOF bar EOF -# LINT: missing "&&" on 'fi' +# LINT: missing "&&" on "fi" fi echo poodle ) && ( -# LINT: 'then' on same line as 'if' +# LINT: "then" on same line as "if" if test -n ""; then echo very && echo empty - if + fi ) diff --git a/t/chainlint/incomplete-line.expect b/t/chainlint/incomplete-line.expect index 2f3ebabdc2..ffac8f9018 100644 --- a/t/chainlint/incomplete-line.expect +++ b/t/chainlint/incomplete-line.expect @@ -1,4 +1,4 @@ line 1 line 2 line 3 line 4 && ( line 5 line 6 line 7 line 8 ->) +) diff --git a/t/chainlint/inline-comment.expect b/t/chainlint/inline-comment.expect index fc9f250ac4..dd0dace077 100644 --- a/t/chainlint/inline-comment.expect +++ b/t/chainlint/inline-comment.expect @@ -1,9 +1,8 @@ ( foobar && -?!AMP?! barfoo + barfoo ?!AMP?! flibble "not a # comment" ->) && +) && -( -cd foo && -> flibble "not a # comment") +(cd foo && + flibble "not a # comment") diff --git a/t/chainlint/loop-in-if.expect b/t/chainlint/loop-in-if.expect index 088e622c31..e1be42376c 100644 --- a/t/chainlint/loop-in-if.expect +++ b/t/chainlint/loop-in-if.expect @@ -3,10 +3,10 @@ then while true do -?!AMP?! echo "pop" + echo "pop" ?!AMP?! echo "glup" -?!AMP?! done + done ?!AMP?! foo -?!AMP?! fi + fi ?!AMP?! bar ->) +) diff --git a/t/chainlint/loop-in-if.test b/t/chainlint/loop-in-if.test index 93e8ba8e4d..dfcc3f98fb 100644 --- a/t/chainlint/loop-in-if.test +++ b/t/chainlint/loop-in-if.test @@ -3,13 +3,13 @@ then while true do -# LINT: missing "&&" on 'echo' +# LINT: missing "&&" on "echo" echo "pop" echo "glup" -# LINT: missing "&&" on 'done' +# LINT: missing "&&" on "done" done foo -# LINT: missing "&&" on 'fi' +# LINT: missing "&&" on "fi" fi bar ) diff --git a/t/chainlint/multi-line-nested-command-substitution.expect b/t/chainlint/multi-line-nested-command-substitution.expect index 59b6c8b850..300058341b 100644 --- a/t/chainlint/multi-line-nested-command-substitution.expect +++ b/t/chainlint/multi-line-nested-command-substitution.expect @@ -3,16 +3,16 @@ x=$( echo bar | cat ->> ) && + ) && echo ok ->) | +) | sort && ( bar && x=$(echo bar | cat ->> ) && + ) && y=$(echo baz | ->> fip) && + fip) && echo fail ->) +) diff --git a/t/chainlint/multi-line-string.expect b/t/chainlint/multi-line-string.expect index 170cb59993..ab0dadf748 100644 --- a/t/chainlint/multi-line-string.expect +++ b/t/chainlint/multi-line-string.expect @@ -1,15 +1,9 @@ ( x="line 1 line 2 line 3" && -?!AMP?! y='line 1 line2' + y="line 1 line2" ?!AMP?! foobar ->) && -( - echo "there's nothing to see here" && - exit ->) && +) && ( echo "xyz" "abc def ghi" && - echo 'xyz' 'abc def ghi' && - echo 'xyz' "abc def ghi" && barfoo ->) +) diff --git a/t/chainlint/multi-line-string.test b/t/chainlint/multi-line-string.test index 287ab89705..4a0af2107d 100644 --- a/t/chainlint/multi-line-string.test +++ b/t/chainlint/multi-line-string.test @@ -3,25 +3,13 @@ line 2 line 3" && # LINT: missing "&&" on assignment - y='line 1 - line2' + y="line 1 + line2" foobar ) && ( -# LINT: apostrophe (in a contraction) within string not misinterpreted as -# LINT: starting multi-line single-quoted string - echo "there's nothing to see here" && - exit -) && -( echo "xyz" "abc def ghi" && - echo 'xyz' 'abc - def - ghi' && - echo 'xyz' "abc - def - ghi" && barfoo ) diff --git a/t/chainlint/negated-one-liner.expect b/t/chainlint/negated-one-liner.expect index cf18429d03..ad4c2d949e 100644 --- a/t/chainlint/negated-one-liner.expect +++ b/t/chainlint/negated-one-liner.expect @@ -1,5 +1,5 @@ ! (foo && bar) && ! (foo && bar) >baz && -?!SEMI?!! (foo; bar) && -?!SEMI?!! (foo; bar) >baz +! (foo; ?!AMP?! bar) && +! (foo; ?!AMP?! bar) >baz diff --git a/t/chainlint/nested-cuddled-subshell.expect b/t/chainlint/nested-cuddled-subshell.expect index c2a59ffc33..2a86885ee6 100644 --- a/t/chainlint/nested-cuddled-subshell.expect +++ b/t/chainlint/nested-cuddled-subshell.expect @@ -1,19 +1,19 @@ ( (cd foo && bar ->> ) && + ) && (cd foo && bar -?!AMP?!>> ) + ) ?!AMP?! ( cd foo && ->> bar) && + bar) && ( cd foo && -?!AMP?!>> bar) + bar) ?!AMP?! (cd foo && ->> bar) && + bar) && (cd foo && -?!AMP?!>> bar) + bar) ?!AMP?! foobar ->) +) diff --git a/t/chainlint/nested-here-doc.expect b/t/chainlint/nested-here-doc.expect index 0c9ef1cfc6..e3bef63f75 100644 --- a/t/chainlint/nested-here-doc.expect +++ b/t/chainlint/nested-here-doc.expect @@ -1,7 +1,7 @@ -cat >foop && +cat <<ARBITRARY >foop && ( - cat && -?!AMP?! cat + cat <<-INPUT_END && + cat <<-EOT ?!AMP?! foobar ->) +) diff --git a/t/chainlint/nested-subshell-comment.expect b/t/chainlint/nested-subshell-comment.expect index 15b68d4373..be4b27a305 100644 --- a/t/chainlint/nested-subshell-comment.expect +++ b/t/chainlint/nested-subshell-comment.expect @@ -2,10 +2,8 @@ foo && ( bar && - # bottles wobble while fiddles gobble - # minor numbers of cows (or do they?) baz && snaff -?!AMP?!>> ) + ) ?!AMP?! fuzzy ->) +) diff --git a/t/chainlint/nested-subshell-comment.test b/t/chainlint/nested-subshell-comment.test index 0ff136ab3c..0215cdb192 100644 --- a/t/chainlint/nested-subshell-comment.test +++ b/t/chainlint/nested-subshell-comment.test @@ -7,7 +7,7 @@ # minor numbers of cows (or do they?) baz && snaff -# LINT: missing "&&" on ')' +# LINT: missing "&&" on ")" ) fuzzy ) diff --git a/t/chainlint/nested-subshell.expect b/t/chainlint/nested-subshell.expect index c8165ad19e..41a48adaa2 100644 --- a/t/chainlint/nested-subshell.expect +++ b/t/chainlint/nested-subshell.expect @@ -3,10 +3,10 @@ ( echo a && echo b ->> ) >file && + ) >file && cd foo && ( echo a echo b ->> ) >file ->) + ) >file +) diff --git a/t/chainlint/nested-subshell.test b/t/chainlint/nested-subshell.test index 998b05a47d..440ee9992d 100644 --- a/t/chainlint/nested-subshell.test +++ b/t/chainlint/nested-subshell.test @@ -7,7 +7,6 @@ cd foo && ( -# LINT: nested multi-line subshell not presently checked for missing "&&" echo a echo b ) >file diff --git a/t/chainlint/not-heredoc.expect b/t/chainlint/not-heredoc.expect new file mode 100644 index 0000000000..2e9bb135fe --- /dev/null +++ b/t/chainlint/not-heredoc.expect @@ -0,0 +1,14 @@ +echo "<<<<<<< ours" && +echo ourside && +echo "=======" && +echo theirside && +echo ">>>>>>> theirs" && + +( + echo "<<<<<<< ours" && + echo ourside && + echo "=======" && + echo theirside && + echo ">>>>>>> theirs" ?!AMP?! + poodle +) >merged diff --git a/t/chainlint/not-heredoc.test b/t/chainlint/not-heredoc.test new file mode 100644 index 0000000000..9aa57346cd --- /dev/null +++ b/t/chainlint/not-heredoc.test @@ -0,0 +1,16 @@ +# LINT: "<< ours" inside string is not here-doc +echo "<<<<<<< ours" && +echo ourside && +echo "=======" && +echo theirside && +echo ">>>>>>> theirs" && + +( +# LINT: "<< ours" inside string is not here-doc + echo "<<<<<<< ours" && + echo ourside && + echo "=======" && + echo theirside && + echo ">>>>>>> theirs" + poodle +) >merged diff --git a/t/chainlint/one-liner.expect b/t/chainlint/one-liner.expect index 237f227349..57a7a444c1 100644 --- a/t/chainlint/one-liner.expect +++ b/t/chainlint/one-liner.expect @@ -2,8 +2,8 @@ (foo && bar) | (foo && bar) >baz && -?!SEMI?!(foo; bar) && -?!SEMI?!(foo; bar) | -?!SEMI?!(foo; bar) >baz +(foo; ?!AMP?! bar) && +(foo; ?!AMP?! bar) | +(foo; ?!AMP?! bar) >baz && (foo "bar; baz") diff --git a/t/chainlint/one-liner.test b/t/chainlint/one-liner.test index ec9acb9825..be9858fa29 100644 --- a/t/chainlint/one-liner.test +++ b/t/chainlint/one-liner.test @@ -3,10 +3,10 @@ (foo && bar) | (foo && bar) >baz && -# LINT: top-level one-liner subshell missing internal "&&" +# LINT: top-level one-liner subshell missing internal "&&" and broken &&-chain (foo; bar) && (foo; bar) | -(foo; bar) >baz +(foo; bar) >baz && # LINT: ";" in string not misinterpreted as broken &&-chain (foo "bar; baz") diff --git a/t/chainlint/p4-filespec.expect b/t/chainlint/p4-filespec.expect index 98b3d881fd..1290fd1ff2 100644 --- a/t/chainlint/p4-filespec.expect +++ b/t/chainlint/p4-filespec.expect @@ -1,4 +1,4 @@ ( p4 print -1 //depot/fiddle#42 >file && foobar ->) +) diff --git a/t/chainlint/pipe.expect b/t/chainlint/pipe.expect index 211b901dbc..2cfc028297 100644 --- a/t/chainlint/pipe.expect +++ b/t/chainlint/pipe.expect @@ -3,6 +3,6 @@ bar | baz && fish | -?!AMP?! cow + cow ?!AMP?! sunder ->) +) diff --git a/t/chainlint/pipe.test b/t/chainlint/pipe.test index e6af4de916..dd82534c66 100644 --- a/t/chainlint/pipe.test +++ b/t/chainlint/pipe.test @@ -4,7 +4,7 @@ bar | baz && -# LINT: final line of pipe sequence ('cow') lacking "&&" +# LINT: final line of pipe sequence ("cow") lacking "&&" fish | cow diff --git a/t/chainlint/semicolon.expect b/t/chainlint/semicolon.expect index 1d79384606..ed0b3707ae 100644 --- a/t/chainlint/semicolon.expect +++ b/t/chainlint/semicolon.expect @@ -1,20 +1,19 @@ ( -?!AMP?!?!SEMI?! cat foo ; echo bar -?!SEMI?! cat foo ; echo bar ->) && + cat foo ; ?!AMP?! echo bar ?!AMP?! + cat foo ; ?!AMP?! echo bar +) && ( -?!SEMI?! cat foo ; echo bar && -?!SEMI?! cat foo ; echo bar ->) && + cat foo ; ?!AMP?! echo bar && + cat foo ; ?!AMP?! echo bar +) && ( echo "foo; bar" && -?!SEMI?! cat foo; echo bar ->) && + cat foo; ?!AMP?! echo bar +) && ( -?!SEMI?! foo; ->) && -( -cd foo && + foo; +) && +(cd foo && for i in a b c; do -?!SEMI?! echo; -> done) + echo; + done) diff --git a/t/chainlint/semicolon.test b/t/chainlint/semicolon.test index d82c8ebbc0..67e1192c50 100644 --- a/t/chainlint/semicolon.test +++ b/t/chainlint/semicolon.test @@ -15,11 +15,11 @@ cat foo; echo bar ) && ( -# LINT: unnecessary terminating semicolon +# LINT: semicolon unnecessary but legitimate foo; ) && (cd foo && for i in a b c; do -# LINT: unnecessary terminating semicolon +# LINT: semicolon unnecessary but legitimate echo; done) diff --git a/t/chainlint/subshell-here-doc.expect b/t/chainlint/subshell-here-doc.expect index 74723e7340..029d129299 100644 --- a/t/chainlint/subshell-here-doc.expect +++ b/t/chainlint/subshell-here-doc.expect @@ -1,11 +1,10 @@ ( - echo wobba gorgo snoot wafta snurb && -?!AMP?! cat >bip - echo >bop ->) && + echo wobba gorgo snoot wafta snurb <<-EOF && + cat <<EOF >bip ?!AMP?! + echo <<-EOF >bop +) && ( - cat >bup && - cat >bup2 && - cat >bup3 && + cat <<-ARBITRARY >bup && + cat <<-ARBITRARY3 >bup3 && meep ->) +) diff --git a/t/chainlint/subshell-here-doc.test b/t/chainlint/subshell-here-doc.test index f6b3ba4214..d40eb65583 100644 --- a/t/chainlint/subshell-here-doc.test +++ b/t/chainlint/subshell-here-doc.test @@ -8,10 +8,10 @@ nevermore... EOF -# LINT: missing "&&" on 'cat' +# LINT: missing "&&" on "cat" cat <<EOF >bip fish fly high - EOF +EOF # LINT: swallow here-doc (EOF is last line of subshell) echo <<-\EOF >bop @@ -27,10 +27,6 @@ glink FIZZ ARBITRARY - cat <<-'ARBITRARY2' >bup2 && - glink - FIZZ - ARBITRARY2 cat <<-"ARBITRARY3" >bup3 && glink FIZZ diff --git a/t/chainlint/subshell-one-liner.expect b/t/chainlint/subshell-one-liner.expect index 51162821d7..b7015361bf 100644 --- a/t/chainlint/subshell-one-liner.expect +++ b/t/chainlint/subshell-one-liner.expect @@ -2,13 +2,13 @@ (foo && bar) && (foo && bar) | (foo && bar) >baz && -?!SEMI?! (foo; bar) && -?!SEMI?! (foo; bar) | -?!SEMI?! (foo; bar) >baz && + (foo; ?!AMP?! bar) && + (foo; ?!AMP?! bar) | + (foo; ?!AMP?! bar) >baz && (foo || exit 1) && (foo || exit 1) | (foo || exit 1) >baz && -?!AMP?! (foo && bar) -?!AMP?!?!SEMI?! (foo && bar; baz) + (foo && bar) ?!AMP?! + (foo && bar; ?!AMP?! baz) ?!AMP?! foobar ->) +) diff --git a/t/chainlint/t7900-subtree.expect b/t/chainlint/t7900-subtree.expect index c9913429e6..1cccc7bf7e 100644 --- a/t/chainlint/t7900-subtree.expect +++ b/t/chainlint/t7900-subtree.expect @@ -1,10 +1,10 @@ ( chks="sub1sub2sub3sub4" && - chks_sub=$(cat | sed 's,^,sub dir/,' ->>) && + chks_sub=$(cat <<TXT | sed "s,^,sub dir/," +) && chkms="main-sub1main-sub2main-sub3main-sub4" && - chkms_sub=$(cat | sed 's,^,sub dir/,' ->>) && + chkms_sub=$(cat <<TXT | sed "s,^,sub dir/," +) && subfiles=$(git ls-files) && check_equal "$subfiles" "$chkms$chks" ->) +) diff --git a/t/chainlint/t7900-subtree.test b/t/chainlint/t7900-subtree.test index 277d8358df..02f3129232 100644 --- a/t/chainlint/t7900-subtree.test +++ b/t/chainlint/t7900-subtree.test @@ -3,7 +3,7 @@ sub2 sub3 sub4" && - chks_sub=$(cat <<TXT | sed 's,^,sub dir/,' + chks_sub=$(cat <<TXT | sed "s,^,sub dir/," $chks TXT ) && @@ -11,7 +11,7 @@ TXT main-sub2 main-sub3 main-sub4" && - chkms_sub=$(cat <<TXT | sed 's,^,sub dir/,' + chkms_sub=$(cat <<TXT | sed "s,^,sub dir/," $chkms TXT ) && diff --git a/t/chainlint/while-loop.expect b/t/chainlint/while-loop.expect index 13cff2c0a5..0d3a9b3d12 100644 --- a/t/chainlint/while-loop.expect +++ b/t/chainlint/while-loop.expect @@ -1,11 +1,11 @@ ( while true do -?!AMP?! echo foo - cat -?!AMP?! done + echo foo ?!AMP?! + cat <<-EOF + done ?!AMP?! while true; do echo foo && cat bar done ->) +) diff --git a/t/chainlint/while-loop.test b/t/chainlint/while-loop.test index f1df085bf0..d09fb016e4 100644 --- a/t/chainlint/while-loop.test +++ b/t/chainlint/while-loop.test @@ -1,17 +1,17 @@ ( -# LINT: 'while, 'do', 'done' do not need "&&" +# LINT: "while", "do", "done" do not need "&&" while true do -# LINT: missing "&&" on 'echo' +# LINT: missing "&&" on "echo" echo foo # LINT: last statement of while does not need "&&" cat <<-\EOF bar EOF -# LINT: missing "&&" on 'done' +# LINT: missing "&&" on "done" done -# LINT: 'do' on same line as 'while' +# LINT: "do" on same line as "while" while true; do echo foo && cat bar diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c index 24dd4bec08..3e4ddaee70 100644 --- a/t/helper/test-ref-store.c +++ b/t/helper/test-ref-store.c @@ -269,7 +269,7 @@ static int cmd_delete_ref(struct ref_store *refs, const char **argv) struct object_id old_oid; if (get_oid_hex(sha1_buf, &old_oid)) - die("not sha-1"); + die("cannot parse %s as %s", sha1_buf, the_hash_algo->name); return refs_delete_ref(refs, msg, refname, &old_oid, flags); } @@ -284,9 +284,10 @@ static int cmd_update_ref(struct ref_store *refs, const char **argv) struct object_id old_oid; struct object_id new_oid; - if (get_oid_hex(old_sha1_buf, &old_oid) || - get_oid_hex(new_sha1_buf, &new_oid)) - die("not sha-1"); + if (get_oid_hex(old_sha1_buf, &old_oid)) + die("cannot parse %s as %s", old_sha1_buf, the_hash_algo->name); + if (get_oid_hex(new_sha1_buf, &new_oid)) + die("cannot parse %s as %s", new_sha1_buf, the_hash_algo->name); return refs_update_ref(refs, msg, refname, &new_oid, &old_oid, diff --git a/t/helper/test-trace2.c b/t/helper/test-trace2.c index f93633f895..59b124bb5f 100644 --- a/t/helper/test-trace2.c +++ b/t/helper/test-trace2.c @@ -262,8 +262,9 @@ static int print_usage(void) * [] the "cmd_name" event has been generated. * [] this writes various "def_param" events for interesting config values. * - * We further assume that if we return (rather than exit()), trace2_cmd_exit() - * will be called by test-tool.c:cmd_main(). + * We return from here and let test-tool.c::cmd_main() pass the exit + * code to common-main.c::main(), which will use it to call + * trace2_cmd_exit(). */ int cmd__trace2(int argc, const char **argv) { diff --git a/t/lib-pager.sh b/t/lib-pager.sh index 3aa7a3ffd8..e5eb28df4e 100644 --- a/t/lib-pager.sh +++ b/t/lib-pager.sh @@ -3,7 +3,7 @@ test_expect_success 'determine default pager' ' test_might_fail git config --unset core.pager && less=$( - unset PAGER GIT_PAGER; + sane_unset PAGER GIT_PAGER && git var GIT_PAGER ) && test -n "$less" diff --git a/t/perf/p0005-status.sh b/t/perf/p0005-status.sh index 0b0aa9858f..ca58d6c9b5 100755 --- a/t/perf/p0005-status.sh +++ b/t/perf/p0005-status.sh @@ -24,17 +24,17 @@ test_perf_default_repo test_expect_success "setup repo" ' if git rev-parse --verify refs/heads/p0006-ballast^{commit} then - echo Assuming synthetic repo from many-files.sh - git branch br_base master - git branch br_ballast p0006-ballast - git config --local core.sparsecheckout 1 + echo Assuming synthetic repo from many-files.sh && + git branch br_base master && + git branch br_ballast p0006-ballast && + git config --local core.sparsecheckout 1 && cat >.git/info/sparse-checkout <<-EOF /* !ballast/* EOF else - echo Assuming non-synthetic repo... - git branch br_base $(git rev-list HEAD | tail -n 1) + echo Assuming non-synthetic repo... && + git branch br_base $(git rev-list HEAD | tail -n 1) && git branch br_ballast HEAD fi && git checkout -q br_ballast && diff --git a/t/perf/p0006-read-tree-checkout.sh b/t/perf/p0006-read-tree-checkout.sh index 78cc23fe2f..900b385c4b 100755 --- a/t/perf/p0006-read-tree-checkout.sh +++ b/t/perf/p0006-read-tree-checkout.sh @@ -24,21 +24,21 @@ test_perf_default_repo test_expect_success "setup repo" ' if git rev-parse --verify refs/heads/p0006-ballast^{commit} then - echo Assuming synthetic repo from many-files.sh - git branch br_base master - git branch br_ballast p0006-ballast^ - git branch br_ballast_alias p0006-ballast^ - git branch br_ballast_plus_1 p0006-ballast - git config --local core.sparsecheckout 1 + echo Assuming synthetic repo from many-files.sh && + git branch br_base master && + git branch br_ballast p0006-ballast^ && + git branch br_ballast_alias p0006-ballast^ && + git branch br_ballast_plus_1 p0006-ballast && + git config --local core.sparsecheckout 1 && cat >.git/info/sparse-checkout <<-EOF /* !ballast/* EOF else - echo Assuming non-synthetic repo... - git branch br_base $(git rev-list HEAD | tail -n 1) - git branch br_ballast HEAD^ || error "no ancestor commit from current head" - git branch br_ballast_alias HEAD^ + echo Assuming non-synthetic repo... && + git branch br_base $(git rev-list HEAD | tail -n 1) && + git branch br_ballast HEAD^ || error "no ancestor commit from current head" && + git branch br_ballast_alias HEAD^ && git branch br_ballast_plus_1 HEAD fi && git checkout -q br_ballast && diff --git a/t/perf/p0007-write-cache.sh b/t/perf/p0007-write-cache.sh index 09595264f0..25d8ff7443 100755 --- a/t/perf/p0007-write-cache.sh +++ b/t/perf/p0007-write-cache.sh @@ -9,8 +9,8 @@ test_perf_default_repo test_expect_success "setup repo" ' if git rev-parse --verify refs/heads/p0006-ballast^{commit} then - echo Assuming synthetic repo from many-files.sh - git config --local core.sparsecheckout 1 + echo Assuming synthetic repo from many-files.sh && + git config --local core.sparsecheckout 1 && cat >.git/info/sparse-checkout <<-EOF /* !ballast/* diff --git a/t/perf/p0100-globbing.sh b/t/perf/p0100-globbing.sh index dd18a9ce2b..439e9c8e3c 100755 --- a/t/perf/p0100-globbing.sh +++ b/t/perf/p0100-globbing.sh @@ -19,9 +19,9 @@ test_expect_success 'setup' ' printf "a" >>refname && for j in $(test_seq 1 $i) do - printf "a*" >>refglob.$i + printf "a*" >>refglob.$i || return 1 done && - echo b >>refglob.$i + echo b >>refglob.$i || return 1 done && test_commit test $(cat refname).t "" $(cat refname).t ' diff --git a/t/perf/p1400-update-ref.sh b/t/perf/p1400-update-ref.sh index dda8a74866..a75969cbb1 100755 --- a/t/perf/p1400-update-ref.sh +++ b/t/perf/p1400-update-ref.sh @@ -13,7 +13,7 @@ test_expect_success "setup" ' do printf "start\ncreate refs/heads/%d PRE\ncommit\n" $i && printf "start\nupdate refs/heads/%d POST PRE\ncommit\n" $i && - printf "start\ndelete refs/heads/%d POST\ncommit\n" $i + printf "start\ndelete refs/heads/%d POST\ncommit\n" $i || return 1 done >instructions ' @@ -22,7 +22,7 @@ test_perf "update-ref" ' do git update-ref refs/heads/branch PRE && git update-ref refs/heads/branch POST PRE && - git update-ref -d refs/heads/branch + git update-ref -d refs/heads/branch || return 1 done ' diff --git a/t/perf/p1451-fsck-skip-list.sh b/t/perf/p1451-fsck-skip-list.sh index c2b97d2487..f767d834f2 100755 --- a/t/perf/p1451-fsck-skip-list.sh +++ b/t/perf/p1451-fsck-skip-list.sh @@ -15,7 +15,7 @@ test_expect_success "setup $n bad commits" ' echo "committer C <c@example.com> 1234567890 +0000" && echo "data <<EOF" && echo "$i.Q." && - echo "EOF" + echo "EOF" || return 1 done | q_to_nul | git fast-import ' diff --git a/t/perf/p3400-rebase.sh b/t/perf/p3400-rebase.sh index 43d5a34e8c..e6b0277729 100755 --- a/t/perf/p3400-rebase.sh +++ b/t/perf/p3400-rebase.sh @@ -22,7 +22,7 @@ test_expect_success 'setup rebasing on top of a lot of changes' ' git add unrelated-file$i && test_tick && git commit -m commit$i-reverse unrelated-file$i || - break + return 1 done && git checkout to-rebase && test_commit our-patch interesting-file diff --git a/t/perf/p4002-diff-color-moved.sh b/t/perf/p4002-diff-color-moved.sh new file mode 100755 index 0000000000..ab2af931c0 --- /dev/null +++ b/t/perf/p4002-diff-color-moved.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +test_description='Tests diff --color-moved performance' +. ./perf-lib.sh + +test_perf_default_repo + +# The endpoints of the diff can be customized by setting TEST_REV_A +# and TEST_REV_B in the environment when running this test. + +rev="${TEST_REV_A:-v2.28.0}" +if ! rev_a="$(git rev-parse --quiet --verify "$rev")" +then + skip_all="skipping because '$rev' was not found. \ + Use TEST_REV_A and TEST_REV_B to set the revs to use" + test_done +fi +rev="${TEST_REV_B:-v2.29.0}" +if ! rev_b="$(git rev-parse --quiet --verify "$rev")" +then + skip_all="skipping because '$rev' was not found. \ + Use TEST_REV_A and TEST_REV_B to set the revs to use" + test_done +fi + +GIT_PAGER_IN_USE=1 +test_export GIT_PAGER_IN_USE rev_a rev_b + +test_perf 'diff --no-color-moved --no-color-moved-ws large change' ' + git diff --no-color-moved --no-color-moved-ws $rev_a $rev_b +' + +test_perf 'diff --color-moved --no-color-moved-ws large change' ' + git diff --color-moved=zebra --no-color-moved-ws $rev_a $rev_b +' + +test_perf 'diff --color-moved-ws=allow-indentation-change large change' ' + git diff --color-moved=zebra --color-moved-ws=allow-indentation-change \ + $rev_a $rev_b +' + +test_perf 'log --no-color-moved --no-color-moved-ws' ' + git log --no-color-moved --no-color-moved-ws --no-merges --patch \ + -n1000 $rev_b +' + +test_perf 'log --color-moved --no-color-moved-ws' ' + git log --color-moved=zebra --no-color-moved-ws --no-merges --patch \ + -n1000 $rev_b +' + +test_perf 'log --color-moved-ws=allow-indentation-change' ' + git log --color-moved=zebra --color-moved-ws=allow-indentation-change \ + --no-merges --patch -n1000 $rev_b +' + +test_done diff --git a/t/perf/p5302-pack-index.sh b/t/perf/p5302-pack-index.sh index 228593d9ad..c16f6a3ff6 100755 --- a/t/perf/p5302-pack-index.sh +++ b/t/perf/p5302-pack-index.sh @@ -21,8 +21,8 @@ test_expect_success 'set up thread-counting tests' ' threads= && while test $t -gt 0 do - threads="$t $threads" - t=$((t / 2)) + threads="$t $threads" && + t=$((t / 2)) || return 1 done ' diff --git a/t/perf/p5303-many-packs.sh b/t/perf/p5303-many-packs.sh index 35c0cbdf49..af173a7b73 100755 --- a/t/perf/p5303-many-packs.sh +++ b/t/perf/p5303-many-packs.sh @@ -126,11 +126,11 @@ done # Measure pack loading with 10,000 packs. test_expect_success 'generate lots of packs' ' for i in $(test_seq 10000); do - echo "blob" - echo "data <<EOF" - echo "blob $i" - echo "EOF" - echo "checkpoint" + echo "blob" && + echo "data <<EOF" && + echo "blob $i" && + echo "EOF" && + echo "checkpoint" || return 1 done | git -c fastimport.unpackLimit=0 fast-import ' diff --git a/t/perf/p7519-fsmonitor.sh b/t/perf/p7519-fsmonitor.sh index 5eb5044a10..c8be58f3c7 100755 --- a/t/perf/p7519-fsmonitor.sh +++ b/t/perf/p7519-fsmonitor.sh @@ -119,10 +119,10 @@ test_expect_success "one time repo setup" ' fi && mkdir 1_file 10_files 100_files 1000_files 10000_files && - for i in $(test_seq 1 10); do touch 10_files/$i; done && - for i in $(test_seq 1 100); do touch 100_files/$i; done && - for i in $(test_seq 1 1000); do touch 1000_files/$i; done && - for i in $(test_seq 1 10000); do touch 10000_files/$i; done && + for i in $(test_seq 1 10); do touch 10_files/$i || return 1; done && + for i in $(test_seq 1 100); do touch 100_files/$i || return 1; done && + for i in $(test_seq 1 1000); do touch 1000_files/$i || return 1; done && + for i in $(test_seq 1 10000); do touch 10000_files/$i || return 1; done && git add 1_file 10_files 100_files 1000_files 10000_files && git commit -qm "Add files" && diff --git a/t/perf/perf-lib.sh b/t/perf/perf-lib.sh index 780a7402d5..407252bac7 100644 --- a/t/perf/perf-lib.sh +++ b/t/perf/perf-lib.sh @@ -161,7 +161,7 @@ test_run_perf_ () { test_cleanup=: test_export_="test_cleanup" export test_cleanup test_export_ - "$GTIME" -f "%E %U %S" -o test_time.$i "$SHELL" -c ' + "$GTIME" -f "%E %U %S" -o test_time.$i "$TEST_SHELL_PATH" -c ' . '"$TEST_DIRECTORY"/test-lib-functions.sh' test_export () { test_export_="$test_export_ $*" diff --git a/t/t0005-signals.sh b/t/t0005-signals.sh index a5ec6a0315..eba75a2490 100755 --- a/t/t0005-signals.sh +++ b/t/t0005-signals.sh @@ -48,7 +48,7 @@ test_expect_success !MINGW 'a constipated git dies with SIGPIPE' ' ' test_expect_success !MINGW 'a constipated git dies with SIGPIPE even if parent ignores it' ' - OUT=$( ((trap "" PIPE; large_git; echo $? 1>&3) | :) 3>&1 ) && + OUT=$( ((trap "" PIPE && large_git; echo $? 1>&3) | :) 3>&1 ) && test_match_signal 13 "$OUT" ' diff --git a/t/t0008-ignores.sh b/t/t0008-ignores.sh index 42d2314804..5575dade8e 100755 --- a/t/t0008-ignores.sh +++ b/t/t0008-ignores.sh @@ -200,7 +200,7 @@ test_expect_success 'setup' ' do : >$dir/not-ignored && : >$dir/ignored-and-untracked && - : >$dir/ignored-but-in-index + : >$dir/ignored-but-in-index || return 1 done && git add -f ignored-but-in-index a/ignored-but-in-index && cat <<-\EOF >a/.gitignore && diff --git a/t/t0011-hashmap.sh b/t/t0011-hashmap.sh index e094975b13..1cb6aa6824 100755 --- a/t/t0011-hashmap.sh +++ b/t/t0011-hashmap.sh @@ -220,7 +220,7 @@ test_expect_success 'grow / shrink' ' for n in $(test_seq 51) do echo put key$n value$n >> in && - echo NULL >> expect + echo NULL >> expect || return 1 done && echo size >> in && echo 64 51 >> expect && @@ -231,7 +231,7 @@ test_expect_success 'grow / shrink' ' for n in $(test_seq 12) do echo remove key$n >> in && - echo value$n >> expect + echo value$n >> expect || return 1 done && echo size >> in && echo 256 40 >> expect && diff --git a/t/t0020-crlf.sh b/t/t0020-crlf.sh index 4125ab8b88..35cc8c3b39 100755 --- a/t/t0020-crlf.sh +++ b/t/t0020-crlf.sh @@ -23,10 +23,10 @@ test_expect_success setup ' git config core.autocrlf false && - for w in Hello world how are you; do echo $w; done >one && + test_write_lines Hello world how are you >one && mkdir dir && - for w in I am very very fine thank you; do echo $w; done >dir/two && - for w in Oh here is NULQin text here; do echo $w; done | q_to_nul >three && + test_write_lines I am very very fine thank you >dir/two && + test_write_lines Oh here is NULQin text here | q_to_nul >three && git add . && git commit -m initial && @@ -36,7 +36,7 @@ test_expect_success setup ' two=$(git rev-parse HEAD:dir/two) && three=$(git rev-parse HEAD:three) && - for w in Some extra lines here; do echo $w; done >>one && + test_write_lines Some extra lines here >>one && git diff >patch.file && patched=$(git hash-object --stdin <one) && git read-tree --reset -u HEAD @@ -47,7 +47,7 @@ test_expect_success 'safecrlf: autocrlf=input, all CRLF' ' git config core.autocrlf input && git config core.safecrlf true && - for w in I am all CRLF; do echo $w; done | append_cr >allcrlf && + test_write_lines I am all CRLF | append_cr >allcrlf && test_must_fail git add allcrlf ' @@ -56,7 +56,7 @@ test_expect_success 'safecrlf: autocrlf=input, mixed LF/CRLF' ' git config core.autocrlf input && git config core.safecrlf true && - for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >mixed && + test_write_lines Oh here is CRLFQ in text | q_to_cr >mixed && test_must_fail git add mixed ' @@ -65,7 +65,7 @@ test_expect_success 'safecrlf: autocrlf=true, all LF' ' git config core.autocrlf true && git config core.safecrlf true && - for w in I am all LF; do echo $w; done >alllf && + test_write_lines I am all LF >alllf && test_must_fail git add alllf ' @@ -74,7 +74,7 @@ test_expect_success 'safecrlf: autocrlf=true mixed LF/CRLF' ' git config core.autocrlf true && git config core.safecrlf true && - for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >mixed && + test_write_lines Oh here is CRLFQ in text | q_to_cr >mixed && test_must_fail git add mixed ' @@ -83,10 +83,10 @@ test_expect_success 'safecrlf: print warning only once' ' git config core.autocrlf input && git config core.safecrlf warn && - for w in I am all LF; do echo $w; done >doublewarn && + test_write_lines I am all LF >doublewarn && git add doublewarn && git commit -m "nowarn" && - for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >doublewarn && + test_write_lines Oh here is CRLFQ in text | q_to_cr >doublewarn && git add doublewarn 2>err && grep "CRLF will be replaced by LF" err >err.warnings && test_line_count = 1 err.warnings @@ -104,7 +104,7 @@ test_expect_success 'safecrlf: no warning with safecrlf=false' ' git config core.autocrlf input && git config core.safecrlf false && - for w in I am all CRLF; do echo $w; done | append_cr >allcrlf && + test_write_lines I am all CRLF | append_cr >allcrlf && git add allcrlf 2>err && test_must_be_empty err ' @@ -352,9 +352,9 @@ test_expect_success 'setting up for new autocrlf tests' ' git config core.autocrlf false && git config core.safecrlf false && rm -rf .????* * && - for w in I am all LF; do echo $w; done >alllf && - for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >mixed && - for w in I am all CRLF; do echo $w; done | append_cr >allcrlf && + test_write_lines I am all LF >alllf && + test_write_lines Oh here is CRLFQ in text | q_to_cr >mixed && + test_write_lines I am all CRLF | append_cr >allcrlf && git add -A . && git commit -m "alllf, allcrlf and mixed only" && git tag -a -m "message" autocrlf-checkpoint diff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh index 33dfc9cd56..bad37abad2 100755 --- a/t/t0021-conversion.sh +++ b/t/t0021-conversion.sh @@ -76,13 +76,13 @@ test_expect_success setup ' git config filter.rot13.clean ./rot13.sh && { - echo "*.t filter=rot13" + echo "*.t filter=rot13" && echo "*.i ident" } >.gitattributes && { - echo a b c d e f g h i j k l m - echo n o p q r s t u v w x y z + echo a b c d e f g h i j k l m && + echo n o p q r s t u v w x y z && echo '\''$Id$'\'' } >test && cat test >test.t && @@ -118,17 +118,17 @@ test_expect_success check ' # If an expanded ident ever gets into the repository, we want to make sure that # it is collapsed before being expanded again on checkout test_expect_success expanded_in_repo ' - { - echo "File with expanded keywords" - echo "\$Id\$" - echo "\$Id:\$" - echo "\$Id: 0000000000000000000000000000000000000000 \$" - echo "\$Id: NoSpaceAtEnd\$" - echo "\$Id:NoSpaceAtFront \$" - echo "\$Id:NoSpaceAtEitherEnd\$" - echo "\$Id: NoTerminatingSymbol" - echo "\$Id: Foreign Commit With Spaces \$" - } >expanded-keywords.0 && + cat >expanded-keywords.0 <<-\EOF && + File with expanded keywords + $Id$ + $Id:$ + $Id: 0000000000000000000000000000000000000000 $ + $Id: NoSpaceAtEnd$ + $Id:NoSpaceAtFront $ + $Id:NoSpaceAtEitherEnd$ + $Id: NoTerminatingSymbol + $Id: Foreign Commit With Spaces $ + EOF { cat expanded-keywords.0 && @@ -139,17 +139,17 @@ test_expect_success expanded_in_repo ' git commit -m "File with keywords expanded" && id=$(git rev-parse --verify :expanded-keywords) && - { - echo "File with expanded keywords" - echo "\$Id: $id \$" - echo "\$Id: $id \$" - echo "\$Id: $id \$" - echo "\$Id: $id \$" - echo "\$Id: $id \$" - echo "\$Id: $id \$" - echo "\$Id: NoTerminatingSymbol" - echo "\$Id: Foreign Commit With Spaces \$" - } >expected-output.0 && + cat >expected-output.0 <<-EOF && + File with expanded keywords + \$Id: $id \$ + \$Id: $id \$ + \$Id: $id \$ + \$Id: $id \$ + \$Id: $id \$ + \$Id: $id \$ + \$Id: NoTerminatingSymbol + \$Id: Foreign Commit With Spaces \$ + EOF { cat expected-output.0 && printf "\$Id: NoTerminatingSymbolAtEOF" @@ -159,7 +159,7 @@ test_expect_success expanded_in_repo ' printf "\$Id: NoTerminatingSymbolAtEOF" } >expected-output-crlf && { - echo "expanded-keywords ident" + echo "expanded-keywords ident" && echo "expanded-keywords-crlf ident text eol=crlf" } >>.gitattributes && @@ -285,7 +285,7 @@ test_expect_success 'required filter with absent smudge field' ' test_expect_success 'filtering large input to small output should use little memory' ' test_config filter.devnull.clean "cat >/dev/null" && test_config filter.devnull.required true && - for i in $(test_seq 1 30); do printf "%1048576d" 1; done >30MB && + for i in $(test_seq 1 30); do printf "%1048576d" 1 || return 1; done >30MB && echo "30MB filter=devnull" >.gitattributes && GIT_MMAP_LIMIT=1m GIT_ALLOC_LIMIT=1m git add 30MB ' @@ -303,7 +303,7 @@ test_expect_success 'filter that does not read is fine' ' test_expect_success EXPENSIVE 'filter large file' ' test_config filter.largefile.smudge cat && test_config filter.largefile.clean cat && - for i in $(test_seq 1 2048); do printf "%1048576d" 1; done >2GB && + for i in $(test_seq 1 2048); do printf "%1048576d" 1 || return 1; done >2GB && echo "2GB filter=largefile" >.gitattributes && git add 2GB 2>err && test_must_be_empty err && @@ -643,7 +643,7 @@ test_expect_success PERL 'required process filter should process multiple packet for FILE in "$TEST_ROOT"/*.file do cp "$FILE" . && - rot13.sh <"$FILE" >"$FILE.rot13" + rot13.sh <"$FILE" >"$FILE.rot13" || return 1 done && echo "*.file filter=protocol" >.gitattributes && @@ -682,7 +682,7 @@ test_expect_success PERL 'required process filter should process multiple packet for FILE in *.file do - test_cmp_committed_rot13 "$TEST_ROOT/$FILE" $FILE + test_cmp_committed_rot13 "$TEST_ROOT/$FILE" $FILE || return 1 done ) ' diff --git a/t/t0026-eol-config.sh b/t/t0026-eol-config.sh index cdcafcdff7..f426a185bb 100755 --- a/t/t0026-eol-config.sh +++ b/t/t0026-eol-config.sh @@ -15,8 +15,8 @@ test_expect_success setup ' echo "one text" > .gitattributes && - for w in Hello world how are you; do echo $w; done >one && - for w in I am very very fine thank you; do echo $w; done >two && + test_write_lines Hello world how are you >one && + test_write_lines I am very very fine thank you >two && git add . && git commit -m initial && diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh index 34d1061f32..71a5d370cc 100755 --- a/t/t0060-path-utils.sh +++ b/t/t0060-path-utils.sh @@ -216,7 +216,7 @@ test_expect_success SYMLINKS 'real path works on symlinks' ' mkdir second && ln -s ../first second/other && mkdir third && - dir="$(cd .git; pwd -P)" && + dir="$(cd .git && pwd -P)" && dir2=third/../second/other/.git && test "$dir" = "$(test-tool path-utils real_path $dir2)" && file="$dir"/index && @@ -224,7 +224,7 @@ test_expect_success SYMLINKS 'real path works on symlinks' ' basename=blub && test "$dir/$basename" = "$(cd .git && test-tool path-utils real_path "$basename")" && ln -s ../first/file .git/syml && - sym="$(cd first; pwd -P)"/file && + sym="$(cd first && pwd -P)"/file && test "$sym" = "$(test-tool path-utils real_path "$dir2/syml")" ' diff --git a/t/t0069-oidtree.sh b/t/t0069-oidtree.sh index 74cc59bf8a..889db50818 100755 --- a/t/t0069-oidtree.sh +++ b/t/t0069-oidtree.sh @@ -28,7 +28,7 @@ test_expect_success 'oidtree insert and contains' ' EOF { echoid insert 444 1 2 3 4 5 a b c d e && - echoid contains 44 441 440 444 4440 4444 + echoid contains 44 441 440 444 4440 4444 && echo clear } | test-tool oidtree >actual && test_cmp expect actual @@ -37,11 +37,11 @@ test_expect_success 'oidtree insert and contains' ' test_expect_success 'oidtree each' ' echoid "" 123 321 321 >expect && { - echoid insert f 9 8 123 321 a b c d e - echo each 12300 - echo each 3211 - echo each 3210 - echo each 32100 + echoid insert f 9 8 123 321 a b c d e && + echo each 12300 && + echo each 3211 && + echo each 3210 && + echo each 32100 && echo clear } | test-tool oidtree >actual && test_cmp expect actual diff --git a/t/t0095-bloom.sh b/t/t0095-bloom.sh index 7e4ab1795f..5945973552 100755 --- a/t/t0095-bloom.sh +++ b/t/t0095-bloom.sh @@ -84,7 +84,7 @@ test_expect_success 'get bloom filter for commit with 10 changes' ' mkdir smallDir && for i in $(test_seq 0 9) do - echo $i >smallDir/$i + echo $i >smallDir/$i || return 1 done && git add smallDir && git commit -m "commit with 10 changes" && @@ -102,7 +102,7 @@ test_expect_success EXPENSIVE 'get bloom filter for commit with 513 changes' ' mkdir bigDir && for i in $(test_seq 0 511) do - echo $i >bigDir/$i + echo $i >bigDir/$i || return 1 done && git add bigDir && git commit -m "commit with 513 changes" && diff --git a/t/t0410-partial-clone.sh b/t/t0410-partial-clone.sh index c76485b1b6..f17abd298c 100755 --- a/t/t0410-partial-clone.sh +++ b/t/t0410-partial-clone.sh @@ -469,7 +469,7 @@ test_expect_success 'rev-list dies for missing objects on cmd line' ' git -C repo rev-list --ignore-missing --objects \ --exclude-promisor-objects "$OBJ" && git -C repo rev-list --ignore-missing --objects-edge-aggressive \ - --exclude-promisor-objects "$OBJ" + --exclude-promisor-objects "$OBJ" || return 1 done ' diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh index 0d4c55f74e..39382fa195 100755 --- a/t/t1006-cat-file.sh +++ b/t/t1006-cat-file.sh @@ -211,14 +211,14 @@ done test_expect_success "--batch-check for a non-existent named object" ' test "foobar42 missing foobar84 missing" = \ - "$( ( echo foobar42; echo_without_newline foobar84; ) | git cat-file --batch-check)" + "$( ( echo foobar42 && echo_without_newline foobar84 ) | git cat-file --batch-check)" ' test_expect_success "--batch-check for a non-existent hash" ' test "0000000000000000000000000000000000000042 missing 0000000000000000000000000000000000000084 missing" = \ - "$( ( echo 0000000000000000000000000000000000000042; - echo_without_newline 0000000000000000000000000000000000000084; ) | + "$( ( echo 0000000000000000000000000000000000000042 && + echo_without_newline 0000000000000000000000000000000000000084 ) | git cat-file --batch-check)" ' @@ -226,8 +226,8 @@ test_expect_success "--batch for an existent and a non-existent hash" ' test "$tag_sha1 tag $tag_size $tag_content 0000000000000000000000000000000000000000 missing" = \ - "$( ( echo $tag_sha1; - echo_without_newline 0000000000000000000000000000000000000000; ) | + "$( ( echo $tag_sha1 && + echo_without_newline 0000000000000000000000000000000000000000 ) | git cat-file --batch)" ' @@ -283,7 +283,7 @@ test_expect_success "--batch-check with multiple sha1s gives correct format" ' test_expect_success 'setup blobs which are likely to delta' ' test-tool genrandom foo 10240 >foo && - { cat foo; echo plus; } >foo-plus && + { cat foo && echo plus; } >foo-plus && git add foo foo-plus && git commit -m foo && cat >blobs <<-\EOF diff --git a/t/t1010-mktree.sh b/t/t1010-mktree.sh index 48bfad07ab..3c08194526 100755 --- a/t/t1010-mktree.sh +++ b/t/t1010-mktree.sh @@ -6,10 +6,10 @@ TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup ' - for d in a a. a0 + for d in a a- a0 do mkdir "$d" && echo "$d/one" >"$d/one" && - git add "$d" + git add "$d" || return 1 done && echo zero >one && git update-index --add --info-only one && diff --git a/t/t1020-subdirectory.sh b/t/t1020-subdirectory.sh index c2df75e495..9fdbb2af80 100755 --- a/t/t1020-subdirectory.sh +++ b/t/t1020-subdirectory.sh @@ -11,9 +11,9 @@ test_description='Try various core-level commands in subdirectory. test_expect_success setup ' long="a b c d e f g h i j k l m n o p q r s t u v w x y z" && - for c in $long; do echo $c; done >one && + test_write_lines $long >one && mkdir dir && - for c in x y z $long a b c; do echo $c; done >dir/two && + test_write_lines x y z $long a b c >dir/two && cp one original.one && cp dir/two original.two ' @@ -22,7 +22,7 @@ test_expect_success 'update-index and ls-files' ' git update-index --add one && case "$(git ls-files)" in one) echo pass one ;; - *) echo bad one; exit 1 ;; + *) echo bad one; return 1 ;; esac && ( cd dir && @@ -34,7 +34,7 @@ test_expect_success 'update-index and ls-files' ' ) && case "$(git ls-files)" in dir/two"$LF"one) echo pass both ;; - *) echo bad; exit 1 ;; + *) echo bad; return 1 ;; esac ' @@ -57,7 +57,7 @@ test_expect_success 'diff-files' ' echo d >>dir/two && case "$(git diff-files --name-only)" in dir/two"$LF"one) echo pass top ;; - *) echo bad top; exit 1 ;; + *) echo bad top; return 1 ;; esac && # diff should not omit leading paths ( diff --git a/t/t1050-large.sh b/t/t1050-large.sh index 6bc1d76fb1..4f3aa17c99 100755 --- a/t/t1050-large.sh +++ b/t/t1050-large.sh @@ -51,42 +51,32 @@ EOF test_expect_success 'add a large file or two' ' git add large1 huge large2 && # make sure we got a single packfile and no loose objects - bad= count=0 idx= && + count=0 idx= && for p in .git/objects/pack/pack-*.pack do - count=$(( $count + 1 )) - if test_path_is_file "$p" && - idx=${p%.pack}.idx && test_path_is_file "$idx" - then - continue - fi - bad=t + count=$(( $count + 1 )) && + test_path_is_file "$p" && + idx=${p%.pack}.idx && + test_path_is_file "$idx" || return 1 done && - test -z "$bad" && test $count = 1 && cnt=$(git show-index <"$idx" | wc -l) && test $cnt = 2 && for l in .git/objects/$OIDPATH_REGEX do - test_path_is_file "$l" || continue - bad=t + test_path_is_missing "$l" || return 1 done && - test -z "$bad" && # attempt to add another copy of the same git add large3 && bad= count=0 && for p in .git/objects/pack/pack-*.pack do - count=$(( $count + 1 )) - if test_path_is_file "$p" && - idx=${p%.pack}.idx && test_path_is_file "$idx" - then - continue - fi - bad=t + count=$(( $count + 1 )) && + test_path_is_file "$p" && + idx=${p%.pack}.idx && + test_path_is_file "$idx" || return 1 done && - test -z "$bad" && test $count = 1 ' @@ -115,7 +105,7 @@ test_expect_success 'packsize limit' ' count=0 && for pi in .git/objects/pack/pack-*.idx do - test_path_is_file "$pi" && count=$(( $count + 1 )) + test_path_is_file "$pi" && count=$(( $count + 1 )) || return 1 done && test $count = 2 && @@ -128,7 +118,7 @@ test_expect_success 'packsize limit' ' for pi in .git/objects/pack/pack-*.idx do - git show-index <"$pi" + git show-index <"$pi" || return 1 done | sed -e "s/^[0-9]* \([0-9a-f]*\) .*/\1/" | sort >actual && diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index 272ba1b566..32a6328ddb 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -41,7 +41,15 @@ test_expect_success 'setup' ' ) ' -test_expect_success 'git sparse-checkout list (empty)' ' +test_expect_success 'git sparse-checkout list (not sparse)' ' + test_must_fail git -C repo sparse-checkout list >list 2>err && + test_must_be_empty list && + test_i18ngrep "this worktree is not sparse" err +' + +test_expect_success 'git sparse-checkout list (not sparse)' ' + git -C repo sparse-checkout set && + rm repo/.git/info/sparse-checkout && git -C repo sparse-checkout list >list 2>err && test_must_be_empty list && test_i18ngrep "this worktree is not sparse (sparse-checkout file may not exist)" err @@ -103,6 +111,18 @@ test_expect_success 'clone --sparse' ' check_files clone a ' +test_expect_success 'switching to cone mode with non-cone mode patterns' ' + git init bad-patterns && + ( + cd bad-patterns && + git sparse-checkout init && + git sparse-checkout add dir && + git config core.sparseCheckoutCone true && + test_must_fail git sparse-checkout add dir 2>err && + grep "existing sparse-checkout patterns do not use cone mode" err + ) +' + test_expect_success 'interaction with clone --no-checkout (unborn index)' ' git clone --no-checkout "file://$(pwd)/repo" clone_no_checkout && git -C clone_no_checkout sparse-checkout init --cone && @@ -165,12 +185,14 @@ test_expect_success 'set sparse-checkout using --stdin' ' ' test_expect_success 'add to sparse-checkout' ' - cat repo/.git/info/sparse-checkout >expect && + cat repo/.git/info/sparse-checkout >old && + test_when_finished cp old repo/.git/info/sparse-checkout && cat >add <<-\EOF && pattern1 /folder1/ pattern2 EOF + cat old >expect && cat add >>expect && git -C repo sparse-checkout add --stdin <add && git -C repo sparse-checkout list >actual && @@ -586,7 +608,7 @@ test_expect_success 'pattern-checks: contained glob characters' ' !/*/ something$c-else/ EOF - check_read_tree_errors repo "a" "disabling cone pattern matching" + check_read_tree_errors repo "a" "disabling cone pattern matching" || return 1 done ' @@ -708,4 +730,25 @@ test_expect_success 'cone mode clears ignored subdirectories' ' test_cmp expect out ' +test_expect_success 'malformed cone-mode patterns' ' + git -C repo sparse-checkout init --cone && + mkdir -p repo/foo/bar && + touch repo/foo/bar/x repo/foo/y && + cat >repo/.git/info/sparse-checkout <<-\EOF && + /* + !/*/ + /foo/ + !/foo/*/ + /foo/\*/ + EOF + + # Listing the patterns will notice the duplicate pattern and + # emit a warning. It will list the patterns directly instead + # of using the cone-mode translation to a set of directories. + git -C repo sparse-checkout list >actual 2>err && + test_cmp repo/.git/info/sparse-checkout actual && + grep "warning: your sparse-checkout file may have issues: pattern .* is repeated" err && + grep "warning: disabling cone pattern matching" err +' + test_done diff --git a/t/t1300-config.sh b/t/t1300-config.sh index f8031afaaf..78359f1f4a 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -718,8 +718,8 @@ test_expect_success bool ' rm -f result && for i in 1 2 3 4 do - git config --bool --get bool.true$i >>result - git config --bool --get bool.false$i >>result + git config --bool --get bool.true$i >>result && + git config --bool --get bool.false$i >>result || return 1 done && test_cmp expect result' @@ -902,7 +902,7 @@ test_expect_success 'get --expiry-date' ' EOF : "work around heredoc parsing bug fixed in dash 0.5.7 (in ec2c84d)" && { - echo "$rel_out $(git config --expiry-date date.valid1)" + echo "$rel_out $(git config --expiry-date date.valid1)" && git config --expiry-date date.valid2 && git config --expiry-date date.valid3 && git config --expiry-date date.valid4 && diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index 640659c9d7..cf58cf025c 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -1368,7 +1368,7 @@ test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction creating branches ( for i in $(test_seq 33) do - echo "create refs/heads/$i HEAD" + echo "create refs/heads/$i HEAD" || exit 1 done >large_input && run_with_limited_open_files git update-ref --stdin <large_input && git rev-parse --verify -q refs/heads/33 @@ -1379,7 +1379,7 @@ test_expect_success ULIMIT_FILE_DESCRIPTORS 'large transaction deleting branches ( for i in $(test_seq 33) do - echo "delete refs/heads/$i HEAD" + echo "delete refs/heads/$i HEAD" || exit 1 done >large_input && run_with_limited_open_files git update-ref --stdin <large_input && test_must_fail git rev-parse --verify -q refs/heads/33 diff --git a/t/t1403-show-ref.sh b/t/t1403-show-ref.sh index 4d261e80c6..9252a581ab 100755 --- a/t/t1403-show-ref.sh +++ b/t/t1403-show-ref.sh @@ -79,7 +79,7 @@ test_expect_success 'show-ref --verify -q' ' test_expect_success 'show-ref -d' ' { echo $(git rev-parse refs/tags/A) refs/tags/A && - echo $(git rev-parse refs/tags/A^0) "refs/tags/A^{}" + echo $(git rev-parse refs/tags/A^0) "refs/tags/A^{}" && echo $(git rev-parse refs/tags/C) refs/tags/C } >expect && git show-ref -d A C >actual && @@ -124,14 +124,14 @@ test_expect_success 'show-ref -d' ' test_expect_success 'show-ref --heads, --tags, --head, pattern' ' for branch in B main side do - echo $(git rev-parse refs/heads/$branch) refs/heads/$branch + echo $(git rev-parse refs/heads/$branch) refs/heads/$branch || return 1 done >expect.heads && git show-ref --heads >actual && test_cmp expect.heads actual && for tag in A B C do - echo $(git rev-parse refs/tags/$tag) refs/tags/$tag + echo $(git rev-parse refs/tags/$tag) refs/tags/$tag || return 1 done >expect.tags && git show-ref --tags >actual && test_cmp expect.tags actual && @@ -149,7 +149,7 @@ test_expect_success 'show-ref --heads, --tags, --head, pattern' ' { echo $(git rev-parse HEAD) HEAD && - echo $(git rev-parse refs/heads/B) refs/heads/B + echo $(git rev-parse refs/heads/B) refs/heads/B && echo $(git rev-parse refs/tags/B) refs/tags/B } >expect && git show-ref --head B >actual && @@ -157,8 +157,8 @@ test_expect_success 'show-ref --heads, --tags, --head, pattern' ' { echo $(git rev-parse HEAD) HEAD && - echo $(git rev-parse refs/heads/B) refs/heads/B - echo $(git rev-parse refs/tags/B) refs/tags/B + echo $(git rev-parse refs/heads/B) refs/heads/B && + echo $(git rev-parse refs/tags/B) refs/tags/B && echo $(git rev-parse refs/tags/B^0) "refs/tags/B^{}" } >expect && git show-ref --head -d B >actual && diff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh index d42f067ff8..d7ddf7612d 100755 --- a/t/t1410-reflog.sh +++ b/t/t1410-reflog.sh @@ -349,12 +349,12 @@ test_expect_success SHA1 'parsing reverse reflogs at BUFSIZ boundaries' ' printf "$zf%02d $zf%02d %s\t" $i $(($i+1)) "$ident" && if test $i = 75; then for j in $(test_seq 1 89); do - printf X + printf X || return 1 done else printf X fi && - printf "\n" + printf "\n" || return 1 done >.git/logs/refs/heads/reflogskip && git rev-parse reflogskip@{73} >actual && echo ${zf}03 >expect && diff --git a/t/t1512-rev-parse-disambiguation.sh b/t/t1512-rev-parse-disambiguation.sh index 7891a6becf..b0119bf8bc 100755 --- a/t/t1512-rev-parse-disambiguation.sh +++ b/t/t1512-rev-parse-disambiguation.sh @@ -34,10 +34,7 @@ fi test_expect_success 'blob and tree' ' test_tick && ( - for i in 0 1 2 3 4 5 6 7 8 9 - do - echo $i - done && + test_write_lines 0 1 2 3 4 5 6 7 8 9 && echo && echo b1rwzyc3 ) >a0blgqsjc && @@ -204,10 +201,7 @@ test_expect_success 'more history' ' git checkout v1.0.0^0 && git mv a0blgqsjc f5518nwu && - for i in h62xsjeu j08bekfvt kg7xflhm - do - echo $i - done >>f5518nwu && + test_write_lines h62xsjeu j08bekfvt kg7xflhm >>f5518nwu && git add f5518nwu && test_tick && @@ -387,7 +381,7 @@ test_expect_success 'ambiguous commits are printed by type first, then hash orde do grep $type objects >$type.objects && sort $type.objects >$type.objects.sorted && - test_cmp $type.objects.sorted $type.objects + test_cmp $type.objects.sorted $type.objects || return 1 done ' diff --git a/t/t1700-split-index.sh b/t/t1700-split-index.sh index decd2527ed..b4ab166369 100755 --- a/t/t1700-split-index.sh +++ b/t/t1700-split-index.sh @@ -48,10 +48,10 @@ test_expect_success 'enable split index' ' # NEEDSWORK: Stop hard-coding checksums. if test "$indexversion" = "4" then - own=$(test_oid own_v4) + own=$(test_oid own_v4) && base=$(test_oid base_v4) else - own=$(test_oid own_v3) + own=$(test_oid own_v3) && base=$(test_oid base_v3) fi && diff --git a/t/t2004-checkout-cache-temp.sh b/t/t2004-checkout-cache-temp.sh index 9bb503a975..b16d69ca4a 100755 --- a/t/t2004-checkout-cache-temp.sh +++ b/t/t2004-checkout-cache-temp.sh @@ -57,7 +57,7 @@ test_expect_success 'checkout all stage 0 to temporary files' ' test $(grep $f actual | cut "-d " -f2) = $f && p=$(grep $f actual | cut "-d " -f1) && test -f $p && - test $(cat $p) = tree1$f + test $(cat $p) = tree1$f || return 1 done ' @@ -85,7 +85,7 @@ test_expect_success 'checkout all stage 2 to temporary files' ' test $(grep $f actual | cut "-d " -f2) = $f && p=$(grep $f actual | cut "-d " -f1) && test -f $p && - test $(cat $p) = tree2$f + test $(cat $p) = tree2$f || return 1 done ' diff --git a/t/t2012-checkout-last.sh b/t/t2012-checkout-last.sh index 0e7d47ab31..42601d5a31 100755 --- a/t/t2012-checkout-last.sh +++ b/t/t2012-checkout-last.sh @@ -49,14 +49,14 @@ test_expect_success '"checkout -" detaches again' ' test_expect_success 'more switches' ' for i in 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 do - git checkout -b branch$i + git checkout -b branch$i || return 1 done ' more_switches () { for i in 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 do - git checkout branch$i + git checkout branch$i || return 1 done } diff --git a/t/t2102-update-index-symlinks.sh b/t/t2102-update-index-symlinks.sh index d7a3485582..c49cdfb6e5 100755 --- a/t/t2102-update-index-symlinks.sh +++ b/t/t2102-update-index-symlinks.sh @@ -26,7 +26,7 @@ test_expect_success \ 'the index entry must still be a symbolic link' ' case "$(git ls-files --stage --cached symlink)" in 120000" "*symlink) echo pass;; -*) echo fail; git ls-files --stage --cached symlink; (exit 1);; +*) echo fail; git ls-files --stage --cached symlink; false;; esac' test_done diff --git a/t/t2103-update-index-ignore-missing.sh b/t/t2103-update-index-ignore-missing.sh index b304714fdb..e9451cd567 100755 --- a/t/t2103-update-index-ignore-missing.sh +++ b/t/t2103-update-index-ignore-missing.sh @@ -24,7 +24,7 @@ test_expect_success basics ' test_cmp expect actual && git update-index --add one two three && - for i in one three two; do echo $i; done >expect && + test_write_lines one three two >expect && git ls-files >actual && test_cmp expect actual && diff --git a/t/t2200-add-update.sh b/t/t2200-add-update.sh index a8297c2943..acd3650d3c 100755 --- a/t/t2200-add-update.sh +++ b/t/t2200-add-update.sh @@ -151,13 +151,13 @@ test_expect_success 'add -u resolves unmerged paths' ' { for path in path1 path2 do - echo "100644 $one 1 $path" - echo "100644 $two 2 $path" - echo "100644 $three 3 $path" - done - echo "100644 $one 1 path3" - echo "100644 $one 1 path4" - echo "100644 $one 3 path5" + echo "100644 $one 1 $path" && + echo "100644 $two 2 $path" && + echo "100644 $three 3 $path" || return 1 + done && + echo "100644 $one 1 path3" && + echo "100644 $one 1 path4" && + echo "100644 $one 3 path5" && echo "100644 $one 3 path6" } | git update-index --index-info && @@ -174,8 +174,8 @@ test_expect_success 'add -u resolves unmerged paths' ' git add -u && git ls-files -s path1 path2 path3 path4 path5 path6 >actual && { - echo "100644 $three 0 path1" - echo "100644 $two 0 path3" + echo "100644 $three 0 path1" && + echo "100644 $two 0 path3" && echo "100644 $two 0 path5" } >expect && test_cmp expect actual diff --git a/t/t2201-add-update-typechange.sh b/t/t2201-add-update-typechange.sh index c6876b120f..dba62d69c6 100755 --- a/t/t2201-add-update-typechange.sh +++ b/t/t2201-add-update-typechange.sh @@ -98,17 +98,17 @@ test_expect_success modify ' " } >expect && { - cat expect - echo ":100644 160000 $_empty $ZERO_OID T yonk" + cat expect && + echo ":100644 160000 $_empty $ZERO_OID T yonk" && echo ":100644 000000 $_empty $ZERO_OID D zifmia" } >expect-files && { - cat expect + cat expect && echo ":000000 160000 $ZERO_OID $ZERO_OID A yonk" } >expect-index && { - echo "100644 $_empty 0 nitfol" - echo "160000 $yomin 0 yomin" + echo "100644 $_empty 0 nitfol" && + echo "160000 $yomin 0 yomin" && echo "160000 $yonk 0 yonk" } >expect-final ' diff --git a/t/t2203-add-intent.sh b/t/t2203-add-intent.sh index cf0175ad6e..db7ca55998 100755 --- a/t/t2203-add-intent.sh +++ b/t/t2203-add-intent.sh @@ -116,7 +116,7 @@ test_expect_success 'cache-tree does not ignore dir that has i-t-a entries' ' mkdir 2 && for f in 1 2/1 2/2 3 do - echo "$f" >"$f" + echo "$f" >"$f" || return 1 done && git add 1 2/2 3 && git add -N 2/1 && diff --git a/t/t2501-cwd-empty.sh b/t/t2501-cwd-empty.sh new file mode 100755 index 0000000000..f6d8d7d03d --- /dev/null +++ b/t/t2501-cwd-empty.sh @@ -0,0 +1,277 @@ +#!/bin/sh + +test_description='Test handling of the current working directory becoming empty' + +. ./test-lib.sh + +test_expect_success setup ' + test_commit init && + + git branch fd_conflict && + + mkdir -p foo/bar && + test_commit foo/bar/baz && + + git revert HEAD && + git tag reverted && + + git checkout fd_conflict && + mkdir dirORfile && + test_commit dirORfile/foo && + + git rm -r dirORfile && + echo not-a-directory >dirORfile && + git add dirORfile && + git commit -m dirORfile && + + git switch -c df_conflict HEAD~1 && + test_commit random_file && + + git switch -c undo_fd_conflict fd_conflict && + git revert HEAD +' + +test_incidental_dir_removal () { + test_when_finished "git reset --hard" && + + git checkout foo/bar/baz^{commit} && + test_path_is_dir foo/bar && + + ( + cd foo && + "$@" && + + # Make sure foo still exists, and commands needing it work + test-tool getcwd && + git status --porcelain + ) && + test_path_is_missing foo/bar/baz && + test_path_is_missing foo/bar && + + test_path_is_dir foo +} + +test_required_dir_removal () { + git checkout df_conflict^{commit} && + test_when_finished "git clean -fdx" && + + ( + cd dirORfile && + + # Ensure command refuses to run + test_must_fail "$@" 2>../error && + grep "Refusing to remove.*current working directory" ../error && + + # ...and that the index and working tree are left clean + git diff --exit-code HEAD && + + # Ensure that getcwd and git status do not error out (which + # they might if the current working directory had been removed) + test-tool getcwd && + git status --porcelain + ) && + + test_path_is_dir dirORfile +} + +test_expect_success 'checkout does not clean cwd incidentally' ' + test_incidental_dir_removal git checkout init +' + +test_expect_success 'checkout fails if cwd needs to be removed' ' + test_required_dir_removal git checkout fd_conflict +' + +test_expect_success 'reset --hard does not clean cwd incidentally' ' + test_incidental_dir_removal git reset --hard init +' + +test_expect_success 'reset --hard fails if cwd needs to be removed' ' + test_required_dir_removal git reset --hard fd_conflict +' + +test_expect_success 'merge does not clean cwd incidentally' ' + test_incidental_dir_removal git merge reverted +' + +# This file uses some simple merges where +# Base: 'dirORfile/' exists +# Side1: random other file changed +# Side2: 'dirORfile/' removed, 'dirORfile' added +# this should resolve cleanly, but merge-recursive throws merge conflicts +# because it's dumb. Add a special test for checking merge-recursive (and +# merge-ort), then after this just hard require ort for all remaining tests. +# +test_expect_success 'merge fails if cwd needs to be removed; recursive friendly' ' + git checkout foo/bar/baz && + test_when_finished "git clean -fdx" && + + mkdir dirORfile && + ( + cd dirORfile && + + test_must_fail git merge fd_conflict 2>../error + ) && + + test_path_is_dir dirORfile && + grep "Refusing to remove the current working directory" error +' + +GIT_TEST_MERGE_ALGORITHM=ort + +test_expect_success 'merge fails if cwd needs to be removed' ' + test_required_dir_removal git merge fd_conflict +' + +test_expect_success 'cherry-pick does not clean cwd incidentally' ' + test_incidental_dir_removal git cherry-pick reverted +' + +test_expect_success 'cherry-pick fails if cwd needs to be removed' ' + test_required_dir_removal git cherry-pick fd_conflict +' + +test_expect_success 'rebase does not clean cwd incidentally' ' + test_incidental_dir_removal git rebase reverted +' + +test_expect_success 'rebase fails if cwd needs to be removed' ' + test_required_dir_removal git rebase fd_conflict +' + +test_expect_success 'revert does not clean cwd incidentally' ' + test_incidental_dir_removal git revert HEAD +' + +test_expect_success 'revert fails if cwd needs to be removed' ' + test_required_dir_removal git revert undo_fd_conflict +' + +test_expect_success 'rm does not clean cwd incidentally' ' + test_incidental_dir_removal git rm bar/baz.t +' + +test_expect_success 'apply does not remove cwd incidentally' ' + git diff HEAD HEAD~1 >patch && + test_incidental_dir_removal git apply ../patch +' + +test_incidental_untracked_dir_removal () { + test_when_finished "git reset --hard" && + + git checkout foo/bar/baz^{commit} && + mkdir -p untracked && + mkdir empty + >untracked/random && + + ( + cd untracked && + "$@" && + + # Make sure untracked still exists, and commands needing it work + test-tool getcwd && + git status --porcelain + ) && + test_path_is_missing empty && + test_path_is_missing untracked/random && + + test_path_is_dir untracked +} + +test_expect_success 'clean does not remove cwd incidentally' ' + test_incidental_untracked_dir_removal \ + git -C .. clean -fd -e warnings . >warnings && + grep "Refusing to remove current working directory" warnings +' + +test_expect_success 'stash does not remove cwd incidentally' ' + test_incidental_untracked_dir_removal \ + git stash --include-untracked +' + +test_expect_success '`rm -rf dir` only removes a subset of dir' ' + test_when_finished "rm -rf a/" && + + mkdir -p a/b/c && + >a/b/c/untracked && + >a/b/c/tracked && + git add a/b/c/tracked && + + ( + cd a/b && + git rm -rf ../b + ) && + + test_path_is_dir a/b && + test_path_is_missing a/b/c/tracked && + test_path_is_file a/b/c/untracked +' + +test_expect_success '`rm -rf dir` even with only tracked files will remove something else' ' + test_when_finished "rm -rf a/" && + + mkdir -p a/b/c && + >a/b/c/tracked && + git add a/b/c/tracked && + + ( + cd a/b && + git rm -rf ../b + ) && + + test_path_is_missing a/b/c/tracked && + test_path_is_missing a/b/c && + test_path_is_dir a/b +' + +test_expect_success 'git version continues working from a deleted dir' ' + mkdir tmp && + ( + cd tmp && + rm -rf ../tmp && + git version + ) +' + +test_submodule_removal () { + path_status=$1 && + shift && + + test_status= + test "$path_status" = dir && test_status=test_must_fail + + test_when_finished "git reset --hard HEAD~1" && + test_when_finished "rm -rf .git/modules/my_submodule" && + + git checkout foo/bar/baz && + + git init my_submodule && + touch my_submodule/file && + git -C my_submodule add file && + git -C my_submodule commit -m "initial commit" && + git submodule add ./my_submodule && + git commit -m "Add the submodule" && + + ( + cd my_submodule && + $test_status "$@" + ) && + + test_path_is_${path_status} my_submodule +} + +test_expect_success 'rm -r with -C leaves submodule if cwd inside' ' + test_submodule_removal dir git -C .. rm -r my_submodule/ +' + +test_expect_success 'rm -r leaves submodule if cwd inside' ' + test_submodule_removal dir \ + git --git-dir=../.git --work-tree=.. rm -r ../my_submodule/ +' + +test_expect_success 'rm -rf removes submodule even if cwd inside' ' + test_submodule_removal missing \ + git --git-dir=../.git --work-tree=.. rm -rf ../my_submodule/ +' + +test_done diff --git a/t/t3005-ls-files-relative.sh b/t/t3005-ls-files-relative.sh index 6ba8b589cd..fbfa210a50 100755 --- a/t/t3005-ls-files-relative.sh +++ b/t/t3005-ls-files-relative.sh @@ -39,10 +39,7 @@ test_expect_success 'ls-files with mixed levels' ' test_expect_success 'ls-files -c' ' ( cd top/sub && - for f in ../y* - do - echo "error: pathspec $SQ$f$SQ did not match any file(s) known to git" - done >expect.err && + printf "error: pathspec $SQ%s$SQ did not match any file(s) known to git\n" ../y* >expect.err && echo "Did you forget to ${SQ}git add${SQ}?" >>expect.err && ls ../x* >expect.out && test_must_fail git ls-files -c --error-unmatch ../[xy]* >actual.out 2>actual.err && @@ -54,10 +51,7 @@ test_expect_success 'ls-files -c' ' test_expect_success 'ls-files -o' ' ( cd top/sub && - for f in ../x* - do - echo "error: pathspec $SQ$f$SQ did not match any file(s) known to git" - done >expect.err && + printf "error: pathspec $SQ%s$SQ did not match any file(s) known to git\n" ../x* >expect.err && echo "Did you forget to ${SQ}git add${SQ}?" >>expect.err && ls ../y* >expect.out && test_must_fail git ls-files -o --error-unmatch ../[xy]* >actual.out 2>actual.err && diff --git a/t/t3070-wildmatch.sh b/t/t3070-wildmatch.sh index 72d5b014d8..f9539968e4 100755 --- a/t/t3070-wildmatch.sh +++ b/t/t3070-wildmatch.sh @@ -193,7 +193,7 @@ match() { file=$(cat .git/expected_test_file) && if should_create_test_file "$file" then - dirs=${file%/*} + dirs=${file%/*} && if test "$file" != "$dirs" then mkdir -p -- "$dirs" && diff --git a/t/t3202-show-branch.sh b/t/t3202-show-branch.sh index d4d64401e4..7a1be73ce8 100755 --- a/t/t3202-show-branch.sh +++ b/t/t3202-show-branch.sh @@ -12,7 +12,7 @@ test_expect_success 'setup' ' for i in $(test_seq 1 10) do git checkout -b branch$i initial && - test_commit --no-tag branch$i + test_commit --no-tag branch$i || return 1 done && git for-each-ref \ --sort=version:refname \ @@ -52,7 +52,7 @@ test_expect_success 'show-branch with more than 8 branches' ' test_expect_success 'show-branch with showbranch.default' ' for branch in $(cat branches.sorted) do - test_config showbranch.default $branch --add + test_config showbranch.default $branch --add || return 1 done && git show-branch >actual && test_cmp expect actual @@ -127,7 +127,7 @@ test_expect_success 'show branch --merge-base with one argument' ' do git rev-parse $branch >expect && git show-branch --merge-base $branch >actual && - test_cmp expect actual + test_cmp expect actual || return 1 done ' @@ -136,7 +136,7 @@ test_expect_success 'show branch --merge-base with two arguments' ' do git rev-parse initial >expect && git show-branch --merge-base initial $branch >actual && - test_cmp expect actual + test_cmp expect actual || return 1 done ' diff --git a/t/t3303-notes-subtrees.sh b/t/t3303-notes-subtrees.sh index f5fd80d4d3..7e0a8960af 100755 --- a/t/t3303-notes-subtrees.sh +++ b/t/t3303-notes-subtrees.sh @@ -31,7 +31,7 @@ verify_notes () { while [ $i -gt 0 ]; do echo " commit #$i" && echo " note for commit #$i" && - i=$(($i-1)); + i=$(($i-1)) || return 1 done > expect && test_cmp expect output } @@ -43,7 +43,7 @@ test_expect_success "setup: create $number_of_commits commits" ' while [ $nr -lt $number_of_commits ]; do nr=$(($nr+1)) && test_tick && - cat <<INPUT_END + cat <<INPUT_END || return 1 commit refs/heads/main committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <<COMMIT @@ -179,7 +179,7 @@ verify_concatenated_notes () { echo " first note for commit #$i" && echo " " && echo " second note for commit #$i" && - i=$(($i-1)); + i=$(($i-1)) || return 1 done > expect && test_cmp expect output } diff --git a/t/t3305-notes-fanout.sh b/t/t3305-notes-fanout.sh index 960d0587e1..1f5964865a 100755 --- a/t/t3305-notes-fanout.sh +++ b/t/t3305-notes-fanout.sh @@ -58,7 +58,7 @@ test_expect_success 'many notes created correctly with git-notes' ' do echo " commit #$i" && echo " note #$i" && - i=$(($i - 1)); + i=$(($i - 1)) || return 1 done > expect && test_cmp expect output ' @@ -107,7 +107,7 @@ test_expect_success 'most notes deleted correctly with git-notes' ' do echo " commit #$i" && echo " note #$i" && - i=$(($i - 1)); + i=$(($i - 1)) || return 1 done > expect && test_cmp expect output ' diff --git a/t/t3402-rebase-merge.sh b/t/t3402-rebase-merge.sh index cfde68f193..7e46f4ca85 100755 --- a/t/t3402-rebase-merge.sh +++ b/t/t3402-rebase-merge.sh @@ -68,7 +68,7 @@ test_expect_success 'merge and rebase should match' ' if test -s difference then cat difference - (exit 1) + false else echo happy fi @@ -102,7 +102,7 @@ test_expect_success 'merge and rebase should match' ' if test -s difference then cat difference - (exit 1) + false else echo happy fi @@ -117,7 +117,7 @@ test_expect_success 'picking rebase' ' echo happy else git show-branch - (exit 1) + false fi && f=$(git diff-tree --name-only HEAD^ HEAD) && g=$(git diff-tree --name-only HEAD^^ HEAD^) && @@ -127,7 +127,7 @@ test_expect_success 'picking rebase' ' *) echo "$f" echo "$g" - (exit 1) + false esac ' diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index 0baa68e9b4..a38f2da769 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -824,7 +824,7 @@ test_expect_success 'always cherry-pick with --no-ff' ' do test ! $(git rev-parse HEAD~$p) = $(git rev-parse original-no-ff-branch~$p) && git diff HEAD~$p original-no-ff-branch~$p > out && - test_must_be_empty out + test_must_be_empty out || return 1 done && test_cmp_rev HEAD~3 original-no-ff-branch~3 && git diff HEAD~3 original-no-ff-branch~3 > out && @@ -1339,7 +1339,7 @@ test_expect_success 'rebase --continue removes CHERRY_PICK_HEAD' ' test_seq 5 | sed "s/$double/&&/" >seq && git add seq && test_tick && - git commit -m seq-$double + git commit -m seq-$double || return 1 done && git tag seq-onto && git reset --hard HEAD~2 && diff --git a/t/t3417-rebase-whitespace-fix.sh b/t/t3417-rebase-whitespace-fix.sh index 946e92f8da..96f2cf22fa 100755 --- a/t/t3417-rebase-whitespace-fix.sh +++ b/t/t3417-rebase-whitespace-fix.sh @@ -115,9 +115,7 @@ test_expect_success 'at beginning of file' ' git config core.whitespace "blank-at-eol" && cp beginning file && git commit -m beginning file && - for i in 1 2 3 4 5; do - echo $i - done >> file && + test_write_lines 1 2 3 4 5 >>file && git commit -m more file && git rebase --whitespace=fix HEAD^^ && test_cmp expect-beginning file diff --git a/t/t3501-revert-cherry-pick.sh b/t/t3501-revert-cherry-pick.sh index 4b5b607673..8617efaaf1 100755 --- a/t/t3501-revert-cherry-pick.sh +++ b/t/t3501-revert-cherry-pick.sh @@ -19,7 +19,7 @@ test_expect_success setup ' for l in a b c d e f g h i j k l m n o do - echo $l$l$l$l$l$l$l$l$l + echo $l$l$l$l$l$l$l$l$l || return 1 done >oops && test_tick && diff --git a/t/t3508-cherry-pick-many-commits.sh b/t/t3508-cherry-pick-many-commits.sh index e8375d1c97..2d53ce754c 100755 --- a/t/t3508-cherry-pick-many-commits.sh +++ b/t/t3508-cherry-pick-many-commits.sh @@ -29,7 +29,7 @@ test_expect_success setup ' git add file1 && test_tick && git commit -m "$val" && - git tag $val + git tag $val || return 1 done ' diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh index bb9ef35dac..e74a318ac3 100755 --- a/t/t3600-rm.sh +++ b/t/t3600-rm.sh @@ -265,7 +265,7 @@ test_expect_success 'choking "git rm" should not let it die with cruft (induce S test_expect_success !MINGW 'choking "git rm" should not let it die with cruft (induce and check SIGPIPE)' ' choke_git_rm_setup && - OUT=$( ((trap "" PIPE; git rm -n "some-file-*"; echo $? 1>&3) | :) 3>&1 ) && + OUT=$( ((trap "" PIPE && git rm -n "some-file-*"; echo $? 1>&3) | :) 3>&1 ) && test_match_signal 13 "$OUT" && test_path_is_missing .git/index.lock ' @@ -274,10 +274,7 @@ test_expect_success 'Resolving by removal is not a warning-worthy event' ' git reset -q --hard && test_when_finished "rm -f .git/index.lock msg && git reset -q --hard" && blob=$(echo blob | git hash-object -w --stdin) && - for stage in 1 2 3 - do - echo "100644 $blob $stage blob" - done | git update-index --index-info && + printf "100644 $blob %d\tblob\n" 1 2 3 | git update-index --index-info && git rm blob >msg 2>&1 && test_i18ngrep ! "needs merge" msg && test_must_fail git ls-files -s --error-unmatch blob diff --git a/t/t3700-add.sh b/t/t3700-add.sh index 283a66955d..b1f90ba325 100755 --- a/t/t3700-add.sh +++ b/t/t3700-add.sh @@ -141,9 +141,9 @@ test_expect_success 'check correct prefix detection' ' test_expect_success 'git add with filemode=0, symlinks=0, and unmerged entries' ' for s in 1 2 3 do - echo $s > stage$s - echo "100755 $(git hash-object -w stage$s) $s file" - echo "120000 $(printf $s | git hash-object -w -t blob --stdin) $s symlink" + echo $s > stage$s && + echo "100755 $(git hash-object -w stage$s) $s file" && + echo "120000 $(printf $s | git hash-object -w -t blob --stdin) $s symlink" || return 1 done | git update-index --index-info && git config core.filemode 0 && git config core.symlinks 0 && @@ -177,7 +177,7 @@ test_expect_success 'git add --refresh' ' git read-tree HEAD && case "$(git diff-index HEAD -- foo)" in :100644" "*"M foo") echo pass;; - *) echo fail; (exit 1);; + *) echo fail; false;; esac && git add --refresh -- foo && test -z "$(git diff-index HEAD -- foo)" diff --git a/t/t3920-crlf-messages.sh b/t/t3920-crlf-messages.sh index a8ad5462d9..0276edbe3d 100755 --- a/t/t3920-crlf-messages.sh +++ b/t/t3920-crlf-messages.sh @@ -70,7 +70,7 @@ test_crlf_subject_body_and_contents() { for ref in ${LIB_CRLF_BRANCHES} do cat .crlf-${file}-\"\${ref}\".txt >>expect && - printf \"\n\" >>expect + printf \"\n\" >>expect || return 1 done && git $command_and_args --format=\"%${atom}\" >actual && test_cmp expect actual @@ -90,7 +90,7 @@ test_expect_success 'branch: --verbose works with messages using CRLF' ' do printf " " >>expect && cat .crlf-subject-${branch}.txt >>expect && - printf "\n" >>expect + printf "\n" >>expect || return 1 done && git branch -v >tmp && # Remove first two columns, and the line for the currently checked out branch diff --git a/t/t4001-diff-rename.sh b/t/t4001-diff-rename.sh index 68f2ebca58..3dc9047044 100755 --- a/t/t4001-diff-rename.sh +++ b/t/t4001-diff-rename.sh @@ -174,7 +174,7 @@ test_expect_success 'setup for many rename source candidates' ' do for j in 0 1 2 3 4 5 6 7 8 9; do - echo "$i$j" >"path$i$j" + echo "$i$j" >"path$i$j" || return 1 done done && git add "path??" && diff --git a/t/t4012-diff-binary.sh b/t/t4012-diff-binary.sh index 00eeafb2ac..c509143c81 100755 --- a/t/t4012-diff-binary.sh +++ b/t/t4012-diff-binary.sh @@ -123,7 +123,7 @@ test_expect_success 'diff --stat with binary files and big change count' ' i=0 && while test $i -lt 10000; do echo $i && - i=$(($i + 1)) + i=$(($i + 1)) || return 1 done >textfile && git add textfile && git diff --cached --stat binfile textfile >output && diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh index 28683d059d..750aee17ea 100755 --- a/t/t4013-diff-various.sh +++ b/t/t4013-diff-various.sh @@ -19,8 +19,8 @@ test_expect_success setup ' mkdir dir && mkdir dir2 && - for i in 1 2 3; do echo $i; done >file0 && - for i in A B; do echo $i; done >dir/sub && + test_write_lines 1 2 3 >file0 && + test_write_lines A B >dir/sub && cat file0 >file2 && git add file0 file2 dir/sub && git commit -m Initial && @@ -32,8 +32,8 @@ test_expect_success setup ' GIT_COMMITTER_DATE="2006-06-26 00:01:00 +0000" && export GIT_AUTHOR_DATE GIT_COMMITTER_DATE && - for i in 4 5 6; do echo $i; done >>file0 && - for i in C D; do echo $i; done >>dir/sub && + test_write_lines 4 5 6 >>file0 && + test_write_lines C D >>dir/sub && rm -f file2 && git update-index --remove file0 file2 dir/sub && git commit -m "Second${LF}${LF}This is the second commit." && @@ -42,9 +42,9 @@ test_expect_success setup ' GIT_COMMITTER_DATE="2006-06-26 00:02:00 +0000" && export GIT_AUTHOR_DATE GIT_COMMITTER_DATE && - for i in A B C; do echo $i; done >file1 && + test_write_lines A B C >file1 && git add file1 && - for i in E F; do echo $i; done >>dir/sub && + test_write_lines E F >>dir/sub && git update-index dir/sub && git commit -m Third && @@ -53,8 +53,8 @@ test_expect_success setup ' export GIT_AUTHOR_DATE GIT_COMMITTER_DATE && git checkout side && - for i in A B C; do echo $i; done >>file0 && - for i in 1 2; do echo $i; done >>dir/sub && + test_write_lines A B C >>file0 && + test_write_lines 1 2 >>dir/sub && cat dir/sub >file3 && git add file3 && git update-index file0 dir/sub && @@ -71,8 +71,8 @@ test_expect_success setup ' GIT_COMMITTER_DATE="2006-06-26 00:05:00 +0000" && export GIT_AUTHOR_DATE GIT_COMMITTER_DATE && - for i in A B C; do echo $i; done >>file0 && - for i in 1 2; do echo $i; done >>dir/sub && + test_write_lines A B C >>file0 && + test_write_lines 1 2 >>dir/sub && git update-index file0 dir/sub && mkdir dir3 && @@ -86,7 +86,7 @@ test_expect_success setup ' GIT_COMMITTER_DATE="2006-06-26 00:06:00 +0000" && export GIT_AUTHOR_DATE GIT_COMMITTER_DATE && git checkout -b rearrange initial && - for i in B A; do echo $i; done >dir/sub && + test_write_lines B A >dir/sub && git add dir/sub && git commit -m "Rearranged lines in dir/sub" && git checkout master && diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index 712d4b5ddf..7dc5a5c736 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -12,25 +12,25 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . "$TEST_DIRECTORY"/lib-terminal.sh test_expect_success setup ' - for i in 1 2 3 4 5 6 7 8 9 10; do echo "$i"; done >file && + test_write_lines 1 2 3 4 5 6 7 8 9 10 >file && cat file >elif && git add file elif && test_tick && git commit -m Initial && git checkout -b side && - for i in 1 2 5 6 A B C 7 8 9 10; do echo "$i"; done >file && + test_write_lines 1 2 5 6 A B C 7 8 9 10 >file && test_chmod +x elif && test_tick && git commit -m "Side changes #1" && - for i in D E F; do echo "$i"; done >>file && + test_write_lines D E F >>file && git update-index file && test_tick && git commit -m "Side changes #2" && git tag C2 && - for i in 5 6 1 2 3 A 4 B C 7 8 9 10 D E F; do echo "$i"; done >file && + test_write_lines 5 6 1 2 3 A 4 B C 7 8 9 10 D E F >file && git update-index file && test_tick && git commit -m "Side changes #3 with \\n backslash-n in it." && @@ -43,18 +43,18 @@ test_expect_success setup ' git checkout side && git checkout -b patchid && - for i in 5 6 1 2 3 A 4 B C 7 8 9 10 D E F; do echo "$i"; done >file2 && - for i in 1 2 3 A 4 B C 7 8 9 10 D E F 5 6; do echo "$i"; done >file3 && - for i in 8 9 10; do echo "$i"; done >file && + test_write_lines 5 6 1 2 3 A 4 B C 7 8 9 10 D E F >file2 && + test_write_lines 1 2 3 A 4 B C 7 8 9 10 D E F 5 6 >file3 && + test_write_lines 8 9 10 >file && git add file file2 file3 && test_tick && git commit -m "patchid 1" && - for i in 4 A B 7 8 9 10; do echo "$i"; done >file2 && - for i in 8 9 10 5 6; do echo "$i"; done >file3 && + test_write_lines 4 A B 7 8 9 10 >file2 && + test_write_lines 8 9 10 5 6 >file3 && git add file2 file3 && test_tick && git commit -m "patchid 2" && - for i in 10 5 6; do echo "$i"; done >file && + test_write_lines 10 5 6 >file && git add file && test_tick && git commit -m "patchid 3" && @@ -325,7 +325,7 @@ test_expect_success 'filename length limit' ' max=$( for patch in 000[1-9]-*.patch do - echo "$patch" | wc -c + echo "$patch" | wc -c || exit 1 done | sort -nr | head -n 1 @@ -343,7 +343,7 @@ test_expect_success 'filename length limit from config' ' max=$( for patch in 000[1-9]-*.patch do - echo "$patch" | wc -c + echo "$patch" | wc -c || exit 1 done | sort -nr | head -n 1 @@ -361,7 +361,7 @@ test_expect_success 'filename limit applies only to basename' ' max=$( for patch in patches/000[1-9]-*.patch do - echo "${patch#patches/}" | wc -c + echo "${patch#patches/}" | wc -c || exit 1 done | sort -nr | head -n 1 @@ -653,7 +653,7 @@ test_expect_success 'excessive subject' ' git checkout side && before=$(git hash-object file) && before=$(git rev-parse --short $before) && - for i in 5 6 1 2 3 A 4 B C 7 8 9 10 D E F; do echo "$i"; done >>file && + test_write_lines 5 6 1 2 3 A 4 B C 7 8 9 10 D E F >>file && after=$(git hash-object file) && after=$(git rev-parse --short $after) && git update-index file && @@ -1086,7 +1086,7 @@ test_expect_success TTY 'format-patch --stdout paginates' ' test_expect_success 'format-patch handles multi-line subjects' ' rm -rf patches/ && echo content >>file && - for i in one two three; do echo $i; done >msg && + test_write_lines one two three >msg && git add file && git commit -F msg && git format-patch -o patches -1 && @@ -1098,7 +1098,7 @@ test_expect_success 'format-patch handles multi-line subjects' ' test_expect_success 'format-patch handles multi-line encoded subjects' ' rm -rf patches/ && echo content >>file && - for i in en två tre; do echo $i; done >msg && + test_write_lines en två tre >msg && git add file && git commit -F msg && git format-patch -o patches -1 && diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh index 2c13b62d3c..9babf13bc9 100755 --- a/t/t4015-diff-whitespace.sh +++ b/t/t4015-diff-whitespace.sh @@ -843,7 +843,7 @@ test_expect_success 'whitespace changes with modification reported (diffstat)' ' test_expect_success 'whitespace-only changes reported across renames (diffstat)' ' git reset --hard && - for i in 1 2 3 4 5 6 7 8 9; do echo "$i$i$i$i$i$i"; done >x && + for i in 1 2 3 4 5 6 7 8 9; do echo "$i$i$i$i$i$i" || return 1; done >x && git add x && git commit -m "base" && sed -e "5s/^/ /" x >z && @@ -859,7 +859,7 @@ test_expect_success 'whitespace-only changes reported across renames (diffstat)' test_expect_success 'whitespace-only changes reported across renames' ' git reset --hard HEAD~1 && - for i in 1 2 3 4 5 6 7 8 9; do echo "$i$i$i$i$i$i"; done >x && + for i in 1 2 3 4 5 6 7 8 9; do echo "$i$i$i$i$i$i" || return 1; done >x && git add x && hash_x=$(git hash-object x) && before=$(git rev-parse --short "$hash_x") && @@ -1442,6 +1442,143 @@ test_expect_success 'detect permutations inside moved code -- dimmed-zebra' ' test_cmp expected actual ' +test_expect_success 'zebra alternate color is only used when necessary' ' + cat >old.txt <<-\EOF && + line 1A should be marked as oldMoved newMovedAlternate + line 1B should be marked as oldMoved newMovedAlternate + unchanged + line 2A should be marked as oldMoved newMovedAlternate + line 2B should be marked as oldMoved newMovedAlternate + line 3A should be marked as oldMovedAlternate newMoved + line 3B should be marked as oldMovedAlternate newMoved + unchanged + line 4A should be marked as oldMoved newMovedAlternate + line 4B should be marked as oldMoved newMovedAlternate + line 5A should be marked as oldMovedAlternate newMoved + line 5B should be marked as oldMovedAlternate newMoved + line 6A should be marked as oldMoved newMoved + line 6B should be marked as oldMoved newMoved + EOF + cat >new.txt <<-\EOF && + line 1A should be marked as oldMoved newMovedAlternate + line 1B should be marked as oldMoved newMovedAlternate + unchanged + line 3A should be marked as oldMovedAlternate newMoved + line 3B should be marked as oldMovedAlternate newMoved + line 2A should be marked as oldMoved newMovedAlternate + line 2B should be marked as oldMoved newMovedAlternate + unchanged + line 6A should be marked as oldMoved newMoved + line 6B should be marked as oldMoved newMoved + line 4A should be marked as oldMoved newMovedAlternate + line 4B should be marked as oldMoved newMovedAlternate + line 5A should be marked as oldMovedAlternate newMoved + line 5B should be marked as oldMovedAlternate newMoved + EOF + test_expect_code 1 git diff --no-index --color --color-moved=zebra \ + --color-moved-ws=allow-indentation-change \ + old.txt new.txt >output && + grep -v index output | test_decode_color >actual && + cat >expected <<-\EOF && + <BOLD>diff --git a/old.txt b/new.txt<RESET> + <BOLD>--- a/old.txt<RESET> + <BOLD>+++ b/new.txt<RESET> + <CYAN>@@ -1,14 +1,14 @@<RESET> + <BOLD;MAGENTA>-line 1A should be marked as oldMoved newMovedAlternate<RESET> + <BOLD;MAGENTA>-line 1B should be marked as oldMoved newMovedAlternate<RESET> + <BOLD;CYAN>+<RESET><BOLD;CYAN> line 1A should be marked as oldMoved newMovedAlternate<RESET> + <BOLD;CYAN>+<RESET><BOLD;CYAN> line 1B should be marked as oldMoved newMovedAlternate<RESET> + unchanged<RESET> + <BOLD;MAGENTA>-line 2A should be marked as oldMoved newMovedAlternate<RESET> + <BOLD;MAGENTA>-line 2B should be marked as oldMoved newMovedAlternate<RESET> + <BOLD;BLUE>-line 3A should be marked as oldMovedAlternate newMoved<RESET> + <BOLD;BLUE>-line 3B should be marked as oldMovedAlternate newMoved<RESET> + <BOLD;CYAN>+<RESET><BOLD;CYAN> line 3A should be marked as oldMovedAlternate newMoved<RESET> + <BOLD;CYAN>+<RESET><BOLD;CYAN> line 3B should be marked as oldMovedAlternate newMoved<RESET> + <BOLD;YELLOW>+<RESET><BOLD;YELLOW> line 2A should be marked as oldMoved newMovedAlternate<RESET> + <BOLD;YELLOW>+<RESET><BOLD;YELLOW> line 2B should be marked as oldMoved newMovedAlternate<RESET> + unchanged<RESET> + <BOLD;MAGENTA>-line 4A should be marked as oldMoved newMovedAlternate<RESET> + <BOLD;MAGENTA>-line 4B should be marked as oldMoved newMovedAlternate<RESET> + <BOLD;BLUE>-line 5A should be marked as oldMovedAlternate newMoved<RESET> + <BOLD;BLUE>-line 5B should be marked as oldMovedAlternate newMoved<RESET> + <BOLD;MAGENTA>-line 6A should be marked as oldMoved newMoved<RESET> + <BOLD;MAGENTA>-line 6B should be marked as oldMoved newMoved<RESET> + <BOLD;CYAN>+<RESET><BOLD;CYAN> line 6A should be marked as oldMoved newMoved<RESET> + <BOLD;CYAN>+<RESET><BOLD;CYAN> line 6B should be marked as oldMoved newMoved<RESET> + <BOLD;YELLOW>+<RESET><BOLD;YELLOW> line 4A should be marked as oldMoved newMovedAlternate<RESET> + <BOLD;YELLOW>+<RESET><BOLD;YELLOW> line 4B should be marked as oldMoved newMovedAlternate<RESET> + <BOLD;CYAN>+<RESET><BOLD;CYAN> line 5A should be marked as oldMovedAlternate newMoved<RESET> + <BOLD;CYAN>+<RESET><BOLD;CYAN> line 5B should be marked as oldMovedAlternate newMoved<RESET> + EOF + test_cmp expected actual +' + +test_expect_success 'short lines of opposite sign do not get marked as moved' ' + cat >old.txt <<-\EOF && + this line should be marked as moved + unchanged + unchanged + unchanged + unchanged + too short + this line should be marked as oldMoved newMoved + this line should be marked as oldMovedAlternate newMoved + unchanged 1 + unchanged 2 + unchanged 3 + unchanged 4 + this line should be marked as oldMoved newMoved/newMovedAlternate + EOF + cat >new.txt <<-\EOF && + too short + unchanged + unchanged + this line should be marked as moved + too short + unchanged + unchanged + this line should be marked as oldMoved newMoved/newMovedAlternate + unchanged 1 + unchanged 2 + this line should be marked as oldMovedAlternate newMoved + this line should be marked as oldMoved newMoved/newMovedAlternate + unchanged 3 + this line should be marked as oldMoved newMoved + unchanged 4 + EOF + test_expect_code 1 git diff --no-index --color --color-moved=zebra \ + old.txt new.txt >output && cat output && + grep -v index output | test_decode_color >actual && + cat >expect <<-\EOF && + <BOLD>diff --git a/old.txt b/new.txt<RESET> + <BOLD>--- a/old.txt<RESET> + <BOLD>+++ b/new.txt<RESET> + <CYAN>@@ -1,13 +1,15 @@<RESET> + <BOLD;MAGENTA>-this line should be marked as moved<RESET> + <GREEN>+<RESET><GREEN>too short<RESET> + unchanged<RESET> + unchanged<RESET> + <BOLD;CYAN>+<RESET><BOLD;CYAN>this line should be marked as moved<RESET> + <GREEN>+<RESET><GREEN>too short<RESET> + unchanged<RESET> + unchanged<RESET> + <RED>-too short<RESET> + <BOLD;MAGENTA>-this line should be marked as oldMoved newMoved<RESET> + <BOLD;BLUE>-this line should be marked as oldMovedAlternate newMoved<RESET> + <BOLD;CYAN>+<RESET><BOLD;CYAN>this line should be marked as oldMoved newMoved/newMovedAlternate<RESET> + unchanged 1<RESET> + unchanged 2<RESET> + <BOLD;CYAN>+<RESET><BOLD;CYAN>this line should be marked as oldMovedAlternate newMoved<RESET> + <BOLD;YELLOW>+<RESET><BOLD;YELLOW>this line should be marked as oldMoved newMoved/newMovedAlternate<RESET> + unchanged 3<RESET> + <BOLD;CYAN>+<RESET><BOLD;CYAN>this line should be marked as oldMoved newMoved<RESET> + unchanged 4<RESET> + <BOLD;MAGENTA>-this line should be marked as oldMoved newMoved/newMovedAlternate<RESET> + EOF + test_cmp expect actual +' + test_expect_success 'cmd option assumes configured colored-moved' ' test_config color.diff.oldMoved "magenta" && test_config color.diff.newMoved "cyan" && @@ -1833,6 +1970,52 @@ test_expect_success '--color-moved treats adjacent blocks as separate for MIN_AL test_cmp expected actual ' +test_expect_success '--color-moved rewinds for MIN_ALNUM_COUNT' ' + git reset --hard && + test_write_lines >file \ + A B C one two three four five six seven D E F G H I J && + git add file && + test_write_lines >file \ + one two A B C D E F G H I J two three four five six seven && + git diff --color-moved=zebra -- file && + + git diff --color-moved=zebra --color -- file >actual.raw && + grep -v "index" actual.raw | test_decode_color >actual && + cat >expected <<-\EOF && + <BOLD>diff --git a/file b/file<RESET> + <BOLD>--- a/file<RESET> + <BOLD>+++ b/file<RESET> + <CYAN>@@ -1,13 +1,8 @@<RESET> + <GREEN>+<RESET><GREEN>one<RESET> + <GREEN>+<RESET><GREEN>two<RESET> + A<RESET> + B<RESET> + C<RESET> + <RED>-one<RESET> + <BOLD;MAGENTA>-two<RESET> + <BOLD;MAGENTA>-three<RESET> + <BOLD;MAGENTA>-four<RESET> + <BOLD;MAGENTA>-five<RESET> + <BOLD;MAGENTA>-six<RESET> + <BOLD;MAGENTA>-seven<RESET> + D<RESET> + E<RESET> + F<RESET> + <CYAN>@@ -15,3 +10,9 @@<RESET> <RESET>G<RESET> + H<RESET> + I<RESET> + J<RESET> + <BOLD;CYAN>+<RESET><BOLD;CYAN>two<RESET> + <BOLD;CYAN>+<RESET><BOLD;CYAN>three<RESET> + <BOLD;CYAN>+<RESET><BOLD;CYAN>four<RESET> + <BOLD;CYAN>+<RESET><BOLD;CYAN>five<RESET> + <BOLD;CYAN>+<RESET><BOLD;CYAN>six<RESET> + <BOLD;CYAN>+<RESET><BOLD;CYAN>seven<RESET> + EOF + + test_cmp expected actual +' + test_expect_success 'move detection with submodules' ' test_create_repo bananas && echo ripe >bananas/recipe && @@ -2023,10 +2206,10 @@ EMPTY='' test_expect_success 'compare mixed whitespace delta across moved blocks' ' git reset --hard && - tr Q_ "\t " <<-EOF >text.txt && - ${EMPTY} - ____too short without - ${EMPTY} + tr "^|Q_" "\f\v\t " <<-EOF >text.txt && + ^__ + |____too short without + ^ ___being grouped across blank line ${EMPTY} context @@ -2045,7 +2228,7 @@ test_expect_success 'compare mixed whitespace delta across moved blocks' ' git add text.txt && git commit -m "add text.txt" && - tr Q_ "\t " <<-EOF >text.txt && + tr "^|Q_" "\f\v\t " <<-EOF >text.txt && context lines to @@ -2056,7 +2239,7 @@ test_expect_success 'compare mixed whitespace delta across moved blocks' ' ${EMPTY} QQtoo short without ${EMPTY} - Q_______being grouped across blank line + ^Q_______being grouped across blank line ${EMPTY} Q_QThese two lines have had their indentation reduced by four spaces @@ -2068,16 +2251,16 @@ test_expect_success 'compare mixed whitespace delta across moved blocks' ' -c core.whitespace=space-before-tab \ diff --color --color-moved --ws-error-highlight=all \ --color-moved-ws=allow-indentation-change >actual.raw && - grep -v "index" actual.raw | test_decode_color >actual && + grep -v "index" actual.raw | tr "\f\v" "^|" | test_decode_color >actual && cat <<-\EOF >expected && <BOLD>diff --git a/text.txt b/text.txt<RESET> <BOLD>--- a/text.txt<RESET> <BOLD>+++ b/text.txt<RESET> <CYAN>@@ -1,16 +1,16 @@<RESET> - <BOLD;MAGENTA>-<RESET> - <BOLD;MAGENTA>-<RESET><BOLD;MAGENTA> too short without<RESET> - <BOLD;MAGENTA>-<RESET> + <BOLD;MAGENTA>-<RESET><BOLD;MAGENTA>^<RESET><BRED> <RESET> + <BOLD;MAGENTA>-<RESET><BOLD;MAGENTA>| too short without<RESET> + <BOLD;MAGENTA>-<RESET><BOLD;MAGENTA>^<RESET> <BOLD;MAGENTA>-<RESET><BOLD;MAGENTA> being grouped across blank line<RESET> <BOLD;MAGENTA>-<RESET> <RESET>context<RESET> @@ -2097,7 +2280,7 @@ test_expect_success 'compare mixed whitespace delta across moved blocks' ' <BOLD;YELLOW>+<RESET> <BOLD;YELLOW>+<RESET> <BOLD;YELLOW>too short without<RESET> <BOLD;YELLOW>+<RESET> - <BOLD;YELLOW>+<RESET> <BOLD;YELLOW> being grouped across blank line<RESET> + <BOLD;YELLOW>+<RESET><BOLD;YELLOW>^ being grouped across blank line<RESET> <BOLD;YELLOW>+<RESET> <BOLD;CYAN>+<RESET> <BRED> <RESET> <BOLD;CYAN>These two lines have had their<RESET> <BOLD;CYAN>+<RESET><BOLD;CYAN>indentation reduced by four spaces<RESET> diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh index 740696c8f7..42a2b9a13b 100755 --- a/t/t4018-diff-funcname.sh +++ b/t/t4018-diff-funcname.sh @@ -75,7 +75,7 @@ test_expect_success 'last regexp must not be negated' ' test_expect_success 'setup hunk header tests' ' for i in $diffpatterns do - echo "$i-* diff=$i" + echo "$i-* diff=$i" || return 1 done > .gitattributes && # add all test files to the index diff --git a/t/t4019-diff-wserror.sh b/t/t4019-diff-wserror.sh index c68729ac09..d2b3109c2d 100755 --- a/t/t4019-diff-wserror.sh +++ b/t/t4019-diff-wserror.sh @@ -287,9 +287,9 @@ test_expect_success 'do not color trailing cr in context' ' ' test_expect_success 'color new trailing blank lines' ' - { echo a; echo b; echo; echo; } >x && + test_write_lines a b "" "" >x && git add x && - { echo a; echo; echo; echo; echo c; echo; echo; echo; echo; } >x && + test_write_lines a "" "" "" c "" "" "" "" >x && git diff --color x >output && cnt=$($grep_a "${blue_grep}" output | wc -l) && test $cnt = 2 diff --git a/t/t4023-diff-rename-typechange.sh b/t/t4023-diff-rename-typechange.sh index 47d6f35dcc..7cb9909293 100755 --- a/t/t4023-diff-rename-typechange.sh +++ b/t/t4023-diff-rename-typechange.sh @@ -55,7 +55,7 @@ test_expect_success 'cross renames to be detected for regular files' ' git diff-tree five six -r --name-status -B -M | sort >actual && { - echo "R100 foo bar" + echo "R100 foo bar" && echo "R100 bar foo" } | sort >expect && test_cmp expect actual @@ -66,7 +66,7 @@ test_expect_success 'cross renames to be detected for typechange' ' git diff-tree one two -r --name-status -B -M | sort >actual && { - echo "R100 foo bar" + echo "R100 foo bar" && echo "R100 bar foo" } | sort >expect && test_cmp expect actual @@ -78,7 +78,7 @@ test_expect_success 'moves and renames' ' git diff-tree three four -r --name-status -B -M | sort >actual && { # see -B -M (#6) in t4008 - echo "C100 foo bar" + echo "C100 foo bar" && echo "T100 foo" } | sort >expect && test_cmp expect actual diff --git a/t/t4024-diff-optimize-common.sh b/t/t4024-diff-optimize-common.sh index 540f93715e..e2f0eca4af 100755 --- a/t/t4024-diff-optimize-common.sh +++ b/t/t4024-diff-optimize-common.sh @@ -149,7 +149,7 @@ test_expect_success 'diff -U0' ' for n in $sample do - git diff -U0 file-?$n + git diff -U0 file-?$n || return 1 done | zc >actual && test_cmp expect actual diff --git a/t/t4025-hunk-header.sh b/t/t4025-hunk-header.sh index 6356961de4..5397cb7d42 100755 --- a/t/t4025-hunk-header.sh +++ b/t/t4025-hunk-header.sh @@ -14,15 +14,9 @@ test_expect_success setup ' ( echo "A $NS" && - for c in B C D E F G H I J K - do - echo " $c" - done && + printf " %s\n" B C D E F G H I J K && echo "L $NS" && - for c in M N O P Q R S T U V - do - echo " $c" - done + printf " %s\n" M N O P Q R S T U V ) >file && git add file && diff --git a/t/t4038-diff-combined.sh b/t/t4038-diff-combined.sh index aeac203c42..9a292bac70 100755 --- a/t/t4038-diff-combined.sh +++ b/t/t4038-diff-combined.sh @@ -100,7 +100,7 @@ test_expect_success 'setup for --cc --raw' ' for i in $(test_seq 1 40) do blob=$(echo file$i | git hash-object --stdin -w) && - trees="$trees$(echo "100644 blob $blob file" | git mktree)$LF" + trees="$trees$(echo "100644 blob $blob file" | git mktree)$LF" || return 1 done ' diff --git a/t/t4046-diff-unmerged.sh b/t/t4046-diff-unmerged.sh index fd3f3a7260..0ae0cd3a52 100755 --- a/t/t4046-diff-unmerged.sh +++ b/t/t4046-diff-unmerged.sh @@ -20,7 +20,7 @@ test_expect_success setup ' for t in o x do path="$b$o$t" && - case "$path" in ooo) continue ;; esac + case "$path" in ooo) continue ;; esac && paths="$paths$path " && p=" $path" && case "$b" in x) echo "$m1$p" ;; esac && @@ -39,7 +39,7 @@ test_expect_success 'diff-files -0' ' for path in $paths do >"$path" && - echo ":000000 100644 $ZERO_OID $ZERO_OID U $path" + echo ":000000 100644 $ZERO_OID $ZERO_OID U $path" || return 1 done >diff-files-0.expect && git diff-files -0 >diff-files-0.actual && test_cmp diff-files-0.expect diff-files-0.actual @@ -52,7 +52,7 @@ test_expect_success 'diff-files -1' ' echo ":000000 100644 $ZERO_OID $ZERO_OID U $path" && case "$path" in x??) echo ":100644 100644 $blob1 $ZERO_OID M $path" - esac + esac || return 1 done >diff-files-1.expect && git diff-files -1 >diff-files-1.actual && test_cmp diff-files-1.expect diff-files-1.actual @@ -65,7 +65,7 @@ test_expect_success 'diff-files -2' ' echo ":000000 100644 $ZERO_OID $ZERO_OID U $path" && case "$path" in ?x?) echo ":100644 100644 $blob2 $ZERO_OID M $path" - esac + esac || return 1 done >diff-files-2.expect && git diff-files -2 >diff-files-2.actual && test_cmp diff-files-2.expect diff-files-2.actual && @@ -80,7 +80,7 @@ test_expect_success 'diff-files -3' ' echo ":000000 100644 $ZERO_OID $ZERO_OID U $path" && case "$path" in ??x) echo ":100644 100644 $blob3 $ZERO_OID M $path" - esac + esac || return 1 done >diff-files-3.expect && git diff-files -3 >diff-files-3.actual && test_cmp diff-files-3.expect diff-files-3.actual diff --git a/t/t4049-diff-stat-count.sh b/t/t4049-diff-stat-count.sh index f5b35e7860..0a4fc735d4 100755 --- a/t/t4049-diff-stat-count.sh +++ b/t/t4049-diff-stat-count.sh @@ -53,7 +53,7 @@ test_expect_success 'exclude unmerged entries from total file count' ' git rm -f d && for stage in 1 2 3 do - sed -e "s/ 0 a/ $stage d/" x + sed -e "s/ 0 a/ $stage d/" x || return 1 done | git update-index --index-info && echo d >d && diff --git a/t/t4052-stat-output.sh b/t/t4052-stat-output.sh index 9eba436211..b5c281edaa 100755 --- a/t/t4052-stat-output.sh +++ b/t/t4052-stat-output.sh @@ -101,7 +101,7 @@ test_expect_success 'preparation for big change tests' ' i=0 && while test $i -lt 1000 do - echo $i && i=$(($i + 1)) + echo $i && i=$(($i + 1)) || return 1 done >abcd && git commit -m message abcd ' diff --git a/t/t4057-diff-combined-paths.sh b/t/t4057-diff-combined-paths.sh index 7e5b74f72e..04b8a1542a 100755 --- a/t/t4057-diff-combined-paths.sh +++ b/t/t4057-diff-combined-paths.sh @@ -18,13 +18,13 @@ test_expect_success 'trivial merge - combine-diff empty' ' for i in $(test_seq 1 9) do echo $i >$i.txt && - git add $i.txt + git add $i.txt || return 1 done && git commit -m "init" && git checkout -b side && for i in $(test_seq 2 9) do - echo $i/2 >>$i.txt + echo $i/2 >>$i.txt || return 1 done && git commit -a -m "side 2-9" && git checkout main && @@ -40,14 +40,14 @@ test_expect_success 'only one truly conflicting path' ' git checkout side && for i in $(test_seq 2 9) do - echo $i/3 >>$i.txt + echo $i/3 >>$i.txt || return 1 done && echo "4side" >>4.txt && git commit -a -m "side 2-9 +4" && git checkout main && for i in $(test_seq 1 9) do - echo $i/3 >>$i.txt + echo $i/3 >>$i.txt || return 1 done && echo "4main" >>4.txt && git commit -a -m "main 1-9 +4" && @@ -69,13 +69,13 @@ test_expect_success 'merge introduces new file' ' git checkout side && for i in $(test_seq 5 9) do - echo $i/4 >>$i.txt + echo $i/4 >>$i.txt || return 1 done && git commit -a -m "side 5-9" && git checkout main && for i in $(test_seq 1 3) do - echo $i/4 >>$i.txt + echo $i/4 >>$i.txt || return 1 done && git commit -a -m "main 1-3 +4hello" && git merge side && @@ -90,13 +90,13 @@ test_expect_success 'merge removed a file' ' git checkout side && for i in $(test_seq 5 9) do - echo $i/5 >>$i.txt + echo $i/5 >>$i.txt || return 1 done && git commit -a -m "side 5-9" && git checkout main && for i in $(test_seq 1 3) do - echo $i/4 >>$i.txt + echo $i/4 >>$i.txt || return 1 done && git commit -a -m "main 1-3" && git merge side && diff --git a/t/t4105-apply-fuzz.sh b/t/t4105-apply-fuzz.sh index 76e2c01b0f..ed814a839e 100755 --- a/t/t4105-apply-fuzz.sh +++ b/t/t4105-apply-fuzz.sh @@ -17,15 +17,9 @@ dotest () { test_expect_success setup ' - for i in 1 2 3 4 5 6 7 8 9 10 11 12 - do - echo $i - done >file && + test_write_lines 1 2 3 4 5 6 7 8 9 10 11 12 >file && git update-index --add file && - for i in 1 2 3 4 5 6 7 a b c d e 8 9 10 11 12 - do - echo $i - done >file && + test_write_lines 1 2 3 4 5 6 7 a b c d e 8 9 10 11 12 >file && cat file >expect && git diff >O0.diff && diff --git a/t/t4106-apply-stdin.sh b/t/t4106-apply-stdin.sh index a57a318699..5c150f3b0b 100755 --- a/t/t4106-apply-stdin.sh +++ b/t/t4106-apply-stdin.sh @@ -20,7 +20,10 @@ test_expect_success 'git apply --numstat - < patch' ' ' test_expect_success 'git apply --numstat - < patch patch' ' - for i in 1 2; do echo "1 1 text"; done >expect && + cat >expect <<-\EOF && + 1 1 text + 1 1 text + EOF git apply --numstat - < patch patch >actual && test_cmp expect actual ' diff --git a/t/t4116-apply-reverse.sh b/t/t4116-apply-reverse.sh index f3b635475a..a9f4ddda6c 100755 --- a/t/t4116-apply-reverse.sh +++ b/t/t4116-apply-reverse.sh @@ -13,14 +13,14 @@ TEST_PASSES_SANITIZE_LEAK=true test_expect_success setup ' - for i in a b c d e f g h i j k l m n; do echo $i; done >file1 && + test_write_lines a b c d e f g h i j k l m n >file1 && perl -pe "y/ijk/\\000\\001\\002/" <file1 >file2 && git add file1 file2 && git commit -m initial && git tag initial && - for i in a b c g h i J K L m o n p q; do echo $i; done >file1 && + test_write_lines a b c g h i J K L m o n p q >file1 && perl -pe "y/mon/\\000\\001\\002/" <file1 >file2 && git commit -a -m second && diff --git a/t/t4117-apply-reject.sh b/t/t4117-apply-reject.sh index 0ee93fe845..c86d05a96f 100755 --- a/t/t4117-apply-reject.sh +++ b/t/t4117-apply-reject.sh @@ -10,25 +10,16 @@ test_description='git apply with rejects . ./test-lib.sh test_expect_success setup ' - for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 - do - echo $i - done >file1 && + test_write_lines 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 >file1 && cat file1 >saved.file1 && git update-index --add file1 && git commit -m initial && - for i in 1 2 A B 4 5 6 7 8 9 10 11 12 C 13 14 15 16 17 18 19 20 D 21 - do - echo $i - done >file1 && + test_write_lines 1 2 A B 4 5 6 7 8 9 10 11 12 C 13 14 15 16 17 18 19 20 D 21 >file1 && git diff >patch.1 && cat file1 >clean && - for i in 1 E 2 3 4 5 6 7 8 9 10 11 12 C 13 14 15 16 17 18 19 20 F 21 - do - echo $i - done >expected && + test_write_lines 1 E 2 3 4 5 6 7 8 9 10 11 12 C 13 14 15 16 17 18 19 20 F 21 >expected && mv file1 file2 && git update-index --add --remove file1 file2 && @@ -38,10 +29,7 @@ test_expect_success setup ' mv saved.file1 file1 && git update-index --add --remove file1 file2 && - for i in 1 E 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 F 21 - do - echo $i - done >file1 && + test_write_lines 1 E 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 F 21 >file1 && cat file1 >saved.file1 ' diff --git a/t/t4118-apply-empty-context.sh b/t/t4118-apply-empty-context.sh index 5fc6d3e4e7..69c9c48e72 100755 --- a/t/t4118-apply-empty-context.sh +++ b/t/t4118-apply-empty-context.sh @@ -12,11 +12,7 @@ TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success setup ' - { - echo; echo; - echo A; echo B; echo C; - echo; - } >file1 && + test_write_lines "" "" A B C "" >file1 && cat file1 >file1.orig && { cat file1 && diff --git a/t/t4123-apply-shrink.sh b/t/t4123-apply-shrink.sh index ef57cd3aeb..dfa053ff28 100755 --- a/t/t4123-apply-shrink.sh +++ b/t/t4123-apply-shrink.sh @@ -47,8 +47,8 @@ test_expect_success 'apply should fail gracefully' ' echo Oops, should not have succeeded false else - status=$? - echo "Status was $status" + status=$? && + echo "Status was $status" && if test -f .git/index.lock then echo Oops, should not have crashed diff --git a/t/t4124-apply-ws-rule.sh b/t/t4124-apply-ws-rule.sh index 0ca29821ec..485c7d2d12 100755 --- a/t/t4124-apply-ws-rule.sh +++ b/t/t4124-apply-ws-rule.sh @@ -230,10 +230,10 @@ test_expect_success 'blank at EOF with --whitespace=fix (1)' ' test_might_fail git config --unset core.whitespace && rm -f .gitattributes && - { echo a; echo b; echo c; } >one && + test_write_lines a b c >one && git add one && - { echo a; echo b; echo c; } >expect && - { cat expect; echo; } >one && + test_write_lines a b c >expect && + { cat expect && echo; } >one && git diff -- one >patch && git checkout one && @@ -242,10 +242,10 @@ test_expect_success 'blank at EOF with --whitespace=fix (1)' ' ' test_expect_success 'blank at EOF with --whitespace=fix (2)' ' - { echo a; echo b; echo c; } >one && + test_write_lines a b c >one && git add one && - { echo a; echo c; } >expect && - { cat expect; echo; echo; } >one && + test_write_lines a b >expect && + { cat expect && test_write_lines "" ""; } >one && git diff -- one >patch && git checkout one && @@ -254,10 +254,10 @@ test_expect_success 'blank at EOF with --whitespace=fix (2)' ' ' test_expect_success 'blank at EOF with --whitespace=fix (3)' ' - { echo a; echo b; echo; } >one && + test_write_lines a b "" >one && git add one && - { echo a; echo c; echo; } >expect && - { cat expect; echo; echo; } >one && + test_write_lines a c "" >expect && + { cat expect && test_write_lines "" ""; } >one && git diff -- one >patch && git checkout one && @@ -266,9 +266,9 @@ test_expect_success 'blank at EOF with --whitespace=fix (3)' ' ' test_expect_success 'blank at end of hunk, not at EOF with --whitespace=fix' ' - { echo a; echo b; echo; echo; echo; echo; echo; echo d; } >one && + test_write_lines a b "" "" "" "" "" d >one && git add one && - { echo a; echo c; echo; echo; echo; echo; echo; echo; echo d; } >expect && + test_write_lines a b "" "" "" "" "" "" d >expect && cp expect one && git diff -- one >patch && @@ -278,7 +278,7 @@ test_expect_success 'blank at end of hunk, not at EOF with --whitespace=fix' ' ' test_expect_success 'blank at EOF with --whitespace=warn' ' - { echo a; echo b; echo c; } >one && + test_write_lines a b c >one && git add one && echo >>one && cat one >expect && @@ -291,7 +291,7 @@ test_expect_success 'blank at EOF with --whitespace=warn' ' ' test_expect_success 'blank at EOF with --whitespace=error' ' - { echo a; echo b; echo c; } >one && + test_write_lines a b c >one && git add one && cat one >expect && echo >>one && @@ -304,7 +304,7 @@ test_expect_success 'blank at EOF with --whitespace=error' ' ' test_expect_success 'blank but not empty at EOF' ' - { echo a; echo b; echo c; } >one && + test_write_lines a b c >one && git add one && echo " " >>one && cat one >expect && @@ -317,13 +317,13 @@ test_expect_success 'blank but not empty at EOF' ' ' test_expect_success 'applying beyond EOF requires one non-blank context line' ' - { echo; echo; echo; echo; } >one && + test_write_lines "" "" "" "" >one && git add one && - { echo b; } >>one && + echo b >>one && git diff -- one >patch && git checkout one && - { echo a; echo; } >one && + test_write_lines a "" >one && cp one expect && test_must_fail git apply --whitespace=fix patch && test_cmp expect one && @@ -333,7 +333,7 @@ test_expect_success 'applying beyond EOF requires one non-blank context line' ' test_expect_success 'tons of blanks at EOF should not apply' ' for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16; do - echo; echo; echo; echo; + test_write_lines "" "" "" "" || return 1 done >one && git add one && echo a >>one && @@ -362,9 +362,9 @@ test_expect_success 'missing blank line at end with --whitespace=fix' ' ' test_expect_success 'two missing blank lines at end with --whitespace=fix' ' - { echo a; echo; echo b; echo c; } >one && + test_write_lines a "" b c >one && cp one no-blank-lines && - { echo; echo; } >>one && + test_write_lines "" "" >>one && git add one && echo d >>one && cp one expect && @@ -381,9 +381,9 @@ test_expect_success 'two missing blank lines at end with --whitespace=fix' ' ' test_expect_success 'missing blank line at end, insert before end, --whitespace=fix' ' - { echo a; echo; } >one && + test_write_lines a "" >one && git add one && - { echo b; echo a; echo; } >one && + test_write_lines b a "" >one && cp one expect && git diff -- one >patch && echo a >one && @@ -393,10 +393,10 @@ test_expect_success 'missing blank line at end, insert before end, --whitespace= ' test_expect_success 'shrink file with tons of missing blanks at end of file' ' - { echo a; echo b; echo c; } >one && + test_write_lines a b c >one && cp one no-blank-lines && for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16; do - echo; echo; echo; echo; + test_write_lines "" "" "" "" || return 1 done >>one && git add one && echo a >one && @@ -412,9 +412,9 @@ test_expect_success 'shrink file with tons of missing blanks at end of file' ' ' test_expect_success 'missing blanks at EOF must only match blank lines' ' - { echo a; echo b; } >one && + test_write_lines a b >one && git add one && - { echo c; echo d; } >>one && + test_write_lines c d >>one && git diff -- one >patch && echo a >one && @@ -434,9 +434,9 @@ test_expect_success 'missing blank line should match context line with spaces' ' git add one && echo d >>one && git diff -- one >patch && - { echo a; echo b; echo c; } >one && + test_write_lines a b c >one && cp one expect && - { echo; echo d; } >>expect && + test_write_lines "" d >>expect && git add one && git apply --whitespace=fix patch && @@ -455,7 +455,7 @@ test_expect_success 'same, but with the --ignore-space-option' ' echo d >>one && cp one expect && git diff -- one >patch && - { echo a; echo b; echo c; } >one && + test_write_lines a b c >one && git add one && git checkout-index -f one && diff --git a/t/t4125-apply-ws-fuzz.sh b/t/t4125-apply-ws-fuzz.sh index 9671de7999..090987c89b 100755 --- a/t/t4125-apply-ws-fuzz.sh +++ b/t/t4125-apply-ws-fuzz.sh @@ -10,10 +10,7 @@ test_expect_success setup ' git add file && # file-0 is full of whitespace breakages - for l in a bb c d eeee f ggg h - do - echo "$l " - done >file-0 && + printf "%s \n" a bb c d eeee f ggg h >file-0 && # patch-0 creates a whitespace broken file cat file-0 >file && diff --git a/t/t4126-apply-empty.sh b/t/t4126-apply-empty.sh index a361e79a81..33860d3829 100755 --- a/t/t4126-apply-empty.sh +++ b/t/t4126-apply-empty.sh @@ -11,10 +11,9 @@ test_expect_success setup ' git add empty && test_tick && git commit -m initial && - for i in a b c d e - do - echo $i - done >empty && + git commit --allow-empty -m "empty commit" && + git format-patch --always HEAD~ >empty.patch && + test_write_lines a b c d e >empty && cat empty >expect && git diff | sed -e "/^diff --git/d" \ @@ -27,30 +26,42 @@ test_expect_success setup ' ' test_expect_success 'apply empty' ' - git reset --hard && rm -f missing && + test_when_finished "git reset --hard" && git apply patch0 && test_cmp expect empty ' +test_expect_success 'apply empty patch fails' ' + test_when_finished "git reset --hard" && + test_must_fail git apply empty.patch && + test_must_fail git apply - </dev/null +' + +test_expect_success 'apply with --allow-empty succeeds' ' + test_when_finished "git reset --hard" && + git apply --allow-empty empty.patch && + git apply --allow-empty - </dev/null +' + test_expect_success 'apply --index empty' ' - git reset --hard && rm -f missing && + test_when_finished "git reset --hard" && git apply --index patch0 && test_cmp expect empty && git diff --exit-code ' test_expect_success 'apply create' ' - git reset --hard && rm -f missing && + test_when_finished "git reset --hard" && git apply patch1 && test_cmp expect missing ' test_expect_success 'apply --index create' ' - git reset --hard && rm -f missing && + test_when_finished "git reset --hard" && git apply --index patch1 && test_cmp expect missing && git diff --exit-code diff --git a/t/t4127-apply-same-fn.sh b/t/t4127-apply-same-fn.sh index c27e9aec57..aa5cfae2b6 100755 --- a/t/t4127-apply-same-fn.sh +++ b/t/t4127-apply-same-fn.sh @@ -12,10 +12,7 @@ modify () { } test_expect_success setup ' - for i in a b c d e f g h i j k l m - do - echo $i - done >same_fn && + test_write_lines a b c d e f g h i j k l m >same_fn && cp same_fn other_fn && git add same_fn other_fn && git commit -m initial diff --git a/t/t4138-apply-ws-expansion.sh b/t/t4138-apply-ws-expansion.sh index b19faeb67a..8bbf8260fa 100755 --- a/t/t4138-apply-ws-expansion.sh +++ b/t/t4138-apply-ws-expansion.sh @@ -29,8 +29,8 @@ test_expect_success setup ' x=1 && while test $x -lt $n do - printf "%63s%d\n" "" $x >>after - x=$(( $x + 1 )) + printf "%63s%d\n" "" $x >>after && + x=$(( $x + 1 )) || return 1 done && printf "\t%s\n" d e f >>after && test_expect_code 1 git diff --no-index before after >patch2.patch.raw && @@ -40,8 +40,8 @@ test_expect_success setup ' x=1 && while test $x -lt $n do - printf "%63s%d\n" "" $x >>expect-2 - x=$(( $x + 1 )) + printf "%63s%d\n" "" $x >>expect-2 && + x=$(( $x + 1 )) || return 1 done && printf "%64s\n" d e f >>expect-2 && @@ -52,8 +52,8 @@ test_expect_success setup ' x=0 && while test $x -lt $n do - printf "%63s%02d\n" "" $x >>after - x=$(( $x + 1 )) + printf "%63s%02d\n" "" $x >>after && + x=$(( $x + 1 )) || return 1 done && printf "\t%s\n" d e f >>after && test_expect_code 1 git diff --no-index before after >patch3.patch.raw && @@ -63,8 +63,8 @@ test_expect_success setup ' x=0 && while test $x -lt $n do - printf "%63s%02d\n" "" $x >>expect-3 - x=$(( $x + 1 )) + printf "%63s%02d\n" "" $x >>expect-3 && + x=$(( $x + 1 )) || return 1 done && printf "%64s\n" d e f >>expect-3 && @@ -73,16 +73,16 @@ test_expect_success setup ' x=0 && while test $x -lt 50 do - printf "\t%02d\n" $x >>before - x=$(( $x + 1 )) + printf "\t%02d\n" $x >>before && + x=$(( $x + 1 )) || return 1 done && cat before >after && printf "%64s\n" a b c >>after && while test $x -lt 100 do - printf "\t%02d\n" $x >>before - printf "\t%02d\n" $x >>after - x=$(( $x + 1 )) + printf "\t%02d\n" $x >>before && + printf "\t%02d\n" $x >>after && + x=$(( $x + 1 )) || return 1 done && test_expect_code 1 git diff --no-index before after >patch4.patch.raw && sed -e "s/before/test-4/" -e "s/after/test-4/" patch4.patch.raw >patch4.patch && @@ -90,16 +90,16 @@ test_expect_success setup ' x=0 && while test $x -lt 50 do - printf "%63s%02d\n" "" $x >>test-4 - x=$(( $x + 1 )) + printf "%63s%02d\n" "" $x >>test-4 && + x=$(( $x + 1 )) || return 1 done && cat test-4 >expect-4 && printf "%64s\n" a b c >>expect-4 && while test $x -lt 100 do - printf "%63s%02d\n" "" $x >>test-4 - printf "%63s%02d\n" "" $x >>expect-4 - x=$(( $x + 1 )) + printf "%63s%02d\n" "" $x >>test-4 && + printf "%63s%02d\n" "" $x >>expect-4 && + x=$(( $x + 1 )) || return 1 done && git config core.whitespace tab-in-indent,tabwidth=63 && diff --git a/t/t4150-am.sh b/t/t4150-am.sh index 2aaaa0d7de..6caff0ca39 100755 --- a/t/t4150-am.sh +++ b/t/t4150-am.sh @@ -116,7 +116,7 @@ test_expect_success setup ' git format-patch --stdout first | sed -e "1d" } | append_cr >patch1-crlf.eml && { - printf "%255s\\n" "" + printf "%255s\\n" "" && echo "X-Fake-Field: Line One" && echo "X-Fake-Field: Line Two" && echo "X-Fake-Field: Line Three" && @@ -196,6 +196,12 @@ test_expect_success setup ' git format-patch -M --stdout lorem^ >rename-add.patch && + git checkout -b empty-commit && + git commit -m "empty commit" --allow-empty && + + : >empty.patch && + git format-patch --always --stdout empty-commit^ >empty-commit.patch && + # reset time sane_unset test_tick && test_tick @@ -1152,4 +1158,105 @@ test_expect_success 'apply binary blob in partial clone' ' git -C client am ../patch ' +test_expect_success 'an empty input file is error regardless of --empty option' ' + test_when_finished "git am --abort || :" && + test_must_fail git am --empty=drop empty.patch 2>actual && + echo "Patch format detection failed." >expected && + test_cmp expected actual +' + +test_expect_success 'invalid when passing the --empty option alone' ' + test_when_finished "git am --abort || :" && + git checkout empty-commit^ && + test_must_fail git am --empty empty-commit.patch 2>err && + echo "error: Invalid value for --empty: empty-commit.patch" >expected && + test_cmp expected err +' + +test_expect_success 'a message without a patch is an error (default)' ' + test_when_finished "git am --abort || :" && + test_must_fail git am empty-commit.patch >err && + grep "Patch is empty" err +' + +test_expect_success 'a message without a patch is an error where an explicit "--empty=stop" is given' ' + test_when_finished "git am --abort || :" && + test_must_fail git am --empty=stop empty-commit.patch >err && + grep "Patch is empty." err +' + +test_expect_success 'a message without a patch will be skipped when "--empty=drop" is given' ' + git am --empty=drop empty-commit.patch >output && + git rev-parse empty-commit^ >expected && + git rev-parse HEAD >actual && + test_cmp expected actual && + grep "Skipping: empty commit" output +' + +test_expect_success 'record as an empty commit when meeting e-mail message that lacks a patch' ' + git am --empty=keep empty-commit.patch >output && + test_path_is_missing .git/rebase-apply && + git show empty-commit --format="%B" >expected && + git show HEAD --format="%B" >actual && + grep -f actual expected && + grep "Creating an empty commit: empty commit" output +' + +test_expect_success 'skip an empty patch in the middle of an am session' ' + git checkout empty-commit^ && + test_must_fail git am empty-commit.patch >err && + grep "Patch is empty." err && + grep "To record the empty patch as an empty commit, run \"git am --allow-empty\"." err && + git am --skip && + test_path_is_missing .git/rebase-apply && + git rev-parse empty-commit^ >expected && + git rev-parse HEAD >actual && + test_cmp expected actual +' + +test_expect_success 'record an empty patch as an empty commit in the middle of an am session' ' + git checkout empty-commit^ && + test_must_fail git am empty-commit.patch >err && + grep "Patch is empty." err && + grep "To record the empty patch as an empty commit, run \"git am --allow-empty\"." err && + git am --allow-empty >output && + grep "No changes - recorded it as an empty commit." output && + test_path_is_missing .git/rebase-apply && + git show empty-commit --format="%B" >expected && + git show HEAD --format="%B" >actual && + grep -f actual expected +' + +test_expect_success 'create an non-empty commit when the index IS changed though "--allow-empty" is given' ' + git checkout empty-commit^ && + test_must_fail git am empty-commit.patch >err && + : >empty-file && + git add empty-file && + git am --allow-empty && + git show empty-commit --format="%B" >expected && + git show HEAD --format="%B" >actual && + grep -f actual expected && + git diff HEAD^..HEAD --name-only +' + +test_expect_success 'cannot create empty commits when there is a clean index due to merge conflicts' ' + test_when_finished "git am --abort || :" && + git rev-parse HEAD >expected && + test_must_fail git am seq.patch && + test_must_fail git am --allow-empty >err && + ! grep "To record the empty patch as an empty commit, run \"git am --allow-empty\"." err && + git rev-parse HEAD >actual && + test_cmp actual expected +' + +test_expect_success 'cannot create empty commits when there is unmerged index due to merge conflicts' ' + test_when_finished "git am --abort || :" && + git rev-parse HEAD >expected && + test_must_fail git am -3 seq.patch && + test_must_fail git am --allow-empty >err && + ! grep "To record the empty patch as an empty commit, run \"git am --allow-empty\"." err && + git rev-parse HEAD >actual && + test_cmp actual expected +' + test_done diff --git a/t/t4151-am-abort.sh b/t/t4151-am-abort.sh index 2374151662..5ed7e22827 100755 --- a/t/t4151-am-abort.sh +++ b/t/t4151-am-abort.sh @@ -5,10 +5,7 @@ test_description='am --abort' . ./test-lib.sh test_expect_success setup ' - for i in a b c d e f g - do - echo $i - done >file-1 && + test_write_lines a b c d e f g >file-1 && cp file-1 file-2 && test_tick && git add file-1 file-2 && @@ -43,10 +40,7 @@ do test_must_fail git am$with3 000[1245]-*.patch && git log --pretty=tformat:%s >actual && - for i in 3 2 initial - do - echo $i - done >expect && + test_write_lines 3 2 initial >expect && test_cmp expect actual ' diff --git a/t/t4202-log.sh b/t/t4202-log.sh index 2ced7e9d81..5049559861 100755 --- a/t/t4202-log.sh +++ b/t/t4202-log.sh @@ -120,48 +120,48 @@ test_expect_success 'diff-filter=A' ' test_expect_success 'diff-filter=M' ' - actual=$(git log --pretty="format:%s" --diff-filter=M HEAD) && - expect=$(echo second) && - verbose test "$actual" = "$expect" + git log --pretty="format:%s" --diff-filter=M HEAD >actual && + printf "second" >expect && + test_cmp expect actual ' test_expect_success 'diff-filter=D' ' - actual=$(git log --no-renames --pretty="format:%s" --diff-filter=D HEAD) && - expect=$(echo sixth ; echo third) && - verbose test "$actual" = "$expect" + git log --no-renames --pretty="format:%s" --diff-filter=D HEAD >actual && + printf "sixth\nthird" >expect && + test_cmp expect actual ' test_expect_success 'diff-filter=R' ' - actual=$(git log -M --pretty="format:%s" --diff-filter=R HEAD) && - expect=$(echo third) && - verbose test "$actual" = "$expect" + git log -M --pretty="format:%s" --diff-filter=R HEAD >actual && + printf "third" >expect && + test_cmp expect actual ' test_expect_success 'diff-filter=C' ' - actual=$(git log -C -C --pretty="format:%s" --diff-filter=C HEAD) && - expect=$(echo fourth) && - verbose test "$actual" = "$expect" + git log -C -C --pretty="format:%s" --diff-filter=C HEAD >actual && + printf "fourth" >expect && + test_cmp expect actual ' test_expect_success 'git log --follow' ' - actual=$(git log --follow --pretty="format:%s" ichi) && - expect=$(echo third ; echo second ; echo initial) && - verbose test "$actual" = "$expect" + git log --follow --pretty="format:%s" ichi >actual && + printf "third\nsecond\ninitial" >expect && + test_cmp expect actual ' test_expect_success 'git config log.follow works like --follow' ' test_config log.follow true && - actual=$(git log --pretty="format:%s" ichi) && - expect=$(echo third ; echo second ; echo initial) && - verbose test "$actual" = "$expect" + git log --pretty="format:%s" ichi >actual && + printf "third\nsecond\ninitial" >expect && + test_cmp expect actual ' test_expect_success 'git config log.follow does not die with multiple paths' ' @@ -176,9 +176,9 @@ test_expect_success 'git config log.follow does not die with no paths' ' test_expect_success 'git config log.follow is overridden by --no-follow' ' test_config log.follow true && - actual=$(git log --no-follow --pretty="format:%s" ichi) && - expect="third" && - verbose test "$actual" = "$expect" + git log --no-follow --pretty="format:%s" ichi >actual && + printf "third" >expect && + test_cmp expect actual ' # Note that these commits are intentionally listed out of order. @@ -250,7 +250,7 @@ test_expect_success 'log --invert-grep --grep' ' test_cmp expect actual && # POSIX extended - git -c grep.patternType=basic log --pretty="tformat:%s" --invert-grep --grep=t[h] --grep=S[e]c >actual && + git -c grep.patternType=extended log --pretty="tformat:%s" --invert-grep --grep=t[h] --grep=S[e]c >actual && test_cmp expect actual && # PCRE @@ -2090,4 +2090,23 @@ test_expect_success 'log --end-of-options' ' test_cmp expect actual ' +test_expect_success 'set up commits with different authors' ' + git checkout --orphan authors && + test_commit --author "Jim <jim@example.com>" jim_1 && + test_commit --author "Val <val@example.com>" val_1 && + test_commit --author "Val <val@example.com>" val_2 && + test_commit --author "Jim <jim@example.com>" jim_2 && + test_commit --author "Val <val@example.com>" val_3 && + test_commit --author "Jim <jim@example.com>" jim_3 +' + +test_expect_success 'log --invert-grep --grep --author' ' + cat >expect <<-\EOF && + val_3 + val_1 + EOF + git log --format=%s --author=Val --grep 2 --invert-grep >actual && + test_cmp expect actual +' + test_done diff --git a/t/t4204-patch-id.sh b/t/t4204-patch-id.sh index e78d8097f3..80f4a65b28 100755 --- a/t/t4204-patch-id.sh +++ b/t/t4204-patch-id.sh @@ -5,7 +5,6 @@ test_description='git patch-id' GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME -TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' @@ -28,7 +27,8 @@ test_expect_success 'setup' ' ' test_expect_success 'patch-id output is well-formed' ' - git log -p -1 | git patch-id >output && + git log -p -1 >log.output && + git patch-id <log.output >output && grep "^$OID_REGEX $(git rev-parse HEAD)$" output ' @@ -36,8 +36,8 @@ test_expect_success 'patch-id output is well-formed' ' calc_patch_id () { patch_name="$1" shift - git patch-id "$@" | - sed "s/ .*//" >patch-id_"$patch_name" && + git patch-id "$@" >patch-id.output && + sed "s/ .*//" patch-id.output >patch-id_"$patch_name" && test_line_count -gt 0 patch-id_"$patch_name" } @@ -46,7 +46,8 @@ get_top_diff () { } get_patch_id () { - get_top_diff "$1" | calc_patch_id "$@" + get_top_diff "$1" >top-diff.output && + calc_patch_id <top-diff.output "$@" } test_expect_success 'patch-id detects equality' ' @@ -64,16 +65,18 @@ test_expect_success 'patch-id detects inequality' ' test_expect_success 'patch-id supports git-format-patch output' ' get_patch_id main && git checkout same && - git format-patch -1 --stdout | calc_patch_id same && + git format-patch -1 --stdout >format-patch.output && + calc_patch_id same <format-patch.output && test_cmp patch-id_main patch-id_same && - set $(git format-patch -1 --stdout | git patch-id) && + set $(git patch-id <format-patch.output) && test "$2" = $(git rev-parse HEAD) ' test_expect_success 'whitespace is irrelevant in footer' ' get_patch_id main && git checkout same && - git format-patch -1 --stdout | sed "s/ \$//" | calc_patch_id same && + git format-patch -1 --stdout >format-patch.output && + sed "s/ \$//" format-patch.output | calc_patch_id same && test_cmp patch-id_main patch-id_same ' @@ -92,10 +95,11 @@ test_patch_id_file_order () { shift name="order-${1}-$relevant" shift - get_top_diff "main" | calc_patch_id "$name" "$@" && + get_top_diff "main" >top-diff.output && + calc_patch_id <top-diff.output "$name" "$@" && git checkout same && - git format-patch -1 --stdout -O foo-then-bar | - calc_patch_id "ordered-$name" "$@" && + git format-patch -1 --stdout -O foo-then-bar >format-patch.output && + calc_patch_id <format-patch.output "ordered-$name" "$@" && cmp_patch_id $relevant "$name" "ordered-$name" } @@ -143,7 +147,8 @@ test_expect_success '--stable overrides patchid.stable = false' ' test_expect_success 'patch-id supports git-format-patch MIME output' ' get_patch_id main && git checkout same && - git format-patch -1 --attach --stdout | calc_patch_id same && + git format-patch -1 --attach --stdout >format-patch.output && + calc_patch_id <format-patch.output same && test_cmp patch-id_main patch-id_same ' diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index 35eef4c865..e448ef2928 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -976,7 +976,7 @@ test_expect_success '%(describe) vs git describe' ' else : >expect-contains-bad fi && - echo "$hash $desc" + echo "$hash $desc" || return 1 done >expect && test_path_exists expect-contains-good && test_path_exists expect-contains-bad && diff --git a/t/t4211-line-log.sh b/t/t4211-line-log.sh index 560127cc07..ac9e4d0928 100755 --- a/t/t4211-line-log.sh +++ b/t/t4211-line-log.sh @@ -137,7 +137,7 @@ test_expect_success 'range_set_union' ' test_seq 1000 > c.c && git add c.c && git commit -m "modify many lines" && - git log $(for x in $(test_seq 200); do echo -L $((2*x)),+1:c.c; done) + git log $(for x in $(test_seq 200); do echo -L $((2*x)),+1:c.c || return 1; done) ' test_expect_success '-s shows only line-log commits' ' diff --git a/t/t4212-log-corrupt.sh b/t/t4212-log-corrupt.sh index 03b952c90d..0244888a5a 100755 --- a/t/t4212-log-corrupt.sh +++ b/t/t4212-log-corrupt.sh @@ -20,10 +20,10 @@ test_expect_success 'fsck notices broken commit' ' test_expect_success 'git log with broken author email' ' { - echo commit $(cat broken_email.hash) - echo "Author: A U Thor <author@example.com>" - echo "Date: Thu Apr 7 15:13:13 2005 -0700" - echo + echo commit $(cat broken_email.hash) && + echo "Author: A U Thor <author@example.com>" && + echo "Date: Thu Apr 7 15:13:13 2005 -0700" && + echo && echo " foo" } >expect.out && diff --git a/t/t4216-log-bloom.sh b/t/t4216-log-bloom.sh index 8018c12a6a..cc3cebf672 100755 --- a/t/t4216-log-bloom.sh +++ b/t/t4216-log-bloom.sh @@ -374,7 +374,7 @@ test_expect_success 'Bloom generation backfills empty commits' ' cd empty && for i in $(test_seq 1 6) do - git commit --allow-empty -m "$i" + git commit --allow-empty -m "$i" || return 1 done && # Generate Bloom filters for empty commits 1-6, two at a time. @@ -387,7 +387,7 @@ test_expect_success 'Bloom generation backfills empty commits' ' test_filter_computed 2 trace.event && test_filter_not_computed 4 trace.event && test_filter_trunc_empty 2 trace.event && - test_filter_trunc_large 0 trace.event + test_filter_trunc_large 0 trace.event || return 1 done && # Finally, make sure that once all commits have filters, that diff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh index 2c88d1c159..7f8d2ab0a7 100755 --- a/t/t5000-tar-tree.sh +++ b/t/t5000-tar-tree.sh @@ -77,7 +77,7 @@ check_tar() { path=$(get_pax_header $header path) && if test -n "$path" then - mv "$data" "$path" + mv "$data" "$path" || exit 1 fi fi done @@ -133,7 +133,7 @@ test_expect_success 'populate workdir' ' for depth in 1 2 3 4 5 do mkdir $p && - cd $p + cd $p || exit 1 done && echo text >file_with_long_path ) && diff --git a/t/t5003-archive-zip.sh b/t/t5003-archive-zip.sh index 1e6d18b140..d726964307 100755 --- a/t/t5003-archive-zip.sh +++ b/t/t5003-archive-zip.sh @@ -106,7 +106,7 @@ test_expect_success \ printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 && printf "A not substituted O" >a/substfile2 && (p=long_path_to_a_file && cd a && - for depth in 1 2 3 4 5; do mkdir $p && cd $p; done && + for depth in 1 2 3 4 5; do mkdir $p && cd $p || exit 1; done && echo text >file_with_long_path) ' diff --git a/t/t5004-archive-corner-cases.sh b/t/t5004-archive-corner-cases.sh index 2d32d0ed12..ae508e2162 100755 --- a/t/t5004-archive-corner-cases.sh +++ b/t/t5004-archive-corner-cases.sh @@ -131,7 +131,7 @@ test_expect_success ZIPINFO 'zip archive with many entries' ' do for b in 0 1 2 3 4 5 6 7 8 9 a b c d e f do - : >00/$a$b + : >00/$a$b || return 1 done done && git add 00 && @@ -143,7 +143,7 @@ test_expect_success ZIPINFO 'zip archive with many entries' ' do for d in 0 1 2 3 4 5 6 7 8 9 a b c d e f do - echo "040000 tree $subtree $c$d" + echo "040000 tree $subtree $c$d" || return 1 done done >tree && tree=$(git mktree <tree) && @@ -171,7 +171,7 @@ test_expect_success EXPENSIVE,UNZIP,UNZIP_ZIP64_SUPPORT \ # create tree containing 65500 entries of that blob for i in $(test_seq 1 65500) do - echo "100644 blob $blob $i" + echo "100644 blob $blob $i" || return 1 done >tree && tree=$(git mktree <tree) && diff --git a/t/t5100-mailinfo.sh b/t/t5100-mailinfo.sh index 141b29f031..cebad1048c 100755 --- a/t/t5100-mailinfo.sh +++ b/t/t5100-mailinfo.sh @@ -122,7 +122,7 @@ test_expect_success 'mailinfo unescapes with --mboxrd' ' do git mailinfo mboxrd/msg mboxrd/patch \ <mboxrd/$i >mboxrd/out && - test_cmp "$DATA/${i}mboxrd" mboxrd/msg + test_cmp "$DATA/${i}mboxrd" mboxrd/msg || return 1 done && sp=" " && echo "From " >expect && diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh index e13a884207..2fd845187e 100755 --- a/t/t5300-pack-object.sh +++ b/t/t5300-pack-object.sh @@ -347,7 +347,7 @@ test_expect_success 'unpacking with --strict' ' for i in 0 1 2 3 4 5 6 7 8 9 do o=$(echo $j$i | git hash-object -w --stdin) && - echo "100644 $o 0 $j$i" + echo "100644 $o 0 $j$i" || return 1 done done >LIST && rm -f .git/index && @@ -361,11 +361,7 @@ test_expect_success 'unpacking with --strict' ' ST=$(git write-tree) && git rev-list --objects "$LIST" "$LI" "$ST" >actual && PACK5=$( git pack-objects test-5 <actual ) && - PACK6=$( ( - echo "$LIST" - echo "$LI" - echo "$ST" - ) | git pack-objects test-6 ) && + PACK6=$( test_write_lines "$LIST" "$LI" "$ST" | git pack-objects test-6 ) && test_create_repo test-5 && ( cd test-5 && @@ -394,7 +390,7 @@ test_expect_success 'index-pack with --strict' ' for i in 0 1 2 3 4 5 6 7 8 9 do o=$(echo $j$i | git hash-object -w --stdin) && - echo "100644 $o 0 $j$i" + echo "100644 $o 0 $j$i" || return 1 done done >LIST && rm -f .git/index && @@ -408,11 +404,7 @@ test_expect_success 'index-pack with --strict' ' ST=$(git write-tree) && git rev-list --objects "$LIST" "$LI" "$ST" >actual && PACK5=$( git pack-objects test-5 <actual ) && - PACK6=$( ( - echo "$LIST" - echo "$LI" - echo "$ST" - ) | git pack-objects test-6 ) && + PACK6=$( test_write_lines "$LIST" "$LI" "$ST" | git pack-objects test-6 ) && test_create_repo test-7 && ( cd test-7 && @@ -594,7 +586,7 @@ test_expect_success 'setup for --stdin-packs tests' ' for id in A B C do git pack-objects .git/objects/pack/pack-$id \ - --incremental --revs <<-EOF + --incremental --revs <<-EOF || exit 1 refs/tags/$id EOF done && diff --git a/t/t5302-pack-index.sh b/t/t5302-pack-index.sh index 7c9d687367..8ee67df38f 100755 --- a/t/t5302-pack-index.sh +++ b/t/t5302-pack-index.sh @@ -14,7 +14,7 @@ test_expect_success 'setup' ' i=1 && while test $i -le 100 do - iii=$(printf "%03i" $i) + iii=$(printf "%03i" $i) && test-tool genrandom "bar" 200 > wide_delta_$iii && test-tool genrandom "baz $iii" 50 >> wide_delta_$iii && test-tool genrandom "foo"$i 100 > deep_delta_$iii && diff --git a/t/t5306-pack-nobase.sh b/t/t5306-pack-nobase.sh index f4931c0c2a..51973f4a51 100755 --- a/t/t5306-pack-nobase.sh +++ b/t/t5306-pack-nobase.sh @@ -12,7 +12,7 @@ test_description='git-pack-object with missing base # test_expect_success \ 'setup base' \ - 'for a in a b c d e f g h i; do echo $a >>text; done && + 'test_write_lines a b c d e f g h i >text && echo side >side && git update-index --add text side && A=$(echo A | git commit-tree $(git write-tree)) && diff --git a/t/t5307-pack-missing-commit.sh b/t/t5307-pack-missing-commit.sh index d3482ab279..1e02c305c4 100755 --- a/t/t5307-pack-missing-commit.sh +++ b/t/t5307-pack-missing-commit.sh @@ -12,7 +12,7 @@ test_expect_success setup ' git add "file$i" && test_tick && git commit -m "$i" && - git tag "tag$i" + git tag "tag$i" || return 1 done && obj=$(git rev-parse --verify tag3) && fanout=$(expr "$obj" : "\(..\)") && diff --git a/t/t5310-pack-bitmaps.sh b/t/t5310-pack-bitmaps.sh index cbd33d5bde..d05ab716f6 100755 --- a/t/t5310-pack-bitmaps.sh +++ b/t/t5310-pack-bitmaps.sh @@ -228,7 +228,7 @@ test_expect_success 'pack reuse respects --honor-pack-keep' ' test_when_finished "rm -f .git/objects/pack/*.keep" && for i in .git/objects/pack/*.pack do - >${i%.pack}.keep + >${i%.pack}.keep || return 1 done && reusable_pack --honor-pack-keep >empty.pack && git index-pack empty.pack && diff --git a/t/t5316-pack-delta-depth.sh b/t/t5316-pack-delta-depth.sh index 759169d074..df524f7b6d 100755 --- a/t/t5316-pack-delta-depth.sh +++ b/t/t5316-pack-delta-depth.sh @@ -57,8 +57,11 @@ test_expect_success 'create series of packs' ' git commit -m $i && cur=$(git rev-parse HEAD^{tree}) && { - test -n "$prev" && echo "-$prev" - echo $cur + if test -n "$prev" + then + echo "-$prev" + fi && + echo $cur && echo "$(git rev-parse :file) file" } | git pack-objects --stdout >tmp && git index-pack --stdin --fix-thin <tmp || return 1 diff --git a/t/t5317-pack-objects-filter-objects.sh b/t/t5317-pack-objects-filter-objects.sh index 13ed3eb136..33b740ce62 100755 --- a/t/t5317-pack-objects-filter-objects.sh +++ b/t/t5317-pack-objects-filter-objects.sh @@ -16,9 +16,9 @@ test_expect_success 'setup r1' ' git init r1 && for n in 1 2 3 4 5 do - echo "This is file: $n" > r1/file.$n - git -C r1 add file.$n - git -C r1 commit -m "$n" + echo "This is file: $n" > r1/file.$n && + git -C r1 add file.$n && + git -C r1 commit -m "$n" || return 1 done ' @@ -116,9 +116,9 @@ test_expect_success 'setup r2' ' git init r2 && for n in 1000 10000 do - printf "%"$n"s" X > r2/large.$n - git -C r2 add large.$n - git -C r2 commit -m "$n" + printf "%"$n"s" X > r2/large.$n && + git -C r2 add large.$n && + git -C r2 commit -m "$n" || return 1 done ' @@ -278,10 +278,10 @@ test_expect_success 'setup r3' ' mkdir r3/dir1 && for n in sparse1 sparse2 do - echo "This is file: $n" > r3/$n - git -C r3 add $n - echo "This is file: dir1/$n" > r3/dir1/$n - git -C r3 add dir1/$n + echo "This is file: $n" > r3/$n && + git -C r3 add $n && + echo "This is file: dir1/$n" > r3/dir1/$n && + git -C r3 add dir1/$n || return 1 done && git -C r3 commit -m "sparse" && echo dir1/ >pattern1 && @@ -331,10 +331,10 @@ test_expect_success 'setup r4' ' mkdir r4/dir1 && for n in sparse1 sparse2 do - echo "This is file: $n" > r4/$n - git -C r4 add $n - echo "This is file: dir1/$n" > r4/dir1/$n - git -C r4 add dir1/$n + echo "This is file: $n" > r4/$n && + git -C r4 add $n && + echo "This is file: dir1/$n" > r4/dir1/$n && + git -C r4 add dir1/$n || return 1 done && echo dir1/ >r4/pattern && git -C r4 add pattern && @@ -409,7 +409,7 @@ test_expect_success 'setup r1 - delete loose blobs' ' for id in `cat expected | sed "s|..|&/|"` do - rm r1/.git/objects/$id + rm r1/.git/objects/$id || return 1 done ' diff --git a/t/t5318-commit-graph.sh b/t/t5318-commit-graph.sh index f516fda7cc..edb728f77c 100755 --- a/t/t5318-commit-graph.sh +++ b/t/t5318-commit-graph.sh @@ -64,7 +64,7 @@ test_expect_success 'create commits and repack' ' for i in $(test_seq 3) do test_commit $i && - git branch commits/$i + git branch commits/$i || return 1 done && git repack ' @@ -147,13 +147,13 @@ test_expect_success 'Add more commits' ' for i in $(test_seq 4 5) do test_commit $i && - git branch commits/$i + git branch commits/$i || return 1 done && git reset --hard commits/2 && for i in $(test_seq 6 7) do test_commit $i && - git branch commits/$i + git branch commits/$i || return 1 done && git reset --hard commits/2 && git merge commits/4 && diff --git a/t/t5319-multi-pack-index.sh b/t/t5319-multi-pack-index.sh index a612e44547..afbe93f162 100755 --- a/t/t5319-multi-pack-index.sh +++ b/t/t5319-multi-pack-index.sh @@ -93,7 +93,7 @@ test_expect_success 'create objects' ' test_commit initial && for i in $(test_seq 1 5) do - generate_objects $i + generate_objects $i || return 1 done && commit_and_list_objects ' @@ -155,7 +155,7 @@ test_expect_success 'corrupt idx reports errors' ' test_expect_success 'add more objects' ' for i in $(test_seq 6 10) do - generate_objects $i + generate_objects $i || return 1 done && commit_and_list_objects ' @@ -203,7 +203,7 @@ test_expect_success 'add more packs' ' do generate_objects $j && commit_and_list_objects && - git pack-objects --index-version=2 $objdir/pack/test-pack <obj-list + git pack-objects --index-version=2 $objdir/pack/test-pack <obj-list || return 1 done ' @@ -596,7 +596,7 @@ test_expect_success 'force some 64-bit offsets with pack-objects' ' mkdir objects64/pack && for i in $(test_seq 1 11) do - generate_objects 11 + generate_objects 11 || return 1 done && commit_and_list_objects && pack64=$(git pack-objects --index-version=2,0x40 objects64/pack/test-64 <obj-list) && @@ -640,7 +640,7 @@ test_expect_success 'setup expire tests' ' git update-index --add large_file.txt && for i in $(test_seq 1 20) do - test_commit $i + test_commit $i || exit 1 done && git branch A HEAD && git branch B HEAD~8 && diff --git a/t/t5322-pack-objects-sparse.sh b/t/t5322-pack-objects-sparse.sh index 61cb907a90..d39958c066 100755 --- a/t/t5322-pack-objects-sparse.sh +++ b/t/t5322-pack-objects-sparse.sh @@ -14,7 +14,7 @@ test_expect_success 'setup repo' ' for j in $(test_seq 1 3) do mkdir f$i/f$j && - echo $j >f$i/f$j/data.txt + echo $j >f$i/f$j/data.txt || return 1 done done && git add . && @@ -23,7 +23,7 @@ test_expect_success 'setup repo' ' do git checkout -b topic$i main && echo change-$i >f$i/f$i/data.txt && - git commit -a -m "Changed f$i/f$i/data.txt" + git commit -a -m "Changed f$i/f$i/data.txt" || return 1 done && cat >packinput.txt <<-EOF && topic1 diff --git a/t/t5325-reverse-index.sh b/t/t5325-reverse-index.sh index da453f68d6..d042d26f2b 100755 --- a/t/t5325-reverse-index.sh +++ b/t/t5325-reverse-index.sh @@ -46,7 +46,7 @@ test_expect_success 'index-pack with --[no-]rev-index' ' test_path_exists $rev && test_index_pack "$conf" --no-rev-index && - test_path_is_missing $rev + test_path_is_missing $rev || return 1 done ' diff --git a/t/t5500-fetch-pack.sh b/t/t5500-fetch-pack.sh index 8a5d3492c7..f0dc4e6968 100755 --- a/t/t5500-fetch-pack.sh +++ b/t/t5500-fetch-pack.sh @@ -95,7 +95,7 @@ test_expect_success 'setup' ' while [ $cur -le 10 ]; do add A$cur $(eval echo \$A$prev) && prev=$cur && - cur=$(($cur+1)) + cur=$(($cur+1)) || return 1 done && add B1 $A1 && git update-ref refs/heads/A "$ATIP" && @@ -112,7 +112,7 @@ test_expect_success 'post 1st pull setup' ' while [ $cur -le 65 ]; do add B$cur $(eval echo \$B$prev) && prev=$cur && - cur=$(($cur+1)) + cur=$(($cur+1)) || return 1 done ' @@ -464,11 +464,11 @@ test_expect_success 'fetch creating new shallow root' ' test_expect_success 'setup tests for the --stdin parameter' ' for head in C D E F do - add $head + add $head || return 1 done && for head in A B C D E F do - git tag $head $head + git tag $head $head || return 1 done && cat >input <<-\EOF && refs/heads/C diff --git a/t/t5502-quickfetch.sh b/t/t5502-quickfetch.sh index 8c05c7715b..b160f8b7fb 100755 --- a/t/t5502-quickfetch.sh +++ b/t/t5502-quickfetch.sh @@ -130,7 +130,7 @@ test_expect_success 'quickfetch should handle ~1000 refs (on Windows)' ' for i in 0 1 2 3 4 5 6 7 8 9; do for j in 0 1 2 3 4 5 6 7 8 9; do for k in 0 1 2 3 4 5 6 7 8 9; do - echo "$branchprefix$i$j$k" >> .git/packed-refs + echo "$branchprefix$i$j$k" >> .git/packed-refs || return 1 done done done && diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index 7ce1a28ef6..9ab315424c 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -1329,7 +1329,6 @@ test_expect_success 'unqualified <dst> refspec DWIM and advice' ' ( cd test && git tag -a -m "Some tag" some-tag main && - exit_with=true && for type in commit tag tree blob do if test "$type" = "blob" @@ -1345,9 +1344,8 @@ test_expect_success 'unqualified <dst> refspec DWIM and advice' ' push origin $oid:dst 2>err && test_i18ngrep "error: The destination you" err && test_i18ngrep ! "hint: Did you mean" err || - exit_with=false - done && - $exit_with + exit 1 + done ) ' diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh index 8c33755c26..20f7110ec1 100755 --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@ -37,11 +37,11 @@ test_expect_success "clone and setup child repos" ' git config branch.main.remote two && git config branch.main.merge refs/heads/one && mkdir -p .git/remotes && - { - echo "URL: ../two/.git/" - echo "Pull: refs/heads/main:refs/heads/two" - echo "Pull: refs/heads/one:refs/heads/one" - } >.git/remotes/two + cat >.git/remotes/two <<-\EOF + URL: ../two/.git/ + Pull: refs/heads/main:refs/heads/two + Pull: refs/heads/one:refs/heads/one + EOF ) && git clone . bundle && git clone . seven @@ -68,7 +68,7 @@ test_expect_success "fetch test for-merge" ' main_in_two=$(cd ../two && git rev-parse main) && one_in_two=$(cd ../two && git rev-parse one) && { - echo "$one_in_two " + echo "$one_in_two " && echo "$main_in_two not-for-merge" } >expected && cut -f -2 .git/FETCH_HEAD >actual && @@ -547,7 +547,7 @@ test_expect_success 'bundle should record HEAD correctly' ' git bundle list-heads bundle5 >actual && for h in HEAD refs/heads/main do - echo "$(git rev-parse --verify $h) $h" + echo "$(git rev-parse --verify $h) $h" || return 1 done >expect && test_cmp expect actual diff --git a/t/t5515-fetch-merge-logic.sh b/t/t5515-fetch-merge-logic.sh index 50f14101c5..320d26796d 100755 --- a/t/t5515-fetch-merge-logic.sh +++ b/t/t5515-fetch-merge-logic.sh @@ -105,19 +105,19 @@ test_expect_success setup ' remotes="$remotes config-glob" && mkdir -p .git/remotes && - { - echo "URL: ../.git/" - echo "Pull: refs/heads/main:remotes/rem/main" - echo "Pull: refs/heads/one:remotes/rem/one" - echo "Pull: two:remotes/rem/two" - echo "Pull: refs/heads/three:remotes/rem/three" - } >.git/remotes/remote-explicit && + cat >.git/remotes/remote-explicit <<-\EOF && + URL: ../.git/ + Pull: refs/heads/main:remotes/rem/main + Pull: refs/heads/one:remotes/rem/one + Pull: two:remotes/rem/two + Pull: refs/heads/three:remotes/rem/three + EOF remotes="$remotes remote-explicit" && - { - echo "URL: ../.git/" - echo "Pull: refs/heads/*:refs/remotes/rem/*" - } >.git/remotes/remote-glob && + cat >.git/remotes/remote-glob <<-\EOF && + URL: ../.git/ + Pull: refs/heads/*:refs/remotes/rem/* + EOF remotes="$remotes remote-glob" && mkdir -p .git/branches && @@ -133,7 +133,7 @@ test_expect_success setup ' git config branch.br-$remote-merge.merge refs/heads/three && git config branch.br-$remote-octopus.remote $remote && git config branch.br-$remote-octopus.merge refs/heads/one && - git config --add branch.br-$remote-octopus.merge two + git config --add branch.br-$remote-octopus.merge two || return 1 done && build_script sed_script ' @@ -191,17 +191,17 @@ do cp "$expect_r" expect_r && convert_expected expect_r sed_script && { - echo "# $cmd" - set x $cmd; shift - git symbolic-ref HEAD refs/heads/$1 ; shift - rm -f .git/FETCH_HEAD + echo "# $cmd" && + set x $cmd && shift && + git symbolic-ref HEAD refs/heads/$1 && shift && + rm -f .git/FETCH_HEAD && git for-each-ref \ refs/heads refs/remotes/rem refs/tags | while read val type refname do - git update-ref -d "$refname" "$val" - done - git fetch "$@" >/dev/null + git update-ref -d "$refname" "$val" || return 1 + done && + git fetch "$@" >/dev/null && cat .git/FETCH_HEAD } >"$actual_f" && git show-ref >"$actual_r" && diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index 837a49642a..2f04cf9a1c 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -1325,10 +1325,7 @@ test_expect_success 'fetch follows tags by default' ' git pull ../testrepo main && git tag -m "annotated" tag && git for-each-ref >tmp1 && - ( - cat tmp1 - sed -n "s|refs/heads/main$|refs/remotes/origin/main|p" tmp1 - ) | + sed -n "p; s|refs/heads/main$|refs/remotes/origin/main|p" tmp1 | sort -k 3 >../expect ) && git init dst && diff --git a/t/t5552-skipping-fetch-negotiator.sh b/t/t5552-skipping-fetch-negotiator.sh index 7b9fb4ff02..165427d57e 100755 --- a/t/t5552-skipping-fetch-negotiator.sh +++ b/t/t5552-skipping-fetch-negotiator.sh @@ -48,7 +48,7 @@ test_expect_success 'commits with no parents are sent regardless of skip distanc git init client && for i in $(test_seq 7) do - test_commit -C client c$i + test_commit -C client c$i || return 1 done && # We send: "c7" (skip 1) "c5" (skip 2) "c2" (skip 4). After that, since @@ -68,7 +68,7 @@ test_expect_success 'when two skips collide, favor the larger one' ' git init client && for i in $(test_seq 11) do - test_commit -C client c$i + test_commit -C client c$i || return 1 done && git -C client checkout c5 && test_commit -C client c5side && @@ -155,14 +155,14 @@ test_expect_success 'do not send "have" with ancestors of commits that server AC for i in $(test_seq 8) do git -C client checkout --orphan b$i && - test_commit -C client b$i.c0 + test_commit -C client b$i.c0 || return 1 done && for j in $(test_seq 19) do for i in $(test_seq 8) do git -C client checkout b$i && - test_commit -C client b$i.c$j + test_commit -C client b$i.c$j || return 1 done done && @@ -201,7 +201,7 @@ test_expect_success 'do not send "have" with ancestors of commits that server AC # should still send the others (in this test, just check b2). for i in $(test_seq 0 8) do - have_not_sent b1.c$i + have_not_sent b1.c$i || return 1 done && have_sent b2.c1 b2.c0 ' diff --git a/t/t5553-set-upstream.sh b/t/t5553-set-upstream.sh index 9c12c0f8c3..48050162c2 100755 --- a/t/t5553-set-upstream.sh +++ b/t/t5553-set-upstream.sh @@ -91,6 +91,17 @@ test_expect_success 'fetch --set-upstream with valid URL sets upstream to URL' ' check_config_missing other2 ' +test_expect_success 'fetch --set-upstream with a detached HEAD' ' + git checkout HEAD^0 && + test_when_finished "git checkout -" && + cat >expect <<-\EOF && + warning: could not set upstream of HEAD to '"'"'main'"'"' from '"'"'upstream'"'"' when it does not point to any branch. + EOF + git fetch --set-upstream upstream main 2>actual.raw && + grep ^warning: actual.raw >actual && + test_cmp expect actual +' + # tests for pull --set-upstream test_expect_success 'setup bare parent pull' ' @@ -178,4 +189,15 @@ test_expect_success 'pull --set-upstream with valid URL and branch sets branch' check_config_missing other2 ' +test_expect_success 'pull --set-upstream with a detached HEAD' ' + git checkout HEAD^0 && + test_when_finished "git checkout -" && + cat >expect <<-\EOF && + warning: could not set upstream of HEAD to '"'"'main'"'"' from '"'"'upstream'"'"' when it does not point to any branch. + EOF + git pull --no-rebase --set-upstream upstream main 2>actual.raw && + grep ^warning: actual.raw >actual && + test_cmp expect actual +' + test_done diff --git a/t/t5562-http-backend-content-length.sh b/t/t5562-http-backend-content-length.sh index 05a58069b0..b68ec22d3f 100755 --- a/t/t5562-http-backend-content-length.sh +++ b/t/t5562-http-backend-content-length.sh @@ -63,7 +63,7 @@ test_expect_success 'setup' ' hash_next=$(git commit-tree -p HEAD -m next HEAD^{tree}) && { printf "%s %s refs/heads/newbranch\\0report-status object-format=%s\\n" \ - "$ZERO_OID" "$hash_next" "$(test_oid algo)" | packetize_raw + "$ZERO_OID" "$hash_next" "$(test_oid algo)" | packetize_raw && printf 0000 && echo "$hash_next" | git pack-objects --stdout } >push_body && diff --git a/t/t5570-git-daemon.sh b/t/t5570-git-daemon.sh index b87ca06a58..1131503b76 100755 --- a/t/t5570-git-daemon.sh +++ b/t/t5570-git-daemon.sh @@ -194,7 +194,7 @@ test_expect_success 'hostname cannot break out of directory' ' test_expect_success FAKENC 'hostname interpolation works after LF-stripping' ' { - printf "git-upload-pack /interp.git\n\0host=localhost" | packetize_raw + printf "git-upload-pack /interp.git\n\0host=localhost" | packetize_raw && printf "0000" } >input && fake_nc "$GIT_DAEMON_HOST_PORT" <input >output && diff --git a/t/t5571-pre-push-hook.sh b/t/t5571-pre-push-hook.sh index ad8d5804f7..660f876eec 100755 --- a/t/t5571-pre-push-hook.sh +++ b/t/t5571-pre-push-hook.sh @@ -114,11 +114,11 @@ test_expect_success 'push to URL' ' test_expect_success 'set up many-ref tests' ' { - nr=1000 + nr=1000 && while test $nr -lt 2000 do - nr=$(( $nr + 1 )) - echo "create refs/heads/b/$nr $COMMIT3" + nr=$(( $nr + 1 )) && + echo "create refs/heads/b/$nr $COMMIT3" || return 1 done } | git update-ref --stdin ' diff --git a/t/t5611-clone-config.sh b/t/t5611-clone-config.sh index f8625f9158..4b3877216e 100755 --- a/t/t5611-clone-config.sh +++ b/t/t5611-clone-config.sh @@ -17,7 +17,7 @@ test_expect_success 'clone -c sets config in cloned repo' ' test_expect_success 'clone -c can set multi-keys' ' rm -rf child && git clone -c core.foo=bar -c core.foo=baz . child && - { echo bar; echo baz; } >expect && + test_write_lines bar baz >expect && git --git-dir=child/.git config --get-all core.foo >actual && test_cmp expect actual ' diff --git a/t/t5616-partial-clone.sh b/t/t5616-partial-clone.sh index cf3e82bdf5..34469b6ac1 100755 --- a/t/t5616-partial-clone.sh +++ b/t/t5616-partial-clone.sh @@ -16,10 +16,10 @@ test_expect_success 'setup normal src repo' ' git init src && for n in 1 2 3 4 do - echo "This is file: $n" > src/file.$n.txt - git -C src add file.$n.txt - git -C src commit -m "file $n" - git -C src ls-files -s file.$n.txt >>temp + echo "This is file: $n" > src/file.$n.txt && + git -C src add file.$n.txt && + git -C src commit -m "file $n" && + git -C src ls-files -s file.$n.txt >>temp || return 1 done && awk -f print_2.awk <temp | sort >expect_1.oids && test_line_count = 4 expect_1.oids @@ -72,9 +72,9 @@ test_expect_success 'push new commits to server' ' git -C src remote add srv "file://$(pwd)/srv.bare" && for x in a b c d e do - echo "Mod file.1.txt $x" >>src/file.1.txt - git -C src add file.1.txt - git -C src commit -m "mod $x" + echo "Mod file.1.txt $x" >>src/file.1.txt && + git -C src add file.1.txt && + git -C src commit -m "mod $x" || return 1 done && git -C src blame main -- file.1.txt >expect.blame && git -C src push -u srv main @@ -114,9 +114,9 @@ test_expect_success 'verify blame causes dynamic object fetch' ' test_expect_success 'push new commits to server for file.2.txt' ' for x in a b c d e f do - echo "Mod file.2.txt $x" >>src/file.2.txt - git -C src add file.2.txt - git -C src commit -m "mod $x" + echo "Mod file.2.txt $x" >>src/file.2.txt && + git -C src add file.2.txt && + git -C src commit -m "mod $x" || return 1 done && git -C src push -u srv main ' @@ -135,9 +135,9 @@ test_expect_success 'override inherited filter-spec using --no-filter' ' test_expect_success 'push new commits to server for file.3.txt' ' for x in a b c d e f do - echo "Mod file.3.txt $x" >>src/file.3.txt - git -C src add file.3.txt - git -C src commit -m "mod $x" + echo "Mod file.3.txt $x" >>src/file.3.txt && + git -C src add file.3.txt && + git -C src commit -m "mod $x" || return 1 done && git -C src push -u srv main ' @@ -385,7 +385,7 @@ setup_triangle () { for i in $(test_seq 1 100) do echo "make the tree big" >server/file$i && - git -C server add file$i + git -C server add file$i || return 1 done && git -C server commit -m "initial" && git clone --bare --filter=tree:0 "file://$(pwd)/server" client && @@ -669,7 +669,7 @@ test_expect_success 'tolerate server sending REF_DELTA against missing promisor for i in $(test_seq 10) do echo "this is a line" >>"$SERVER/foo.txt" && - echo "this is another line" >>"$SERVER/have.txt" + echo "this is another line" >>"$SERVER/have.txt" || return 1 done && git -C "$SERVER" add foo.txt have.txt && git -C "$SERVER" commit -m bar && diff --git a/t/t5702-protocol-v2.sh b/t/t5702-protocol-v2.sh index 78f85b0714..710f33e2aa 100755 --- a/t/t5702-protocol-v2.sh +++ b/t/t5702-protocol-v2.sh @@ -747,7 +747,7 @@ test_expect_success 'clone big repository with http:// using protocol v2' ' echo "data 0" && echo "M 644 inline bla.txt" && echo "data 4" && - echo "bla" + echo "bla" || return 1 done | git -C "$HTTPD_DOCUMENT_ROOT_PATH/big" fast-import && GIT_TRACE_PACKET="$(pwd)/log" GIT_TRACE_CURL="$(pwd)/log" git \ @@ -942,7 +942,7 @@ test_expect_success 'part of packfile response provided as URI' ' then >h2found fi - fi + fi || return 1 done && test -f hfound && test -f h2found && diff --git a/t/t6005-rev-list-count.sh b/t/t6005-rev-list-count.sh index d763de0041..86542c650e 100755 --- a/t/t6005-rev-list-count.sh +++ b/t/t6005-rev-list-count.sh @@ -6,10 +6,10 @@ TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh test_expect_success 'setup' ' - for n in 1 2 3 4 5 ; do \ - echo $n > a ; \ - git add a ; \ - git commit -m "$n" ; \ + for n in 1 2 3 4 5 ; do + echo $n > a && + git add a && + git commit -m "$n" || return 1 done ' diff --git a/t/t6009-rev-list-parent.sh b/t/t6009-rev-list-parent.sh index 63fa7c8313..5a67bbc760 100755 --- a/t/t6009-rev-list-parent.sh +++ b/t/t6009-rev-list-parent.sh @@ -124,7 +124,7 @@ test_expect_success 'dodecapus' ' git checkout -b root$i five && test_commit $i && roots="$roots root$i" || - return + return 1 done && git checkout main && test_tick && @@ -142,8 +142,8 @@ test_expect_success 'ancestors with the same commit time' ' test_tick_keep=$test_tick && for i in 1 2 3 4 5 6 7 8; do - test_tick=$test_tick_keep - test_commit t$i + test_tick=$test_tick_keep && + test_commit t$i || return 1 done && git rev-list t1^! --not t$i >result && test_must_be_empty result diff --git a/t/t6019-rev-list-ancestry-path.sh b/t/t6019-rev-list-ancestry-path.sh index 20adbece65..af57a04b7f 100755 --- a/t/t6019-rev-list-ancestry-path.sh +++ b/t/t6019-rev-list-ancestry-path.sh @@ -51,7 +51,7 @@ test_expect_success setup ' ' test_expect_success 'rev-list D..M' ' - for c in E F G H I J K L M; do echo $c; done >expect && + test_write_lines E F G H I J K L M >expect && git rev-list --format=%s D..M | sed -e "/^commit /d" | sort >actual && @@ -59,7 +59,7 @@ test_expect_success 'rev-list D..M' ' ' test_expect_success 'rev-list --ancestry-path D..M' ' - for c in E F H I J L M; do echo $c; done >expect && + test_write_lines E F H I J L M >expect && git rev-list --ancestry-path --format=%s D..M | sed -e "/^commit /d" | sort >actual && @@ -81,7 +81,7 @@ test_expect_success 'rev-list --ancestry-path D..M -- M.t' ' ' test_expect_success 'rev-list F...I' ' - for c in F G H I; do echo $c; done >expect && + test_write_lines F G H I >expect && git rev-list --format=%s F...I | sed -e "/^commit /d" | sort >actual && @@ -89,7 +89,7 @@ test_expect_success 'rev-list F...I' ' ' test_expect_success 'rev-list --ancestry-path F...I' ' - for c in F H I; do echo $c; done >expect && + test_write_lines F H I >expect && git rev-list --ancestry-path --format=%s F...I | sed -e "/^commit /d" | sort >actual && @@ -111,7 +111,7 @@ test_expect_success 'rev-list --ancestry-path G..M -- G.t' ' ' test_expect_success 'rev-list --ancestry-path --simplify-merges G^..M -- G.t' ' - for c in G L; do echo $c; done >expect && + test_write_lines G L >expect && git rev-list --ancestry-path --simplify-merges --format=%s G^..M -- G.t | sed -e "/^commit /d" | sort >actual && diff --git a/t/t6060-merge-index.sh b/t/t6060-merge-index.sh index ddf34f0115..ed449abe55 100755 --- a/t/t6060-merge-index.sh +++ b/t/t6060-merge-index.sh @@ -4,9 +4,7 @@ test_description='basic git merge-index / git-merge-one-file tests' . ./test-lib.sh test_expect_success 'setup diverging branches' ' - for i in 1 2 3 4 5 6 7 8 9 10; do - echo $i - done >file && + test_write_lines 1 2 3 4 5 6 7 8 9 10 >file && git add file && git commit -m base && git tag base && diff --git a/t/t6101-rev-parse-parents.sh b/t/t6101-rev-parse-parents.sh index 78b5851780..c571fa5179 100755 --- a/t/t6101-rev-parse-parents.sh +++ b/t/t6101-rev-parse-parents.sh @@ -32,7 +32,7 @@ test_expect_success 'setup' ' test_tick && git commit --allow-empty -m "$i" && commit=$(git rev-parse --verify HEAD) && - printf "$commit " >>.git/info/grafts + printf "$commit " >>.git/info/grafts || return 1 done ' diff --git a/t/t6112-rev-list-filters-objects.sh b/t/t6112-rev-list-filters-objects.sh index 4ade105db3..8d9d6604f0 100755 --- a/t/t6112-rev-list-filters-objects.sh +++ b/t/t6112-rev-list-filters-objects.sh @@ -16,9 +16,9 @@ test_expect_success 'setup r1' ' git init r1 && for n in 1 2 3 4 5 do - echo "This is file: $n" > r1/file.$n - git -C r1 add file.$n - git -C r1 commit -m "$n" + echo "This is file: $n" > r1/file.$n && + git -C r1 add file.$n && + git -C r1 commit -m "$n" || return 1 done ' @@ -73,9 +73,9 @@ test_expect_success 'setup r2' ' git init r2 && for n in 1000 10000 do - printf "%"$n"s" X > r2/large.$n - git -C r2 add large.$n - git -C r2 commit -m "$n" + printf "%"$n"s" X > r2/large.$n && + git -C r2 add large.$n && + git -C r2 commit -m "$n" || return 1 done ' @@ -245,10 +245,10 @@ test_expect_success 'setup r3' ' mkdir r3/dir1 && for n in sparse1 sparse2 do - echo "This is file: $n" > r3/$n - git -C r3 add $n - echo "This is file: dir1/$n" > r3/dir1/$n - git -C r3 add dir1/$n + echo "This is file: $n" > r3/$n && + git -C r3 add $n && + echo "This is file: dir1/$n" > r3/dir1/$n && + git -C r3 add dir1/$n || return 1 done && git -C r3 commit -m "sparse" && echo dir1/ >pattern1 && @@ -672,7 +672,7 @@ test_expect_success 'rev-list W/ --missing=print' ' for id in `cat expected | sed "s|..|&/|"` do - rm r1/.git/objects/$id + rm r1/.git/objects/$id || return 1 done && git -C r1 rev-list --quiet --missing=print --objects HEAD >revs && diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh index bae2419150..d8af2bb9d2 100755 --- a/t/t6120-describe.sh +++ b/t/t6120-describe.sh @@ -262,7 +262,7 @@ test_expect_success 'name-rev --all' ' >expect.unsorted && for rev in $(git rev-list --all) do - git name-rev $rev >>expect.unsorted + git name-rev $rev >>expect.unsorted || return 1 done && sort <expect.unsorted >expect && git name-rev --all >actual.unsorted && @@ -275,7 +275,7 @@ test_expect_success 'name-rev --stdin' ' for rev in $(git rev-list --all) do name=$(git name-rev --name-only $rev) && - echo "$rev ($name)" >>expect.unsorted + echo "$rev ($name)" >>expect.unsorted || return 1 done && sort <expect.unsorted >expect && git rev-list --all | git name-rev --stdin >actual.unsorted && @@ -390,9 +390,12 @@ test_expect_success ULIMIT_STACK_SIZE 'name-rev works in a deep repo' ' committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200 data <<EOF commit #$i -EOF" - test $i = 1 && echo "from refs/heads/main^0" - i=$(($i + 1)) +EOF" && + if test $i = 1 + then + echo "from refs/heads/main^0" + fi && + i=$(($i + 1)) || return 1 done | git fast-import && git checkout main && git tag far-far-away HEAD^ && diff --git a/t/t6132-pathspec-exclude.sh b/t/t6132-pathspec-exclude.sh index 30328b87f0..8ff1d76f79 100755 --- a/t/t6132-pathspec-exclude.sh +++ b/t/t6132-pathspec-exclude.sh @@ -11,7 +11,7 @@ test_expect_success 'setup' ' fi && : >$p && git add $p && - git commit -m $p + git commit -m $p || return 1 done && git log --oneline --format=%s >actual && cat <<EOF >expect && diff --git a/t/t6200-fmt-merge-msg.sh b/t/t6200-fmt-merge-msg.sh index 6e10a539ce..7544245f90 100755 --- a/t/t6200-fmt-merge-msg.sh +++ b/t/t6200-fmt-merge-msg.sh @@ -579,7 +579,7 @@ test_expect_success 'merge-msg lots of commits' ' while test $i -gt 9 do echo " $i" && - i=$(($i-1)) + i=$(($i-1)) || return 1 done && echo " ..." } >expected && @@ -633,7 +633,35 @@ test_expect_success 'merge-msg with "merging" an annotated tag' ' test_cmp expected .git/MERGE_MSG ' +test_expect_success 'merge --into-name=<name>' ' + test_when_finished "git checkout main" && + git checkout -B side main && + git commit --allow-empty -m "One step ahead" && + + git checkout --detach main && + git merge --no-ff side && + git show -s --format="%s" >full.0 && + head -n1 full.0 >actual && + # expect that HEAD is shown as-is + grep -e "Merge branch .side. into HEAD$" actual && + + git reset --hard main && + git merge --no-ff --into-name=main side && + git show -s --format="%s" >full.1 && + head -n1 full.1 >actual && + # expect that we pretend to be merging to main, that is suppressed + grep -e "Merge branch .side.$" actual && + + git checkout -b throwaway main && + git merge --no-ff --into-name=main side && + git show -s --format="%s" >full.2 && + head -n1 full.2 >actual && + # expect that we pretend to be merging to main, that is suppressed + grep -e "Merge branch .side.$" actual +' + test_expect_success 'merge.suppressDest configuration' ' + test_when_finished "git checkout main" && git checkout -B side main && git commit --allow-empty -m "One step ahead" && git checkout main && @@ -650,7 +678,19 @@ test_expect_success 'merge.suppressDest configuration' ' git -c merge.suppressDest="ma?*[rn]" fmt-merge-msg <.git/FETCH_HEAD >full.3 && head -n1 full.3 >actual && grep -e "Merge branch .side." actual && - ! grep -e " into main$" actual + ! grep -e " into main$" actual && + + git checkout --detach HEAD && + git -c merge.suppressDest="main" fmt-merge-msg <.git/FETCH_HEAD >full.4 && + head -n1 full.4 >actual && + grep -e "Merge branch .side. into HEAD$" actual && + + git -c merge.suppressDest="main" fmt-merge-msg \ + --into-name=main <.git/FETCH_HEAD >full.5 && + head -n1 full.5 >actual && + grep -e "Merge branch .side." actual && + ! grep -e " into main$" actual && + ! grep -e " into HEAD$" actual ' test_done diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh index 6aa9fb17ea..dcaab7265f 100755 --- a/t/t6300-for-each-ref.sh +++ b/t/t6300-for-each-ref.sh @@ -952,10 +952,7 @@ test_expect_success '%(raw) with --shell and --sort=raw must fail' ' ' test_expect_success '%(raw:size) with --shell' ' - git for-each-ref --format="%(raw:size)" | while read line - do - echo "'\''$line'\''" >>expect - done && + git for-each-ref --format="%(raw:size)" | sed "s/^/$SQ/;s/$/$SQ/" >expect && git for-each-ref --format="%(raw:size)" --shell >actual && test_cmp expect actual ' @@ -1338,7 +1335,7 @@ test_expect_success ':remotename and :remoteref' ' echo "${pair#*=}" >expect && git for-each-ref --format="${pair%=*}" \ refs/heads/main >actual && - test_cmp expect actual + test_cmp expect actual || exit 1 done && git branch push-simple && git config branch.push-simple.pushRemote from && diff --git a/t/t6406-merge-attr.sh b/t/t6406-merge-attr.sh index 8494645837..57e6af5eaa 100755 --- a/t/t6406-merge-attr.sh +++ b/t/t6406-merge-attr.sh @@ -62,10 +62,10 @@ test_expect_success setup ' test_expect_success merge ' - { - echo "binary -merge" - echo "union merge=union" - } >.gitattributes && + cat >.gitattributes <<-\EOF && + binary -merge + union merge=union + EOF if git merge main then diff --git a/t/t6407-merge-binary.sh b/t/t6407-merge-binary.sh index e34676c204..8e6241f92e 100755 --- a/t/t6407-merge-binary.sh +++ b/t/t6407-merge-binary.sh @@ -48,7 +48,7 @@ test_expect_success resolve ' echo Oops, should not have succeeded false else - git ls-files -s >current + git ls-files -s >current && test_cmp expect current fi ' @@ -63,7 +63,7 @@ test_expect_success recursive ' echo Oops, should not have succeeded false else - git ls-files -s >current + git ls-files -s >current && test_cmp expect current fi ' diff --git a/t/t6409-merge-subtree.sh b/t/t6409-merge-subtree.sh index ba7890ec52..e9ba6f1690 100755 --- a/t/t6409-merge-subtree.sh +++ b/t/t6409-merge-subtree.sh @@ -10,7 +10,7 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME test_expect_success setup ' s="1 2 3 4 5 6 7 8" && - for i in $s; do echo $i; done >hello && + test_write_lines $s >hello && git add hello && git commit -m initial && git checkout -b side && @@ -18,7 +18,7 @@ test_expect_success setup ' git add hello && git commit -m second && git checkout main && - for i in mundo $s; do echo $i; done >hello && + test_write_lines mundo $s >hello && git add hello && git commit -m main @@ -27,7 +27,7 @@ test_expect_success setup ' test_expect_success 'subtree available and works like recursive' ' git merge -s subtree side && - for i in mundo $s world; do echo $i; done >expect && + test_write_lines mundo $s world >expect && test_cmp expect hello ' diff --git a/t/t6411-merge-filemode.sh b/t/t6411-merge-filemode.sh index f54c915d6a..6ae2489286 100755 --- a/t/t6411-merge-filemode.sh +++ b/t/t6411-merge-filemode.sh @@ -51,10 +51,10 @@ test_expect_success 'set up mode change in both branches' ' : >file2 && git add file2 && git commit -m b2 && - { - echo "100755 $H 2 file2" - echo "100644 $H 3 file2" - } >expect + cat >expect <<-EOF + 100755 $H 2 file2 + 100644 $H 3 file2 + EOF ' do_both_modes () { diff --git a/t/t6412-merge-large-rename.sh b/t/t6412-merge-large-rename.sh index c50d315722..ca018d11f5 100755 --- a/t/t6412-merge-large-rename.sh +++ b/t/t6412-merge-large-rename.sh @@ -37,18 +37,18 @@ test_rename() { test_might_fail git branch -D test$n && git reset --hard initial && for i in $(count $n); do - make_text $i initial initial >$i + make_text $i initial initial >$i || return 1 done && git add . && git commit -m add=$n && for i in $(count $n); do - make_text $i changed initial >$i + make_text $i changed initial >$i || return 1 done && git commit -a -m change=$n && git checkout -b test$n HEAD^ && for i in $(count $n); do - git rm $i - make_text $i initial changed >$i.moved + git rm $i && + make_text $i initial changed >$i.moved || return 1 done && git add . && git commit -m change+rename=$n && @@ -79,7 +79,7 @@ test_expect_success 'setup large simple rename' ' git reset --hard initial && for i in $(count 200); do - make_text foo bar baz >$i + make_text foo bar baz >$i || return 1 done && git add . && git commit -m create-files && diff --git a/t/t6416-recursive-corner-cases.sh b/t/t6416-recursive-corner-cases.sh index 84f5082366..690c8482b1 100755 --- a/t/t6416-recursive-corner-cases.sh +++ b/t/t6416-recursive-corner-cases.sh @@ -24,14 +24,8 @@ test_expect_success 'setup basic criss-cross + rename with no modifications' ' cd basic-rename && ten="0 1 2 3 4 5 6 7 8 9" && - for i in $ten - do - echo line $i in a sample file - done >one && - for i in $ten - do - echo line $i in another sample file - done >two && + printf "line %d in a sample file\n" $ten >one && + printf "line %d in another sample file\n" $ten >two && git add one two && test_tick && git commit -m initial && @@ -96,14 +90,8 @@ test_expect_success 'setup criss-cross + rename merges with basic modification' cd rename-modify && ten="0 1 2 3 4 5 6 7 8 9" && - for i in $ten - do - echo line $i in a sample file - done >one && - for i in $ten - do - echo line $i in another sample file - done >two && + printf "line %d in a sample file\n" $ten >one && + printf "line %d in another sample file\n" $ten >two && git add one two && test_tick && git commit -m initial && @@ -1588,10 +1576,7 @@ test_expect_success 'setup nested conflicts' ' cd nested_conflicts && # Create some related files now - for i in $(test_seq 1 10) - do - echo Random base content line $i - done >initial && + printf "Random base content line %d\n" $(test_seq 1 10) >initial && cp initial b_L1 && cp initial b_R1 && @@ -1777,10 +1762,7 @@ test_expect_success 'setup virtual merge base with nested conflicts' ' cd virtual_merge_base_has_nested_conflicts && # Create some related files now - for i in $(test_seq 1 10) - do - echo Random base content line $i - done >content && + printf "Random base content line %d\n" $(test_seq 1 10) >content && # Setup original commit git add content && diff --git a/t/t6417-merge-ours-theirs.sh b/t/t6417-merge-ours-theirs.sh index ec065d6a65..62d1406119 100755 --- a/t/t6417-merge-ours-theirs.sh +++ b/t/t6417-merge-ours-theirs.sh @@ -7,10 +7,7 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh test_expect_success setup ' - for i in 1 2 3 4 5 6 7 8 9 - do - echo "$i" - done >file && + test_write_lines 1 2 3 4 5 6 7 8 9 >file && git add file && cp file elif && git commit -m initial && diff --git a/t/t6430-merge-recursive.sh b/t/t6430-merge-recursive.sh index a0efe7cb6d..07067bb347 100755 --- a/t/t6430-merge-recursive.sh +++ b/t/t6430-merge-recursive.sh @@ -706,7 +706,7 @@ test_expect_success 'merge-recursive remembers the names of all base trees' ' # more trees than static slots used by oid_to_hex() for commit in $c0 $c2 $c4 $c5 $c6 $c7 do - git rev-parse "$commit^{tree}" + git rev-parse "$commit^{tree}" || return 1 done >trees && # ignore the return code; it only fails because the input is weird... diff --git a/t/t6600-test-reach.sh b/t/t6600-test-reach.sh index 3d7a62ddab..338a9c46a2 100755 --- a/t/t6600-test-reach.sh +++ b/t/t6600-test-reach.sh @@ -32,7 +32,7 @@ test_expect_success 'setup' ' do test_commit "1-$i" && git branch -f commit-1-$i && - git tag -a -m "1-$i" tag-1-$i commit-1-$i + git tag -a -m "1-$i" tag-1-$i commit-1-$i || return 1 done && for j in $(test_seq 1 9) do @@ -46,7 +46,7 @@ test_expect_success 'setup' ' do git merge commit-$j-$i -m "$x-$i" && git branch -f commit-$x-$i && - git tag -a -m "$x-$i" tag-$x-$i commit-$x-$i + git tag -a -m "$x-$i" tag-$x-$i commit-$x-$i || return 1 done done && git commit-graph write --reachable && diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh index bc8a221b2c..9aa1660651 100755 --- a/t/t7004-tag.sh +++ b/t/t7004-tag.sh @@ -1976,9 +1976,12 @@ test_expect_success ULIMIT_STACK_SIZE '--contains and --no-contains work in a de committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200 data <<EOF commit #$i -EOF" - test $i = 1 && echo "from refs/heads/main^0" - i=$(($i + 1)) +EOF" && + if test $i = 1 + then + echo "from refs/heads/main^0" + fi && + i=$(($i + 1)) || return 1 done | git fast-import && git checkout main && git tag far-far-away HEAD^ && diff --git a/t/t7010-setup.sh b/t/t7010-setup.sh index 0335a9a158..520f96d09f 100755 --- a/t/t7010-setup.sh +++ b/t/t7010-setup.sh @@ -137,7 +137,7 @@ test_expect_success 'setup deeper work tree' ' test_expect_success 'add a directory outside the work tree' '( cd tester && - d1="$(cd .. ; pwd)" && + d1="$(cd .. && pwd)" && test_must_fail git add "$d1" )' diff --git a/t/t7110-reset-merge.sh b/t/t7110-reset-merge.sh index a82a07a04a..3d62e10b53 100755 --- a/t/t7110-reset-merge.sh +++ b/t/t7110-reset-merge.sh @@ -8,7 +8,7 @@ test_description='Tests for "git reset" with "--merge" and "--keep" options' . ./test-lib.sh test_expect_success setup ' - for i in 1 2 3; do echo line $i; done >file1 && + printf "line %d\n" 1 2 3 >file1 && cat file1 >file2 && git add file1 file2 && test_tick && diff --git a/t/t7501-commit-basic-functionality.sh b/t/t7501-commit-basic-functionality.sh index 512ae2781f..fb5417d5e7 100755 --- a/t/t7501-commit-basic-functionality.sh +++ b/t/t7501-commit-basic-functionality.sh @@ -667,10 +667,7 @@ test_expect_success 'amend can copy notes' ' test_expect_success 'commit a file whose name is a dash' ' git reset --hard && - for i in 1 2 3 4 5 - do - echo $i - done >./- && + test_write_lines 1 2 3 4 5 >./- && git add ./- && test_tick && git commit -m "add dash" >output </dev/null && diff --git a/t/t7505-prepare-commit-msg-hook.sh b/t/t7505-prepare-commit-msg-hook.sh index 2a07c70867..e39c809ca4 100755 --- a/t/t7505-prepare-commit-msg-hook.sh +++ b/t/t7505-prepare-commit-msg-hook.sh @@ -16,7 +16,7 @@ test_expect_success 'set up commits for rebasing' ' test_commit rebase-b b bb && for i in $(test_seq 1 13) do - test_commit rebase-$i c $i + test_commit rebase-$i c $i || return 1 done && git checkout main && diff --git a/t/t7512-status-help.sh b/t/t7512-status-help.sh index 7f2956d77a..2f16d5787e 100755 --- a/t/t7512-status-help.sh +++ b/t/t7512-status-help.sh @@ -659,6 +659,7 @@ On branch am_empty You are in the middle of an am session. The current patch is empty. (use "git am --skip" to skip this patch) + (use "git am --allow-empty" to record this patch as an empty commit) (use "git am --abort" to restore the original branch) nothing to commit (use -u to show untracked files) diff --git a/t/t7513-interpret-trailers.sh b/t/t7513-interpret-trailers.sh index 04885d0a5e..97f10905d2 100755 --- a/t/t7513-interpret-trailers.sh +++ b/t/t7513-interpret-trailers.sh @@ -156,7 +156,7 @@ test_expect_success 'with config option on the command line' ' Acked-by: Johan Reviewed-by: Peff EOF - { echo; echo "Acked-by: Johan"; } | + { echo && echo "Acked-by: Johan"; } | git -c "trailer.Acked-by.ifexists=addifdifferent" interpret-trailers \ --trailer "Reviewed-by: Peff" --trailer "Acked-by: Johan" >actual && test_cmp expected actual diff --git a/t/t7519-status-fsmonitor.sh b/t/t7519-status-fsmonitor.sh index a5e2233cb1..a6308acf00 100755 --- a/t/t7519-status-fsmonitor.sh +++ b/t/t7519-status-fsmonitor.sh @@ -248,7 +248,7 @@ do git config core.preloadIndex $preload_val && if test $preload_val = true then - GIT_TEST_PRELOAD_INDEX=$preload_val; export GIT_TEST_PRELOAD_INDEX + GIT_TEST_PRELOAD_INDEX=$preload_val && export GIT_TEST_PRELOAD_INDEX else sane_unset GIT_TEST_PRELOAD_INDEX fi diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh index c773e30b3f..f0f6fda150 100755 --- a/t/t7600-merge.sh +++ b/t/t7600-merge.sh @@ -967,7 +967,7 @@ test_expect_success 'set up mod-256 conflict scenario' ' # 256 near-identical stanzas... for i in $(test_seq 1 256); do for j in 1 2 3 4 5; do - echo $i-$j + echo $i-$j || return 1 done done >file && git add file && diff --git a/t/t7602-merge-octopus-many.sh b/t/t7602-merge-octopus-many.sh index a9c816b47f..ff085b086c 100755 --- a/t/t7602-merge-octopus-many.sh +++ b/t/t7602-merge-octopus-many.sh @@ -29,8 +29,8 @@ test_expect_success 'merge c1 with c2, c3, c4, ... c29' ' refs="" && while test $i -le 30 do - refs="$refs c$i" - i=$(expr $i + 1) + refs="$refs c$i" && + i=$(expr $i + 1) || return 1 done && git merge $refs && test "$(git rev-parse c1)" != "$(git rev-parse HEAD)" && diff --git a/t/t7603-merge-reduce-heads.sh b/t/t7603-merge-reduce-heads.sh index 27cd94ad6f..4887ca705b 100755 --- a/t/t7603-merge-reduce-heads.sh +++ b/t/t7603-merge-reduce-heads.sh @@ -95,7 +95,7 @@ test_expect_success 'setup' ' echo $i > $i.c && git add $i.c && git commit -m $i && - git tag $i + git tag $i || return 1 done && git reset --hard A && for i in F G H I @@ -103,7 +103,7 @@ test_expect_success 'setup' ' echo $i > $i.c && git add $i.c && git commit -m $i && - git tag $i + git tag $i || return 1 done ' diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 0260ad6f0e..e489869dd9 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -5,6 +5,7 @@ test_description='git repack works correctly' . ./test-lib.sh . "${TEST_DIRECTORY}/lib-bitmap.sh" . "${TEST_DIRECTORY}/lib-midx.sh" +. "${TEST_DIRECTORY}/lib-terminal.sh" commit_and_pack () { test_commit "$@" 1>&2 && @@ -117,7 +118,7 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' ' rm alt_objects/pack/$base_name.keep else touch alt_objects/pack/$base_name.keep - fi + fi || return 1 done && git repack -a -d && test_no_missing_in_packs @@ -372,4 +373,16 @@ test_expect_success '--write-midx with preferred bitmap tips' ' ) ' +test_expect_success '--write-midx -b packs non-kept objects' ' + GIT_TRACE2_EVENT="$(pwd)/trace.txt" \ + git repack --write-midx -a -b && + test_subcommand_inexact git pack-objects --honor-pack-keep <trace.txt +' + +test_expect_success TTY '--quiet disables progress' ' + test_terminal env GIT_PROGRESS_DELAY=0 \ + git -C midx repack -ad --quiet --write-midx 2>stderr && + test_must_be_empty stderr +' + test_done diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh index 6b6423a07c..424c31c328 100755 --- a/t/t7810-grep.sh +++ b/t/t7810-grep.sh @@ -31,28 +31,28 @@ int main(int argc, const char **argv) EOF test_expect_success setup ' - { - echo foo mmap bar - echo foo_mmap bar - echo foo_mmap bar mmap - echo foo mmap bar_mmap - echo foo_mmap bar mmap baz - } >file && - { - echo Hello world - echo HeLLo world - echo Hello_world - echo HeLLo_world - } >hello_world && - { - echo "a+b*c" - echo "a+bc" - echo "abc" - } >ab && - { - echo d && - echo 0 - } >d0 && + cat >file <<-\EOF && + foo mmap bar + foo_mmap bar + foo_mmap bar mmap + foo mmap bar_mmap + foo_mmap bar mmap baz + EOF + cat >hello_world <<-\EOF && + Hello world + HeLLo world + Hello_world + HeLLo_world + EOF + cat >ab <<-\EOF && + a+b*c + a+bc + abc + EOF + cat >d0 <<-\EOF && + d + 0 + EOF echo vvv >v && echo ww w >w && echo x x xx x >x && @@ -63,13 +63,13 @@ test_expect_success setup ' echo vvv >t/v && mkdir t/a && echo vvv >t/a/v && - { - echo "line without leading space1" - echo " line with leading space1" - echo " line with leading space2" - echo " line with leading space3" - echo "line without leading space2" - } >space && + qz_to_tab_space >space <<-\EOF && + line without leading space1 + Zline with leading space1 + Zline with leading space2 + Zline with leading space3 + line without leading space2 + EOF cat >hello.ps1 <<-\EOF && # No-op. function dummy() {} @@ -106,129 +106,129 @@ do esac test_expect_success "grep -w $L" ' - { - echo ${HC}file:1:foo mmap bar - echo ${HC}file:3:foo_mmap bar mmap - echo ${HC}file:4:foo mmap bar_mmap - echo ${HC}file:5:foo_mmap bar mmap baz - } >expected && + cat >expected <<-EOF && + ${HC}file:1:foo mmap bar + ${HC}file:3:foo_mmap bar mmap + ${HC}file:4:foo mmap bar_mmap + ${HC}file:5:foo_mmap bar mmap baz + EOF git -c grep.linenumber=false grep -n -w -e mmap $H >actual && test_cmp expected actual ' test_expect_success "grep -w $L (with --column)" ' - { - echo ${HC}file:5:foo mmap bar - echo ${HC}file:14:foo_mmap bar mmap - echo ${HC}file:5:foo mmap bar_mmap - echo ${HC}file:14:foo_mmap bar mmap baz - } >expected && + cat >expected <<-EOF && + ${HC}file:5:foo mmap bar + ${HC}file:14:foo_mmap bar mmap + ${HC}file:5:foo mmap bar_mmap + ${HC}file:14:foo_mmap bar mmap baz + EOF git grep --column -w -e mmap $H >actual && test_cmp expected actual ' test_expect_success "grep -w $L (with --column, extended OR)" ' - { - echo ${HC}file:14:foo_mmap bar mmap - echo ${HC}file:19:foo_mmap bar mmap baz - } >expected && + cat >expected <<-EOF && + ${HC}file:14:foo_mmap bar mmap + ${HC}file:19:foo_mmap bar mmap baz + EOF git grep --column -w -e mmap$ --or -e baz $H >actual && test_cmp expected actual ' test_expect_success "grep -w $L (with --column, --invert-match)" ' - { - echo ${HC}file:1:foo mmap bar - echo ${HC}file:1:foo_mmap bar - echo ${HC}file:1:foo_mmap bar mmap - echo ${HC}file:1:foo mmap bar_mmap - } >expected && + cat >expected <<-EOF && + ${HC}file:1:foo mmap bar + ${HC}file:1:foo_mmap bar + ${HC}file:1:foo_mmap bar mmap + ${HC}file:1:foo mmap bar_mmap + EOF git grep --column --invert-match -w -e baz $H -- file >actual && test_cmp expected actual ' test_expect_success "grep $L (with --column, --invert-match, extended OR)" ' - { - echo ${HC}hello_world:6:HeLLo_world - } >expected && + cat >expected <<-EOF && + ${HC}hello_world:6:HeLLo_world + EOF git grep --column --invert-match -e ll --or --not -e _ $H -- hello_world \ >actual && test_cmp expected actual ' test_expect_success "grep $L (with --column, --invert-match, extended AND)" ' - { - echo ${HC}hello_world:3:Hello world - echo ${HC}hello_world:3:Hello_world - echo ${HC}hello_world:6:HeLLo_world - } >expected && + cat >expected <<-EOF && + ${HC}hello_world:3:Hello world + ${HC}hello_world:3:Hello_world + ${HC}hello_world:6:HeLLo_world + EOF git grep --column --invert-match --not -e _ --and --not -e ll $H -- hello_world \ >actual && test_cmp expected actual ' test_expect_success "grep $L (with --column, double-negation)" ' - { - echo ${HC}file:1:foo_mmap bar mmap baz - } >expected && + cat >expected <<-EOF && + ${HC}file:1:foo_mmap bar mmap baz + EOF git grep --column --not \( --not -e foo --or --not -e baz \) $H -- file \ >actual && test_cmp expected actual ' test_expect_success "grep -w $L (with --column, -C)" ' - { - echo ${HC}file:5:foo mmap bar - echo ${HC}file-foo_mmap bar - echo ${HC}file:14:foo_mmap bar mmap - echo ${HC}file:5:foo mmap bar_mmap - echo ${HC}file:14:foo_mmap bar mmap baz - } >expected && + cat >expected <<-EOF && + ${HC}file:5:foo mmap bar + ${HC}file-foo_mmap bar + ${HC}file:14:foo_mmap bar mmap + ${HC}file:5:foo mmap bar_mmap + ${HC}file:14:foo_mmap bar mmap baz + EOF git grep --column -w -C1 -e mmap $H >actual && test_cmp expected actual ' test_expect_success "grep -w $L (with --line-number, --column)" ' - { - echo ${HC}file:1:5:foo mmap bar - echo ${HC}file:3:14:foo_mmap bar mmap - echo ${HC}file:4:5:foo mmap bar_mmap - echo ${HC}file:5:14:foo_mmap bar mmap baz - } >expected && + cat >expected <<-EOF && + ${HC}file:1:5:foo mmap bar + ${HC}file:3:14:foo_mmap bar mmap + ${HC}file:4:5:foo mmap bar_mmap + ${HC}file:5:14:foo_mmap bar mmap baz + EOF git grep -n --column -w -e mmap $H >actual && test_cmp expected actual ' test_expect_success "grep -w $L (with non-extended patterns, --column)" ' - { - echo ${HC}file:5:foo mmap bar - echo ${HC}file:10:foo_mmap bar - echo ${HC}file:10:foo_mmap bar mmap - echo ${HC}file:5:foo mmap bar_mmap - echo ${HC}file:10:foo_mmap bar mmap baz - } >expected && + cat >expected <<-EOF && + ${HC}file:5:foo mmap bar + ${HC}file:10:foo_mmap bar + ${HC}file:10:foo_mmap bar mmap + ${HC}file:5:foo mmap bar_mmap + ${HC}file:10:foo_mmap bar mmap baz + EOF git grep --column -w -e bar -e mmap $H >actual && test_cmp expected actual ' test_expect_success "grep -w $L" ' - { - echo ${HC}file:1:foo mmap bar - echo ${HC}file:3:foo_mmap bar mmap - echo ${HC}file:4:foo mmap bar_mmap - echo ${HC}file:5:foo_mmap bar mmap baz - } >expected && + cat >expected <<-EOF && + ${HC}file:1:foo mmap bar + ${HC}file:3:foo_mmap bar mmap + ${HC}file:4:foo mmap bar_mmap + ${HC}file:5:foo_mmap bar mmap baz + EOF git -c grep.linenumber=true grep -w -e mmap $H >actual && test_cmp expected actual ' test_expect_success "grep -w $L" ' - { - echo ${HC}file:foo mmap bar - echo ${HC}file:foo_mmap bar mmap - echo ${HC}file:foo mmap bar_mmap - echo ${HC}file:foo_mmap bar mmap baz - } >expected && + cat >expected <<-EOF && + ${HC}file:foo mmap bar + ${HC}file:foo_mmap bar mmap + ${HC}file:foo mmap bar_mmap + ${HC}file:foo_mmap bar mmap baz + EOF git -c grep.linenumber=true grep --no-line-number -w -e mmap $H >actual && test_cmp expected actual ' @@ -239,17 +239,17 @@ do ' test_expect_success "grep -w $L (x)" ' - { - echo ${HC}x:1:x x xx x - } >expected && + cat >expected <<-EOF && + ${HC}x:1:x x xx x + EOF git grep -n -w -e "x xx* x" $H >actual && test_cmp expected actual ' test_expect_success "grep -w $L (y-1)" ' - { - echo ${HC}y:1:y yy - } >expected && + cat >expected <<-EOF && + ${HC}y:1:y yy + EOF git grep -n -w -e "^y" $H >actual && test_cmp expected actual ' @@ -277,16 +277,16 @@ do ' test_expect_success "grep $L (with --column, --only-matching)" ' - { - echo ${HC}file:1:5:mmap - echo ${HC}file:2:5:mmap - echo ${HC}file:3:5:mmap - echo ${HC}file:3:13:mmap - echo ${HC}file:4:5:mmap - echo ${HC}file:4:13:mmap - echo ${HC}file:5:5:mmap - echo ${HC}file:5:13:mmap - } >expected && + cat >expected <<-EOF && + ${HC}file:1:5:mmap + ${HC}file:2:5:mmap + ${HC}file:3:5:mmap + ${HC}file:3:13:mmap + ${HC}file:4:5:mmap + ${HC}file:4:13:mmap + ${HC}file:5:5:mmap + ${HC}file:5:13:mmap + EOF git grep --column -n -o -e mmap $H >actual && test_cmp expected actual ' @@ -320,11 +320,11 @@ do ' test_expect_success "grep --max-depth -1 $L" ' - { - echo ${HC}t/a/v:1:vvv - echo ${HC}t/v:1:vvv - echo ${HC}v:1:vvv - } >expected && + cat >expected <<-EOF && + ${HC}t/a/v:1:vvv + ${HC}t/v:1:vvv + ${HC}v:1:vvv + EOF git grep --max-depth -1 -n -e vvv $H >actual && test_cmp expected actual && git grep --recursive -n -e vvv $H >actual && @@ -332,9 +332,9 @@ do ' test_expect_success "grep --max-depth 0 $L" ' - { - echo ${HC}v:1:vvv - } >expected && + cat >expected <<-EOF && + ${HC}v:1:vvv + EOF git grep --max-depth 0 -n -e vvv $H >actual && test_cmp expected actual && git grep --no-recursive -n -e vvv $H >actual && @@ -342,11 +342,11 @@ do ' test_expect_success "grep --max-depth 0 -- '*' $L" ' - { - echo ${HC}t/a/v:1:vvv - echo ${HC}t/v:1:vvv - echo ${HC}v:1:vvv - } >expected && + cat >expected <<-EOF && + ${HC}t/a/v:1:vvv + ${HC}t/v:1:vvv + ${HC}v:1:vvv + EOF git grep --max-depth 0 -n -e vvv $H -- "*" >actual && test_cmp expected actual && git grep --no-recursive -n -e vvv $H -- "*" >actual && @@ -354,18 +354,18 @@ do ' test_expect_success "grep --max-depth 1 $L" ' - { - echo ${HC}t/v:1:vvv - echo ${HC}v:1:vvv - } >expected && + cat >expected <<-EOF && + ${HC}t/v:1:vvv + ${HC}v:1:vvv + EOF git grep --max-depth 1 -n -e vvv $H >actual && test_cmp expected actual ' test_expect_success "grep --max-depth 0 -- t $L" ' - { - echo ${HC}t/v:1:vvv - } >expected && + cat >expected <<-EOF && + ${HC}t/v:1:vvv + EOF git grep --max-depth 0 -n -e vvv $H -- t >actual && test_cmp expected actual && git grep --no-recursive -n -e vvv $H -- t >actual && @@ -373,10 +373,10 @@ do ' test_expect_success "grep --max-depth 0 -- . t $L" ' - { - echo ${HC}t/v:1:vvv - echo ${HC}v:1:vvv - } >expected && + cat >expected <<-EOF && + ${HC}t/v:1:vvv + ${HC}v:1:vvv + EOF git grep --max-depth 0 -n -e vvv $H -- . t >actual && test_cmp expected actual && git grep --no-recursive -n -e vvv $H -- . t >actual && @@ -384,10 +384,10 @@ do ' test_expect_success "grep --max-depth 0 -- t . $L" ' - { - echo ${HC}t/v:1:vvv - echo ${HC}v:1:vvv - } >expected && + cat >expected <<-EOF && + ${HC}t/v:1:vvv + ${HC}v:1:vvv + EOF git grep --max-depth 0 -n -e vvv $H -- t . >actual && test_cmp expected actual && git grep --no-recursive -n -e vvv $H -- t . >actual && @@ -1314,10 +1314,10 @@ test_expect_success PCRE 'grep -P pattern with grep.extendedRegexp=true' ' ' test_expect_success PCRE 'grep -P -v pattern' ' - { - echo "ab:a+b*c" - echo "ab:a+bc" - } >expected && + cat >expected <<-\EOF && + ab:a+b*c + ab:a+bc + EOF git grep -P -v "abc" ab >actual && test_cmp expected actual ' @@ -1331,10 +1331,10 @@ test_expect_success PCRE 'grep -P -i pattern' ' ' test_expect_success PCRE 'grep -P -w pattern' ' - { - echo "hello_world:Hello world" - echo "hello_world:HeLLo world" - } >expected && + cat >expected <<-\EOF && + hello_world:Hello world + hello_world:HeLLo world + EOF git grep -P -w "He((?i)ll)o" hello_world >actual && test_cmp expected actual ' @@ -1469,10 +1469,10 @@ test_expect_success 'grep -F pattern with grep.patternType=basic' ' ' test_expect_success 'grep -G pattern with grep.patternType=fixed' ' - { - echo "ab:a+b*c" - echo "ab:a+bc" - } >expected && + cat >expected <<-\EOF && + ab:a+b*c + ab:a+bc + EOF git \ -c grep.patterntype=fixed \ grep -G "a+b" ab >actual && @@ -1480,11 +1480,11 @@ test_expect_success 'grep -G pattern with grep.patternType=fixed' ' ' test_expect_success 'grep -E pattern with grep.patternType=fixed' ' - { - echo "ab:a+b*c" - echo "ab:a+bc" - echo "ab:abc" - } >expected && + cat >expected <<-\EOF && + ab:a+b*c + ab:a+bc + ab:abc + EOF git \ -c grep.patterntype=fixed \ grep -E "a+" ab >actual && diff --git a/t/t7812-grep-icase-non-ascii.sh b/t/t7812-grep-icase-non-ascii.sh index e5d1e4ea68..ca3f24f807 100755 --- a/t/t7812-grep-icase-non-ascii.sh +++ b/t/t7812-grep-icase-non-ascii.sh @@ -123,4 +123,10 @@ test_expect_success GETTEXT_LOCALE,LIBPCRE2,PCRE2_MATCH_INVALID_UTF 'PCRE v2: gr test_cmp invalid-0xe5 actual ' +test_expect_success GETTEXT_LOCALE,LIBPCRE2 'PCRE v2: grep non-literal ASCII from UTF-8' ' + git grep --perl-regexp -h -o -e ll. file >actual && + echo "lló" >expected && + test_cmp expected actual +' + test_done diff --git a/t/t8002-blame.sh b/t/t8002-blame.sh index 5bb302b1ba..ee4fdd8f18 100755 --- a/t/t8002-blame.sh +++ b/t/t8002-blame.sh @@ -97,7 +97,7 @@ test_expect_success 'set up abbrev tests' ' test_commit abbrev && sha1=$(git rev-parse --verify HEAD) && check_abbrev () { - expect=$1; shift + expect=$1 && shift && echo $sha1 | cut -c 1-$expect >expect && git blame "$@" abbrev.t >actual && perl -lne "/[0-9a-f]+/ and print \$&" <actual >actual.sha && diff --git a/t/t8003-blame-corner-cases.sh b/t/t8003-blame-corner-cases.sh index da80f815ce..d751d48b7d 100755 --- a/t/t8003-blame-corner-cases.sh +++ b/t/t8003-blame-corner-cases.sh @@ -13,14 +13,8 @@ test_expect_success setup ' echo B B B B B >two && echo C C C C C >tres && echo ABC >mouse && - for i in 1 2 3 4 5 6 7 8 9 - do - echo $i - done >nine_lines && - for i in 1 2 3 4 5 6 7 8 9 a - do - echo $i - done >ten_lines && + test_write_lines 1 2 3 4 5 6 7 8 9 >nine_lines && + test_write_lines 1 2 3 4 5 6 7 8 9 a >ten_lines && git add one two tres mouse nine_lines ten_lines && test_tick && GIT_AUTHOR_NAME=Initial git commit -m Initial && diff --git a/t/t8014-blame-ignore-fuzzy.sh b/t/t8014-blame-ignore-fuzzy.sh index e68e6115a6..0bd0341301 100755 --- a/t/t8014-blame-ignore-fuzzy.sh +++ b/t/t8014-blame-ignore-fuzzy.sh @@ -310,7 +310,7 @@ test_expect_success setup ' echo "$line" >>"$i" && git add "$i" && test_tick && - GIT_AUTHOR_NAME="$line_count" git commit -m "$line_count" + GIT_AUTHOR_NAME="$line_count" git commit -m "$line_count" || return 1 done <"a$i" done && @@ -318,7 +318,7 @@ test_expect_success setup ' do # Overwrite the files with the final content. cp b$i $i && - git add $i + git add $i || return 1 done && test_tick && diff --git a/t/t9104-git-svn-follow-parent.sh b/t/t9104-git-svn-follow-parent.sh index 67eed2fefc..c7d8e0bf00 100755 --- a/t/t9104-git-svn-follow-parent.sh +++ b/t/t9104-git-svn-follow-parent.sh @@ -117,7 +117,7 @@ test_expect_success 'follow-parent avoids deleting relevant info' ' mkdir -p import/trunk/subversion/bindings/swig/perl/t && for i in a b c ; do \ echo $i > import/trunk/subversion/bindings/swig/perl/$i.pm && - echo _$i > import/trunk/subversion/bindings/swig/perl/t/$i.t; \ + echo _$i > import/trunk/subversion/bindings/swig/perl/t/$i.t || return 1 done && echo "bad delete test" > \ import/trunk/subversion/bindings/swig/perl/t/larger-parent && @@ -134,7 +134,7 @@ test_expect_success 'follow-parent avoids deleting relevant info' ' svn mv t native/t && for i in a b c do - svn mv $i.pm native/$i.pm + svn mv $i.pm native/$i.pm || return 1 done && echo z >>native/t/c.t && poke native/t/c.t && diff --git a/t/t9107-git-svn-migrate.sh b/t/t9107-git-svn-migrate.sh index ceaa5bad10..aa908bbc2f 100755 --- a/t/t9107-git-svn-migrate.sh +++ b/t/t9107-git-svn-migrate.sh @@ -98,10 +98,10 @@ test_expect_success 'migrate --minimize on old inited layout' ' rm -rf "$GIT_DIR"/svn && for i in $(cat fetch.out) do - path=$(expr $i : "\([^:]*\):.*$") - ref=$(expr $i : "[^:]*:\(refs/remotes/.*\)$") - if test -z "$ref"; then continue; fi - if test -n "$path"; then path="/$path"; fi + path=${i%%:*} && + ref=${i#*:} && + if test "$ref" = "${ref#refs/remotes/}"; then continue; fi && + if test -n "$path"; then path="/$path"; fi && mkdir -p "$GIT_DIR"/svn/$ref/info/ && echo "$svnrepo"$path >"$GIT_DIR"/svn/$ref/info/url || return 1 diff --git a/t/t9130-git-svn-authors-file.sh b/t/t9130-git-svn-authors-file.sh index cb764bcadc..90325db909 100755 --- a/t/t9130-git-svn-authors-file.sh +++ b/t/t9130-git-svn-authors-file.sh @@ -15,7 +15,7 @@ EOF test_expect_success 'setup svnrepo' ' for i in aa bb cc dd do - svn_cmd mkdir -m $i --username $i "$svnrepo"/$i + svn_cmd mkdir -m $i --username $i "$svnrepo"/$i || return 1 done ' @@ -59,8 +59,8 @@ test_expect_success 'authors-file against globs' ' git svn clone --authors-file=svn-authors -s "$svnrepo"/aa aa-work && for i in bb ee cc do - branch="aa/branches/$i" - svn_cmd mkdir -m "$branch" --username $i "$svnrepo/$branch" + branch="aa/branches/$i" && + svn_cmd mkdir -m "$branch" --username $i "$svnrepo/$branch" || return 1 done ' diff --git a/t/t9134-git-svn-ignore-paths.sh b/t/t9134-git-svn-ignore-paths.sh index fff49c4100..4a77eb9f60 100755 --- a/t/t9134-git-svn-ignore-paths.sh +++ b/t/t9134-git-svn-ignore-paths.sh @@ -27,7 +27,7 @@ test_expect_success 'setup test repository' ' test_expect_success 'clone an SVN repository with ignored www directory' ' git svn clone --ignore-paths="^www" "$svnrepo" g && echo test_qqq > expect && - for i in g/*/*.txt; do cat $i >> expect2; done && + for i in g/*/*.txt; do cat $i >> expect2 || return 1; done && test_cmp expect expect2 ' @@ -36,7 +36,7 @@ test_expect_success 'init+fetch an SVN repository with ignored www directory' ' ( cd c && git svn fetch --ignore-paths="^www" ) && rm expect2 && echo test_qqq > expect && - for i in c/*/*.txt; do cat $i >> expect2; done && + for i in c/*/*.txt; do cat $i >> expect2 || return 1; done && test_cmp expect expect2 ' @@ -62,7 +62,7 @@ test_expect_success 'update git svn-cloned repo (config ignore)' ' cd g && git svn rebase && printf "test_qqq\nb\n" > expect && - for i in */*.txt; do cat $i >> expect2; done && + for i in */*.txt; do cat $i >> expect2 || exit 1; done && test_cmp expect2 expect && rm expect expect2 ) @@ -73,7 +73,7 @@ test_expect_success 'update git svn-cloned repo (option ignore)' ' cd c && git svn rebase --ignore-paths="^www" && printf "test_qqq\nb\n" > expect && - for i in */*.txt; do cat $i >> expect2; done && + for i in */*.txt; do cat $i >> expect2 || exit 1; done && test_cmp expect2 expect && rm expect expect2 ) @@ -94,7 +94,7 @@ test_expect_success 'update git svn-cloned repo (config ignore)' ' cd g && git svn rebase && printf "test_qqq\nb\n" > expect && - for i in */*.txt; do cat $i >> expect2; done && + for i in */*.txt; do cat $i >> expect2 || exit 1; done && test_cmp expect2 expect && rm expect expect2 ) @@ -105,7 +105,7 @@ test_expect_success 'update git svn-cloned repo (option ignore)' ' cd c && git svn rebase --ignore-paths="^www" && printf "test_qqq\nb\n" > expect && - for i in */*.txt; do cat $i >> expect2; done && + for i in */*.txt; do cat $i >> expect2 || exit 1; done && test_cmp expect2 expect && rm expect expect2 ) @@ -127,7 +127,7 @@ test_expect_success 'update git svn-cloned repo again (config ignore)' ' cd g && git svn rebase && printf "test_qqq\nb\nygg\n" > expect && - for i in */*.txt; do cat $i >> expect2; done && + for i in */*.txt; do cat $i >> expect2 || exit 1; done && test_cmp expect2 expect && rm expect expect2 ) @@ -138,7 +138,7 @@ test_expect_success 'update git svn-cloned repo again (option ignore)' ' cd c && git svn rebase --ignore-paths="^www" && printf "test_qqq\nb\nygg\n" > expect && - for i in */*.txt; do cat $i >> expect2; done && + for i in */*.txt; do cat $i >> expect2 || exit 1; done && test_cmp expect2 expect && rm expect expect2 ) diff --git a/t/t9138-git-svn-authors-prog.sh b/t/t9138-git-svn-authors-prog.sh index 027b416720..784ec7fc2d 100755 --- a/t/t9138-git-svn-authors-prog.sh +++ b/t/t9138-git-svn-authors-prog.sh @@ -27,7 +27,7 @@ test_expect_success 'svn-authors setup' ' test_expect_success 'setup svnrepo' ' for i in aa bb cc-sub dd-sub ee-foo ff do - svn mkdir -m $i --username $i "$svnrepo"/$i + svn mkdir -m $i --username $i "$svnrepo"/$i || return 1 done ' diff --git a/t/t9146-git-svn-empty-dirs.sh b/t/t9146-git-svn-empty-dirs.sh index 5f91c0d68b..80cb55fee7 100755 --- a/t/t9146-git-svn-empty-dirs.sh +++ b/t/t9146-git-svn-empty-dirs.sh @@ -8,7 +8,7 @@ test_description='git svn creates empty directories' test_expect_success 'initialize repo' ' for i in a b c d d/e d/e/f "weird file name" do - svn_cmd mkdir -m "mkdir $i" "$svnrepo"/"$i" + svn_cmd mkdir -m "mkdir $i" "$svnrepo"/"$i" || return 1 done ' @@ -102,7 +102,7 @@ test_expect_success 'git svn mkdirs -r works' ' test_expect_success 'initialize trunk' ' for i in trunk trunk/a trunk/"weird file name" do - svn_cmd mkdir -m "mkdir $i" "$svnrepo"/"$i" + svn_cmd mkdir -m "mkdir $i" "$svnrepo"/"$i" || return 1 done ' diff --git a/t/t9147-git-svn-include-paths.sh b/t/t9147-git-svn-include-paths.sh index d292bf9f55..257fc8f2f8 100755 --- a/t/t9147-git-svn-include-paths.sh +++ b/t/t9147-git-svn-include-paths.sh @@ -28,7 +28,7 @@ test_expect_success 'setup test repository' ' test_expect_success 'clone an SVN repository with filter to include qqq directory' ' git svn clone --include-paths="qqq" "$svnrepo" g && echo test_qqq > expect && - for i in g/*/*.txt; do cat $i >> expect2; done && + for i in g/*/*.txt; do cat $i >> expect2 || return 1; done && test_cmp expect expect2 ' @@ -38,7 +38,7 @@ test_expect_success 'init+fetch an SVN repository with included qqq directory' ' ( cd c && git svn fetch --include-paths="qqq" ) && rm expect2 && echo test_qqq > expect && - for i in c/*/*.txt; do cat $i >> expect2; done && + for i in c/*/*.txt; do cat $i >> expect2 || return 1; done && test_cmp expect expect2 ' @@ -64,7 +64,7 @@ test_expect_success 'update git svn-cloned repo (config include)' ' cd g && git svn rebase && printf "test_qqq\nb\n" > expect && - for i in */*.txt; do cat $i >> expect2; done && + for i in */*.txt; do cat $i >> expect2 || exit 1; done && test_cmp expect2 expect && rm expect expect2 ) @@ -75,7 +75,7 @@ test_expect_success 'update git svn-cloned repo (option include)' ' cd c && git svn rebase --include-paths="qqq" && printf "test_qqq\nb\n" > expect && - for i in */*.txt; do cat $i >> expect2; done && + for i in */*.txt; do cat $i >> expect2 || exit 1; done && test_cmp expect2 expect && rm expect expect2 ) @@ -96,7 +96,7 @@ test_expect_success 'update git svn-cloned repo (config include)' ' cd g && git svn rebase && printf "test_qqq\nb\n" > expect && - for i in */*.txt; do cat $i >> expect2; done && + for i in */*.txt; do cat $i >> expect2 || exit 1; done && test_cmp expect2 expect && rm expect expect2 ) @@ -107,7 +107,7 @@ test_expect_success 'update git svn-cloned repo (option include)' ' cd c && git svn rebase --include-paths="qqq" && printf "test_qqq\nb\n" > expect && - for i in */*.txt; do cat $i >> expect2; done && + for i in */*.txt; do cat $i >> expect2 || exit 1; done && test_cmp expect2 expect && rm expect expect2 ) @@ -129,7 +129,7 @@ test_expect_success 'update git svn-cloned repo again (config include)' ' cd g && git svn rebase && printf "test_qqq\nb\nygg\n" > expect && - for i in */*.txt; do cat $i >> expect2; done && + for i in */*.txt; do cat $i >> expect2 || exit 1; done && test_cmp expect2 expect && rm expect expect2 ) @@ -140,7 +140,7 @@ test_expect_success 'update git svn-cloned repo again (option include)' ' cd c && git svn rebase --include-paths="qqq" && printf "test_qqq\nb\nygg\n" > expect && - for i in */*.txt; do cat $i >> expect2; done && + for i in */*.txt; do cat $i >> expect2 || exit 1; done && test_cmp expect2 expect && rm expect expect2 ) diff --git a/t/t9152-svn-empty-dirs-after-gc.sh b/t/t9152-svn-empty-dirs-after-gc.sh index 89f285d082..a597c42f77 100755 --- a/t/t9152-svn-empty-dirs-after-gc.sh +++ b/t/t9152-svn-empty-dirs-after-gc.sh @@ -8,7 +8,7 @@ test_description='git svn creates empty directories, calls git gc, makes sure th test_expect_success 'initialize repo' ' for i in a b c d d/e d/e/f "weird file name" do - svn_cmd mkdir -m "mkdir $i" "$svnrepo"/"$i" + svn_cmd mkdir -m "mkdir $i" "$svnrepo"/"$i" || return 1 done ' diff --git a/t/t9304-fast-import-marks.sh b/t/t9304-fast-import-marks.sh index d4359dba21..bed01c99ea 100755 --- a/t/t9304-fast-import-marks.sh +++ b/t/t9304-fast-import-marks.sh @@ -16,7 +16,7 @@ test_expect_success 'setup large marks file' ' blob=$(git rev-parse HEAD:one.t) && for i in $(test_seq 1024 16384) do - echo ":$i $blob" + echo ":$i $blob" || return 1 done >>marks ' diff --git a/t/t9350-fast-export.sh b/t/t9350-fast-export.sh index 409b48e244..7b7a18dd2c 100755 --- a/t/t9350-fast-export.sh +++ b/t/t9350-fast-export.sh @@ -750,4 +750,36 @@ test_expect_success 'merge commit gets exported with --import-marks' ' ) ' + +test_expect_success 'fast-export --first-parent outputs all revisions output by revision walk' ' + git init first-parent && + ( + cd first-parent && + test_commit A && + git checkout -b topic1 && + test_commit B && + git checkout main && + git merge --no-ff topic1 && + + git checkout -b topic2 && + test_commit C && + git checkout main && + git merge --no-ff topic2 && + + test_commit D && + + git fast-export main -- --first-parent >first-parent-export && + git fast-export main -- --first-parent --reverse >first-parent-reverse-export && + test_cmp first-parent-export first-parent-reverse-export && + + git init import && + git -C import fast-import <first-parent-export && + + git log --format="%ad %s" --first-parent main >expected && + git -C import log --format="%ad %s" --all >actual && + test_cmp expected actual && + test_line_count = 4 actual + ) +' + test_done diff --git a/t/t9400-git-cvsserver-server.sh b/t/t9400-git-cvsserver-server.sh index 17f988edd2..210ddf09e3 100755 --- a/t/t9400-git-cvsserver-server.sh +++ b/t/t9400-git-cvsserver-server.sh @@ -338,7 +338,7 @@ test_expect_success 'cvs update (subdirectories)' \ '(for dir in A A/B A/B/C A/D E; do mkdir $dir && echo "test file in $dir" >"$dir/file_in_$(echo $dir|sed -e "s#/# #g")" && - git add $dir + git add $dir || exit 1 done) && git commit -q -m "deep sub directory structure" && git push gitcvs.git >/dev/null && @@ -350,10 +350,9 @@ test_expect_success 'cvs update (subdirectories)' \ test_cmp "$dir/$filename" "../$dir/$filename"; then : else - echo >failure + exit 1 fi - done) && - test ! -f failure' + done)' cd "$WORKDIR" test_expect_success 'cvs update (delete file)' \ @@ -382,7 +381,7 @@ test_expect_success 'cvs update (merge)' \ for i in 1 2 3 4 5 6 7 do echo Line $i >>merge && - echo Line $i >>expected + echo Line $i >>expected || return 1 done && echo Line 8 >>expected && git add merge && @@ -592,7 +591,7 @@ test_expect_success 'cvs annotate' ' cd cvswork && GIT_CONFIG="$git_config" cvs annotate merge >../out && sed -e "s/ .*//" ../out >../actual && - for i in 3 1 1 1 1 1 1 1 2 4; do echo 1.$i; done >../expect && + printf "1.%d\n" 3 1 1 1 1 1 1 1 2 4 >../expect && test_cmp ../expect ../actual ' diff --git a/t/t9800-git-p4-basic.sh b/t/t9800-git-p4-basic.sh index 81bc8e8da1..806005a793 100755 --- a/t/t9800-git-p4-basic.sh +++ b/t/t9800-git-p4-basic.sh @@ -171,7 +171,7 @@ test_expect_success 'clone using non-numeric revision ranges' ' cd "$git" && git ls-files >lines && test_line_count = 8 lines - ) + ) || return 1 done ' diff --git a/t/t9810-git-p4-rcs.sh b/t/t9810-git-p4-rcs.sh index e3836888ec..5fe83315ec 100755 --- a/t/t9810-git-p4-rcs.sh +++ b/t/t9810-git-p4-rcs.sh @@ -4,6 +4,8 @@ test_description='git p4 rcs keywords' . ./lib-git-p4.sh +CP1252="\223\224" + test_expect_success 'start p4d' ' start_p4d ' @@ -32,6 +34,9 @@ test_expect_success 'init depot' ' p4 submit -d "filek" && p4 add -t text+ko fileko && p4 submit -d "fileko" && + printf "$CP1252" >fileko_cp1252 && + p4 add -t text+ko fileko_cp1252 && + p4 submit -d "fileko_cp1252" && p4 add -t text file_text && p4 submit -d "file_text" ) @@ -359,4 +364,14 @@ test_expect_failure 'Add keywords in git which do not match the default p4 value ) ' +test_expect_success 'check cp1252 smart quote are preserved through RCS keyword processing' ' + test_when_finished cleanup_git && + git p4 clone --dest="$git" //depot && + ( + cd "$git" && + printf "$CP1252" >expect && + test_cmp_bin expect fileko_cp1252 + ) +' + test_done diff --git a/t/t9818-git-p4-block.sh b/t/t9818-git-p4-block.sh index 0db7ab9918..de591d875c 100755 --- a/t/t9818-git-p4-block.sh +++ b/t/t9818-git-p4-block.sh @@ -92,11 +92,11 @@ test_expect_success 'Add some more files' ' for i in $(test_seq 0 10) do p4_add_file "included/x$i" && - p4_add_file "excluded/x$i" + p4_add_file "excluded/x$i" || return 1 done && for i in $(test_seq 0 10) do - p4_add_file "excluded/y$i" + p4_add_file "excluded/y$i" || return 1 done ' @@ -123,7 +123,7 @@ test_expect_success 'Create a repo with multiple depot paths' ' do for i in $(test_seq 1 10) do - p4_add_file "$p/file$p$i" + p4_add_file "$p/file$p$i" || return 1 done done ' diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 0f28c4ad94..98c6280632 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -876,7 +876,7 @@ test_expect_success '__git_refs - unique remote branches for git checkout DWIMer refs/remotes/remote/branch-in-remote do git update-ref $remote_ref main && - test_when_finished "git update-ref -d $remote_ref" + test_when_finished "git update-ref -d $remote_ref" || return 1 done && ( cur= && @@ -1049,7 +1049,7 @@ test_expect_success '__git_refs - only matching refs - checkout DWIMery' ' refs/remotes/remote/branch-in-remote do git update-ref $remote_ref main && - test_when_finished "git update-ref -d $remote_ref" + test_when_finished "git update-ref -d $remote_ref" || return 1 done && ( cur=mat && diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 389153e591..c3d38aaccb 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -1760,6 +1760,40 @@ test_subcommand () { } # Check that the given command was invoked as part of the +# trace2-format trace on stdin, but without an exact set of +# arguments. +# +# test_subcommand [!] <command> <args>... < <trace> +# +# For example, to look for an invocation of "git pack-objects" +# with the "--honor-pack-keep" argument, use +# +# GIT_TRACE2_EVENT=event.log git repack ... && +# test_subcommand git pack-objects --honor-pack-keep <event.log +# +# If the first parameter passed is !, this instead checks that +# the given command was not called. +# +test_subcommand_inexact () { + local negate= + if test "$1" = "!" + then + negate=t + shift + fi + + local expr=$(printf '"%s".*' "$@") + expr="${expr%,}" + + if test -n "$negate" + then + ! grep "\"event\":\"child_start\".*\[$expr\]" + else + grep "\"event\":\"child_start\".*\[$expr\]" + fi +} + +# Check that the given command was invoked as part of the # trace2-format trace on stdin. # # test_region [!] <category> <label> git <command> <args>... |