diff options
Diffstat (limited to 't')
111 files changed, 5995 insertions, 643 deletions
diff --git a/t/aggregate-results.sh b/t/aggregate-results.sh index d206b7c4cf..7913e206ed 100755 --- a/t/aggregate-results.sh +++ b/t/aggregate-results.sh @@ -1,5 +1,6 @@ #!/bin/sh +failed_tests= fixed=0 success=0 failed=0 @@ -18,7 +19,13 @@ do success) success=$(($success + $value)) ;; failed) - failed=$(($failed + $value)) ;; + failed=$(($failed + $value)) + if test $value != 0 + then + testnum=$(expr "$file" : 'test-results/\(t[0-9]*\)-') + failed_tests="$failed_tests $testnum" + fi + ;; broken) broken=$(($broken + $value)) ;; total) @@ -27,6 +34,11 @@ do done <"$file" done +if test -n "$failed_tests" +then + printf "\nfailed test(s):$failed_tests\n\n" +fi + printf "%-8s%d\n" fixed $fixed printf "%-8s%d\n" success $success printf "%-8s%d\n" failed $failed diff --git a/t/lib-diff-alternative.sh b/t/lib-diff-alternative.sh new file mode 100644 index 0000000000..75ffd9174f --- /dev/null +++ b/t/lib-diff-alternative.sh @@ -0,0 +1,165 @@ +#!/bin/sh + +test_diff_frobnitz() { + cat >file1 <<\EOF +#include <stdio.h> + +// Frobs foo heartily +int frobnitz(int foo) +{ + int i; + for(i = 0; i < 10; i++) + { + printf("Your answer is: "); + printf("%d\n", foo); + } +} + +int fact(int n) +{ + if(n > 1) + { + return fact(n-1) * n; + } + return 1; +} + +int main(int argc, char **argv) +{ + frobnitz(fact(10)); +} +EOF + + cat >file2 <<\EOF +#include <stdio.h> + +int fib(int n) +{ + if(n > 2) + { + return fib(n-1) + fib(n-2); + } + return 1; +} + +// Frobs foo heartily +int frobnitz(int foo) +{ + int i; + for(i = 0; i < 10; i++) + { + printf("%d\n", foo); + } +} + +int main(int argc, char **argv) +{ + frobnitz(fib(10)); +} +EOF + + cat >expect <<\EOF +diff --git a/file1 b/file2 +index 6faa5a3..e3af329 100644 +--- a/file1 ++++ b/file2 +@@ -1,26 +1,25 @@ + #include <stdio.h> + ++int fib(int n) ++{ ++ if(n > 2) ++ { ++ return fib(n-1) + fib(n-2); ++ } ++ return 1; ++} ++ + // Frobs foo heartily + int frobnitz(int foo) + { + int i; + for(i = 0; i < 10; i++) + { +- printf("Your answer is: "); + printf("%d\n", foo); + } + } + +-int fact(int n) +-{ +- if(n > 1) +- { +- return fact(n-1) * n; +- } +- return 1; +-} +- + int main(int argc, char **argv) + { +- frobnitz(fact(10)); ++ frobnitz(fib(10)); + } +EOF + + STRATEGY=$1 + + test_expect_success "$STRATEGY diff" ' + test_must_fail git diff --no-index "--$STRATEGY" file1 file2 > output && + test_cmp expect output + ' + + test_expect_success "$STRATEGY diff output is valid" ' + mv file2 expect && + git apply < output && + test_cmp expect file2 + ' +} + +test_diff_unique() { + cat >uniq1 <<\EOF +1 +2 +3 +4 +5 +6 +EOF + + cat >uniq2 <<\EOF +a +b +c +d +e +f +EOF + + cat >expect <<\EOF +diff --git a/uniq1 b/uniq2 +index b414108..0fdf397 100644 +--- a/uniq1 ++++ b/uniq2 +@@ -1,6 +1,6 @@ +-1 +-2 +-3 +-4 +-5 +-6 ++a ++b ++c ++d ++e ++f +EOF + + STRATEGY=$1 + + test_expect_success 'completely different files' ' + test_must_fail git diff --no-index "--$STRATEGY" uniq1 uniq2 > output && + test_cmp expect output + ' +} + diff --git a/t/lib-gpg.sh b/t/lib-gpg.sh new file mode 100755 index 0000000000..05824fa8e4 --- /dev/null +++ b/t/lib-gpg.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +gpg_version=`gpg --version 2>&1` +if test $? = 127; then + say "You do not seem to have gpg installed" +else + # As said here: http://www.gnupg.org/documentation/faqs.html#q6.19 + # the gpg version 1.0.6 didn't parse trust packets correctly, so for + # that version, creation of signed tags using the generated key fails. + case "$gpg_version" in + 'gpg (GnuPG) 1.0.6'*) + say "Your version of gpg (1.0.6) is too buggy for testing" + ;; + *) + # key generation info: gpg --homedir t/lib-gpg --gen-key + # Type DSA and Elgamal, size 2048 bits, no expiration date. + # Name and email: C O Mitter <committer@example.com> + # No password given, to enable non-interactive operation. + cp -R "$TEST_DIRECTORY"/lib-gpg ./gpghome + chmod 0700 gpghome + GNUPGHOME="$(pwd)/gpghome" + export GNUPGHOME + test_set_prereq GPG + ;; + esac +fi + +sanitize_pgp() { + perl -ne ' + /^-----END PGP/ and $in_pgp = 0; + print unless $in_pgp; + /^-----BEGIN PGP/ and $in_pgp = 1; + ' +} diff --git a/t/t7004/pubring.gpg b/t/lib-gpg/pubring.gpg Binary files differindex 83855fa4e1..83855fa4e1 100644 --- a/t/t7004/pubring.gpg +++ b/t/lib-gpg/pubring.gpg diff --git a/t/t7004/random_seed b/t/lib-gpg/random_seed Binary files differindex 8fed1339ed..8fed1339ed 100644 --- a/t/t7004/random_seed +++ b/t/lib-gpg/random_seed diff --git a/t/t7004/secring.gpg b/t/lib-gpg/secring.gpg Binary files differindex d831cd9eb3..d831cd9eb3 100644 --- a/t/t7004/secring.gpg +++ b/t/lib-gpg/secring.gpg diff --git a/t/t7004/trustdb.gpg b/t/lib-gpg/trustdb.gpg Binary files differindex abace962b8..abace962b8 100644 --- a/t/t7004/trustdb.gpg +++ b/t/lib-gpg/trustdb.gpg diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh index ebbc7554a7..dbb2623d93 100755 --- a/t/t0003-attributes.sh +++ b/t/t0003-attributes.sh @@ -5,20 +5,17 @@ test_description=gitattributes . ./test-lib.sh attr_check () { + path="$1" expect="$2" - path="$1" - expect="$2" - - git check-attr test -- "$path" >actual && + git $3 check-attr test -- "$path" >actual 2>err && echo "$path: test: $2" >expect && - test_cmp expect actual - + test_cmp expect actual && + test_line_count = 0 err } test_expect_success 'setup' ' - - mkdir -p a/b/d a/c && + mkdir -p a/b/d a/c b && ( echo "[attr]notest !test" echo "f test=f" @@ -26,6 +23,7 @@ test_expect_success 'setup' ' echo "onoff test -test" echo "offon -test test" echo "no notest" + echo "A/e/F test=A/e/F" ) >.gitattributes && ( echo "g test=a/g" && @@ -35,15 +33,43 @@ test_expect_success 'setup' ' echo "h test=a/b/h" && echo "d/* test=a/b/d/*" echo "d/yes notest" - ) >a/b/.gitattributes + ) >a/b/.gitattributes && ( echo "global test=global" - ) >"$HOME"/global-gitattributes + ) >"$HOME"/global-gitattributes && + cat <<-EOF >expect-all + f: test: f + a/f: test: f + a/c/f: test: f + a/g: test: a/g + a/b/g: test: a/b/g + b/g: test: unspecified + a/b/h: test: a/b/h + a/b/d/g: test: a/b/d/* + onoff: test: unset + offon: test: set + no: notest: set + no: test: unspecified + a/b/d/no: notest: set + a/b/d/no: test: a/b/d/* + a/b/d/yes: notest: set + a/b/d/yes: test: unspecified + EOF +' +test_expect_success 'command line checks' ' + test_must_fail git check-attr && + test_must_fail git check-attr -- && + test_must_fail git check-attr test && + test_must_fail git check-attr test -- && + test_must_fail git check-attr -- f && + echo "f" | test_must_fail git check-attr --stdin && + echo "f" | test_must_fail git check-attr --stdin -- f && + echo "f" | test_must_fail git check-attr --stdin test -- f && + test_must_fail git check-attr "" -- f ' test_expect_success 'attribute test' ' - attr_check f f && attr_check a/f f && attr_check a/c/f f && @@ -57,7 +83,80 @@ test_expect_success 'attribute test' ' attr_check no unspecified && attr_check a/b/d/no "a/b/d/*" && attr_check a/b/d/yes unspecified +' + +test_expect_success 'attribute matching is case sensitive when core.ignorecase=0' ' + + test_must_fail attr_check F f "-c core.ignorecase=0" && + test_must_fail attr_check a/F f "-c core.ignorecase=0" && + test_must_fail attr_check a/c/F f "-c core.ignorecase=0" && + test_must_fail attr_check a/G a/g "-c core.ignorecase=0" && + test_must_fail attr_check a/B/g a/b/g "-c core.ignorecase=0" && + test_must_fail attr_check a/b/G a/b/g "-c core.ignorecase=0" && + test_must_fail attr_check a/b/H a/b/h "-c core.ignorecase=0" && + test_must_fail attr_check a/b/D/g "a/b/d/*" "-c core.ignorecase=0" && + test_must_fail attr_check oNoFf unset "-c core.ignorecase=0" && + test_must_fail attr_check oFfOn set "-c core.ignorecase=0" && + attr_check NO unspecified "-c core.ignorecase=0" && + test_must_fail attr_check a/b/D/NO "a/b/d/*" "-c core.ignorecase=0" && + attr_check a/b/d/YES a/b/d/* "-c core.ignorecase=0" && + test_must_fail attr_check a/E/f "A/e/F" "-c core.ignorecase=0" + +' + +test_expect_success 'attribute matching is case insensitive when core.ignorecase=1' ' + + attr_check F f "-c core.ignorecase=1" && + attr_check a/F f "-c core.ignorecase=1" && + attr_check a/c/F f "-c core.ignorecase=1" && + attr_check a/G a/g "-c core.ignorecase=1" && + attr_check a/B/g a/b/g "-c core.ignorecase=1" && + attr_check a/b/G a/b/g "-c core.ignorecase=1" && + attr_check a/b/H a/b/h "-c core.ignorecase=1" && + attr_check a/b/D/g "a/b/d/*" "-c core.ignorecase=1" && + attr_check oNoFf unset "-c core.ignorecase=1" && + attr_check oFfOn set "-c core.ignorecase=1" && + attr_check NO unspecified "-c core.ignorecase=1" && + attr_check a/b/D/NO "a/b/d/*" "-c core.ignorecase=1" && + attr_check a/b/d/YES unspecified "-c core.ignorecase=1" && + attr_check a/E/f "A/e/F" "-c core.ignorecase=1" + +' + +test_expect_success 'check whether FS is case-insensitive' ' + mkdir junk && + echo good >junk/CamelCase && + echo bad >junk/camelcase && + if test "$(cat junk/CamelCase)" != good + then + test_set_prereq CASE_INSENSITIVE_FS + fi +' + +test_expect_success CASE_INSENSITIVE_FS 'additional case insensitivity tests' ' + test_must_fail attr_check a/B/D/g "a/b/d/*" "-c core.ignorecase=0" && + test_must_fail attr_check A/B/D/NO "a/b/d/*" "-c core.ignorecase=0" && + attr_check A/b/h a/b/h "-c core.ignorecase=1" && + attr_check a/B/D/g "a/b/d/*" "-c core.ignorecase=1" && + attr_check A/B/D/NO "a/b/d/*" "-c core.ignorecase=1" +' + +test_expect_success 'unnormalized paths' ' + attr_check ./f f && + attr_check ./a/g a/g && + attr_check a/./g a/g && + attr_check a/c/../b/g a/b/g +' +test_expect_success 'relative paths' ' + (cd a && attr_check ../f f) && + (cd a && attr_check f f) && + (cd a && attr_check i a/i) && + (cd a && attr_check g a/g) && + (cd a && attr_check b/g a/b/g) && + (cd b && attr_check ../a/f f) && + (cd b && attr_check ../a/g a/g) && + (cd b && attr_check ../a/b/g a/b/g) ' test_expect_success 'core.attributesfile' ' @@ -66,48 +165,43 @@ test_expect_success 'core.attributesfile' ' attr_check global global && git config core.attributesfile "~/global-gitattributes" && attr_check global global && - echo "global test=precedence" >> .gitattributes && + echo "global test=precedence" >>.gitattributes && attr_check global precedence ' test_expect_success 'attribute test: read paths from stdin' ' - - cat <<EOF > expect && -f: test: f -a/f: test: f -a/c/f: test: f -a/g: test: a/g -a/b/g: test: a/b/g -b/g: test: unspecified -a/b/h: test: a/b/h -a/b/d/g: test: a/b/d/* -onoff: test: unset -offon: test: set -no: test: unspecified -a/b/d/no: test: a/b/d/* -a/b/d/yes: test: unspecified -EOF - - sed -e "s/:.*//" < expect | git check-attr --stdin test > actual && + grep -v notest <expect-all >expect && + sed -e "s/:.*//" <expect | git check-attr --stdin test >actual && test_cmp expect actual ' -test_expect_success 'root subdir attribute test' ' +test_expect_success 'attribute test: --all option' ' + grep -v unspecified <expect-all | sort >specified-all && + sed -e "s/:.*//" <expect-all | uniq >stdin-all && + git check-attr --stdin --all <stdin-all | sort >actual && + test_cmp specified-all actual +' + +test_expect_success 'attribute test: --cached option' ' + : >empty && + git check-attr --cached --stdin --all <stdin-all | sort >actual && + test_cmp empty actual && + git add .gitattributes a/.gitattributes a/b/.gitattributes && + git check-attr --cached --stdin --all <stdin-all | sort >actual && + test_cmp specified-all actual +' +test_expect_success 'root subdir attribute test' ' attr_check a/i a/i && attr_check subdir/a/i unspecified - ' test_expect_success 'setup bare' ' - git clone --bare . bare.git && cd bare.git - ' test_expect_success 'bare repository: check that .gitattribute is ignored' ' - ( echo "f test=f" echo "a/i test=a/i" @@ -117,11 +211,16 @@ test_expect_success 'bare repository: check that .gitattribute is ignored' ' attr_check a/c/f unspecified && attr_check a/i unspecified && attr_check subdir/a/i unspecified +' +test_expect_success 'bare repository: check that --cached honors index' ' + GIT_INDEX_FILE=../.git/index \ + git check-attr --cached --stdin --all <../stdin-all | + sort >actual && + test_cmp ../specified-all actual ' test_expect_success 'bare repository: test info/attributes' ' - ( echo "f test=f" echo "a/i test=a/i" @@ -131,7 +230,6 @@ test_expect_success 'bare repository: test info/attributes' ' attr_check a/c/f f && attr_check a/i a/i && attr_check subdir/a/i unspecified - ' test_done diff --git a/t/t0006-date.sh b/t/t0006-date.sh index f87abb5a06..1d29810a7a 100755 --- a/t/t0006-date.sh +++ b/t/t0006-date.sh @@ -40,6 +40,12 @@ check_parse 2008-02 bad check_parse 2008-02-14 bad check_parse '2008-02-14 20:30:45' '2008-02-14 20:30:45 +0000' check_parse '2008-02-14 20:30:45 -0500' '2008-02-14 20:30:45 -0500' +check_parse '2008-02-14 20:30:45 -0015' '2008-02-14 20:30:45 -0015' +check_parse '2008-02-14 20:30:45 -5' '2008-02-14 20:30:45 +0000' +check_parse '2008-02-14 20:30:45 -5:' '2008-02-14 20:30:45 +0000' +check_parse '2008-02-14 20:30:45 -05' '2008-02-14 20:30:45 -0500' +check_parse '2008-02-14 20:30:45 -:30' '2008-02-14 20:30:45 +0000' +check_parse '2008-02-14 20:30:45 -05:00' '2008-02-14 20:30:45 -0500' check_parse '2008-02-14 20:30:45' '2008-02-14 20:30:45 -0500' EST5 check_approxidate() { diff --git a/t/t0040-parse-options.sh b/t/t0040-parse-options.sh index 007f39d5e1..a1e4616feb 100755 --- a/t/t0040-parse-options.sh +++ b/t/t0040-parse-options.sh @@ -87,7 +87,7 @@ EOF test_expect_success 'long options' ' test-parse-options --boolean --integer 1729 --boolean --string2=321 \ --verbose --verbose --no-dry-run --abbrev=10 --file fi.le\ - > output 2> output.err && + --obsolete > output 2> output.err && test ! -s output.err && test_cmp expect output ' diff --git a/t/t1011-read-tree-sparse-checkout.sh b/t/t1011-read-tree-sparse-checkout.sh index 018c3546b6..5c0053a20b 100755 --- a/t/t1011-read-tree-sparse-checkout.sh +++ b/t/t1011-read-tree-sparse-checkout.sh @@ -234,4 +234,20 @@ test_expect_success 'read-tree --reset removes outside worktree' ' test_cmp empty result ' +test_expect_success 'print errors when failed to update worktree' ' + echo sub >.git/info/sparse-checkout && + git checkout -f init && + mkdir sub && + touch sub/added sub/addedtoo && + test_must_fail git checkout top 2>actual && + cat >expected <<\EOF && +error: The following untracked working tree files would be overwritten by checkout: + sub/added + sub/addedtoo +Please move or remove them before you can switch branches. +Aborting +EOF + test_cmp expected actual +' + test_done diff --git a/t/t1013-loose-object-format.sh b/t/t1013-loose-object-format.sh new file mode 100755 index 0000000000..0a9cedd374 --- /dev/null +++ b/t/t1013-loose-object-format.sh @@ -0,0 +1,66 @@ +#!/bin/sh +# +# Copyright (c) 2011 Roberto Tyley +# + +test_description='Correctly identify and parse loose object headers + +There are two file formats for loose objects - the original standard +format, and the experimental format introduced with Git v1.4.3, later +deprecated with v1.5.3. Although Git no longer writes the +experimental format, objects in both formats must be read, with the +format for a given file being determined by the header. + +Detecting file format based on header is not entirely trivial, not +least because the first byte of a zlib-deflated stream will vary +depending on how much memory was allocated for the deflation window +buffer when the object was written out (for example 4KB on Android, +rather that 32KB on a normal PC). + +The loose objects used as test vectors have been generated with the +following Git versions: + +standard format: Git v1.7.4.1 +experimental format: Git v1.4.3 (legacyheaders=false) +standard format, deflated with 4KB window size: Agit/JGit on Android +' + +. ./test-lib.sh + +assert_blob_equals() { + printf "%s" "$2" >expected && + git cat-file -p "$1" >actual && + test_cmp expected actual +} + +test_expect_success setup ' + cp -R "$TEST_DIRECTORY/t1013/objects" .git/ + git --version +' + +test_expect_success 'read standard-format loose objects' ' + git cat-file tag 8d4e360d6c70fbd72411991c02a09c442cf7a9fa && + git cat-file commit 6baee0540ea990d9761a3eb9ab183003a71c3696 && + git ls-tree 7a37b887a73791d12d26c0d3e39568a8fb0fa6e8 && + assert_blob_equals "257cc5642cb1a054f08cc83f2d943e56fd3ebe99" "foo$LF" +' + +test_expect_success 'read experimental-format loose objects' ' + git cat-file tag 76e7fa9941f4d5f97f64fea65a2cba436bc79cbb && + git cat-file commit 7875c6237d3fcdd0ac2f0decc7d3fa6a50b66c09 && + git ls-tree 95b1625de3ba8b2214d1e0d0591138aea733f64f && + assert_blob_equals "2e65efe2a145dda7ee51d1741299f848e5bf752e" "a" && + assert_blob_equals "9ae9e86b7bd6cb1472d9373702d8249973da0832" "ab" && + assert_blob_equals "85df50785d62d3b05ab03d9cbf7e4a0b49449730" "abcd" && + assert_blob_equals "1656f9233d999f61ef23ef390b9c71d75399f435" "abcdefgh" && + assert_blob_equals "1e72a6b2c4a577ab0338860fa9fe87f761fc9bbd" "abcdefghi" && + assert_blob_equals "70e6a83d8dcb26fc8bc0cf702e2ddeb6adca18fd" "abcdefghijklmnop" && + assert_blob_equals "bd15045f6ce8ff75747562173640456a394412c8" "abcdefghijklmnopqrstuvwx" +' + +test_expect_success 'read standard-format objects deflated with smaller window buffer' ' + git cat-file tag f816d5255855ac160652ee5253b06cd8ee14165a && + git cat-file tag 149cedb5c46929d18e0f118e9fa31927487af3b6 +' + +test_done diff --git a/t/t1013/objects/14/9cedb5c46929d18e0f118e9fa31927487af3b6 b/t/t1013/objects/14/9cedb5c46929d18e0f118e9fa31927487af3b6 Binary files differnew file mode 100644 index 0000000000..472fd1458e --- /dev/null +++ b/t/t1013/objects/14/9cedb5c46929d18e0f118e9fa31927487af3b6 diff --git a/t/t1013/objects/16/56f9233d999f61ef23ef390b9c71d75399f435 b/t/t1013/objects/16/56f9233d999f61ef23ef390b9c71d75399f435 Binary files differnew file mode 100644 index 0000000000..c379d74ae2 --- /dev/null +++ b/t/t1013/objects/16/56f9233d999f61ef23ef390b9c71d75399f435 diff --git a/t/t1013/objects/1e/72a6b2c4a577ab0338860fa9fe87f761fc9bbd b/t/t1013/objects/1e/72a6b2c4a577ab0338860fa9fe87f761fc9bbd Binary files differnew file mode 100644 index 0000000000..93706305bc --- /dev/null +++ b/t/t1013/objects/1e/72a6b2c4a577ab0338860fa9fe87f761fc9bbd diff --git a/t/t1013/objects/25/7cc5642cb1a054f08cc83f2d943e56fd3ebe99 b/t/t1013/objects/25/7cc5642cb1a054f08cc83f2d943e56fd3ebe99 Binary files differnew file mode 100644 index 0000000000..bdcf704c9e --- /dev/null +++ b/t/t1013/objects/25/7cc5642cb1a054f08cc83f2d943e56fd3ebe99 diff --git a/t/t1013/objects/2e/65efe2a145dda7ee51d1741299f848e5bf752e b/t/t1013/objects/2e/65efe2a145dda7ee51d1741299f848e5bf752e Binary files differnew file mode 100644 index 0000000000..ad62c43e41 --- /dev/null +++ b/t/t1013/objects/2e/65efe2a145dda7ee51d1741299f848e5bf752e diff --git a/t/t1013/objects/6b/aee0540ea990d9761a3eb9ab183003a71c3696 b/t/t1013/objects/6b/aee0540ea990d9761a3eb9ab183003a71c3696 Binary files differnew file mode 100644 index 0000000000..3d2f0337db --- /dev/null +++ b/t/t1013/objects/6b/aee0540ea990d9761a3eb9ab183003a71c3696 diff --git a/t/t1013/objects/70/e6a83d8dcb26fc8bc0cf702e2ddeb6adca18fd b/t/t1013/objects/70/e6a83d8dcb26fc8bc0cf702e2ddeb6adca18fd Binary files differnew file mode 100644 index 0000000000..b3f71a6ee5 --- /dev/null +++ b/t/t1013/objects/70/e6a83d8dcb26fc8bc0cf702e2ddeb6adca18fd diff --git a/t/t1013/objects/76/e7fa9941f4d5f97f64fea65a2cba436bc79cbb b/t/t1013/objects/76/e7fa9941f4d5f97f64fea65a2cba436bc79cbb new file mode 100644 index 0000000000..af4e9a7b0c --- /dev/null +++ b/t/t1013/objects/76/e7fa9941f4d5f97f64fea65a2cba436bc79cbb @@ -0,0 +1,2 @@ +x%A0@}O1{cSZ(νthZޠ?
m6di9GhبZR'QRpqL9=gsIoopeϫ_1$*SiNwpPRB +[(d-L9
\ No newline at end of file diff --git a/t/t1013/objects/78/75c6237d3fcdd0ac2f0decc7d3fa6a50b66c09 b/t/t1013/objects/78/75c6237d3fcdd0ac2f0decc7d3fa6a50b66c09 Binary files differnew file mode 100644 index 0000000000..3dd28be5c6 --- /dev/null +++ b/t/t1013/objects/78/75c6237d3fcdd0ac2f0decc7d3fa6a50b66c09 diff --git a/t/t1013/objects/7a/37b887a73791d12d26c0d3e39568a8fb0fa6e8 b/t/t1013/objects/7a/37b887a73791d12d26c0d3e39568a8fb0fa6e8 Binary files differnew file mode 100644 index 0000000000..2b97b264c3 --- /dev/null +++ b/t/t1013/objects/7a/37b887a73791d12d26c0d3e39568a8fb0fa6e8 diff --git a/t/t1013/objects/85/df50785d62d3b05ab03d9cbf7e4a0b49449730 b/t/t1013/objects/85/df50785d62d3b05ab03d9cbf7e4a0b49449730 Binary files differnew file mode 100644 index 0000000000..6dff746876 --- /dev/null +++ b/t/t1013/objects/85/df50785d62d3b05ab03d9cbf7e4a0b49449730 diff --git a/t/t1013/objects/8d/4e360d6c70fbd72411991c02a09c442cf7a9fa b/t/t1013/objects/8d/4e360d6c70fbd72411991c02a09c442cf7a9fa Binary files differnew file mode 100644 index 0000000000..cb41e92d07 --- /dev/null +++ b/t/t1013/objects/8d/4e360d6c70fbd72411991c02a09c442cf7a9fa diff --git a/t/t1013/objects/95/b1625de3ba8b2214d1e0d0591138aea733f64f b/t/t1013/objects/95/b1625de3ba8b2214d1e0d0591138aea733f64f Binary files differnew file mode 100644 index 0000000000..7ac46b4f70 --- /dev/null +++ b/t/t1013/objects/95/b1625de3ba8b2214d1e0d0591138aea733f64f diff --git a/t/t1013/objects/9a/e9e86b7bd6cb1472d9373702d8249973da0832 b/t/t1013/objects/9a/e9e86b7bd6cb1472d9373702d8249973da0832 Binary files differnew file mode 100644 index 0000000000..9d8316d4e5 --- /dev/null +++ b/t/t1013/objects/9a/e9e86b7bd6cb1472d9373702d8249973da0832 diff --git a/t/t1013/objects/bd/15045f6ce8ff75747562173640456a394412c8 b/t/t1013/objects/bd/15045f6ce8ff75747562173640456a394412c8 Binary files differnew file mode 100644 index 0000000000..eebf23956e --- /dev/null +++ b/t/t1013/objects/bd/15045f6ce8ff75747562173640456a394412c8 diff --git a/t/t1013/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 b/t/t1013/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 Binary files differnew file mode 100644 index 0000000000..134cf19379 --- /dev/null +++ b/t/t1013/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/t/t1013/objects/f8/16d5255855ac160652ee5253b06cd8ee14165a b/t/t1013/objects/f8/16d5255855ac160652ee5253b06cd8ee14165a new file mode 100644 index 0000000000..26b75aec56 --- /dev/null +++ b/t/t1013/objects/f8/16d5255855ac160652ee5253b06cd8ee14165a @@ -0,0 +1 @@ +H0a{
Ie&*G^D҆wUҗS4 ,f[VAۺx6[wtGLu?@"g{+by%M
\ No newline at end of file diff --git a/t/t1020-subdirectory.sh b/t/t1020-subdirectory.sh index 865b8ed26d..3b1b985996 100755 --- a/t/t1020-subdirectory.sh +++ b/t/t1020-subdirectory.sh @@ -17,8 +17,6 @@ test_expect_success setup ' cp one original.one && cp dir/two original.two ' -LF=' -' test_expect_success 'update-index and ls-files' ' git update-index --add one && diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh index 3e140c18f4..fba5ae0d18 100755 --- a/t/t1300-repo-config.sh +++ b/t/t1300-repo-config.sh @@ -7,28 +7,28 @@ test_description='Test git config in different settings' . ./test-lib.sh -test -f .git/config && rm .git/config - -git config core.penguin "little blue" +test_expect_success 'clear default config' ' + rm -f .git/config +' cat > expect << EOF [core] penguin = little blue EOF - -test_expect_success 'initial' 'cmp .git/config expect' - -git config Core.Movie BadPhysics +test_expect_success 'initial' ' + git config core.penguin "little blue" && + test_cmp expect .git/config +' cat > expect << EOF [core] penguin = little blue Movie = BadPhysics EOF - -test_expect_success 'mixed case' 'cmp .git/config expect' - -git config Cores.WhatEver Second +test_expect_success 'mixed case' ' + git config Core.Movie BadPhysics && + test_cmp expect .git/config +' cat > expect << EOF [core] @@ -37,10 +37,10 @@ cat > expect << EOF [Cores] WhatEver = Second EOF - -test_expect_success 'similar section' 'cmp .git/config expect' - -git config CORE.UPPERCASE true +test_expect_success 'similar section' ' + git config Cores.WhatEver Second + test_cmp expect .git/config +' cat > expect << EOF [core] @@ -50,8 +50,10 @@ cat > expect << EOF [Cores] WhatEver = Second EOF - -test_expect_success 'similar section' 'cmp .git/config expect' +test_expect_success 'uppercase section' ' + git config CORE.UPPERCASE true && + test_cmp expect .git/config +' test_expect_success 'replace with non-match' \ 'git config core.penguin kingpin !blue' @@ -69,7 +71,34 @@ cat > expect << EOF WhatEver = Second EOF -test_expect_success 'non-match result' 'cmp .git/config expect' +test_expect_success 'non-match result' 'test_cmp expect .git/config' + +test_expect_success 'find mixed-case key by canonical name' ' + echo Second >expect && + git config cores.whatever >actual && + test_cmp expect actual +' + +test_expect_success 'find mixed-case key by non-canonical name' ' + echo Second >expect && + git config CoReS.WhAtEvEr >actual && + test_cmp expect actual +' + +test_expect_success 'subsections are not canonicalized by git-config' ' + cat >>.git/config <<-\EOF && + [section.SubSection] + key = one + [section "SubSection"] + key = two + EOF + echo one >expect && + git config section.subsection.key >actual && + test_cmp expect actual && + echo two >expect && + git config section.SubSection.key >actual && + test_cmp expect actual +' cat > .git/config <<\EOF [alpha] @@ -88,7 +117,7 @@ bar = foo [beta] EOF -test_expect_success 'unset with cont. lines is correct' 'cmp .git/config expect' +test_expect_success 'unset with cont. lines is correct' 'test_cmp expect .git/config' cat > .git/config << EOF [beta] ; silly comment # another comment @@ -116,7 +145,7 @@ noIndent= sillyValue ; 'nother silly comment [nextSection] noNewline = ouch EOF -test_expect_success 'multiple unset is correct' 'cmp .git/config expect' +test_expect_success 'multiple unset is correct' 'test_cmp expect .git/config' cp .git/config2 .git/config @@ -140,9 +169,7 @@ noIndent= sillyValue ; 'nother silly comment [nextSection] noNewline = ouch EOF -test_expect_success 'all replaced' 'cmp .git/config expect' - -git config beta.haha alpha +test_expect_success 'all replaced' 'test_cmp expect .git/config' cat > expect << EOF [beta] ; silly comment # another comment @@ -153,10 +180,10 @@ noIndent= sillyValue ; 'nother silly comment haha = alpha [nextSection] noNewline = ouch EOF - -test_expect_success 'really mean test' 'cmp .git/config expect' - -git config nextsection.nonewline wow +test_expect_success 'really mean test' ' + git config beta.haha alpha && + test_cmp expect .git/config +' cat > expect << EOF [beta] ; silly comment # another comment @@ -168,11 +195,12 @@ noIndent= sillyValue ; 'nother silly comment [nextSection] nonewline = wow EOF - -test_expect_success 'really really mean test' 'cmp .git/config expect' +test_expect_success 'really really mean test' ' + git config nextsection.nonewline wow && + test_cmp expect .git/config +' test_expect_success 'get value' 'test alpha = $(git config beta.haha)' -git config --unset beta.haha cat > expect << EOF [beta] ; silly comment # another comment @@ -183,10 +211,10 @@ noIndent= sillyValue ; 'nother silly comment [nextSection] nonewline = wow EOF - -test_expect_success 'unset' 'cmp .git/config expect' - -git config nextsection.NoNewLine "wow2 for me" "for me$" +test_expect_success 'unset' ' + git config --unset beta.haha && + test_cmp expect .git/config +' cat > expect << EOF [beta] ; silly comment # another comment @@ -198,8 +226,10 @@ noIndent= sillyValue ; 'nother silly comment nonewline = wow NoNewLine = wow2 for me EOF - -test_expect_success 'multivar' 'cmp .git/config expect' +test_expect_success 'multivar' ' + git config nextsection.NoNewLine "wow2 for me" "for me$" && + test_cmp expect .git/config +' test_expect_success 'non-match' \ 'git config --get nextsection.nonewline !for' @@ -214,8 +244,6 @@ test_expect_success 'ambiguous get' ' test_expect_success 'get multivar' \ 'git config --get-all nextsection.nonewline' -git config nextsection.nonewline "wow3" "wow$" - cat > expect << EOF [beta] ; silly comment # another comment noIndent= sillyValue ; 'nother silly comment @@ -226,8 +254,10 @@ noIndent= sillyValue ; 'nother silly comment nonewline = wow3 NoNewLine = wow2 for me EOF - -test_expect_success 'multivar replace' 'cmp .git/config expect' +test_expect_success 'multivar replace' ' + git config nextsection.nonewline "wow3" "wow$" && + test_cmp expect .git/config +' test_expect_success 'ambiguous value' ' test_must_fail git config nextsection.nonewline @@ -241,8 +271,6 @@ test_expect_success 'invalid unset' ' test_must_fail git config --unset somesection.nonewline ' -git config --unset nextsection.nonewline "wow3$" - cat > expect << EOF [beta] ; silly comment # another comment noIndent= sillyValue ; 'nother silly comment @@ -253,7 +281,10 @@ noIndent= sillyValue ; 'nother silly comment NoNewLine = wow2 for me EOF -test_expect_success 'multivar unset' 'cmp .git/config expect' +test_expect_success 'multivar unset' ' + git config --unset nextsection.nonewline "wow3$" && + test_cmp expect .git/config +' test_expect_success 'invalid key' 'test_must_fail git config inval.2key blabla' @@ -276,7 +307,7 @@ noIndent= sillyValue ; 'nother silly comment Alpha = beta EOF -test_expect_success 'hierarchical section value' 'cmp .git/config expect' +test_expect_success 'hierarchical section value' 'test_cmp expect .git/config' cat > expect << EOF beta.noindent=sillyValue @@ -304,15 +335,16 @@ EOF test_expect_success '--get-regexp' \ 'git config --get-regexp in > output && cmp output expect' -git config --add nextsection.nonewline "wow4 for you" - cat > expect << EOF wow2 for me wow4 for you EOF -test_expect_success '--add' \ - 'git config --get-all nextsection.nonewline > output && cmp output expect' +test_expect_success '--add' ' + git config --add nextsection.nonewline "wow4 for you" && + git config --get-all nextsection.nonewline > output && + test_cmp expect output +' cat > .git/config << EOF [novalue] @@ -333,6 +365,12 @@ test_expect_success 'get-regexp variable with no value' \ 'git config --get-regexp novalue > output && cmp output expect' +echo 'novalue.variable true' > expect + +test_expect_success 'get-regexp --bool variable with no value' \ + 'git config --bool --get-regexp novalue > output && + cmp output expect' + echo 'emptyvalue.variable ' > expect test_expect_success 'get-regexp variable with empty value' \ @@ -361,8 +399,6 @@ cat > .git/config << EOF c = d EOF -git config a.x y - cat > expect << EOF [a.b] c = d @@ -370,10 +406,10 @@ cat > expect << EOF x = y EOF -test_expect_success 'new section is partial match of another' 'cmp .git/config expect' - -git config b.x y -git config a.b c +test_expect_success 'new section is partial match of another' ' + git config a.x y && + test_cmp expect .git/config +' cat > expect << EOF [a.b] @@ -385,7 +421,11 @@ cat > expect << EOF x = y EOF -test_expect_success 'new variable inserts into proper section' 'cmp .git/config expect' +test_expect_success 'new variable inserts into proper section' ' + git config b.x y && + git config a.b c && + test_cmp expect .git/config +' test_expect_success 'alternative GIT_CONFIG (non-existing file should fail)' \ 'test_must_fail git config --file non-existing-config -l' @@ -399,9 +439,10 @@ cat > expect << EOF ein.bahn=strasse EOF -GIT_CONFIG=other-config git config -l > output - -test_expect_success 'alternative GIT_CONFIG' 'cmp output expect' +test_expect_success 'alternative GIT_CONFIG' ' + GIT_CONFIG=other-config git config -l >output && + test_cmp expect output +' test_expect_success 'alternative GIT_CONFIG (--file)' \ 'git config --file other-config -l > output && cmp output expect' @@ -417,8 +458,6 @@ test_expect_success 'refer config from subdirectory' ' ' -GIT_CONFIG=other-config git config anwohner.park ausweis - cat > expect << EOF [ein] bahn = strasse @@ -426,7 +465,10 @@ cat > expect << EOF park = ausweis EOF -test_expect_success '--set in alternative GIT_CONFIG' 'cmp other-config expect' +test_expect_success '--set in alternative GIT_CONFIG' ' + GIT_CONFIG=other-config git config anwohner.park ausweis && + test_cmp expect other-config +' cat > .git/config << EOF # Hallo @@ -531,7 +573,7 @@ test_expect_success 'section ending' ' git config gitcvs.enabled true && git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite && git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite && - cmp .git/config expect + test_cmp expect .git/config ' @@ -750,13 +792,6 @@ test_expect_success NOT_MINGW 'get --path copes with unset $HOME' ' test_cmp expect result ' -rm .git/config - -git config quote.leading " test" -git config quote.ending "test " -git config quote.semicolon "test;test" -git config quote.hash "test#test" - cat > expect << EOF [quote] leading = " test" @@ -764,8 +799,14 @@ cat > expect << EOF semicolon = "test;test" hash = "test#test" EOF - -test_expect_success 'quoting' 'cmp .git/config expect' +test_expect_success 'quoting' ' + rm .git/config && + git config quote.leading " test" && + git config quote.ending "test " && + git config quote.semicolon "test;test" && + git config quote.hash "test#test" && + test_cmp expect .git/config +' test_expect_success 'key with newline' ' test_must_fail git config "key.with @@ -790,9 +831,10 @@ section.noncont=not continued section.quotecont=cont;inued EOF -git config --list > result - -test_expect_success 'value continued on next line' 'cmp result expect' +test_expect_success 'value continued on next line' ' + git config --list > result && + cmp result expect +' cat > .git/config <<\EOF [section "sub=section"] @@ -813,16 +855,17 @@ barQsection.sub=section.val3 Qsection.sub=section.val4 Qsection.sub=section.val5Q EOF +test_expect_success '--null --list' ' + git config --null --list | nul_to_q >result && + echo >>result && + test_cmp expect 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]' | perl -pe 'y/\000/Q/' > result -echo >>result - -test_expect_success '--null --get-regexp' 'cmp result expect' +test_expect_success '--null --get-regexp' ' + git config --null --get-regexp "val[0-9]" | nul_to_q >result && + echo >>result && + test_cmp expect result +' test_expect_success 'inner whitespace kept verbatim' ' git config section.val "foo bar" && diff --git a/t/t1304-default-acl.sh b/t/t1304-default-acl.sh index b5d89a2250..2b962cfda7 100755 --- a/t/t1304-default-acl.sh +++ b/t/t1304-default-acl.sh @@ -25,6 +25,11 @@ else test_set_prereq SETFACL fi +if test -z "$LOGNAME" +then + LOGNAME=$USER +fi + check_perms_and_acl () { test -r "$1" && getfacl "$1" > actual && diff --git a/t/t1402-check-ref-format.sh b/t/t1402-check-ref-format.sh index 1b0f82fa4c..1ae4d87c92 100755 --- a/t/t1402-check-ref-format.sh +++ b/t/t1402-check-ref-format.sh @@ -5,28 +5,126 @@ test_description='Test git check-ref-format' . ./test-lib.sh valid_ref() { - test_expect_success "ref name '$1' is valid" \ - "git check-ref-format '$1'" + prereq= + case $1 in + [A-Z]*) + prereq=$1 + shift + esac + test_expect_success $prereq "ref name '$1' is valid${2:+ with options $2}" " + git check-ref-format $2 '$1' + " } invalid_ref() { - test_expect_success "ref name '$1' is not valid" \ - "test_must_fail git check-ref-format '$1'" + prereq= + case $1 in + [A-Z]*) + prereq=$1 + shift + esac + test_expect_success $prereq "ref name '$1' is invalid${2:+ with options $2}" " + test_must_fail git check-ref-format $2 '$1' + " } -valid_ref 'heads/foo' -invalid_ref 'foo' +invalid_ref '' +invalid_ref NOT_MINGW '/' +invalid_ref NOT_MINGW '/' --allow-onelevel +invalid_ref NOT_MINGW '/' --normalize +invalid_ref NOT_MINGW '/' '--allow-onelevel --normalize' valid_ref 'foo/bar/baz' -valid_ref 'refs///heads/foo' +valid_ref 'foo/bar/baz' --normalize +invalid_ref 'refs///heads/foo' +valid_ref 'refs///heads/foo' --normalize invalid_ref 'heads/foo/' +invalid_ref NOT_MINGW '/heads/foo' +valid_ref NOT_MINGW '/heads/foo' --normalize +invalid_ref '///heads/foo' +valid_ref '///heads/foo' --normalize invalid_ref './foo' +invalid_ref './foo/bar' +invalid_ref 'foo/./bar' +invalid_ref 'foo/bar/.' invalid_ref '.refs/foo' invalid_ref 'heads/foo..bar' invalid_ref 'heads/foo?bar' valid_ref 'foo./bar' invalid_ref 'heads/foo.lock' +invalid_ref 'heads///foo.lock' +invalid_ref 'foo.lock/bar' +invalid_ref 'foo.lock///bar' valid_ref 'heads/foo@bar' invalid_ref 'heads/v@{ation' invalid_ref 'heads/foo\bar' +invalid_ref "$(printf 'heads/foo\t')" +invalid_ref "$(printf 'heads/foo\177')" +valid_ref "$(printf 'heads/fu\303\237')" +invalid_ref 'heads/*foo/bar' --refspec-pattern +invalid_ref 'heads/foo*/bar' --refspec-pattern +invalid_ref 'heads/f*o/bar' --refspec-pattern + +ref='foo' +invalid_ref "$ref" +valid_ref "$ref" --allow-onelevel +invalid_ref "$ref" --refspec-pattern +valid_ref "$ref" '--refspec-pattern --allow-onelevel' +invalid_ref "$ref" --normalize +valid_ref "$ref" '--allow-onelevel --normalize' + +ref='foo/bar' +valid_ref "$ref" +valid_ref "$ref" --allow-onelevel +valid_ref "$ref" --refspec-pattern +valid_ref "$ref" '--refspec-pattern --allow-onelevel' +valid_ref "$ref" --normalize + +ref='foo/*' +invalid_ref "$ref" +invalid_ref "$ref" --allow-onelevel +valid_ref "$ref" --refspec-pattern +valid_ref "$ref" '--refspec-pattern --allow-onelevel' + +ref='*/foo' +invalid_ref "$ref" +invalid_ref "$ref" --allow-onelevel +valid_ref "$ref" --refspec-pattern +valid_ref "$ref" '--refspec-pattern --allow-onelevel' +invalid_ref "$ref" --normalize +valid_ref "$ref" '--refspec-pattern --normalize' + +ref='foo/*/bar' +invalid_ref "$ref" +invalid_ref "$ref" --allow-onelevel +valid_ref "$ref" --refspec-pattern +valid_ref "$ref" '--refspec-pattern --allow-onelevel' + +ref='*' +invalid_ref "$ref" +invalid_ref "$ref" --allow-onelevel +invalid_ref "$ref" --refspec-pattern +valid_ref "$ref" '--refspec-pattern --allow-onelevel' + +ref='foo/*/*' +invalid_ref "$ref" --refspec-pattern +invalid_ref "$ref" '--refspec-pattern --allow-onelevel' + +ref='*/foo/*' +invalid_ref "$ref" --refspec-pattern +invalid_ref "$ref" '--refspec-pattern --allow-onelevel' + +ref='*/*/foo' +invalid_ref "$ref" --refspec-pattern +invalid_ref "$ref" '--refspec-pattern --allow-onelevel' + +ref='/foo' +invalid_ref NOT_MINGW "$ref" +invalid_ref NOT_MINGW "$ref" --allow-onelevel +invalid_ref NOT_MINGW "$ref" --refspec-pattern +invalid_ref NOT_MINGW "$ref" '--refspec-pattern --allow-onelevel' +invalid_ref NOT_MINGW "$ref" --normalize +valid_ref NOT_MINGW "$ref" '--allow-onelevel --normalize' +invalid_ref NOT_MINGW "$ref" '--refspec-pattern --normalize' +valid_ref NOT_MINGW "$ref" '--refspec-pattern --allow-onelevel --normalize' test_expect_success "check-ref-format --branch @{-1}" ' T=$(git write-tree) && @@ -59,20 +157,41 @@ test_expect_success 'check-ref-format --branch from subdir' ' ' valid_ref_normalized() { - test_expect_success "ref name '$1' simplifies to '$2'" " - refname=\$(git check-ref-format --print '$1') && - test \"\$refname\" = '$2'" + prereq= + case $1 in + [A-Z]*) + prereq=$1 + shift + esac + test_expect_success $prereq "ref name '$1' simplifies to '$2'" " + refname=\$(git check-ref-format --normalize '$1') && + test \"\$refname\" = '$2' + " } invalid_ref_normalized() { - test_expect_success "check-ref-format --print rejects '$1'" " - test_must_fail git check-ref-format --print '$1'" + prereq= + case $1 in + [A-Z]*) + prereq=$1 + shift + esac + test_expect_success $prereq "check-ref-format --normalize rejects '$1'" " + test_must_fail git check-ref-format --normalize '$1' + " } valid_ref_normalized 'heads/foo' 'heads/foo' valid_ref_normalized 'refs///heads/foo' 'refs/heads/foo' +valid_ref_normalized NOT_MINGW '/heads/foo' 'heads/foo' +valid_ref_normalized '///heads/foo' 'heads/foo' invalid_ref_normalized 'foo' +invalid_ref_normalized NOT_MINGW '/foo' invalid_ref_normalized 'heads/foo/../bar' invalid_ref_normalized 'heads/./foo' invalid_ref_normalized 'heads\foo' +invalid_ref_normalized 'heads/foo.lock' +invalid_ref_normalized 'heads///foo.lock' +invalid_ref_normalized 'foo.lock/bar' +invalid_ref_normalized 'foo.lock///bar' test_done diff --git a/t/t1412-reflog-loop.sh b/t/t1412-reflog-loop.sh index 7f519e5ebe..647d888507 100755 --- a/t/t1412-reflog-loop.sh +++ b/t/t1412-reflog-loop.sh @@ -21,10 +21,10 @@ test_expect_success 'setup reflog with alternating commits' ' test_expect_success 'reflog shows all entries' ' cat >expect <<-\EOF - topic@{0} two: updating HEAD - topic@{1} one: updating HEAD - topic@{2} two: updating HEAD - topic@{3} one: updating HEAD + topic@{0} reset: moving to two + topic@{1} reset: moving to one + topic@{2} reset: moving to two + topic@{3} reset: moving to one topic@{4} branch: Created from HEAD EOF git log -g --format="%gd %gs" topic >actual && diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index bb01d5ab8f..523ce9c45b 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -110,6 +110,42 @@ test_expect_success 'email with embedded > is not okay' ' grep "error in commit $new" out ' +test_expect_success 'missing < email delimiter is reported nicely' ' + git cat-file commit HEAD >basis && + sed "s/<//" basis >bad-email-2 && + new=$(git hash-object -t commit -w --stdin <bad-email-2) && + test_when_finished "remove_object $new" && + git update-ref refs/heads/bogus "$new" && + test_when_finished "git update-ref -d refs/heads/bogus" && + git fsck 2>out && + cat out && + grep "error in commit $new.* - bad name" out +' + +test_expect_success 'missing email is reported nicely' ' + git cat-file commit HEAD >basis && + sed "s/[a-z]* <[^>]*>//" basis >bad-email-3 && + new=$(git hash-object -t commit -w --stdin <bad-email-3) && + test_when_finished "remove_object $new" && + git update-ref refs/heads/bogus "$new" && + test_when_finished "git update-ref -d refs/heads/bogus" && + git fsck 2>out && + cat out && + grep "error in commit $new.* - missing email" out +' + +test_expect_success '> in name is reported' ' + git cat-file commit HEAD >basis && + sed "s/ </> </" basis >bad-email-4 && + new=$(git hash-object -t commit -w --stdin <bad-email-4) && + test_when_finished "remove_object $new" && + git update-ref refs/heads/bogus "$new" && + test_when_finished "git update-ref -d refs/heads/bogus" && + git fsck 2>out && + cat out && + grep "error in commit $new" out +' + test_expect_success 'tag pointing to nonexistent' ' cat >invalid-tag <<-\EOF && object ffffffffffffffffffffffffffffffffffffffff diff --git a/t/t2018-checkout-branch.sh b/t/t2018-checkout-branch.sh index a42e03967b..75874e85df 100755 --- a/t/t2018-checkout-branch.sh +++ b/t/t2018-checkout-branch.sh @@ -118,6 +118,15 @@ test_expect_success 'checkout -b to an existing branch fails' ' test_must_fail do_checkout branch2 $HEAD2 ' +test_expect_success 'checkout -b to @{-1} fails with the right branch name' ' + git reset --hard HEAD && + git checkout branch1 && + git checkout branch2 && + echo >expect "fatal: A branch named '\''branch1'\'' already exists." && + test_must_fail git checkout -b @{-1} 2>actual && + test_cmp expect actual +' + test_expect_success 'checkout -B to an existing branch resets branch to HEAD' ' git checkout branch1 && @@ -180,4 +189,12 @@ test_expect_success 'checkout -b <describe>' ' test_cmp expect actual ' +test_expect_success 'checkout -B to the current branch fails before merging' ' + git checkout branch1 && + setup_dirty_mergeable && + git commit -mfooble && + test_must_fail git checkout -B branch1 initial && + test_must_fail test_dirty_mergeable +' + test_done diff --git a/t/t2020-checkout-detach.sh b/t/t2020-checkout-detach.sh index 2366f0f414..068fba4c8e 100755 --- a/t/t2020-checkout-detach.sh +++ b/t/t2020-checkout-detach.sh @@ -12,11 +12,14 @@ check_not_detached () { } ORPHAN_WARNING='you are leaving .* commit.*behind' +PREV_HEAD_DESC='Previous HEAD position was' check_orphan_warning() { - test_i18ngrep "$ORPHAN_WARNING" "$1" + test_i18ngrep "$ORPHAN_WARNING" "$1" && + test_i18ngrep ! "$PREV_HEAD_DESC" "$1" } check_no_orphan_warning() { - test_i18ngrep ! "$ORPHAN_WARNING" "$1" + test_i18ngrep ! "$ORPHAN_WARNING" "$1" && + test_i18ngrep "$PREV_HEAD_DESC" "$1" } reset () { diff --git a/t/t2022-checkout-paths.sh b/t/t2022-checkout-paths.sh new file mode 100755 index 0000000000..56090d2eba --- /dev/null +++ b/t/t2022-checkout-paths.sh @@ -0,0 +1,42 @@ +#!/bin/sh + +test_description='checkout $tree -- $paths' +. ./test-lib.sh + +test_expect_success setup ' + mkdir dir && + >dir/master && + echo common >dir/common && + git add dir/master dir/common && + test_tick && git commit -m "master has dir/master" && + git checkout -b next && + git mv dir/master dir/next0 && + echo next >dir/next1 && + git add dir && + test_tick && git commit -m "next has dir/next but not dir/master" +' + +test_expect_success 'checking out paths out of a tree does not clobber unrelated paths' ' + git checkout next && + git reset --hard && + rm dir/next0 && + cat dir/common >expect.common && + echo modified >expect.next1 && + cat expect.next1 >dir/next1 && + echo untracked >expect.next2 && + cat expect.next2 >dir/next2 && + + git checkout master dir && + + test_cmp expect.common dir/common && + test_path_is_file dir/master && + git diff --exit-code master dir/master && + + test_path_is_missing dir/next0 && + test_cmp expect.next1 dir/next1 && + test_path_is_file dir/next2 && + test_must_fail git ls-files --error-unmatch dir/next2 && + test_cmp expect.next2 dir/next2 +' + +test_done diff --git a/t/t3000-ls-files-others.sh b/t/t3000-ls-files-others.sh index 2eec0118c4..e9160dfc1d 100755 --- a/t/t3000-ls-files-others.sh +++ b/t/t3000-ls-files-others.sh @@ -65,4 +65,23 @@ test_expect_success '--no-empty-directory hides empty directory' ' test_cmp expected3 output ' +test_expect_success SYMLINKS 'ls-files --others with symlinked submodule' ' + git init super && + git init sub && + ( + cd sub && + >a && + git add a && + git commit -m sub && + git pack-refs --all + ) && + ( + cd super && + "$TEST_DIRECTORY/../contrib/workdir/git-new-workdir" ../sub sub + git ls-files --others --exclude-standard >../actual + ) && + echo sub/ >expect && + test_cmp expect actual +' + test_done diff --git a/t/t3005-ls-files-relative.sh b/t/t3005-ls-files-relative.sh new file mode 100755 index 0000000000..377869432e --- /dev/null +++ b/t/t3005-ls-files-relative.sh @@ -0,0 +1,72 @@ +#!/bin/sh + +test_description='ls-files tests with relative paths + +This test runs git ls-files with various relative path arguments. +' + +. ./test-lib.sh + +new_line=' +' +sq=\' + +test_expect_success 'prepare' ' + : >never-mind-me && + git add never-mind-me && + mkdir top && + ( + cd top && + mkdir sub && + x="x xa xbc xdef xghij xklmno" && + y=$(echo "$x" | tr x y) && + touch $x && + touch $y && + cd sub && + git add ../x* + ) +' + +test_expect_success 'ls-files with mixed levels' ' + ( + cd top/sub && + cat >expect <<-EOF && + ../../never-mind-me + ../x + EOF + git ls-files $(cat expect) >actual && + test_cmp expect actual + ) +' + +test_expect_success 'ls-files -c' ' + ( + cd top/sub && + for f in ../y* + do + echo "error: pathspec $sq$f$sq did not match any file(s) known to git." + done >expect.err && + echo "Did you forget to ${sq}git add${sq}?" >>expect.err && + ls ../x* >expect.out && + test_must_fail git ls-files -c --error-unmatch ../[xy]* >actual.out 2>actual.err && + test_cmp expect.out actual.out && + test_cmp expect.err actual.err + ) +' + +test_expect_success 'ls-files -o' ' + ( + cd top/sub && + for f in ../x* + do + echo "error: pathspec $sq$f$sq did not match any file(s) known to git." + done >expect.err && + echo "Did you forget to ${sq}git add${sq}?" >>expect.err && + ls ../y* >expect.out && + test_must_fail git ls-files -o --error-unmatch ../[xy]* >actual.out 2>actual.err && + test_cmp expect.out actual.out && + test_cmp expect.err actual.err + ) +' + +test_done diff --git a/t/t3030-merge-recursive.sh b/t/t3030-merge-recursive.sh index 0c02d56952..55ef1895d7 100755 --- a/t/t3030-merge-recursive.sh +++ b/t/t3030-merge-recursive.sh @@ -267,7 +267,8 @@ test_expect_success 'setup 8' ' ln -s e a && git add a e && test_tick && - git commit -m "rename a->e, symlink a->e" + git commit -m "rename a->e, symlink a->e" && + oln=`printf e | git hash-object --stdin` fi ' @@ -630,16 +631,18 @@ test_expect_success 'merge-recursive copy vs. rename' ' if test_have_prereq SYMLINKS then - test_expect_success 'merge-recursive rename vs. rename/symlink' ' + test_expect_failure 'merge-recursive rename vs. rename/symlink' ' git checkout -f rename && git merge rename-ln && ( git ls-tree -r HEAD ; git ls-files -s ) >actual && ( + echo "120000 blob $oln a" echo "100644 blob $o0 b" echo "100644 blob $o0 c" echo "100644 blob $o0 d/e" echo "100644 blob $o0 e" + echo "120000 $oln 0 a" echo "100644 $o0 0 b" echo "100644 $o0 0 c" echo "100644 $o0 0 d/e" diff --git a/t/t3103-ls-tree-misc.sh b/t/t3103-ls-tree-misc.sh new file mode 100755 index 0000000000..09dcf043fd --- /dev/null +++ b/t/t3103-ls-tree-misc.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +test_description=' +Miscellaneous tests for git ls-tree. + + 1. git ls-tree fails in presence of tree damage. + +' + +. ./test-lib.sh + +test_expect_success 'setup' ' + mkdir a && + touch a/one && + git add a/one && + git commit -m test +' + +test_expect_success 'ls-tree fails with non-zero exit code on broken tree' ' + rm -f .git/objects/5f/cffbd6e4c5c5b8d81f5e9314b20e338e3ffff5 && + test_must_fail git ls-tree -r HEAD +' + +test_done diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh index 9e69c8c926..2f5eada0d2 100755 --- a/t/t3200-branch.sh +++ b/t/t3200-branch.sh @@ -23,7 +23,7 @@ test_expect_success \ 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_path_is_missing .git/refs/heads/--help ' test_expect_success 'branch -h in broken repository' ' @@ -39,11 +39,11 @@ test_expect_success 'branch -h in broken repository' ' test_expect_success \ 'git branch abc should create a branch' \ - 'git branch abc && test -f .git/refs/heads/abc' + 'git branch abc && test_path_is_file .git/refs/heads/abc' test_expect_success \ 'git branch a/b/c should create a branch' \ - 'git branch a/b/c && test -f .git/refs/heads/a/b/c' + 'git branch a/b/c && test_path_is_file .git/refs/heads/a/b/c' cat >expect <<EOF $_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master @@ -52,15 +52,15 @@ test_expect_success \ 'git branch -l d/e/f should create a branch and a log' \ 'GIT_COMMITTER_DATE="2005-05-26 23:30" \ git branch -l d/e/f && - test -f .git/refs/heads/d/e/f && - test -f .git/logs/refs/heads/d/e/f && + test_path_is_file .git/refs/heads/d/e/f && + test_path_is_file .git/logs/refs/heads/d/e/f && test_cmp expect .git/logs/refs/heads/d/e/f' test_expect_success \ 'git branch -d d/e/f should delete a branch and a log' \ 'git branch -d d/e/f && - test ! -f .git/refs/heads/d/e/f && - test ! -f .git/logs/refs/heads/d/e/f' + test_path_is_missing .git/refs/heads/d/e/f && + test_path_is_missing .git/logs/refs/heads/d/e/f' test_expect_success \ 'git branch j/k should work after branch j has been deleted' \ @@ -78,13 +78,13 @@ test_expect_success \ 'git branch -m m m/m should work' \ 'git branch -l m && git branch -m m m/m && - test -f .git/logs/refs/heads/m/m' + test_path_is_file .git/logs/refs/heads/m/m' test_expect_success \ 'git branch -m n/n n should work' \ 'git branch -l n/n && git branch -m n/n n - test -f .git/logs/refs/heads/n' + test_path_is_file .git/logs/refs/heads/n' test_expect_success 'git branch -m o/o o should fail when o/p exists' ' git branch o/o && @@ -98,6 +98,50 @@ test_expect_success 'git branch -m q r/q should fail when r exists' ' test_must_fail git branch -m q r/q ' +test_expect_success 'git branch -M foo bar should fail when bar is checked out' ' + git branch bar && + git checkout -b foo && + test_must_fail git branch -M bar foo +' + +test_expect_success 'git branch -M baz bam should succeed when baz is checked out' ' + git checkout -b baz && + git branch bam && + git branch -M baz bam +' + +test_expect_success 'git branch -v -d t should work' ' + git branch t && + test_path_is_file .git/refs/heads/t && + git branch -v -d t && + test_path_is_missing .git/refs/heads/t +' + +test_expect_success 'git branch -v -m t s should work' ' + git branch t && + test_path_is_file .git/refs/heads/t && + git branch -v -m t s && + test_path_is_missing .git/refs/heads/t && + test_path_is_file .git/refs/heads/s && + git branch -d s +' + +test_expect_success 'git branch -m -d t s should fail' ' + git branch t && + test_path_is_file .git/refs/heads/t && + test_must_fail git branch -m -d t s && + git branch -d t && + test_path_is_missing .git/refs/heads/t +' + +test_expect_success 'git branch --list -d t should fail' ' + git branch t && + test_path_is_file .git/refs/heads/t && + test_must_fail git branch --list -d t && + git branch -d t && + test_path_is_missing .git/refs/heads/t +' + mv .git/config .git/config-saved test_expect_success 'git branch -m q q2 without config should succeed' ' @@ -112,12 +156,12 @@ git config branch.s/s.dummy Hello test_expect_success \ 'git branch -m s/s s should work when s/t is deleted' \ 'git branch -l s/s && - test -f .git/logs/refs/heads/s/s && + test_path_is_file .git/logs/refs/heads/s/s && git branch -l s/t && - test -f .git/logs/refs/heads/s/t && + test_path_is_file .git/logs/refs/heads/s/t && git branch -d s/t && git branch -m s/s s && - test -f .git/logs/refs/heads/s' + test_path_is_file .git/logs/refs/heads/s' test_expect_success 'config information was renamed, too' \ "test $(git config branch.s.dummy) = Hello && @@ -128,8 +172,8 @@ test_expect_success 'renaming a symref is not allowed' \ git symbolic-ref refs/heads/master2 refs/heads/master && test_must_fail git branch -m master2 master3 && git symbolic-ref refs/heads/master2 && - test -f .git/refs/heads/master && - ! test -f .git/refs/heads/master3 + test_path_is_file .git/refs/heads/master && + test_path_is_missing .git/refs/heads/master3 ' test_expect_success SYMLINKS \ @@ -238,8 +282,8 @@ test_expect_success \ 'git checkout -b g/h/i -l should create a branch and a log' \ 'GIT_COMMITTER_DATE="2005-05-26 23:30" \ git checkout -b g/h/i -l master && - test -f .git/refs/heads/g/h/i && - test -f .git/logs/refs/heads/g/h/i && + test_path_is_file .git/refs/heads/g/h/i && + test_path_is_file .git/logs/refs/heads/g/h/i && test_cmp expect .git/logs/refs/heads/g/h/i' test_expect_success 'checkout -b makes reflog by default' ' @@ -542,4 +586,17 @@ test_expect_success 'attempt to delete a branch merged to its base' ' test_must_fail git branch -d my10 ' +test_expect_success 'use set-upstream on the current branch' ' + git checkout master && + git --bare init myupstream.git && + git push myupstream.git master:refs/heads/frotz && + git remote add origin myupstream.git && + git fetch && + git branch --set-upstream master origin/frotz && + + test "z$(git config branch.master.remote)" = "zorigin" && + test "z$(git config branch.master.merge)" = "zrefs/heads/frotz" + +' + test_done diff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh index 6b7c118e4f..76fe7e0060 100755 --- a/t/t3203-branch-output.sh +++ b/t/t3203-branch-output.sh @@ -32,6 +32,20 @@ test_expect_success 'git branch shows local branches' ' test_cmp expect actual ' +test_expect_success 'git branch --list shows local branches' ' + git branch --list >actual && + test_cmp expect actual +' + +cat >expect <<'EOF' + branch-one + branch-two +EOF +test_expect_success 'git branch --list pattern shows matching local branches' ' + git branch --list branch* >actual && + test_cmp expect actual +' + cat >expect <<'EOF' origin/HEAD -> origin/branch-one origin/branch-one @@ -67,6 +81,20 @@ test_expect_success 'git branch -v shows branch summaries' ' ' cat >expect <<'EOF' +two +one +EOF +test_expect_success 'git branch --list -v pattern shows branch summaries' ' + git branch --list -v branch* >tmp && + awk "{print \$NF}" <tmp >actual && + test_cmp expect actual +' + +test_expect_success 'git branch -v pattern does not show branch summaries' ' + test_must_fail git branch -v branch* +' + +cat >expect <<'EOF' * (no branch) branch-one branch-two diff --git a/t/t3307-notes-man.sh b/t/t3307-notes-man.sh index 2ea3be6546..1aa366a410 100755 --- a/t/t3307-notes-man.sh +++ b/t/t3307-notes-man.sh @@ -26,13 +26,13 @@ test_expect_success 'example 1: notes to add an Acked-by line' ' ' test_expect_success 'example 2: binary notes' ' - cp "$TEST_DIRECTORY"/test4012.png . && + cp "$TEST_DIRECTORY"/test-binary-1.png . && git checkout B && - blob=$(git hash-object -w test4012.png) && + blob=$(git hash-object -w test-binary-1.png) && git notes --ref=logo add -C "$blob" && git notes --ref=logo copy B C && git notes --ref=logo show C >actual && - test_cmp test4012.png actual + test_cmp test-binary-1.png actual ' test_done diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index 8538813d1d..b981572d73 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -527,6 +527,20 @@ test_expect_success 'auto-amend only edited commits after "edit"' ' git rebase --abort ' +test_expect_success 'clean error after failed "exec"' ' + test_tick && + test_when_finished "git rebase --abort || :" && + ( + FAKE_LINES="1 exec_false" && + export FAKE_LINES && + test_must_fail git rebase -i HEAD^ + ) && + echo "edited again" > file7 && + git add file7 && + test_must_fail git rebase --continue 2>error && + grep "You have staged changes in your working tree." error +' + test_expect_success 'rebase a detached HEAD' ' grandparent=$(git rev-parse HEAD~2) && git checkout $(git rev-parse HEAD) && diff --git a/t/t3503-cherry-pick-root.sh b/t/t3503-cherry-pick-root.sh index 9aefe3a1be..e27f39d1e5 100755 --- a/t/t3503-cherry-pick-root.sh +++ b/t/t3503-cherry-pick-root.sh @@ -16,12 +16,20 @@ test_expect_success setup ' echo second > file2 && git add file2 && test_tick && - git commit -m "second" + git commit -m "second" && + + git symbolic-ref HEAD refs/heads/third && + rm .git/index file2 && + echo third > file3 && + git add file3 && + test_tick && + git commit -m "third" ' test_expect_success 'cherry-pick a root commit' ' + git checkout second^0 && git cherry-pick master && echo first >expect && test_cmp expect file1 @@ -50,4 +58,21 @@ test_expect_success 'revert a root commit with an external strategy' ' ' +test_expect_success 'cherry-pick two root commits' ' + + echo first >expect.file1 && + echo second >expect.file2 && + echo third >expect.file3 && + + git checkout second^0 && + git cherry-pick master third && + + test_cmp expect.file1 file1 && + test_cmp expect.file2 file2 && + test_cmp expect.file3 file3 && + git rev-parse --verify HEAD^^ && + test_must_fail git rev-parse --verify HEAD^^^ + +' + test_done diff --git a/t/t3510-cherry-pick-sequence.sh b/t/t3510-cherry-pick-sequence.sh new file mode 100755 index 0000000000..3bca2b3dd5 --- /dev/null +++ b/t/t3510-cherry-pick-sequence.sh @@ -0,0 +1,214 @@ +#!/bin/sh + +test_description='Test cherry-pick continuation features + + + anotherpick: rewrites foo to d + + picked: rewrites foo to c + + unrelatedpick: rewrites unrelated to reallyunrelated + + base: rewrites foo to b + + initial: writes foo as a, unrelated as unrelated + +' + +. ./test-lib.sh + +pristine_detach () { + git cherry-pick --reset && + git checkout -f "$1^0" && + git read-tree -u --reset HEAD && + git clean -d -f -f -q -x +} + +test_expect_success setup ' + echo unrelated >unrelated && + git add unrelated && + test_commit initial foo a && + test_commit base foo b && + test_commit unrelatedpick unrelated reallyunrelated && + test_commit picked foo c && + test_commit anotherpick foo d && + git config advice.detachedhead false + +' + +test_expect_success 'cherry-pick persists data on failure' ' + pristine_detach initial && + test_must_fail git cherry-pick -s base..anotherpick && + test_path_is_dir .git/sequencer && + test_path_is_file .git/sequencer/head && + test_path_is_file .git/sequencer/todo && + test_path_is_file .git/sequencer/opts +' + +test_expect_success 'cherry-pick persists opts correctly' ' + pristine_detach initial && + test_must_fail git cherry-pick -s -m 1 --strategy=recursive -X patience -X ours base..anotherpick && + test_path_is_dir .git/sequencer && + test_path_is_file .git/sequencer/head && + test_path_is_file .git/sequencer/todo && + test_path_is_file .git/sequencer/opts && + echo "true" >expect && + git config --file=.git/sequencer/opts --get-all options.signoff >actual && + test_cmp expect actual && + echo "1" >expect && + git config --file=.git/sequencer/opts --get-all options.mainline >actual && + test_cmp expect actual && + echo "recursive" >expect && + git config --file=.git/sequencer/opts --get-all options.strategy >actual && + test_cmp expect actual && + cat >expect <<-\EOF && + patience + ours + EOF + git config --file=.git/sequencer/opts --get-all options.strategy-option >actual && + test_cmp expect actual +' + +test_expect_success 'cherry-pick cleans up sequencer state upon success' ' + pristine_detach initial && + git cherry-pick initial..picked && + test_path_is_missing .git/sequencer +' + +test_expect_success '--reset does not complain when no cherry-pick is in progress' ' + pristine_detach initial && + git cherry-pick --reset +' + +test_expect_success '--reset cleans up sequencer state' ' + pristine_detach initial && + test_must_fail git cherry-pick base..picked && + git cherry-pick --reset && + test_path_is_missing .git/sequencer +' + +test_expect_success 'cherry-pick cleans up sequencer state when one commit is left' ' + pristine_detach initial && + test_must_fail git cherry-pick base..picked && + test_path_is_missing .git/sequencer && + echo "resolved" >foo && + git add foo && + git commit && + { + git rev-list HEAD | + git diff-tree --root --stdin | + sed "s/$_x40/OBJID/g" + } >actual && + cat >expect <<-\EOF && + OBJID + :100644 100644 OBJID OBJID M foo + OBJID + :100644 100644 OBJID OBJID M unrelated + OBJID + :000000 100644 OBJID OBJID A foo + :000000 100644 OBJID OBJID A unrelated + EOF + test_cmp expect actual +' + +test_expect_success 'cherry-pick does not implicitly stomp an existing operation' ' + pristine_detach initial && + test_must_fail git cherry-pick base..anotherpick && + test-chmtime -v +0 .git/sequencer >expect && + test_must_fail git cherry-pick unrelatedpick && + test-chmtime -v +0 .git/sequencer >actual && + test_cmp expect actual +' + +test_expect_success '--continue complains when no cherry-pick is in progress' ' + pristine_detach initial && + test_must_fail git cherry-pick --continue +' + +test_expect_success '--continue complains when there are unresolved conflicts' ' + pristine_detach initial && + test_must_fail git cherry-pick base..anotherpick && + test_must_fail git cherry-pick --continue +' + +test_expect_success '--continue continues after conflicts are resolved' ' + pristine_detach initial && + test_must_fail git cherry-pick base..anotherpick && + echo "c" >foo && + git add foo && + git commit && + git cherry-pick --continue && + test_path_is_missing .git/sequencer && + { + git rev-list HEAD | + git diff-tree --root --stdin | + sed "s/$_x40/OBJID/g" + } >actual && + cat >expect <<-\EOF && + OBJID + :100644 100644 OBJID OBJID M foo + OBJID + :100644 100644 OBJID OBJID M foo + OBJID + :100644 100644 OBJID OBJID M unrelated + OBJID + :000000 100644 OBJID OBJID A foo + :000000 100644 OBJID OBJID A unrelated + EOF + test_cmp expect actual +' + +test_expect_success '--continue respects opts' ' + pristine_detach initial && + test_must_fail git cherry-pick -x base..anotherpick && + echo "c" >foo && + git add foo && + git commit && + git cherry-pick --continue && + test_path_is_missing .git/sequencer && + git cat-file commit HEAD >anotherpick_msg && + git cat-file commit HEAD~1 >picked_msg && + git cat-file commit HEAD~2 >unrelatedpick_msg && + git cat-file commit HEAD~3 >initial_msg && + test_must_fail grep "cherry picked from" initial_msg && + grep "cherry picked from" unrelatedpick_msg && + grep "cherry picked from" picked_msg && + grep "cherry picked from" anotherpick_msg +' + +test_expect_success '--signoff is not automatically propagated to resolved conflict' ' + pristine_detach initial && + test_must_fail git cherry-pick --signoff base..anotherpick && + echo "c" >foo && + git add foo && + git commit && + git cherry-pick --continue && + test_path_is_missing .git/sequencer && + git cat-file commit HEAD >anotherpick_msg && + git cat-file commit HEAD~1 >picked_msg && + git cat-file commit HEAD~2 >unrelatedpick_msg && + git cat-file commit HEAD~3 >initial_msg && + test_must_fail grep "Signed-off-by:" initial_msg && + grep "Signed-off-by:" unrelatedpick_msg && + test_must_fail grep "Signed-off-by:" picked_msg && + grep "Signed-off-by:" anotherpick_msg +' + +test_expect_success 'malformed instruction sheet 1' ' + pristine_detach initial && + test_must_fail git cherry-pick base..anotherpick && + echo "resolved" >foo && + git add foo && + git commit && + sed "s/pick /pick/" .git/sequencer/todo >new_sheet && + cp new_sheet .git/sequencer/todo && + test_must_fail git cherry-pick --continue +' + +test_expect_success 'malformed instruction sheet 2' ' + pristine_detach initial && + test_must_fail git cherry-pick base..anotherpick && + echo "resolved" >foo && + git add foo && + git commit && + sed "s/pick/revert/" .git/sequencer/todo >new_sheet && + cp new_sheet .git/sequencer/todo && + test_must_fail git cherry-pick --continue +' + +test_done diff --git a/t/t3900-i18n-commit.sh b/t/t3900-i18n-commit.sh index c06a5ee766..1f62c151b0 100755 --- a/t/t3900-i18n-commit.sh +++ b/t/t3900-i18n-commit.sh @@ -147,7 +147,7 @@ test_commit_autosquash_flags () { git commit -a -m "intermediate commit" && test_tick && echo $H $flag >>F && - git commit -a --$flag HEAD~1 $3 && + git commit -a --$flag HEAD~1 && E=$(git cat-file commit '$H-$flag' | sed -ne "s/^encoding //p") && test "z$E" = "z$H" && @@ -160,6 +160,6 @@ test_commit_autosquash_flags () { test_commit_autosquash_flags eucJP fixup -test_commit_autosquash_flags ISO-2022-JP squash '-m "squash message"' +test_commit_autosquash_flags ISO-2022-JP squash test_done diff --git a/t/t3902-quoted.sh b/t/t3902-quoted.sh index da82b655b3..534ee08a44 100755 --- a/t/t3902-quoted.sh +++ b/t/t3902-quoted.sh @@ -10,8 +10,6 @@ test_description='quoted output' FN='濱野' GN='純' HT=' ' -LF=' -' DQ='"' echo foo 2>/dev/null > "Name and an${HT}HT" diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh index 7197aae1ed..fcdb18217a 100755 --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@ -542,7 +542,7 @@ test_expect_success 'ref with non-existent reflog' ' echo bar6 > file2 && git add file2 && git stash && - ! "git rev-parse --quiet --verify does-not-exist" && + test_must_fail git rev-parse --quiet --verify does-not-exist && test_must_fail git stash drop does-not-exist && test_must_fail git stash drop does-not-exist@{0} && test_must_fail git stash pop does-not-exist && diff --git a/t/t3905-stash-include-untracked.sh b/t/t3905-stash-include-untracked.sh new file mode 100755 index 0000000000..ef44fb2260 --- /dev/null +++ b/t/t3905-stash-include-untracked.sh @@ -0,0 +1,175 @@ +#!/bin/sh +# +# Copyright (c) 2011 David Caldwell +# + +test_description='Test git stash --include-untracked' + +. ./test-lib.sh + +test_expect_success 'stash save --include-untracked some dirty working directory' ' + echo 1 > file && + git add file && + test_tick && + git commit -m initial && + echo 2 > file && + git add file && + echo 3 > file && + test_tick && + echo 1 > file2 && + mkdir untracked && + echo untracked >untracked/untracked && + git stash --include-untracked && + git diff-files --quiet && + git diff-index --cached --quiet HEAD +' + +cat > expect <<EOF +?? actual +?? expect +EOF + +test_expect_success 'stash save --include-untracked cleaned the untracked files' ' + git status --porcelain >actual && + test_cmp expect actual +' + +cat > expect.diff <<EOF +diff --git a/file2 b/file2 +new file mode 100644 +index 0000000..d00491f +--- /dev/null ++++ b/file2 +@@ -0,0 +1 @@ ++1 +diff --git a/untracked/untracked b/untracked/untracked +new file mode 100644 +index 0000000..5a72eb2 +--- /dev/null ++++ b/untracked/untracked +@@ -0,0 +1 @@ ++untracked +EOF +cat > expect.lstree <<EOF +file2 +untracked +EOF + +test_expect_success 'stash save --include-untracked stashed the untracked files' ' + test "!" -f file2 && + test ! -e untracked && + git diff HEAD stash^3 -- file2 untracked >actual && + test_cmp expect.diff actual && + git ls-tree --name-only stash^3: >actual && + test_cmp expect.lstree actual +' +test_expect_success 'stash save --patch --include-untracked fails' ' + test_must_fail git stash --patch --include-untracked +' + +test_expect_success 'stash save --patch --all fails' ' + test_must_fail git stash --patch --all +' + +git clean --force --quiet + +cat > expect <<EOF + M file +?? actual +?? expect +?? file2 +?? untracked/ +EOF + +test_expect_success 'stash pop after save --include-untracked leaves files untracked again' ' + git stash pop && + git status --porcelain >actual && + test_cmp expect actual && + test "1" = "`cat file2`" && + test untracked = "`cat untracked/untracked`" +' + +git clean --force --quiet -d + +test_expect_success 'stash save -u dirty index' ' + echo 4 > file3 && + git add file3 && + test_tick && + git stash -u +' + +cat > expect <<EOF +diff --git a/file3 b/file3 +new file mode 100644 +index 0000000..b8626c4 +--- /dev/null ++++ b/file3 +@@ -0,0 +1 @@ ++4 +EOF + +test_expect_success 'stash save --include-untracked dirty index got stashed' ' + git stash pop --index && + git diff --cached >actual && + test_cmp expect actual +' + +git reset > /dev/null + +test_expect_success 'stash save --include-untracked -q is quiet' ' + echo 1 > file5 && + git stash save --include-untracked --quiet > output.out 2>&1 && + test ! -s output.out +' + +test_expect_success 'stash save --include-untracked removed files' ' + rm -f file && + git stash save --include-untracked && + echo 1 > expect && + test_cmp file expect +' + +rm -f expect + +test_expect_success 'stash save --include-untracked removed files got stashed' ' + git stash pop && + test ! -f file +' + +cat > .gitignore <<EOF +.gitignore +ignored +ignored.d/ +EOF + +test_expect_success 'stash save --include-untracked respects .gitignore' ' + echo ignored > ignored && + mkdir ignored.d && + echo ignored >ignored.d/untracked && + git stash -u && + test -s ignored && + test -s ignored.d/untracked && + test -s .gitignore +' + +test_expect_success 'stash save -u can stash with only untracked files different' ' + echo 4 > file4 && + git stash -u && + test "!" -f file4 +' + +test_expect_success 'stash save --all does not respect .gitignore' ' + git stash -a && + test "!" -f ignored && + test "!" -e ignored.d && + test "!" -f .gitignore +' + +test_expect_success 'stash save --all is stash poppable' ' + git stash pop && + test -s ignored && + test -s ignored.d/untracked && + test -s .gitignore +' + +test_done diff --git a/t/t4012-diff-binary.sh b/t/t4012-diff-binary.sh index 05ec062832..2d9f9a0cf1 100755 --- a/t/t4012-diff-binary.sh +++ b/t/t4012-diff-binary.sh @@ -12,7 +12,7 @@ test_expect_success 'prepare repository' \ 'echo AIT >a && echo BIT >b && echo CIT >c && echo DIT >d && git update-index --add a b c d && echo git >a && - cat "$TEST_DIRECTORY"/test4012.png >b && + cat "$TEST_DIRECTORY"/test-binary-1.png >b && echo git >c && cat b b >d' diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index 92248d24c4..67975129bc 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -179,12 +179,21 @@ test_expect_success 'configuration To: header' ' grep "^To: R. E. Cipient <rcipient@example.com>\$" patch9 ' +# check_patch <patch>: Verify that <patch> looks like a half-sane +# patch email to avoid a false positive with !grep +check_patch () { + grep -e "^From:" "$1" && + grep -e "^Date:" "$1" && + grep -e "^Subject:" "$1" +} + test_expect_success '--no-to overrides config.to' ' git config --replace-all format.to \ "R. E. Cipient <rcipient@example.com>" && git format-patch --no-to --stdout master..side | sed -e "/^\$/q" >patch10 && + check_patch patch10 && ! grep "^To: R. E. Cipient <rcipient@example.com>\$" patch10 ' @@ -195,6 +204,7 @@ test_expect_success '--no-to and --to replaces config.to' ' git format-patch --no-to --to="Someone Else <else@out.there>" \ --stdout master..side | sed -e "/^\$/q" >patch11 && + check_patch patch11 && ! grep "^To: Someone <someone@out.there>\$" patch11 && grep "^To: Someone Else <else@out.there>\$" patch11 ' @@ -205,15 +215,17 @@ test_expect_success '--no-cc overrides config.cc' ' "C. E. Cipient <rcipient@example.com>" && git format-patch --no-cc --stdout master..side | sed -e "/^\$/q" >patch12 && + check_patch patch12 && ! grep "^Cc: C. E. Cipient <rcipient@example.com>\$" patch12 ' -test_expect_success '--no-add-headers overrides config.headers' ' +test_expect_success '--no-add-header overrides config.headers' ' git config --replace-all format.headers \ "Header1: B. E. Cipient <rcipient@example.com>" && - git format-patch --no-add-headers --stdout master..side | + git format-patch --no-add-header --stdout master..side | sed -e "/^\$/q" >patch13 && + check_patch patch13 && ! grep "^Header1: B. E. Cipient <rcipient@example.com>\$" patch13 ' @@ -445,22 +457,22 @@ test_expect_success 'thread deep cover-letter in-reply-to' ' ' test_expect_success 'thread via config' ' - git config format.thread true && + test_config format.thread true && check_threading expect.thread master ' test_expect_success 'thread deep via config' ' - git config format.thread deep && + test_config format.thread deep && check_threading expect.deep master ' test_expect_success 'thread config + override' ' - git config format.thread deep && + test_config format.thread deep && check_threading expect.thread --thread master ' test_expect_success 'thread config + --no-thread' ' - git config format.thread deep && + test_config format.thread deep && check_threading expect.no-threading --no-thread master ' @@ -480,6 +492,7 @@ test_expect_success 'cover-letter inherits diff options' ' git mv file foo && git commit -m foo && git format-patch --cover-letter -1 && + check_patch 0000-cover-letter.patch && ! grep "file => foo .* 0 *\$" 0000-cover-letter.patch && git format-patch --cover-letter -1 -M && grep "file => foo .* 0 *\$" 0000-cover-letter.patch @@ -657,6 +670,7 @@ test_expect_success 'format-patch --no-signature ignores format.signature' ' git config format.signature "config sig" && git format-patch --stdout --signature="my sig" --no-signature \ -1 >output && + check_patch output && ! grep "config sig" output && ! grep "my sig" output && ! grep "^-- \$" output @@ -673,17 +687,20 @@ test_expect_success 'format-patch --signature --cover-letter' ' test_expect_success 'format.signature="" supresses signatures' ' git config format.signature "" && git format-patch --stdout -1 >output && + check_patch output && ! grep "^-- \$" output ' test_expect_success 'format-patch --no-signature supresses signatures' ' git config --unset-all format.signature && git format-patch --stdout --no-signature -1 >output && + check_patch output && ! grep "^-- \$" output ' test_expect_success 'format-patch --signature="" supresses signatures' ' - git format-patch --signature="" -1 >output && + git format-patch --stdout --signature="" -1 >output && + check_patch output && ! grep "^-- \$" output ' @@ -869,4 +886,12 @@ test_expect_success 'empty subject prefix does not have extra space' ' test_cmp expect actual ' +test_expect_success 'format patch ignores color.ui' ' + test_unconfig color.ui && + git format-patch --stdout -1 >expect && + test_config color.ui always && + git format-patch --stdout -1 >actual && + test_cmp expect actual +' + test_done diff --git a/t/t4033-diff-patience.sh b/t/t4033-diff-patience.sh index 1eb14989df..3c9932edf3 100755 --- a/t/t4033-diff-patience.sh +++ b/t/t4033-diff-patience.sh @@ -3,166 +3,10 @@ test_description='patience diff algorithm' . ./test-lib.sh +. "$TEST_DIRECTORY"/lib-diff-alternative.sh -cat >file1 <<\EOF -#include <stdio.h> +test_diff_frobnitz "patience" -// Frobs foo heartily -int frobnitz(int foo) -{ - int i; - for(i = 0; i < 10; i++) - { - printf("Your answer is: "); - printf("%d\n", foo); - } -} - -int fact(int n) -{ - if(n > 1) - { - return fact(n-1) * n; - } - return 1; -} - -int main(int argc, char **argv) -{ - frobnitz(fact(10)); -} -EOF - -cat >file2 <<\EOF -#include <stdio.h> - -int fib(int n) -{ - if(n > 2) - { - return fib(n-1) + fib(n-2); - } - return 1; -} - -// Frobs foo heartily -int frobnitz(int foo) -{ - int i; - for(i = 0; i < 10; i++) - { - printf("%d\n", foo); - } -} - -int main(int argc, char **argv) -{ - frobnitz(fib(10)); -} -EOF - -cat >expect <<\EOF -diff --git a/file1 b/file2 -index 6faa5a3..e3af329 100644 ---- a/file1 -+++ b/file2 -@@ -1,26 +1,25 @@ - #include <stdio.h> - -+int fib(int n) -+{ -+ if(n > 2) -+ { -+ return fib(n-1) + fib(n-2); -+ } -+ return 1; -+} -+ - // Frobs foo heartily - int frobnitz(int foo) - { - int i; - for(i = 0; i < 10; i++) - { -- printf("Your answer is: "); - printf("%d\n", foo); - } - } - --int fact(int n) --{ -- if(n > 1) -- { -- return fact(n-1) * n; -- } -- return 1; --} -- - int main(int argc, char **argv) - { -- frobnitz(fact(10)); -+ frobnitz(fib(10)); - } -EOF - -test_expect_success 'patience diff' ' - - test_must_fail git diff --no-index --patience file1 file2 > output && - test_cmp expect output - -' - -test_expect_success 'patience diff output is valid' ' - - mv file2 expect && - git apply < output && - test_cmp expect file2 - -' - -cat >uniq1 <<\EOF -1 -2 -3 -4 -5 -6 -EOF - -cat >uniq2 <<\EOF -a -b -c -d -e -f -EOF - -cat >expect <<\EOF -diff --git a/uniq1 b/uniq2 -index b414108..0fdf397 100644 ---- a/uniq1 -+++ b/uniq2 -@@ -1,6 +1,6 @@ --1 --2 --3 --4 --5 --6 -+a -+b -+c -+d -+e -+f -EOF - -test_expect_success 'completely different files' ' - - test_must_fail git diff --no-index --patience uniq1 uniq2 > output && - test_cmp expect output - -' +test_diff_unique "patience" test_done diff --git a/t/t4050-diff-histogram.sh b/t/t4050-diff-histogram.sh new file mode 100755 index 0000000000..fd3e86a74f --- /dev/null +++ b/t/t4050-diff-histogram.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +test_description='histogram diff algorithm' + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-diff-alternative.sh + +test_diff_frobnitz "histogram" + +test_diff_unique "histogram" + +test_done diff --git a/t/t4150-am.sh b/t/t4150-am.sh index 151404e090..d7d9ccc1c8 100755 --- a/t/t4150-am.sh +++ b/t/t4150-am.sh @@ -96,6 +96,13 @@ test_expect_success setup ' echo "X-Fake-Field: Line Three" && git format-patch --stdout first | sed -e "1d" } | append_cr >patch1-crlf.eml && + { + printf "%255s\\n" "" + echo "X-Fake-Field: Line One" && + echo "X-Fake-Field: Line Two" && + echo "X-Fake-Field: Line Three" && + git format-patch --stdout first | sed -e "1d" + } > patch1-ws.eml && sed -n -e "3,\$p" msg >file && git add file && @@ -167,6 +174,17 @@ test_expect_success 'am applies patch e-mail not in a mbox with CRLF' ' test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)" ' +test_expect_success 'am applies patch e-mail with preceding whitespace' ' + rm -fr .git/rebase-apply && + git reset --hard && + git checkout first && + git am patch1-ws.eml && + ! test -d .git/rebase-apply && + git diff --exit-code second && + test "$(git rev-parse second)" = "$(git rev-parse HEAD)" && + test "$(git rev-parse second^)" = "$(git rev-parse HEAD^)" +' + test_expect_success 'setup: new author and committer' ' GIT_AUTHOR_NAME="Another Thor" && GIT_AUTHOR_EMAIL="a.thor@example.com" && diff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh index 9e3ba98fc8..d9068981f8 100755 --- a/t/t5000-tar-tree.sh +++ b/t/t5000-tar-tree.sh @@ -266,7 +266,7 @@ test_expect_success 'archive --list mentions user filter' ' grep "^bar\$" output ' -test_expect_success 'archive --list shows only enabled remote filters' ' +test_expect_success NOT_MINGW 'archive --list shows only enabled remote filters' ' git archive --list --remote=. >output && ! grep "^tar\.foo\$" output && grep "^bar\$" output @@ -298,7 +298,7 @@ test_expect_success 'extension matching requires dot' ' test_cmp b.tar config-implicittar.foo ' -test_expect_success 'only enabled filters are available remotely' ' +test_expect_success NOT_MINGW 'only enabled filters are available remotely' ' test_must_fail git archive --remote=. --format=tar.foo HEAD \ >remote.tar.foo && git archive --remote=. --format=bar >remote.bar HEAD && @@ -341,12 +341,12 @@ test_expect_success GZIP,GUNZIP 'extract tgz file' ' test_cmp b.tar j.tar ' -test_expect_success GZIP 'remote tar.gz is allowed by default' ' +test_expect_success GZIP,NOT_MINGW 'remote tar.gz is allowed by default' ' git archive --remote=. --format=tar.gz HEAD >remote.tar.gz && test_cmp j.tgz remote.tar.gz ' -test_expect_success GZIP 'remote tar.gz can be disabled' ' +test_expect_success GZIP,NOT_MINGW 'remote tar.gz can be disabled' ' git config tar.tar.gz.remote false && test_must_fail git archive --remote=. --format=tar.gz HEAD \ >remote.tar.gz diff --git a/t/t5001-archive-attr.sh b/t/t5001-archive-attr.sh index 02d4d2284d..f47d8717fd 100755 --- a/t/t5001-archive-attr.sh +++ b/t/t5001-archive-attr.sh @@ -57,6 +57,15 @@ test_expect_missing worktree/ignored test_expect_exists worktree/ignored-by-tree test_expect_missing worktree/ignored-by-worktree +test_expect_success 'git archive --worktree-attributes option' ' + git archive --worktree-attributes --worktree-attributes HEAD >worktree.tar && + (mkdir worktree2 && cd worktree2 && "$TAR" xf -) <worktree.tar +' + +test_expect_missing worktree2/ignored +test_expect_exists worktree2/ignored-by-tree +test_expect_missing worktree2/ignored-by-worktree + test_expect_success 'git archive vs. bare' ' (cd bare && git archive HEAD) >bare-archive.tar && test_cmp archive.tar bare-archive.tar diff --git a/t/t5403-post-checkout-hook.sh b/t/t5403-post-checkout-hook.sh index d05a9138b4..1753ef2b91 100755 --- a/t/t5403-post-checkout-hook.sh +++ b/t/t5403-post-checkout-hook.sh @@ -31,44 +31,44 @@ EOF done test_expect_success 'post-checkout runs as expected ' ' - GIT_DIR=clone1/.git git checkout master && - test -e clone1/.git/post-checkout.args + GIT_DIR=clone1/.git git checkout master && + test -e clone1/.git/post-checkout.args ' test_expect_success 'post-checkout receives the right arguments with HEAD unchanged ' ' - old=$(awk "{print \$1}" clone1/.git/post-checkout.args) && - new=$(awk "{print \$2}" clone1/.git/post-checkout.args) && - flag=$(awk "{print \$3}" clone1/.git/post-checkout.args) && - test $old = $new -a $flag = 1 + old=$(awk "{print \$1}" clone1/.git/post-checkout.args) && + new=$(awk "{print \$2}" clone1/.git/post-checkout.args) && + flag=$(awk "{print \$3}" clone1/.git/post-checkout.args) && + test $old = $new -a $flag = 1 ' test_expect_success 'post-checkout runs as expected ' ' - GIT_DIR=clone1/.git git checkout master && - test -e clone1/.git/post-checkout.args + GIT_DIR=clone1/.git git checkout master && + test -e clone1/.git/post-checkout.args ' test_expect_success 'post-checkout args are correct with git checkout -b ' ' - GIT_DIR=clone1/.git git checkout -b new1 && - old=$(awk "{print \$1}" clone1/.git/post-checkout.args) && - new=$(awk "{print \$2}" clone1/.git/post-checkout.args) && - flag=$(awk "{print \$3}" clone1/.git/post-checkout.args) && - test $old = $new -a $flag = 1 + GIT_DIR=clone1/.git git checkout -b new1 && + old=$(awk "{print \$1}" clone1/.git/post-checkout.args) && + new=$(awk "{print \$2}" clone1/.git/post-checkout.args) && + flag=$(awk "{print \$3}" clone1/.git/post-checkout.args) && + test $old = $new -a $flag = 1 ' test_expect_success 'post-checkout receives the right args with HEAD changed ' ' - GIT_DIR=clone2/.git git checkout new2 && - old=$(awk "{print \$1}" clone2/.git/post-checkout.args) && - new=$(awk "{print \$2}" clone2/.git/post-checkout.args) && - flag=$(awk "{print \$3}" clone2/.git/post-checkout.args) && - test $old != $new -a $flag = 1 + GIT_DIR=clone2/.git git checkout new2 && + old=$(awk "{print \$1}" clone2/.git/post-checkout.args) && + new=$(awk "{print \$2}" clone2/.git/post-checkout.args) && + flag=$(awk "{print \$3}" clone2/.git/post-checkout.args) && + test $old != $new -a $flag = 1 ' test_expect_success 'post-checkout receives the right args when not switching branches ' ' - GIT_DIR=clone2/.git git checkout master b && - old=$(awk "{print \$1}" clone2/.git/post-checkout.args) && - new=$(awk "{print \$2}" clone2/.git/post-checkout.args) && - flag=$(awk "{print \$3}" clone2/.git/post-checkout.args) && - test $old = $new -a $flag = 0 + GIT_DIR=clone2/.git git checkout master b && + old=$(awk "{print \$1}" clone2/.git/post-checkout.args) && + new=$(awk "{print \$2}" clone2/.git/post-checkout.args) && + flag=$(awk "{print \$3}" clone2/.git/post-checkout.args) && + test $old = $new -a $flag = 0 ' if test "$(git config --bool core.filemode)" = true; then diff --git a/t/t5504-fetch-receive-strict.sh b/t/t5504-fetch-receive-strict.sh new file mode 100755 index 0000000000..8341fc4d15 --- /dev/null +++ b/t/t5504-fetch-receive-strict.sh @@ -0,0 +1,104 @@ +#!/bin/sh + +test_description='fetch/receive strict mode' +. ./test-lib.sh + +test_expect_success setup ' + echo hello >greetings && + git add greetings && + git commit -m greetings && + + S=$(git rev-parse :greetings | sed -e "s|^..|&/|") && + X=$(echo bye | git hash-object -w --stdin | sed -e "s|^..|&/|") && + mv -f .git/objects/$X .git/objects/$S && + + test_must_fail git fsck +' + +test_expect_success 'fetch without strict' ' + rm -rf dst && + git init dst && + ( + cd dst && + git config fetch.fsckobjects false && + git config transfer.fsckobjects false && + test_must_fail git fetch ../.git master + ) +' + +test_expect_success 'fetch with !fetch.fsckobjects' ' + rm -rf dst && + git init dst && + ( + cd dst && + git config fetch.fsckobjects false && + git config transfer.fsckobjects true && + test_must_fail git fetch ../.git master + ) +' + +test_expect_success 'fetch with fetch.fsckobjects' ' + rm -rf dst && + git init dst && + ( + cd dst && + git config fetch.fsckobjects true && + git config transfer.fsckobjects false && + test_must_fail git fetch ../.git master + ) +' + +test_expect_success 'fetch with transfer.fsckobjects' ' + rm -rf dst && + git init dst && + ( + cd dst && + git config transfer.fsckobjects true && + test_must_fail git fetch ../.git master + ) +' + +test_expect_success 'push without strict' ' + rm -rf dst && + git init dst && + ( + cd dst && + git config fetch.fsckobjects false && + git config transfer.fsckobjects false + ) && + git push dst master:refs/heads/test +' + +test_expect_success 'push with !receive.fsckobjects' ' + rm -rf dst && + git init dst && + ( + cd dst && + git config receive.fsckobjects false && + git config transfer.fsckobjects true + ) && + git push dst master:refs/heads/test +' + +test_expect_success 'push with receive.fsckobjects' ' + rm -rf dst && + git init dst && + ( + cd dst && + git config receive.fsckobjects true && + git config transfer.fsckobjects false + ) && + test_must_fail git push dst master:refs/heads/test +' + +test_expect_success 'push with transfer.fsckobjects' ' + rm -rf dst && + git init dst && + ( + cd dst && + git config transfer.fsckobjects true + ) && + test_must_fail git push dst master:refs/heads/test +' + +test_done diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index 0d0222ea2a..e8af615e6d 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -631,6 +631,37 @@ test_expect_success 'rename a remote' ' ' +test_expect_success 'rename does not update a non-default fetch refspec' ' + + git clone one four.one && + (cd four.one && + git config remote.origin.fetch +refs/heads/*:refs/heads/origin/* && + git remote rename origin upstream && + test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/heads/origin/*" && + git rev-parse -q origin/master) + +' + +test_expect_success 'rename a remote with name part of fetch spec' ' + + git clone one four.two && + (cd four.two && + git remote rename origin remote && + git remote rename remote upstream && + test "$(git config remote.upstream.fetch)" = "+refs/heads/*:refs/remotes/upstream/*") + +' + +test_expect_success 'rename a remote with name prefix of other remote' ' + + git clone one four.three && + (cd four.three && + git remote add o git://example.com/repo.git && + git remote rename o upstream && + test "$(git rev-parse origin/master)" = "$(git rev-parse master)") + +' + cat > remotes_origin << EOF URL: $(pwd)/one Push: refs/heads/master:refs/heads/upstream diff --git a/t/t5509-fetch-push-namespaces.sh b/t/t5509-fetch-push-namespaces.sh new file mode 100755 index 0000000000..cc0b31f6b0 --- /dev/null +++ b/t/t5509-fetch-push-namespaces.sh @@ -0,0 +1,85 @@ +#!/bin/sh + +test_description='fetch/push involving ref namespaces' +. ./test-lib.sh + +test_expect_success setup ' + test_tick && + git init original && + ( + cd original && + echo 0 >count && + git add count && + test_commit 0 && + echo 1 >count && + git add count && + test_commit 1 && + git remote add pushee-namespaced "ext::git --namespace=namespace %s ../pushee" && + git remote add pushee-unnamespaced ../pushee + ) && + commit0=$(cd original && git rev-parse HEAD^) && + commit1=$(cd original && git rev-parse HEAD) && + git init pushee && + git init puller +' + +test_expect_success 'pushing into a repository using a ref namespace' ' + ( + cd original && + git push pushee-namespaced master && + git ls-remote pushee-namespaced >actual && + printf "$commit1\trefs/heads/master\n" >expected && + test_cmp expected actual && + git push pushee-namespaced --tags && + git ls-remote pushee-namespaced >actual && + printf "$commit0\trefs/tags/0\n" >>expected && + printf "$commit1\trefs/tags/1\n" >>expected && + test_cmp expected actual && + # Verify that the GIT_NAMESPACE environment variable works as well + GIT_NAMESPACE=namespace git ls-remote "ext::git %s ../pushee" >actual && + test_cmp expected actual && + # Verify that --namespace overrides GIT_NAMESPACE + GIT_NAMESPACE=garbage git ls-remote pushee-namespaced >actual && + test_cmp expected actual && + # Try a namespace with no content + git ls-remote "ext::git --namespace=garbage %s ../pushee" >actual && + test_cmp /dev/null actual && + git ls-remote pushee-unnamespaced >actual && + sed -e "s|refs/|refs/namespaces/namespace/refs/|" expected >expected.unnamespaced && + test_cmp expected.unnamespaced actual + ) +' + +test_expect_success 'pulling from a repository using a ref namespace' ' + ( + cd puller && + git remote add -f pushee-namespaced "ext::git --namespace=namespace %s ../pushee" && + git for-each-ref refs/ >actual && + printf "$commit1 commit\trefs/remotes/pushee-namespaced/master\n" >expected && + printf "$commit0 commit\trefs/tags/0\n" >>expected && + printf "$commit1 commit\trefs/tags/1\n" >>expected && + test_cmp expected actual + ) +' + +# This test with clone --mirror checks for possible regressions in clone +# or the machinery underneath it. It ensures that no future change +# causes clone to ignore refs in refs/namespaces/*. In particular, it +# protects against a regression caused by any future change to the refs +# machinery that might cause it to ignore refs outside of refs/heads/* +# or refs/tags/*. More generally, this test also checks the high-level +# functionality of using clone --mirror to back up a set of repos hosted +# in the namespaces of a single repo. +test_expect_success 'mirroring a repository using a ref namespace' ' + git clone --mirror pushee mirror && + ( + cd mirror && + git for-each-ref refs/ >actual && + printf "$commit1 commit\trefs/namespaces/namespace/refs/heads/master\n" >expected && + printf "$commit0 commit\trefs/namespaces/namespace/refs/tags/0\n" >>expected && + printf "$commit1 commit\trefs/namespaces/namespace/refs/tags/1\n" >>expected && + test_cmp expected actual + ) +' + +test_done diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index 3abb2907ea..b69cf574d7 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -40,6 +40,40 @@ mk_test () { ) } +mk_test_with_hooks() { + mk_test "$@" && + ( + cd testrepo && + mkdir .git/hooks && + cd .git/hooks && + + cat >pre-receive <<-'EOF' && + #!/bin/sh + cat - >>pre-receive.actual + EOF + + cat >update <<-'EOF' && + #!/bin/sh + printf "%s %s %s\n" "$@" >>update.actual + EOF + + cat >post-receive <<-'EOF' && + #!/bin/sh + cat - >>post-receive.actual + EOF + + cat >post-update <<-'EOF' && + #!/bin/sh + for ref in "$@" + do + printf "%s\n" "$ref" >>post-update.actual + done + EOF + + chmod +x pre-receive update post-receive post-update + ) +} + mk_child() { rm -rf "$1" && git clone testrepo "$1" @@ -559,6 +593,169 @@ test_expect_success 'allow deleting an invalid remote ref' ' ' +test_expect_success 'pushing valid refs triggers post-receive and post-update hooks' ' + mk_test_with_hooks heads/master heads/next && + orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) && + newmaster=$(git show-ref -s --verify refs/heads/master) && + orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) && + newnext=$_z40 && + git push testrepo refs/heads/master:refs/heads/master :refs/heads/next && + ( + cd testrepo/.git && + cat >pre-receive.expect <<-EOF && + $orgmaster $newmaster refs/heads/master + $orgnext $newnext refs/heads/next + EOF + + cat >update.expect <<-EOF && + refs/heads/master $orgmaster $newmaster + refs/heads/next $orgnext $newnext + EOF + + cat >post-receive.expect <<-EOF && + $orgmaster $newmaster refs/heads/master + $orgnext $newnext refs/heads/next + EOF + + cat >post-update.expect <<-EOF && + refs/heads/master + refs/heads/next + EOF + + test_cmp pre-receive.expect pre-receive.actual && + test_cmp update.expect update.actual && + test_cmp post-receive.expect post-receive.actual && + test_cmp post-update.expect post-update.actual + ) +' + +test_expect_success 'deleting dangling ref triggers hooks with correct args' ' + mk_test_with_hooks heads/master && + rm -f testrepo/.git/objects/??/* && + git push testrepo :refs/heads/master && + ( + cd testrepo/.git && + cat >pre-receive.expect <<-EOF && + $_z40 $_z40 refs/heads/master + EOF + + cat >update.expect <<-EOF && + refs/heads/master $_z40 $_z40 + EOF + + cat >post-receive.expect <<-EOF && + $_z40 $_z40 refs/heads/master + EOF + + cat >post-update.expect <<-EOF && + refs/heads/master + EOF + + test_cmp pre-receive.expect pre-receive.actual && + test_cmp update.expect update.actual && + test_cmp post-receive.expect post-receive.actual && + test_cmp post-update.expect post-update.actual + ) +' + +test_expect_success 'deletion of a non-existent ref is not fed to post-receive and post-update hooks' ' + mk_test_with_hooks heads/master && + orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) && + newmaster=$(git show-ref -s --verify refs/heads/master) && + git push testrepo master :refs/heads/nonexistent && + ( + cd testrepo/.git && + cat >pre-receive.expect <<-EOF && + $orgmaster $newmaster refs/heads/master + $_z40 $_z40 refs/heads/nonexistent + EOF + + cat >update.expect <<-EOF && + refs/heads/master $orgmaster $newmaster + refs/heads/nonexistent $_z40 $_z40 + EOF + + cat >post-receive.expect <<-EOF && + $orgmaster $newmaster refs/heads/master + EOF + + cat >post-update.expect <<-EOF && + refs/heads/master + EOF + + test_cmp pre-receive.expect pre-receive.actual && + test_cmp update.expect update.actual && + test_cmp post-receive.expect post-receive.actual && + test_cmp post-update.expect post-update.actual + ) +' + +test_expect_success 'deletion of a non-existent ref alone does trigger post-receive and post-update hooks' ' + mk_test_with_hooks heads/master && + git push testrepo :refs/heads/nonexistent && + ( + cd testrepo/.git && + cat >pre-receive.expect <<-EOF && + $_z40 $_z40 refs/heads/nonexistent + EOF + + cat >update.expect <<-EOF && + refs/heads/nonexistent $_z40 $_z40 + EOF + + test_cmp pre-receive.expect pre-receive.actual && + test_cmp update.expect update.actual && + test_path_is_missing post-receive.actual && + test_path_is_missing post-update.actual + ) +' + +test_expect_success 'mixed ref updates, deletes, invalid deletes trigger hooks with correct input' ' + mk_test_with_hooks heads/master heads/next heads/pu && + orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) && + newmaster=$(git show-ref -s --verify refs/heads/master) && + orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) && + newnext=$_z40 && + orgpu=$(cd testrepo && git show-ref -s --verify refs/heads/pu) && + newpu=$(git show-ref -s --verify refs/heads/master) && + git push testrepo refs/heads/master:refs/heads/master \ + refs/heads/master:refs/heads/pu :refs/heads/next \ + :refs/heads/nonexistent && + ( + cd testrepo/.git && + cat >pre-receive.expect <<-EOF && + $orgmaster $newmaster refs/heads/master + $orgnext $newnext refs/heads/next + $orgpu $newpu refs/heads/pu + $_z40 $_z40 refs/heads/nonexistent + EOF + + cat >update.expect <<-EOF && + refs/heads/master $orgmaster $newmaster + refs/heads/next $orgnext $newnext + refs/heads/pu $orgpu $newpu + refs/heads/nonexistent $_z40 $_z40 + EOF + + cat >post-receive.expect <<-EOF && + $orgmaster $newmaster refs/heads/master + $orgnext $newnext refs/heads/next + $orgpu $newpu refs/heads/pu + EOF + + cat >post-update.expect <<-EOF && + refs/heads/master + refs/heads/next + refs/heads/pu + EOF + + test_cmp pre-receive.expect pre-receive.actual && + test_cmp update.expect update.actual && + test_cmp post-receive.expect post-receive.actual && + test_cmp post-update.expect post-update.actual + ) +' + test_expect_success 'allow deleting a ref using --delete' ' mk_test heads/master && (cd testrepo && git config receive.denyDeleteCurrent warn) && diff --git a/t/t5531-deep-submodule-push.sh b/t/t5531-deep-submodule-push.sh index faa2e96337..30bec4b5f9 100755 --- a/t/t5531-deep-submodule-push.sh +++ b/t/t5531-deep-submodule-push.sh @@ -32,4 +32,91 @@ test_expect_success push ' ) ' +test_expect_success 'push if submodule has no remote' ' + ( + cd work/gar/bage && + >junk2 && + git add junk2 && + git commit -m "Second junk" + ) && + ( + cd work && + git add gar/bage && + git commit -m "Second commit for gar/bage" && + git push --recurse-submodules=check ../pub.git master + ) +' + +test_expect_success 'push fails if submodule commit not on remote' ' + ( + cd work/gar && + git clone --bare bage ../../submodule.git && + cd bage && + git remote add origin ../../../submodule.git && + git fetch && + >junk3 && + git add junk3 && + git commit -m "Third junk" + ) && + ( + cd work && + git add gar/bage && + git commit -m "Third commit for gar/bage" && + test_must_fail git push --recurse-submodules=check ../pub.git master + ) +' + +test_expect_success 'push succeeds after commit was pushed to remote' ' + ( + cd work/gar/bage && + git push origin master + ) && + ( + cd work && + git push --recurse-submodules=check ../pub.git master + ) +' + +test_expect_success 'push fails when commit on multiple branches if one branch has no remote' ' + ( + cd work/gar/bage && + >junk4 && + git add junk4 && + git commit -m "Fourth junk" + ) && + ( + cd work && + git branch branch2 && + git add gar/bage && + git commit -m "Fourth commit for gar/bage" && + git checkout branch2 && + ( + cd gar/bage && + git checkout HEAD~1 + ) && + >junk1 && + git add junk1 && + git commit -m "First junk" && + test_must_fail git push --recurse-submodules=check ../pub.git + ) +' + +test_expect_success 'push succeeds if submodule has no remote and is on the first superproject commit' ' + git init --bare a + git clone a a1 && + ( + cd a1 && + git init b + ( + cd b && + >junk && + git add junk && + git commit -m "initial" + ) && + git add b && + git commit -m "added submodule" && + git push --recurse-submodule=check origin master + ) +' + test_done diff --git a/t/t5540-http-push.sh b/t/t5540-http-push.sh index a266ca5636..64767d8705 100755 --- a/t/t5540-http-push.sh +++ b/t/t5540-http-push.sh @@ -132,8 +132,12 @@ x38="$x5$x5$x5$x5$x5$x5$x5$x1$x1$x1" x40="$x38$x2" test_expect_success 'PUT and MOVE sends object to URLs with SHA-1 hash suffix' ' - sed -e "s/PUT /OP /" -e "s/MOVE /OP /" "$HTTPD_ROOT_PATH"/access.log | - grep -e "\"OP .*/objects/$x2/${x38}_$x40 HTTP/[.0-9]*\" 20[0-9] " + sed \ + -e "s/PUT /OP /" \ + -e "s/MOVE /OP /" \ + -e "s|/objects/$x2/${x38}_$x40|WANTED_PATH_REQUEST|" \ + "$HTTPD_ROOT_PATH"/access.log | + grep -e "\"OP .*WANTED_PATH_REQUEST HTTP/[.0-9]*\" 20[0-9] " ' diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh index 151ea531bd..e8103144bb 100755 --- a/t/t5601-clone.sh +++ b/t/t5601-clone.sh @@ -202,9 +202,36 @@ test_expect_success 'clone separate gitdir: output' ' test_cmp expected dst/.git ' +test_expect_success 'clone from .git file' ' + git clone dst/.git dst2 +' + test_expect_success 'clone separate gitdir where target already exists' ' rm -rf dst && test_must_fail git clone --separate-git-dir realgitdir src dst ' +test_expect_success 'clone --reference from original' ' + git clone --shared --bare src src-1 && + git clone --bare src src-2 && + git clone --reference=src-2 --bare src-1 target-8 && + grep /src-2/ target-8/objects/info/alternates +' + +test_expect_success 'clone with more than one --reference' ' + git clone --bare src src-3 && + git clone --bare src src-4 && + git clone --reference=src-3 --reference=src-4 src target-9 && + grep /src-3/ target-9/.git/objects/info/alternates && + grep /src-4/ target-9/.git/objects/info/alternates +' + +test_expect_success 'clone from original with relative alternate' ' + mkdir nest && + git clone --bare src nest/src-5 && + echo ../../../src/.git/objects >nest/src-5/objects/info/alternates && + git clone --bare nest/src-5 target-10 && + grep /src/\\.git/objects target-10/objects/info/alternates +' + test_done diff --git a/t/t5707-clone-detached.sh b/t/t5707-clone-detached.sh new file mode 100755 index 0000000000..8b0d607df1 --- /dev/null +++ b/t/t5707-clone-detached.sh @@ -0,0 +1,76 @@ +#!/bin/sh + +test_description='test cloning a repository with detached HEAD' +. ./test-lib.sh + +head_is_detached() { + git --git-dir=$1/.git rev-parse --verify HEAD && + test_must_fail git --git-dir=$1/.git symbolic-ref HEAD +} + +test_expect_success 'setup' ' + echo one >file && + git add file && + git commit -m one && + echo two >file && + git commit -a -m two && + git tag two && + echo three >file && + git commit -a -m three +' + +test_expect_success 'clone repo (detached HEAD points to branch)' ' + git checkout master^0 && + git clone "file://$PWD" detached-branch +' +test_expect_success 'cloned HEAD matches' ' + echo three >expect && + git --git-dir=detached-branch/.git log -1 --format=%s >actual && + test_cmp expect actual +' +test_expect_failure 'cloned HEAD is detached' ' + head_is_detached detached-branch +' + +test_expect_success 'clone repo (detached HEAD points to tag)' ' + git checkout two^0 && + git clone "file://$PWD" detached-tag +' +test_expect_success 'cloned HEAD matches' ' + echo two >expect && + git --git-dir=detached-tag/.git log -1 --format=%s >actual && + test_cmp expect actual +' +test_expect_success 'cloned HEAD is detached' ' + head_is_detached detached-tag +' + +test_expect_success 'clone repo (detached HEAD points to history)' ' + git checkout two^ && + git clone "file://$PWD" detached-history +' +test_expect_success 'cloned HEAD matches' ' + echo one >expect && + git --git-dir=detached-history/.git log -1 --format=%s >actual && + test_cmp expect actual +' +test_expect_success 'cloned HEAD is detached' ' + head_is_detached detached-history +' + +test_expect_success 'clone repo (orphan detached HEAD)' ' + git checkout master^0 && + echo four >file && + git commit -a -m four && + git clone "file://$PWD" detached-orphan +' +test_expect_success 'cloned HEAD matches' ' + echo four >expect && + git --git-dir=detached-orphan/.git log -1 --format=%s >actual && + test_cmp expect actual +' +test_expect_success 'cloned HEAD is detached' ' + head_is_detached detached-orphan +' + +test_done diff --git a/t/t5800-remote-helpers.sh b/t/t5800-remote-helpers.sh index 1fb6380fce..1c62001fce 100755 --- a/t/t5800-remote-helpers.sh +++ b/t/t5800-remote-helpers.sh @@ -7,17 +7,27 @@ test_description='Test remote-helper import and export commands' . ./test-lib.sh -if test_have_prereq PYTHON && "$PYTHON_PATH" -c ' +if ! test_have_prereq PYTHON ; then + skip_all='skipping git-remote-hg tests, python not available' + test_done +fi + +"$PYTHON_PATH" -c ' import sys if sys.hexversion < 0x02040000: sys.exit(1) -' -then - # Requires Python 2.4 or newer - test_set_prereq PYTHON_24 -fi +' || { + skip_all='skipping git-remote-hg tests, python version < 2.4' + test_done +} + +compare_refs() { + git --git-dir="$1/.git" rev-parse --verify $2 >expect && + git --git-dir="$3/.git" rev-parse --verify $4 >actual && + test_cmp expect actual +} -test_expect_success PYTHON_24 'setup repository' ' +test_expect_success 'setup repository' ' git init --bare server/.git && git clone server public && (cd public && @@ -27,54 +37,99 @@ test_expect_success PYTHON_24 'setup repository' ' git push origin master) ' -test_expect_success PYTHON_24 'cloning from local repo' ' +test_expect_success 'cloning from local repo' ' git clone "testgit::${PWD}/server" localclone && test_cmp public/file localclone/file ' -test_expect_success PYTHON_24 'cloning from remote repo' ' +test_expect_success 'cloning from remote repo' ' git clone "testgit::file://${PWD}/server" clone && test_cmp public/file clone/file ' -test_expect_success PYTHON_24 'create new commit on remote' ' +test_expect_success 'create new commit on remote' ' (cd public && echo content >>file && git commit -a -m two && git push) ' -test_expect_success PYTHON_24 'pulling from local repo' ' +test_expect_success 'pulling from local repo' ' (cd localclone && git pull) && test_cmp public/file localclone/file ' -test_expect_success PYTHON_24 'pulling from remote remote' ' +test_expect_success 'pulling from remote remote' ' (cd clone && git pull) && test_cmp public/file clone/file ' -test_expect_success PYTHON_24 'pushing to local repo' ' +test_expect_success 'pushing to local repo' ' (cd localclone && echo content >>file && git commit -a -m three && git push) && - HEAD=$(git --git-dir=localclone/.git rev-parse --verify HEAD) && - test $HEAD = $(git --git-dir=server/.git rev-parse --verify HEAD) + compare_refs localclone HEAD server HEAD ' -test_expect_success PYTHON_24 'synch with changes from localclone' ' +test_expect_success 'synch with changes from localclone' ' (cd clone && git pull) ' -test_expect_success PYTHON_24 'pushing remote local repo' ' +test_expect_success 'pushing remote local repo' ' (cd clone && echo content >>file && git commit -a -m four && git push) && - HEAD=$(git --git-dir=clone/.git rev-parse --verify HEAD) && - test $HEAD = $(git --git-dir=server/.git rev-parse --verify HEAD) + compare_refs clone HEAD server HEAD +' + +test_expect_success 'fetch new branch' ' + (cd public && + git checkout -b new && + echo content >>file && + git commit -a -m five && + git push origin new + ) && + (cd localclone && + git fetch origin new + ) && + compare_refs public HEAD localclone FETCH_HEAD +' + +test_expect_success 'fetch multiple branches' ' + (cd localclone && + git fetch + ) && + compare_refs server master localclone refs/remotes/origin/master && + compare_refs server new localclone refs/remotes/origin/new +' + +test_expect_success 'push when remote has extra refs' ' + (cd clone && + echo content >>file && + git commit -a -m six && + git push + ) && + compare_refs clone master server master +' + +test_expect_success 'push new branch by name' ' + (cd clone && + git checkout -b new-name && + echo content >>file && + git commit -a -m seven && + git push origin new-name + ) && + compare_refs clone HEAD server refs/heads/new-name +' + +test_expect_failure 'push new branch with old:new refspec' ' + (cd clone && + git push origin new-name:new-refspec + ) && + compare_refs clone HEAD server refs/heads/new-refspec ' test_done diff --git a/t/t6019-rev-list-ancestry-path.sh b/t/t6019-rev-list-ancestry-path.sh index 76410293b3..39b4cb0ecd 100755 --- a/t/t6019-rev-list-ancestry-path.sh +++ b/t/t6019-rev-list-ancestry-path.sh @@ -70,4 +70,42 @@ test_expect_success 'rev-list --ancestry-patch D..M -- M.t' ' test_cmp expect actual ' +# b---bc +# / \ / +# a X +# \ / \ +# c---cb +# +# All refnames prefixed with 'x' to avoid confusion with the tags +# generated by test_commit on case-insensitive systems. +test_expect_success 'setup criss-cross' ' + mkdir criss-cross && + (cd criss-cross && + git init && + test_commit A && + git checkout -b xb master && + test_commit B && + git checkout -b xc master && + test_commit C && + git checkout -b xbc xb -- && + git merge xc && + git checkout -b xcb xc -- && + git merge xb && + git checkout master) +' + +# no commits in bc descend from cb +test_expect_success 'criss-cross: rev-list --ancestry-path cb..bc' ' + (cd criss-cross && + git rev-list --ancestry-path xcb..xbc > actual && + test -z "$(cat actual)") +' + +# no commits in repository descend from cb +test_expect_success 'criss-cross: rev-list --ancestry-path --all ^cb' ' + (cd criss-cross && + git rev-list --ancestry-path --all ^xcb > actual && + test -z "$(cat actual)") +' + test_done diff --git a/t/t6020-merge-df.sh b/t/t6020-merge-df.sh index eec8f4e3ed..27c3d73961 100755 --- a/t/t6020-merge-df.sh +++ b/t/t6020-merge-df.sh @@ -59,15 +59,19 @@ test_expect_success 'setup modify/delete + directory/file conflict' ' git add letters && git commit -m initial && + # Throw in letters.txt for sorting order fun + # ("letters.txt" sorts between "letters" and "letters/file") echo i >>letters && - git add letters && + echo "version 2" >letters.txt && + git add letters letters.txt && git commit -m modified && git checkout -b delete HEAD^ && git rm letters && mkdir letters && >letters/file && - git add letters && + echo "version 1" >letters.txt && + git add letters letters.txt && git commit -m deleted ' @@ -75,25 +79,31 @@ test_expect_success 'modify/delete + directory/file conflict' ' git checkout delete^0 && test_must_fail git merge modify && - test 3 = $(git ls-files -s | wc -l) && - test 2 = $(git ls-files -u | wc -l) && - test 1 = $(git ls-files -o | wc -l) && + test 5 -eq $(git ls-files -s | wc -l) && + test 4 -eq $(git ls-files -u | wc -l) && + test 1 -eq $(git ls-files -o | wc -l) && test -f letters/file && + test -f letters.txt && test -f letters~modify ' test_expect_success 'modify/delete + directory/file conflict; other way' ' + # Yes, we really need the double reset since "letters" appears as + # both a file and a directory. + git reset --hard && git reset --hard && git clean -f && git checkout modify^0 && + test_must_fail git merge delete && - test 3 = $(git ls-files -s | wc -l) && - test 2 = $(git ls-files -u | wc -l) && - test 1 = $(git ls-files -o | wc -l) && + test 5 -eq $(git ls-files -s | wc -l) && + test 4 -eq $(git ls-files -u | wc -l) && + test 1 -eq $(git ls-files -o | wc -l) && test -f letters/file && + test -f letters.txt && test -f letters~HEAD ' diff --git a/t/t6022-merge-rename.sh b/t/t6022-merge-rename.sh index 1ed259d864..9d8584e957 100755 --- a/t/t6022-merge-rename.sh +++ b/t/t6022-merge-rename.sh @@ -252,6 +252,7 @@ test_expect_success 'setup for rename + d/f conflicts' ' git reset --hard && git checkout --orphan dir-in-way && git rm -rf . && + git clean -fdqx && mkdir sub && mkdir dir && @@ -302,11 +303,11 @@ test_expect_success 'Rename+D/F conflict; renamed file merges but dir in way' ' git checkout -q renamed-file-has-no-conflicts^0 && test_must_fail git merge --strategy=recursive dir-in-way >output && - grep "CONFLICT (delete/modify): dir/file-in-the-way" output && + grep "CONFLICT (modify/delete): dir/file-in-the-way" output && grep "Auto-merging dir" output && grep "Adding as dir~HEAD instead" output && - test 2 -eq "$(git ls-files -u | wc -l)" && + test 3 -eq "$(git ls-files -u | wc -l)" && test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" && test_must_fail git diff --quiet && @@ -324,11 +325,11 @@ test_expect_success 'Same as previous, but merged other way' ' test_must_fail git merge --strategy=recursive renamed-file-has-no-conflicts >output 2>errors && ! grep "error: refusing to lose untracked file at" errors && - grep "CONFLICT (delete/modify): dir/file-in-the-way" output && + grep "CONFLICT (modify/delete): dir/file-in-the-way" output && grep "Auto-merging dir" output && grep "Adding as dir~renamed-file-has-no-conflicts instead" output && - test 2 -eq "$(git ls-files -u | wc -l)" && + test 3 -eq "$(git ls-files -u | wc -l)" && test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" && test_must_fail git diff --quiet && @@ -350,11 +351,11 @@ cat >expected <<\EOF && 8 9 10 -<<<<<<< HEAD +<<<<<<< HEAD:dir 12 ======= 11 ->>>>>>> dir-not-in-way +>>>>>>> dir-not-in-way:sub/file EOF test_expect_success 'Rename+D/F conflict; renamed file cannot merge, dir not in way' ' @@ -404,11 +405,11 @@ cat >expected <<\EOF && 8 9 10 -<<<<<<< HEAD +<<<<<<< HEAD:sub/file 11 ======= 12 ->>>>>>> renamed-file-has-conflicts +>>>>>>> renamed-file-has-conflicts:dir EOF test_expect_success 'Same as previous, but merged other way' ' @@ -609,4 +610,278 @@ test_expect_success 'check handling of differently renamed file with D/F conflic ! test -f original ' +test_expect_success 'setup avoid unnecessary update, normal rename' ' + git reset --hard && + git checkout --orphan avoid-unnecessary-update-1 && + git rm -rf . && + git clean -fdqx && + + printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >original && + git add -A && + git commit -m "Common commmit" && + + git mv original rename && + echo 11 >>rename && + git add -u && + git commit -m "Renamed and modified" && + + git checkout -b merge-branch-1 HEAD~1 && + echo "random content" >random-file && + git add -A && + git commit -m "Random, unrelated changes" +' + +test_expect_success 'avoid unnecessary update, normal rename' ' + git checkout -q avoid-unnecessary-update-1^0 && + test-chmtime =1000000000 rename && + test-chmtime -v +0 rename >expect && + git merge merge-branch-1 && + test-chmtime -v +0 rename >actual && + test_cmp expect actual # "rename" should have stayed intact +' + +test_expect_success 'setup to test avoiding unnecessary update, with D/F conflict' ' + git reset --hard && + git checkout --orphan avoid-unnecessary-update-2 && + git rm -rf . && + git clean -fdqx && + + mkdir df && + printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >df/file && + git add -A && + git commit -m "Common commmit" && + + git mv df/file temp && + rm -rf df && + git mv temp df && + echo 11 >>df && + git add -u && + git commit -m "Renamed and modified" && + + git checkout -b merge-branch-2 HEAD~1 && + >unrelated-change && + git add unrelated-change && + git commit -m "Only unrelated changes" +' + +test_expect_success 'avoid unnecessary update, with D/F conflict' ' + git checkout -q avoid-unnecessary-update-2^0 && + test-chmtime =1000000000 df && + test-chmtime -v +0 df >expect && + git merge merge-branch-2 && + test-chmtime -v +0 df >actual && + test_cmp expect actual # "df" should have stayed intact +' + +test_expect_success 'setup avoid unnecessary update, dir->(file,nothing)' ' + git rm -rf . && + git clean -fdqx && + rm -rf .git && + git init && + + >irrelevant && + mkdir df && + >df/file && + git add -A && + git commit -mA && + + git checkout -b side + git rm -rf df && + git commit -mB && + + git checkout master && + git rm -rf df && + echo bla >df && + git add -A && + git commit -m "Add a newfile" +' + +test_expect_success 'avoid unnecessary update, dir->(file,nothing)' ' + git checkout -q master^0 && + test-chmtime =1000000000 df && + test-chmtime -v +0 df >expect && + git merge side && + test-chmtime -v +0 df >actual && + test_cmp expect actual # "df" should have stayed intact +' + +test_expect_success 'setup avoid unnecessary update, modify/delete' ' + git rm -rf . && + git clean -fdqx && + rm -rf .git && + git init && + + >irrelevant && + >file && + git add -A && + git commit -mA && + + git checkout -b side + git rm -f file && + git commit -m "Delete file" && + + git checkout master && + echo bla >file && + git add -A && + git commit -m "Modify file" +' + +test_expect_success 'avoid unnecessary update, modify/delete' ' + git checkout -q master^0 && + test-chmtime =1000000000 file && + test-chmtime -v +0 file >expect && + test_must_fail git merge side && + test-chmtime -v +0 file >actual && + test_cmp expect actual # "file" should have stayed intact +' + +test_expect_success 'setup avoid unnecessary update, rename/add-dest' ' + git rm -rf . && + git clean -fdqx && + rm -rf .git && + git init && + + printf "1\n2\n3\n4\n5\n6\n7\n8\n" >file && + git add -A && + git commit -mA && + + git checkout -b side + cp file newfile && + git add -A && + git commit -m "Add file copy" && + + git checkout master && + git mv file newfile && + git commit -m "Rename file" +' + +test_expect_success 'avoid unnecessary update, rename/add-dest' ' + git checkout -q master^0 && + test-chmtime =1000000000 newfile && + test-chmtime -v +0 newfile >expect && + git merge side && + test-chmtime -v +0 newfile >actual && + test_cmp expect actual # "file" should have stayed intact +' + +test_expect_success 'setup merge of rename + small change' ' + git reset --hard && + git checkout --orphan rename-plus-small-change && + git rm -rf . && + git clean -fdqx && + + echo ORIGINAL >file && + git add file && + + test_tick && + git commit -m Initial && + git checkout -b rename_branch && + git mv file renamed_file && + git commit -m Rename && + git checkout rename-plus-small-change && + echo NEW-VERSION >file && + git commit -a -m Reformat +' + +test_expect_success 'merge rename + small change' ' + git merge rename_branch && + + test 1 -eq $(git ls-files -s | wc -l) && + test 0 -eq $(git ls-files -o | wc -l) && + test $(git rev-parse HEAD:renamed_file) = $(git rev-parse HEAD~1:file) +' + +test_expect_success 'setup for use of extended merge markers' ' + git rm -rf . && + git clean -fdqx && + rm -rf .git && + git init && + + printf "1\n2\n3\n4\n5\n6\n7\n8\n" >original_file && + git add original_file && + git commit -mA && + + git checkout -b rename && + echo 9 >>original_file && + git add original_file && + git mv original_file renamed_file && + git commit -mB && + + git checkout master && + echo 8.5 >>original_file && + git add original_file && + git commit -mC +' + +cat >expected <<\EOF && +1 +2 +3 +4 +5 +6 +7 +8 +<<<<<<< HEAD:renamed_file +9 +======= +8.5 +>>>>>>> master^0:original_file +EOF + +test_expect_success 'merge master into rename has correct extended markers' ' + git checkout rename^0 && + test_must_fail git merge -s recursive master^0 && + test_cmp expected renamed_file +' + +cat >expected <<\EOF && +1 +2 +3 +4 +5 +6 +7 +8 +<<<<<<< HEAD:original_file +8.5 +======= +9 +>>>>>>> rename^0:renamed_file +EOF + +test_expect_success 'merge rename into master has correct extended markers' ' + git reset --hard && + git checkout master^0 && + test_must_fail git merge -s recursive rename^0 && + test_cmp expected renamed_file +' + +test_expect_success 'setup spurious "refusing to lose untracked" message' ' + git rm -rf . && + git clean -fdqx && + rm -rf .git && + git init && + + > irrelevant_file && + printf "1\n2\n3\n4\n5\n6\n7\n8\n" >original_file && + git add irrelevant_file original_file && + git commit -mA && + + git checkout -b rename && + git mv original_file renamed_file && + git commit -mB && + + git checkout master && + git rm original_file && + git commit -mC +' + +test_expect_success 'no spurious "refusing to lose untracked" message' ' + git checkout master^0 && + test_must_fail git merge rename^0 2>errors.txt && + ! grep "refusing to lose untracked file" errors.txt +' + test_done diff --git a/t/t6023-merge-file.sh b/t/t6023-merge-file.sh index d9f343942c..432f086c06 100755 --- a/t/t6023-merge-file.sh +++ b/t/t6023-merge-file.sh @@ -154,7 +154,7 @@ test_expect_success "expected conflict markers" "test_cmp expect out" test_expect_success 'binary files cannot be merged' ' test_must_fail git merge-file -p \ - orig.txt "$TEST_DIRECTORY"/test4012.png new1.txt 2> merge.err && + orig.txt "$TEST_DIRECTORY"/test-binary-1.png new1.txt 2> merge.err && grep "Cannot merge binary files" merge.err ' diff --git a/t/t6027-merge-binary.sh b/t/t6027-merge-binary.sh index b519626ca0..07735410b9 100755 --- a/t/t6027-merge-binary.sh +++ b/t/t6027-merge-binary.sh @@ -6,7 +6,7 @@ test_description='ask merge-recursive to merge binary files' test_expect_success setup ' - cat "$TEST_DIRECTORY"/test4012.png >m && + cat "$TEST_DIRECTORY"/test-binary-1.png >m && git add m && git ls-files -s | sed -e "s/ 0 / 1 /" >E1 && test_tick && diff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh index b5063b6fe6..c6f1f9f8ab 100755 --- a/t/t6030-bisect-porcelain.sh +++ b/t/t6030-bisect-porcelain.sh @@ -126,6 +126,18 @@ test_expect_success 'bisect reset removes packed refs' ' test -z "$(git for-each-ref "refs/heads/bisect")" ' +test_expect_success 'bisect reset removes bisect state after --no-checkout' ' + git bisect reset && + git bisect start --no-checkout && + git bisect good $HASH1 && + git bisect bad $HASH3 && + git bisect next && + git bisect reset && + test -z "$(git for-each-ref "refs/bisect/*")" && + test -z "$(git for-each-ref "refs/heads/bisect")" && + test -z "$(git for-each-ref "BISECT_HEAD")" +' + test_expect_success 'bisect start: back in good branch' ' git branch > branch.output && grep "* other" branch.output > /dev/null && @@ -138,15 +150,23 @@ test_expect_success 'bisect start: back in good branch' ' grep "* other" branch.output > /dev/null ' -test_expect_success 'bisect start: no ".git/BISECT_START" if junk rev' ' - git bisect start $HASH4 $HASH1 -- && - git bisect good && +test_expect_success 'bisect start: no ".git/BISECT_START" created if junk rev' ' + git bisect reset && test_must_fail git bisect start $HASH4 foo -- && git branch > branch.output && grep "* other" branch.output > /dev/null && test_must_fail test -e .git/BISECT_START ' +test_expect_success 'bisect start: existing ".git/BISECT_START" not modified if junk rev' ' + git bisect start $HASH4 $HASH1 -- && + git bisect good && + cp .git/BISECT_START saved && + test_must_fail git bisect start $HASH4 foo -- && + git branch > branch.output && + grep "* (no branch)" branch.output > /dev/null && + test_cmp saved .git/BISECT_START +' test_expect_success 'bisect start: no ".git/BISECT_START" if mistaken rev' ' git bisect start $HASH4 $HASH1 -- && git bisect good && @@ -572,6 +592,155 @@ test_expect_success 'erroring out when using bad path parameters' ' grep "bad path parameters" error.txt ' +test_expect_success 'test bisection on bare repo - --no-checkout specified' ' + git clone --bare . bare.nocheckout && + ( + cd bare.nocheckout && + git bisect start --no-checkout && + git bisect good $HASH1 && + git bisect bad $HASH4 && + git bisect run eval \ + "test \$(git rev-list BISECT_HEAD ^$HASH2 --max-count=1 | wc -l) = 0" \ + >../nocheckout.log && + git bisect reset + ) && + grep "$HASH3 is the first bad commit" nocheckout.log +' + + +test_expect_success 'test bisection on bare repo - --no-checkout defaulted' ' + git clone --bare . bare.defaulted && + ( + cd bare.defaulted && + git bisect start && + git bisect good $HASH1 && + git bisect bad $HASH4 && + git bisect run eval \ + "test \$(git rev-list BISECT_HEAD ^$HASH2 --max-count=1 | wc -l) = 0" \ + >../defaulted.log && + git bisect reset + ) && + grep "$HASH3 is the first bad commit" defaulted.log +' + # +# This creates a broken branch which cannot be checked out because +# the tree created has been deleted. # +# H1-H2-H3-H4-H5-H6-H7 <--other +# \ +# S5-S6'-S7'-S8'-S9 <--broken +# +# Commits marked with ' have a missing tree. +# +test_expect_success 'broken branch creation' ' + git bisect reset && + git checkout -b broken $HASH4 && + git tag BROKEN_HASH4 $HASH4 && + add_line_into_file "5(broken): first line on a broken branch" hello2 && + git tag BROKEN_HASH5 && + mkdir missing && + :> missing/MISSING && + git add missing/MISSING && + git commit -m "6(broken): Added file that will be deleted" + git tag BROKEN_HASH6 && + add_line_into_file "7(broken): second line on a broken branch" hello2 && + git tag BROKEN_HASH7 && + add_line_into_file "8(broken): third line on a broken branch" hello2 && + git tag BROKEN_HASH8 && + git rm missing/MISSING && + git commit -m "9(broken): Remove missing file" + git tag BROKEN_HASH9 && + rm .git/objects/39/f7e61a724187ab767d2e08442d9b6b9dab587d +' + +echo "" > expected.ok +cat > expected.missing-tree.default <<EOF +fatal: unable to read tree 39f7e61a724187ab767d2e08442d9b6b9dab587d +EOF + +test_expect_success 'bisect fails if tree is broken on start commit' ' + git bisect reset && + test_must_fail git bisect start BROKEN_HASH7 BROKEN_HASH4 2>error.txt && + test_cmp expected.missing-tree.default error.txt +' + +test_expect_success 'bisect fails if tree is broken on trial commit' ' + git bisect reset && + test_must_fail git bisect start BROKEN_HASH9 BROKEN_HASH4 2>error.txt && + git reset --hard broken && + git checkout broken && + test_cmp expected.missing-tree.default error.txt +' + +check_same() +{ + echo "Checking $1 is the same as $2" && + git rev-parse "$1" > expected.same && + git rev-parse "$2" > expected.actual && + test_cmp expected.same expected.actual +} + +test_expect_success 'bisect: --no-checkout - start commit bad' ' + git bisect reset && + git bisect start BROKEN_HASH7 BROKEN_HASH4 --no-checkout && + check_same BROKEN_HASH6 BISECT_HEAD && + git bisect reset +' + +test_expect_success 'bisect: --no-checkout - trial commit bad' ' + git bisect reset && + git bisect start broken BROKEN_HASH4 --no-checkout && + check_same BROKEN_HASH6 BISECT_HEAD && + git bisect reset +' + +test_expect_success 'bisect: --no-checkout - target before breakage' ' + git bisect reset && + git bisect start broken BROKEN_HASH4 --no-checkout && + check_same BROKEN_HASH6 BISECT_HEAD && + git bisect bad BISECT_HEAD && + check_same BROKEN_HASH5 BISECT_HEAD && + git bisect bad BISECT_HEAD && + check_same BROKEN_HASH5 bisect/bad && + git bisect reset +' + +test_expect_success 'bisect: --no-checkout - target in breakage' ' + git bisect reset && + git bisect start broken BROKEN_HASH4 --no-checkout && + check_same BROKEN_HASH6 BISECT_HEAD && + git bisect bad BISECT_HEAD && + check_same BROKEN_HASH5 BISECT_HEAD && + git bisect good BISECT_HEAD && + check_same BROKEN_HASH6 bisect/bad && + git bisect reset +' + +test_expect_success 'bisect: --no-checkout - target after breakage' ' + git bisect reset && + git bisect start broken BROKEN_HASH4 --no-checkout && + check_same BROKEN_HASH6 BISECT_HEAD && + git bisect good BISECT_HEAD && + check_same BROKEN_HASH8 BISECT_HEAD && + git bisect good BISECT_HEAD && + check_same BROKEN_HASH9 bisect/bad && + git bisect reset +' + +test_expect_success 'bisect: demonstrate identification of damage boundary' " + git bisect reset && + git checkout broken && + git bisect start broken master --no-checkout && + git bisect run \"\$SHELL_PATH\" -c ' + GOOD=\$(git for-each-ref \"--format=%(objectname)\" refs/bisect/good-*) && + git rev-list --objects BISECT_HEAD --not \$GOOD >tmp.\$\$ && + git pack-objects --stdout >/dev/null < tmp.\$\$ + rc=\$? + rm -f tmp.\$\$ + test \$rc = 0' && + check_same BROKEN_HASH6 bisect/bad && + git bisect reset +" + test_done diff --git a/t/t6036-recursive-corner-cases.sh b/t/t6036-recursive-corner-cases.sh index 871577d90c..dfee7d159b 100755 --- a/t/t6036-recursive-corner-cases.sh +++ b/t/t6036-recursive-corner-cases.sh @@ -1,9 +1,15 @@ #!/bin/sh -test_description='recursive merge corner cases' +test_description='recursive merge corner cases involving criss-cross merges' . ./test-lib.sh +get_clean_checkout () { + git reset --hard && + git clean -fdqx && + git checkout "$1" +} + # # L1 L2 # o---o @@ -51,23 +57,15 @@ test_expect_success 'merge simple rename+criss-cross with no modifications' ' test_must_fail git merge -s recursive R2^0 && - test 5 = $(git ls-files -s | wc -l) && - test 3 = $(git ls-files -u | wc -l) && - test 0 = $(git ls-files -o | wc -l) && + test 2 = $(git ls-files -s | wc -l) && + test 2 = $(git ls-files -u | wc -l) && + test 2 = $(git ls-files -o | wc -l) && - test $(git rev-parse :0:one) = $(git rev-parse L2:one) && - test $(git rev-parse :0:two) = $(git rev-parse R2:two) && test $(git rev-parse :2:three) = $(git rev-parse L2:three) && test $(git rev-parse :3:three) = $(git rev-parse R2:three) && - cp two merged && - >empty && - test_must_fail git merge-file \ - -L "Temporary merge branch 2" \ - -L "" \ - -L "Temporary merge branch 1" \ - merged empty one && - test $(git rev-parse :1:three) = $(git hash-object merged) + test $(git rev-parse L2:three) = $(git hash-object three~HEAD) && + test $(git rev-parse R2:three) = $(git hash-object three~R2^0) ' # @@ -126,24 +124,15 @@ test_expect_success 'merge criss-cross + rename merges with basic modification' test_must_fail git merge -s recursive R2^0 && - test 5 = $(git ls-files -s | wc -l) && - test 3 = $(git ls-files -u | wc -l) && - test 0 = $(git ls-files -o | wc -l) && + test 2 = $(git ls-files -s | wc -l) && + test 2 = $(git ls-files -u | wc -l) && + test 2 = $(git ls-files -o | wc -l) && - test $(git rev-parse :0:one) = $(git rev-parse L2:one) && - test $(git rev-parse :0:two) = $(git rev-parse R2:two) && test $(git rev-parse :2:three) = $(git rev-parse L2:three) && test $(git rev-parse :3:three) = $(git rev-parse R2:three) && - head -n 10 two >merged && - cp one merge-me && - >empty && - test_must_fail git merge-file \ - -L "Temporary merge branch 2" \ - -L "" \ - -L "Temporary merge branch 1" \ - merged empty merge-me && - test $(git rev-parse :1:three) = $(git hash-object merged) + test $(git rev-parse L2:three) = $(git hash-object three~HEAD) && + test $(git rev-parse R2:three) = $(git hash-object three~R2^0) ' # @@ -231,4 +220,557 @@ test_expect_success 'git detects differently handled merges conflict' ' test $(git rev-parse :1:new_a) = $(git hash-object merged) ' +# +# criss-cross + modify/delete: +# +# B D +# o---o +# / \ / \ +# A o X ? F +# \ / \ / +# o---o +# C E +# +# Commit A: file with contents 'A\n' +# Commit B: file with contents 'B\n' +# Commit C: file not present +# Commit D: file with contents 'B\n' +# Commit E: file not present +# +# Merging commits D & E should result in modify/delete conflict. + +test_expect_success 'setup criss-cross + modify/delete resolved differently' ' + git rm -rf . && + git clean -fdqx && + rm -rf .git && + git init && + + echo A >file && + git add file && + test_tick && + git commit -m A && + + git branch B && + git checkout -b C && + git rm file && + test_tick && + git commit -m C && + + git checkout B && + echo B >file && + git add file && + test_tick && + git commit -m B && + + git checkout B^0 && + test_must_fail git merge C && + echo B >file && + git add file && + test_tick && + git commit -m D && + git tag D && + + git checkout C^0 && + test_must_fail git merge B && + git rm file && + test_tick && + git commit -m E && + git tag E +' + +test_expect_success 'git detects conflict merging criss-cross+modify/delete' ' + git checkout D^0 && + + test_must_fail git merge -s recursive E^0 && + + test 2 -eq $(git ls-files -s | wc -l) && + test 2 -eq $(git ls-files -u | wc -l) && + + test $(git rev-parse :1:file) = $(git rev-parse master:file) && + test $(git rev-parse :2:file) = $(git rev-parse B:file) +' + +test_expect_success 'git detects conflict merging criss-cross+modify/delete, reverse direction' ' + git reset --hard && + git checkout E^0 && + + test_must_fail git merge -s recursive D^0 && + + test 2 -eq $(git ls-files -s | wc -l) && + test 2 -eq $(git ls-files -u | wc -l) && + + test $(git rev-parse :1:file) = $(git rev-parse master:file) && + test $(git rev-parse :3:file) = $(git rev-parse B:file) +' + +# +# criss-cross + modify/modify with very contrived file contents: +# +# B D +# o---o +# / \ / \ +# A o X ? F +# \ / \ / +# o---o +# C E +# +# Commit A: file with contents 'A\n' +# Commit B: file with contents 'B\n' +# Commit C: file with contents 'C\n' +# Commit D: file with contents 'D\n' +# Commit E: file with contents: +# <<<<<<< Temporary merge branch 1 +# C +# ======= +# B +# >>>>>>> Temporary merge branch 2 +# +# Now, when we merge commits D & E, does git detect the conflict? + +test_expect_success 'setup differently handled merges of content conflict' ' + git clean -fdqx && + rm -rf .git && + git init && + + echo A >file && + git add file && + test_tick && + git commit -m A && + + git branch B && + git checkout -b C && + echo C >file && + git add file && + test_tick && + git commit -m C && + + git checkout B && + echo B >file && + git add file && + test_tick && + git commit -m B && + + git checkout B^0 && + test_must_fail git merge C && + echo D >file && + git add file && + test_tick && + git commit -m D && + git tag D && + + git checkout C^0 && + test_must_fail git merge B && + cat <<EOF >file && +<<<<<<< Temporary merge branch 1 +C +======= +B +>>>>>>> Temporary merge branch 2 +EOF + git add file && + test_tick && + git commit -m E && + git tag E +' + +test_expect_failure 'git detects conflict w/ criss-cross+contrived resolution' ' + git checkout D^0 && + + test_must_fail git merge -s recursive E^0 && + + test 3 -eq $(git ls-files -s | wc -l) && + test 3 -eq $(git ls-files -u | wc -l) && + test 0 -eq $(git ls-files -o | wc -l) && + + test $(git rev-parse :2:file) = $(git rev-parse D:file) && + test $(git rev-parse :3:file) = $(git rev-parse E:file) +' + +# +# criss-cross + d/f conflict via add/add: +# Commit A: Neither file 'a' nor directory 'a/' exist. +# Commit B: Introduce 'a' +# Commit C: Introduce 'a/file' +# Commit D: Merge B & C, keeping 'a' and deleting 'a/' +# +# Two different later cases: +# Commit E1: Merge B & C, deleting 'a' but keeping 'a/file' +# Commit E2: Merge B & C, deleting 'a' but keeping a slightly modified 'a/file' +# +# B D +# o---o +# / \ / \ +# A o X ? F +# \ / \ / +# o---o +# C E1 or E2 +# +# Merging D & E1 requires we first create a virtual merge base X from +# merging A & B in memory. Now, if X could keep both 'a' and 'a/file' in +# the index, then the merge of D & E1 could be resolved cleanly with both +# 'a' and 'a/file' removed. Since git does not currently allow creating +# such a tree, the best we can do is have X contain both 'a~<unique>' and +# 'a/file' resulting in the merge of D and E1 having a rename/delete +# conflict for 'a'. (Although this merge appears to be unsolvable with git +# currently, git could do a lot better than it currently does with these +# d/f conflicts, which is the purpose of this test.) +# +# Merge of D & E2 has similar issues for path 'a', but should always result +# in a modify/delete conflict for path 'a/file'. +# +# We run each merge in both directions, to check for directional issues +# with D/F conflict handling. +# + +test_expect_success 'setup differently handled merges of directory/file conflict' ' + git rm -rf . && + git clean -fdqx && + rm -rf .git && + git init && + + >ignore-me && + git add ignore-me && + test_tick && + git commit -m A && + git tag A && + + git branch B && + git checkout -b C && + mkdir a && + echo 10 >a/file && + git add a/file && + test_tick && + git commit -m C && + + git checkout B && + echo 5 >a && + git add a && + test_tick && + git commit -m B && + + git checkout B^0 && + test_must_fail git merge C && + git clean -f && + rm -rf a/ && + echo 5 >a && + git add a && + test_tick && + git commit -m D && + git tag D && + + git checkout C^0 && + test_must_fail git merge B && + git clean -f && + git rm --cached a && + echo 10 >a/file && + git add a/file && + test_tick && + git commit -m E1 && + git tag E1 && + + git checkout C^0 && + test_must_fail git merge B && + git clean -f && + git rm --cached a && + printf "10\n11\n" >a/file && + git add a/file && + test_tick && + git commit -m E2 && + git tag E2 +' + +test_expect_success 'merge of D & E1 fails but has appropriate contents' ' + get_clean_checkout D^0 && + + test_must_fail git merge -s recursive E1^0 && + + test 2 -eq $(git ls-files -s | wc -l) && + test 1 -eq $(git ls-files -u | wc -l) && + test 0 -eq $(git ls-files -o | wc -l) && + + test $(git rev-parse :0:ignore-me) = $(git rev-parse A:ignore-me) && + test $(git rev-parse :2:a) = $(git rev-parse B:a) +' + +test_expect_success 'merge of E1 & D fails but has appropriate contents' ' + get_clean_checkout E1^0 && + + test_must_fail git merge -s recursive D^0 && + + test 2 -eq $(git ls-files -s | wc -l) && + test 1 -eq $(git ls-files -u | wc -l) && + test 0 -eq $(git ls-files -o | wc -l) && + + test $(git rev-parse :0:ignore-me) = $(git rev-parse A:ignore-me) && + test $(git rev-parse :3:a) = $(git rev-parse B:a) +' + +test_expect_success 'merge of D & E2 fails but has appropriate contents' ' + get_clean_checkout D^0 && + + test_must_fail git merge -s recursive E2^0 && + + test 4 -eq $(git ls-files -s | wc -l) && + test 3 -eq $(git ls-files -u | wc -l) && + test 1 -eq $(git ls-files -o | wc -l) && + + test $(git rev-parse :2:a) = $(git rev-parse B:a) && + test $(git rev-parse :3:a/file) = $(git rev-parse E2:a/file) && + test $(git rev-parse :1:a/file) = $(git rev-parse C:a/file) && + test $(git rev-parse :0:ignore-me) = $(git rev-parse A:ignore-me) && + + test -f a~HEAD +' + +test_expect_success 'merge of E2 & D fails but has appropriate contents' ' + get_clean_checkout E2^0 && + + test_must_fail git merge -s recursive D^0 && + + test 4 -eq $(git ls-files -s | wc -l) && + test 3 -eq $(git ls-files -u | wc -l) && + test 1 -eq $(git ls-files -o | wc -l) && + + test $(git rev-parse :3:a) = $(git rev-parse B:a) && + test $(git rev-parse :2:a/file) = $(git rev-parse E2:a/file) && + test $(git rev-parse :1:a/file) = $(git rev-parse C:a/file) + test $(git rev-parse :0:ignore-me) = $(git rev-parse A:ignore-me) && + + test -f a~D^0 +' + +# +# criss-cross with rename/rename(1to2)/modify followed by +# rename/rename(2to1)/modify: +# +# B D +# o---o +# / \ / \ +# A o X ? F +# \ / \ / +# o---o +# C E +# +# Commit A: new file: a +# Commit B: rename a->b, modifying by adding a line +# Commit C: rename a->c +# Commit D: merge B&C, resolving conflict by keeping contents in newname +# Commit E: merge B&C, resolving conflict similar to D but adding another line +# +# There is a conflict merging B & C, but one of filename not of file +# content. Whoever created D and E chose specific resolutions for that +# conflict resolution. Now, since: (1) there is no content conflict +# merging B & C, (2) D does not modify that merged content further, and (3) +# both D & E resolve the name conflict in the same way, the modification to +# newname in E should not cause any conflicts when it is merged with D. +# (Note that this can be accomplished by having the virtual merge base have +# the merged contents of b and c stored in a file named a, which seems like +# the most logical choice anyway.) +# +# Comment from Junio: I do not necessarily agree with the choice "a", but +# it feels sound to say "B and C do not agree what the final pathname +# should be, but we know this content was derived from the common A:a so we +# use one path whose name is arbitrary in the virtual merge base X between +# D and E" and then further let the rename detection to notice that that +# arbitrary path gets renamed between X-D to "newname" and X-E also to +# "newname" to resolve it as both sides renaming it to the same new +# name. It is akin to what we do at the content level, i.e. "B and C do not +# agree what the final contents should be, so we leave the conflict marker +# but that may cancel out at the final merge stage". + +test_expect_success 'setup rename/rename(1to2)/modify followed by what looks like rename/rename(2to1)/modify' ' + git reset --hard && + git rm -rf . && + git clean -fdqx && + rm -rf .git && + git init && + + printf "1\n2\n3\n4\n5\n6\n" >a && + git add a && + git commit -m A && + git tag A && + + git checkout -b B A && + git mv a b && + echo 7 >>b && + git add -u && + git commit -m B && + + git checkout -b C A && + git mv a c && + git commit -m C && + + git checkout -q B^0 && + git merge --no-commit -s ours C^0 && + git mv b newname && + git commit -m "Merge commit C^0 into HEAD" && + git tag D && + + git checkout -q C^0 && + git merge --no-commit -s ours B^0 && + git mv c newname && + printf "7\n8\n" >>newname && + git add -u && + git commit -m "Merge commit B^0 into HEAD" && + git tag E +' + +test_expect_success 'handle rename/rename(1to2)/modify followed by what looks like rename/rename(2to1)/modify' ' + git checkout D^0 && + + git merge -s recursive E^0 && + + test 1 -eq $(git ls-files -s | wc -l) && + test 0 -eq $(git ls-files -u | wc -l) && + test 0 -eq $(git ls-files -o | wc -l) && + + test $(git rev-parse HEAD:newname) = $(git rev-parse E:newname) +' + +# +# criss-cross with rename/rename(1to2)/add-source + resolvable modify/modify: +# +# B D +# o---o +# / \ / \ +# A o X ? F +# \ / \ / +# o---o +# C E +# +# Commit A: new file: a +# Commit B: rename a->b +# Commit C: rename a->c, add different a +# Commit D: merge B&C, keeping b&c and (new) a modified at beginning +# Commit E: merge B&C, keeping b&c and (new) a modified at end +# +# Merging commits D & E should result in no conflict; doing so correctly +# requires getting the virtual merge base (from merging B&C) right, handling +# renaming carefully (both in the virtual merge base and later), and getting +# content merge handled. + +test_expect_success 'setup criss-cross + rename/rename/add + modify/modify' ' + git rm -rf . && + git clean -fdqx && + rm -rf .git && + git init && + + printf "lots\nof\nwords\nand\ncontent\n" >a && + git add a && + git commit -m A && + git tag A && + + git checkout -b B A && + git mv a b && + git commit -m B && + + git checkout -b C A && + git mv a c && + printf "2\n3\n4\n5\n6\n7\n" >a && + git add a && + git commit -m C && + + git checkout B^0 && + git merge --no-commit -s ours C^0 && + git checkout C -- a c && + mv a old_a && + echo 1 >a && + cat old_a >>a && + rm old_a && + git add -u && + git commit -m "Merge commit C^0 into HEAD" && + git tag D && + + git checkout C^0 && + git merge --no-commit -s ours B^0 && + git checkout B -- b && + echo 8 >>a && + git add -u && + git commit -m "Merge commit B^0 into HEAD" && + git tag E +' + +test_expect_failure 'detect rename/rename/add-source for virtual merge-base' ' + git checkout D^0 && + + git merge -s recursive E^0 && + + test 3 -eq $(git ls-files -s | wc -l) && + test 0 -eq $(git ls-files -u | wc -l) && + test 0 -eq $(git ls-files -o | wc -l) && + + test $(git rev-parse HEAD:b) = $(git rev-parse A:a) && + test $(git rev-parse HEAD:c) = $(git rev-parse A:a) && + test "$(cat a)" = "$(printf "1\n2\n3\n4\n5\n6\n7\n8\n")" +' + +# +# criss-cross with rename/rename(1to2)/add-dest + simple modify: +# +# B D +# o---o +# / \ / \ +# A o X ? F +# \ / \ / +# o---o +# C E +# +# Commit A: new file: a +# Commit B: rename a->b, add c +# Commit C: rename a->c +# Commit D: merge B&C, keeping A:a and B:c +# Commit E: merge B&C, keeping A:a and slightly modified c from B +# +# Merging commits D & E should result in no conflict. The virtual merge +# base of B & C needs to not delete B:c for that to work, though... + +test_expect_success 'setup criss-cross+rename/rename/add-dest + simple modify' ' + git rm -rf . && + git clean -fdqx && + rm -rf .git && + git init && + + >a && + git add a && + git commit -m A && + git tag A && + + git checkout -b B A && + git mv a b && + printf "1\n2\n3\n4\n5\n6\n7\n" >c && + git add c && + git commit -m B && + + git checkout -b C A && + git mv a c && + git commit -m C && + + git checkout B^0 && + git merge --no-commit -s ours C^0 && + git mv b a && + git commit -m "D is like B but renames b back to a" && + git tag D && + + git checkout B^0 && + git merge --no-commit -s ours C^0 && + git mv b a && + echo 8 >>c && + git add c && + git commit -m "E like D but has mod in c" && + git tag E +' + +test_expect_success 'virtual merge base handles rename/rename(1to2)/add-dest' ' + git checkout D^0 && + + git merge -s recursive E^0 && + + test 2 -eq $(git ls-files -s | wc -l) && + test 0 -eq $(git ls-files -u | wc -l) && + test 0 -eq $(git ls-files -o | wc -l) && + + test $(git rev-parse HEAD:a) = $(git rev-parse A:a) && + test $(git rev-parse HEAD:c) = $(git rev-parse E:c) +' + test_done diff --git a/t/t6040-tracking-info.sh b/t/t6040-tracking-info.sh index a9b0ac1efc..19272bc551 100755 --- a/t/t6040-tracking-info.sh +++ b/t/t6040-tracking-info.sh @@ -51,6 +51,22 @@ test_expect_success 'branch -v' ' test_i18ncmp expect actual ' +cat >expect <<\EOF +b1 origin/master: ahead 1, behind 1 +b2 origin/master: ahead 1, behind 1 +b3 origin/master: behind 1 +b4 origin/master: ahead 2 +EOF + +test_expect_success 'branch -vv' ' + ( + cd test && + git branch -vv + ) | + sed -n -e "$script" >actual && + test_i18ncmp expect actual +' + test_expect_success 'checkout' ' ( cd test && git checkout b1 @@ -110,4 +126,18 @@ test_expect_success '--set-upstream does not change branch' ' grep -q "^refs/heads/master$" actual && cmp expect2 actual2 ' + +test_expect_success '--set-upstream @{-1}' ' + git checkout from-master && + git checkout from-master2 && + git config branch.from-master2.merge > expect2 && + git branch --set-upstream @{-1} follower && + git config branch.from-master.merge > actual && + git config branch.from-master2.merge > actual2 && + git branch --set-upstream from-master follower && + git config branch.from-master.merge > expect && + test_cmp expect2 actual2 && + test_cmp expect actual +' + test_done diff --git a/t/t6042-merge-rename-corner-cases.sh b/t/t6042-merge-rename-corner-cases.sh new file mode 100755 index 0000000000..32591f9413 --- /dev/null +++ b/t/t6042-merge-rename-corner-cases.sh @@ -0,0 +1,578 @@ +#!/bin/sh + +test_description="recursive merge corner cases w/ renames but not criss-crosses" +# t6036 has corner cases that involve both criss-cross merges and renames + +. ./test-lib.sh + +test_expect_success 'setup rename/delete + untracked file' ' + echo "A pretty inscription" >ring && + git add ring && + test_tick && + git commit -m beginning && + + git branch people && + git checkout -b rename-the-ring && + git mv ring one-ring-to-rule-them-all && + test_tick && + git commit -m fullname && + + git checkout people && + git rm ring && + echo gollum >owner && + git add owner && + test_tick && + git commit -m track-people-instead-of-objects && + echo "Myyy PRECIOUSSS" >ring +' + +test_expect_success "Does git preserve Gollum's precious artifact?" ' + test_must_fail git merge -s recursive rename-the-ring && + + # Make sure git did not delete an untracked file + test -f ring +' + +# Testcase setup for rename/modify/add-source: +# Commit A: new file: a +# Commit B: modify a slightly +# Commit C: rename a->b, add completely different a +# +# We should be able to merge B & C cleanly + +test_expect_success 'setup rename/modify/add-source conflict' ' + git rm -rf . && + git clean -fdqx && + rm -rf .git && + git init && + + printf "1\n2\n3\n4\n5\n6\n7\n" >a && + git add a && + git commit -m A && + git tag A && + + git checkout -b B A && + echo 8 >>a && + git add a && + git commit -m B && + + git checkout -b C A && + git mv a b && + echo something completely different >a && + git add a && + git commit -m C +' + +test_expect_failure 'rename/modify/add-source conflict resolvable' ' + git checkout B^0 && + + git merge -s recursive C^0 && + + test $(git rev-parse B:a) = $(git rev-parse b) && + test $(git rev-parse C:a) = $(git rev-parse a) +' + +test_expect_success 'setup resolvable conflict missed if rename missed' ' + git rm -rf . && + git clean -fdqx && + rm -rf .git && + git init && + + printf "1\n2\n3\n4\n5\n" >a && + echo foo >b && + git add a b && + git commit -m A && + git tag A && + + git checkout -b B A && + git mv a c && + echo "Completely different content" >a && + git add a && + git commit -m B && + + git checkout -b C A && + echo 6 >>a && + git add a && + git commit -m C +' + +test_expect_failure 'conflict caused if rename not detected' ' + git checkout -q C^0 && + git merge -s recursive B^0 && + + test 3 -eq $(git ls-files -s | wc -l) && + test 0 -eq $(git ls-files -u | wc -l) && + test 0 -eq $(git ls-files -o | wc -l) && + + test 6 -eq $(wc -l < c) && + test $(git rev-parse HEAD:a) = $(git rev-parse B:a) && + test $(git rev-parse HEAD:b) = $(git rev-parse A:b) +' + +test_expect_success 'setup conflict resolved wrong if rename missed' ' + git reset --hard && + git clean -f && + + git checkout -b D A && + echo 7 >>a && + git add a && + git mv a c && + echo "Completely different content" >a && + git add a && + git commit -m D && + + git checkout -b E A && + git rm a && + echo "Completely different content" >>a && + git add a && + git commit -m E +' + +test_expect_failure 'missed conflict if rename not detected' ' + git checkout -q E^0 && + test_must_fail git merge -s recursive D^0 +' + +# Tests for undetected rename/add-source causing a file to erroneously be +# deleted (and for mishandled rename/rename(1to1) causing the same issue). +# +# This test uses a rename/rename(1to1)+add-source conflict (1to1 means the +# same file is renamed on both sides to the same thing; it should trigger +# the 1to2 logic, which it would do if the add-source didn't cause issues +# for git's rename detection): +# Commit A: new file: a +# Commit B: rename a->b +# Commit C: rename a->b, add unrelated a + +test_expect_success 'setup undetected rename/add-source causes data loss' ' + git rm -rf . && + git clean -fdqx && + rm -rf .git && + git init && + + printf "1\n2\n3\n4\n5\n" >a && + git add a && + git commit -m A && + git tag A && + + git checkout -b B A && + git mv a b && + git commit -m B && + + git checkout -b C A && + git mv a b && + echo foobar >a && + git add a && + git commit -m C +' + +test_expect_failure 'detect rename/add-source and preserve all data' ' + git checkout B^0 && + + git merge -s recursive C^0 && + + test 2 -eq $(git ls-files -s | wc -l) && + test 2 -eq $(git ls-files -u | wc -l) && + test 0 -eq $(git ls-files -o | wc -l) && + + test -f a && + test -f b && + + test $(git rev-parse HEAD:b) = $(git rev-parse A:a) && + test $(git rev-parse HEAD:a) = $(git rev-parse C:a) +' + +test_expect_failure 'detect rename/add-source and preserve all data, merge other way' ' + git checkout C^0 && + + git merge -s recursive B^0 && + + test 2 -eq $(git ls-files -s | wc -l) && + test 2 -eq $(git ls-files -u | wc -l) && + test 0 -eq $(git ls-files -o | wc -l) && + + test -f a && + test -f b && + + test $(git rev-parse HEAD:b) = $(git rev-parse A:a) && + test $(git rev-parse HEAD:a) = $(git rev-parse C:a) +' + +test_expect_success 'setup content merge + rename/directory conflict' ' + git rm -rf . && + git clean -fdqx && + rm -rf .git && + git init && + + printf "1\n2\n3\n4\n5\n6\n" >file && + git add file && + test_tick && + git commit -m base && + git tag base && + + git checkout -b right && + echo 7 >>file && + mkdir newfile && + echo junk >newfile/realfile && + git add file newfile/realfile && + test_tick && + git commit -m right && + + git checkout -b left-conflict base && + echo 8 >>file && + git add file && + git mv file newfile && + test_tick && + git commit -m left && + + git checkout -b left-clean base && + echo 0 >newfile && + cat file >>newfile && + git add newfile && + git rm file && + test_tick && + git commit -m left +' + +test_expect_success 'rename/directory conflict + clean content merge' ' + git reset --hard && + git reset --hard && + git clean -fdqx && + + git checkout left-clean^0 && + + test_must_fail git merge -s recursive right^0 && + + test 2 -eq $(git ls-files -s | wc -l) && + test 1 -eq $(git ls-files -u | wc -l) && + test 1 -eq $(git ls-files -o | wc -l) && + + echo 0 >expect && + git cat-file -p base:file >>expect && + echo 7 >>expect && + test_cmp expect newfile~HEAD && + + test $(git rev-parse :2:newfile) = $(git hash-object expect) && + + test -f newfile/realfile && + test -f newfile~HEAD +' + +test_expect_success 'rename/directory conflict + content merge conflict' ' + git reset --hard && + git reset --hard && + git clean -fdqx && + + git checkout left-conflict^0 && + + test_must_fail git merge -s recursive right^0 && + + test 4 -eq $(git ls-files -s | wc -l) && + test 3 -eq $(git ls-files -u | wc -l) && + test 1 -eq $(git ls-files -o | wc -l) && + + git cat-file -p left-conflict:newfile >left && + git cat-file -p base:file >base && + git cat-file -p right:file >right && + test_must_fail git merge-file \ + -L "HEAD:newfile" \ + -L "" \ + -L "right^0:file" \ + left base right && + test_cmp left newfile~HEAD && + + test $(git rev-parse :1:newfile) = $(git rev-parse base:file) && + test $(git rev-parse :2:newfile) = $(git rev-parse left-conflict:newfile) && + test $(git rev-parse :3:newfile) = $(git rev-parse right:file) && + + test -f newfile/realfile && + test -f newfile~HEAD +' + +test_expect_success 'setup content merge + rename/directory conflict w/ disappearing dir' ' + git reset --hard && + git rm -rf . && + git clean -fdqx && + rm -rf .git && + git init && + + mkdir sub && + printf "1\n2\n3\n4\n5\n6\n" >sub/file && + git add sub/file && + test_tick && + git commit -m base && + git tag base && + + git checkout -b right && + echo 7 >>sub/file && + git add sub/file && + test_tick && + git commit -m right && + + git checkout -b left base && + echo 0 >newfile && + cat sub/file >>newfile && + git rm sub/file && + mv newfile sub && + git add sub && + test_tick && + git commit -m left +' + +test_expect_success 'disappearing dir in rename/directory conflict handled' ' + git reset --hard && + git clean -fdqx && + + git checkout left^0 && + + git merge -s recursive right^0 && + + test 1 -eq $(git ls-files -s | wc -l) && + test 0 -eq $(git ls-files -u | wc -l) && + test 0 -eq $(git ls-files -o | wc -l) && + + echo 0 >expect && + git cat-file -p base:sub/file >>expect && + echo 7 >>expect && + test_cmp expect sub && + + test -f sub +' + +# Test for all kinds of things that can go wrong with rename/rename (2to1): +# Commit A: new files: a & b +# Commit B: rename a->c, modify b +# Commit C: rename b->c, modify a +# +# Merging of B & C should NOT be clean. Questions: +# * Both a & b should be removed by the merge; are they? +# * The two c's should contain modifications to a & b; do they? +# * The index should contain two files, both for c; does it? +# * The working copy should have two files, both of form c~<unique>; does it? +# * Nothing else should be present. Is anything? + +test_expect_success 'setup rename/rename (2to1) + modify/modify' ' + git rm -rf . && + git clean -fdqx && + rm -rf .git && + git init && + + printf "1\n2\n3\n4\n5\n" >a && + printf "5\n4\n3\n2\n1\n" >b && + git add a b && + git commit -m A && + git tag A && + + git checkout -b B A && + git mv a c && + echo 0 >>b && + git add b && + git commit -m B && + + git checkout -b C A && + git mv b c && + echo 6 >>a && + git add a && + git commit -m C +' + +test_expect_success 'handle rename/rename (2to1) conflict correctly' ' + git checkout B^0 && + + test_must_fail git merge -s recursive C^0 >out && + grep "CONFLICT (rename/rename)" out && + + test 2 -eq $(git ls-files -s | wc -l) && + test 2 -eq $(git ls-files -u | wc -l) && + test 2 -eq $(git ls-files -u c | wc -l) && + test 3 -eq $(git ls-files -o | wc -l) && + + test ! -f a && + test ! -f b && + test -f c~HEAD && + test -f c~C^0 && + + test $(git hash-object c~HEAD) = $(git rev-parse C:a) && + test $(git hash-object c~C^0) = $(git rev-parse B:b) +' + +# Testcase setup for simple rename/rename (1to2) conflict: +# Commit A: new file: a +# Commit B: rename a->b +# Commit C: rename a->c +test_expect_success 'setup simple rename/rename (1to2) conflict' ' + git rm -rf . && + git clean -fdqx && + rm -rf .git && + git init && + + echo stuff >a && + git add a && + test_tick && + git commit -m A && + git tag A && + + git checkout -b B A && + git mv a b && + test_tick && + git commit -m B && + + git checkout -b C A && + git mv a c && + test_tick && + git commit -m C +' + +test_expect_success 'merge has correct working tree contents' ' + git checkout C^0 && + + test_must_fail git merge -s recursive B^0 && + + test 3 -eq $(git ls-files -s | wc -l) && + test 3 -eq $(git ls-files -u | wc -l) && + test 0 -eq $(git ls-files -o | wc -l) && + + test $(git rev-parse :1:a) = $(git rev-parse A:a) && + test $(git rev-parse :3:b) = $(git rev-parse A:a) && + test $(git rev-parse :2:c) = $(git rev-parse A:a) && + + test ! -f a && + test $(git hash-object b) = $(git rev-parse A:a) && + test $(git hash-object c) = $(git rev-parse A:a) +' + +# Testcase setup for rename/rename(1to2)/add-source conflict: +# Commit A: new file: a +# Commit B: rename a->b +# Commit C: rename a->c, add completely different a +# +# Merging of B & C should NOT be clean; there's a rename/rename conflict + +test_expect_success 'setup rename/rename(1to2)/add-source conflict' ' + git rm -rf . && + git clean -fdqx && + rm -rf .git && + git init && + + printf "1\n2\n3\n4\n5\n6\n7\n" >a && + git add a && + git commit -m A && + git tag A && + + git checkout -b B A && + git mv a b && + git commit -m B && + + git checkout -b C A && + git mv a c && + echo something completely different >a && + git add a && + git commit -m C +' + +test_expect_failure 'detect conflict with rename/rename(1to2)/add-source merge' ' + git checkout B^0 && + + test_must_fail git merge -s recursive C^0 && + + test 4 -eq $(git ls-files -s | wc -l) && + test 0 -eq $(git ls-files -o | wc -l) && + + test $(git rev-parse 3:a) = $(git rev-parse C:a) && + test $(git rev-parse 1:a) = $(git rev-parse A:a) && + test $(git rev-parse 2:b) = $(git rev-parse B:b) && + test $(git rev-parse 3:c) = $(git rev-parse C:c) && + + test -f a && + test -f b && + test -f c +' + +test_expect_success 'setup rename/rename(1to2)/add-source resolvable conflict' ' + git rm -rf . && + git clean -fdqx && + rm -rf .git && + git init && + + >a && + git add a && + test_tick && + git commit -m base && + git tag A && + + git checkout -b B A && + git mv a b && + test_tick && + git commit -m one && + + git checkout -b C A && + git mv a b && + echo important-info >a && + git add a && + test_tick && + git commit -m two +' + +test_expect_failure 'rename/rename/add-source still tracks new a file' ' + git checkout C^0 && + git merge -s recursive B^0 && + + test 2 -eq $(git ls-files -s | wc -l) && + test 0 -eq $(git ls-files -o | wc -l) && + + test $(git rev-parse HEAD:a) = $(git rev-parse C:a) && + test $(git rev-parse HEAD:b) = $(git rev-parse A:a) +' + +test_expect_success 'setup rename/rename(1to2)/add-dest conflict' ' + git rm -rf . && + git clean -fdqx && + rm -rf .git && + git init && + + echo stuff >a && + git add a && + test_tick && + git commit -m base && + git tag A && + + git checkout -b B A && + git mv a b && + echo precious-data >c && + git add c && + test_tick && + git commit -m one && + + git checkout -b C A && + git mv a c && + echo important-info >b && + git add b && + test_tick && + git commit -m two +' + +test_expect_success 'rename/rename/add-dest merge still knows about conflicting file versions' ' + git checkout C^0 && + test_must_fail git merge -s recursive B^0 && + + test 5 -eq $(git ls-files -s | wc -l) && + test 2 -eq $(git ls-files -u b | wc -l) && + test 2 -eq $(git ls-files -u c | wc -l) && + test 4 -eq $(git ls-files -o | wc -l) && + + test $(git rev-parse :1:a) = $(git rev-parse A:a) && + test $(git rev-parse :2:b) = $(git rev-parse C:b) && + test $(git rev-parse :3:b) = $(git rev-parse B:b) && + test $(git rev-parse :2:c) = $(git rev-parse C:c) && + test $(git rev-parse :3:c) = $(git rev-parse B:c) && + + test $(git hash-object c~HEAD) = $(git rev-parse C:c) && + test $(git hash-object c~B\^0) = $(git rev-parse B:c) && + test $(git hash-object b~HEAD) = $(git rev-parse C:b) && + test $(git hash-object b~B\^0) = $(git rev-parse B:b) && + + test ! -f b && + test ! -f c +' + +test_done diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh index 7dc8a510c7..172178490a 100755 --- a/t/t6300-for-each-ref.sh +++ b/t/t6300-for-each-ref.sh @@ -6,6 +6,7 @@ test_description='for-each-ref test' . ./test-lib.sh +. "$TEST_DIRECTORY"/lib-gpg.sh # Mon Jul 3 15:18:43 2006 +0000 datestamp=1151939923 @@ -37,11 +38,13 @@ test_atom() { case "$1" in head) ref=refs/heads/master ;; tag) ref=refs/tags/testtag ;; + *) ref=$1 ;; esac printf '%s\n' "$3" >expected - test_expect_${4:-success} "basic atom: $1 $2" " + test_expect_${4:-success} $PREREQ "basic atom: $1 $2" " git for-each-ref --format='%($2)' $ref >actual && - test_cmp expected actual + sanitize_pgp <actual >actual.clean && + test_cmp expected actual.clean " } @@ -71,7 +74,10 @@ test_atom head taggerdate '' test_atom head creator 'C O Mitter <committer@example.com> 1151939923 +0200' test_atom head creatordate 'Mon Jul 3 17:18:43 2006 +0200' test_atom head subject 'Initial' +test_atom head contents:subject 'Initial' test_atom head body '' +test_atom head contents:body '' +test_atom head contents:signature '' test_atom head contents 'Initial ' @@ -101,7 +107,10 @@ test_atom tag taggerdate 'Mon Jul 3 17:18:45 2006 +0200' test_atom tag creator 'C O Mitter <committer@example.com> 1151939925 +0200' test_atom tag creatordate 'Mon Jul 3 17:18:45 2006 +0200' test_atom tag subject 'Tagging at 1151939927' +test_atom tag contents:subject 'Tagging at 1151939927' test_atom tag body '' +test_atom tag contents:body '' +test_atom tag contents:signature '' test_atom tag contents 'Tagging at 1151939927 ' @@ -359,4 +368,92 @@ test_expect_success 'an unusual tag with an incomplete line' ' ' +test_expect_success 'create tag with subject and body content' ' + cat >>msg <<-\EOF && + the subject line + + first body line + second body line + EOF + git tag -F msg subject-body +' +test_atom refs/tags/subject-body subject 'the subject line' +test_atom refs/tags/subject-body body 'first body line +second body line +' +test_atom refs/tags/subject-body contents 'the subject line + +first body line +second body line +' + +test_expect_success 'create tag with multiline subject' ' + cat >msg <<-\EOF && + first subject line + second subject line + + first body line + second body line + EOF + git tag -F msg multiline +' +test_atom refs/tags/multiline subject 'first subject line second subject line' +test_atom refs/tags/multiline contents:subject 'first subject line second subject line' +test_atom refs/tags/multiline body 'first body line +second body line +' +test_atom refs/tags/multiline contents:body 'first body line +second body line +' +test_atom refs/tags/multiline contents:signature '' +test_atom refs/tags/multiline contents 'first subject line +second subject line + +first body line +second body line +' + +test_expect_success GPG 'create signed tags' ' + git tag -s -m "" signed-empty && + git tag -s -m "subject line" signed-short && + cat >msg <<-\EOF && + subject line + + body contents + EOF + git tag -s -F msg signed-long +' + +sig='-----BEGIN PGP SIGNATURE----- +-----END PGP SIGNATURE----- +' + +PREREQ=GPG +test_atom refs/tags/signed-empty subject '' +test_atom refs/tags/signed-empty contents:subject '' +test_atom refs/tags/signed-empty body "$sig" +test_atom refs/tags/signed-empty contents:body '' +test_atom refs/tags/signed-empty contents:signature "$sig" +test_atom refs/tags/signed-empty contents "$sig" + +test_atom refs/tags/signed-short subject 'subject line' +test_atom refs/tags/signed-short contents:subject 'subject line' +test_atom refs/tags/signed-short body "$sig" +test_atom refs/tags/signed-short contents:body '' +test_atom refs/tags/signed-short contents:signature "$sig" +test_atom refs/tags/signed-short contents "subject line +$sig" + +test_atom refs/tags/signed-long subject 'subject line' +test_atom refs/tags/signed-long contents:subject 'subject line' +test_atom refs/tags/signed-long body "body contents +$sig" +test_atom refs/tags/signed-long contents:body 'body contents +' +test_atom refs/tags/signed-long contents:signature "$sig" +test_atom refs/tags/signed-long contents "subject line + +body contents +$sig" + test_done diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh index 097ce2bc83..e93ac73829 100755 --- a/t/t7004-tag.sh +++ b/t/t7004-tag.sh @@ -8,6 +8,7 @@ test_description='git tag Tests for operations with tags.' . ./test-lib.sh +. "$TEST_DIRECTORY"/lib-gpg.sh # creating and listing lightweight tags: @@ -585,24 +586,6 @@ test_expect_success \ test_cmp expect actual ' -# subsequent tests require gpg; check if it is available -gpg --version >/dev/null 2>/dev/null -if [ $? -eq 127 ]; then - say "# gpg not found - skipping tag signing and verification tests" -else - # As said here: http://www.gnupg.org/documentation/faqs.html#q6.19 - # the gpg version 1.0.6 didn't parse trust packets correctly, so for - # that version, creation of signed tags using the generated key fails. - case "$(gpg --version)" in - 'gpg (GnuPG) 1.0.6'*) - say "Skipping signed tag tests, because a bug in 1.0.6 version" - ;; - *) - test_set_prereq GPG - ;; - esac -fi - # trying to verify annotated non-signed tags: test_expect_success GPG \ @@ -625,16 +608,6 @@ test_expect_success GPG \ # creating and verifying signed tags: -# key generation info: gpg --homedir t/t7004 --gen-key -# Type DSA and Elgamal, size 2048 bits, no expiration date. -# Name and email: C O Mitter <committer@example.com> -# No password given, to enable non-interactive operation. - -cp -R "$TEST_DIRECTORY"/t7004 ./gpghome -chmod 0700 gpghome -GNUPGHOME="$(pwd)/gpghome" -export GNUPGHOME - get_tag_header signed-tag $commit commit $time >expect echo 'A signed tag message' >>expect echo '-----BEGIN PGP SIGNATURE-----' >>expect diff --git a/t/t7006-pager.sh b/t/t7006-pager.sh index ed7575d0fd..320e1d1dbe 100755 --- a/t/t7006-pager.sh +++ b/t/t7006-pager.sh @@ -13,7 +13,7 @@ cleanup_fail() { test_expect_success 'setup' ' sane_unset GIT_PAGER GIT_PAGER_IN_USE && - test_might_fail git config --unset core.pager && + test_unconfig core.pager && PAGER="cat >paginated.out" && export PAGER && @@ -94,21 +94,19 @@ test_expect_success TTY 'no pager with --no-pager' ' test_expect_success TTY 'configuration can disable pager' ' rm -f paginated.out && - test_might_fail git config --unset pager.grep && + test_unconfig pager.grep && test_terminal git grep initial && test -e paginated.out && rm -f paginated.out && - git config pager.grep false && - test_when_finished "git config --unset pager.grep" && + test_config pager.grep false && test_terminal git grep initial && ! test -e paginated.out ' test_expect_success TTY 'git config uses a pager if configured to' ' rm -f paginated.out && - git config pager.config true && - test_when_finished "git config --unset pager.config" && + test_config pager.config true && test_terminal git config --list && test -e paginated.out ' @@ -116,8 +114,7 @@ test_expect_success TTY 'git config uses a pager if configured to' ' test_expect_success TTY 'configuration can enable pager (from subdir)' ' rm -f paginated.out && mkdir -p subdir && - git config pager.bundle true && - test_when_finished "git config --unset pager.bundle" && + test_config pager.bundle true && git bundle create test.bundle --all && rm -f paginated.out subdir/paginated.out && @@ -150,7 +147,7 @@ test_expect_success 'tests can detect color' ' test_expect_success 'no color when stdout is a regular file' ' rm -f colorless.log && - git config color.ui auto || + test_config color.ui auto || cleanup_fail && git log >colorless.log && @@ -159,7 +156,7 @@ test_expect_success 'no color when stdout is a regular file' ' test_expect_success TTY 'color when writing to a pager' ' rm -f paginated.out && - git config color.ui auto || + test_config color.ui auto || cleanup_fail && ( @@ -170,9 +167,21 @@ test_expect_success TTY 'color when writing to a pager' ' colorful paginated.out ' +test_expect_success TTY 'colors are suppressed by color.pager' ' + rm -f paginated.out && + test_config color.ui auto && + test_config color.pager false && + ( + TERM=vt100 && + export TERM && + test_terminal git log + ) && + ! colorful paginated.out +' + test_expect_success 'color when writing to a file intended for a pager' ' rm -f colorful.log && - git config color.ui auto || + test_config color.ui auto || cleanup_fail && ( @@ -184,6 +193,17 @@ test_expect_success 'color when writing to a file intended for a pager' ' colorful colorful.log ' +test_expect_success TTY 'colors are sent to pager for external commands' ' + test_config alias.externallog "!git log" && + test_config color.ui auto && + ( + TERM=vt100 && + export TERM && + test_terminal git -p externallog + ) && + colorful paginated.out +' + # Use this helper to make it easy for the caller of your # terminal-using function to specify whether it should fail. # If you write @@ -221,7 +241,7 @@ test_default_pager() { $test_expectation SIMPLEPAGER,TTY "$cmd - default pager is used by default" " sane_unset PAGER GIT_PAGER && - test_might_fail git config --unset core.pager && + test_unconfig core.pager && rm -f default_pager_used || cleanup_fail && @@ -244,7 +264,7 @@ test_PAGER_overrides() { $test_expectation TTY "$cmd - PAGER overrides default pager" " sane_unset GIT_PAGER && - test_might_fail git config --unset core.pager && + test_unconfig core.pager && rm -f PAGER_used || cleanup_fail && @@ -277,7 +297,7 @@ test_core_pager() { PAGER=wc && export PAGER && - git config core.pager 'wc >core.pager_used' && + test_config core.pager 'wc >core.pager_used' && $full_command && ${if_local_config}test -e core.pager_used " @@ -307,7 +327,7 @@ test_pager_subdir_helper() { PAGER=wc && stampname=\$(pwd)/core.pager_used && export PAGER stampname && - git config core.pager 'wc >\"\$stampname\"' && + test_config core.pager 'wc >\"\$stampname\"' && mkdir sub && ( cd sub && @@ -324,7 +344,7 @@ test_GIT_PAGER_overrides() { rm -f GIT_PAGER_used || cleanup_fail && - git config core.pager wc && + test_config core.pager wc && GIT_PAGER='wc >GIT_PAGER_used' && export GIT_PAGER && $full_command && @@ -402,21 +422,21 @@ test_core_pager_subdir expect_success test_must_fail \ 'git -p apply </dev/null' test_expect_success TTY 'command-specific pager' ' - unset PAGER GIT_PAGER; + sane_unset PAGER GIT_PAGER && echo "foo:initial" >expect && >actual && - git config --unset core.pager && - git config pager.log "sed s/^/foo:/ >actual" && + test_unconfig core.pager && + test_config pager.log "sed s/^/foo:/ >actual" && test_terminal git log --format=%s -1 && test_cmp expect actual ' test_expect_success TTY 'command-specific pager overrides core.pager' ' - unset PAGER GIT_PAGER; + sane_unset PAGER GIT_PAGER && echo "foo:initial" >expect && >actual && - git config core.pager "exit 1" - git config pager.log "sed s/^/foo:/ >actual" && + test_config core.pager "exit 1" + test_config pager.log "sed s/^/foo:/ >actual" && test_terminal git log --format=%s -1 && test_cmp expect actual ' @@ -425,9 +445,45 @@ test_expect_success TTY 'command-specific pager overridden by environment' ' GIT_PAGER="sed s/^/foo:/ >actual" && export GIT_PAGER && >actual && echo "foo:initial" >expect && - git config pager.log "exit 1" && + test_config pager.log "exit 1" && test_terminal git log --format=%s -1 && test_cmp expect actual ' +test_expect_success 'setup external command' ' + cat >git-external <<-\EOF && + #!/bin/sh + git "$@" + EOF + chmod +x git-external +' + +test_expect_success TTY 'command-specific pager works for external commands' ' + sane_unset PAGER GIT_PAGER && + echo "foo:initial" >expect && + >actual && + test_config pager.external "sed s/^/foo:/ >actual" && + test_terminal git --exec-path="`pwd`" external log --format=%s -1 && + test_cmp expect actual +' + +test_expect_success TTY 'sub-commands of externals use their own pager' ' + sane_unset PAGER GIT_PAGER && + echo "foo:initial" >expect && + >actual && + test_config pager.log "sed s/^/foo:/ >actual" && + test_terminal git --exec-path=. external log --format=%s -1 && + test_cmp expect actual +' + +test_expect_success TTY 'external command pagers override sub-commands' ' + sane_unset PAGER GIT_PAGER && + >expect && + >actual && + test_config pager.external false && + test_config pager.log "sed s/^/log:/ >actual" && + test_terminal git --exec-path=. external log --format=%s -1 && + test_cmp expect actual +' + test_done diff --git a/t/t7008-grep-binary.sh b/t/t7008-grep-binary.sh index e058d184d1..917a264eea 100755 --- a/t/t7008-grep-binary.sh +++ b/t/t7008-grep-binary.sh @@ -84,7 +84,7 @@ test_expect_success 'git grep -Fi Y<NUL>f a' " git grep -f f -Fi a " -test_expect_failure 'git grep -Fi Y<NUL>x a' " +test_expect_success 'git grep -Fi Y<NUL>x a' " printf 'YQx' | q_to_nul >f && test_must_fail git grep -f f -Fi a " @@ -94,7 +94,7 @@ test_expect_success 'git grep y<NUL>f a' " git grep -f f a " -test_expect_failure 'git grep y<NUL>x a' " +test_expect_success 'git grep y<NUL>x a' " printf 'yQx' | q_to_nul >f && test_must_fail git grep -f f a " diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh index f1cfc9ac95..b096dc88c2 100755 --- a/t/t7102-reset.sh +++ b/t/t7102-reset.sh @@ -429,6 +429,21 @@ test_expect_success '--mixed refreshes the index' ' test_i18ncmp expect output ' +test_expect_success 'resetting specific path that is unmerged' ' + git rm --cached file2 && + F1=$(git rev-parse HEAD:file1) && + F2=$(git rev-parse HEAD:file2) && + F3=$(git rev-parse HEAD:secondfile) && + { + echo "100644 $F1 1 file2" && + echo "100644 $F2 2 file2" && + echo "100644 $F3 3 file2" + } | git update-index --index-info && + git ls-files -u && + test_must_fail git reset HEAD file2 && + git diff-index --exit-code --cached HEAD +' + test_expect_success 'disambiguation (1)' ' git reset --hard && diff --git a/t/t7106-reset-sequence.sh b/t/t7106-reset-sequence.sh new file mode 100755 index 0000000000..4956caaf82 --- /dev/null +++ b/t/t7106-reset-sequence.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +test_description='Test interaction of reset --hard with sequencer + + + anotherpick: rewrites foo to d + + picked: rewrites foo to c + + unrelatedpick: rewrites unrelated to reallyunrelated + + base: rewrites foo to b + + initial: writes foo as a, unrelated as unrelated +' + +. ./test-lib.sh + +pristine_detach () { + git cherry-pick --reset && + git checkout -f "$1^0" && + git read-tree -u --reset HEAD && + git clean -d -f -f -q -x +} + +test_expect_success setup ' + echo unrelated >unrelated && + git add unrelated && + test_commit initial foo a && + test_commit base foo b && + test_commit unrelatedpick unrelated reallyunrelated && + test_commit picked foo c && + test_commit anotherpick foo d && + git config advice.detachedhead false + +' + +test_expect_success 'reset --hard cleans up sequencer state, providing one-level undo' ' + pristine_detach initial && + test_must_fail git cherry-pick base..anotherpick && + test_path_is_dir .git/sequencer && + git reset --hard && + test_path_is_missing .git/sequencer && + test_path_is_dir .git/sequencer-old && + git reset --hard && + test_path_is_missing .git/sequencer-old +' + +test_done diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index b2b26b72d0..695f7afdf3 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -47,8 +47,10 @@ test_expect_success 'setup - repository to add submodules to' ' ' # The 'submodule add' tests need some repository to add as a submodule. -# The trash directory is a good one as any. -submodurl=$TRASH_DIRECTORY +# The trash directory is a good one as any. We need to canonicalize +# the name, though, as some tests compare it to the absolute path git +# generates, which will expand symbolic links. +submodurl=$(pwd -P) listbranches() { git for-each-ref --format='%(refname)' 'refs/heads/*' @@ -75,7 +77,8 @@ test_expect_success 'submodule add' ' ( cd addtest && - git submodule add "$submodurl" submod && + git submodule add -q "$submodurl" submod >actual && + test ! -s actual && git submodule init ) && @@ -273,7 +276,8 @@ test_expect_success 'update should work when path is an empty dir' ' echo "$rev1" >expect && mkdir init && - git submodule update && + git submodule update -q >update.out && + test ! -s update.out && inspect init && test_cmp expect head-sha1 @@ -358,10 +362,10 @@ test_expect_success 'update --init' ' git submodule update init > update.out && cat update.out && test_i18ngrep "not initialized" update.out && - ! test -d init/.git && + test_must_fail git rev-parse --resolve-git-dir init/.git && git submodule update --init init && - test -d init/.git + git rev-parse --resolve-git-dir init/.git ' test_expect_success 'do not add files from a submodule' ' @@ -446,6 +450,16 @@ test_expect_success 'add should fail when path is used by an existing directory' ) ' +test_expect_success 'use superproject as upstream when path is relative and no url is set there' ' + ( + cd addtest && + git submodule add ../repo relative && + test "$(git config -f .gitmodules submodule.relative.url)" = ../repo && + git submodule sync relative && + test "$(git config submodule.relative.url)" = "$submodurl/repo" + ) +' + test_expect_success 'set up for relative path tests' ' mkdir reltest && ( diff --git a/t/t7403-submodule-sync.sh b/t/t7403-submodule-sync.sh index 95ffe349a7..3620215c1f 100755 --- a/t/t7403-submodule-sync.sh +++ b/t/t7403-submodule-sync.sh @@ -56,8 +56,9 @@ test_expect_success '"git submodule sync" should update submodule URLs' ' git pull --no-recurse-submodules && git submodule sync ) && - test -d "$(git config -f super-clone/submodule/.git/config \ - remote.origin.url)" && + test -d "$(cd super-clone/submodule && + git config remote.origin.url + )" && (cd super-clone/submodule && git checkout master && git pull diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh index c679f36a4d..33b292b8a8 100755 --- a/t/t7406-submodule-update.sh +++ b/t/t7406-submodule-update.sh @@ -30,6 +30,7 @@ test_expect_success 'setup a submodule tree' ' git clone super submodule && git clone super rebasing && git clone super merging && + git clone super none && (cd super && git submodule add ../submodule submodule && test_tick && @@ -58,6 +59,11 @@ test_expect_success 'setup a submodule tree' ' test_tick && git commit -m "rebasing" ) + (cd super && + git submodule add ../none none && + test_tick && + git commit -m "none" + ) ' test_expect_success 'submodule update detaching the HEAD ' ' @@ -298,6 +304,62 @@ test_expect_success 'submodule update ignores update=rebase config for new submo ) ' +test_expect_success 'submodule init picks up update=none' ' + (cd super && + git config -f .gitmodules submodule.none.update none && + git submodule init none && + test "none" = "$(git config submodule.none.update)" + ) +' + +test_expect_success 'submodule update - update=none in .git/config' ' + (cd super && + git config submodule.submodule.update none && + (cd submodule && + git checkout master && + compare_head + ) && + git diff --raw | grep " submodule" && + git submodule update && + git diff --raw | grep " submodule" && + (cd submodule && + compare_head + ) && + git config --unset submodule.submodule.update && + git submodule update submodule + ) +' + +test_expect_success 'submodule update - update=none in .git/config but --checkout given' ' + (cd super && + git config submodule.submodule.update none && + (cd submodule && + git checkout master && + compare_head + ) && + git diff --raw | grep " submodule" && + git submodule update --checkout && + test_must_fail git diff --raw \| grep " submodule" && + (cd submodule && + test_must_fail compare_head + ) && + git config --unset submodule.submodule.update + ) +' + +test_expect_success 'submodule update --init skips submodule with update=none' ' + (cd super && + git add .gitmodules && + git commit -m ".gitmodules" + ) && + git clone super cloned && + (cd cloned && + git submodule update --init && + test -e submodule/.git && + test_must_fail test -e none/.git + ) +' + test_expect_success 'submodule update continues after checkout error' ' (cd super && git reset --hard HEAD && @@ -408,6 +470,7 @@ test_expect_success 'submodule update exit immediately in case of merge conflict test_cmp expect actual ) ' + test_expect_success 'submodule update exit immediately after recursive rebase error' ' (cd super && git checkout master && @@ -442,4 +505,110 @@ test_expect_success 'submodule update exit immediately after recursive rebase er test_cmp expect actual ) ' + +test_expect_success 'add different submodules to the same path' ' + (cd super && + git submodule add ../submodule s1 && + test_must_fail git submodule add ../merging s1 + ) +' + +test_expect_success 'submodule add places git-dir in superprojects git-dir' ' + (cd super && + mkdir deeper && + git submodule add ../submodule deeper/submodule && + (cd deeper/submodule && + git log > ../../expected + ) && + (cd .git/modules/deeper/submodule && + git log > ../../../../actual + ) && + test_cmp actual expected + ) +' + +test_expect_success 'submodule update places git-dir in superprojects git-dir' ' + (cd super && + git commit -m "added submodule" + ) && + git clone super super2 && + (cd super2 && + git submodule init deeper/submodule && + git submodule update && + (cd deeper/submodule && + git log > ../../expected + ) && + (cd .git/modules/deeper/submodule && + git log > ../../../../actual + ) && + test_cmp actual expected + ) +' + +test_expect_success 'submodule add places git-dir in superprojects git-dir recursive' ' + (cd super2 && + (cd deeper/submodule && + git submodule add ../submodule subsubmodule && + (cd subsubmodule && + git log > ../../../expected + ) && + git commit -m "added subsubmodule" && + git push + ) && + (cd .git/modules/deeper/submodule/modules/subsubmodule && + git log > ../../../../../actual + ) && + git add deeper/submodule && + git commit -m "update submodule" && + git push && + test_cmp actual expected + ) +' + +test_expect_success 'submodule update places git-dir in superprojects git-dir recursive' ' + mkdir super_update_r && + (cd super_update_r && + git init --bare + ) && + mkdir subsuper_update_r && + (cd subsuper_update_r && + git init --bare + ) && + mkdir subsubsuper_update_r && + (cd subsubsuper_update_r && + git init --bare + ) && + git clone subsubsuper_update_r subsubsuper_update_r2 && + (cd subsubsuper_update_r2 && + test_commit "update_subsubsuper" file && + git push origin master + ) && + git clone subsuper_update_r subsuper_update_r2 && + (cd subsuper_update_r2 && + test_commit "update_subsuper" file && + git submodule add ../subsubsuper_update_r subsubmodule && + git commit -am "subsubmodule" && + git push origin master + ) && + git clone super_update_r super_update_r2 && + (cd super_update_r2 && + test_commit "update_super" file && + git submodule add ../subsuper_update_r submodule && + git commit -am "submodule" && + git push origin master + ) && + rm -rf super_update_r2 && + git clone super_update_r super_update_r2 && + (cd super_update_r2 && + git submodule update --init --recursive && + (cd submodule/subsubmodule && + git log > ../../expected + ) && + (cd .git/modules/submodule/modules/subsubmodule + git log > ../../../../../actual + ) + test_cmp actual expected + ) +' + test_done diff --git a/t/t7407-submodule-foreach.sh b/t/t7407-submodule-foreach.sh index be745fb23f..9b69fe2e14 100755 --- a/t/t7407-submodule-foreach.sh +++ b/t/t7407-submodule-foreach.sh @@ -118,19 +118,19 @@ test_expect_success 'use "submodule foreach" to checkout 2nd level submodule' ' git clone super clone2 && ( cd clone2 && - test ! -d sub1/.git && - test ! -d sub2/.git && - test ! -d sub3/.git && - test ! -d nested1/.git && + test_must_fail git rev-parse --resolve-git-dir sub1/.git && + test_must_fail git rev-parse --resolve-git-dir sub2/.git && + test_must_fail git rev-parse --resolve-git-dir sub3/.git && + test_must_fail git rev-parse --resolve-git-dir nested1/.git && git submodule update --init && - test -d sub1/.git && - test -d sub2/.git && - test -d sub3/.git && - test -d nested1/.git && - test ! -d nested1/nested2/.git && + git rev-parse --resolve-git-dir sub1/.git && + git rev-parse --resolve-git-dir sub2/.git && + git rev-parse --resolve-git-dir sub3/.git && + git rev-parse --resolve-git-dir nested1/.git && + test_must_fail git rev-parse --resolve-git-dir nested1/nested2/.git && git submodule foreach "git submodule update --init" && - test -d nested1/nested2/.git && - test ! -d nested1/nested2/nested3/.git + git rev-parse --resolve-git-dir nested1/nested1/nested2/.git + test_must_fail git rev-parse --resolve-git-dir nested1/nested2/nested3/.git ) ' @@ -138,8 +138,8 @@ test_expect_success 'use "foreach --recursive" to checkout all submodules' ' ( cd clone2 && git submodule foreach --recursive "git submodule update --init" && - test -d nested1/nested2/nested3/.git && - test -d nested1/nested2/nested3/submodule/.git + git rev-parse --resolve-git-dir nested1/nested2/nested3/.git && + git rev-parse --resolve-git-dir nested1/nested2/nested3/submodule/.git ) ' @@ -183,18 +183,18 @@ test_expect_success 'use "update --recursive" to checkout all submodules' ' git clone super clone3 && ( cd clone3 && - test ! -d sub1/.git && - test ! -d sub2/.git && - test ! -d sub3/.git && - test ! -d nested1/.git && + test_must_fail git rev-parse --resolve-git-dir sub1/.git && + test_must_fail git rev-parse --resolve-git-dir sub2/.git && + test_must_fail git rev-parse --resolve-git-dir sub3/.git && + test_must_fail git rev-parse --resolve-git-dir nested1/.git && git submodule update --init --recursive && - test -d sub1/.git && - test -d sub2/.git && - test -d sub3/.git && - test -d nested1/.git && - test -d nested1/nested2/.git && - test -d nested1/nested2/nested3/.git && - test -d nested1/nested2/nested3/submodule/.git + git rev-parse --resolve-git-dir sub1/.git && + git rev-parse --resolve-git-dir sub2/.git && + git rev-parse --resolve-git-dir sub3/.git && + git rev-parse --resolve-git-dir nested1/.git && + git rev-parse --resolve-git-dir nested1/nested2/.git && + git rev-parse --resolve-git-dir nested1/nested2/nested3/.git && + git rev-parse --resolve-git-dir nested1/nested2/nested3/submodule/.git ) ' @@ -247,14 +247,17 @@ test_expect_success 'ensure "status --cached --recursive" preserves the --cached test_expect_success 'use "git clone --recursive" to checkout all submodules' ' git clone --recursive super clone4 && - test -d clone4/.git && - test -d clone4/sub1/.git && - test -d clone4/sub2/.git && - test -d clone4/sub3/.git && - test -d clone4/nested1/.git && - test -d clone4/nested1/nested2/.git && - test -d clone4/nested1/nested2/nested3/.git && - test -d clone4/nested1/nested2/nested3/submodule/.git + ( + cd clone4 && + git rev-parse --resolve-git-dir .git && + git rev-parse --resolve-git-dir sub1/.git && + git rev-parse --resolve-git-dir sub2/.git && + git rev-parse --resolve-git-dir sub3/.git && + git rev-parse --resolve-git-dir nested1/.git && + git rev-parse --resolve-git-dir nested1/nested2/.git && + git rev-parse --resolve-git-dir nested1/nested2/nested3/.git && + git rev-parse --resolve-git-dir nested1/nested2/nested3/submodule/.git + ) ' test_expect_success 'test "update --recursive" with a flag with spaces' ' @@ -262,14 +265,14 @@ test_expect_success 'test "update --recursive" with a flag with spaces' ' git clone super clone5 && ( cd clone5 && - test ! -d nested1/.git && + test_must_fail git rev-parse --resolve-git-dir d nested1/.git && git submodule update --init --recursive --reference="$(dirname "$PWD")/common objects" && - test -d nested1/.git && - test -d nested1/nested2/.git && - test -d nested1/nested2/nested3/.git && - test -f nested1/.git/objects/info/alternates && - test -f nested1/nested2/.git/objects/info/alternates && - test -f nested1/nested2/nested3/.git/objects/info/alternates + git rev-parse --resolve-git-dir nested1/.git && + git rev-parse --resolve-git-dir nested1/nested2/.git && + git rev-parse --resolve-git-dir nested1/nested2/nested3/.git && + test -f .git/modules/nested1/objects/info/alternates && + test -f .git/modules/nested1/modules/nested2/objects/info/alternates && + test -f .git/modules/nested1/modules/nested2/modules/nested3/objects/info/alternates ) ' @@ -277,18 +280,18 @@ test_expect_success 'use "update --recursive nested1" to checkout all submodules git clone super clone6 && ( cd clone6 && - test ! -d sub1/.git && - test ! -d sub2/.git && - test ! -d sub3/.git && - test ! -d nested1/.git && + test_must_fail git rev-parse --resolve-git-dir sub1/.git && + test_must_fail git rev-parse --resolve-git-dir sub2/.git && + test_must_fail git rev-parse --resolve-git-dir sub3/.git && + test_must_fail git rev-parse --resolve-git-dir nested1/.git && git submodule update --init --recursive -- nested1 && - test ! -d sub1/.git && - test ! -d sub2/.git && - test ! -d sub3/.git && - test -d nested1/.git && - test -d nested1/nested2/.git && - test -d nested1/nested2/nested3/.git && - test -d nested1/nested2/nested3/submodule/.git + test_must_fail git rev-parse --resolve-git-dir sub1/.git && + test_must_fail git rev-parse --resolve-git-dir sub2/.git && + test_must_fail git rev-parse --resolve-git-dir sub3/.git && + git rev-parse --resolve-git-dir nested1/.git && + git rev-parse --resolve-git-dir nested1/nested2/.git && + git rev-parse --resolve-git-dir nested1/nested2/nested3/.git && + git rev-parse --resolve-git-dir nested1/nested2/nested3/submodule/.git ) ' diff --git a/t/t7408-submodule-reference.sh b/t/t7408-submodule-reference.sh index cc16d3f05d..ab37c368d0 100755 --- a/t/t7408-submodule-reference.sh +++ b/t/t7408-submodule-reference.sh @@ -43,7 +43,7 @@ git commit -m B-super-added' cd "$base_dir" test_expect_success 'after add: existence of info/alternates' \ -'test `wc -l <super/sub/.git/objects/info/alternates` = 1' +'test `wc -l <super/.git/modules/sub/objects/info/alternates` = 1' cd "$base_dir" @@ -66,7 +66,7 @@ test_expect_success 'update with reference' \ cd "$base_dir" test_expect_success 'after update: existence of info/alternates' \ -'test `wc -l <super-clone/sub/.git/objects/info/alternates` = 1' +'test `wc -l <super-clone/.git/modules/sub/objects/info/alternates` = 1' cd "$base_dir" diff --git a/t/t7602-merge-octopus-many.sh b/t/t7602-merge-octopus-many.sh index 0a46795ae7..61f36baa1f 100755 --- a/t/t7602-merge-octopus-many.sh +++ b/t/t7602-merge-octopus-many.sh @@ -53,7 +53,7 @@ cat >expected <<\EOF Trying simple merge with c2 Trying simple merge with c3 Trying simple merge with c4 -Merge made by octopus. +Merge made by the 'octopus' strategy. c2.c | 1 + c3.c | 1 + c4.c | 1 + @@ -72,7 +72,7 @@ test_expect_success 'merge output uses pretty names' ' cat >expected <<\EOF Already up-to-date with c4 Trying simple merge with c5 -Merge made by octopus. +Merge made by the 'octopus' strategy. c5.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 c5.c @@ -86,7 +86,7 @@ test_expect_success 'merge up-to-date output uses pretty names' ' cat >expected <<\EOF Fast-forwarding to: c1 Trying simple merge with c2 -Merge made by octopus. +Merge made by the 'octopus' strategy. c1.c | 1 + c2.c | 1 + 2 files changed, 2 insertions(+), 0 deletions(-) diff --git a/t/t7607-merge-overwrite.sh b/t/t7607-merge-overwrite.sh index 72a8731d5e..aa74184c31 100755 --- a/t/t7607-merge-overwrite.sh +++ b/t/t7607-merge-overwrite.sh @@ -107,6 +107,7 @@ error: The following untracked working tree files would be overwritten by merge: sub sub2 Please move or remove them before you can merge. +Aborting EOF test_expect_success 'will not overwrite untracked file in leading path' ' diff --git a/t/t7609-merge-co-error-msgs.sh b/t/t7609-merge-co-error-msgs.sh index c994836c53..0e4a682c64 100755 --- a/t/t7609-merge-co-error-msgs.sh +++ b/t/t7609-merge-co-error-msgs.sh @@ -32,6 +32,7 @@ error: The following untracked working tree files would be overwritten by merge: three two Please move or remove them before you can merge. +Aborting EOF test_expect_success 'untracked files overwritten by merge (fast and non-fast forward)' ' @@ -56,6 +57,7 @@ Please, commit your changes or stash them before you can merge. error: The following untracked working tree files would be overwritten by merge: five Please move or remove them before you can merge. +Aborting EOF test_expect_success 'untracked files or local changes ovewritten by merge' ' @@ -71,6 +73,7 @@ error: Your local changes to the following files would be overwritten by checkou rep/one rep/two Please, commit your changes or stash them before you can switch branches. +Aborting EOF test_expect_success 'cannot switch branches because of local changes' ' @@ -92,6 +95,7 @@ error: Your local changes to the following files would be overwritten by checkou rep/one rep/two Please, commit your changes or stash them before you can switch branches. +Aborting EOF test_expect_success 'not uptodate file porcelain checkout error' ' @@ -105,6 +109,7 @@ error: Updating the following directories would lose untracked files in it: rep rep2 +Aborting EOF test_expect_success 'not_uptodate_dir porcelain checkout error' ' diff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh index cbc08e3276..4aab2a75b8 100755 --- a/t/t7610-mergetool.sh +++ b/t/t7610-mergetool.sh @@ -16,6 +16,7 @@ Testing basic merge tool invocation' test_expect_success 'setup' ' git config rerere.enabled true && echo master >file1 && + echo master spaced >"spaced name" && echo master file11 >file11 && echo master file12 >file12 && echo master file13 >file13 && @@ -30,13 +31,14 @@ test_expect_success 'setup' ' git commit -m "Add foo" ) && git submodule add git://example.com/submod submod && - git add file1 file1[1-4] subdir/file3 .gitmodules submod && + git add file1 "spaced name" file1[1-4] subdir/file3 .gitmodules submod && git commit -m "add initial versions" && git checkout -b branch1 master && git submodule update -N && echo branch1 change >file1 && echo branch1 newfile >file2 && + echo branch1 spaced >"spaced name" && echo branch1 change file11 >file11 && echo branch1 change file13 >file13 && echo branch1 sub >subdir/file3 && @@ -47,7 +49,7 @@ test_expect_success 'setup' ' git commit -m "Add bar on branch1" && git checkout -b submod-branch1 ) && - git add file1 file11 file13 file2 subdir/file3 submod && + git add file1 "spaced name" file11 file13 file2 subdir/file3 submod && git rm file12 && git commit -m "branch1 changes" && @@ -55,6 +57,7 @@ test_expect_success 'setup' ' git submodule update -N && echo master updated >file1 && echo master new >file2 && + echo master updated spaced >"spaced name" && echo master updated file12 >file12 && echo master updated file14 >file14 && echo master new sub >subdir/file3 && @@ -65,7 +68,7 @@ test_expect_success 'setup' ' git commit -m "Add bar on master" && git checkout -b submod-master ) && - git add file1 file12 file14 file2 subdir/file3 submod && + git add file1 "spaced name" file12 file14 file2 subdir/file3 submod && git rm file11 && git commit -m "master updates" && @@ -78,8 +81,8 @@ test_expect_success 'custom mergetool' ' git checkout -b test1 branch1 && git submodule update -N && test_must_fail git merge master >/dev/null 2>&1 && - ( yes "" | git mergetool file1 >/dev/null 2>&1 ) && - ( yes "" | git mergetool file2 >/dev/null 2>&1 ) && + ( yes "" | git mergetool file1 file1 ) && + ( yes "" | git mergetool file2 "spaced name" >/dev/null 2>&1 ) && ( yes "" | git mergetool subdir/file3 >/dev/null 2>&1 ) && ( yes "d" | git mergetool file11 >/dev/null 2>&1 ) && ( yes "d" | git mergetool file12 >/dev/null 2>&1 ) && @@ -97,6 +100,7 @@ test_expect_success 'mergetool crlf' ' test_must_fail git merge master >/dev/null 2>&1 && ( yes "" | git mergetool file1 >/dev/null 2>&1 ) && ( yes "" | git mergetool file2 >/dev/null 2>&1 ) && + ( yes "" | git mergetool "spaced name" >/dev/null 2>&1 ) && ( yes "" | git mergetool subdir/file3 >/dev/null 2>&1 ) && ( yes "d" | git mergetool file11 >/dev/null 2>&1 ) && ( yes "d" | git mergetool file12 >/dev/null 2>&1 ) && @@ -126,7 +130,7 @@ test_expect_success 'mergetool on file in parent dir' ' ( cd subdir && ( yes "" | git mergetool ../file1 >/dev/null 2>&1 ) && - ( yes "" | git mergetool ../file2 >/dev/null 2>&1 ) && + ( yes "" | git mergetool ../file2 ../spaced\ name >/dev/null 2>&1 ) && ( yes "d" | git mergetool ../file11 >/dev/null 2>&1 ) && ( yes "d" | git mergetool ../file12 >/dev/null 2>&1 ) && ( yes "l" | git mergetool ../submod >/dev/null 2>&1 ) && @@ -180,6 +184,24 @@ test_expect_success 'mergetool skips resolved paths when rerere is active' ' git reset --hard ' +test_expect_success 'mergetool takes partial path' ' + git config rerere.enabled false && + git checkout -b test12 branch1 && + git submodule update -N && + test_must_fail git merge master && + + #shouldnt need these lines + #( yes "d" | git mergetool file11 >/dev/null 2>&1 ) && + #( yes "d" | git mergetool file12 >/dev/null 2>&1 ) && + #( yes "l" | git mergetool submod >/dev/null 2>&1 ) && + #( yes "" | git mergetool file1 file2 >/dev/null 2>&1 ) && + + ( yes "" | git mergetool subdir ) && + + test "$(cat subdir/file3)" = "master new sub" && + git reset --hard +' + test_expect_success 'deleted vs modified submodule' ' git checkout -b test6 branch1 && git submodule update -N && @@ -189,7 +211,7 @@ test_expect_success 'deleted vs modified submodule' ' git checkout -b test6.a test6 && test_must_fail git merge master && test -n "$(git ls-files -u)" && - ( yes "" | git mergetool file1 file2 subdir/file3 >/dev/null 2>&1 ) && + ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && ( yes "r" | git mergetool submod ) && rmdir submod && mv submod-movedaside submod && @@ -205,7 +227,7 @@ test_expect_success 'deleted vs modified submodule' ' git submodule update -N && test_must_fail git merge master && test -n "$(git ls-files -u)" && - ( yes "" | git mergetool file1 file2 subdir/file3 >/dev/null 2>&1 ) && + ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && ( yes "l" | git mergetool submod ) && test ! -e submod && @@ -218,7 +240,7 @@ test_expect_success 'deleted vs modified submodule' ' git submodule update -N && test_must_fail git merge test6 && test -n "$(git ls-files -u)" && - ( yes "" | git mergetool file1 file2 subdir/file3 >/dev/null 2>&1 ) && + ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && ( yes "r" | git mergetool submod ) && test ! -e submod && @@ -233,7 +255,7 @@ test_expect_success 'deleted vs modified submodule' ' git submodule update -N && test_must_fail git merge test6 && test -n "$(git ls-files -u)" && - ( yes "" | git mergetool file1 file2 subdir/file3 >/dev/null 2>&1 ) && + ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && ( yes "l" | git mergetool submod ) && test "$(cat submod/bar)" = "master submodule" && @@ -256,7 +278,7 @@ test_expect_success 'file vs modified submodule' ' git checkout -b test7.a branch1 && test_must_fail git merge master && test -n "$(git ls-files -u)" && - ( yes "" | git mergetool file1 file2 subdir/file3 >/dev/null 2>&1 ) && + ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && ( yes "r" | git mergetool submod ) && rmdir submod && mv submod-movedaside submod && @@ -271,7 +293,7 @@ test_expect_success 'file vs modified submodule' ' git checkout -b test7.b test7 && test_must_fail git merge master && test -n "$(git ls-files -u)" && - ( yes "" | git mergetool file1 file2 subdir/file3 >/dev/null 2>&1 ) && + ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && ( yes "l" | git mergetool submod ) && git submodule update -N && @@ -286,7 +308,7 @@ test_expect_success 'file vs modified submodule' ' git submodule update -N && test_must_fail git merge test7 && test -n "$(git ls-files -u)" && - ( yes "" | git mergetool file1 file2 subdir/file3 >/dev/null 2>&1 ) && + ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && ( yes "r" | git mergetool submod ) && test -d submod.orig && @@ -301,7 +323,7 @@ test_expect_success 'file vs modified submodule' ' git submodule update -N && test_must_fail git merge test7 && test -n "$(git ls-files -u)" && - ( yes "" | git mergetool file1 file2 subdir/file3 >/dev/null 2>&1 ) && + ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && ( yes "l" | git mergetool submod ) && test "$(cat submod/bar)" = "master submodule" && @@ -388,7 +410,7 @@ test_expect_success 'directory vs modified submodule' ' test "$(cat submod/file16)" = "not a submodule" && rm -rf submod.orig && - git reset --hard && + git reset --hard >/dev/null 2>&1 && test_must_fail git merge master && test -n "$(git ls-files -u)" && test ! -e submod.orig && @@ -400,7 +422,7 @@ test_expect_success 'directory vs modified submodule' ' ( cd submod && git clean -f && git reset --hard ) && git submodule update -N && test "$(cat submod/bar)" = "master submodule" && - git reset --hard && rm -rf submod-movedaside && + git reset --hard >/dev/null 2>&1 && rm -rf submod-movedaside && git checkout -b test11.c master && git submodule update -N && @@ -410,7 +432,7 @@ test_expect_success 'directory vs modified submodule' ' git submodule update -N && test "$(cat submod/bar)" = "master submodule" && - git reset --hard && + git reset --hard >/dev/null 2>&1 && git submodule update -N && test_must_fail git merge test11 && test -n "$(git ls-files -u)" && @@ -418,7 +440,7 @@ test_expect_success 'directory vs modified submodule' ' ( yes "r" | git mergetool submod ) && test "$(cat submod/file16)" = "not a submodule" && - git reset --hard master && + git reset --hard master >/dev/null 2>&1 && ( cd submod && git clean -f && git reset --hard ) && git submodule update -N ' diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh index 4048d106d4..395adfc8a9 100755 --- a/t/t7800-difftool.sh +++ b/t/t7800-difftool.sh @@ -10,9 +10,6 @@ Testing basic diff tool invocation . ./test-lib.sh -LF=' -' - remove_config_vars() { # Unset all config variables used by git-difftool diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh index a29ae45b39..81263b7851 100755 --- a/t/t7810-grep.sh +++ b/t/t7810-grep.sh @@ -509,6 +509,20 @@ test_expect_success 'grep -p -B5' ' test_cmp expected actual ' +cat >expected <<EOF +hello.c=int main(int argc, const char **argv) +hello.c-{ +hello.c- printf("Hello world.\n"); +hello.c: return 0; +hello.c- /* char ?? */ +hello.c-} +EOF + +test_expect_success 'grep -W' ' + git grep -W return >actual && + test_cmp expected actual +' + test_expect_success 'grep from a subdirectory to search wider area (1)' ' mkdir -p s && ( @@ -540,7 +554,6 @@ test_expect_success 'outside of git repository' ' mkdir -p non/git/sub && echo hello >non/git/file1 && echo world >non/git/sub/file2 && - echo ".*o*" >non/git/.gitignore && { echo file1:hello && echo sub/file2:world @@ -557,6 +570,23 @@ test_expect_success 'outside of git repository' ' test_must_fail git grep o && git grep --no-index o >../../actual.sub && test_cmp ../../expect.sub ../../actual.sub + ) && + + echo ".*o*" >non/git/.gitignore && + ( + GIT_CEILING_DIRECTORIES="$(pwd)/non/git" && + export GIT_CEILING_DIRECTORIES && + cd non/git && + test_must_fail git grep o && + git grep --no-index --exclude-standard o >../actual.full && + test_cmp ../expect.full ../actual.full && + + { + echo ".gitignore:.*o*" + cat ../expect.full + } >../expect.with.ignored && + git grep --no-index --no-exclude o >../actual.full && + test_cmp ../expect.with.ignored ../actual.full ) ' @@ -569,6 +599,10 @@ test_expect_success 'inside git repository but with --no-index' ' { echo file1:hello && echo sub/file2:world + } >is/expect.unignored && + { + echo ".gitignore:.*o*" && + cat is/expect.unignored } >is/expect.full && : >is/expect.empty && echo file2:world >is/expect.sub && @@ -577,12 +611,24 @@ test_expect_success 'inside git repository but with --no-index' ' git init && test_must_fail git grep o >../actual.full && test_cmp ../expect.empty ../actual.full && + + git grep --untracked o >../actual.unignored && + test_cmp ../expect.unignored ../actual.unignored && + git grep --no-index o >../actual.full && test_cmp ../expect.full ../actual.full && + + git grep --no-index --exclude-standard o >../actual.unignored && + test_cmp ../expect.unignored ../actual.unignored && + cd sub && test_must_fail git grep o >../../actual.sub && test_cmp ../../expect.empty ../../actual.sub && + git grep --no-index o >../../actual.sub && + test_cmp ../../expect.sub ../../actual.sub && + + git grep --untracked o >../../actual.sub && test_cmp ../../expect.sub ../../actual.sub ) ' diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index 579ddb7572..87b4acc9a6 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -1168,4 +1168,32 @@ test_expect_success $PREREQ '--force sends cover letter template anyway' ' test -n "$(ls msgtxt*)" ' +test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' ' + clean_fake_sendmail && + echo "alias sbd somebody@example.org" >.mailrc && + git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" && + git config sendemail.aliasfiletype mailrc && + git send-email \ + --from="Example <nobody@example.com>" \ + --to=sbd \ + --smtp-server="$(pwd)/fake.sendmail" \ + outdir/0001-*.patch \ + 2>errors >out && + grep "^!somebody@example\.org!$" commandline1 +' + +test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' ' + clean_fake_sendmail && + echo "alias sbd someone@example.org" >~/.mailrc && + git config --replace-all sendemail.aliasesfile "~/.mailrc" && + git config sendemail.aliasfiletype mailrc && + git send-email \ + --from="Example <nobody@example.com>" \ + --to=sbd \ + --smtp-server="$(pwd)/fake.sendmail" \ + outdir/0001-*.patch \ + 2>errors >out && + grep "^!someone@example\.org!$" commandline1 +' + test_done diff --git a/t/t9158-git-svn-mergeinfo.sh b/t/t9158-git-svn-mergeinfo.sh index 3ab43902b3..8c9539e1b4 100755 --- a/t/t9158-git-svn-mergeinfo.sh +++ b/t/t9158-git-svn-mergeinfo.sh @@ -38,4 +38,17 @@ test_expect_success 'verify svn:mergeinfo' ' test "$mergeinfo" = "/branches/foo:1-10" ' +test_expect_success 'change svn:mergeinfo multiline' ' + touch baz && + git add baz && + git commit -m "baz" && + git svn dcommit --mergeinfo="/branches/bar:1-10 /branches/other:3-5,8,10-11" +' + +test_expect_success 'verify svn:mergeinfo multiline' ' + mergeinfo=$(svn_cmd propget svn:mergeinfo "$svnrepo"/trunk) + test "$mergeinfo" = "/branches/bar:1-10 +/branches/other:3-5,8,10-11" +' + test_done diff --git a/t/t9159-git-svn-no-parent-mergeinfo.sh b/t/t9159-git-svn-no-parent-mergeinfo.sh index 85120b70db..69e4815781 100755 --- a/t/t9159-git-svn-no-parent-mergeinfo.sh +++ b/t/t9159-git-svn-no-parent-mergeinfo.sh @@ -2,6 +2,14 @@ test_description='git svn handling of root commits in merge ranges' . ./lib-git-svn.sh +svn_ver="$(svn --version --quiet)" +case $svn_ver in +0.* | 1.[0-4].*) + skip_all="skipping git-svn test - SVN too old ($svn_ver)" + test_done + ;; +esac + test_expect_success 'test handling of root commits in merge ranges' ' mkdir -p init/trunk init/branches init/tags && echo "r1" > init/trunk/file.txt && diff --git a/t/t9160-git-svn-preserve-empty-dirs.sh b/t/t9160-git-svn-preserve-empty-dirs.sh new file mode 100755 index 0000000000..b4a4434604 --- /dev/null +++ b/t/t9160-git-svn-preserve-empty-dirs.sh @@ -0,0 +1,153 @@ +#!/bin/sh +# +# Copyright (c) 2011 Ray Chen +# + +test_description='git svn test (option --preserve-empty-dirs) + +This test uses git to clone a Subversion repository that contains empty +directories, and checks that corresponding directories are created in the +local Git repository with placeholder files.' + +. ./lib-git-svn.sh + +say 'define NO_SVN_TESTS to skip git svn tests' +GIT_REPO=git-svn-repo + +test_expect_success 'initialize source svn repo containing empty dirs' ' + svn_cmd mkdir -m x "$svnrepo"/trunk && + svn_cmd co "$svnrepo"/trunk "$SVN_TREE" && + ( + cd "$SVN_TREE" && + mkdir -p 1 2 3/a 3/b 4 5 6 && + echo "First non-empty file" > 2/file1.txt && + echo "Second non-empty file" > 2/file2.txt && + echo "Third non-empty file" > 3/a/file1.txt && + echo "Fourth non-empty file" > 3/b/file1.txt && + svn_cmd add 1 2 3 4 5 6 && + svn_cmd commit -m "initial commit" && + + mkdir 4/a && + svn_cmd add 4/a && + svn_cmd commit -m "nested empty directory" && + mkdir 4/a/b && + svn_cmd add 4/a/b && + svn_cmd commit -m "deeply nested empty directory" && + mkdir 4/a/b/c && + svn_cmd add 4/a/b/c && + svn_cmd commit -m "really deeply nested empty directory" && + echo "Kill the placeholder file" > 4/a/b/c/foo && + svn_cmd add 4/a/b/c/foo && + svn_cmd commit -m "Regular file to remove placeholder" && + + svn_cmd del 2/file2.txt && + svn_cmd del 3/b && + svn_cmd commit -m "delete non-last entry in directory" && + + svn_cmd del 2/file1.txt && + svn_cmd del 3/a && + svn_cmd commit -m "delete last entry in directory" && + + echo "Conflict file" > 5/.placeholder && + mkdir 6/.placeholder && + svn_cmd add 5/.placeholder 6/.placeholder && + svn_cmd commit -m "Placeholder Namespace conflict" + ) && + rm -rf "$SVN_TREE" +' + +test_expect_success 'clone svn repo with --preserve-empty-dirs' ' + git svn clone "$svnrepo"/trunk --preserve-empty-dirs "$GIT_REPO" +' + +# "$GIT_REPO"/1 should only contain the placeholder file. +test_expect_success 'directory empty from inception' ' + test -f "$GIT_REPO"/1/.gitignore && + test $(find "$GIT_REPO"/1 -type f | wc -l) = "1" +' + +# "$GIT_REPO"/2 and "$GIT_REPO"/3 should only contain the placeholder file. +test_expect_success 'directory empty from subsequent svn commit' ' + test -f "$GIT_REPO"/2/.gitignore && + test $(find "$GIT_REPO"/2 -type f | wc -l) = "1" && + test -f "$GIT_REPO"/3/.gitignore && + test $(find "$GIT_REPO"/3 -type f | wc -l) = "1" +' + +# No placeholder files should exist in "$GIT_REPO"/4, even though one was +# generated for every sub-directory at some point in the repo's history. +test_expect_success 'add entry to previously empty directory' ' + test $(find "$GIT_REPO"/4 -type f | wc -l) = "1" && + test -f "$GIT_REPO"/4/a/b/c/foo +' + +# The HEAD~2 commit should not have introduced .gitignore placeholder files. +test_expect_success 'remove non-last entry from directory' ' + ( + cd "$GIT_REPO" && + git checkout HEAD~2 + ) && + test_must_fail test -f "$GIT_REPO"/2/.gitignore && + test_must_fail test -f "$GIT_REPO"/3/.gitignore +' + +# After re-cloning the repository with --placeholder-file specified, there +# should be 5 files named ".placeholder" in the local Git repo. +test_expect_success 'clone svn repo with --placeholder-file specified' ' + rm -rf "$GIT_REPO" && + git svn clone "$svnrepo"/trunk --preserve-empty-dirs \ + --placeholder-file=.placeholder "$GIT_REPO" && + find "$GIT_REPO" -type f -name ".placeholder" && + test $(find "$GIT_REPO" -type f -name ".placeholder" | wc -l) = "5" +' + +# "$GIT_REPO"/5/.placeholder should be a file, and non-empty. +test_expect_success 'placeholder namespace conflict with file' ' + test -s "$GIT_REPO"/5/.placeholder +' + +# "$GIT_REPO"/6/.placeholder should be a directory, and the "$GIT_REPO"/6 tree +# should only contain one file: the placeholder. +test_expect_success 'placeholder namespace conflict with directory' ' + test -d "$GIT_REPO"/6/.placeholder && + test -f "$GIT_REPO"/6/.placeholder/.placeholder && + test $(find "$GIT_REPO"/6 -type f | wc -l) = "1" +' + +# Prepare a second set of svn commits to test persistence during rebase. +test_expect_success 'second set of svn commits and rebase' ' + svn_cmd co "$svnrepo"/trunk "$SVN_TREE" && + ( + cd "$SVN_TREE" && + mkdir -p 7 && + echo "This should remove placeholder" > 1/file1.txt && + echo "This should not remove placeholder" > 5/file1.txt && + svn_cmd add 7 1/file1.txt 5/file1.txt && + svn_cmd commit -m "subsequent svn commit for persistence tests" + ) && + rm -rf "$SVN_TREE" && + ( + cd "$GIT_REPO" && + git svn rebase + ) +' + +# Check that --preserve-empty-dirs and --placeholder-file flag state +# stays persistent over multiple invocations. +test_expect_success 'flag persistence during subsqeuent rebase' ' + test -f "$GIT_REPO"/7/.placeholder && + test $(find "$GIT_REPO"/7 -type f | wc -l) = "1" +' + +# Check that placeholder files are properly removed when unnecessary, +# even across multiple invocations. +test_expect_success 'placeholder list persistence during subsqeuent rebase' ' + test -f "$GIT_REPO"/1/file1.txt && + test $(find "$GIT_REPO"/1 -type f | wc -l) = "1" && + + test -f "$GIT_REPO"/5/file1.txt && + test -f "$GIT_REPO"/5/.placeholder && + test $(find "$GIT_REPO"/5 -type f | wc -l) = "2" +' + +test_done diff --git a/t/t9161-git-svn-mergeinfo-push.sh b/t/t9161-git-svn-mergeinfo-push.sh new file mode 100755 index 0000000000..6ef0c0bde3 --- /dev/null +++ b/t/t9161-git-svn-mergeinfo-push.sh @@ -0,0 +1,104 @@ +#!/bin/sh +# +# Portions copyright (c) 2007, 2009 Sam Vilain +# Portions copyright (c) 2011 Bryan Jacobs +# + +test_description='git-svn svn mergeinfo propagation' + +. ./lib-git-svn.sh + +test_expect_success 'load svn dump' " + svnadmin load -q '$rawsvnrepo' \ + < '$TEST_DIRECTORY/t9161/branches.dump' && + git svn init --minimize-url -R svnmerge \ + -T trunk -b branches '$svnrepo' && + git svn fetch --all + " + +test_expect_success 'propagate merge information' ' + git config svn.pushmergeinfo yes && + git checkout svnb1 && + git merge --no-ff svnb2 && + git svn dcommit + ' + +test_expect_success 'check svn:mergeinfo' ' + mergeinfo=$(svn_cmd propget svn:mergeinfo "$svnrepo"/branches/svnb1) + test "$mergeinfo" = "/branches/svnb2:3,8" + ' + +test_expect_success 'merge another branch' ' + git merge --no-ff svnb3 && + git svn dcommit + ' + +test_expect_success 'check primary parent mergeinfo respected' ' + mergeinfo=$(svn_cmd propget svn:mergeinfo "$svnrepo"/branches/svnb1) + test "$mergeinfo" = "/branches/svnb2:3,8 +/branches/svnb3:4,9" + ' + +test_expect_success 'merge existing merge' ' + git merge --no-ff svnb4 && + git svn dcommit + ' + +test_expect_success "check both parents' mergeinfo respected" ' + mergeinfo=$(svn_cmd propget svn:mergeinfo "$svnrepo"/branches/svnb1) + test "$mergeinfo" = "/branches/svnb2:3,8 +/branches/svnb3:4,9 +/branches/svnb4:5-6,10-12 +/branches/svnb5:6,11" + ' + +test_expect_success 'make further commits to branch' ' + git checkout svnb2 && + touch newb2file && + git add newb2file && + git commit -m "later b2 commit" && + touch newb2file-2 && + git add newb2file-2 && + git commit -m "later b2 commit 2" && + git svn dcommit + ' + +test_expect_success 'second forward merge' ' + git checkout svnb1 && + git merge --no-ff svnb2 && + git svn dcommit + ' + +test_expect_success 'check new mergeinfo added' ' + mergeinfo=$(svn_cmd propget svn:mergeinfo "$svnrepo"/branches/svnb1) + test "$mergeinfo" = "/branches/svnb2:3,8,16-17 +/branches/svnb3:4,9 +/branches/svnb4:5-6,10-12 +/branches/svnb5:6,11" + ' + +test_expect_success 'reintegration merge' ' + git checkout svnb4 && + git merge --no-ff svnb1 && + git svn dcommit + ' + +test_expect_success 'check reintegration mergeinfo' ' + mergeinfo=$(svn_cmd propget svn:mergeinfo "$svnrepo"/branches/svnb4) + test "$mergeinfo" = "/branches/svnb1:2-4,7-9,13-18 +/branches/svnb2:3,8,16-17 +/branches/svnb3:4,9 +/branches/svnb4:5-6,10-12 +/branches/svnb5:6,11" + ' + +test_expect_success 'dcommit a merge at the top of a stack' ' + git checkout svnb1 && + touch anotherfile && + git add anotherfile && + git commit -m "a commit" && + git merge svnb4 && + git svn dcommit + ' + +test_done diff --git a/t/t9161/branches.dump b/t/t9161/branches.dump new file mode 100644 index 0000000000..e61c3e7236 --- /dev/null +++ b/t/t9161/branches.dump @@ -0,0 +1,374 @@ +SVN-fs-dump-format-version: 2 + +UUID: 1ef08553-f2d1-45df-b38c-19af6b7c926d + +Revision-number: 0 +Prop-content-length: 56 +Content-length: 56 + +K 8 +svn:date +V 27 +2011-09-02T16:08:02.941384Z +PROPS-END + +Revision-number: 1 +Prop-content-length: 114 +Content-length: 114 + +K 7 +svn:log +V 12 +Base commit + +K 10 +svn:author +V 7 +bjacobs +K 8 +svn:date +V 27 +2011-09-02T16:08:27.205062Z +PROPS-END + +Node-path: branches +Node-kind: dir +Node-action: add +Prop-content-length: 10 +Content-length: 10 + +PROPS-END + + +Node-path: trunk +Node-kind: dir +Node-action: add +Prop-content-length: 10 +Content-length: 10 + +PROPS-END + + +Revision-number: 2 +Prop-content-length: 121 +Content-length: 121 + +K 7 +svn:log +V 19 +Create branch svnb1 +K 10 +svn:author +V 7 +bjacobs +K 8 +svn:date +V 27 +2011-09-02T16:09:43.628137Z +PROPS-END + +Node-path: branches/svnb1 +Node-kind: dir +Node-action: add +Node-copyfrom-rev: 1 +Node-copyfrom-path: trunk + + +Revision-number: 3 +Prop-content-length: 121 +Content-length: 121 + +K 7 +svn:log +V 19 +Create branch svnb2 +K 10 +svn:author +V 7 +bjacobs +K 8 +svn:date +V 27 +2011-09-02T16:09:46.339930Z +PROPS-END + +Node-path: branches/svnb2 +Node-kind: dir +Node-action: add +Node-copyfrom-rev: 1 +Node-copyfrom-path: trunk + + +Revision-number: 4 +Prop-content-length: 121 +Content-length: 121 + +K 7 +svn:log +V 19 +Create branch svnb3 +K 10 +svn:author +V 7 +bjacobs +K 8 +svn:date +V 27 +2011-09-02T16:09:49.394515Z +PROPS-END + +Node-path: branches/svnb3 +Node-kind: dir +Node-action: add +Node-copyfrom-rev: 1 +Node-copyfrom-path: trunk + + +Revision-number: 5 +Prop-content-length: 121 +Content-length: 121 + +K 7 +svn:log +V 19 +Create branch svnb4 +K 10 +svn:author +V 7 +bjacobs +K 8 +svn:date +V 27 +2011-09-02T16:09:54.114607Z +PROPS-END + +Node-path: branches/svnb4 +Node-kind: dir +Node-action: add +Node-copyfrom-rev: 1 +Node-copyfrom-path: trunk + + +Revision-number: 6 +Prop-content-length: 121 +Content-length: 121 + +K 7 +svn:log +V 19 +Create branch svnb5 +K 10 +svn:author +V 7 +bjacobs +K 8 +svn:date +V 27 +2011-09-02T16:09:58.602623Z +PROPS-END + +Node-path: branches/svnb5 +Node-kind: dir +Node-action: add +Node-copyfrom-rev: 1 +Node-copyfrom-path: trunk + + +Revision-number: 7 +Prop-content-length: 110 +Content-length: 110 + +K 7 +svn:log +V 9 +b1 commit +K 10 +svn:author +V 7 +bjacobs +K 8 +svn:date +V 27 +2011-09-02T16:10:20.292369Z +PROPS-END + +Node-path: branches/svnb1/b1file +Node-kind: file +Node-action: add +Prop-content-length: 10 +Text-content-length: 0 +Text-content-md5: d41d8cd98f00b204e9800998ecf8427e +Text-content-sha1: da39a3ee5e6b4b0d3255bfef95601890afd80709 +Content-length: 10 + +PROPS-END + + +Revision-number: 8 +Prop-content-length: 110 +Content-length: 110 + +K 7 +svn:log +V 9 +b2 commit +K 10 +svn:author +V 7 +bjacobs +K 8 +svn:date +V 27 +2011-09-02T16:10:38.429199Z +PROPS-END + +Node-path: branches/svnb2/b2file +Node-kind: file +Node-action: add +Prop-content-length: 10 +Text-content-length: 0 +Text-content-md5: d41d8cd98f00b204e9800998ecf8427e +Text-content-sha1: da39a3ee5e6b4b0d3255bfef95601890afd80709 +Content-length: 10 + +PROPS-END + + +Revision-number: 9 +Prop-content-length: 110 +Content-length: 110 + +K 7 +svn:log +V 9 +b3 commit +K 10 +svn:author +V 7 +bjacobs +K 8 +svn:date +V 27 +2011-09-02T16:10:52.843023Z +PROPS-END + +Node-path: branches/svnb3/b3file +Node-kind: file +Node-action: add +Prop-content-length: 10 +Text-content-length: 0 +Text-content-md5: d41d8cd98f00b204e9800998ecf8427e +Text-content-sha1: da39a3ee5e6b4b0d3255bfef95601890afd80709 +Content-length: 10 + +PROPS-END + + +Revision-number: 10 +Prop-content-length: 110 +Content-length: 110 + +K 7 +svn:log +V 9 +b4 commit +K 10 +svn:author +V 7 +bjacobs +K 8 +svn:date +V 27 +2011-09-02T16:11:17.489870Z +PROPS-END + +Node-path: branches/svnb4/b4file +Node-kind: file +Node-action: add +Prop-content-length: 10 +Text-content-length: 0 +Text-content-md5: d41d8cd98f00b204e9800998ecf8427e +Text-content-sha1: da39a3ee5e6b4b0d3255bfef95601890afd80709 +Content-length: 10 + +PROPS-END + + +Revision-number: 11 +Prop-content-length: 110 +Content-length: 110 + +K 7 +svn:log +V 9 +b5 commit +K 10 +svn:author +V 7 +bjacobs +K 8 +svn:date +V 27 +2011-09-02T16:11:32.277404Z +PROPS-END + +Node-path: branches/svnb5/b5file +Node-kind: file +Node-action: add +Prop-content-length: 10 +Text-content-length: 0 +Text-content-md5: d41d8cd98f00b204e9800998ecf8427e +Text-content-sha1: da39a3ee5e6b4b0d3255bfef95601890afd80709 +Content-length: 10 + +PROPS-END + + +Revision-number: 12 +Prop-content-length: 192 +Content-length: 192 + +K 7 +svn:log +V 90 +Merge remote-tracking branch 'svnb5' into HEAD + +* svnb5: + b5 commit + Create branch svnb5 +K 10 +svn:author +V 7 +bjacobs +K 8 +svn:date +V 27 +2011-09-02T16:11:54.274722Z +PROPS-END + +Node-path: branches/svnb4 +Node-kind: dir +Node-action: change +Prop-content-length: 56 +Content-length: 56 + +K 13 +svn:mergeinfo +V 21 +/branches/svnb5:6,11 + +PROPS-END + + +Node-path: branches/svnb4/b5file +Node-kind: file +Node-action: add +Prop-content-length: 10 +Text-content-length: 0 +Text-content-md5: d41d8cd98f00b204e9800998ecf8427e +Text-content-sha1: da39a3ee5e6b4b0d3255bfef95601890afd80709 +Content-length: 10 + +PROPS-END + + diff --git a/t/t9162-git-svn-dcommit-interactive.sh b/t/t9162-git-svn-dcommit-interactive.sh new file mode 100644 index 0000000000..e38d9fa37b --- /dev/null +++ b/t/t9162-git-svn-dcommit-interactive.sh @@ -0,0 +1,64 @@ +#!/bin/sh +# +# Copyright (c) 2011 Frédéric Heitzmann + +test_description='git svn dcommit --interactive series' +. ./lib-git-svn.sh + +test_expect_success 'initialize repo' ' + svn_cmd mkdir -m"mkdir test-interactive" "$svnrepo/test-interactive" && + git svn clone "$svnrepo/test-interactive" test-interactive && + cd test-interactive && + touch foo && git add foo && git commit -m"foo: first commit" && + git svn dcommit + ' + +test_expect_success 'answers: y [\n] yes' ' + ( + echo "change #1" >> foo && git commit -a -m"change #1" && + echo "change #2" >> foo && git commit -a -m"change #2" && + echo "change #3" >> foo && git commit -a -m"change #3" && + ( echo "y + +y" | GIT_SVN_NOTTY=1 git svn dcommit --interactive ) && + test $(git rev-parse HEAD) = $(git rev-parse remotes/git-svn) + ) + ' + +test_expect_success 'answers: yes yes no' ' + ( + echo "change #1" >> foo && git commit -a -m"change #1" && + echo "change #2" >> foo && git commit -a -m"change #2" && + echo "change #3" >> foo && git commit -a -m"change #3" && + ( echo "yes +yes +no" | GIT_SVN_NOTTY=1 git svn dcommit --interactive ) && + test $(git rev-parse HEAD^^^) = $(git rev-parse remotes/git-svn) && + git reset --hard remotes/git-svn + ) + ' + +test_expect_success 'answers: yes quit' ' + ( + echo "change #1" >> foo && git commit -a -m"change #1" && + echo "change #2" >> foo && git commit -a -m"change #2" && + echo "change #3" >> foo && git commit -a -m"change #3" && + ( echo "yes +quit" | GIT_SVN_NOTTY=1 git svn dcommit --interactive ) && + test $(git rev-parse HEAD^^^) = $(git rev-parse remotes/git-svn) && + git reset --hard remotes/git-svn + ) + ' + +test_expect_success 'answers: all' ' + ( + echo "change #1" >> foo && git commit -a -m"change #1" && + echo "change #2" >> foo && git commit -a -m"change #2" && + echo "change #3" >> foo && git commit -a -m"change #3" && + ( echo "all" | GIT_SVN_NOTTY=1 git svn dcommit --interactive ) && + test $(git rev-parse HEAD) = $(git rev-parse remotes/git-svn) && + git reset --hard remotes/git-svn + ) + ' + +test_done diff --git a/t/t9200-git-cvsexportcommit.sh b/t/t9200-git-cvsexportcommit.sh index e5da65b99f..41db05cb4a 100755 --- a/t/t9200-git-cvsexportcommit.sh +++ b/t/t9200-git-cvsexportcommit.sh @@ -50,8 +50,8 @@ test_expect_success \ 'mkdir A B C D E F && echo hello1 >A/newfile1.txt && echo hello2 >B/newfile2.txt && - cp "$TEST_DIRECTORY"/test9200a.png C/newfile3.png && - cp "$TEST_DIRECTORY"/test9200a.png D/newfile4.png && + cp "$TEST_DIRECTORY"/test-binary-1.png C/newfile3.png && + cp "$TEST_DIRECTORY"/test-binary-1.png D/newfile4.png && git add A/newfile1.txt && git add B/newfile2.txt && git add C/newfile3.png && @@ -76,8 +76,8 @@ test_expect_success \ rm -f B/newfile2.txt && rm -f C/newfile3.png && echo Hello5 >E/newfile5.txt && - cp "$TEST_DIRECTORY"/test9200b.png D/newfile4.png && - cp "$TEST_DIRECTORY"/test9200a.png F/newfile6.png && + cp "$TEST_DIRECTORY"/test-binary-2.png D/newfile4.png && + cp "$TEST_DIRECTORY"/test-binary-1.png F/newfile6.png && git add E/newfile5.txt && git add F/newfile6.png && git commit -a -m "Test: Remove, add and update" && @@ -165,7 +165,7 @@ test_expect_success \ 'mkdir "G g" && echo ok then >"G g/with spaces.txt" && git add "G g/with spaces.txt" && \ - cp "$TEST_DIRECTORY"/test9200a.png "G g/with spaces.png" && \ + cp "$TEST_DIRECTORY"/test-binary-1.png "G g/with spaces.png" && \ git add "G g/with spaces.png" && git commit -a -m "With spaces" && id=$(git rev-list --max-count=1 HEAD) && @@ -177,7 +177,7 @@ test_expect_success \ test_expect_success \ 'Update file with spaces in file name' \ 'echo Ok then >>"G g/with spaces.txt" && - cat "$TEST_DIRECTORY"/test9200a.png >>"G g/with spaces.png" && \ + cat "$TEST_DIRECTORY"/test-binary-1.png >>"G g/with spaces.png" && \ git add "G g/with spaces.png" && git commit -a -m "Update with spaces" && id=$(git rev-list --max-count=1 HEAD) && @@ -202,7 +202,7 @@ test_expect_success \ 'mkdir -p Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö && echo Foo >Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö/gårdetsågårdet.txt && git add Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö/gårdetsågårdet.txt && - cp "$TEST_DIRECTORY"/test9200a.png Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö/gårdetsågårdet.png && + cp "$TEST_DIRECTORY"/test-binary-1.png Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö/gårdetsågårdet.png && git add Å/goo/a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y/z/å/ä/ö/gårdetsågårdet.png && git commit -a -m "Går det så går det" && \ id=$(git rev-list --max-count=1 HEAD) && diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh index 2a53640c5b..bd32b91d8f 100755 --- a/t/t9300-fast-import.sh +++ b/t/t9300-fast-import.sh @@ -94,6 +94,12 @@ data <<EOF An annotated tag without a tagger EOF +tag series-A-blob +from :3 +data <<EOF +An annotated tag that annotates a blob. +EOF + INPUT_END test_expect_success \ 'A: create pack from stdin' \ @@ -152,6 +158,18 @@ test_expect_success 'A: verify tag/series-A' ' ' cat >expect <<EOF +object $(git rev-parse refs/heads/master:file3) +type blob +tag series-A-blob + +An annotated tag that annotates a blob. +EOF +test_expect_success 'A: verify tag/series-A-blob' ' + git cat-file tag tags/series-A-blob >actual && + test_cmp expect actual +' + +cat >expect <<EOF :2 `git rev-parse --verify master:file2` :3 `git rev-parse --verify master:file3` :4 `git rev-parse --verify master:file4` @@ -170,6 +188,55 @@ test_expect_success \ test_cmp expect marks.new' test_tick +new_blob=$(echo testing | git hash-object --stdin) +cat >input <<INPUT_END +tag series-A-blob-2 +from $(git rev-parse refs/heads/master:file3) +data <<EOF +Tag blob by sha1. +EOF + +blob +mark :6 +data <<EOF +testing +EOF + +commit refs/heads/new_blob +committer <> 0 +0000 +data 0 +M 644 :6 new_blob +#pretend we got sha1 from fast-import +ls "new_blob" + +tag series-A-blob-3 +from $new_blob +data <<EOF +Tag new_blob. +EOF +INPUT_END + +cat >expect <<EOF +object $(git rev-parse refs/heads/master:file3) +type blob +tag series-A-blob-2 + +Tag blob by sha1. +object $new_blob +type blob +tag series-A-blob-3 + +Tag new_blob. +EOF + +test_expect_success \ + 'A: tag blob by sha1' \ + 'git fast-import <input && + git cat-file tag tags/series-A-blob-2 >actual && + git cat-file tag tags/series-A-blob-3 >>actual && + test_cmp expect actual' + +test_tick cat >input <<INPUT_END commit refs/heads/verify--import-marks committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE @@ -324,6 +391,105 @@ test_expect_success \ test `git rev-parse master` = `git rev-parse TEMP_TAG^`' rm -f .git/TEMP_TAG +git gc 2>/dev/null >/dev/null +git prune 2>/dev/null >/dev/null + +cat >input <<INPUT_END +commit refs/heads/empty-committer-1 +committer <> $GIT_COMMITTER_DATE +data <<COMMIT +empty commit +COMMIT +INPUT_END +test_expect_success 'B: accept empty committer' ' + git fast-import <input && + out=$(git fsck) && + echo "$out" && + test -z "$out" +' +git update-ref -d refs/heads/empty-committer-1 || true + +git gc 2>/dev/null >/dev/null +git prune 2>/dev/null >/dev/null + +cat >input <<INPUT_END +commit refs/heads/empty-committer-2 +committer <a@b.com> $GIT_COMMITTER_DATE +data <<COMMIT +empty commit +COMMIT +INPUT_END +test_expect_success 'B: accept and fixup committer with no name' ' + git fast-import <input && + out=$(git fsck) && + echo "$out" && + test -z "$out" +' +git update-ref -d refs/heads/empty-committer-2 || true + +git gc 2>/dev/null >/dev/null +git prune 2>/dev/null >/dev/null + +cat >input <<INPUT_END +commit refs/heads/invalid-committer +committer Name email> $GIT_COMMITTER_DATE +data <<COMMIT +empty commit +COMMIT +INPUT_END +test_expect_success 'B: fail on invalid committer (1)' ' + test_must_fail git fast-import <input +' +git update-ref -d refs/heads/invalid-committer || true + +cat >input <<INPUT_END +commit refs/heads/invalid-committer +committer Name <e<mail> $GIT_COMMITTER_DATE +data <<COMMIT +empty commit +COMMIT +INPUT_END +test_expect_success 'B: fail on invalid committer (2)' ' + test_must_fail git fast-import <input +' +git update-ref -d refs/heads/invalid-committer || true + +cat >input <<INPUT_END +commit refs/heads/invalid-committer +committer Name <email>> $GIT_COMMITTER_DATE +data <<COMMIT +empty commit +COMMIT +INPUT_END +test_expect_success 'B: fail on invalid committer (3)' ' + test_must_fail git fast-import <input +' +git update-ref -d refs/heads/invalid-committer || true + +cat >input <<INPUT_END +commit refs/heads/invalid-committer +committer Name <email $GIT_COMMITTER_DATE +data <<COMMIT +empty commit +COMMIT +INPUT_END +test_expect_success 'B: fail on invalid committer (4)' ' + test_must_fail git fast-import <input +' +git update-ref -d refs/heads/invalid-committer || true + +cat >input <<INPUT_END +commit refs/heads/invalid-committer +committer Name<email> $GIT_COMMITTER_DATE +data <<COMMIT +empty commit +COMMIT +INPUT_END +test_expect_success 'B: fail on invalid committer (5)' ' + test_must_fail git fast-import <input +' +git update-ref -d refs/heads/invalid-committer || true + ### ### series C ### @@ -654,6 +820,18 @@ test_expect_success \ 'test 1 = `git rev-list J | wc -l` && test 0 = `git ls-tree J | wc -l`' +cat >input <<INPUT_END +reset refs/heads/J2 + +tag wrong_tag +from refs/heads/J2 +data <<EOF +Tag branch that was reset. +EOF +INPUT_END +test_expect_success \ + 'J: tag must fail on empty branch' \ + 'test_must_fail git fast-import <input' ### ### series K ### @@ -734,6 +912,47 @@ test_expect_success \ git diff-tree --abbrev --raw L^ L >output && test_cmp expect output' +cat >input <<INPUT_END +blob +mark :1 +data <<EOF +the data +EOF + +commit refs/heads/L2 +committer C O Mitter <committer@example.com> 1112912473 -0700 +data <<COMMIT +init L2 +COMMIT +M 644 :1 a/b/c +M 644 :1 a/b/d +M 644 :1 a/e/f + +commit refs/heads/L2 +committer C O Mitter <committer@example.com> 1112912473 -0700 +data <<COMMIT +update L2 +COMMIT +C a g +C a/e g/b +M 644 :1 g/b/h +INPUT_END + +cat <<EOF >expect +g/b/f +g/b/h +EOF + +test_expect_success \ + 'L: nested tree copy does not corrupt deltas' \ + 'git fast-import <input && + git ls-tree L2 g/b/ >tmp && + cat tmp | cut -f 2 >actual && + test_cmp expect actual && + git fsck `git rev-parse L2`' + +git update-ref -d refs/heads/L2 + ### ### series M ### @@ -1768,6 +1987,23 @@ test_expect_success \ 'Q: verify second note for second commit' \ 'git cat-file blob refs/notes/foobar:$commit2 >actual && test_cmp expect actual' +cat >input <<EOF +reset refs/heads/Q0 + +commit refs/heads/note-Q0 +committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE +data <<COMMIT +Note for an empty branch. +COMMIT + +N inline refs/heads/Q0 +data <<NOTE +some note +NOTE +EOF +test_expect_success \ + 'Q: deny note on empty branch' \ + 'test_must_fail git fast-import <input' ### ### series R (feature and option) ### @@ -1882,6 +2118,53 @@ test_expect_success 'R: --import-marks-if-exists' ' test_cmp expect io.marks ' +test_expect_success 'R: feature import-marks-if-exists' ' + rm -f io.marks && + >expect && + + git fast-import --export-marks=io.marks <<-\EOF && + feature import-marks-if-exists=not_io.marks + EOF + test_cmp expect io.marks && + + blob=$(echo hi | git hash-object --stdin) && + + echo ":1 $blob" >io.marks && + echo ":1 $blob" >expect && + echo ":2 $blob" >>expect && + + git fast-import --export-marks=io.marks <<-\EOF && + feature import-marks-if-exists=io.marks + blob + mark :2 + data 3 + hi + + EOF + test_cmp expect io.marks && + + echo ":3 $blob" >>expect && + + git fast-import --import-marks=io.marks \ + --export-marks=io.marks <<-\EOF && + feature import-marks-if-exists=not_io.marks + blob + mark :3 + data 3 + hi + + EOF + test_cmp expect io.marks && + + >expect && + + git fast-import --import-marks-if-exists=not_io.marks \ + --export-marks=io.marks <<-\EOF + feature import-marks-if-exists=io.marks + EOF + test_cmp expect io.marks +' + cat >input << EOF feature import-marks=marks.out feature export-marks=marks.new @@ -2197,6 +2480,48 @@ test_expect_success 'R: quiet option results in no stats being output' ' test_cmp empty output ' +test_expect_success 'R: feature done means terminating "done" is mandatory' ' + echo feature done | test_must_fail git fast-import && + test_must_fail git fast-import --done </dev/null +' + +test_expect_success 'R: terminating "done" with trailing gibberish is ok' ' + git fast-import <<-\EOF && + feature done + done + trailing gibberish + EOF + git fast-import <<-\EOF + done + more trailing gibberish + EOF +' + +test_expect_success 'R: terminating "done" within commit' ' + cat >expect <<-\EOF && + OBJID + :000000 100644 OBJID OBJID A hello.c + :000000 100644 OBJID OBJID A hello2.c + EOF + git fast-import <<-EOF && + commit refs/heads/done-ends + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + data <<EOT + Commit terminated by "done" command + EOT + M 100644 inline hello.c + data <<EOT + Hello, world. + EOT + C hello.c hello2.c + done + EOF + git rev-list done-ends | + git diff-tree -r --stdin --root --always | + sed -e "s/$_x40/OBJID/g" >actual && + test_cmp expect actual +' + cat >input <<EOF option git non-existing-option EOF diff --git a/t/t9350-fast-export.sh b/t/t9350-fast-export.sh index f823c05305..950d0ff498 100755 --- a/t/t9350-fast-export.sh +++ b/t/t9350-fast-export.sh @@ -228,7 +228,7 @@ test_expect_success 'fast-export -C -C | fast-import' ' mkdir new && git --git-dir=new/.git init && git fast-export -C -C --signed-tags=strip --all > output && - grep "^C \"file6\" \"file7\"\$" output && + grep "^C file6 file7\$" output && cat output | (cd new && git fast-import && @@ -414,4 +414,30 @@ test_expect_success SYMLINKS 'directory becomes symlink' ' (cd result && git show master:foo) ' +test_expect_success 'fast-export quotes pathnames' ' + git init crazy-paths && + (cd crazy-paths && + blob=`echo foo | git hash-object -w --stdin` && + git update-index --add \ + --cacheinfo 100644 $blob "$(printf "path with\\nnewline")" \ + --cacheinfo 100644 $blob "path with \"quote\"" \ + --cacheinfo 100644 $blob "path with \\backslash" \ + --cacheinfo 100644 $blob "path with space" && + git commit -m addition && + git ls-files -z -s | perl -0pe "s{\\t}{$&subdir/}" >index && + git read-tree --empty && + git update-index -z --index-info <index && + git commit -m rename && + git read-tree --empty && + git commit -m deletion && + git fast-export HEAD >export.out && + git rev-list HEAD >expect && + git init result && + cd result && + git fast-import <../export.out && + git rev-list HEAD >actual && + test_cmp ../expect actual + ) +' + test_done diff --git a/t/t9800-git-p4.sh b/t/t9800-git-p4.sh index 33b0127651..01ba041fde 100755 --- a/t/t9800-git-p4.sh +++ b/t/t9800-git-p4.sh @@ -45,29 +45,33 @@ test_expect_success 'add p4 files' ' cd "$TRASH_DIRECTORY" ' +cleanup_git() { + cd "$TRASH_DIRECTORY" && + rm -rf "$git" && + mkdir "$git" +} + test_expect_success 'basic git-p4 clone' ' "$GITP4" clone --dest="$git" //depot && + test_when_finished cleanup_git && cd "$git" && git log --oneline >lines && - test_line_count = 1 lines && - cd .. && - rm -rf "$git" && mkdir "$git" + test_line_count = 1 lines ' test_expect_success 'git-p4 clone @all' ' "$GITP4" clone --dest="$git" //depot@all && + test_when_finished cleanup_git && cd "$git" && git log --oneline >lines && - test_line_count = 2 lines && - cd .. && - rm -rf "$git" && mkdir "$git" + test_line_count = 2 lines ' test_expect_success 'git-p4 sync uninitialized repo' ' test_create_repo "$git" && + test_when_finished cleanup_git && cd "$git" && - test_must_fail "$GITP4" sync && - rm -rf "$git" && mkdir "$git" + test_must_fail "$GITP4" sync ' # @@ -76,19 +80,18 @@ test_expect_success 'git-p4 sync uninitialized repo' ' # test_expect_success 'git-p4 sync new branch' ' test_create_repo "$git" && + test_when_finished cleanup_git && cd "$git" && test_commit head && "$GITP4" sync --branch=refs/remotes/p4/depot //depot@all && git log --oneline p4/depot >lines && - cat lines && - test_line_count = 2 lines && - cd .. && - rm -rf "$git" && mkdir "$git" + test_line_count = 2 lines ' test_expect_success 'exit when p4 fails to produce marshaled output' ' badp4dir="$TRASH_DIRECTORY/badp4dir" && mkdir -p "$badp4dir" && + test_when_finished "rm -rf $badp4dir" && cat >"$badp4dir"/p4 <<-EOF && #!$SHELL_PATH exit 1 @@ -106,29 +109,26 @@ test_expect_success 'add p4 files with wildcards in the names' ' echo file-wild-at >file-wild@at && echo file-wild-percent >file-wild%percent && p4 add -f file-wild* && - p4 submit -d "file wildcards" && - cd "$TRASH_DIRECTORY" + p4 submit -d "file wildcards" ' test_expect_success 'wildcard files git-p4 clone' ' "$GITP4" clone --dest="$git" //depot && + test_when_finished cleanup_git && cd "$git" && test -f file-wild#hash && test -f file-wild\*star && test -f file-wild@at && - test -f file-wild%percent && - cd "$TRASH_DIRECTORY" && - rm -rf "$git" && mkdir "$git" + test -f file-wild%percent ' test_expect_success 'clone bare' ' "$GITP4" clone --dest="$git" --bare //depot && + test_when_finished cleanup_git && cd "$git" && test ! -d .git && bare=`git config --get core.bare` && - test "$bare" = true && - cd "$TRASH_DIRECTORY" && - rm -rf "$git" && mkdir "$git" + test "$bare" = true ' p4_add_user() { @@ -173,6 +173,7 @@ test_expect_success 'preserve users' ' p4_add_user bob Bob && p4_grant_admin alice && "$GITP4" clone --dest="$git" //depot && + test_when_finished cleanup_git && cd "$git" && echo "username: a change by alice" >> file1 && echo "username: a change by bob" >> file2 && @@ -181,29 +182,28 @@ test_expect_success 'preserve users' ' git config git-p4.skipSubmitEditCheck true && P4EDITOR=touch P4USER=alice P4PASSWD=secret "$GITP4" commit --preserve-user && p4_check_commit_author file1 alice && - p4_check_commit_author file2 bob && - cd "$TRASH_DIRECTORY" && - rm -rf "$git" && mkdir "$git" + p4_check_commit_author file2 bob ' # Test username support, submitting as bob, who lacks admin rights. Should # not submit change to p4 (git diff should show deltas). test_expect_success 'refuse to preserve users without perms' ' "$GITP4" clone --dest="$git" //depot && + test_when_finished cleanup_git && cd "$git" && + git config git-p4.skipSubmitEditCheck true && echo "username-noperms: a change by alice" >> file1 && git commit --author "Alice <alice@localhost>" -m "perms: a change by alice" file1 && ! P4EDITOR=touch P4USER=bob P4PASSWD=secret "$GITP4" commit --preserve-user && - ! git diff --exit-code HEAD..p4/master > /dev/null && - cd "$TRASH_DIRECTORY" && - rm -rf "$git" && mkdir "$git" + ! git diff --exit-code HEAD..p4/master > /dev/null ' # What happens with unknown author? Without allowMissingP4Users it should fail. test_expect_success 'preserve user where author is unknown to p4' ' "$GITP4" clone --dest="$git" //depot && + test_when_finished cleanup_git && cd "$git" && - git config git-p4.skipSubmitEditCheck true + git config git-p4.skipSubmitEditCheck true && echo "username-bob: a change by bob" >> file1 && git commit --author "Bob <bob@localhost>" -m "preserve: a change by bob" file1 && echo "username-unknown: a change by charlie" >> file1 && @@ -215,9 +215,7 @@ test_expect_success 'preserve user where author is unknown to p4' ' git config git-p4.preserveUser true && P4EDITOR=touch P4USER=alice P4PASSWD=secret "$GITP4" commit && git diff --exit-code HEAD..p4/master > /dev/null && - p4_check_commit_author file1 alice && - cd "$TRASH_DIRECTORY" && - rm -rf "$git" && mkdir "$git" + p4_check_commit_author file1 alice ' # If we're *not* using --preserve-user, git-p4 should warn if we're submitting @@ -226,33 +224,247 @@ test_expect_success 'preserve user where author is unknown to p4' ' # Test: warning disabled and user is the same. test_expect_success 'not preserving user with mixed authorship' ' "$GITP4" clone --dest="$git" //depot && - ( - cd "$git" && - git config git-p4.skipSubmitEditCheck true && - p4_add_user derek Derek && - - make_change_by_user usernamefile3 Derek derek@localhost && - P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual && - grep "git author derek@localhost does not match" actual && - - make_change_by_user usernamefile3 Charlie charlie@localhost && - P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual && - grep "git author charlie@localhost does not match" actual && - - make_change_by_user usernamefile3 alice alice@localhost && - P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual && - ! grep "git author.*does not match" actual && - - git config git-p4.skipUserNameCheck true && - make_change_by_user usernamefile3 Charlie charlie@localhost && - P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual && - ! grep "git author.*does not match" actual && - - p4_check_commit_author usernamefile3 alice - ) && - rm -rf "$git" && mkdir "$git" + test_when_finished cleanup_git && + cd "$git" && + git config git-p4.skipSubmitEditCheck true && + p4_add_user derek Derek && + + make_change_by_user usernamefile3 Derek derek@localhost && + P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual && + grep "git author derek@localhost does not match" actual && + + make_change_by_user usernamefile3 Charlie charlie@localhost && + P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual && + grep "git author charlie@localhost does not match" actual && + + make_change_by_user usernamefile3 alice alice@localhost && + P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual && + ! grep "git author.*does not match" actual && + + git config git-p4.skipUserNameCheck true && + make_change_by_user usernamefile3 Charlie charlie@localhost && + P4EDITOR=cat P4USER=alice P4PASSWD=secret "$GITP4" commit >actual && + ! grep "git author.*does not match" actual && + + p4_check_commit_author usernamefile3 alice ' +marshal_dump() { + what=$1 + python -c 'import marshal, sys; d = marshal.load(sys.stdin); print d["'$what'"]' +} + +# Sleep a bit so that the top-most p4 change did not happen "now". Then +# import the repo and make sure that the initial import has the same time +# as the top-most change. +test_expect_success 'initial import time from top change time' ' + p4change=$(p4 -G changes -m 1 //depot/... | marshal_dump change) && + p4time=$(p4 -G changes -m 1 //depot/... | marshal_dump time) && + sleep 3 && + "$GITP4" clone --dest="$git" //depot && + test_when_finished cleanup_git && + cd "$git" && + gittime=$(git show -s --raw --pretty=format:%at HEAD) && + echo $p4time $gittime && + test $p4time = $gittime +' + +# Rename a file and confirm that rename is not detected in P4. +# Rename the new file again with detectRenames option enabled and confirm that +# this is detected in P4. +# Rename the new file again adding an extra line, configure a big threshold in +# detectRenames and confirm that rename is not detected in P4. +# Repeat, this time with a smaller threshold and confirm that the rename is +# detected in P4. +test_expect_success 'detect renames' ' + "$GITP4" clone --dest="$git" //depot@all && + test_when_finished cleanup_git && + cd "$git" && + git config git-p4.skipSubmitEditCheck true && + + git mv file1 file4 && + git commit -a -m "Rename file1 to file4" && + git diff-tree -r -M HEAD && + "$GITP4" submit && + p4 filelog //depot/file4 && + ! p4 filelog //depot/file4 | grep -q "branch from" && + + git mv file4 file5 && + git commit -a -m "Rename file4 to file5" && + git diff-tree -r -M HEAD && + git config git-p4.detectRenames true && + "$GITP4" submit && + p4 filelog //depot/file5 && + p4 filelog //depot/file5 | grep -q "branch from //depot/file4" && + + git mv file5 file6 && + echo update >>file6 && + git add file6 && + git commit -a -m "Rename file5 to file6 with changes" && + git diff-tree -r -M HEAD && + level=$(git diff-tree -r -M HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/R0*//") && + test -n "$level" && test "$level" -gt 0 && test "$level" -lt 98 && + git config git-p4.detectRenames $((level + 2)) && + "$GITP4" submit && + p4 filelog //depot/file6 && + ! p4 filelog //depot/file6 | grep -q "branch from" && + + git mv file6 file7 && + echo update >>file7 && + git add file7 && + git commit -a -m "Rename file6 to file7 with changes" && + git diff-tree -r -M HEAD && + level=$(git diff-tree -r -M HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/R0*//") && + test -n "$level" && test "$level" -gt 2 && test "$level" -lt 100 && + git config git-p4.detectRenames $((level - 2)) && + "$GITP4" submit && + p4 filelog //depot/file7 && + p4 filelog //depot/file7 | grep -q "branch from //depot/file6" +' + +# Copy a file and confirm that copy is not detected in P4. +# Copy a file with detectCopies option enabled and confirm that copy is not +# detected in P4. +# Modify and copy a file with detectCopies option enabled and confirm that copy +# is detected in P4. +# Copy a file with detectCopies and detectCopiesHarder options enabled and +# confirm that copy is detected in P4. +# Modify and copy a file, configure a bigger threshold in detectCopies and +# confirm that copy is not detected in P4. +# Modify and copy a file, configure a smaller threshold in detectCopies and +# confirm that copy is detected in P4. +test_expect_success 'detect copies' ' + "$GITP4" clone --dest="$git" //depot@all && + test_when_finished cleanup_git && + cd "$git" && + git config git-p4.skipSubmitEditCheck true && + + cp file2 file8 && + git add file8 && + git commit -a -m "Copy file2 to file8" && + git diff-tree -r -C HEAD && + "$GITP4" submit && + p4 filelog //depot/file8 && + ! p4 filelog //depot/file8 | grep -q "branch from" && + + cp file2 file9 && + git add file9 && + git commit -a -m "Copy file2 to file9" && + git diff-tree -r -C HEAD && + git config git-p4.detectCopies true && + "$GITP4" submit && + p4 filelog //depot/file9 && + ! p4 filelog //depot/file9 | grep -q "branch from" && + + echo "file2" >>file2 && + cp file2 file10 && + git add file2 file10 && + git commit -a -m "Modify and copy file2 to file10" && + git diff-tree -r -C HEAD && + "$GITP4" submit && + p4 filelog //depot/file10 && + p4 filelog //depot/file10 | grep -q "branch from //depot/file" && + + cp file2 file11 && + git add file11 && + git commit -a -m "Copy file2 to file11" && + git diff-tree -r -C --find-copies-harder HEAD && + src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) && + test "$src" = file10 && + git config git-p4.detectCopiesHarder true && + "$GITP4" submit && + p4 filelog //depot/file11 && + p4 filelog //depot/file11 | grep -q "branch from //depot/file" && + + cp file2 file12 && + echo "some text" >>file12 && + git add file12 && + git commit -a -m "Copy file2 to file12 with changes" && + git diff-tree -r -C --find-copies-harder HEAD && + level=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/C0*//") && + test -n "$level" && test "$level" -gt 0 && test "$level" -lt 98 && + src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) && + test "$src" = file10 && + git config git-p4.detectCopies $((level + 2)) && + "$GITP4" submit && + p4 filelog //depot/file12 && + ! p4 filelog //depot/file12 | grep -q "branch from" && + + cp file2 file13 && + echo "different text" >>file13 && + git add file13 && + git commit -a -m "Copy file2 to file13 with changes" && + git diff-tree -r -C --find-copies-harder HEAD && + level=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/C0*//") && + test -n "$level" && test "$level" -gt 2 && test "$level" -lt 100 && + src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) && + test "$src" = file10 && + git config git-p4.detectCopies $((level - 2)) && + "$GITP4" submit && + p4 filelog //depot/file13 && + p4 filelog //depot/file13 | grep -q "branch from //depot/file" +' + +# Create a simple branch structure in P4 depot to check if it is correctly +# cloned. +test_expect_success 'add simple p4 branches' ' + cd "$cli" && + mkdir branch1 && + cd branch1 && + echo file1 >file1 && + echo file2 >file2 && + p4 add file1 file2 && + p4 submit -d "branch1" && + p4 integrate //depot/branch1/... //depot/branch2/... && + p4 submit -d "branch2" && + echo file3 >file3 && + p4 add file3 && + p4 submit -d "add file3 in branch1" && + p4 open file2 && + echo update >>file2 && + p4 submit -d "update file2 in branch1" && + p4 integrate //depot/branch1/... //depot/branch3/... && + p4 submit -d "branch3" && + cd "$TRASH_DIRECTORY" +' + +# Configure branches through git-config and clone them. +# All files are tested to make sure branches were cloned correctly. +# Finally, make an update to branch1 on P4 side to check if it is imported +# correctly by git-p4. +test_expect_success 'git-p4 clone simple branches' ' + test_when_finished cleanup_git && + test_create_repo "$git" && + cd "$git" && + git config git-p4.branchList branch1:branch2 && + git config --add git-p4.branchList branch1:branch3 && + "$GITP4" clone --dest=. --detect-branches //depot@all && + git log --all --graph --decorate --stat && + git reset --hard p4/depot/branch1 && + test -f file1 && + test -f file2 && + test -f file3 && + grep -q update file2 && + git reset --hard p4/depot/branch2 && + test -f file1 && + test -f file2 && + test ! -f file3 && + ! grep -q update file2 && + git reset --hard p4/depot/branch3 && + test -f file1 && + test -f file2 && + test -f file3 && + grep -q update file2 && + cd "$cli" && + cd branch1 && + p4 edit file2 && + echo file2_ >>file2 && + p4 submit -d "update file2 in branch1" && + cd "$git" && + git reset --hard p4/depot/branch1 && + "$GITP4" rebase && + grep -q file2_ file2 +' test_expect_success 'shutdown' ' pid=`pgrep -f p4d` && diff --git a/t/t9901-git-web--browse.sh b/t/t9901-git-web--browse.sh new file mode 100755 index 0000000000..7906e5d032 --- /dev/null +++ b/t/t9901-git-web--browse.sh @@ -0,0 +1,66 @@ +#!/bin/sh +# + +test_description='git web--browse basic tests + +This test checks that git web--browse can handle various valid URLs.' + +. ./test-lib.sh + +test_expect_success \ + 'URL with an ampersand in it' ' + echo http://example.com/foo\&bar >expect && + git config browser.custom.cmd echo && + git web--browse --browser=custom \ + http://example.com/foo\&bar >actual && + test_cmp expect actual +' + +test_expect_success \ + 'URL with a semi-colon in it' ' + echo http://example.com/foo\;bar >expect && + git config browser.custom.cmd echo && + git web--browse --browser=custom \ + http://example.com/foo\;bar >actual && + test_cmp expect actual +' + +test_expect_success \ + 'URL with a hash in it' ' + echo http://example.com/foo#bar >expect && + git config browser.custom.cmd echo && + git web--browse --browser=custom \ + http://example.com/foo#bar >actual && + test_cmp expect actual +' + +test_expect_success \ + 'browser paths are properly quoted' ' + echo fake: http://example.com/foo >expect && + cat >"fake browser" <<-\EOF && + #!/bin/sh + echo fake: "$@" + EOF + chmod +x "fake browser" && + git config browser.w3m.path "`pwd`/fake browser" && + git web--browse --browser=w3m \ + http://example.com/foo >actual && + test_cmp expect actual +' + +test_expect_success \ + 'browser command allows arbitrary shell code' ' + echo "arg: http://example.com/foo" >expect && + git config browser.custom.cmd " + f() { + for i in \"\$@\"; do + echo arg: \$i + done + } + f" && + git web--browse --browser=custom \ + http://example.com/foo >actual && + test_cmp expect actual +' + +test_done diff --git a/t/test4012.png b/t/test-binary-1.png Binary files differindex 7b181d15ce..7b181d15ce 100644 --- a/t/test4012.png +++ b/t/test-binary-1.png diff --git a/t/test9200b.png b/t/test-binary-2.png Binary files differindex ac22ccbd3e..ac22ccbd3e 100644 --- a/t/test9200b.png +++ b/t/test-binary-2.png diff --git a/t/test-lib.sh b/t/test-lib.sh index df25f17929..bdd9513b84 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -92,6 +92,10 @@ _x40="$_x05$_x05$_x05$_x05$_x05$_x05$_x05$_x05" # Zero SHA-1 _z40=0000000000000000000000000000000000000000 +# Line feed +LF=' +' + # Each test should start with something like this, after copyright notices: # # test_description='Description of this test... @@ -357,6 +361,24 @@ test_chmod () { git update-index --add "--chmod=$@" } +# Unset a configuration variable, but don't fail if it doesn't exist. +test_unconfig () { + git config --unset-all "$@" + config_status=$? + case "$config_status" in + 5) # ok, nothing to unset + config_status=0 + ;; + esac + return $config_status +} + +# Set git config, automatically unsetting it after the test is over. +test_config () { + test_when_finished "test_unconfig '$1'" && + git config "$@" +} + # Use test_set_prereq to tell that a particular prerequisite is available. # The prerequisite can later be checked for in two ways: # @@ -444,20 +466,26 @@ test_debug () { test "$debug" = "" || eval "$1" } +test_eval_ () { + # This is a separate function because some tests use + # "return" to end a test_expect_success block early. + eval >&3 2>&4 "$*" +} + test_run_ () { test_cleanup=: expecting_failure=$2 - eval >&3 2>&4 "$1" + test_eval_ "$1" eval_ret=$? if test -z "$immediate" || test $eval_ret = 0 || test -n "$expecting_failure" then - eval >&3 2>&4 "$test_cleanup" + test_eval_ "$test_cleanup" fi if test "$verbose" = "t" && test -n "$HARNESS_ACTIVE"; then echo "" fi - return 0 + return "$eval_ret" } test_skip () { @@ -502,8 +530,7 @@ test_expect_failure () { if ! test_skip "$@" then say >&3 "checking known breakage: $2" - test_run_ "$2" expecting_failure - if [ "$?" = 0 -a "$eval_ret" = 0 ] + if test_run_ "$2" expecting_failure then test_known_broken_ok_ "$1" else @@ -521,8 +548,7 @@ test_expect_success () { if ! test_skip "$@" then say >&3 "expecting success: $2" - test_run_ "$2" - if [ "$?" = 0 -a "$eval_ret" = 0 ] + if test_run_ "$2" then test_ok_ "$1" else @@ -924,6 +950,8 @@ then do make_valgrind_symlink $file done + # special-case the mergetools loadables + make_symlink "$GIT_BUILD_DIR"/mergetools "$GIT_VALGRIND/bin/mergetools" OLDIFS=$IFS IFS=: for path in $PATH diff --git a/t/test9200a.png b/t/test9200a.png Binary files differdeleted file mode 100644 index 7b181d15ce..0000000000 --- a/t/test9200a.png +++ /dev/null |