diff options
Diffstat (limited to 't')
125 files changed, 3540 insertions, 600 deletions
diff --git a/t/.gitattributes b/t/.gitattributes new file mode 100644 index 0000000000..562b12e16e --- /dev/null +++ b/t/.gitattributes @@ -0,0 +1 @@ +* -whitespace @@ -160,14 +160,12 @@ library for your script to use. - test_expect_failure <message> <script> - This is the opposite of test_expect_success. If <script> - yields success, test is considered a failure. - - Example: - - test_expect_failure \ - 'git-update-index without --add should fail adding.' \ - 'git-update-index should-be-empty' + This is NOT the opposite of test_expect_success, but is used + to mark a test that demonstrates a known breakage. Unlike + the usual test_expect_success tests, which say "ok" on + success and "FAIL" on failure, this will say "FIXED" on + success and "still broken" on failure. Failures from these + tests won't cause -i (immediate) to stop. - test_debug <script> diff --git a/t/diff-lib.sh b/t/diff-lib.sh index 7dc6d7eb1e..28b941c493 100644 --- a/t/diff-lib.sh +++ b/t/diff-lib.sh @@ -21,8 +21,8 @@ compare_diff_raw_z () { # Also we do not check SHA1 hash generation in this test, which # is a job for t0000-basic.sh - tr '\000' '\012' <"$1" | sed -e "$sanitize_diff_raw_z" >.tmp-1 - tr '\000' '\012' <"$2" | sed -e "$sanitize_diff_raw_z" >.tmp-2 + perl -pe 'y/\000/\012/' <"$1" | sed -e "$sanitize_diff_raw_z" >.tmp-1 + perl -pe 'y/\000/\012/' <"$2" | sed -e "$sanitize_diff_raw_z" >.tmp-2 git diff .tmp-1 .tmp-2 && rm -f .tmp-1 .tmp-2 } diff --git a/t/lib-httpd.sh b/t/lib-httpd.sh new file mode 100644 index 0000000000..7f206c56cf --- /dev/null +++ b/t/lib-httpd.sh @@ -0,0 +1,96 @@ +#!/bin/sh +# +# Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at> +# + +if test -z "$GIT_TEST_HTTPD" +then + say "skipping test, network testing disabled by default" + say "(define GIT_TEST_HTTPD to enable)" + test_done + exit +fi + +LIB_HTTPD_PATH=${LIB_HTTPD_PATH-'/usr/sbin/apache2'} +LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'8111'} + +TEST_PATH="$PWD"/../lib-httpd +HTTPD_ROOT_PATH="$PWD"/httpd +HTTPD_DOCUMENT_ROOT_PATH=$HTTPD_ROOT_PATH/www + +if ! test -x "$LIB_HTTPD_PATH" +then + say "skipping test, no web server found at '$LIB_HTTPD_PATH'" + test_done + exit +fi + +HTTPD_VERSION=`$LIB_HTTPD_PATH -v | \ + sed -n 's/^Server version: Apache\/\([0-9]*\)\..*$/\1/p; q'` + +if test -n "$HTTPD_VERSION" +then + if test -z "$LIB_HTTPD_MODULE_PATH" + then + if ! test $HTTPD_VERSION -ge 2 + then + say "skipping test, at least Apache version 2 is required" + test_done + exit + fi + + LIB_HTTPD_MODULE_PATH='/usr/lib/apache2/modules' + fi +else + error "Could not identify web server at '$LIB_HTTPD_PATH'" +fi + +HTTPD_PARA="-d $HTTPD_ROOT_PATH -f $TEST_PATH/apache.conf" + +prepare_httpd() { + mkdir -p $HTTPD_DOCUMENT_ROOT_PATH + + ln -s $LIB_HTTPD_MODULE_PATH $HTTPD_ROOT_PATH/modules + + if test -n "$LIB_HTTPD_SSL" + then + HTTPD_URL=https://127.0.0.1:$LIB_HTTPD_PORT + + RANDFILE_PATH="$HTTPD_ROOT_PATH"/.rnd openssl req \ + -config $TEST_PATH/ssl.cnf \ + -new -x509 -nodes \ + -out $HTTPD_ROOT_PATH/httpd.pem \ + -keyout $HTTPD_ROOT_PATH/httpd.pem + export GIT_SSL_NO_VERIFY=t + HTTPD_PARA="$HTTPD_PARA -DSSL" + else + HTTPD_URL=http://127.0.0.1:$LIB_HTTPD_PORT + fi + + if test -n "$LIB_HTTPD_DAV" -o -n "$LIB_HTTPD_SVN" + then + HTTPD_PARA="$HTTPD_PARA -DDAV" + + if test -n "$LIB_HTTPD_SVN" + then + HTTPD_PARA="$HTTPD_PARA -DSVN" + rawsvnrepo="$HTTPD_ROOT_PATH/svnrepo" + svnrepo="http://127.0.0.1:$LIB_HTTPD_PORT/svn" + fi + fi +} + +start_httpd() { + prepare_httpd + + trap 'stop_httpd; die' exit + + "$LIB_HTTPD_PATH" $HTTPD_PARA \ + -c "Listen 127.0.0.1:$LIB_HTTPD_PORT" -k start +} + +stop_httpd() { + trap 'die' exit + + "$LIB_HTTPD_PATH" $HTTPD_PARA -k stop +} diff --git a/t/lib-httpd/apache.conf b/t/lib-httpd/apache.conf new file mode 100644 index 0000000000..a4473462d1 --- /dev/null +++ b/t/lib-httpd/apache.conf @@ -0,0 +1,34 @@ +PidFile httpd.pid +DocumentRoot www +ErrorLog error.log + +<IfDefine SSL> +LoadModule ssl_module modules/mod_ssl.so + +SSLCertificateFile httpd.pem +SSLCertificateKeyFile httpd.pem +SSLRandomSeed startup file:/dev/urandom 512 +SSLRandomSeed connect file:/dev/urandom 512 +SSLSessionCache none +SSLMutex file:ssl_mutex +SSLEngine On +</IfDefine> + +<IfDefine DAV> + LoadModule dav_module modules/mod_dav.so + LoadModule dav_fs_module modules/mod_dav_fs.so + + DAVLockDB DAVLock + <Location /> + Dav on + </Location> +</IfDefine> + +<IfDefine SVN> + LoadModule dav_svn_module modules/mod_dav_svn.so + + <Location /svn> + DAV svn + SVNPath svnrepo + </Location> +</IfDefine> diff --git a/t/lib-httpd/ssl.cnf b/t/lib-httpd/ssl.cnf new file mode 100644 index 0000000000..6dab2579cb --- /dev/null +++ b/t/lib-httpd/ssl.cnf @@ -0,0 +1,8 @@ +RANDFILE = $ENV::RANDFILE_PATH + +[ req ] +default_bits = 1024 +distinguished_name = req_distinguished_name +prompt = no +[ req_distinguished_name ] +commonName = 127.0.0.1 diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index 4e49d59065..27b54cbb12 100755 --- a/t/t0000-basic.sh +++ b/t/t0000-basic.sh @@ -47,12 +47,24 @@ test_expect_success \ 'test $(wc -l < full-of-directories) = 3' ################################################################ +# Test harness +test_expect_success 'success is reported like this' ' + : +' +test_expect_failure 'pretend we have a known breakage' ' + false +' +test_expect_failure 'pretend we have fixed a known breakage' ' + : +' + +################################################################ # Basics of the basics # updating a new file without --add should fail. -test_expect_failure \ - 'git update-index without --add should fail adding.' \ - 'git update-index should-be-empty' +test_expect_success 'git update-index without --add should fail adding.' ' + ! git update-index should-be-empty +' # and with --add it should succeed, even if it is empty (it used to fail). test_expect_success \ @@ -70,9 +82,9 @@ test_expect_success \ # Removing paths. rm -f should-be-empty full-of-directories -test_expect_failure \ - 'git update-index without --remove should fail removing.' \ - 'git update-index should-be-empty' +test_expect_success 'git update-index without --remove should fail removing.' ' + ! git update-index should-be-empty +' test_expect_success \ 'git update-index with --remove should be able to remove.' \ @@ -204,9 +216,9 @@ test_expect_success \ 'put invalid objects into the index.' \ 'git update-index --index-info < badobjects' -test_expect_failure \ - 'writing this tree without --missing-ok.' \ - 'git write-tree' +test_expect_success 'writing this tree without --missing-ok.' ' + ! git write-tree +' test_expect_success \ 'writing this tree with --missing-ok.' \ @@ -292,9 +304,31 @@ test_expect_success 'absolute path works as expected' ' test "$dir" = "$(test-absolute-path $dir2)" && file="$dir"/index && test "$file" = "$(test-absolute-path $dir2/index)" && + basename=blub && + test "$dir/$basename" = $(cd .git && test-absolute-path $basename) && ln -s ../first/file .git/syml && sym="$(cd first; pwd -P)"/file && test "$sym" = "$(test-absolute-path $dir2/syml)" ' +test_expect_success 'very long name in the index handled sanely' ' + + a=a && # 1 + a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 16 + a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 256 + a=$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a$a && # 4096 + a=${a}q && + + >path4 && + git update-index --add path4 && + ( + git ls-files -s path4 | + sed -e "s/ .*/ /" | + tr -d "\012" + echo "$a" + ) | git update-index --index-info && + len=$(git ls-files "a*" | wc -c) && + test $len = 4098 +' + test_done diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh index 47f08a46c2..3faf135e38 100755 --- a/t/t0003-attributes.sh +++ b/t/t0003-attributes.sh @@ -11,7 +11,7 @@ attr_check () { git check-attr test -- "$path" >actual && echo "$path: test: $2" >expect && - diff -u expect actual + test_cmp expect actual } diff --git a/t/t0020-crlf.sh b/t/t0020-crlf.sh index 8b27aa892b..2bfeac986e 100755 --- a/t/t0020-crlf.sh +++ b/t/t0020-crlf.sh @@ -5,7 +5,11 @@ test_description='CRLF conversion' . ./test-lib.sh q_to_nul () { - tr Q '\000' + perl -pe 'y/Q/\000/' +} + +q_to_cr () { + tr Q '\015' } append_cr () { @@ -42,6 +46,60 @@ test_expect_success setup ' echo happy. ' +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 && + ! git add allcrlf +' + +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 && + ! git add mixed +' + +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 && + ! git add alllf +' + +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 && + ! git add mixed +' + +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 && + 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 $(git add doublewarn 2>&1 | grep "CRLF will be replaced by LF" | wc -l) = 1 +' + +test_expect_success 'switch off autocrlf, safecrlf, reset HEAD' ' + git config core.autocrlf false && + git config core.safecrlf false && + git reset --hard HEAD^ +' + test_expect_success 'update with autocrlf=input' ' rm -f tmp one dir/two three && diff --git a/t/t0022-crlf-rename.sh b/t/t0022-crlf-rename.sh index 430a1d1d38..7d1ce2d056 100755 --- a/t/t0022-crlf-rename.sh +++ b/t/t0022-crlf-rename.sh @@ -26,7 +26,7 @@ test_expect_success 'diff -M' ' git diff-tree -M -r --name-status HEAD^ HEAD | sed -e "s/R[0-9]*/RNUM/" >actual && echo "RNUM sample elpmas" >expect && - diff -u expect actual + test_cmp expect actual ' diff --git a/t/t0030-stripspace.sh b/t/t0030-stripspace.sh index cad95f35ad..3ecdd6626a 100755 --- a/t/t0030-stripspace.sh +++ b/t/t0030-stripspace.sh @@ -243,14 +243,14 @@ test_expect_success \ test `printf "$ttt$sss$sss$sss" | git stripspace | wc -l` -gt 0 ' -test_expect_failure \ +test_expect_success \ 'text plus spaces without newline at end should not show spaces' ' - printf "$ttt$sss" | git stripspace | grep -q " " || - printf "$ttt$ttt$sss" | git stripspace | grep -q " " || - printf "$ttt$ttt$ttt$sss" | git stripspace | grep -q " " || - printf "$ttt$sss$sss" | git stripspace | grep -q " " || - printf "$ttt$ttt$sss$sss" | git stripspace | grep -q " " || - printf "$ttt$sss$sss$sss" | git stripspace | grep -q " " + ! (printf "$ttt$sss" | git stripspace | grep " " >/dev/null) && + ! (printf "$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) && + ! (printf "$ttt$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) && + ! (printf "$ttt$sss$sss" | git stripspace | grep " " >/dev/null) && + ! (printf "$ttt$ttt$sss$sss" | git stripspace | grep " " >/dev/null) && + ! (printf "$ttt$sss$sss$sss" | git stripspace | grep " " >/dev/null) ' test_expect_success \ @@ -280,14 +280,14 @@ test_expect_success \ git diff expect actual ' -test_expect_failure \ +test_expect_success \ 'text plus spaces at end should not show spaces' ' - echo "$ttt$sss" | git stripspace | grep -q " " || - echo "$ttt$ttt$sss" | git stripspace | grep -q " " || - echo "$ttt$ttt$ttt$sss" | git stripspace | grep -q " " || - echo "$ttt$sss$sss" | git stripspace | grep -q " " || - echo "$ttt$ttt$sss$sss" | git stripspace | grep -q " " || - echo "$ttt$sss$sss$sss" | git stripspace | grep -q " " + ! (echo "$ttt$sss" | git stripspace | grep " " >/dev/null) && + ! (echo "$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) && + ! (echo "$ttt$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) && + ! (echo "$ttt$sss$sss" | git stripspace | grep " " >/dev/null) && + ! (echo "$ttt$ttt$sss$sss" | git stripspace | grep " " >/dev/null) && + ! (echo "$ttt$sss$sss$sss" | git stripspace | grep " " >/dev/null) ' test_expect_success \ @@ -339,13 +339,13 @@ test_expect_success \ git diff expect actual ' -test_expect_failure \ +test_expect_success \ 'spaces without newline at end should not show spaces' ' - printf "" | git stripspace | grep -q " " || - printf "$sss" | git stripspace | grep -q " " || - printf "$sss$sss" | git stripspace | grep -q " " || - printf "$sss$sss$sss" | git stripspace | grep -q " " || - printf "$sss$sss$sss$sss" | git stripspace | grep -q " " + ! (printf "" | git stripspace | grep " " >/dev/null) && + ! (printf "$sss" | git stripspace | grep " " >/dev/null) && + ! (printf "$sss$sss" | git stripspace | grep " " >/dev/null) && + ! (printf "$sss$sss$sss" | git stripspace | grep " " >/dev/null) && + ! (printf "$sss$sss$sss$sss" | git stripspace | grep " " >/dev/null) ' test_expect_success \ diff --git a/t/t0040-parse-options.sh b/t/t0040-parse-options.sh index 0a3b55d121..c23f0ace85 100755 --- a/t/t0040-parse-options.sh +++ b/t/t0040-parse-options.sh @@ -21,6 +21,9 @@ string options --st <st> get another string (pervert ordering) -o <str> get another string +magic arguments + --quux means --quux + EOF test_expect_success 'test help' ' @@ -87,9 +90,9 @@ test_expect_success 'unambiguously abbreviated option with "="' ' git diff expect output ' -test_expect_failure 'ambiguously abbreviated option' ' +test_expect_success 'ambiguously abbreviated option' ' test-parse-options --strin 123; - test $? != 129 + test $? = 129 ' cat > expect << EOF @@ -114,4 +117,17 @@ test_expect_success 'detect possible typos' ' git diff expect.err output.err ' +cat > expect <<EOF +boolean: 0 +integer: 0 +string: (not set) +arg 00: --quux +EOF + +test_expect_success 'keep some options as arguments' ' + test-parse-options --quux > output 2> output.err && + test ! -s output.err && + git diff expect output +' + test_done diff --git a/t/t0050-filesystem.sh b/t/t0050-filesystem.sh new file mode 100755 index 0000000000..3fbad77811 --- /dev/null +++ b/t/t0050-filesystem.sh @@ -0,0 +1,93 @@ +#!/bin/sh + +test_description='Various filesystem issues' + +. ./test-lib.sh + +auml=`printf '\xc3\xa4'` +aumlcdiar=`printf '\x61\xcc\x88'` + +test_expect_success 'see if we expect ' ' + + test_case=test_expect_success + test_unicode=test_expect_success + mkdir junk && + echo good >junk/CamelCase && + echo bad >junk/camelcase && + if test "$(cat junk/CamelCase)" != good + then + test_case=test_expect_failure + say "will test on a case insensitive filesystem" + fi && + rm -fr junk && + mkdir junk && + >junk/"$auml" && + case "$(cd junk && echo *)" in + "$aumlcdiar") + test_unicode=test_expect_failure + say "will test on a unicode corrupting filesystem" + ;; + *) ;; + esac && + rm -fr junk +' + +test_expect_success "setup case tests" ' + + touch camelcase && + git add camelcase && + git commit -m "initial" && + git tag initial && + git checkout -b topic && + git mv camelcase tmp && + git mv tmp CamelCase && + git commit -m "rename" && + git checkout -f master + +' + +$test_case 'rename (case change)' ' + + git mv camelcase CamelCase && + git commit -m "rename" + +' + +$test_case 'merge (case change)' ' + + git reset --hard initial && + git merge topic + +' + +test_expect_success "setup unicode normalization tests" ' + + test_create_repo unicode && + cd unicode && + touch "$aumlcdiar" && + git add "$aumlcdiar" && + git commit -m initial + git tag initial && + git checkout -b topic && + git mv $aumlcdiar tmp && + git mv tmp "$auml" && + git commit -m rename && + git checkout -f master + +' + +$test_unicode 'rename (silent unicode normalization)' ' + + git mv "$aumlcdiar" "$auml" && + git commit -m rename + +' + +$test_unicode 'merge (silent unicode normalization)' ' + + git reset --hard initial && + git merge topic + +' + +test_done diff --git a/t/t1000-read-tree-m-3way.sh b/t/t1000-read-tree-m-3way.sh index 37add1b504..6c065bfa21 100755 --- a/t/t1000-read-tree-m-3way.sh +++ b/t/t1000-read-tree-m-3way.sh @@ -210,12 +210,12 @@ DF (file) when tree B require DF to be a directory by having DF/DF END_OF_CASE_TABLE -test_expect_failure \ - '1 - must not have an entry not in A.' \ - "rm -f .git/index XX && +test_expect_success '1 - must not have an entry not in A.' " + rm -f .git/index XX && echo XX >XX && git update-index --add XX && - git read-tree -m $tree_O $tree_A $tree_B" + ! git read-tree -m $tree_O $tree_A $tree_B +" test_expect_success \ '2 - must match B in !O && !A && B case.' \ @@ -248,13 +248,14 @@ test_expect_success \ echo extra >>AN && git read-tree -m $tree_O $tree_A $tree_B" -test_expect_failure \ - '3 (fail) - must match A in !O && A && !B case.' \ - "rm -f .git/index AN && +test_expect_success \ + '3 (fail) - must match A in !O && A && !B case.' " + rm -f .git/index AN && cp .orig-A/AN AN && echo extra >>AN && git update-index --add AN && - git read-tree -m $tree_O $tree_A $tree_B" + ! git read-tree -m $tree_O $tree_A $tree_B +" test_expect_success \ '4 - must match and be up-to-date in !O && A && B && A!=B case.' \ @@ -264,21 +265,23 @@ test_expect_success \ git read-tree -m $tree_O $tree_A $tree_B && check_result" -test_expect_failure \ - '4 (fail) - must match and be up-to-date in !O && A && B && A!=B case.' \ - "rm -f .git/index AA && +test_expect_success \ + '4 (fail) - must match and be up-to-date in !O && A && B && A!=B case.' " + rm -f .git/index AA && cp .orig-A/AA AA && git update-index --add AA && echo extra >>AA && - git read-tree -m $tree_O $tree_A $tree_B" + ! git read-tree -m $tree_O $tree_A $tree_B +" -test_expect_failure \ - '4 (fail) - must match and be up-to-date in !O && A && B && A!=B case.' \ - "rm -f .git/index AA && +test_expect_success \ + '4 (fail) - must match and be up-to-date in !O && A && B && A!=B case.' " + rm -f .git/index AA && cp .orig-A/AA AA && echo extra >>AA && git update-index --add AA && - git read-tree -m $tree_O $tree_A $tree_B" + ! git read-tree -m $tree_O $tree_A $tree_B +" test_expect_success \ '5 - must match in !O && A && B && A==B case.' \ @@ -297,34 +300,38 @@ test_expect_success \ git read-tree -m $tree_O $tree_A $tree_B && check_result" -test_expect_failure \ - '5 (fail) - must match A in !O && A && B && A==B case.' \ - "rm -f .git/index LL && +test_expect_success \ + '5 (fail) - must match A in !O && A && B && A==B case.' " + rm -f .git/index LL && cp .orig-A/LL LL && echo extra >>LL && git update-index --add LL && - git read-tree -m $tree_O $tree_A $tree_B" + ! git read-tree -m $tree_O $tree_A $tree_B +" -test_expect_failure \ - '6 - must not exist in O && !A && !B case' \ - "rm -f .git/index DD && +test_expect_success \ + '6 - must not exist in O && !A && !B case' " + rm -f .git/index DD && echo DD >DD git update-index --add DD && - git read-tree -m $tree_O $tree_A $tree_B" + ! git read-tree -m $tree_O $tree_A $tree_B +" -test_expect_failure \ - '7 - must not exist in O && !A && B && O!=B case' \ - "rm -f .git/index DM && +test_expect_success \ + '7 - must not exist in O && !A && B && O!=B case' " + rm -f .git/index DM && cp .orig-B/DM DM && git update-index --add DM && - git read-tree -m $tree_O $tree_A $tree_B" + ! git read-tree -m $tree_O $tree_A $tree_B +" -test_expect_failure \ - '8 - must not exist in O && !A && B && O==B case' \ - "rm -f .git/index DN && +test_expect_success \ + '8 - must not exist in O && !A && B && O==B case' " + rm -f .git/index DN && cp .orig-B/DN DN && git update-index --add DN && - git read-tree -m $tree_O $tree_A $tree_B" + ! git read-tree -m $tree_O $tree_A $tree_B +" test_expect_success \ '9 - must match and be up-to-date in O && A && !B && O!=A case' \ @@ -334,21 +341,23 @@ test_expect_success \ git read-tree -m $tree_O $tree_A $tree_B && check_result" -test_expect_failure \ - '9 (fail) - must match and be up-to-date in O && A && !B && O!=A case' \ - "rm -f .git/index MD && +test_expect_success \ + '9 (fail) - must match and be up-to-date in O && A && !B && O!=A case' " + rm -f .git/index MD && cp .orig-A/MD MD && git update-index --add MD && echo extra >>MD && - git read-tree -m $tree_O $tree_A $tree_B" + ! git read-tree -m $tree_O $tree_A $tree_B +" -test_expect_failure \ - '9 (fail) - must match and be up-to-date in O && A && !B && O!=A case' \ - "rm -f .git/index MD && +test_expect_success \ + '9 (fail) - must match and be up-to-date in O && A && !B && O!=A case' " + rm -f .git/index MD && cp .orig-A/MD MD && echo extra >>MD && git update-index --add MD && - git read-tree -m $tree_O $tree_A $tree_B" + ! git read-tree -m $tree_O $tree_A $tree_B +" test_expect_success \ '10 - must match and be up-to-date in O && A && !B && O==A case' \ @@ -358,21 +367,23 @@ test_expect_success \ git read-tree -m $tree_O $tree_A $tree_B && check_result" -test_expect_failure \ - '10 (fail) - must match and be up-to-date in O && A && !B && O==A case' \ - "rm -f .git/index ND && +test_expect_success \ + '10 (fail) - must match and be up-to-date in O && A && !B && O==A case' " + rm -f .git/index ND && cp .orig-A/ND ND && git update-index --add ND && echo extra >>ND && - git read-tree -m $tree_O $tree_A $tree_B" + ! git read-tree -m $tree_O $tree_A $tree_B +" -test_expect_failure \ - '10 (fail) - must match and be up-to-date in O && A && !B && O==A case' \ - "rm -f .git/index ND && +test_expect_success \ + '10 (fail) - must match and be up-to-date in O && A && !B && O==A case' " + rm -f .git/index ND && cp .orig-A/ND ND && echo extra >>ND && git update-index --add ND && - git read-tree -m $tree_O $tree_A $tree_B" + ! git read-tree -m $tree_O $tree_A $tree_B +" test_expect_success \ '11 - must match and be up-to-date in O && A && B && O!=A && O!=B && A!=B case' \ @@ -382,21 +393,23 @@ test_expect_success \ git read-tree -m $tree_O $tree_A $tree_B && check_result" -test_expect_failure \ - '11 (fail) - must match and be up-to-date in O && A && B && O!=A && O!=B && A!=B case' \ - "rm -f .git/index MM && +test_expect_success \ + '11 (fail) - must match and be up-to-date in O && A && B && O!=A && O!=B && A!=B case' " + rm -f .git/index MM && cp .orig-A/MM MM && git update-index --add MM && echo extra >>MM && - git read-tree -m $tree_O $tree_A $tree_B" + ! git read-tree -m $tree_O $tree_A $tree_B +" -test_expect_failure \ - '11 (fail) - must match and be up-to-date in O && A && B && O!=A && O!=B && A!=B case' \ - "rm -f .git/index MM && +test_expect_success \ + '11 (fail) - must match and be up-to-date in O && A && B && O!=A && O!=B && A!=B case' " + rm -f .git/index MM && cp .orig-A/MM MM && echo extra >>MM && git update-index --add MM && - git read-tree -m $tree_O $tree_A $tree_B" + ! git read-tree -m $tree_O $tree_A $tree_B +" test_expect_success \ '12 - must match A in O && A && B && O!=A && A==B case' \ @@ -415,13 +428,14 @@ test_expect_success \ git read-tree -m $tree_O $tree_A $tree_B && check_result" -test_expect_failure \ - '12 (fail) - must match A in O && A && B && O!=A && A==B case' \ - "rm -f .git/index SS && +test_expect_success \ + '12 (fail) - must match A in O && A && B && O!=A && A==B case' " + rm -f .git/index SS && cp .orig-A/SS SS && echo extra >>SS && git update-index --add SS && - git read-tree -m $tree_O $tree_A $tree_B" + ! git read-tree -m $tree_O $tree_A $tree_B +" test_expect_success \ '13 - must match A in O && A && B && O!=A && O==B case' \ @@ -457,21 +471,23 @@ test_expect_success \ git read-tree -m $tree_O $tree_A $tree_B && check_result" -test_expect_failure \ - '14 (fail) - must match and be up-to-date in O && A && B && O==A && O!=B case' \ - "rm -f .git/index NM && +test_expect_success \ + '14 (fail) - must match and be up-to-date in O && A && B && O==A && O!=B case' " + rm -f .git/index NM && cp .orig-A/NM NM && git update-index --add NM && echo extra >>NM && - git read-tree -m $tree_O $tree_A $tree_B" + ! git read-tree -m $tree_O $tree_A $tree_B +" -test_expect_failure \ - '14 (fail) - must match and be up-to-date in O && A && B && O==A && O!=B case' \ - "rm -f .git/index NM && +test_expect_success \ + '14 (fail) - must match and be up-to-date in O && A && B && O==A && O!=B case' " + rm -f .git/index NM && cp .orig-A/NM NM && echo extra >>NM && git update-index --add NM && - git read-tree -m $tree_O $tree_A $tree_B" + ! git read-tree -m $tree_O $tree_A $tree_B +" test_expect_success \ '15 - must match A in O && A && B && O==A && O==B case' \ @@ -490,13 +506,14 @@ test_expect_success \ git read-tree -m $tree_O $tree_A $tree_B && check_result" -test_expect_failure \ - '15 (fail) - must match A in O && A && B && O==A && O==B case' \ - "rm -f .git/index NN && +test_expect_success \ + '15 (fail) - must match A in O && A && B && O==A && O==B case' " + rm -f .git/index NN && cp .orig-A/NN NN && echo extra >>NN && git update-index --add NN && - git read-tree -m $tree_O $tree_A $tree_B" + ! git read-tree -m $tree_O $tree_A $tree_B +" # #16 test_expect_success \ diff --git a/t/t1005-read-tree-reset.sh b/t/t1005-read-tree-reset.sh new file mode 100755 index 0000000000..b0d31f5a9b --- /dev/null +++ b/t/t1005-read-tree-reset.sh @@ -0,0 +1,30 @@ +#!/bin/sh + +test_description='read-tree -u --reset' + +. ./test-lib.sh + +# two-tree test + +test_expect_success 'setup' ' + git init && + mkdir df && + echo content >df/file && + git add df/file && + git commit -m one && + git ls-files >expect && + rm -rf df && + echo content >df && + git add df && + echo content >new && + git add new && + git commit -m two +' + +test_expect_success 'reset should work' ' + git read-tree -u --reset HEAD^ && + git ls-files >actual && + test_cmp expect actual +' + +test_done diff --git a/t/t1200-tutorial.sh b/t/t1200-tutorial.sh index 991d3c5e9c..dcb3108c29 100755 --- a/t/t1200-tutorial.sh +++ b/t/t1200-tutorial.sh @@ -101,8 +101,8 @@ echo "Play, play, play" >>hello echo "Lots of fun" >>example git commit -m 'Some fun.' -i hello example -test_expect_failure 'git resolve now fails' ' - git merge -m "Merge work in mybranch" mybranch +test_expect_success 'git resolve now fails' ' + ! git merge -m "Merge work in mybranch" mybranch ' cat > hello << EOF @@ -156,6 +156,8 @@ test_expect_success 'git show-branch' 'cmp show-branch2.expect show-branch2.outp test_expect_success 'git repack' 'git repack' test_expect_success 'git prune-packed' 'git prune-packed' -test_expect_failure '-> only packed objects' 'find -type f .git/objects/[0-9a-f][0-9a-f]' +test_expect_success '-> only packed objects' ' + ! find -type f .git/objects/[0-9a-f][0-9a-f] +' test_done diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh index d9e358e1b4..b36a9012ec 100755 --- a/t/t1300-repo-config.sh +++ b/t/t1300-repo-config.sh @@ -200,8 +200,9 @@ test_expect_success 'non-match' \ test_expect_success 'non-match value' \ 'test wow = $(git config --get nextsection.nonewline !for)' -test_expect_failure 'ambiguous get' \ - 'git config --get nextsection.nonewline' +test_expect_success 'ambiguous get' ' + ! git config --get nextsection.nonewline +' test_expect_success 'get multivar' \ 'git config --get-all nextsection.nonewline' @@ -221,13 +222,17 @@ EOF test_expect_success 'multivar replace' 'cmp .git/config expect' -test_expect_failure 'ambiguous value' 'git config nextsection.nonewline' +test_expect_success 'ambiguous value' ' + ! git config nextsection.nonewline +' -test_expect_failure 'ambiguous unset' \ - 'git config --unset nextsection.nonewline' +test_expect_success 'ambiguous unset' ' + ! git config --unset nextsection.nonewline +' -test_expect_failure 'invalid unset' \ - 'git config --unset somesection.nonewline' +test_expect_success 'invalid unset' ' + ! git config --unset somesection.nonewline +' git config --unset nextsection.nonewline "wow3$" @@ -243,7 +248,7 @@ EOF test_expect_success 'multivar unset' 'cmp .git/config expect' -test_expect_failure 'invalid key' 'git config inval.2key blabla' +test_expect_success 'invalid key' '! git config inval.2key blabla' test_expect_success 'correct key' 'git config 123456.a123 987' @@ -424,8 +429,9 @@ EOF test_expect_success "rename succeeded" "git diff expect .git/config" -test_expect_failure "rename non-existing section" \ - 'git config --rename-section branch."world domination" branch.drei' +test_expect_success "rename non-existing section" ' + ! git config --rename-section branch."world domination" branch.drei +' test_expect_success "rename succeeded" "git diff expect .git/config" @@ -536,14 +542,14 @@ test_expect_success bool ' done && cmp expect result' -test_expect_failure 'invalid bool (--get)' ' +test_expect_success 'invalid bool (--get)' ' git config bool.nobool foobar && - git config --bool --get bool.nobool' + ! git config --bool --get bool.nobool' -test_expect_failure 'invalid bool (set)' ' +test_expect_success 'invalid bool (set)' ' - git config --bool bool.nobool foobar' + ! git config --bool bool.nobool foobar' rm .git/config @@ -604,8 +610,9 @@ EOF test_expect_success 'quoting' 'cmp .git/config expect' -test_expect_failure 'key with newline' 'git config key.with\\\ -newline 123' +test_expect_success 'key with newline' ' + ! git config "key.with +newline" 123' test_expect_success 'value with newline' 'git config key.sub value.with\\\ newline' @@ -650,12 +657,12 @@ Qsection.sub=section.val4 Qsection.sub=section.val5Q EOF -git config --null --list | tr '\000' 'Q' > result +git config --null --list | perl -pe 'y/\000/Q/' > result echo >>result test_expect_success '--null --list' 'cmp result expect' -git config --null --get-regexp 'val[0-9]' | tr '\000' 'Q' > result +git config --null --get-regexp 'val[0-9]' | perl -pe 'y/\000/Q/' > result echo >>result test_expect_success '--null --get-regexp' 'cmp result expect' diff --git a/t/t1302-repo-version.sh b/t/t1302-repo-version.sh index 37fc1c8d36..9be0770e76 100755 --- a/t/t1302-repo-version.sh +++ b/t/t1302-repo-version.sh @@ -40,7 +40,8 @@ test_expect_success 'gitdir required mode on normal repos' ' (git apply --check --index test.patch && cd test && git apply --check --index ../test.patch)' -test_expect_failure 'gitdir required mode on unsupported repo' ' - (cd test2 && git apply --check --index ../test.patch)' +test_expect_success 'gitdir required mode on unsupported repo' ' + (cd test2 && ! git apply --check --index ../test.patch) +' test_done diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index 71ab2dd0ee..78cd41245b 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -51,23 +51,23 @@ test_expect_success \ test $B"' = $(cat .git/'"$m"')' rm -f .git/$m -test_expect_failure \ - '(not) create HEAD with old sha1' \ - "git update-ref HEAD $A $B" -test_expect_failure \ - "(not) prior created .git/$m" \ - "test -f .git/$m" +test_expect_success '(not) create HEAD with old sha1' " + ! git update-ref HEAD $A $B +" +test_expect_success "(not) prior created .git/$m" " + ! test -f .git/$m +" rm -f .git/$m test_expect_success \ "create HEAD" \ "git update-ref HEAD $A" -test_expect_failure \ - '(not) change HEAD with wrong SHA1' \ - "git update-ref HEAD $B $Z" -test_expect_failure \ - "(not) changed .git/$m" \ - "test $B"' = $(cat .git/'"$m"')' +test_expect_success '(not) change HEAD with wrong SHA1' " + ! git update-ref HEAD $B $Z +" +test_expect_success "(not) changed .git/$m" " + ! test $B"' = $(cat .git/'"$m"') +' rm -f .git/$m : a repository with working tree always has reflog these days... diff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh index f959aae846..73f830db23 100755 --- a/t/t1410-reflog.sh +++ b/t/t1410-reflog.sh @@ -175,21 +175,30 @@ test_expect_success 'recover and check' ' ' -test_expect_success 'prune --expire' ' - - before=$(git count-objects | sed "s/ .*//") && - BLOB=$(echo aleph | git hash-object -w --stdin) && - BLOB_FILE=.git/objects/$(echo $BLOB | sed "s/^../&\//") && - test $((1 + $before)) = $(git count-objects | sed "s/ .*//") && - test -f $BLOB_FILE && - git reset --hard && - git prune --expire=1.hour.ago && - test $((1 + $before)) = $(git count-objects | sed "s/ .*//") && - test -f $BLOB_FILE && - test-chmtime -86500 $BLOB_FILE && - git prune --expire 1.day && - test $before = $(git count-objects | sed "s/ .*//") && - ! test -f $BLOB_FILE +test_expect_success 'delete' ' + echo 1 > C && + test_tick && + git commit -m rat C && + + echo 2 > C && + test_tick && + git commit -m ox C && + + echo 3 > C && + test_tick && + git commit -m tiger C && + + test 5 = $(git reflog | wc -l) && + + git reflog delete master@{1} && + git reflog show master > output && + test 4 = $(wc -l < output) && + ! grep ox < output && + + git reflog delete master@{07.04.2005.15:15:00.-0700} && + git reflog show master > output && + test 3 = $(wc -l < output) && + ! grep dragon < output ' diff --git a/t/t1500-rev-parse.sh b/t/t1500-rev-parse.sh index e474b3f1d5..38a2bf09af 100755 --- a/t/t1500-rev-parse.sh +++ b/t/t1500-rev-parse.sh @@ -33,9 +33,9 @@ test_rev_parse() { test_rev_parse toplevel false false true '' cd .git || exit 1 -test_rev_parse .git/ true true false '' +test_rev_parse .git/ false true false '' cd objects || exit 1 -test_rev_parse .git/objects/ true true false '' +test_rev_parse .git/objects/ false true false '' cd ../.. || exit 1 mkdir -p sub/dir || exit 1 diff --git a/t/t2000-checkout-cache-clash.sh b/t/t2000-checkout-cache-clash.sh index ac84335b0a..5141fab7cf 100755 --- a/t/t2000-checkout-cache-clash.sh +++ b/t/t2000-checkout-cache-clash.sh @@ -36,9 +36,9 @@ mkdir path0 date >path0/file0 date >path1 -test_expect_failure \ +test_expect_success \ 'git checkout-index without -f should fail on conflicting work tree.' \ - 'git checkout-index -a' + '! git checkout-index -a' test_expect_success \ 'git checkout-index with -f should succeed.' \ diff --git a/t/t2002-checkout-cache-u.sh b/t/t2002-checkout-cache-u.sh index f7a0055920..0f441bcef7 100755 --- a/t/t2002-checkout-cache-u.sh +++ b/t/t2002-checkout-cache-u.sh @@ -16,12 +16,12 @@ echo frotz >path0 && git update-index --add path0 && t=$(git write-tree)' -test_expect_failure \ +test_expect_success \ 'without -u, git checkout-index smudges stat information.' ' rm -f path0 && git read-tree $t && git checkout-index -f -a && -git diff-files | diff - /dev/null' +! git diff-files | diff - /dev/null' test_expect_success \ 'with -u, git checkout-index picks up stat information from new files.' ' diff --git a/t/t2009-checkout-statinfo.sh b/t/t2009-checkout-statinfo.sh new file mode 100755 index 0000000000..f3c2152087 --- /dev/null +++ b/t/t2009-checkout-statinfo.sh @@ -0,0 +1,52 @@ +#!/bin/sh + +test_description='checkout should leave clean stat info' + +. ./test-lib.sh + +test_expect_success 'setup' ' + + echo hello >world && + git update-index --add world && + git commit -m initial && + git branch side && + echo goodbye >world && + git update-index --add world && + git commit -m second + +' + +test_expect_success 'branch switching' ' + + git reset --hard && + test "$(git diff-files --raw)" = "" && + + git checkout master && + test "$(git diff-files --raw)" = "" && + + git checkout side && + test "$(git diff-files --raw)" = "" && + + git checkout master && + test "$(git diff-files --raw)" = "" + +' + +test_expect_success 'path checkout' ' + + git reset --hard && + test "$(git diff-files --raw)" = "" && + + git checkout master world && + test "$(git diff-files --raw)" = "" && + + git checkout side world && + test "$(git diff-files --raw)" = "" && + + git checkout master world && + test "$(git diff-files --raw)" = "" + +' + +test_done + diff --git a/t/t2100-update-cache-badpath.sh b/t/t2100-update-cache-badpath.sh index 04a1ed1a6b..9beaecd18b 100755 --- a/t/t2100-update-cache-badpath.sh +++ b/t/t2100-update-cache-badpath.sh @@ -44,8 +44,8 @@ date >path1/file1 for p in path0/file0 path1/file1 path2 path3 do - test_expect_failure \ + test_expect_success \ "git update-index to add conflicting path $p should fail." \ - "git update-index --add -- $p" + "! git update-index --add -- $p" done test_done diff --git a/t/t2200-add-update.sh b/t/t2200-add-update.sh index 24f892f793..b664341926 100755 --- a/t/t2200-add-update.sh +++ b/t/t2200-add-update.sh @@ -62,7 +62,7 @@ test_expect_success 'cache tree has not been corrupted' ' sed -e "s/ 0 / /" >expect && git ls-tree -r $(git write-tree) | sed -e "s/ blob / /" >current && - diff -u expect current + test_cmp expect current ' diff --git a/t/t3001-ls-files-others-exclude.sh b/t/t3001-ls-files-others-exclude.sh index e25b255683..55f057cebe 100755 --- a/t/t3001-ls-files-others-exclude.sh +++ b/t/t3001-ls-files-others-exclude.sh @@ -97,6 +97,47 @@ cat > expect << EOF EOF test_expect_success 'git-status honours core.excludesfile' \ - 'diff -u expect output' + 'test_cmp expect output' + +test_expect_success 'trailing slash in exclude allows directory match(1)' ' + + git ls-files --others --exclude=one/ >output && + if grep "^one/" output + then + echo Ooops + false + else + : happy + fi + +' + +test_expect_success 'trailing slash in exclude allows directory match (2)' ' + + git ls-files --others --exclude=one/two/ >output && + if grep "^one/two/" output + then + echo Ooops + false + else + : happy + fi + +' + +test_expect_success 'trailing slash in exclude forces directory match (1)' ' + + >two + git ls-files --others --exclude=two/ >output && + grep "^two" output + +' + +test_expect_success 'trailing slash in exclude forces directory match (2)' ' + + git ls-files --others --exclude=one/a.1/ >output && + grep "^one/a.1" output + +' test_done diff --git a/t/t3020-ls-files-error-unmatch.sh b/t/t3020-ls-files-error-unmatch.sh index c83f820ad2..f4da869932 100755 --- a/t/t3020-ls-files-error-unmatch.sh +++ b/t/t3020-ls-files-error-unmatch.sh @@ -15,9 +15,9 @@ touch foo bar git update-index --add foo bar git-commit -m "add foo bar" -test_expect_failure \ +test_expect_success \ 'git ls-files --error-unmatch should fail with unmatched path.' \ - 'git ls-files --error-unmatch foo bar-does-not-match' + '! git ls-files --error-unmatch foo bar-does-not-match' test_expect_success \ 'git ls-files --error-unmatch should succeed eith matched paths.' \ diff --git a/t/t3050-subprojects-fetch.sh b/t/t3050-subprojects-fetch.sh index 34f26a8d9e..2b21b1070d 100755 --- a/t/t3050-subprojects-fetch.sh +++ b/t/t3050-subprojects-fetch.sh @@ -26,7 +26,7 @@ test_expect_success clone ' cd cloned && (git rev-parse HEAD; git ls-files -s) >../actual ) && - diff -u expected actual + test_cmp expected actual ' test_expect_success advance ' @@ -46,7 +46,7 @@ test_expect_success fetch ' git pull && (git rev-parse HEAD; git ls-files -s) >../actual ) && - diff -u expected actual + test_cmp expected actual ' test_done diff --git a/t/t3060-ls-files-with-tree.sh b/t/t3060-ls-files-with-tree.sh index 68eb266d73..3ce501bb97 100755 --- a/t/t3060-ls-files-with-tree.sh +++ b/t/t3060-ls-files-with-tree.sh @@ -66,6 +66,6 @@ test_expect_success 'git -ls-files --with-tree should succeed from subdir' ' cd .. test_expect_success \ 'git -ls-files --with-tree should add entries from named tree.' \ - 'diff -u expected output' + 'test_cmp expected output' test_done diff --git a/t/t3101-ls-tree-dirname.sh b/t/t3101-ls-tree-dirname.sh index 39fe2676dc..70f9ce9d52 100755 --- a/t/t3101-ls-tree-dirname.sh +++ b/t/t3101-ls-tree-dirname.sh @@ -120,7 +120,7 @@ EOF # having 1.txt and path3 test_expect_success \ 'ls-tree filter odd names' \ - 'git ls-tree $tree 1.txt /1.txt //1.txt path3/1.txt /path3/1.txt //path3//1.txt path3 /path3/ path3// >current && + 'git ls-tree $tree 1.txt ./1.txt .//1.txt path3/1.txt path3/./1.txt path3 path3// >current && cat >expected <<\EOF && 100644 blob X 1.txt 100644 blob X path3/1.txt diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh index ef1eeb7d8a..38a90adad6 100755 --- a/t/t3200-branch.sh +++ b/t/t3200-branch.sh @@ -15,12 +15,16 @@ test_expect_success \ 'echo Hello > A && git update-index --add A && git-commit -m "Initial commit." && + echo World >> A && + git update-index --add A && + git-commit -m "Second commit." && HEAD=$(git rev-parse --verify HEAD)' -test_expect_failure \ - 'git branch --help should not have created a bogus branch' \ - 'git branch --help </dev/null >/dev/null 2>/dev/null || : - test -f .git/refs/heads/--help' +test_expect_success \ + 'git branch --help should not have created a bogus branch' ' + git branch --help </dev/null >/dev/null 2>/dev/null; + ! test -f .git/refs/heads/--help +' test_expect_success \ 'git branch abc should create a branch' \ @@ -71,17 +75,17 @@ test_expect_success \ git branch -m n/n n test -f .git/logs/refs/heads/n' -test_expect_failure \ - 'git branch -m o/o o should fail when o/p exists' \ - 'git branch o/o && +test_expect_success 'git branch -m o/o o should fail when o/p exists' ' + git branch o/o && git branch o/p && - git branch -m o/o o' + ! git branch -m o/o o +' -test_expect_failure \ - 'git branch -m q r/q should fail when r exists' \ - 'git branch q && - git branch r && - git branch -m q r/q' +test_expect_success 'git branch -m q r/q should fail when r exists' ' + git branch q && + git branch r && + ! git branch -m q r/q +' mv .git/config .git/config-saved @@ -108,12 +112,13 @@ test_expect_success 'config information was renamed, too' \ "test $(git config branch.s.dummy) = Hello && ! git config branch.s/s/dummy" -test_expect_failure \ - 'git branch -m u v should fail when the reflog for u is a symlink' \ - 'git branch -l u && +test_expect_success \ + 'git branch -m u v should fail when the reflog for u is a symlink' ' + git branch -l u && mv .git/logs/refs/heads/u real-u && ln -s real-u .git/logs/refs/heads/u && - git branch -m u v' + ! git branch -m u v +' test_expect_success 'test tracking setup via --track' \ 'git config remote.local.url . && @@ -169,7 +174,9 @@ test_expect_success 'test overriding tracking setup via --no-track' \ ! test "$(git config branch.my2.merge)" = refs/heads/master' test_expect_success 'no tracking without .fetch entries' \ - 'git branch --track my6 s && + 'git config branch.autosetupmerge true && + git branch my6 s && + git config branch.automsetupmerge false && test -z "$(git config branch.my6.remote)" && test -z "$(git config branch.my6.merge)"' @@ -190,6 +197,21 @@ test_expect_success 'test deleting branch without config' \ 'git branch my7 s && test "$(git branch -d my7 2>&1)" = "Deleted branch my7."' +test_expect_success 'test --track without .fetch entries' \ + 'git branch --track my8 && + test "$(git config branch.my8.remote)" && + test "$(git config branch.my8.merge)"' + +test_expect_success \ + 'branch from non-branch HEAD w/autosetupmerge=always' \ + 'git config branch.autosetupmerge always && + git branch my9 HEAD^ && + git config branch.autosetupmerge false' + +test_expect_success \ + 'branch from non-branch HEAD w/--track causes failure' \ + '!(git branch --track my10 HEAD^)' + # Keep this test last, as it changes the current branch cat >expect <<EOF 0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master diff --git a/t/t3201-branch-contains.sh b/t/t3201-branch-contains.sh index 9ef593f0e1..b4cf628d22 100755 --- a/t/t3201-branch-contains.sh +++ b/t/t3201-branch-contains.sh @@ -31,7 +31,7 @@ test_expect_success 'branch --contains=master' ' { echo " master" && echo "* side" } >expect && - diff -u expect actual + test_cmp expect actual ' @@ -41,7 +41,7 @@ test_expect_success 'branch --contains master' ' { echo " master" && echo "* side" } >expect && - diff -u expect actual + test_cmp expect actual ' @@ -51,7 +51,7 @@ test_expect_success 'branch --contains=side' ' { echo "* side" } >expect && - diff -u expect actual + test_cmp expect actual ' diff --git a/t/t3210-pack-refs.sh b/t/t3210-pack-refs.sh index 4ddc6342a9..b64ccfbc5b 100755 --- a/t/t3210-pack-refs.sh +++ b/t/t3210-pack-refs.sh @@ -39,12 +39,12 @@ test_expect_success \ git show-ref b >result && diff expect result' -test_expect_failure \ - 'git branch c/d should barf if branch c exists' \ - 'git branch c && +test_expect_success 'git branch c/d should barf if branch c exists' ' + git branch c && git pack-refs --all && - rm .git/refs/heads/c && - git branch c/d' + rm -f .git/refs/heads/c && + ! git branch c/d +' test_expect_success \ 'see if a branch still exists after git pack-refs --prune' \ @@ -54,11 +54,11 @@ test_expect_success \ git show-ref e >result && diff expect result' -test_expect_failure \ - 'see if git pack-refs --prune remove ref files' \ - 'git branch f && +test_expect_success 'see if git pack-refs --prune remove ref files' ' + git branch f && git pack-refs --all --prune && - ls .git/refs/heads/f' + ! test -f .git/refs/heads/f +' test_expect_success \ 'git branch g should work when git branch g/h has been deleted' \ @@ -69,11 +69,11 @@ test_expect_success \ git pack-refs --all && git branch -d g' -test_expect_failure \ - 'git branch i/j/k should barf if branch i exists' \ - 'git branch i && +test_expect_success 'git branch i/j/k should barf if branch i exists' ' + git branch i && git pack-refs --all --prune && - git branch i/j/k' + ! git branch i/j/k +' test_expect_success \ 'test git branch k after branch k/l/m and k/lm have been deleted' \ diff --git a/t/t3300-funny-names.sh b/t/t3300-funny-names.sh index 98c133db50..24a00a9df1 100755 --- a/t/t3300-funny-names.sh +++ b/t/t3300-funny-names.sh @@ -54,7 +54,7 @@ echo 'just space no-funny tabs ," (dq) and spaces' >expected test_expect_success 'git ls-files -z with-funny' \ - 'git ls-files -z | tr \\000 \\012 >current && + 'git ls-files -z | perl -pe y/\\000/\\012/ >current && git diff expected current' t1=`git write-tree` @@ -83,11 +83,11 @@ test_expect_success 'git diff-tree with-funny' \ echo 'A tabs ," (dq) and spaces' >expected test_expect_success 'git diff-index -z with-funny' \ - 'git diff-index -z --name-status $t0 | tr \\000 \\012 >current && + 'git diff-index -z --name-status $t0 | perl -pe y/\\000/\\012/ >current && git diff expected current' test_expect_success 'git diff-tree -z with-funny' \ - 'git diff-tree -z --name-status $t0 $t1 | tr \\000 \\012 >current && + 'git diff-tree -z --name-status $t0 $t1 | perl -pe y/\\000/\\012/ >current && git diff expected current' cat > expected <<\EOF diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh index 95e33b5210..496f4ec172 100755 --- a/t/t3400-rebase.sh +++ b/t/t3400-rebase.sh @@ -42,9 +42,9 @@ test_expect_success \ test_expect_success 'rebase against master' ' git rebase master' -test_expect_failure \ +test_expect_success \ 'the rebase operation should not have destroyed author information' \ - 'git log | grep "Author:" | grep "<>"' + '! git log | grep "Author:" | grep "<>"' test_expect_success 'rebase after merge master' ' git reset --hard topic && diff --git a/t/t3403-rebase-skip.sh b/t/t3403-rebase-skip.sh index 657f68104d..0a26099658 100755 --- a/t/t3403-rebase-skip.sh +++ b/t/t3403-rebase-skip.sh @@ -31,8 +31,8 @@ test_expect_success setup ' git branch skip-merge skip-reference ' -test_expect_failure 'rebase with git am -3 (default)' ' - git rebase master +test_expect_success 'rebase with git am -3 (default)' ' + ! git rebase master ' test_expect_success 'rebase --skip with am -3' ' @@ -53,7 +53,7 @@ test_expect_success 'rebase moves back to skip-reference' ' test_expect_success 'checkout skip-merge' 'git checkout -f skip-merge' -test_expect_failure 'rebase with --merge' 'git rebase --merge master' +test_expect_success 'rebase with --merge' '! git rebase --merge master' test_expect_success 'rebase --skip with --merge' ' git rebase --skip diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index e5ed74545b..9cf873f7eb 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -61,8 +61,8 @@ test_expect_success 'setup' ' git tag I ' -cat > fake-editor.sh <<\EOF -#!/bin/sh +echo "#!$SHELL_PATH" >fake-editor.sh +cat >> fake-editor.sh <<\EOF case "$1" in */COMMIT_EDITMSG) test -z "$FAKE_COMMIT_MESSAGE" || echo "$FAKE_COMMIT_MESSAGE" > "$1" @@ -122,8 +122,8 @@ test_expect_success 'reflog for the branch shows state before rebase' ' test_expect_success 'exchange two commits' ' FAKE_LINES="2 1" git rebase -i HEAD~2 && - test H = $(git cat-file commit HEAD^ | tail -n 1) && - test G = $(git cat-file commit HEAD | tail -n 1) + test H = $(git cat-file commit HEAD^ | sed -ne \$p) && + test G = $(git cat-file commit HEAD | sed -ne \$p) ' cat > expect << EOF @@ -146,11 +146,10 @@ EOF test_expect_success 'stop on conflicting pick' ' git tag new-branch1 && ! git rebase -i master && - diff -u expect .git/.dotest-merge/patch && - diff -u expect2 file1 && + test_cmp expect .git/.dotest-merge/patch && + test_cmp expect2 file1 && test 4 = $(grep -v "^#" < .git/.dotest-merge/done | wc -l) && - test 0 = $(grep -ve "^#" -e "^$" < .git/.dotest-merge/git-rebase-todo | - wc -l) + test 0 = $(grep -c "^[^#]" < .git/.dotest-merge/git-rebase-todo) ' test_expect_success 'abort' ' diff --git a/t/t3405-rebase-malformed.sh b/t/t3405-rebase-malformed.sh index e4e2e649ed..e5ad67c643 100755 --- a/t/t3405-rebase-malformed.sh +++ b/t/t3405-rebase-malformed.sh @@ -41,8 +41,8 @@ test_expect_success rebase ' git rebase master side && git cat-file commit HEAD | sed -e "1,/^\$/d" >F1 && - diff -u F0 F1 && - diff -u F F0 + test_cmp F0 F1 && + test_cmp F F0 ' test_done diff --git a/t/t3406-rebase-message.sh b/t/t3406-rebase-message.sh index 332b2b2feb..5391080943 100755 --- a/t/t3406-rebase-message.sh +++ b/t/t3406-rebase-message.sh @@ -37,7 +37,7 @@ test_expect_success 'rebase -m' ' git rebase -m master >report && sed -n -e "/^Already applied: /p" \ -e "/^Committed: /p" report >actual && - diff -u expect actual + test_cmp expect actual ' diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh index b1ee622ef7..f542f0af41 100755 --- a/t/t3600-rm.sh +++ b/t/t3600-rm.sh @@ -59,15 +59,16 @@ test_expect_success \ echo "other content" > foo git rm --cached foo' -test_expect_failure \ - 'Test that git rm --cached foo fails if the index matches neither the file nor HEAD' \ - 'echo content > foo +test_expect_success \ + 'Test that git rm --cached foo fails if the index matches neither the file nor HEAD' ' + echo content > foo git add foo git commit -m foo echo "other content" > foo git add foo echo "yet another content" > foo - git rm --cached foo' + ! git rm --cached foo +' test_expect_success \ 'Test that git rm --cached -f foo works in case where --cached only did not' \ @@ -106,9 +107,9 @@ embedded'" if test "$test_failed_remove" = y; then chmod a-w . -test_expect_failure \ +test_expect_success \ 'Test that "git rm -f" fails if its rm fails' \ - 'git rm -f baz' + '! git rm -f baz' chmod 775 . else test_expect_success 'skipping removal failure (perhaps running as root?)' : @@ -212,8 +213,8 @@ test_expect_success 'Recursive with -r -f' ' ! test -d frotz ' -test_expect_failure 'Remove nonexistent file returns nonzero exit status' ' - git rm nonexistent +test_expect_success 'Remove nonexistent file returns nonzero exit status' ' + ! git rm nonexistent ' test_done diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh new file mode 100755 index 0000000000..77c90f6fa0 --- /dev/null +++ b/t/t3701-add-interactive.sh @@ -0,0 +1,69 @@ +#!/bin/sh + +test_description='add -i basic tests' +. ./test-lib.sh + +test_expect_success 'setup (initial)' ' + echo content >file && + git add file && + echo more >>file && + echo lines >>file +' +test_expect_success 'status works (initial)' ' + git add -i </dev/null >output && + grep "+1/-0 *+2/-0 file" output +' +cat >expected <<EOF +new file mode 100644 +index 0000000..d95f3ad +--- /dev/null ++++ b/file +@@ -0,0 +1 @@ ++content +EOF +test_expect_success 'diff works (initial)' ' + (echo d; echo 1) | git add -i >output && + sed -ne "/new file/,/content/p" <output >diff && + test_cmp expected diff +' +test_expect_success 'revert works (initial)' ' + git add file && + (echo r; echo 1) | git add -i && + git ls-files >output && + ! grep . output +' + +test_expect_success 'setup (commit)' ' + echo baseline >file && + git add file && + git commit -m commit && + echo content >>file && + git add file && + echo more >>file && + echo lines >>file +' +test_expect_success 'status works (commit)' ' + git add -i </dev/null >output && + grep "+1/-0 *+2/-0 file" output +' +cat >expected <<EOF +index 180b47c..b6f2c08 100644 +--- a/file ++++ b/file +@@ -1 +1,2 @@ + baseline ++content +EOF +test_expect_success 'diff works (commit)' ' + (echo d; echo 1) | git add -i >output && + sed -ne "/^index/,/content/p" <output >diff && + test_cmp expected diff +' +test_expect_success 'revert works (commit)' ' + git add file && + (echo r; echo 1) | git add -i && + git add -i </dev/null >output && + grep "unchanged *+3/-0 file" output +' + +test_done diff --git a/t/t3800-mktag.sh b/t/t3800-mktag.sh index f2803206f1..278075823b 100755 --- a/t/t3800-mktag.sh +++ b/t/t3800-mktag.sh @@ -15,7 +15,7 @@ check_verify_failure () { expect="$2" test_expect_success "$1" ' ( ! git-mktag <tag.sig 2>message ) && - grep -q "$expect" message + grep "$expect" message ' } diff --git a/t/t3902-quoted.sh b/t/t3902-quoted.sh index 73da45f18c..fe4fb5116a 100755 --- a/t/t3902-quoted.sh +++ b/t/t3902-quoted.sh @@ -78,28 +78,28 @@ EOF test_expect_success 'check fully quoted output from ls-files' ' - git ls-files >current && diff -u expect.quoted current + git ls-files >current && test_cmp expect.quoted current ' test_expect_success 'check fully quoted output from diff-files' ' git diff --name-only >current && - diff -u expect.quoted current + test_cmp expect.quoted current ' test_expect_success 'check fully quoted output from diff-index' ' git diff --name-only HEAD >current && - diff -u expect.quoted current + test_cmp expect.quoted current ' test_expect_success 'check fully quoted output from diff-tree' ' git diff --name-only HEAD^ HEAD >current && - diff -u expect.quoted current + test_cmp expect.quoted current ' @@ -111,28 +111,28 @@ test_expect_success 'setting core.quotepath' ' test_expect_success 'check fully quoted output from ls-files' ' - git ls-files >current && diff -u expect.raw current + git ls-files >current && test_cmp expect.raw current ' test_expect_success 'check fully quoted output from diff-files' ' git diff --name-only >current && - diff -u expect.raw current + test_cmp expect.raw current ' test_expect_success 'check fully quoted output from diff-index' ' git diff --name-only HEAD >current && - diff -u expect.raw current + test_cmp expect.raw current ' test_expect_success 'check fully quoted output from diff-tree' ' git diff --name-only HEAD^ HEAD >current && - diff -u expect.raw current + test_cmp expect.raw current ' diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh index 9a9a250d2c..2d3ee3b78c 100755 --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@ -34,14 +34,14 @@ EOF test_expect_success 'parents of stash' ' test $(git rev-parse stash^) = $(git rev-parse HEAD) && git diff stash^2..stash > output && - diff -u output expect + test_cmp output expect ' test_expect_success 'apply needs clean working directory' ' echo 4 > other-file && git add other-file && - echo 5 > other-file - ! git stash apply + echo 5 > other-file && + test_must_fail git stash apply ' test_expect_success 'apply stashed changes' ' @@ -70,7 +70,51 @@ test_expect_success 'unstashing in a subdirectory' ' git reset --hard HEAD && mkdir subdir && cd subdir && - git stash apply + git stash apply && + cd .. +' + +test_expect_success 'drop top stash' ' + git reset --hard && + git stash list > stashlist1 && + echo 7 > file && + git stash && + git stash drop && + git stash list > stashlist2 && + diff stashlist1 stashlist2 && + git stash apply && + test 3 = $(cat file) && + test 1 = $(git show :file) && + test 1 = $(git show HEAD:file) +' + +test_expect_success 'drop middle stash' ' + git reset --hard && + echo 8 > file && + git stash && + echo 9 > file && + git stash && + git stash drop stash@{1} && + test 2 = $(git stash list | wc -l) && + git stash apply && + test 9 = $(cat file) && + test 1 = $(git show :file) && + test 1 = $(git show HEAD:file) && + git reset --hard && + git stash drop && + git stash apply && + test 3 = $(cat file) && + test 1 = $(git show :file) && + test 1 = $(git show HEAD:file) +' + +test_expect_success 'stash pop' ' + git reset --hard && + git stash pop && + test 3 = $(cat file) && + test 1 = $(git show :file) && + test 1 = $(git show HEAD:file) && + test 0 = $(git stash list | wc -l) ' test_done diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh index 9eec754221..6b4d1c52bb 100755 --- a/t/t4013-diff-various.sh +++ b/t/t4013-diff-various.sh @@ -245,6 +245,7 @@ format-patch --inline --stdout initial..master format-patch --inline --stdout --subject-prefix=TESTCASE initial..master config format.subjectprefix DIFFERENT_PREFIX format-patch --inline --stdout initial..master^^ +format-patch --stdout --cover-letter -n initial..master^ diff --abbrev initial..side diff -r initial..side diff --git a/t/t4013/diff.format-patch_--stdout_--cover-letter_-n_initial..master^ b/t/t4013/diff.format-patch_--stdout_--cover-letter_-n_initial..master^ new file mode 100644 index 0000000000..8dab4bf93e --- /dev/null +++ b/t/t4013/diff.format-patch_--stdout_--cover-letter_-n_initial..master^ @@ -0,0 +1,100 @@ +$ git format-patch --stdout --cover-letter -n initial..master^ +From 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 Mon Sep 17 00:00:00 2001 +From: C O Mitter <committer@example.com> +Date: Mon, 26 Jun 2006 00:05:00 +0000 +Subject: [DIFFERENT_PREFIX 0/2] *** SUBJECT HERE *** + +*** BLURB HERE *** + +A U Thor (2): + Second + Third + + dir/sub | 4 ++++ + file0 | 3 +++ + file1 | 3 +++ + file2 | 3 --- + 4 files changed, 10 insertions(+), 3 deletions(-) + create mode 100644 file1 + delete mode 100644 file2 + +From 1bde4ae5f36c8d9abe3a0fce0c6aab3c4a12fe44 Mon Sep 17 00:00:00 2001 +From: A U Thor <author@example.com> +Date: Mon, 26 Jun 2006 00:01:00 +0000 +Subject: [DIFFERENT_PREFIX 1/2] Second + +This is the second commit. +--- + dir/sub | 2 ++ + file0 | 3 +++ + file2 | 3 --- + 3 files changed, 5 insertions(+), 3 deletions(-) + delete mode 100644 file2 + +diff --git a/dir/sub b/dir/sub +index 35d242b..8422d40 100644 +--- a/dir/sub ++++ b/dir/sub +@@ -1,2 +1,4 @@ + A + B ++C ++D +diff --git a/file0 b/file0 +index 01e79c3..b414108 100644 +--- a/file0 ++++ b/file0 +@@ -1,3 +1,6 @@ + 1 + 2 + 3 ++4 ++5 ++6 +diff --git a/file2 b/file2 +deleted file mode 100644 +index 01e79c3..0000000 +--- a/file2 ++++ /dev/null +@@ -1,3 +0,0 @@ +-1 +-2 +-3 +-- +g-i-t--v-e-r-s-i-o-n + + +From 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 Mon Sep 17 00:00:00 2001 +From: A U Thor <author@example.com> +Date: Mon, 26 Jun 2006 00:02:00 +0000 +Subject: [DIFFERENT_PREFIX 2/2] Third + +--- + dir/sub | 2 ++ + file1 | 3 +++ + 2 files changed, 5 insertions(+), 0 deletions(-) + create mode 100644 file1 + +diff --git a/dir/sub b/dir/sub +index 8422d40..cead32e 100644 +--- a/dir/sub ++++ b/dir/sub +@@ -2,3 +2,5 @@ A + B + C + D ++E ++F +diff --git a/file1 b/file1 +new file mode 100644 +index 0000000..b1e6722 +--- /dev/null ++++ b/file1 +@@ -0,0 +1,3 @@ ++A ++B ++C +-- +g-i-t--v-e-r-s-i-o-n + +$ diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index 0a6fe53375..b2b7a8db85 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -88,4 +88,146 @@ test_expect_success 'replay did not screw up the log message' ' ' +test_expect_success 'extra headers' ' + + git config format.headers "To: R. E. Cipient <rcipient@example.com> +" && + git config --add format.headers "Cc: S. E. Cipient <scipient@example.com> +" && + git format-patch --stdout master..side > patch2 && + sed -e "/^$/q" patch2 > hdrs2 && + grep "^To: R. E. Cipient <rcipient@example.com>$" hdrs2 && + grep "^Cc: S. E. Cipient <scipient@example.com>$" hdrs2 + +' + +test_expect_success 'extra headers without newlines' ' + + git config --replace-all format.headers "To: R. E. Cipient <rcipient@example.com>" && + git config --add format.headers "Cc: S. E. Cipient <scipient@example.com>" && + git format-patch --stdout master..side >patch3 && + sed -e "/^$/q" patch3 > hdrs3 && + grep "^To: R. E. Cipient <rcipient@example.com>$" hdrs3 && + grep "^Cc: S. E. Cipient <scipient@example.com>$" hdrs3 + +' + +test_expect_success 'extra headers with multiple To:s' ' + + git config --replace-all format.headers "To: R. E. Cipient <rcipient@example.com>" && + git config --add format.headers "To: S. E. Cipient <scipient@example.com>" && + git format-patch --stdout master..side > patch4 && + sed -e "/^$/q" patch4 > hdrs4 && + grep "^To: R. E. Cipient <rcipient@example.com>,$" hdrs4 && + grep "^ *S. E. Cipient <scipient@example.com>$" hdrs4 +' + +test_expect_success 'additional command line cc' ' + + git config --replace-all format.headers "Cc: R. E. Cipient <rcipient@example.com>" && + git format-patch --cc="S. E. Cipient <scipient@example.com>" --stdout master..side | sed -e "/^$/q" >patch5 && + grep "^Cc: R. E. Cipient <rcipient@example.com>,$" patch5 && + grep "^ *S. E. Cipient <scipient@example.com>$" patch5 +' + +test_expect_success 'multiple files' ' + + rm -rf patches/ && + git checkout side && + git format-patch -o patches/ master && + ls patches/0001-Side-changes-1.patch patches/0002-Side-changes-2.patch patches/0003-Side-changes-3-with-n-backslash-n-in-it.patch +' + +test_expect_success 'thread' ' + + rm -rf patches/ && + git checkout side && + git format-patch --thread -o patches/ master && + FIRST_MID=$(grep "Message-Id:" patches/0001-* | sed "s/^[^<]*\(<[^>]*>\).*$/\1/") && + for i in patches/0002-* patches/0003-* + do + grep "References: $FIRST_MID" $i && + grep "In-Reply-To: $FIRST_MID" $i || break + done +' + +test_expect_success 'thread in-reply-to' ' + + rm -rf patches/ && + git checkout side && + git format-patch --in-reply-to="<test.message>" --thread -o patches/ master && + FIRST_MID="<test.message>" && + for i in patches/* + do + grep "References: $FIRST_MID" $i && + grep "In-Reply-To: $FIRST_MID" $i || break + done +' + +test_expect_success 'thread cover-letter' ' + + rm -rf patches/ && + git checkout side && + git format-patch --cover-letter --thread -o patches/ master && + FIRST_MID=$(grep "Message-Id:" patches/0000-* | sed "s/^[^<]*\(<[^>]*>\).*$/\1/") && + for i in patches/0001-* patches/0002-* patches/0003-* + do + grep "References: $FIRST_MID" $i && + grep "In-Reply-To: $FIRST_MID" $i || break + done +' + +test_expect_success 'thread cover-letter in-reply-to' ' + + rm -rf patches/ && + git checkout side && + git format-patch --cover-letter --in-reply-to="<test.message>" --thread -o patches/ master && + FIRST_MID="<test.message>" && + for i in patches/* + do + grep "References: $FIRST_MID" $i && + grep "In-Reply-To: $FIRST_MID" $i || break + done +' + +test_expect_success 'excessive subject' ' + + rm -rf patches/ && + git checkout side && + for i in 5 6 1 2 3 A 4 B C 7 8 9 10 D E F; do echo "$i"; done >>file && + git update-index file && + git commit -m "This is an excessively long subject line for a message due to the habit some projects have of not having a short, one-line subject at the start of the commit message, but rather sticking a whole paragraph right at the start as the only thing in the commit message. It had better not become the filename for the patch." && + git format-patch -o patches/ master..side && + ls patches/0004-This-is-an-excessively-long-subject-line-for-a-messa.patch +' + +test_expect_success 'cover-letter inherits diff options' ' + + git mv file foo && + git commit -m foo && + git format-patch --cover-letter -1 && + ! grep "file => foo .* 0 *$" 0000-cover-letter.patch && + git format-patch --cover-letter -1 -M && + grep "file => foo .* 0 *$" 0000-cover-letter.patch + +' + +cat > expect << EOF + This is an excessively long subject line for a message due to the + habit some projects have of not having a short, one-line subject at + the start of the commit message, but rather sticking a whole + paragraph right at the start as the only thing in the commit + message. It had better not become the filename for the patch. + foo + +EOF + +test_expect_success 'shortlog of cover-letter wraps overly-long onelines' ' + + git format-patch --cover-letter -2 && + sed -e "1,/A U Thor/d" -e "/^$/q" < 0000-cover-letter.patch > output && + git diff expect output + +' + test_done diff --git a/t/t4019-diff-wserror.sh b/t/t4019-diff-wserror.sh index 67e080bdbe..0d9cbb6261 100755 --- a/t/t4019-diff-wserror.sh +++ b/t/t4019-diff-wserror.sh @@ -12,6 +12,7 @@ test_expect_success setup ' echo " Eight SP indent" >>F && echo " HT and SP indent" >>F && echo "With trailing SP " >>F && + echo "Carriage ReturnQ" | tr Q "\015" >>F && echo "No problem" >>F ' @@ -27,6 +28,7 @@ test_expect_success default ' grep Eight normal >/dev/null && grep HT error >/dev/null && grep With error >/dev/null && + grep Return error >/dev/null && grep No normal >/dev/null ' @@ -41,6 +43,7 @@ test_expect_success 'without -trail' ' grep Eight normal >/dev/null && grep HT error >/dev/null && grep With normal >/dev/null && + grep Return normal >/dev/null && grep No normal >/dev/null ' @@ -56,6 +59,7 @@ test_expect_success 'without -trail (attribute)' ' grep Eight normal >/dev/null && grep HT error >/dev/null && grep With normal >/dev/null && + grep Return normal >/dev/null && grep No normal >/dev/null ' @@ -71,6 +75,7 @@ test_expect_success 'without -space' ' grep Eight normal >/dev/null && grep HT normal >/dev/null && grep With error >/dev/null && + grep Return error >/dev/null && grep No normal >/dev/null ' @@ -86,6 +91,7 @@ test_expect_success 'without -space (attribute)' ' grep Eight normal >/dev/null && grep HT normal >/dev/null && grep With error >/dev/null && + grep Return error >/dev/null && grep No normal >/dev/null ' @@ -101,6 +107,7 @@ test_expect_success 'with indent-non-tab only' ' grep Eight error >/dev/null && grep HT normal >/dev/null && grep With normal >/dev/null && + grep Return normal >/dev/null && grep No normal >/dev/null ' @@ -116,6 +123,39 @@ test_expect_success 'with indent-non-tab only (attribute)' ' grep Eight error >/dev/null && grep HT normal >/dev/null && grep With normal >/dev/null && + grep Return normal >/dev/null && + grep No normal >/dev/null + +' + +test_expect_success 'with cr-at-eol' ' + + rm -f .gitattributes + git config core.whitespace cr-at-eol + git diff --color >output + grep "$blue_grep" output >error + grep -v "$blue_grep" output >normal + + grep Eight normal >/dev/null && + grep HT error >/dev/null && + grep With error >/dev/null && + grep Return normal >/dev/null && + grep No normal >/dev/null + +' + +test_expect_success 'with cr-at-eol (attribute)' ' + + git config --unset core.whitespace + echo "F whitespace=trailing,cr-at-eol" >.gitattributes + git diff --color >output + grep "$blue_grep" output >error + grep -v "$blue_grep" output >normal + + grep Eight normal >/dev/null && + grep HT error >/dev/null && + grep With error >/dev/null && + grep Return normal >/dev/null && grep No normal >/dev/null ' diff --git a/t/t4020-diff-external.sh b/t/t4020-diff-external.sh index 888293361d..637b4e19d5 100755 --- a/t/t4020-diff-external.sh +++ b/t/t4020-diff-external.sh @@ -99,11 +99,12 @@ test_expect_success 'no diff with -diff' ' git diff | grep Binary ' -echo NULZbetweenZwords | tr Z '\000' > file +echo NULZbetweenZwords | perl -pe 'y/Z/\000/' > file test_expect_success 'force diff with "diff"' ' echo >.gitattributes "file diff" && - git diff | grep -a second + git diff >actual && + test_cmp ../t4020/diff.NUL actual ' test_done diff --git a/t/t4020/diff.NUL b/t/t4020/diff.NUL Binary files differnew file mode 100644 index 0000000000..db2f89090c --- /dev/null +++ b/t/t4020/diff.NUL diff --git a/t/t4022-diff-rewrite.sh b/t/t4022-diff-rewrite.sh index 6de4acbd44..bf996fc414 100755 --- a/t/t4022-diff-rewrite.sh +++ b/t/t4022-diff-rewrite.sh @@ -8,7 +8,10 @@ test_expect_success setup ' cat ../../COPYING >test && git add test && - tr 'a-zA-Z' 'n-za-mN-ZA-M' <../../COPYING >test + tr \ + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" \ + "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM" \ + <../../COPYING >test ' diff --git a/t/t4023-diff-rename-typechange.sh b/t/t4023-diff-rename-typechange.sh index 255604effd..4dbfc6e8b7 100755 --- a/t/t4023-diff-rename-typechange.sh +++ b/t/t4023-diff-rename-typechange.sh @@ -57,7 +57,7 @@ test_expect_success 'cross renames to be detected for regular files' ' echo "R100 foo bar" echo "R100 bar foo" } | sort >expect && - diff -u expect actual + test_cmp expect actual ' @@ -68,7 +68,7 @@ test_expect_success 'cross renames to be detected for typechange' ' echo "R100 foo bar" echo "R100 bar foo" } | sort >expect && - diff -u expect actual + test_cmp expect actual ' @@ -79,7 +79,7 @@ test_expect_success 'moves and renames' ' echo "R100 foo bar" echo "T100 foo" } | sort >expect && - diff -u expect actual + test_cmp expect actual ' diff --git a/t/t4024-diff-optimize-common.sh b/t/t4024-diff-optimize-common.sh index 3c66102f7a..c4d733f5db 100755 --- a/t/t4024-diff-optimize-common.sh +++ b/t/t4024-diff-optimize-common.sh @@ -150,7 +150,7 @@ test_expect_success 'diff -U0' ' do git diff -U0 file-?$n done | zc >actual && - diff -u expect actual + test_cmp expect actual ' diff --git a/t/t4025-hunk-header.sh b/t/t4025-hunk-header.sh index 9ba06b74ce..7a3dbc1ea2 100755 --- a/t/t4025-hunk-header.sh +++ b/t/t4025-hunk-header.sh @@ -37,7 +37,7 @@ test_expect_success 'hunk header truncation with an overly long line' ' echo " A $N$N$N$N$N$N$N$N$N2" echo " L $N$N$N$N$N$N$N$N$N1" ) >expected && - diff -u actual expected + test_cmp actual expected ' diff --git a/t/t4027-diff-submodule.sh b/t/t4027-diff-submodule.sh new file mode 100755 index 0000000000..1fd3fb74d7 --- /dev/null +++ b/t/t4027-diff-submodule.sh @@ -0,0 +1,53 @@ +#!/bin/sh + +test_description='difference in submodules' + +. ./test-lib.sh +. ../diff-lib.sh + +_z40=0000000000000000000000000000000000000000 +test_expect_success setup ' + test_tick && + test_create_repo sub && + ( + cd sub && + echo hello >world && + git add world && + git commit -m submodule + ) && + + test_tick && + echo frotz >nitfol && + git add nitfol sub && + git commit -m superproject && + + ( + cd sub && + echo goodbye >world && + git add world && + git commit -m "submodule #2" + ) && + + set x $( + cd sub && + git rev-list HEAD + ) && + echo ":160000 160000 $3 $_z40 M sub" >expect +' + +test_expect_success 'git diff --raw HEAD' ' + git diff --raw --abbrev=40 HEAD >actual && + test_cmp expect actual +' + +test_expect_success 'git diff-index --raw HEAD' ' + git diff-index --raw HEAD >actual.index && + test_cmp expect actual.index +' + +test_expect_success 'git diff-files --raw' ' + git diff-files --raw >actual.files && + test_cmp expect actual.files +' + +test_done diff --git a/t/t4103-apply-binary.sh b/t/t4103-apply-binary.sh index 74f06ec730..1b58233da6 100755 --- a/t/t4103-apply-binary.sh +++ b/t/t4103-apply-binary.sh @@ -24,10 +24,10 @@ git update-index --add --remove file1 file2 file4 git-commit -m 'Initial Version' 2>/dev/null git-checkout -b binary -tr 'x' '\000' <file1 >file3 +perl -pe 'y/x/\000/' <file1 >file3 cat file3 >file4 git add file2 -tr '\000' 'v' <file3 >file1 +perl -pe 'y/\000/v/' <file3 >file1 rm -f file2 git update-index --add --remove file1 file2 file3 file4 git-commit -m 'Second Version' @@ -46,21 +46,25 @@ test_expect_success 'stat binary diff (copy) -- should not fail.' \ 'git-checkout master git apply --stat --summary C.diff' -test_expect_failure 'check binary diff -- should fail.' \ - 'git-checkout master - git apply --check B.diff' +test_expect_success 'check binary diff -- should fail.' \ + 'git-checkout master && + ! git apply --check B.diff' -test_expect_failure 'check binary diff (copy) -- should fail.' \ - 'git-checkout master - git apply --check C.diff' +test_expect_success 'check binary diff (copy) -- should fail.' \ + 'git-checkout master && + ! git apply --check C.diff' -test_expect_failure 'check incomplete binary diff with replacement -- should fail.' \ - 'git-checkout master - git apply --check --allow-binary-replacement B.diff' +test_expect_success \ + 'check incomplete binary diff with replacement -- should fail.' ' + git-checkout master && + ! git apply --check --allow-binary-replacement B.diff +' -test_expect_failure 'check incomplete binary diff with replacement (copy) -- should fail.' \ - 'git-checkout master - git apply --check --allow-binary-replacement C.diff' +test_expect_success \ + 'check incomplete binary diff with replacement (copy) -- should fail.' ' + git-checkout master && + ! git apply --check --allow-binary-replacement C.diff +' test_expect_success 'check binary diff with replacement.' \ 'git-checkout master @@ -73,42 +77,42 @@ test_expect_success 'check binary diff with replacement (copy).' \ # Now we start applying them. do_reset () { - rm -f file? - git-reset --hard + rm -f file? && + git-reset --hard && git-checkout -f master } -test_expect_failure 'apply binary diff -- should fail.' \ - 'do_reset - git apply B.diff' +test_expect_success 'apply binary diff -- should fail.' \ + 'do_reset && + ! git apply B.diff' -test_expect_failure 'apply binary diff -- should fail.' \ - 'do_reset - git apply --index B.diff' +test_expect_success 'apply binary diff -- should fail.' \ + 'do_reset && + ! git apply --index B.diff' -test_expect_failure 'apply binary diff (copy) -- should fail.' \ - 'do_reset - git apply C.diff' +test_expect_success 'apply binary diff (copy) -- should fail.' \ + 'do_reset && + ! git apply C.diff' -test_expect_failure 'apply binary diff (copy) -- should fail.' \ - 'do_reset - git apply --index C.diff' +test_expect_success 'apply binary diff (copy) -- should fail.' \ + 'do_reset && + ! git apply --index C.diff' test_expect_success 'apply binary diff without replacement.' \ - 'do_reset + 'do_reset && git apply BF.diff' test_expect_success 'apply binary diff without replacement (copy).' \ - 'do_reset + 'do_reset && git apply CF.diff' test_expect_success 'apply binary diff.' \ - 'do_reset + 'do_reset && git apply --allow-binary-replacement --index BF.diff && test -z "$(git diff --name-status binary)"' test_expect_success 'apply binary diff (copy).' \ - 'do_reset + 'do_reset && git apply --allow-binary-replacement --index CF.diff && test -z "$(git diff --name-status binary)"' diff --git a/t/t4105-apply-fuzz.sh b/t/t4105-apply-fuzz.sh new file mode 100755 index 0000000000..3266e39400 --- /dev/null +++ b/t/t4105-apply-fuzz.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +test_description='apply with fuzz and offset' + +. ./test-lib.sh + +dotest () { + name="$1" && shift && + test_expect_success "$name" " + git checkout-index -f -q -u file && + git apply $* && + test_cmp expect file + " +} + +test_expect_success setup ' + + for i in 1 2 3 4 5 6 7 8 9 10 11 12 + do + echo $i + done >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 && + cat file >expect && + git diff >O0.diff && + + sed -e "s/@@ -5,6 +5,11 @@/@@ -2,6 +2,11 @@/" >O1.diff O0.diff && + sed -e "s/@@ -5,6 +5,11 @@/@@ -7,6 +7,11 @@/" >O2.diff O0.diff && + sed -e "s/@@ -5,6 +5,11 @@/@@ -19,6 +19,11 @@/" >O3.diff O0.diff && + + sed -e "s/^ 5/ S/" >F0.diff O0.diff && + sed -e "s/^ 5/ S/" >F1.diff O1.diff && + sed -e "s/^ 5/ S/" >F2.diff O2.diff && + sed -e "s/^ 5/ S/" >F3.diff O3.diff + +' + +dotest 'unmodified patch' O0.diff + +dotest 'minus offset' O1.diff + +dotest 'plus offset' O2.diff + +dotest 'big offset' O3.diff + +dotest 'fuzz with no offset' -C2 F0.diff + +dotest 'fuzz with minus offset' -C2 F1.diff + +dotest 'fuzz with plus offset' -C2 F2.diff + +dotest 'fuzz with big offset' -C2 F3.diff + +test_done diff --git a/t/t4113-apply-ending.sh b/t/t4113-apply-ending.sh index 1c6bec044a..d741039882 100755 --- a/t/t4113-apply-ending.sh +++ b/t/t4113-apply-ending.sh @@ -29,8 +29,8 @@ test_expect_success setup \ # test -test_expect_failure 'apply at the end' \ - 'git apply --index test-patch' +test_expect_success 'apply at the end' \ + '! git apply --index test-patch' cat >test-patch <<\EOF diff a/file b/file @@ -47,7 +47,7 @@ b c' git update-index file -test_expect_failure 'apply at the beginning' \ - 'git apply --index test-patch' +test_expect_success 'apply at the beginning' \ + '! git apply --index test-patch' test_done diff --git a/t/t4116-apply-reverse.sh b/t/t4116-apply-reverse.sh index b1d35ab04d..c3f4579007 100755 --- a/t/t4116-apply-reverse.sh +++ b/t/t4116-apply-reverse.sh @@ -12,14 +12,14 @@ test_description='git apply in reverse 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 && - tr "ijk" '\''\000\001\002'\'' <file1 >file2 && + 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 && - tr "mon" '\''\000\001\002'\'' <file1 >file2 && + perl -pe "y/mon/\\000\\001\\002/" <file1 >file2 && git commit -a -m second && git tag second && diff --git a/t/t4125-apply-ws-fuzz.sh b/t/t4125-apply-ws-fuzz.sh new file mode 100755 index 0000000000..3b471b641b --- /dev/null +++ b/t/t4125-apply-ws-fuzz.sh @@ -0,0 +1,103 @@ +#!/bin/sh + +test_description='applying patch that has broken whitespaces in context' + +. ./test-lib.sh + +test_expect_success setup ' + + >file && + 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 && + + # patch-0 creates a whitespace broken file + cat file-0 >file && + git diff >patch-0 && + git add file && + + # file-1 is still full of whitespace breakages, + # but has one line updated, without fixing any + # whitespaces. + # patch-1 records that change. + sed -e "s/d/D/" file-0 >file-1 && + cat file-1 >file && + git diff >patch-1 && + + # patch-all is the effect of both patch-0 and patch-1 + >file && + git add file && + cat file-1 >file && + git diff >patch-all && + + # patch-2 is the same as patch-1 but is based + # on a version that already has whitespace fixed, + # and does not introduce whitespace breakages. + sed -e "s/ $//" patch-1 >patch-2 && + + # If all whitespace breakages are fixed the contents + # should look like file-fixed + sed -e "s/ $//" file-1 >file-fixed + +' + +test_expect_success nofix ' + + >file && + git add file && + + # Baseline. Applying without fixing any whitespace + # breakages. + git apply --whitespace=nowarn patch-0 && + git apply --whitespace=nowarn patch-1 && + + # The result should obviously match. + test_cmp file-1 file +' + +test_expect_success 'withfix (forward)' ' + + >file && + git add file && + + # The first application will munge the context lines + # the second patch depends on. We should be able to + # adjust and still apply. + git apply --whitespace=fix patch-0 && + git apply --whitespace=fix patch-1 && + + test_cmp file-fixed file +' + +test_expect_success 'withfix (backward)' ' + + >file && + git add file && + + # Now we have a whitespace breakages on our side. + git apply --whitespace=nowarn patch-0 && + + # And somebody sends in a patch based on image + # with whitespace already fixed. + git apply --whitespace=fix patch-2 && + + # The result should accept the whitespace fixed + # postimage. But the line with "h" is beyond context + # horizon and left unfixed. + + sed -e /h/d file-fixed >fixed-head && + sed -e /h/d file >file-head && + test_cmp fixed-head file-head && + + sed -n -e /h/p file-fixed >fixed-tail && + sed -n -e /h/p file >file-tail && + + ! test_cmp fixed-tail file-tail + +' + +test_done diff --git a/t/t4150-am-subdir.sh b/t/t4150-am-subdir.sh new file mode 100755 index 0000000000..52069b469b --- /dev/null +++ b/t/t4150-am-subdir.sh @@ -0,0 +1,72 @@ +#!/bin/sh + +test_description='git am running from a subdirectory' + +. ./test-lib.sh + +test_expect_success setup ' + echo hello >world && + git add world && + test_tick && + git commit -m initial && + git tag initial && + echo goodbye >world && + git add world && + test_tick && + git commit -m second && + git format-patch --stdout HEAD^ >patchfile && + : >expect +' + +test_expect_success 'am regularly from stdin' ' + git checkout initial && + git am <patchfile && + git diff master >actual && + test_cmp expect actual +' + +test_expect_success 'am regularly from file' ' + git checkout initial && + git am patchfile && + git diff master >actual && + test_cmp expect actual +' + +test_expect_success 'am regularly from stdin in subdirectory' ' + rm -fr subdir && + git checkout initial && + ( + mkdir -p subdir && + cd subdir && + git am <../patchfile + ) && + git diff master>actual && + test_cmp expect actual +' + +test_expect_success 'am regularly from file in subdirectory' ' + rm -fr subdir && + git checkout initial && + ( + mkdir -p subdir && + cd subdir && + git am ../patchfile + ) && + git diff master >actual && + test_cmp expect actual +' + +test_expect_success 'am regularly from file in subdirectory with full path' ' + rm -fr subdir && + git checkout initial && + P=$(pwd) && + ( + mkdir -p subdir && + cd subdir && + git am "$P/patchfile" + ) && + git diff master >actual && + test_cmp expect actual +' + +test_done diff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh index eeff3c9c07..3cbfee704e 100755 --- a/t/t4200-rerere.sh +++ b/t/t4200-rerere.sh @@ -129,7 +129,7 @@ test_expect_success 'rerere kicked in' "! grep ======= a1" test_expect_success 'rerere prefers first change' 'git diff a1 expect' rm $rr/postimage -echo "$sha1 a1" | tr '\012' '\000' > .git/rr-cache/MERGE_RR +echo "$sha1 a1" | perl -pe 'y/\012/\000/' > .git/rr-cache/MERGE_RR test_expect_success 'rerere clear' 'git rerere clear' diff --git a/t/t4201-shortlog.sh b/t/t4201-shortlog.sh index 6d12efb74d..405b971191 100755 --- a/t/t4201-shortlog.sh +++ b/t/t4201-shortlog.sh @@ -45,6 +45,11 @@ A U Thor (5): EOF -test_expect_success 'shortlog wrapping' 'diff -u expect out' +test_expect_success 'shortlog wrapping' 'test_cmp expect out' + +git log HEAD > log +GIT_DIR=non-existing git shortlog -w < log > out + +test_expect_success 'shortlog from non-git directory' 'test_cmp expect out' test_done diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh index 6e594bf1e2..c955fe44f5 100755 --- a/t/t5300-pack-object.sh +++ b/t/t5300-pack-object.sh @@ -15,7 +15,7 @@ test_expect_success \ 'rm -f .git/index* for i in a b c do - dd if=/dev/zero bs=4k count=1 | tr "\\000" $i >$i && + dd if=/dev/zero bs=4k count=1 | perl -pe "y/\\000/$i/" >$i && git update-index --add $i || return 1 done && cat c >d && echo foo >>d && git update-index --add d && @@ -264,8 +264,14 @@ test_expect_success \ cp -f .git/objects/9d/235ed07cd19811a6ceb342de82f190e49c9f68 \ .git/objects/c8/2de19312b6c3695c0c18f70709a6c535682a67' -test_expect_failure \ +test_expect_success \ 'make sure index-pack detects the SHA1 collision' \ - 'git-index-pack -o bad.idx test-3.pack' + '! git-index-pack -o bad.idx test-3.pack' + +test_expect_success \ + 'honor pack.packSizeLimit' \ + 'git config pack.packSizeLimit 200 && + packname_4=$(git pack-objects test-4 <obj-list) && + test 3 = $(ls test-4-*.pack | wc -l)' test_done diff --git a/t/t5302-pack-index.sh b/t/t5302-pack-index.sh index 2a2878b572..b88b5bbd02 100755 --- a/t/t5302-pack-index.sh +++ b/t/t5302-pack-index.sh @@ -42,9 +42,9 @@ test_expect_success \ 'both packs should be identical' \ 'cmp "test-1-${pack1}.pack" "test-2-${pack2}.pack"' -test_expect_failure \ +test_expect_success \ 'index v1 and index v2 should be different' \ - 'cmp "test-1-${pack1}.idx" "test-2-${pack2}.idx"' + '! cmp "test-1-${pack1}.idx" "test-2-${pack2}.idx"' test_expect_success \ 'index-pack with index version 1' \ @@ -78,9 +78,9 @@ test_expect_success \ 'git verify-pack -v "test-3-${pack3}.pack"' test "$have_64bits" && -test_expect_failure \ +test_expect_success \ '64-bit offsets: should be different from previous index v2 results' \ - 'cmp "test-2-${pack2}.idx" "test-3-${pack3}.idx"' + '! cmp "test-2-${pack2}.idx" "test-3-${pack3}.idx"' test "$have_64bits" && test_expect_success \ @@ -103,7 +103,7 @@ test_expect_success \ test_expect_success \ '[index v1] 2) create a stealth corruption in a delta base reference' \ '# this test assumes a delta smaller than 16 bytes at the end of the pack - git show-index <1.idx | sort -n | tail -n 1 | ( + git show-index <1.idx | sort -n | sed -ne \$p | ( read delta_offs delta_sha1 && git cat-file blob "$delta_sha1" > blob_1 && chmod +w ".git/objects/pack/pack-${pack1}.pack" && @@ -112,22 +112,22 @@ test_expect_success \ bs=1 count=20 conv=notrunc && git cat-file blob "$delta_sha1" > blob_2 )' -test_expect_failure \ +test_expect_success \ '[index v1] 3) corrupted delta happily returned wrong data' \ - 'cmp blob_1 blob_2' + '! cmp blob_1 blob_2' -test_expect_failure \ +test_expect_success \ '[index v1] 4) confirm that the pack is actually corrupted' \ - 'git fsck --full $commit' + '! git fsck --full $commit' test_expect_success \ '[index v1] 5) pack-objects happily reuses corrupted data' \ 'pack4=$(git pack-objects test-4 <obj-list) && test -f "test-4-${pack1}.pack"' -test_expect_failure \ +test_expect_success \ '[index v1] 6) newly created pack is BAD !' \ - 'git verify-pack -v "test-4-${pack1}.pack"' + '! git verify-pack -v "test-4-${pack1}.pack"' test_expect_success \ '[index v2] 1) stream pack to repository' \ @@ -141,7 +141,7 @@ test_expect_success \ test_expect_success \ '[index v2] 2) create a stealth corruption in a delta base reference' \ '# this test assumes a delta smaller than 16 bytes at the end of the pack - git show-index <1.idx | sort -n | tail -n 1 | ( + git show-index <1.idx | sort -n | sed -ne \$p | ( read delta_offs delta_sha1 delta_crc && git cat-file blob "$delta_sha1" > blob_3 && chmod +w ".git/objects/pack/pack-${pack1}.pack" && @@ -150,16 +150,16 @@ test_expect_success \ bs=1 count=20 conv=notrunc && git cat-file blob "$delta_sha1" > blob_4 )' -test_expect_failure \ +test_expect_success \ '[index v2] 3) corrupted delta happily returned wrong data' \ - 'cmp blob_3 blob_4' + '! cmp blob_3 blob_4' -test_expect_failure \ +test_expect_success \ '[index v2] 4) confirm that the pack is actually corrupted' \ - 'git fsck --full $commit' + '! git fsck --full $commit' -test_expect_failure \ +test_expect_success \ '[index v2] 5) pack-objects refuses to reuse corrupted data' \ - 'git pack-objects test-5 <obj-list' + '! git pack-objects test-5 <obj-list' test_done diff --git a/t/t5303-hash-object.sh b/t/t5303-hash-object.sh new file mode 100755 index 0000000000..543c0784bd --- /dev/null +++ b/t/t5303-hash-object.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +test_description=git-hash-object + +. ./test-lib.sh + +test_expect_success \ + 'git hash-object -w --stdin saves the object' \ + 'obname=$(echo foo | git hash-object -w --stdin) && + obpath=$(echo $obname | sed -e "s/\(..\)/\1\//") && + test -r .git/objects/"$obpath" && + rm -f .git/objects/"$obpath"' + +test_expect_success \ + 'git hash-object --stdin -w saves the object' \ + 'obname=$(echo foo | git hash-object --stdin -w) && + obpath=$(echo $obname | sed -e "s/\(..\)/\1\//") && + test -r .git/objects/"$obpath" && + rm -f .git/objects/"$obpath"' + +test_expect_success \ + 'git hash-object --stdin file1 <file0 first operates on file0, then file1' \ + 'echo foo > file1 && + obname0=$(echo bar | git hash-object --stdin) && + obname1=$(git hash-object file1) && + obname0new=$(echo bar | git hash-object --stdin file1 | sed -n -e 1p) && + obname1new=$(echo bar | git hash-object --stdin file1 | sed -n -e 2p) && + test "$obname0" = "$obname0new" && + test "$obname1" = "$obname1new"' + +test_expect_success \ + 'git hash-object refuses multiple --stdin arguments' \ + '! git hash-object --stdin --stdin < file1' + +test_done diff --git a/t/t5304-prune.sh b/t/t5304-prune.sh index 6560af756e..47090c4cf5 100644 --- a/t/t5304-prune.sh +++ b/t/t5304-prune.sh @@ -29,4 +29,53 @@ test_expect_success 'prune stale packs' ' ' +test_expect_success 'prune --expire' ' + + before=$(git count-objects | sed "s/ .*//") && + BLOB=$(echo aleph | git hash-object -w --stdin) && + BLOB_FILE=.git/objects/$(echo $BLOB | sed "s/^../&\//") && + test $((1 + $before)) = $(git count-objects | sed "s/ .*//") && + test -f $BLOB_FILE && + git prune --expire=1.hour.ago && + test $((1 + $before)) = $(git count-objects | sed "s/ .*//") && + test -f $BLOB_FILE && + test-chmtime -86500 $BLOB_FILE && + git prune --expire 1.day && + test $before = $(git count-objects | sed "s/ .*//") && + ! test -f $BLOB_FILE + +' + +test_expect_success 'gc: implicit prune --expire' ' + + before=$(git count-objects | sed "s/ .*//") && + BLOB=$(echo aleph_0 | git hash-object -w --stdin) && + BLOB_FILE=.git/objects/$(echo $BLOB | sed "s/^../&\//") && + test $((1 + $before)) = $(git count-objects | sed "s/ .*//") && + test -f $BLOB_FILE && + test-chmtime -$((86400*14-30)) $BLOB_FILE && + git gc && + test $((1 + $before)) = $(git count-objects | sed "s/ .*//") && + test -f $BLOB_FILE && + test-chmtime -$((86400*14+1)) $BLOB_FILE && + git gc && + test $before = $(git count-objects | sed "s/ .*//") && + ! test -f $BLOB_FILE + +' + +test_expect_success 'gc: refuse to start with invalid gc.pruneExpire' ' + + git config gc.pruneExpire invalid && + test_must_fail git gc + +' + +test_expect_success 'gc: start with ok gc.pruneExpire' ' + + git config gc.pruneExpire 2.days.ago && + git gc + +' + test_done diff --git a/t/t5305-include-tag.sh b/t/t5305-include-tag.sh new file mode 100755 index 0000000000..0db27547ac --- /dev/null +++ b/t/t5305-include-tag.sh @@ -0,0 +1,84 @@ +#!/bin/sh + +test_description='git-pack-object --include-tag' +. ./test-lib.sh + +TRASH=`pwd` + +test_expect_success setup ' + echo c >d && + git update-index --add d && + tree=`git write-tree` && + commit=`git commit-tree $tree </dev/null` && + echo "object $commit" >sig && + echo "type commit" >>sig && + echo "tag mytag" >>sig && + echo "tagger $(git var GIT_COMMITTER_IDENT)" >>sig && + echo >>sig && + echo "our test tag" >>sig && + tag=`git mktag <sig` && + rm d sig && + git update-ref refs/tags/mytag $tag && { + echo $tree && + echo $commit && + git ls-tree $tree | sed -e "s/.* \\([0-9a-f]*\\) .*/\\1/" + } >obj-list +' + +rm -rf clone.git +test_expect_success 'pack without --include-tag' ' + packname_1=$(git pack-objects \ + --window=0 \ + test-1 <obj-list) +' + +test_expect_success 'unpack objects' ' + ( + GIT_DIR=clone.git && + export GIT_DIR && + git init && + git unpack-objects -n <test-1-${packname_1}.pack && + git unpack-objects <test-1-${packname_1}.pack + ) +' + +test_expect_success 'check unpacked result (have commit, no tag)' ' + git rev-list --objects $commit >list.expect && + ( + GIT_DIR=clone.git && + export GIT_DIR && + test_must_fail git cat-file -e $tag && + git rev-list --objects $commit + ) >list.actual && + git diff list.expect list.actual +' + +rm -rf clone.git +test_expect_success 'pack with --include-tag' ' + packname_1=$(git pack-objects \ + --window=0 \ + --include-tag \ + test-2 <obj-list) +' + +test_expect_success 'unpack objects' ' + ( + GIT_DIR=clone.git && + export GIT_DIR && + git init && + git unpack-objects -n <test-2-${packname_1}.pack && + git unpack-objects <test-2-${packname_1}.pack + ) +' + +test_expect_success 'check unpacked result (have commit, have tag)' ' + git rev-list --objects mytag >list.expect && + ( + GIT_DIR=clone.git && + export GIT_DIR && + git rev-list --objects $tag + ) >list.actual && + git diff list.expect list.actual +' + +test_done diff --git a/t/t5400-send-pack.sh b/t/t5400-send-pack.sh index 2d0c07fd6a..2b6b6e3f71 100755 --- a/t/t5400-send-pack.sh +++ b/t/t5400-send-pack.sh @@ -120,7 +120,7 @@ test_expect_success \ cd .. && git-clone parent child && cd child && git-push --all && cd ../parent && - git-branch -a >branches && ! grep -q origin/master branches + git-branch -a >branches && ! grep origin/master branches ' rewound_push_setup() { diff --git a/t/t5401-update-hooks.sh b/t/t5401-update-hooks.sh index 9734fc542f..9a12024241 100755 --- a/t/t5401-update-hooks.sh +++ b/t/t5401-update-hooks.sh @@ -60,8 +60,8 @@ echo STDERR post-update >&2 EOF chmod u+x victim/.git/hooks/post-update -test_expect_failure push ' - git-send-pack --force ./victim/.git master tofail >send.out 2>send.err +test_expect_success push ' + ! git-send-pack --force ./victim/.git master tofail >send.out 2>send.err ' test_expect_success 'updated as expected' ' @@ -112,8 +112,8 @@ test_expect_success 'all *-receive hook args are empty' ' ! test -s victim/.git/post-receive.args ' -test_expect_failure 'send-pack produced no output' ' - test -s send.out +test_expect_success 'send-pack produced no output' ' + ! test -s send.out ' cat <<EOF >expect diff --git a/t/t5402-post-merge-hook.sh b/t/t5402-post-merge-hook.sh index 1c4b0b32ab..1394047a8d 100755 --- a/t/t5402-post-merge-hook.sh +++ b/t/t5402-post-merge-hook.sh @@ -30,9 +30,9 @@ EOF chmod u+x clone${clone}/.git/hooks/post-merge done -test_expect_failure 'post-merge does not run for up-to-date ' ' +test_expect_success 'post-merge does not run for up-to-date ' ' GIT_DIR=clone1/.git git merge $commit0 && - test -e clone1/.git/post-merge.args + ! test -f clone1/.git/post-merge.args ' test_expect_success 'post-merge runs as expected ' ' diff --git a/t/t5500-fetch-pack.sh b/t/t5500-fetch-pack.sh index 7b6798d8b5..788b4a5aae 100755 --- a/t/t5500-fetch-pack.sh +++ b/t/t5500-fetch-pack.sh @@ -176,7 +176,7 @@ test_expect_success "deepening fetch in shallow repo" \ test_expect_success "clone shallow object count" \ "test \"count: 18\" = \"$(grep count count.shallow)\"" -test_expect_failure "pull in shallow repo with missing merge base" \ - "(cd shallow; git pull --depth 4 .. A)" +test_expect_success "pull in shallow repo with missing merge base" \ + "(cd shallow && ! git pull --depth 4 .. A)" test_done diff --git a/t/t5503-tagfollow.sh b/t/t5503-tagfollow.sh new file mode 100755 index 0000000000..86e5b9bc26 --- /dev/null +++ b/t/t5503-tagfollow.sh @@ -0,0 +1,150 @@ +#!/bin/sh + +test_description='test automatic tag following' + +. ./test-lib.sh + +# End state of the repository: +# +# T - tag1 S - tag2 +# / / +# L - A ------ O ------ B +# \ \ \ +# \ C - origin/cat \ +# origin/master master + +test_expect_success setup ' + test_tick && + echo ichi >file && + git add file && + git commit -m L && + L=$(git rev-parse --verify HEAD) && + + ( + mkdir cloned && + cd cloned && + git init-db && + git remote add -f origin .. + ) && + + test_tick && + echo A >file && + git add file && + git commit -m A && + A=$(git rev-parse --verify HEAD) +' + +U=UPLOAD_LOG + +cat - <<EOF >expect +#S +want $A +#E +EOF +test_expect_success 'fetch A (new commit : 1 connection)' ' + rm -f $U + ( + cd cloned && + GIT_DEBUG_SEND_PACK=3 git fetch 3>../$U && + test $A = $(git rev-parse --verify origin/master) + ) && + test -s $U && + cut -d" " -f1,2 $U >actual && + git diff expect actual +' + +test_expect_success "create tag T on A, create C on branch cat" ' + git tag -a -m tag1 tag1 $A && + T=$(git rev-parse --verify tag1) && + + git checkout -b cat && + echo C >file && + git add file && + git commit -m C && + C=$(git rev-parse --verify HEAD) && + git checkout master +' + +cat - <<EOF >expect +#S +want $C +want $T +#E +EOF +test_expect_success 'fetch C, T (new branch, tag : 1 connection)' ' + rm -f $U + ( + cd cloned && + GIT_DEBUG_SEND_PACK=3 git fetch 3>../$U && + test $C = $(git rev-parse --verify origin/cat) && + test $T = $(git rev-parse --verify tag1) && + test $A = $(git rev-parse --verify tag1^0) + ) && + test -s $U && + cut -d" " -f1,2 $U >actual && + git diff expect actual +' + +test_expect_success "create commits O, B, tag S on B" ' + test_tick && + echo O >file && + git add file && + git commit -m O && + + test_tick && + echo B >file && + git add file && + git commit -m B && + B=$(git rev-parse --verify HEAD) && + + git tag -a -m tag2 tag2 $B && + S=$(git rev-parse --verify tag2) +' + +cat - <<EOF >expect +#S +want $B +want $S +#E +EOF +test_expect_success 'fetch B, S (commit and tag : 1 connection)' ' + rm -f $U + ( + cd cloned && + GIT_DEBUG_SEND_PACK=3 git fetch 3>../$U && + test $B = $(git rev-parse --verify origin/master) && + test $B = $(git rev-parse --verify tag2^0) && + test $S = $(git rev-parse --verify tag2) + ) && + test -s $U && + cut -d" " -f1,2 $U >actual && + git diff expect actual +' + +cat - <<EOF >expect +#S +want $B +want $S +#E +EOF +test_expect_success 'new clone fetch master and tags' ' + git branch -D cat + rm -f $U + ( + mkdir clone2 && + cd clone2 && + git init && + git remote add origin .. && + GIT_DEBUG_SEND_PACK=3 git fetch 3>../$U && + test $B = $(git rev-parse --verify origin/master) && + test $S = $(git rev-parse --verify tag2) && + test $B = $(git rev-parse --verify tag2^0) && + test $T = $(git rev-parse --verify tag1) && + test $A = $(git rev-parse --verify tag1^0) + ) && + test -s $U && + cut -d" " -f1,2 $U >actual && + git diff expect actual +' + +test_done diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index 4fc62f550c..ecfc999aaa 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -10,10 +10,12 @@ setup_repository () { git init && >file && git add file && + test_tick && git commit -m "Initial" && git checkout -b side && >elif && git add elif && + test_tick && git commit -m "Second" && git checkout master ) @@ -22,7 +24,7 @@ setup_repository () { tokens_match () { echo "$1" | tr ' ' '\012' | sort | sed -e '/^$/d' >expect && echo "$2" | tr ' ' '\012' | sort | sed -e '/^$/d' >actual && - diff -u expect actual + test_cmp expect actual } check_remote_track () { @@ -71,13 +73,14 @@ test_expect_success 'add another remote' ' sed -e "/^refs\/remotes\/origin\//d" \ -e "/^refs\/remotes\/second\//d" >actual && >expect && - diff -u expect actual + test_cmp expect actual ) ' test_expect_success 'remove remote' ' ( cd test && + git symbolic-ref refs/remotes/second/HEAD refs/remotes/second/master && git remote rm second ) ' @@ -90,8 +93,148 @@ test_expect_success 'remove remote' ' git for-each-ref "--format=%(refname)" refs/remotes | sed -e "/^refs\/remotes\/origin\//d" >actual && >expect && - diff -u expect actual + test_cmp expect actual ) ' +cat > test/expect << EOF +* remote origin + URL: $(pwd)/one/.git + Remote branch merged with 'git pull' while on branch master + master + New remote branch (next fetch will store in remotes/origin) + master + Tracked remote branches + side master +EOF + +test_expect_success 'show' ' + (cd test && + git config --add remote.origin.fetch \ + refs/heads/master:refs/heads/upstream && + git fetch && + git branch -d -r origin/master && + (cd ../one && + echo 1 > file && + test_tick && + git commit -m update file) && + git remote show origin > output && + git diff expect output) +' + +test_expect_success 'prune' ' + (cd one && + git branch -m side side2) && + (cd test && + git fetch origin && + git remote prune origin && + git rev-parse refs/remotes/origin/side2 && + ! git rev-parse refs/remotes/origin/side) +' + +test_expect_success 'add --mirror && prune' ' + (mkdir mirror && + cd mirror && + git init && + git remote add --mirror -f origin ../one) && + (cd one && + git branch -m side2 side) && + (cd mirror && + git rev-parse --verify refs/heads/side2 && + ! git rev-parse --verify refs/heads/side && + git fetch origin && + git remote prune origin && + ! git rev-parse --verify refs/heads/side2 && + git rev-parse --verify refs/heads/side) +' + +cat > one/expect << EOF + apis/master + apis/side + drosophila/another + drosophila/master + drosophila/side +EOF + +test_expect_success 'update' ' + + (cd one && + git remote add drosophila ../two && + git remote add apis ../mirror && + git remote update && + git branch -r > output && + git diff expect output) + +' + +cat > one/expect << EOF + drosophila/another + drosophila/master + drosophila/side + manduca/master + manduca/side + megaloprepus/master + megaloprepus/side +EOF + +test_expect_success 'update with arguments' ' + + (cd one && + for b in $(git branch -r) + do + git branch -r -d $b || break + done && + git remote add manduca ../mirror && + git remote add megaloprepus ../mirror && + git config remotes.phobaeticus "drosophila megaloprepus" && + git config remotes.titanus manduca && + git remote update phobaeticus titanus && + git branch -r > output && + git diff expect output) + +' + +cat > one/expect << EOF + apis/master + apis/side + manduca/master + manduca/side + megaloprepus/master + megaloprepus/side +EOF + +test_expect_success 'update default' ' + + (cd one && + for b in $(git branch -r) + do + git branch -r -d $b || break + done && + git config remote.drosophila.skipDefaultUpdate true && + git remote update default && + git branch -r > output && + git diff expect output) + +' + +cat > one/expect << EOF + drosophila/another + drosophila/master + drosophila/side +EOF + +test_expect_success 'update default (overridden, with funny whitespace)' ' + + (cd one && + for b in $(git branch -r) + do + git branch -r -d $b || break + done && + git config remotes.default "$(printf "\t drosophila \n")" && + git remote update default && + git branch -r > output && + git diff expect output) + +' + test_done diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh index 02882c1e4b..6946557c67 100755 --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@ -95,7 +95,7 @@ test_expect_success 'fetch following tags' ' ' -test_expect_failure 'fetch must not resolve short tag name' ' +test_expect_success 'fetch must not resolve short tag name' ' cd "$D" && @@ -103,11 +103,11 @@ test_expect_failure 'fetch must not resolve short tag name' ' cd five && git init && - git fetch .. anno:five + ! git fetch .. anno:five ' -test_expect_failure 'fetch must not resolve short remote name' ' +test_expect_success 'fetch must not resolve short remote name' ' cd "$D" && git-update-ref refs/remotes/six/HEAD HEAD @@ -116,7 +116,7 @@ test_expect_failure 'fetch must not resolve short remote name' ' cd six && git init && - git fetch .. six:six + ! git fetch .. six:six ' @@ -139,10 +139,10 @@ test_expect_success 'create bundle 2' ' git bundle create bundle2 master~2..master ' -test_expect_failure 'unbundle 1' ' +test_expect_success 'unbundle 1' ' cd "$D/bundle" && git checkout -b some-branch && - git fetch "$D/bundle1" master:master + ! git fetch "$D/bundle1" master:master ' test_expect_success 'bundle 1 has only 3 files ' ' @@ -249,7 +249,7 @@ test_expect_success 'bundle should record HEAD correctly' ' do echo "$(git rev-parse --verify $h) $h" done >expect && - diff -u expect actual + test_cmp expect actual ' diff --git a/t/t5512-ls-remote.sh b/t/t5512-ls-remote.sh index 6ec5f7c48b..c0dc94909b 100755 --- a/t/t5512-ls-remote.sh +++ b/t/t5512-ls-remote.sh @@ -24,28 +24,28 @@ test_expect_success setup ' test_expect_success 'ls-remote --tags .git' ' git ls-remote --tags .git >actual && - diff -u expected.tag actual + test_cmp expected.tag actual ' test_expect_success 'ls-remote .git' ' git ls-remote .git >actual && - diff -u expected.all actual + test_cmp expected.all actual ' test_expect_success 'ls-remote --tags self' ' git ls-remote --tags self >actual && - diff -u expected.tag actual + test_cmp expected.tag actual ' test_expect_success 'ls-remote self' ' git ls-remote self >actual && - diff -u expected.all actual + test_cmp expected.all actual ' diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index 9d2dc33cbd..793ffc6600 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -100,6 +100,23 @@ test_expect_success 'fetch with wildcard' ' ) ' +test_expect_success 'fetch with insteadOf' ' + mk_empty && + ( + TRASH=$(pwd) && + cd testrepo && + git config url./$TRASH/.insteadOf trash/ + git config remote.up.url trash/. && + git config remote.up.fetch "refs/heads/*:refs/remotes/origin/*" && + git fetch up && + + r=$(git show-ref -s --verify refs/remotes/origin/master) && + test "z$r" = "z$the_commit" && + + test 1 = $(git for-each-ref refs/remotes/origin | wc -l) + ) +' + test_expect_success 'push without wildcard' ' mk_empty && @@ -126,6 +143,20 @@ test_expect_success 'push with wildcard' ' ) ' +test_expect_success 'push with insteadOf' ' + mk_empty && + TRASH=$(pwd) && + git config url./$TRASH/.insteadOf trash/ && + git push trash/testrepo refs/heads/master:refs/remotes/origin/master && + ( + cd testrepo && + r=$(git show-ref -s --verify refs/remotes/origin/master) && + test "z$r" = "z$the_commit" && + + test 1 = $(git for-each-ref refs/remotes/origin | wc -l) + ) +' + test_expect_success 'push with matching heads' ' mk_test heads/master && @@ -271,6 +302,49 @@ test_expect_success 'push with HEAD nonexisting at remote' ' check_push_result $the_commit heads/local ' +test_expect_success 'push with +HEAD' ' + + mk_test heads/master && + git checkout master && + git branch -D local && + git checkout -b local && + git push testrepo master local && + check_push_result $the_commit heads/master && + check_push_result $the_commit heads/local && + + # Without force rewinding should fail + git reset --hard HEAD^ && + ! git push testrepo HEAD && + check_push_result $the_commit heads/local && + + # With force rewinding should succeed + git push testrepo +HEAD && + check_push_result $the_first_commit heads/local + +' + +test_expect_success 'push with config remote.*.push = HEAD' ' + + mk_test heads/local && + git checkout master && + git branch -f local $the_commit && + ( + cd testrepo && + git checkout local && + git reset --hard $the_first_commit + ) && + git config remote.there.url testrepo && + git config remote.there.push HEAD && + git config branch.master.remote there && + git push && + check_push_result $the_commit heads/master && + check_push_result $the_first_commit heads/local +' + +# clean up the cruft left with the previous one +git config --remove-section remote.there +git config --remove-section branch.master + test_expect_success 'push with dry-run' ' mk_test heads/master && diff --git a/t/t5530-upload-pack-error.sh b/t/t5530-upload-pack-error.sh index cc8949e3ef..8b05091069 100755 --- a/t/t5530-upload-pack-error.sh +++ b/t/t5530-upload-pack-error.sh @@ -26,9 +26,8 @@ test_expect_success 'setup and corrupt repository' ' ' -test_expect_failure 'fsck fails' ' - - git fsck +test_expect_success 'fsck fails' ' + ! git fsck ' test_expect_success 'upload-pack fails due to error in pack-objects' ' @@ -46,9 +45,8 @@ test_expect_success 'corrupt repo differently' ' ' -test_expect_failure 'fsck fails' ' - - git fsck +test_expect_success 'fsck fails' ' + ! git fsck ' test_expect_success 'upload-pack fails due to error in rev-list' ' @@ -66,9 +64,9 @@ test_expect_success 'create empty repository' ' ' -test_expect_failure 'fetch fails' ' +test_expect_success 'fetch fails' ' - git fetch .. master + ! git fetch .. master ' diff --git a/t/t5540-http-push.sh b/t/t5540-http-push.sh new file mode 100755 index 0000000000..7372439164 --- /dev/null +++ b/t/t5540-http-push.sh @@ -0,0 +1,73 @@ +#!/bin/sh +# +# Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at> +# + +test_description='test http-push + +This test runs various sanity checks on http-push.' + +. ./test-lib.sh + +ROOT_PATH="$PWD" +LIB_HTTPD_DAV=t + +. ../lib-httpd.sh + +if ! start_httpd >&3 2>&4 +then + say "skipping test, web server setup failed" + test_done + exit +fi + +test_expect_success 'setup remote repository' ' + cd "$ROOT_PATH" && + mkdir test_repo && + cd test_repo && + git init && + : >path1 && + git add path1 && + test_tick && + git commit -m initial && + cd - && + git clone --bare test_repo test_repo.git && + cd test_repo.git && + git --bare update-server-info && + chmod +x hooks/post-update && + cd - && + mv test_repo.git $HTTPD_DOCUMENT_ROOT_PATH +' + +test_expect_success 'clone remote repository' ' + cd "$ROOT_PATH" && + git clone $HTTPD_URL/test_repo.git test_repo_clone +' + +test_expect_success 'push to remote repository' ' + cd "$ROOT_PATH"/test_repo_clone && + : >path2 && + git add path2 && + test_tick && + git commit -m path2 && + git push +' + +test_expect_success 'create and delete remote branch' ' + cd "$ROOT_PATH"/test_repo_clone && + git checkout -b dev && + : >path3 && + git add path3 && + test_tick && + git commit -m dev && + git push origin dev && + git fetch && + git push origin :dev && + git branch -d -r origin/dev && + git fetch && + ! git show-ref --verify refs/remotes/origin/dev +' + +stop_httpd + +test_done diff --git a/t/t5600-clone-fail-cleanup.sh b/t/t5600-clone-fail-cleanup.sh index 1776b377f3..acf34cec8f 100755 --- a/t/t5600-clone-fail-cleanup.sh +++ b/t/t5600-clone-fail-cleanup.sh @@ -11,13 +11,13 @@ remove the directory before attempting a clone again.' . ./test-lib.sh -test_expect_failure \ +test_expect_success \ 'clone of non-existent source should fail' \ - 'git-clone foo bar' + '! git-clone foo bar' -test_expect_failure \ +test_expect_success \ 'failed clone should not leave a directory' \ - 'cd bar' + '! test -d bar' # Need a repo to clone test_create_repo foo @@ -27,9 +27,9 @@ test_create_repo foo # source repository given to git-clone should be relative to the # current path not to the target dir -test_expect_failure \ +test_expect_success \ 'clone of non-existent (relative to $PWD) source should fail' \ - 'git-clone ../foo baz' + '! git-clone ../foo baz' test_expect_success \ 'clone should work now that source exists' \ diff --git a/t/t5701-clone-local.sh b/t/t5701-clone-local.sh index 59a165a6d4..8dfaaa456e 100755 --- a/t/t5701-clone-local.sh +++ b/t/t5701-clone-local.sh @@ -11,6 +11,11 @@ test_expect_success 'preparing origin repository' ' git clone --bare . x && test "$(GIT_CONFIG=a.git/config git config --bool core.bare)" = true && test "$(GIT_CONFIG=x/config git config --bool core.bare)" = true + git bundle create b1.bundle --all HEAD && + git bundle create b2.bundle --all && + mkdir dir && + cp b1.bundle dir/b3 + cp b1.bundle b4 ' test_expect_success 'local clone without .git suffix' ' @@ -71,4 +76,44 @@ test_expect_success 'local clone of repo with nonexistent ref in HEAD' ' git fetch && test ! -e .git/refs/remotes/origin/HEAD' +test_expect_success 'bundle clone without .bundle suffix' ' + cd "$D" && + git clone dir/b3 && + cd b3 && + git fetch +' + +test_expect_success 'bundle clone with .bundle suffix' ' + cd "$D" && + git clone b1.bundle && + cd b1 && + git fetch +' + +test_expect_success 'bundle clone from b4' ' + cd "$D" && + git clone b4 bdl && + cd bdl && + git fetch +' + +test_expect_success 'bundle clone from b4.bundle that does not exist' ' + cd "$D" && + if git clone b4.bundle bb + then + echo "Oops, should have failed" + false + else + echo happy + fi +' + +test_expect_success 'bundle clone with nonexistent HEAD' ' + cd "$D" && + git clone b2.bundle b2 && + cd b2 && + git fetch + test ! -e .git/refs/heads/master +' + test_done diff --git a/t/t5710-info-alternate.sh b/t/t5710-info-alternate.sh index 1908dc8b06..910ccb4fff 100755 --- a/t/t5710-info-alternate.sh +++ b/t/t5710-info-alternate.sh @@ -87,10 +87,10 @@ test_valid_repo" cd "$base_dir" -test_expect_failure 'that info/alternates is necessary' \ +test_expect_success 'that info/alternates is necessary' \ 'cd C && -rm .git/objects/info/alternates && -test_valid_repo' +rm -f .git/objects/info/alternates && +! (test_valid_repo)' cd "$base_dir" @@ -101,9 +101,11 @@ test_valid_repo' cd "$base_dir" -test_expect_failure 'that relative alternate is only possible for current dir' \ -'cd D && -test_valid_repo' +test_expect_success \ + 'that relative alternate is only possible for current dir' ' + cd D && + ! (test_valid_repo) +' cd "$base_dir" diff --git a/t/t6000lib.sh b/t/t6000lib.sh index 180633e1e0..c0baaa5360 100755 --- a/t/t6000lib.sh +++ b/t/t6000lib.sh @@ -97,7 +97,13 @@ check_output() # from front and back. name_from_description() { - tr "'" '-' | tr '~`!@#$%^&*()_+={}[]|\;:"<>,/? ' '-' | tr -s '-' | tr '[A-Z]' '[a-z]' | sed "s/^-*//;s/-*\$//" + perl -pe ' + s/[^A-Za-z0-9.]/-/g; + s/-+/-/g; + s/-$//; + s/^-//; + y/A-Z/a-z/; + ' } diff --git a/t/t6004-rev-list-path-optim.sh b/t/t6004-rev-list-path-optim.sh index 80d71988b8..5dabf1c5e3 100755 --- a/t/t6004-rev-list-path-optim.sh +++ b/t/t6004-rev-list-path-optim.sh @@ -45,7 +45,7 @@ test_expect_success 'further setup' ' test_expect_success 'path optimization 2' ' ( echo "$side"; echo "$initial" ) >expected && git rev-list HEAD -- a >actual && - diff -u expected actual + test_cmp expected actual ' test_done diff --git a/t/t6009-rev-list-parent.sh b/t/t6009-rev-list-parent.sh new file mode 100755 index 0000000000..f248a3293c --- /dev/null +++ b/t/t6009-rev-list-parent.sh @@ -0,0 +1,38 @@ +#!/bin/sh + +test_description='properly cull all ancestors' + +. ./test-lib.sh + +commit () { + test_tick && + echo $1 >file && + git commit -a -m $1 && + git tag $1 +} + +test_expect_success setup ' + + touch file && + git add file && + + commit one && + + test_tick=$(($test_tick - 2400)) + + commit two && + commit three && + commit four && + + git log --pretty=oneline --abbrev-commit +' + +test_expect_failure 'one is ancestor of others and should not be shown' ' + + git rev-list one --not four >result && + >expect && + test_cmp expect result + +' + +test_done diff --git a/t/t6023-merge-file.sh b/t/t6023-merge-file.sh index ae3b6f2831..79dc58b2ce 100755 --- a/t/t6023-merge-file.sh +++ b/t/t6023-merge-file.sh @@ -66,8 +66,8 @@ test_expect_success "merge result added missing LF" \ "git diff test.txt test2.txt" cp test.txt backup.txt -test_expect_failure "merge with conflicts" \ - "git merge-file test.txt orig.txt new3.txt" +test_expect_success "merge with conflicts" \ + "! git merge-file test.txt orig.txt new3.txt" cat > expect.txt << EOF <<<<<<< test.txt @@ -89,8 +89,8 @@ EOF test_expect_success "expected conflict markers" "git diff test.txt expect.txt" cp backup.txt test.txt -test_expect_failure "merge with conflicts, using -L" \ - "git merge-file -L 1 -L 2 test.txt orig.txt new3.txt" +test_expect_success "merge with conflicts, using -L" \ + "! git merge-file -L 1 -L 2 test.txt orig.txt new3.txt" cat > expect.txt << EOF <<<<<<< 1 @@ -113,8 +113,8 @@ test_expect_success "expected conflict markers, with -L" \ "git diff test.txt expect.txt" sed "s/ tu / TU /" < new1.txt > new5.txt -test_expect_failure "conflict in removed tail" \ - "git merge-file -p orig.txt new1.txt new5.txt > out" +test_expect_success "conflict in removed tail" \ + "! git merge-file -p orig.txt new1.txt new5.txt > out" cat > expect << EOF Dominus regit me, @@ -139,4 +139,24 @@ test_expect_success 'binary files cannot be merged' ' grep "Cannot merge binary files" merge.err ' +sed -e "s/deerit.$/deerit;/" -e "s/me;$/me./" < new5.txt > new6.txt +sed -e "s/deerit.$/deerit,/" -e "s/me;$/me,/" < new5.txt > new7.txt + +test_expect_success 'MERGE_ZEALOUS simplifies non-conflicts' ' + + ! git merge-file -p new6.txt new5.txt new7.txt > output && + test 1 = $(grep ======= < output | wc -l) + +' + +sed -e 's/deerit./&\n\n\n\n/' -e "s/locavit,/locavit;/" < new6.txt > new8.txt +sed -e 's/deerit./&\n\n\n\n/' -e "s/locavit,/locavit --/" < new7.txt > new9.txt + +test_expect_success 'ZEALOUS_ALNUM' ' + + ! git merge-file -p new8.txt new5.txt new9.txt > merge.out && + test 1 = $(grep ======= < merge.out | wc -l) + +' + test_done diff --git a/t/t6024-recursive-merge.sh b/t/t6024-recursive-merge.sh index c154f03cf5..23d24d3feb 100755 --- a/t/t6024-recursive-merge.sh +++ b/t/t6024-recursive-merge.sh @@ -60,7 +60,7 @@ git update-index a1 && GIT_AUTHOR_DATE="2006-12-12 23:00:08" git commit -m F ' -test_expect_failure "combined merge conflicts" "git merge -m final G" +test_expect_success "combined merge conflicts" "! git merge -m final G" cat > expect << EOF <<<<<<< HEAD:a1 @@ -81,8 +81,8 @@ EOF test_expect_success "virtual trees were processed" "git diff expect out" -git reset --hard test_expect_success 'refuse to merge binary files' ' + git reset --hard && printf "\0" > binary-file && git add binary-file && git commit -m binary && diff --git a/t/t6025-merge-symlinks.sh b/t/t6025-merge-symlinks.sh index 950c2e9b63..6004deb432 100755 --- a/t/t6025-merge-symlinks.sh +++ b/t/t6025-merge-symlinks.sh @@ -30,30 +30,29 @@ echo plain-file > symlink && git add symlink && git-commit -m b-file' -test_expect_failure \ +test_expect_success \ 'merge master into b-symlink, which has a different symbolic link' ' -! git-checkout b-symlink || -git-merge master' +git-checkout b-symlink && +! git-merge master' test_expect_success \ 'the merge result must be a file' ' test -f symlink' -test_expect_failure \ +test_expect_success \ 'merge master into b-file, which has a file instead of a symbolic link' ' -! (git-reset --hard && -git-checkout b-file) || -git-merge master' +git-reset --hard && git-checkout b-file && +! git-merge master' test_expect_success \ 'the merge result must be a file' ' test -f symlink' -test_expect_failure \ +test_expect_success \ 'merge b-file, which has a file instead of a symbolic link, into master' ' -! (git-reset --hard && -git-checkout master) || -git-merge b-file' +git-reset --hard && +git-checkout master && +! git-merge b-file' test_expect_success \ 'the merge result must be a file' ' diff --git a/t/t6027-merge-binary.sh b/t/t6027-merge-binary.sh index a7358f75b1..92ca1f0f8c 100755 --- a/t/t6027-merge-binary.sh +++ b/t/t6027-merge-binary.sh @@ -45,7 +45,7 @@ test_expect_success resolve ' false else git ls-files -s >current - diff -u current expect + test_cmp current expect fi ' @@ -60,7 +60,7 @@ test_expect_success recursive ' false else git ls-files -s >current - diff -u current expect + test_cmp current expect fi ' diff --git a/t/t6029-merge-subtree.sh b/t/t6029-merge-subtree.sh new file mode 100755 index 0000000000..43f5459c35 --- /dev/null +++ b/t/t6029-merge-subtree.sh @@ -0,0 +1,79 @@ +#!/bin/sh + +test_description='subtree merge strategy' + +. ./test-lib.sh + +test_expect_success setup ' + + s="1 2 3 4 5 6 7 8" + for i in $s; do echo $i; done >hello && + git add hello && + git commit -m initial && + git checkout -b side && + echo >>hello world && + git add hello && + git commit -m second && + git checkout master && + for i in mundo $s; do echo $i; done >hello && + git add hello && + git commit -m master + +' + +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_cmp expect hello + +' + +test_expect_success 'setup' ' + mkdir git-gui && + cd git-gui && + git init && + echo git-gui > git-gui.sh && + o1=$(git hash-object git-gui.sh) && + git add git-gui.sh && + git commit -m "initial git-gui" && + cd .. && + mkdir git && + cd git && + git init && + echo git >git.c && + o2=$(git hash-object git.c) && + git add git.c && + git commit -m "initial git" +' + +test_expect_success 'initial merge' ' + git remote add -f gui ../git-gui && + git merge -s ours --no-commit gui/master && + git read-tree --prefix=git-gui/ -u gui/master && + git commit -m "Merge git-gui as our subdirectory" && + git ls-files -s >actual && + ( + echo "100644 $o1 0 git-gui/git-gui.sh" + echo "100644 $o2 0 git.c" + ) >expected && + git diff -u expected actual +' + +test_expect_success 'merge update' ' + cd ../git-gui && + echo git-gui2 > git-gui.sh && + o3=$(git hash-object git-gui.sh) && + git add git-gui.sh && + git commit -m "update git-gui" && + cd ../git && + git pull -s subtree gui master && + git ls-files -s >actual && + ( + echo "100644 $o3 0 git-gui/git-gui.sh" + echo "100644 $o2 0 git.c" + ) >expected && + git diff -u expected actual +' + +test_done diff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh index 4908e878fe..f471c1526f 100755 --- a/t/t6030-bisect-porcelain.sh +++ b/t/t6030-bisect-porcelain.sh @@ -219,7 +219,7 @@ test_expect_success 'bisect run & skip: cannot tell between 2' ' add_line_into_file "6: Yet a line." hello && HASH6=$(git rev-parse --verify HEAD) && echo "#"\!"/bin/sh" > test_script.sh && - echo "tail -1 hello | grep Ciao > /dev/null && exit 125" >> test_script.sh && + echo "sed -ne \\\$p hello | grep Ciao > /dev/null && exit 125" >> test_script.sh && echo "grep line hello > /dev/null" >> test_script.sh && echo "test \$? -ne 0" >> test_script.sh && chmod +x test_script.sh && @@ -244,8 +244,8 @@ test_expect_success 'bisect run & skip: find first bad' ' add_line_into_file "7: Should be the last line." hello && HASH7=$(git rev-parse --verify HEAD) && echo "#"\!"/bin/sh" > test_script.sh && - echo "tail -1 hello | grep Ciao > /dev/null && exit 125" >> test_script.sh && - echo "tail -1 hello | grep day > /dev/null && exit 125" >> test_script.sh && + echo "sed -ne \\\$p hello | grep Ciao > /dev/null && exit 125" >> test_script.sh && + echo "sed -ne \\\$p hello | grep day > /dev/null && exit 125" >> test_script.sh && echo "grep Yet hello > /dev/null" >> test_script.sh && echo "test \$? -ne 0" >> test_script.sh && chmod +x test_script.sh && diff --git a/t/t6031-merge-recursive.sh b/t/t6031-merge-recursive.sh index 5bb6b93780..c8310aee4f 100755 --- a/t/t6031-merge-recursive.sh +++ b/t/t6031-merge-recursive.sh @@ -42,7 +42,7 @@ test_expect_success 'mode change in both branches: expect conflict' ' echo "100755 $H 2 file2" echo "100644 $H 3 file2" ) >expect && - diff -u actual expect && + test_cmp actual expect && test -x file2 ' diff --git a/t/t6101-rev-parse-parents.sh b/t/t6101-rev-parse-parents.sh index 0724864e56..2328b69947 100755 --- a/t/t6101-rev-parse-parents.sh +++ b/t/t6101-rev-parse-parents.sh @@ -26,7 +26,7 @@ test_expect_success 'final^1^1^1 = final^^^' "test $(git rev-parse final^1^1^1) test_expect_success 'final^1^2' "test $(git rev-parse start2) = $(git rev-parse final^1^2)" test_expect_success 'final^1^2 != final^1^1' "test $(git rev-parse final^1^2) != $(git rev-parse final^1^1)" test_expect_success 'final^1^3 not valid' "if git rev-parse --verify final^1^3; then false; else :; fi" -test_expect_failure '--verify start2^1' 'git rev-parse --verify start2^1' +test_expect_success '--verify start2^1' '! git rev-parse --verify start2^1' test_expect_success '--verify start2^0' 'git rev-parse --verify start2^0' test_expect_success 'repack for next test' 'git repack -a -d' diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh index ae8ee11183..56bbd8519d 100755 --- a/t/t6120-describe.sh +++ b/t/t6120-describe.sh @@ -15,8 +15,11 @@ test_description='test describe check_describe () { expect="$1" shift - R=$(git describe "$@") && + R=$(git describe "$@" 2>err.actual) + S=$? + cat err.actual >&3 test_expect_success "describe $*" ' + test $S = 0 && case "$R" in $expect) echo happy ;; *) echo "Oops - $R is not $expect"; @@ -94,4 +97,24 @@ check_describe D-* --tags HEAD^^ check_describe A-* --tags HEAD^^2 check_describe B --tags HEAD^^2^ +check_describe B-0-* --long HEAD^^2^ +check_describe A-3-* --long HEAD^^2 + +test_expect_success 'rename tag A to Q locally' ' + mv .git/refs/tags/A .git/refs/tags/Q +' +cat - >err.expect <<EOF +warning: tag 'A' is really 'Q' here +EOF +check_describe A-* HEAD +test_expect_success 'warning was displayed for Q' ' + git diff err.expect err.actual +' +test_expect_success 'rename tag Q back to A' ' + mv .git/refs/tags/Q .git/refs/tags/A +' + +test_expect_success 'pack tag refs' 'git pack-refs' +check_describe A-* HEAD + test_done diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh index 8a23aaf21b..f46ec93c83 100755 --- a/t/t6300-for-each-ref.sh +++ b/t/t6300-for-each-ref.sh @@ -43,8 +43,8 @@ test_expect_success 'Check atom names are valid' ' test -z "$bad" ' -test_expect_failure 'Check invalid atoms names are errors' ' - git-for-each-ref --format="%(INVALID)" refs/heads +test_expect_success 'Check invalid atoms names are errors' ' + ! git-for-each-ref --format="%(INVALID)" refs/heads ' test_expect_success 'Check format specifiers are ignored in naming date atoms' ' @@ -63,8 +63,8 @@ test_expect_success 'Check valid format specifiers for date fields' ' git-for-each-ref --format="%(authordate:rfc2822)" refs/heads ' -test_expect_failure 'Check invalid format specifiers are errors' ' - git-for-each-ref --format="%(authordate:INVALID)" refs/heads +test_expect_success 'Check invalid format specifiers are errors' ' + ! git-for-each-ref --format="%(authordate:INVALID)" refs/heads ' cat >expected <<\EOF diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index b730c900b1..fa382c58da 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -78,9 +78,9 @@ test_expect_success \ git diff-tree -r -M --name-status HEAD^ HEAD | \ grep "^R100..*path2/README..*path1/path2/README"' -test_expect_failure \ +test_expect_success \ 'do not move directory over existing directory' \ - 'mkdir path0 && mkdir path0/path2 && git mv path2 path0' + 'mkdir path0 && mkdir path0/path2 && ! git mv path2 path0' test_expect_success \ 'move into "."' \ @@ -118,4 +118,42 @@ test_expect_success "Sergey Vlasov's test case" ' git mv ab a ' +test_expect_success 'absolute pathname' '( + + rm -fr mine && + mkdir mine && + cd mine && + test_create_repo one && + cd one && + mkdir sub && + >sub/file && + git add sub/file && + + git mv sub "$(pwd)/in" && + ! test -d sub && + test -d in && + git ls-files --error-unmatch in/file + + +)' + +test_expect_success 'absolute pathname outside should fail' '( + + rm -fr mine && + mkdir mine && + cd mine && + out=$(pwd) && + test_create_repo one && + cd one && + mkdir sub && + >sub/file && + git add sub/file && + + ! git mv sub "$out/out" && + test -d sub && + ! test -d ../in && + git ls-files --error-unmatch sub/file + +)' + test_done diff --git a/t/t7002-grep.sh b/t/t7002-grep.sh index 68b2b92879..c8b4f65f38 100755 --- a/t/t7002-grep.sh +++ b/t/t7002-grep.sh @@ -107,8 +107,8 @@ do diff expected actual ' - test_expect_failure "grep -c $L (no /dev/null)" ' - git grep -c test $H | grep -q "/dev/null" + test_expect_success "grep -c $L (no /dev/null)" ' + ! git grep -c test $H | grep -q /dev/null ' done diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh index 6e14bf1c7f..553131fcf4 100755 --- a/t/t7003-filter-branch.sh +++ b/t/t7003-filter-branch.sh @@ -4,7 +4,7 @@ test_description='git-filter-branch' . ./test-lib.sh make_commit () { - lower=$(echo $1 | tr A-Z a-z) + lower=$(echo $1 | tr '[A-Z]' '[a-z]') echo $lower > $lower git add $lower test_tick diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh index df496a95ff..75cd33bde8 100755 --- a/t/t7004-tag.sh +++ b/t/t7004-tag.sh @@ -26,8 +26,8 @@ test_expect_success 'listing all tags in an empty tree should output nothing' ' test `git-tag | wc -l` -eq 0 ' -test_expect_failure 'looking for a tag in an empty tree should fail' \ - 'tag_exists mytag' +test_expect_success 'looking for a tag in an empty tree should fail' \ + '! (tag_exists mytag)' test_expect_success 'creating a tag in an empty tree should fail' ' ! git-tag mynotag && @@ -83,9 +83,9 @@ test_expect_success \ # special cases for creating tags: -test_expect_failure \ +test_expect_success \ 'trying to create a tag with the name of one existing should fail' \ - 'git tag mytag' + '! git tag mytag' test_expect_success \ 'trying to create a tag with a non-valid name should fail' ' @@ -146,8 +146,8 @@ test_expect_success \ ! tag_exists myhead ' -test_expect_failure 'trying to delete an already deleted tag should fail' \ - 'git-tag -d mytag' +test_expect_success 'trying to delete an already deleted tag should fail' \ + '! git-tag -d mytag' # listing various tags with pattern matching: @@ -265,16 +265,16 @@ test_expect_success \ test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD) ' -test_expect_failure 'trying to verify an unknown tag should fail' \ - 'git-tag -v unknown-tag' +test_expect_success 'trying to verify an unknown tag should fail' \ + '! git-tag -v unknown-tag' -test_expect_failure \ +test_expect_success \ 'trying to verify a non-annotated and non-signed tag should fail' \ - 'git-tag -v non-annotated-tag' + '! git-tag -v non-annotated-tag' -test_expect_failure \ +test_expect_success \ 'trying to verify many non-annotated or unknown tags, should fail' \ - 'git-tag -v unknown-tag1 non-annotated-tag unknown-tag2' + '! git-tag -v unknown-tag1 non-annotated-tag unknown-tag2' # creating annotated tags: @@ -1027,21 +1027,21 @@ test_expect_success \ # try to sign with bad user.signingkey git config user.signingkey BobTheMouse -test_expect_failure \ +test_expect_success \ 'git-tag -s fails if gpg is misconfigured' \ - 'git tag -s -m tail tag-gpg-failure' + '! git tag -s -m tail tag-gpg-failure' git config --unset user.signingkey # try to verify without gpg: rm -rf gpghome -test_expect_failure \ +test_expect_success \ 'verify signed tag fails when public key is not present' \ - 'git-tag -v signed-tag' + '! git-tag -v signed-tag' -test_expect_failure \ +test_expect_success \ 'git-tag -a fails if tag annotation is empty' ' - GIT_EDITOR=cat git tag -a initial-comment + ! (GIT_EDITOR=cat git tag -a initial-comment) ' test_expect_success \ diff --git a/t/t7010-setup.sh b/t/t7010-setup.sh new file mode 100755 index 0000000000..02cf7c5c9d --- /dev/null +++ b/t/t7010-setup.sh @@ -0,0 +1,165 @@ +#!/bin/sh + +test_description='setup taking and sanitizing funny paths' + +. ./test-lib.sh + +test_expect_success setup ' + + mkdir -p a/b/c a/e && + D=$(pwd) && + >a/b/c/d && + >a/e/f + +' + +test_expect_success 'git add (absolute)' ' + + git add "$D/a/b/c/d" && + git ls-files >current && + echo a/b/c/d >expect && + test_cmp expect current + +' + + +test_expect_success 'git add (funny relative)' ' + + rm -f .git/index && + ( + cd a/b && + git add "../e/./f" + ) && + git ls-files >current && + echo a/e/f >expect && + test_cmp expect current + +' + +test_expect_success 'git rm (absolute)' ' + + rm -f .git/index && + git add a && + git rm -f --cached "$D/a/b/c/d" && + git ls-files >current && + echo a/e/f >expect && + test_cmp expect current + +' + +test_expect_success 'git rm (funny relative)' ' + + rm -f .git/index && + git add a && + ( + cd a/b && + git rm -f --cached "../e/./f" + ) && + git ls-files >current && + echo a/b/c/d >expect && + test_cmp expect current + +' + +test_expect_success 'git ls-files (absolute)' ' + + rm -f .git/index && + git add a && + git ls-files "$D/a/e/../b" >current && + echo a/b/c/d >expect && + test_cmp expect current + +' + +test_expect_success 'git ls-files (relative #1)' ' + + rm -f .git/index && + git add a && + ( + cd a/b && + git ls-files "../b/c" + ) >current && + echo c/d >expect && + test_cmp expect current + +' + +test_expect_success 'git ls-files (relative #2)' ' + + rm -f .git/index && + git add a && + ( + cd a/b && + git ls-files --full-name "../e/f" + ) >current && + echo a/e/f >expect && + test_cmp expect current + +' + +test_expect_success 'git ls-files (relative #3)' ' + + rm -f .git/index && + git add a && + ( + cd a/b && + if git ls-files "../e/f" + then + echo Gaah, should have failed + exit 1 + else + : happy + fi + ) + +' + +test_expect_success 'commit using absolute path names' ' + git commit -m "foo" && + echo aa >>a/b/c/d && + git commit -m "aa" "$(pwd)/a/b/c/d" +' + +test_expect_success 'log using absolute path names' ' + echo bb >>a/b/c/d && + git commit -m "bb" $(pwd)/a/b/c/d && + + git log a/b/c/d >f1.txt && + git log "$(pwd)/a/b/c/d" >f2.txt && + test_cmp f1.txt f2.txt +' + +test_expect_success 'blame using absolute path names' ' + git blame a/b/c/d >f1.txt && + git blame "$(pwd)/a/b/c/d" >f2.txt && + test_cmp f1.txt f2.txt +' + +test_expect_success 'setup deeper work tree' ' + test_create_repo tester +' + +test_expect_success 'add a directory outside the work tree' '( + cd tester && + d1="$(cd .. ; pwd)" && + test_must_fail git add "$d1" +)' + + +test_expect_success 'add a file outside the work tree, nasty case 1' '( + cd tester && + f="$(pwd)x" && + echo "$f" && + touch "$f" && + test_must_fail git add "$f" +)' + +test_expect_success 'add a file outside the work tree, nasty case 2' '( + cd tester && + f="$(pwd | sed "s/.$//")x" && + echo "$f" && + touch "$f" && + test_must_fail git add "$f" +)' + +test_done diff --git a/t/t7101-reset.sh b/t/t7101-reset.sh index 66d40430b2..0d9874bfd7 100755 --- a/t/t7101-reset.sh +++ b/t/t7101-reset.sh @@ -36,28 +36,28 @@ test_expect_success \ 'test -d path0 && test -f path0/COPYING' -test_expect_failure \ +test_expect_success \ 'checking lack of path1/path2/COPYING' \ - 'test -f path1/path2/COPYING' + '! test -f path1/path2/COPYING' -test_expect_failure \ +test_expect_success \ 'checking lack of path1/COPYING' \ - 'test -f path1/COPYING' + '! test -f path1/COPYING' -test_expect_failure \ +test_expect_success \ 'checking lack of COPYING' \ - 'test -f COPYING' + '! test -f COPYING' -test_expect_failure \ +test_expect_success \ 'checking checking lack of path1/COPYING-TOO' \ - 'test -f path0/COPYING-TOO' + '! test -f path0/COPYING-TOO' -test_expect_failure \ +test_expect_success \ 'checking lack of path1/path2' \ - 'test -d path1/path2' + '! test -d path1/path2' -test_expect_failure \ +test_expect_success \ 'checking lack of path1' \ - 'test -d path1' + '! test -d path1' test_done diff --git a/t/t7104-reset.sh b/t/t7104-reset.sh new file mode 100755 index 0000000000..f136ee7bb5 --- /dev/null +++ b/t/t7104-reset.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +test_description='reset --hard unmerged' + +. ./test-lib.sh + +test_expect_success setup ' + + mkdir before later && + >before/1 && + >before/2 && + >hello && + >later/3 && + git add before hello later && + git commit -m world && + + H=$(git rev-parse :hello) && + git rm --cached hello && + echo "100644 $H 2 hello" | git update-index --index-info && + + rm -f hello && + mkdir -p hello && + >hello/world && + test "$(git ls-files -o)" = hello/world + +' + +test_expect_success 'reset --hard should restore unmerged ones' ' + + git reset --hard && + git ls-files --error-unmatch before/1 before/2 hello later/3 && + test -f hello + +' + +test_expect_success 'reset --hard did not corrupt index nor cached-tree' ' + + T=$(git write-tree) && + rm -f .git/index && + git add before hello later && + U=$(git write-tree) && + test "$T" = "$U" + +' + +test_done diff --git a/t/t7201-co.sh b/t/t7201-co.sh index 73d8a00e2c..3111baa9e3 100755 --- a/t/t7201-co.sh +++ b/t/t7201-co.sh @@ -83,13 +83,13 @@ test_expect_success "checkout with unrelated dirty tree without -m" ' fill 0 1 2 3 4 5 6 7 8 >same && cp same kept git checkout side >messages && - git diff same kept + test_cmp same kept (cat > messages.expect <<EOF M same EOF ) && touch messages.expect && - git diff messages.expect messages + test_cmp messages.expect messages ' test_expect_success "checkout -m with dirty tree" ' @@ -103,29 +103,22 @@ test_expect_success "checkout -m with dirty tree" ' test "$(git symbolic-ref HEAD)" = "refs/heads/side" && (cat >expect.messages <<EOF -Merging side with local -Merging: -ab76817 Side M one, D two, A three -virtual local -found 1 common ancestor(s): -7329388 Initial A one, A two -Auto-merged one M one EOF ) && - git diff expect.messages messages && + test_cmp expect.messages messages && fill "M one" "A three" "D two" >expect.master && git diff --name-status master >current.master && - diff expect.master current.master && + test_cmp expect.master current.master && fill "M one" >expect.side && git diff --name-status side >current.side && - diff expect.side current.side && + test_cmp expect.side current.side && : >expect.index && git diff --cached >current.index && - diff expect.index current.index + test_cmp expect.index current.index ' test_expect_success "checkout -m with dirty tree, renamed" ' @@ -143,7 +136,7 @@ test_expect_success "checkout -m with dirty tree, renamed" ' git checkout -m renamer && fill 1 3 4 5 7 8 >expect && - diff expect uno && + test_cmp expect uno && ! test -f one && git diff --cached >current && ! test -s current @@ -168,7 +161,7 @@ test_expect_success 'checkout -m with merge conflict' ' git diff master:one :3:uno | sed -e "1,/^@@/d" -e "/^ /d" -e "s/^-/d/" -e "s/^+/a/" >current && fill d2 aT d7 aS >expect && - diff current expect && + test_cmp current expect && git diff --cached two >current && ! test -s current ' @@ -185,7 +178,7 @@ If you want to create a new branch from this checkout, you may do so HEAD is now at 7329388... Initial A one, A two EOF ) && - git diff messages.expect messages && + test_cmp messages.expect messages && H=$(git rev-parse --verify HEAD) && M=$(git show-ref -s --verify refs/heads/master) && test "z$H" = "z$M" && @@ -214,6 +207,22 @@ test_expect_success 'checkout to detach HEAD with branchname^' ' fi ' +test_expect_success 'checkout to detach HEAD with :/message' ' + + git checkout -f master && git clean -f && + git checkout ":/Initial" && + H=$(git rev-parse --verify HEAD) && + M=$(git show-ref -s --verify refs/heads/master) && + test "z$H" = "z$M" && + if git symbolic-ref HEAD >/dev/null 2>&1 + then + echo "OOPS, HEAD is still symbolic???" + false + else + : happy + fi +' + test_expect_success 'checkout to detach HEAD with HEAD^0' ' git checkout -f master && git clean -f && @@ -270,4 +279,62 @@ test_expect_success 'checkout with ambiguous tag/branch names' ' ' +test_expect_success 'switch branches while in subdirectory' ' + + git reset --hard && + git checkout master && + + mkdir subs && + ( + cd subs && + git checkout side + ) && + ! test -f subs/one && + rm -fr subs + +' + +test_expect_success 'checkout specific path while in subdirectory' ' + + git reset --hard && + git checkout side && + mkdir subs && + >subs/bero && + git add subs/bero && + git commit -m "add subs/bero" && + + git checkout master && + mkdir -p subs && + ( + cd subs && + git checkout side -- bero + ) && + test -f subs/bero + +' + +test_expect_success \ + 'checkout w/--track sets up tracking' ' + git config branch.autosetupmerge false && + git checkout master && + git checkout --track -b track1 && + test "$(git config branch.track1.remote)" && + test "$(git config branch.track1.merge)"' + +test_expect_success \ + 'checkout w/autosetupmerge=always sets up tracking' ' + git config branch.autosetupmerge always && + git checkout master && + git checkout -b track2 && + test "$(git config branch.track2.remote)" && + test "$(git config branch.track2.merge)" + git config branch.autosetupmerge false' + +test_expect_success \ + 'checkout w/--track from non-branch HEAD fails' ' + git checkout -b delete-me master && + rm .git/refs/heads/delete-me && + test refs/heads/delete-me = "$(git symbolic-ref HEAD)" && + !(git checkout --track -b track)' + test_done diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh index dfd118878f..afccfc9973 100755 --- a/t/t7300-clean.sh +++ b/t/t7300-clean.sh @@ -89,6 +89,58 @@ test_expect_success 'git-clean with prefix' ' test -f build/lib.so ' + +test_expect_success 'git-clean with relative prefix' ' + + mkdir -p build docs && + touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && + would_clean=$( + cd docs && + git clean -n ../src | + sed -n -e "s|^Would remove ||p" + ) && + test "$would_clean" = ../src/part3.c || { + echo "OOps <$would_clean>" + false + } +' + +test_expect_success 'git-clean with absolute path' ' + + mkdir -p build docs && + touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && + would_clean=$( + cd docs && + git clean -n $(pwd)/../src | + sed -n -e "s|^Would remove ||p" + ) && + test "$would_clean" = ../src/part3.c || { + echo "OOps <$would_clean>" + false + } +' + +test_expect_success 'git-clean with out of work tree relative path' ' + + mkdir -p build docs && + touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && + ( + cd docs && + test_must_fail git clean -n ../.. + ) +' + +test_expect_success 'git-clean with out of work tree absolute path' ' + + mkdir -p build docs && + touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && + dd=$(cd .. && pwd) && + ( + cd docs && + test_must_fail git clean -n $dd + ) +' + test_expect_success 'git-clean -d with prefix and path' ' mkdir -p build docs src/feature && @@ -316,4 +368,15 @@ test_expect_success 'core.excludesfile' ' ' +test_expect_success 'removal failure' ' + + mkdir foo && + touch foo/bar && + exec <foo/bar && + chmod 0 foo && + test_must_fail git clean -f -d + +' +chmod 755 foo + test_done diff --git a/t/t7401-submodule-summary.sh b/t/t7401-submodule-summary.sh new file mode 100755 index 0000000000..0f3c42ab35 --- /dev/null +++ b/t/t7401-submodule-summary.sh @@ -0,0 +1,195 @@ +#!/bin/sh +# +# Copyright (c) 2008 Ping Yin +# + +test_description='Summary support for submodules + +This test tries to verify the sanity of summary subcommand of git-submodule. +' + +. ./test-lib.sh + +add_file () { + sm=$1 + shift + owd=$(pwd) + cd "$sm" + for name; do + echo "$name" > "$name" && + git add "$name" && + test_tick && + git commit -m "Add $name" + done >/dev/null + git rev-parse --verify HEAD | cut -c1-7 + cd "$owd" +} +commit_file () { + test_tick && + git commit "$@" -m "Commit $*" >/dev/null +} + +test_create_repo sm1 && +add_file . foo + +head1=$(add_file sm1 foo1 foo2) + +test_expect_success 'added submodule' " + git add sm1 && + git submodule summary >actual && + diff actual - <<-EOF +* sm1 0000000...$head1 (2): + > Add foo2 + +EOF +" + +commit_file sm1 && +head2=$(add_file sm1 foo3) + +test_expect_success 'modified submodule(forward)' " + git submodule summary >actual && + diff actual - <<-EOF +* sm1 $head1...$head2 (1): + > Add foo3 + +EOF +" + +commit_file sm1 && +cd sm1 && +git reset --hard HEAD~2 >/dev/null && +head3=$(git rev-parse --verify HEAD | cut -c1-7) && +cd .. + +test_expect_success 'modified submodule(backward)' " + git submodule summary >actual && + diff actual - <<-EOF +* sm1 $head2...$head3 (2): + < Add foo3 + < Add foo2 + +EOF +" + +head4=$(add_file sm1 foo4 foo5) && +head4_full=$(GIT_DIR=sm1/.git git rev-parse --verify HEAD) +test_expect_success 'modified submodule(backward and forward)' " + git submodule summary >actual && + diff actual - <<-EOF +* sm1 $head2...$head4 (4): + > Add foo5 + > Add foo4 + < Add foo3 + < Add foo2 + +EOF +" + +test_expect_success '--summary-limit' " + git submodule summary -n 3 >actual && + diff actual - <<-EOF +* sm1 $head2...$head4 (4): + > Add foo5 + > Add foo4 + < Add foo3 + +EOF +" + +commit_file sm1 && +mv sm1 sm1-bak && +echo sm1 >sm1 && +head5=$(git hash-object sm1 | cut -c1-7) && +git add sm1 && +rm -f sm1 && +mv sm1-bak sm1 + +test_expect_success 'typechanged submodule(submodule->blob), --cached' " + git submodule summary --cached >actual && + diff actual - <<-EOF +* sm1 $head4(submodule)->$head5(blob) (3): + < Add foo5 + +EOF +" + +rm -rf sm1 && +git checkout-index sm1 +test_expect_success 'typechanged submodule(submodule->blob)' " + git submodule summary >actual && + diff actual - <<-EOF +* sm1 $head4(submodule)->$head5(blob): + +EOF +" + +rm -f sm1 && +test_create_repo sm1 && +head6=$(add_file sm1 foo6 foo7) +test_expect_success 'nonexistent commit' " + git submodule summary >actual && + diff actual - <<-EOF +* sm1 $head4...$head6: + Warn: sm1 doesn't contain commit $head4_full + +EOF +" + +commit_file +test_expect_success 'typechanged submodule(blob->submodule)' " + git submodule summary >actual && + diff actual - <<-EOF +* sm1 $head5(blob)->$head6(submodule) (2): + > Add foo7 + +EOF +" + +commit_file sm1 && +rm -rf sm1 +test_expect_success 'deleted submodule' " + git submodule summary >actual && + diff actual - <<-EOF +* sm1 $head6...0000000: + +EOF +" + +test_create_repo sm2 && +head7=$(add_file sm2 foo8 foo9) && +git add sm2 + +test_expect_success 'multiple submodules' " + git submodule summary >actual && + diff actual - <<-EOF +* sm1 $head6...0000000: + +* sm2 0000000...$head7 (2): + > Add foo9 + +EOF +" + +test_expect_success 'path filter' " + git submodule summary sm2 >actual && + diff actual - <<-EOF +* sm2 0000000...$head7 (2): + > Add foo9 + +EOF +" + +commit_file sm2 +test_expect_success 'given commit' " + git submodule summary HEAD^ >actual && + diff actual - <<-EOF +* sm1 $head6...0000000: + +* sm2 0000000...$head7 (2): + > Add foo9 + +EOF +" + +test_done diff --git a/t/t7501-commit.sh b/t/t7501-commit.sh index 55043d102f..c0288f345f 100755 --- a/t/t7501-commit.sh +++ b/t/t7501-commit.sh @@ -17,49 +17,49 @@ test_expect_success \ git-add file && \ git-status | grep 'Initial commit'" -test_expect_failure \ +test_expect_success \ "fail initial amend" \ - "git-commit --amend" + "! git-commit --amend" test_expect_success \ "initial commit" \ "git-commit -m initial" -test_expect_failure \ +test_expect_success \ "invalid options 1" \ - "git-commit -m foo -m bar -F file" + "! git-commit -m foo -m bar -F file" -test_expect_failure \ +test_expect_success \ "invalid options 2" \ - "git-commit -C HEAD -m illegal" + "! git-commit -C HEAD -m illegal" -test_expect_failure \ +test_expect_success \ "using paths with -a" \ "echo King of the bongo >file && - git-commit -m foo -a file" + ! git-commit -m foo -a file" -test_expect_failure \ +test_expect_success \ "using paths with --interactive" \ "echo bong-o-bong >file && - echo 7 | git-commit -m foo --interactive file" + ! echo 7 | git-commit -m foo --interactive file" -test_expect_failure \ +test_expect_success \ "using invalid commit with -C" \ - "git-commit -C bogus" + "! git-commit -C bogus" -test_expect_failure \ +test_expect_success \ "testing nothing to commit" \ - "git-commit -m initial" + "! git-commit -m initial" test_expect_success \ "next commit" \ "echo 'bongo bongo bongo' >file \ git-commit -m next -a" -test_expect_failure \ +test_expect_success \ "commit message from non-existing file" \ "echo 'more bongo: bongo bongo bongo bongo' >file && \ - git-commit -F gah -a" + ! git-commit -F gah -a" # Empty except stray tabs and spaces on a few lines. sed -e 's/@$//' >msg <<EOF @@ -68,9 +68,9 @@ sed -e 's/@$//' >msg <<EOF @ Signed-off-by: hula EOF -test_expect_failure \ +test_expect_success \ "empty commit message" \ - "git-commit -F msg -a" + "! git-commit -F msg -a" test_expect_success \ "commit message from file" \ @@ -88,10 +88,10 @@ test_expect_success \ "amend commit" \ "VISUAL=./editor git-commit --amend" -test_expect_failure \ +test_expect_success \ "passing -m and -F" \ "echo 'enough with the bongos' >file && \ - git-commit -F msg -m amending ." + ! git-commit -F msg -m amending ." test_expect_success \ "using message from other commit" \ @@ -203,7 +203,7 @@ test_expect_success 'sign off (1)' ' git var GIT_COMMITTER_IDENT | sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ) >expected && - diff -u expected actual + test_cmp expected actual ' @@ -223,7 +223,7 @@ $existing" && git var GIT_COMMITTER_IDENT | sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ) >expected && - diff -u expected actual + test_cmp expected actual ' @@ -240,7 +240,7 @@ test_expect_success 'multiple -m' ' echo echo three ) >expected && - diff -u expected actual + test_cmp expected actual ' @@ -301,12 +301,12 @@ test_expect_success 'same tree (merge and amend merge)' ' git merge -s ours side -m "empty ok" && git diff HEAD^ HEAD >actual && : >expected && - diff -u expected actual && + test_cmp expected actual && git commit --amend -m "empty really ok" && git diff HEAD^ HEAD >actual && : >expected && - diff -u expected actual + test_cmp expected actual ' @@ -323,7 +323,7 @@ test_expect_success 'amend using the message from another commit' ' git commit --allow-empty --amend -C "$old" && git show --pretty="format:%ad %s" "$old" >expected && git show --pretty="format:%ad %s" HEAD >actual && - diff -u expected actual + test_cmp expected actual ' @@ -341,7 +341,7 @@ test_expect_success 'amend using the message from a commit named with tag' ' git commit --allow-empty --amend -C tagged-old && git show --pretty="format:%ad %s" "$old" >expected && git show --pretty="format:%ad %s" HEAD >actual && - diff -u expected actual + test_cmp expected actual ' diff --git a/t/t7502-commit.sh b/t/t7502-commit.sh index aaf497e6a5..284c941247 100755 --- a/t/t7502-commit.sh +++ b/t/t7502-commit.sh @@ -85,7 +85,7 @@ test_expect_success 'verbose' ' git add negative && git status -v | sed -ne "/^diff --git /p" >actual && echo "diff --git a/negative b/negative" >expect && - diff -u expect actual + test_cmp expect actual ' @@ -95,7 +95,7 @@ test_expect_success 'cleanup commit messages (verbatim,-t)' ' { echo;echo "# text";echo; } >expect && git commit --cleanup=verbatim -t expect -a && git cat-file -p HEAD |sed -e "1,/^\$/d" |head -n 3 >actual && - diff -u expect actual + test_cmp expect actual ' @@ -104,7 +104,7 @@ test_expect_success 'cleanup commit messages (verbatim,-F)' ' echo >>negative && git commit --cleanup=verbatim -F expect -a && git cat-file -p HEAD |sed -e "1,/^\$/d">actual && - diff -u expect actual + test_cmp expect actual ' @@ -113,7 +113,7 @@ test_expect_success 'cleanup commit messages (verbatim,-m)' ' echo >>negative && git commit --cleanup=verbatim -m "$(cat expect)" -a && git cat-file -p HEAD |sed -e "1,/^\$/d">actual && - diff -u expect actual + test_cmp expect actual ' @@ -124,7 +124,7 @@ test_expect_success 'cleanup commit messages (whitespace,-F)' ' echo "# text" >expect && git commit --cleanup=whitespace -F text -a && git cat-file -p HEAD |sed -e "1,/^\$/d">actual && - diff -u expect actual + test_cmp expect actual ' @@ -135,7 +135,7 @@ test_expect_success 'cleanup commit messages (strip,-F)' ' echo sample >expect && git commit --cleanup=strip -F text -a && git cat-file -p HEAD |sed -e "1,/^\$/d">actual && - diff -u expect actual + test_cmp expect actual ' @@ -150,8 +150,37 @@ test_expect_success 'cleanup commit messages (strip,-F,-e)' ' { echo;echo sample;echo; } >text && git commit -e -F text -a && head -n 4 .git/COMMIT_EDITMSG >actual && - diff -u expect actual + test_cmp expect actual ' +pwd=`pwd` +cat >> .git/FAKE_EDITOR << EOF +#! /bin/sh +echo editor started > "$pwd/.git/result" +exit 0 +EOF +chmod +x .git/FAKE_EDITOR + +test_expect_success 'do not fire editor in the presence of conflicts' ' + + git clean + echo f>g + git add g + git commit -myes + git branch second + echo master>g + echo g>h + git add g h + git commit -mmaster + git checkout second + echo second>g + git add g + git commit -msecond + git cherry-pick -n master + echo "editor not started" > .git/result + GIT_EDITOR=`pwd`/.git/FAKE_EDITOR git commit && exit 1 # should fail + test "`cat .git/result`" = "editor not started" +' + test_done diff --git a/t/t7502-status.sh b/t/t7502-status.sh index e00607490b..cd08516e6d 100755 --- a/t/t7502-status.sh +++ b/t/t7502-status.sh @@ -33,7 +33,7 @@ test_expect_success 'setup' ' test_expect_success 'status (1)' ' - grep -e "use \"git rm --cached <file>\.\.\.\" to unstage" output + grep "use \"git rm --cached <file>\.\.\.\" to unstage" output ' @@ -146,7 +146,7 @@ cat <<EOF >expect EOF test_expect_success 'status of partial commit excluding new file in index' ' git status dir1/modified >output && - diff -u expect output + test_cmp expect output ' test_done diff --git a/t/t7503-pre-commit-hook.sh b/t/t7503-pre-commit-hook.sh index d787cac2f7..2dd5a5e302 100755 --- a/t/t7503-pre-commit-hook.sh +++ b/t/t7503-pre-commit-hook.sh @@ -52,11 +52,11 @@ cat > "$HOOK" <<EOF exit 1 EOF -test_expect_failure 'with failing hook' ' +test_expect_success 'with failing hook' ' echo "another" >> file && git add file && - git commit -m "another" + ! git commit -m "another" ' diff --git a/t/t7504-commit-msg-hook.sh b/t/t7504-commit-msg-hook.sh index 751b11300b..eff36aaee3 100755 --- a/t/t7504-commit-msg-hook.sh +++ b/t/t7504-commit-msg-hook.sh @@ -98,20 +98,20 @@ cat > "$HOOK" <<EOF exit 1 EOF -test_expect_failure 'with failing hook' ' +test_expect_success 'with failing hook' ' echo "another" >> file && git add file && - git commit -m "another" + ! git commit -m "another" ' -test_expect_failure 'with failing hook (editor)' ' +test_expect_success 'with failing hook (editor)' ' echo "more another" >> file && git add file && echo "more another" > FAKE_MSG && - GIT_EDITOR="$FAKE_EDITOR" git commit + ! (GIT_EDITOR="$FAKE_EDITOR" git commit) ' diff --git a/t/t7505-prepare-commit-msg-hook.sh b/t/t7505-prepare-commit-msg-hook.sh new file mode 100755 index 0000000000..802aa624d0 --- /dev/null +++ b/t/t7505-prepare-commit-msg-hook.sh @@ -0,0 +1,156 @@ +#!/bin/sh + +test_description='prepare-commit-msg hook' + +. ./test-lib.sh + +test_expect_success 'with no hook' ' + + echo "foo" > file && + git add file && + git commit -m "first" + +' + +# set up fake editor for interactive editing +cat > fake-editor <<'EOF' +#!/bin/sh +exit 0 +EOF +chmod +x fake-editor +FAKE_EDITOR="$(pwd)/fake-editor" +export FAKE_EDITOR + +# now install hook that always succeeds and adds a message +HOOKDIR="$(git rev-parse --git-dir)/hooks" +HOOK="$HOOKDIR/prepare-commit-msg" +mkdir -p "$HOOKDIR" +echo "#!$SHELL_PATH" > "$HOOK" +cat >> "$HOOK" <<'EOF' + +if test "$2" = commit; then + source=$(git-rev-parse "$3") +else + source=${2-default} +fi +if test "$GIT_EDITOR" = :; then + sed -e "1s/.*/$source (no editor)/" "$1" > msg.tmp +else + sed -e "1s/.*/$source/" "$1" > msg.tmp +fi +mv msg.tmp "$1" +exit 0 +EOF +chmod +x "$HOOK" + +echo dummy template > "$(git rev-parse --git-dir)/template" + +test_expect_success 'with hook (-m)' ' + + echo "more" >> file && + git add file && + git commit -m "more" && + test "`git log -1 --pretty=format:%s`" = "message (no editor)" + +' + +test_expect_success 'with hook (-m editor)' ' + + echo "more" >> file && + git add file && + GIT_EDITOR="$FAKE_EDITOR" git commit -e -m "more more" && + test "`git log -1 --pretty=format:%s`" = message + +' + +test_expect_success 'with hook (-t)' ' + + echo "more" >> file && + git add file && + git commit -t "$(git rev-parse --git-dir)/template" && + test "`git log -1 --pretty=format:%s`" = template + +' + +test_expect_success 'with hook (-F)' ' + + echo "more" >> file && + git add file && + (echo more | git commit -F -) && + test "`git log -1 --pretty=format:%s`" = "message (no editor)" + +' + +test_expect_success 'with hook (-F editor)' ' + + echo "more" >> file && + git add file && + (echo more more | GIT_EDITOR="$FAKE_EDITOR" git commit -e -F -) && + test "`git log -1 --pretty=format:%s`" = message + +' + +test_expect_success 'with hook (-C)' ' + + head=`git rev-parse HEAD` && + echo "more" >> file && + git add file && + git commit -C $head && + test "`git log -1 --pretty=format:%s`" = "$head (no editor)" + +' + +test_expect_success 'with hook (editor)' ' + + echo "more more" >> file && + git add file && + GIT_EDITOR="$FAKE_EDITOR" git commit && + test "`git log -1 --pretty=format:%s`" = default + +' + +test_expect_success 'with hook (--amend)' ' + + head=`git rev-parse HEAD` && + echo "more" >> file && + git add file && + GIT_EDITOR="$FAKE_EDITOR" git commit --amend && + test "`git log -1 --pretty=format:%s`" = "$head" + +' + +test_expect_success 'with hook (-c)' ' + + head=`git rev-parse HEAD` && + echo "more" >> file && + git add file && + GIT_EDITOR="$FAKE_EDITOR" git commit -c $head && + test "`git log -1 --pretty=format:%s`" = "$head" + +' + +cat > "$HOOK" <<'EOF' +#!/bin/sh +exit 1 +EOF + +test_expect_success 'with failing hook' ' + + head=`git rev-parse HEAD` && + echo "more" >> file && + git add file && + ! GIT_EDITOR="$FAKE_EDITOR" git commit -c $head + +' + +test_expect_success 'with failing hook (--no-verify)' ' + + head=`git rev-parse HEAD` && + echo "more" >> file && + git add file && + ! GIT_EDITOR="$FAKE_EDITOR" git commit --no-verify -c $head + +' + + +test_done diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh index 5d166280cb..56869aceed 100755 --- a/t/t7600-merge.sh +++ b/t/t7600-merge.sh @@ -108,7 +108,7 @@ create_merge_msgs() { } verify_diff() { - if ! diff -u "$1" "$2" + if ! test_cmp "$1" "$2" then echo "$3" false @@ -165,7 +165,7 @@ verify_mergeheads() { fi && while test $# -gt 0 do - head=$(head -n $i .git/MERGE_HEAD | tail -n 1) + head=$(head -n $i .git/MERGE_HEAD | sed -ne \$p) if test "$1" != "$head" then echo "[OOPS] MERGE_HEAD $i != $1" @@ -371,7 +371,7 @@ test_expect_success 'override config option -n' ' git merge --summary c2 >diffstat.txt && verify_merge file result.1-5 msg.1-5 && verify_parents $c1 $c2 && - if ! grep -e "^ file | *2 +-$" diffstat.txt + if ! grep "^ file | *2 +-$" diffstat.txt then echo "[OOPS] diffstat was not generated" fi @@ -386,7 +386,7 @@ test_expect_success 'override config option --summary' ' git merge -n c2 >diffstat.txt && verify_merge file result.1-5 msg.1-5 && verify_parents $c1 $c2 && - if grep -e "^ file | *2 +-$" diffstat.txt + if grep "^ file | *2 +-$" diffstat.txt then echo "[OOPS] diffstat was generated" false diff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh new file mode 100644 index 0000000000..6b0483f3e9 --- /dev/null +++ b/t/t7610-mergetool.sh @@ -0,0 +1,46 @@ +#!/bin/sh +# +# Copyright (c) 2008 Charles Bailey +# + +test_description='git-mergetool + +Testing basic merge tool invocation' + +. ./test-lib.sh + +test_expect_success 'setup' ' + echo master >file1 && + git add file1 && + git commit -m "added file1" && + git checkout -b branch1 master && + echo branch1 change >file1 && + echo branch1 newfile >file2 && + git add file1 file2 && + git commit -m "branch1 changes" && + git checkout -b branch2 master && + echo branch2 change >file1 && + echo branch2 newfile >file2 && + git add file1 file2 && + git commit -m "branch2 changes" && + git checkout master && + echo master updated >file1 && + echo master new >file2 && + git add file1 file2 && + git commit -m "master updates" +' + +test_expect_success 'custom mergetool' ' + git config merge.tool mytool && + git config mergetool.mytool.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" && + git config mergetool.mytool.trustExitCode true && + git checkout branch1 && + ! git merge master >/dev/null 2>&1 && + ( yes "" | git mergetool file1>/dev/null 2>&1 ) && + ( yes "" | git mergetool file2>/dev/null 2>&1 ) && + test "$(cat file1)" = "master updated" && + test "$(cat file2)" = "master new" && + git commit -m "branch1 resolved with mergetool" +' + +test_done diff --git a/t/t8003-blame.sh b/t/t8003-blame.sh index db51b3a6bb..966bb0a61a 100755 --- a/t/t8003-blame.sh +++ b/t/t8003-blame.sh @@ -112,7 +112,7 @@ test_expect_success 'blame wholesale copy' ' echo mouse-Second echo mouse-Third } >expected && - diff -u expected current + test_cmp expected current ' @@ -125,7 +125,7 @@ test_expect_success 'blame wholesale copy and more' ' echo cow-Fifth echo mouse-Third } >expected && - diff -u expected current + test_cmp expected current ' diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index 2efaed441d..c0973b4e6e 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -15,16 +15,22 @@ test_expect_success \ 'Setup helper tool' \ '(echo "#!/bin/sh" echo shift + echo output=1 + echo "while test -f commandline\$output; do output=\$((\$output+1)); done" echo for a echo do echo " echo \"!\$a!\"" - echo "done >commandline" - echo "cat > msgtxt" + echo "done >commandline\$output" + echo "cat > msgtxt\$output" ) >fake.sendmail && chmod +x ./fake.sendmail && git add fake.sendmail && GIT_AUTHOR_NAME="A" git commit -a -m "Second."' +clean_fake_sendmail() { + rm -f commandline* msgtxt* +} + test_expect_success 'Extract patches' ' patches=`git format-patch -n HEAD^1` ' @@ -39,7 +45,7 @@ cat >expected <<\EOF EOF test_expect_success \ 'Verify commandline' \ - 'diff commandline expected' + 'diff commandline1 expected' cat >expected-show-all-headers <<\EOF 0001-Second.patch @@ -75,14 +81,14 @@ test_expect_success 'Show all headers' ' -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \ -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \ >actual-show-all-headers && - diff -u expected-show-all-headers actual-show-all-headers + test_cmp expected-show-all-headers actual-show-all-headers ' z8=zzzzzzzz z64=$z8$z8$z8$z8$z8$z8$z8$z8 z512=$z64$z64$z64$z64$z64$z64$z64$z64 test_expect_success 'reject long lines' ' - rm -f commandline && + clean_fake_sendmail && cp $patches longline.patch && echo $z512$z512 >>longline.patch && ! git send-email \ @@ -95,7 +101,7 @@ test_expect_success 'reject long lines' ' ' test_expect_success 'no patch was sent' ' - ! test -e commandline + ! test -e commandline1 ' test_expect_success 'allow long lines with --no-validate' ' @@ -109,6 +115,7 @@ test_expect_success 'allow long lines with --no-validate' ' ' test_expect_success 'Invalid In-Reply-To' ' + clean_fake_sendmail && git send-email \ --from="Example <nobody@example.com>" \ --to=nobody@example.com \ @@ -116,17 +123,47 @@ test_expect_success 'Invalid In-Reply-To' ' --smtp-server="$(pwd)/fake.sendmail" \ $patches 2>errors - ! grep "^In-Reply-To: < *>" msgtxt + ! grep "^In-Reply-To: < *>" msgtxt1 ' test_expect_success 'Valid In-Reply-To when prompting' ' + clean_fake_sendmail && (echo "From Example <from@example.com>" echo "To Example <to@example.com>" echo "" ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \ --smtp-server="$(pwd)/fake.sendmail" \ $patches 2>errors && - ! grep "^In-Reply-To: < *>" msgtxt + ! grep "^In-Reply-To: < *>" msgtxt1 +' + +test_expect_success 'setup fake editor' ' + (echo "#!/bin/sh" && + echo "echo fake edit >>\$1" + ) >fake-editor && + chmod +x fake-editor +' + +test_expect_success '--compose works' ' + clean_fake_sendmail && + echo y | \ + GIT_EDITOR=$(pwd)/fake-editor \ + GIT_SEND_EMAIL_NOTTY=1 \ + git send-email \ + --compose --subject foo \ + --from="Example <nobody@example.com>" \ + --to=nobody@example.com \ + --smtp-server="$(pwd)/fake.sendmail" \ + $patches \ + 2>errors +' + +test_expect_success 'first message is compose text' ' + grep "^fake edit" msgtxt1 +' + +test_expect_success 'second message is patch' ' + grep "Subject:.*Second" msgtxt2 ' test_done diff --git a/t/t9100-git-svn-basic.sh b/t/t9100-git-svn-basic.sh index 614cf50d19..4e24ab3a7d 100755 --- a/t/t9100-git-svn-basic.sh +++ b/t/t9100-git-svn-basic.sh @@ -56,19 +56,19 @@ test_expect_success "$name" " name='detect node change from file to directory #1' -test_expect_failure "$name" " +test_expect_success "$name" " mkdir dir/new_file && mv dir/file dir/new_file/file && mv dir/new_file dir/file && git update-index --remove dir/file && git update-index --add dir/file/file && - git commit -m '$name' && - git-svn set-tree --find-copies-harder --rmdir \ + git commit -m '$name' && + ! git-svn set-tree --find-copies-harder --rmdir \ remotes/git-svn..mybranch" || true name='detect node change from directory to file #1' -test_expect_failure "$name" " +test_expect_success "$name" " rm -rf dir '$GIT_DIR'/index && git checkout -f -b mybranch2 remotes/git-svn && mv bar/zzz zzz && @@ -77,12 +77,12 @@ test_expect_failure "$name" " git update-index --remove -- bar/zzz && git update-index --add -- bar && git commit -m '$name' && - git-svn set-tree --find-copies-harder --rmdir \ + ! git-svn set-tree --find-copies-harder --rmdir \ remotes/git-svn..mybranch2" || true name='detect node change from file to directory #2' -test_expect_failure "$name" " +test_expect_success "$name" " rm -f '$GIT_DIR'/index && git checkout -f -b mybranch3 remotes/git-svn && rm bar/zzz && @@ -91,12 +91,12 @@ test_expect_failure "$name" " echo yyy > bar/zzz/yyy && git update-index --add bar/zzz/yyy && git commit -m '$name' && - git-svn set-tree --find-copies-harder --rmdir \ + ! git-svn set-tree --find-copies-harder --rmdir \ remotes/git-svn..mybranch3" || true name='detect node change from directory to file #2' -test_expect_failure "$name" " +test_expect_success "$name" " rm -f '$GIT_DIR'/index && git checkout -f -b mybranch4 remotes/git-svn && rm -rf dir && @@ -105,7 +105,7 @@ test_expect_failure "$name" " echo asdf > dir && git update-index --add -- dir && git commit -m '$name' && - git-svn set-tree --find-copies-harder --rmdir \ + ! git-svn set-tree --find-copies-harder --rmdir \ remotes/git-svn..mybranch4" || true @@ -213,18 +213,18 @@ EOF test_expect_success "$name" "git diff a expected" -test_expect_failure 'exit if remote refs are ambigious' " +test_expect_success 'exit if remote refs are ambigious' " git config --add svn-remote.svn.fetch \ bar:refs/remotes/git-svn && - git-svn migrate - " + ! git-svn migrate +" -test_expect_failure 'exit if init-ing a would clobber a URL' " +test_expect_success 'exit if init-ing a would clobber a URL' " svnadmin create ${PWD}/svnrepo2 && svn mkdir -m 'mkdir bar' ${svnrepo}2/bar && git config --unset svn-remote.svn.fetch \ '^bar:refs/remotes/git-svn$' && - git-svn init ${svnrepo}2/bar + ! git-svn init ${svnrepo}2/bar " test_expect_success \ diff --git a/t/t9106-git-svn-commit-diff-clobber.sh b/t/t9106-git-svn-commit-diff-clobber.sh index 79b7968eaf..f74ab1269e 100755 --- a/t/t9106-git-svn-commit-diff-clobber.sh +++ b/t/t9106-git-svn-commit-diff-clobber.sh @@ -24,11 +24,11 @@ test_expect_success 'commit change from svn side' " rm -rf t.svn " -test_expect_failure 'commit conflicting change from git' " +test_expect_success 'commit conflicting change from git' " echo second line from git >> file && git commit -a -m 'second line from git' && - git-svn commit-diff -r1 HEAD~1 HEAD $svnrepo - " || true + ! git-svn commit-diff -r1 HEAD~1 HEAD $svnrepo +" test_expect_success 'commit complementing change from git' " git reset --hard HEAD~1 && @@ -39,7 +39,7 @@ test_expect_success 'commit complementing change from git' " git-svn commit-diff -r2 HEAD~1 HEAD $svnrepo " -test_expect_failure 'dcommit fails to commit because of conflict' " +test_expect_success 'dcommit fails to commit because of conflict' " git-svn init $svnrepo && git-svn fetch && git reset --hard refs/remotes/git-svn && @@ -52,8 +52,8 @@ test_expect_failure 'dcommit fails to commit because of conflict' " rm -rf t.svn && echo 'fourth line from git' >> file && git commit -a -m 'fourth line from git' && - git-svn dcommit - " || true + ! git-svn dcommit + " test_expect_success 'dcommit does the svn equivalent of an index merge' " git reset --hard refs/remotes/git-svn && @@ -76,15 +76,15 @@ test_expect_success 'commit another change from svn side' " rm -rf t.svn " -test_expect_failure 'multiple dcommit from git-svn will not clobber svn' " +test_expect_success 'multiple dcommit from git-svn will not clobber svn' " git reset --hard refs/remotes/git-svn && echo new file >> new-file && git update-index --add new-file && git commit -a -m 'new file' && echo clobber > file && git commit -a -m 'clobber' && - git svn dcommit - " || true + ! git svn dcommit + " test_expect_success 'check that rebase really failed' 'test -d .dotest' diff --git a/t/t9106-git-svn-dcommit-clobber-series.sh b/t/t9106-git-svn-dcommit-clobber-series.sh index 745254665d..ca8a00ed0a 100755 --- a/t/t9106-git-svn-dcommit-clobber-series.sh +++ b/t/t9106-git-svn-dcommit-clobber-series.sh @@ -54,10 +54,10 @@ test_expect_success 'change file but in unrelated area' " test x\"\`sed -n -e 61p < file\`\" = x6611 " -test_expect_failure 'attempt to dcommit with a dirty index' ' +test_expect_success 'attempt to dcommit with a dirty index' ' echo foo >>file && git add file && - git svn dcommit + ! git svn dcommit ' test_done diff --git a/t/t9112-git-svn-md5less-file.sh b/t/t9112-git-svn-md5less-file.sh index 08313bb545..646a5f0cdb 100755 --- a/t/t9112-git-svn-md5less-file.sh +++ b/t/t9112-git-svn-md5less-file.sh @@ -1,3 +1,5 @@ +#!/bin/sh + test_description='test that git handles an svn repository with missing md5sums' . ./lib-git-svn.sh diff --git a/t/t9116-git-svn-log.sh b/t/t9116-git-svn-log.sh index 902ed4145d..e1e8bdf0e3 100755 --- a/t/t9116-git-svn-log.sh +++ b/t/t9116-git-svn-log.sh @@ -55,74 +55,74 @@ printf 'r1 \nr2 \nr4 \n' > expected-range-r1-r2-r4 test_expect_success 'test ascending revision range' " git reset --hard trunk && - git svn log -r 1:4 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r1-r2-r4 - + git svn log -r 1:4 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r1-r2-r4 - " printf 'r4 \nr2 \nr1 \n' > expected-range-r4-r2-r1 test_expect_success 'test descending revision range' " git reset --hard trunk && - git svn log -r 4:1 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r4-r2-r1 - + git svn log -r 4:1 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r4-r2-r1 - " printf 'r1 \nr2 \n' > expected-range-r1-r2 test_expect_success 'test ascending revision range with unreachable revision' " git reset --hard trunk && - git svn log -r 1:3 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r1-r2 - + git svn log -r 1:3 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r1-r2 - " printf 'r2 \nr1 \n' > expected-range-r2-r1 test_expect_success 'test descending revision range with unreachable revision' " git reset --hard trunk && - git svn log -r 3:1 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r2-r1 - + git svn log -r 3:1 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r2-r1 - " printf 'r2 \n' > expected-range-r2 test_expect_success 'test ascending revision range with unreachable upper boundary revision and 1 commit' " git reset --hard trunk && - git svn log -r 2:3 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r2 - + git svn log -r 2:3 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r2 - " test_expect_success 'test descending revision range with unreachable upper boundary revision and 1 commit' " git reset --hard trunk && - git svn log -r 3:2 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r2 - + git svn log -r 3:2 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r2 - " printf 'r4 \n' > expected-range-r4 test_expect_success 'test ascending revision range with unreachable lower boundary revision and 1 commit' " git reset --hard trunk && - git svn log -r 3:4 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r4 - + git svn log -r 3:4 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r4 - " test_expect_success 'test descending revision range with unreachable lower boundary revision and 1 commit' " git reset --hard trunk && - git svn log -r 4:3 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r4 - + git svn log -r 4:3 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r4 - " printf -- '------------------------------------------------------------------------\n' > expected-separator test_expect_success 'test ascending revision range with unreachable boundary revisions and no commits' " git reset --hard trunk && - git svn log -r 5:6 | diff -u expected-separator - + git svn log -r 5:6 | test_cmp expected-separator - " test_expect_success 'test descending revision range with unreachable boundary revisions and no commits' " git reset --hard trunk && - git svn log -r 6:5 | diff -u expected-separator - + git svn log -r 6:5 | test_cmp expected-separator - " test_expect_success 'test ascending revision range with unreachable boundary revisions and 1 commit' " git reset --hard trunk && - git svn log -r 3:5 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r4 - + git svn log -r 3:5 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r4 - " test_expect_success 'test descending revision range with unreachable boundary revisions and 1 commit' " git reset --hard trunk && - git svn log -r 5:3 | grep '^r[0-9]' | cut -d'|' -f1 | diff -u expected-range-r4 - + git svn log -r 5:3 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r4 - " test_done diff --git a/t/t9200-git-cvsexportcommit.sh b/t/t9200-git-cvsexportcommit.sh index 58c59ed5ae..42b144b1b3 100755 --- a/t/t9200-git-cvsexportcommit.sh +++ b/t/t9200-git-cvsexportcommit.sh @@ -37,7 +37,7 @@ check_entries () { else printf '%s\n' "$2" | tr '|' '\012' >expected fi - diff -u expected actual + test_cmp expected actual } test_expect_success \ @@ -257,8 +257,8 @@ test_expect_success '-w option should work with relative GIT_DIR' ' (cd "$GIT_DIR" && GIT_DIR=. git cvsexportcommit -w "$CVSWORK" -c $id && check_entries "$CVSWORK/W" "file1.txt/1.1/|file2.txt/1.1/" && - diff -u "$CVSWORK/W/file1.txt" ../W/file1.txt && - diff -u "$CVSWORK/W/file2.txt" ../W/file2.txt + test_cmp "$CVSWORK/W/file1.txt" ../W/file1.txt && + test_cmp "$CVSWORK/W/file2.txt" ../W/file2.txt ) ' @@ -279,9 +279,9 @@ test_expect_success 'check files before directories' ' git cvsexportcommit -w "$CVSWORK" -c $id && check_entries "$CVSWORK/E" "DS/1.1/|newfile5.txt/1.1/" && check_entries "$CVSWORK" "DS/1.1/|release-notes/1.2/" && - diff -u "$CVSWORK/DS" DS && - diff -u "$CVSWORK/E/DS" E/DS && - diff -u "$CVSWORK/release-notes" release-notes + test_cmp "$CVSWORK/DS" DS && + test_cmp "$CVSWORK/E/DS" E/DS && + test_cmp "$CVSWORK/release-notes" release-notes ' @@ -293,7 +293,7 @@ test_expect_success 'commit a file with leading spaces in the name' ' id=$(git rev-parse HEAD) && git cvsexportcommit -w "$CVSWORK" -c $id && check_entries "$CVSWORK" " space/1.1/|DS/1.1/|release-notes/1.2/" && - diff -u "$CVSWORK/ space" " space" + test_cmp "$CVSWORK/ space" " space" ' diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh index 142d42f3b3..c4f4465dc6 100755 --- a/t/t9300-fast-import.sh +++ b/t/t9300-fast-import.sh @@ -165,9 +165,9 @@ from refs/heads/master M 755 0000000000000000000000000000000000000001 zero1 INPUT_END -test_expect_failure \ - 'B: fail on invalid blob sha1' \ - 'git-fast-import <input' +test_expect_success 'B: fail on invalid blob sha1' ' + ! git-fast-import <input +' rm -f .git/objects/pack_* .git/objects/index_* cat >input <<INPUT_END @@ -180,9 +180,9 @@ COMMIT from refs/heads/master INPUT_END -test_expect_failure \ - 'B: fail on invalid branch name ".badbranchname"' \ - 'git-fast-import <input' +test_expect_success 'B: fail on invalid branch name ".badbranchname"' ' + ! git-fast-import <input +' rm -f .git/objects/pack_* .git/objects/index_* cat >input <<INPUT_END @@ -195,9 +195,9 @@ COMMIT from refs/heads/master INPUT_END -test_expect_failure \ - 'B: fail on invalid branch name "bad[branch]name"' \ - 'git-fast-import <input' +test_expect_success 'B: fail on invalid branch name "bad[branch]name"' ' + ! git-fast-import <input +' rm -f .git/objects/pack_* .git/objects/index_* cat >input <<INPUT_END @@ -339,9 +339,9 @@ COMMIT from refs/heads/branch^0 INPUT_END -test_expect_failure \ - 'E: rfc2822 date, --date-format=raw' \ - 'git-fast-import --date-format=raw <input' +test_expect_success 'E: rfc2822 date, --date-format=raw' ' + ! git-fast-import --date-format=raw <input +' test_expect_success \ 'E: rfc2822 date, --date-format=rfc2822' \ 'git-fast-import --date-format=rfc2822 <input' diff --git a/t/t9400-git-cvsserver-server.sh b/t/t9400-git-cvsserver-server.sh index 75d1ce433d..b91b151417 100755 --- a/t/t9400-git-cvsserver-server.sh +++ b/t/t9400-git-cvsserver-server.sh @@ -54,7 +54,7 @@ test_expect_success 'setup' ' test_expect_success 'basic checkout' \ 'GIT_CONFIG="$git_config" cvs -Q co -d cvswork master && test "$(echo $(grep -v ^D cvswork/CVS/Entries|cut -d/ -f2,3,5 | head -n 1))" = "empty/1.1/" - test "$(echo $(grep -v ^D cvswork/CVS/Entries|cut -d/ -f2,3,5 | tail -n 1))" = "secondrootfile/1.1/"' + test "$(echo $(grep -v ^D cvswork/CVS/Entries|cut -d/ -f2,3,5 | sed -ne \$p))" = "secondrootfile/1.1/"' #------------------------ # PSERVER AUTHENTICATION @@ -94,7 +94,7 @@ EOF test_expect_success 'pserver authentication' \ 'cat request-anonymous | git-cvsserver pserver >log 2>&1 && - tail -n1 log | grep -q "^I LOVE YOU$"' + sed -ne \$p log | grep "^I LOVE YOU$"' test_expect_success 'pserver authentication failure (non-anonymous user)' \ 'if cat request-git | git-cvsserver pserver >log 2>&1 @@ -103,11 +103,11 @@ test_expect_success 'pserver authentication failure (non-anonymous user)' \ else true fi && - tail -n1 log | grep -q "^I HATE YOU$"' + sed -ne \$p log | grep "^I HATE YOU$"' test_expect_success 'pserver authentication (login)' \ 'cat login-anonymous | git-cvsserver pserver >log 2>&1 && - tail -n1 log | grep -q "^I LOVE YOU$"' + sed -ne \$p log | grep "^I LOVE YOU$"' test_expect_success 'pserver authentication failure (login/non-anonymous user)' \ 'if cat login-git | git-cvsserver pserver >log 2>&1 @@ -116,7 +116,7 @@ test_expect_success 'pserver authentication failure (login/non-anonymous user)' else true fi && - tail -n1 log | grep -q "^I HATE YOU$"' + sed -ne \$p log | grep "^I HATE YOU$"' # misuse pserver authentication for testing of req_Root @@ -146,25 +146,29 @@ test_expect_success 'req_Root failure (relative pathname)' \ else true fi && - tail log | grep -q "^error 1 Root must be an absolute pathname$"' + tail log | grep "^error 1 Root must be an absolute pathname$"' test_expect_success 'req_Root failure (conflicting roots)' \ 'cat request-conflict | git-cvsserver pserver >log 2>&1 && - tail log | grep -q "^error 1 Conflicting roots specified$"' + tail log | grep "^error 1 Conflicting roots specified$"' test_expect_success 'req_Root (strict paths)' \ 'cat request-anonymous | git-cvsserver --strict-paths pserver $SERVERDIR >log 2>&1 && - tail -n1 log | grep -q "^I LOVE YOU$"' + sed -ne \$p log | grep "^I LOVE YOU$"' -test_expect_failure 'req_Root failure (strict-paths)' \ - 'cat request-anonymous | git-cvsserver --strict-paths pserver $WORKDIR >log 2>&1' +test_expect_success 'req_Root failure (strict-paths)' ' + ! cat request-anonymous | + git-cvsserver --strict-paths pserver $WORKDIR >log 2>&1 +' test_expect_success 'req_Root (w/o strict-paths)' \ 'cat request-anonymous | git-cvsserver pserver $WORKDIR/ >log 2>&1 && - tail -n1 log | grep -q "^I LOVE YOU$"' + sed -ne \$p log | grep "^I LOVE YOU$"' -test_expect_failure 'req_Root failure (w/o strict-paths)' \ - 'cat request-anonymous | git-cvsserver pserver $WORKDIR/gitcvs >log 2>&1' +test_expect_success 'req_Root failure (w/o strict-paths)' ' + ! cat request-anonymous | + git-cvsserver pserver $WORKDIR/gitcvs >log 2>&1 +' cat >request-base <<EOF BEGIN AUTH REQUEST @@ -177,24 +181,25 @@ EOF test_expect_success 'req_Root (base-path)' \ 'cat request-base | git-cvsserver --strict-paths --base-path $WORKDIR/ pserver $SERVERDIR >log 2>&1 && - tail -n1 log | grep -q "^I LOVE YOU$"' + sed -ne \$p log | grep "^I LOVE YOU$"' -test_expect_failure 'req_Root failure (base-path)' \ - 'cat request-anonymous | git-cvsserver --strict-paths --base-path $WORKDIR pserver $SERVERDIR >log 2>&1' +test_expect_success 'req_Root failure (base-path)' ' + ! cat request-anonymous | + git-cvsserver --strict-paths --base-path $WORKDIR pserver $SERVERDIR >log 2>&1 +' GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled false || exit 1 test_expect_success 'req_Root (export-all)' \ 'cat request-anonymous | git-cvsserver --export-all pserver $WORKDIR >log 2>&1 && - tail -n1 log | grep -q "^I LOVE YOU$"' + sed -ne \$p log | grep "^I LOVE YOU$"' -test_expect_failure 'req_Root failure (export-all w/o whitelist)' \ - 'cat request-anonymous | git-cvsserver --export-all pserver >log 2>&1 || - false' +test_expect_success 'req_Root failure (export-all w/o whitelist)' \ + '! (cat request-anonymous | git-cvsserver --export-all pserver >log 2>&1 || false)' test_expect_success 'req_Root (everything together)' \ 'cat request-base | git-cvsserver --export-all --strict-paths --base-path $WORKDIR/ pserver $SERVERDIR >log 2>&1 && - tail -n1 log | grep -q "^I LOVE YOU$"' + sed -ne \$p log | grep "^I LOVE YOU$"' GIT_DIR="$SERVERDIR" git config --bool gitcvs.enabled true || exit 1 @@ -211,7 +216,7 @@ test_expect_success 'gitcvs.enabled = false' \ else true fi && - cat cvs.log | grep -q "GITCVS emulation disabled" && + grep "GITCVS emulation disabled" cvs.log && test ! -d cvswork2' rm -fr cvswork2 @@ -232,7 +237,7 @@ test_expect_success 'gitcvs.ext.enabled = false' \ else true fi && - cat cvs.log | grep -q "GITCVS emulation disabled" && + grep "GITCVS emulation disabled" cvs.log && test ! -d cvswork2' rm -fr cvswork2 @@ -290,15 +295,16 @@ test_expect_success 'cvs update (update existing file)' \ cd "$WORKDIR" #TODO: cvsserver doesn't support update w/o -d -test_expect_failure "cvs update w/o -d doesn't create subdir (TODO)" \ - 'mkdir test && +test_expect_failure "cvs update w/o -d doesn't create subdir (TODO)" ' + mkdir test && echo >test/empty && git add test && git commit -q -m "Single Subdirectory" && git push gitcvs.git >/dev/null && cd cvswork && GIT_CONFIG="$git_config" cvs -Q update && - test ! -d test' + test ! -d test +' cd "$WORKDIR" test_expect_success 'cvs update (subdirectories)' \ diff --git a/t/test-lib.sh b/t/test-lib.sh index 44f5776a1b..268b26c959 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -42,6 +42,7 @@ export GIT_MERGE_VERBOSITY export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME export EDITOR VISUAL +GIT_TEST_CMP=${GIT_TEST_CMP:-diff -u} # Protect ourselves from common misconfiguration to export # CDPATH into the environment @@ -86,7 +87,7 @@ do -q|--q|--qu|--qui|--quie|--quiet) quiet=t; shift ;; --no-color) - color=; shift ;; + color=; shift ;; --no-python) # noop now... shift ;; @@ -149,8 +150,15 @@ fi test_failure=0 test_count=0 +test_fixed=0 +test_broken=0 -trap 'echo >&5 "FATAL: Unexpected exit with code $?"; exit 1' exit +die () { + echo >&5 "FATAL: Unexpected exit with code $?" + exit 1 +} + +trap 'die' exit test_tick () { if test -z "${test_tick+set}" @@ -181,6 +189,17 @@ test_failure_ () { test "$immediate" = "" || { trap - exit; exit 1; } } +test_known_broken_ok_ () { + test_count=$(expr "$test_count" + 1) + test_fixed=$(($test_fixed+1)) + say_color "" " FIXED $test_count: $@" +} + +test_known_broken_failure_ () { + test_count=$(expr "$test_count" + 1) + test_broken=$(($test_broken+1)) + say_color skip " still broken $test_count: $@" +} test_debug () { test "$debug" = "" || eval "$1" @@ -221,13 +240,13 @@ test_expect_failure () { error "bug in the test script: not 2 parameters to test-expect-failure" if ! test_skip "$@" then - say >&3 "expecting failure: $2" + say >&3 "checking known breakage: $2" test_run_ "$2" - if [ "$?" = 0 -a "$eval_ret" != 0 -a "$eval_ret" -lt 129 ] + if [ "$?" = 0 -a "$eval_ret" = 0 ] then - test_ok_ "$1" + test_known_broken_ok_ "$1" else - test_failure_ "$@" + test_known_broken_failure_ "$1" fi fi echo >&3 "" @@ -284,6 +303,23 @@ test_must_fail () { test $? -gt 0 -a $? -le 128 } +# test_cmp is a helper function to compare actual and expected output. +# You can use it like: +# +# test_expect_success 'foo works' ' +# echo expected >expected && +# foo >actual && +# test_cmp expected actual +# ' +# +# This could be written as either "cmp" or "diff -u", but: +# - cmp's output is not nearly as easy to read as diff -u +# - not all diff versions understand "-u" + +test_cmp() { + $GIT_TEST_CMP "$@" +} + # Most tests can use the created repository, but some may need to create more. # Usage: test_create_repo <directory> test_create_repo () { @@ -301,6 +337,18 @@ test_create_repo () { test_done () { trap - exit + + if test "$test_fixed" != 0 + then + say_color pass "fixed $test_fixed known breakage(s)" + fi + if test "$test_broken" != 0 + then + say_color error "still have $test_broken known breakage(s)" + msg="remaining $(($test_count-$test_broken)) test(s)" + else + msg="$test_count test(s)" + fi case "$test_failure" in 0) # We could: @@ -311,11 +359,11 @@ test_done () { # The Makefile provided will clean this test area so # we will leave things as they are. - say_color pass "passed all $test_count test(s)" + say_color pass "passed all $msg" exit 0 ;; *) - say_color error "failed $test_failure among $test_count test(s)" + say_color error "failed $test_failure among $msg" exit 1 ;; esac @@ -326,8 +374,11 @@ test_done () { PATH=$(pwd)/..:$PATH GIT_EXEC_PATH=$(pwd)/.. GIT_TEMPLATE_DIR=$(pwd)/../templates/blt -GIT_CONFIG=.git/config -export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG +unset GIT_CONFIG +unset GIT_CONFIG_LOCAL +GIT_CONFIG_NOSYSTEM=1 +GIT_CONFIG_NOGLOBAL=1 +export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_CONFIG_NOGLOBAL GITPERLLIB=$(pwd)/../perl/blib/lib:$(pwd)/../perl/blib/arch/auto/Git export GITPERLLIB @@ -341,6 +392,8 @@ if ! test -x ../test-chmtime; then exit 1 fi +. ../GIT-BUILD-OPTIONS + # Test repository test=trash rm -fr "$test" |