diff options
Diffstat (limited to 't')
89 files changed, 4317 insertions, 839 deletions
@@ -82,6 +82,12 @@ appropriately before running "make". numbers matching <pattern>. The number matched against is simply the running count of the test within the file. +-x:: + Turn on shell tracing (i.e., `set -x`) during the tests + themselves. Implies `--verbose`. Note that this can cause + failures in some tests which redirect and test the + output of shell functions. Use with caution. + -d:: --debug:: This may help the person who is developing a new test. diff --git a/t/lib-credential.sh b/t/lib-credential.sh index 9e7d7962b0..d8e41f7ddd 100755 --- a/t/lib-credential.sh +++ b/t/lib-credential.sh @@ -278,12 +278,10 @@ helper_test_timeout() { ' } -cat >askpass <<\EOF -#!/bin/sh +write_script askpass <<\EOF echo >&2 askpass: $* what=$(echo $1 | cut -d" " -f1 | tr A-Z a-z | tr -cd a-z) echo "askpass-$what" EOF -chmod +x askpass GIT_ASKPASS="$PWD/askpass" export GIT_ASKPASS diff --git a/t/lib-gpg.sh b/t/lib-gpg.sh index fd499e7c49..cd2baef383 100755 --- a/t/lib-gpg.sh +++ b/t/lib-gpg.sh @@ -18,6 +18,7 @@ else # No password given, to enable non-interactive operation. cp -R "$TEST_DIRECTORY"/lib-gpg ./gpghome chmod 0700 gpghome + chmod 0600 gpghome/* GNUPGHOME="$(pwd)/gpghome" export GNUPGHOME test_set_prereq GPG diff --git a/t/lib-httpd/apache.conf b/t/lib-httpd/apache.conf index b384d79935..7713dd2609 100644 --- a/t/lib-httpd/apache.conf +++ b/t/lib-httpd/apache.conf @@ -68,6 +68,7 @@ LockFile accept.lock PassEnv GIT_VALGRIND PassEnv GIT_VALGRIND_OPTIONS +PassEnv GNUPGHOME Alias /dumb/ www/ Alias /auth/dumb/ www/auth/dumb/ diff --git a/t/t0001-init.sh b/t/t0001-init.sh index e62c0ffbc2..7de8d85ee8 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -12,6 +12,13 @@ check_config () { echo "expected a directory $1, a file $1/config and $1/refs" return 1 fi + + if test_have_prereq POSIXPERM && test -x "$1/config" + then + echo "$1/config is executable?" + return 1 + fi + bare=$(cd "$1" && git config --bool core.bare) worktree=$(cd "$1" && git config core.worktree) || worktree=unset diff --git a/t/t0005-signals.sh b/t/t0005-signals.sh index 981437b3a8..aeea50c633 100755 --- a/t/t0005-signals.sh +++ b/t/t0005-signals.sh @@ -27,4 +27,26 @@ test_expect_success !MINGW 'signals are propagated using shell convention' ' test_expect_code 143 git sigterm ' +large_git () { + for i in $(test_seq 1 100) + do + git diff --cached --binary || return + done +} + +test_expect_success 'create blob' ' + test-genrandom foo 16384 >file && + git add file +' + +test_expect_success !MINGW 'a constipated git dies with SIGPIPE' ' + OUT=$( ((large_git; echo $? 1>&3) | :) 3>&1 ) + test "$OUT" -eq 141 +' + +test_expect_success !MINGW 'a constipated git dies with SIGPIPE even if parent ignores it' ' + OUT=$( ((trap "" PIPE; large_git; echo $? 1>&3) | :) 3>&1 ) + test "$OUT" -eq 141 +' + test_done diff --git a/t/t0008-ignores.sh b/t/t0008-ignores.sh index 39e55a13c8..8dc6939b90 100755 --- a/t/t0008-ignores.sh +++ b/t/t0008-ignores.sh @@ -806,7 +806,7 @@ test_expect_success !MINGW 'quoting allows trailing whitespace' ' test_cmp err.expect err ' -test_expect_success NOT_MINGW,NOT_CYGWIN 'correct handling of backslashes' ' +test_expect_success !MINGW,!CYGWIN 'correct handling of backslashes' ' rm -rf whitespace && mkdir whitespace && >"whitespace/trailing 1 " && diff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh index f890c54d13..ca7d2a630a 100755 --- a/t/t0021-conversion.sh +++ b/t/t0021-conversion.sh @@ -153,17 +153,23 @@ test_expect_success 'filter shell-escaped filenames' ' : ' -test_expect_success 'required filter success' ' - git config filter.required.smudge cat && - git config filter.required.clean cat && +test_expect_success 'required filter should filter data' ' + git config filter.required.smudge ./rot13.sh && + git config filter.required.clean ./rot13.sh && git config filter.required.required true && echo "*.r filter=required" >.gitattributes && - echo test >test.r && + cat test.o >test.r && git add test.r && + rm -f test.r && - git checkout -- test.r + git checkout -- test.r && + cmp test.o test.r && + + ./rot13.sh <test.o >expected && + git cat-file blob :test.r >actual && + cmp expected actual ' test_expect_success 'required filter smudge failure' ' @@ -190,6 +196,14 @@ test_expect_success 'required filter clean failure' ' test_must_fail git add test.fc ' +test_expect_success 'filtering large input to small output should use little memory' ' + git config filter.devnull.clean "cat >/dev/null" && + git config filter.devnull.required true && + for i in $(test_seq 1 30); do printf "%1048576d" 1; done >30MB && + echo "30MB filter=devnull" >.gitattributes && + GIT_MMAP_LIMIT=1m GIT_ALLOC_LIMIT=1m git add 30MB +' + test_expect_success EXPENSIVE 'filter large file' ' git config filter.largefile.smudge cat && git config filter.largefile.clean cat && diff --git a/t/t0026-eol-config.sh b/t/t0026-eol-config.sh index 4807b0f015..c5203e232c 100755 --- a/t/t0026-eol-config.sh +++ b/t/t0026-eol-config.sh @@ -80,4 +80,24 @@ test_expect_success 'autocrlf=true overrides unset eol' ' test -z "$onediff" && test -z "$twodiff" ' +test_expect_success NATIVE_CRLF 'eol native is crlf' ' + + rm -rf native_eol && mkdir native_eol && + ( + cd native_eol && + printf "*.txt text\n" >.gitattributes && + printf "one\r\ntwo\r\nthree\r\n" >filedos.txt && + printf "one\ntwo\nthree\n" >fileunix.txt && + git init && + git config core.autocrlf false && + git config core.eol native && + git add filedos.txt fileunix.txt && + git commit -m "first" && + rm file*.txt && + git reset --hard HEAD && + has_cr filedos.txt && + has_cr fileunix.txt + ) +' + test_done diff --git a/t/t0027-auto-crlf.sh b/t/t0027-auto-crlf.sh index 72dd3e8bb4..2a4a6c1226 100755 --- a/t/t0027-auto-crlf.sh +++ b/t/t0027-auto-crlf.sh @@ -10,30 +10,26 @@ then test_done fi - -compare_files() -{ - od -c <"$1" >"$1".expect && - od -c <"$2" >"$2".actual && +compare_files () { + tr '\015\000' QN <"$1" >"$1".expect && + tr '\015\000' QN <"$2" >"$2".actual && test_cmp "$1".expect "$2".actual && rm "$1".expect "$2".actual } -compare_ws_file() -{ +compare_ws_file () { pfx=$1 exp=$2.expect act=$pfx.actual.$3 - od -c <"$2" >"$exp" && - od -c <"$3" >"$act" && + tr '\015\000' QN <"$2" >"$exp" && + tr '\015\000' QN <"$3" >"$act" && test_cmp $exp $act && rm $exp $act } -create_gitattributes() -{ - txtbin=$1 - case "$txtbin" in +create_gitattributes () { + attr=$1 + case "$attr" in auto) echo "*.txt text=auto" >.gitattributes ;; @@ -43,35 +39,43 @@ create_gitattributes() -text) echo "*.txt -text" >.gitattributes ;; - *) + crlf) + echo "*.txt eol=crlf" >.gitattributes + ;; + lf) + echo "*.txt eol=lf" >.gitattributes + ;; + "") echo >.gitattributes ;; + *) + echo >&2 invalid attribute: $attr + exit 1 + ;; esac } -create_file_in_repo() -{ +create_file_in_repo () { crlf=$1 - txtbin=$2 - create_gitattributes "$txtbin" && + attr=$2 + create_gitattributes "$attr" && for f in LF CRLF LF_mix_CR CRLF_mix_LF CRLF_nul do - pfx=crlf_${crlf}_attr_${txtbin}_$f.txt && + pfx=crlf_${crlf}_attr_${attr}_$f.txt && cp $f $pfx && git -c core.autocrlf=$crlf add $pfx done && git commit -m "core.autocrlf $crlf" } -check_files_in_repo() -{ +check_files_in_repo () { crlf=$1 - txtbin=$2 + attr=$2 lfname=$3 crlfname=$4 lfmixcrlf=$5 lfmixcr=$6 crlfnul=$7 - pfx=crlf_${crlf}_attr_${txtbin}_ && + pfx=crlf_${crlf}_attr_${attr}_ && compare_files $lfname ${pfx}LF.txt && compare_files $crlfname ${pfx}CRLF.txt && compare_files $lfmixcrlf ${pfx}CRLF_mix_LF.txt && @@ -80,19 +84,18 @@ check_files_in_repo() } -check_files_in_ws() -{ +check_files_in_ws () { eol=$1 crlf=$2 - txtbin=$3 + attr=$3 lfname=$4 crlfname=$5 lfmixcrlf=$6 lfmixcr=$7 crlfnul=$8 - create_gitattributes $txtbin && + create_gitattributes $attr && git config core.autocrlf $crlf && - pfx=eol_${eol}_crlf_${crlf}_attr_${txtbin}_ && + pfx=eol_${eol}_crlf_${crlf}_attr_${attr}_ && src=crlf_false_attr__ && for f in LF CRLF LF_mix_CR CRLF_mix_LF CRLF_nul do @@ -104,42 +107,24 @@ check_files_in_ws() fi done - - test_expect_success "checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$txtbin file=LF" " + test_expect_success "checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$attr file=LF" " compare_ws_file $pfx $lfname ${src}LF.txt " - test_expect_success "checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$txtbin file=CRLF" " + test_expect_success "checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$attr file=CRLF" " compare_ws_file $pfx $crlfname ${src}CRLF.txt " - test_expect_success "checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$txtbin file=CRLF_mix_LF" " + test_expect_success "checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$attr file=CRLF_mix_LF" " compare_ws_file $pfx $lfmixcrlf ${src}CRLF_mix_LF.txt " - test_expect_success "checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$txtbin file=LF_mix_CR" " + test_expect_success "checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$attr file=LF_mix_CR" " compare_ws_file $pfx $lfmixcr ${src}LF_mix_CR.txt " - test_expect_success "checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$txtbin file=CRLF_nul" " + test_expect_success "checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$attr file=CRLF_nul" " compare_ws_file $pfx $crlfnul ${src}CRLF_nul.txt " } ####### -( - type od >/dev/null && - printf "line1Q\r\nline2\r\nline3" | q_to_nul >CRLF_nul && - cat >expect <<-EOF && - 0000000 l i n e 1 \0 \r \n l i n e 2 \r \n l - 0000020 i n e 3 - 0000024 -EOF - od -c CRLF_nul | sed -e "s/[ ][ ]*/ /g" -e "s/ *$//" >actual - test_cmp expect actual && - rm expect actual -) || { - skip_all="od not found or od -c not usable" - exit 0 - test_done -} - test_expect_success 'setup master' ' echo >.gitattributes && git checkout -b master && @@ -150,9 +135,10 @@ test_expect_success 'setup master' ' printf "line1\r\nline2\nline3" >CRLF_mix_LF && printf "line1\nline2\rline3" >LF_mix_CR && printf "line1\r\nline2\rline3" >CRLF_mix_CR && + printf "line1Q\r\nline2\r\nline3" | q_to_nul >CRLF_nul && printf "line1Q\nline2\nline3" | q_to_nul >LF_nul ' -# CRLF_nul had been created above + test_expect_success 'create files' ' create_file_in_repo false "" && @@ -201,7 +187,8 @@ test_expect_success 'commit -text' ' ################################################################################ # Check how files in the repo are changed when they are checked out # How to read the table below: -# - check_files_in_ws will check multiple files, see below +# - check_files_in_ws will check multiple files with a combination of settings +# and attributes (core.autocrlf=input is forbidden with core.eol=crlf) # - parameter $1 : core.eol lf | crlf # - parameter $2 : core.autocrlf false | true | input # - parameter $3 : text in .gitattributs "" (empty) | auto | text | -text @@ -211,55 +198,88 @@ test_expect_success 'commit -text' ' # - parameter $7 : reference for a file with LF and CR in the repo (does somebody uses this ?) # - parameter $8 : reference for a file with CRLF and a NUL (should be handled as binary when auto) -check_files_in_ws lf false "" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul -check_files_in_ws lf true "" CRLF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul -check_files_in_ws lf input "" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul - -check_files_in_ws lf false "auto" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul -check_files_in_ws lf true "auto" CRLF CRLF CRLF LF_mix_CR CRLF_nul -check_files_in_ws lf input "auto" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul - -check_files_in_ws lf false "text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul -check_files_in_ws lf true "text" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul -check_files_in_ws lf input "text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul - -check_files_in_ws lf false "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul -check_files_in_ws lf true "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul -check_files_in_ws lf input "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul - -########### -#core.autocrlf=input is forbidden with core.eol=crlf -check_files_in_ws crlf false "" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul -check_files_in_ws crlf true "" CRLF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul - -check_files_in_ws crlf false "auto" CRLF CRLF CRLF LF_mix_CR CRLF_nul -check_files_in_ws crlf true "auto" CRLF CRLF CRLF LF_mix_CR CRLF_nul - -check_files_in_ws crlf false "text" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul -check_files_in_ws crlf true "text" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul - -check_files_in_ws crlf false "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul -check_files_in_ws crlf true "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul - +# What we have in the repo: +# ----------------- EOL in repo ---------------- +# LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +# settings with checkout: +# core. core. .gitattr +# eol acrlf +# ---------------------------------------------- +# What we want to have in the working tree: if test_have_prereq MINGW then -check_files_in_ws "" false "" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul -check_files_in_ws "" true "" CRLF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul -check_files_in_ws "" false "auto" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul -check_files_in_ws "" true "auto" CRLF CRLF CRLF LF_mix_CR CRLF_nul -check_files_in_ws "" false "text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul -check_files_in_ws "" true "text" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul -check_files_in_ws "" false "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul -check_files_in_ws "" true "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul - -check_files_in_ws native false "" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul -check_files_in_ws native true "" CRLF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul -check_files_in_ws native false "auto" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul -check_files_in_ws native true "auto" CRLF CRLF CRLF LF_mix_CR CRLF_nul -check_files_in_ws native false "text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul -check_files_in_ws native true "text" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul -check_files_in_ws native false "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul -check_files_in_ws native true "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +MIX_CRLF_LF=CRLF +MIX_LF_CR=CRLF_mix_CR +NL=CRLF +else +MIX_CRLF_LF=CRLF_mix_LF +MIX_LF_CR=LF_mix_CR +NL=LF fi +export CRLF_MIX_LF_CR MIX NL + +check_files_in_ws lf false "" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws lf true "" CRLF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws lf input "" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws lf false "auto" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws lf true "auto" CRLF CRLF CRLF LF_mix_CR CRLF_nul +check_files_in_ws lf input "auto" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws lf false "text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws lf true "text" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul +check_files_in_ws lf input "text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws lf false "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws lf true "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws lf input "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws lf false "lf" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws lf true "lf" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws lf input "lf" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws lf false "crlf" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul +check_files_in_ws lf true "crlf" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul +check_files_in_ws lf input "crlf" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul + +check_files_in_ws crlf false "" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws crlf true "" CRLF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws crlf false "auto" CRLF CRLF CRLF LF_mix_CR CRLF_nul +check_files_in_ws crlf true "auto" CRLF CRLF CRLF LF_mix_CR CRLF_nul +check_files_in_ws crlf false "text" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul +check_files_in_ws crlf true "text" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul +check_files_in_ws crlf false "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws crlf true "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws crlf false "lf" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws crlf true "lf" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws crlf false "crlf" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul +check_files_in_ws crlf true "crlf" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul + +check_files_in_ws "" false "" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws "" true "" CRLF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws "" input "" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws "" false "auto" $NL CRLF $MIX_CRLF_LF LF_mix_CR CRLF_nul +check_files_in_ws "" true "auto" CRLF CRLF CRLF LF_mix_CR CRLF_nul +check_files_in_ws "" input "auto" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws "" false "text" $NL CRLF $MIX_CRLF_LF $MIX_LF_CR CRLF_nul +check_files_in_ws "" true "text" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul +check_files_in_ws "" input "text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws "" false "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws "" true "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws "" input "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws "" false "lf" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws "" true "lf" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws "" input "lf" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws "" false "crlf" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul +check_files_in_ws "" true "crlf" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul +check_files_in_ws "" input "crlf" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul + +check_files_in_ws native false "" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws native true "" CRLF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws native false "auto" $NL CRLF $MIX_CRLF_LF LF_mix_CR CRLF_nul +check_files_in_ws native true "auto" CRLF CRLF CRLF LF_mix_CR CRLF_nul +check_files_in_ws native false "text" $NL CRLF $MIX_CRLF_LF $MIX_LF_CR CRLF_nul +check_files_in_ws native true "text" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul +check_files_in_ws native false "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws native true "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws native false "lf" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws native true "lf" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws native false "crlf" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul +check_files_in_ws native true "crlf" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul test_done diff --git a/t/t0064-sha1-array.sh b/t/t0064-sha1-array.sh new file mode 100755 index 0000000000..50b31ffe75 --- /dev/null +++ b/t/t0064-sha1-array.sh @@ -0,0 +1,94 @@ +#!/bin/sh + +test_description='basic tests for the SHA1 array implementation' +. ./test-lib.sh + +echo20 () { + prefix="${1:+$1 }" + shift + while test $# -gt 0 + do + echo "$prefix$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1$1" + shift + done +} + +test_expect_success 'ordered enumeration' ' + echo20 "" 44 55 88 aa >expect && + { + echo20 append 88 44 aa 55 && + echo for_each_unique + } | test-sha1-array >actual && + test_cmp expect actual +' + +test_expect_success 'ordered enumeration with duplicate suppression' ' + echo20 "" 44 55 88 aa >expect && + { + echo20 append 88 44 aa 55 && + echo20 append 88 44 aa 55 && + echo for_each_unique + } | test-sha1-array >actual && + test_cmp expect actual +' + +test_expect_success 'lookup' ' + { + echo20 append 88 44 aa 55 && + echo20 lookup 55 + } | test-sha1-array >actual && + n=$(cat actual) && + test "$n" -eq 1 +' + +test_expect_success 'lookup non-existing entry' ' + { + echo20 append 88 44 aa 55 && + echo20 lookup 33 + } | test-sha1-array >actual && + n=$(cat actual) && + test "$n" -lt 0 +' + +test_expect_success 'lookup with duplicates' ' + { + echo20 append 88 44 aa 55 && + echo20 append 88 44 aa 55 && + echo20 lookup 55 + } | test-sha1-array >actual && + n=$(cat actual) && + test "$n" -ge 2 && + test "$n" -le 3 +' + +test_expect_success 'lookup non-existing entry with duplicates' ' + { + echo20 append 88 44 aa 55 && + echo20 append 88 44 aa 55 && + echo20 lookup 66 + } | test-sha1-array >actual && + n=$(cat actual) && + test "$n" -lt 0 +' + +test_expect_success 'lookup with almost duplicate values' ' + { + echo "append 5555555555555555555555555555555555555555" && + echo "append 555555555555555555555555555555555555555f" && + echo20 lookup 55 + } | test-sha1-array >actual && + n=$(cat actual) && + test "$n" -eq 0 +' + +test_expect_success 'lookup with single duplicate value' ' + { + echo20 append 55 55 && + echo20 lookup 55 + } | test-sha1-array >actual && + n=$(cat actual) && + test "$n" -ge 0 && + test "$n" -le 1 +' + +test_done diff --git a/t/t0081-line-buffer.sh b/t/t0081-line-buffer.sh index 25dba008f3..ce92e6acad 100755 --- a/t/t0081-line-buffer.sh +++ b/t/t0081-line-buffer.sh @@ -29,7 +29,7 @@ test_expect_success '0-length read, send along greeting' ' test_cmp expect actual ' -test_expect_success NOT_MINGW 'read from file descriptor' ' +test_expect_success !MINGW 'read from file descriptor' ' rm -f input && echo hello >expect && echo hello >input && diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh index 6c33e28ee8..067f4c6e52 100755 --- a/t/t0090-cache-tree.sh +++ b/t/t0090-cache-tree.sh @@ -8,7 +8,7 @@ cache-tree extension. . ./test-lib.sh cmp_cache_tree () { - test-dump-cache-tree >actual && + test-dump-cache-tree | sed -e '/#(ref)/d' >actual && sed "s/$_x40/SHA/" <actual >filtered && test_cmp "$1" filtered } @@ -16,15 +16,40 @@ cmp_cache_tree () { # We don't bother with actually checking the SHA1: # test-dump-cache-tree already verifies that all existing data is # correct. -test_shallow_cache_tree () { - printf "SHA (%d entries, 0 subtrees)\n" $(git ls-files|wc -l) >expect && +generate_expected_cache_tree_rec () { + dir="$1${1:+/}" && + parent="$2" && + # ls-files might have foo/bar, foo/bar/baz, and foo/bar/quux + # We want to count only foo because it's the only direct child + subtrees=$(git ls-files|grep /|cut -d / -f 1|uniq) && + subtree_count=$(echo "$subtrees"|awk -v c=0 '$1 {++c} END {print c}') && + entries=$(git ls-files|wc -l) && + printf "SHA $dir (%d entries, %d subtrees)\n" "$entries" "$subtree_count" && + for subtree in $subtrees + do + cd "$subtree" + generate_expected_cache_tree_rec "$dir$subtree" "$dir" || return 1 + cd .. + done && + dir=$parent +} + +generate_expected_cache_tree () { + ( + generate_expected_cache_tree_rec + ) +} + +test_cache_tree () { + generate_expected_cache_tree >expect && cmp_cache_tree expect } test_invalid_cache_tree () { - echo "invalid (0 subtrees)" >expect && - printf "SHA #(ref) (%d entries, 0 subtrees)\n" $(git ls-files|wc -l) >>expect && - cmp_cache_tree expect + printf "invalid %s ()\n" "" "$@" >expect && + test-dump-cache-tree | + sed -n -e "s/[0-9]* subtrees//" -e '/#(ref)/d' -e '/^invalid /p' >actual && + test_cmp expect actual } test_no_cache_tree () { @@ -32,26 +57,59 @@ test_no_cache_tree () { cmp_cache_tree expect } -test_expect_failure 'initial commit has cache-tree' ' +test_expect_success 'initial commit has cache-tree' ' test_commit foo && - test_shallow_cache_tree + test_cache_tree ' test_expect_success 'read-tree HEAD establishes cache-tree' ' git read-tree HEAD && - test_shallow_cache_tree + test_cache_tree ' test_expect_success 'git-add invalidates cache-tree' ' test_when_finished "git reset --hard; git read-tree HEAD" && - echo "I changed this file" > foo && + echo "I changed this file" >foo && git add foo && test_invalid_cache_tree ' +test_expect_success 'git-add in subdir invalidates cache-tree' ' + test_when_finished "git reset --hard; git read-tree HEAD" && + mkdir dirx && + echo "I changed this file" >dirx/foo && + git add dirx/foo && + test_invalid_cache_tree +' + +cat >before <<\EOF +SHA (3 entries, 2 subtrees) +SHA dir1/ (1 entries, 0 subtrees) +SHA dir2/ (1 entries, 0 subtrees) +EOF + +cat >expect <<\EOF +invalid (2 subtrees) +invalid dir1/ (0 subtrees) +SHA dir2/ (1 entries, 0 subtrees) +EOF + +test_expect_success 'git-add in subdir does not invalidate sibling cache-tree' ' + git tag no-children && + test_when_finished "git reset --hard no-children; git read-tree HEAD" && + mkdir dir1 dir2 && + test_commit dir1/a && + test_commit dir2/b && + echo "I changed this file" >dir1/a && + cmp_cache_tree before && + echo "I changed this file" >dir1/a && + git add dir1/a && + cmp_cache_tree expect +' + test_expect_success 'update-index invalidates cache-tree' ' test_when_finished "git reset --hard; git read-tree HEAD" && - echo "I changed this file" > foo && + echo "I changed this file" >foo && git update-index --add foo && test_invalid_cache_tree ' @@ -59,7 +117,7 @@ test_expect_success 'update-index invalidates cache-tree' ' test_expect_success 'write-tree establishes cache-tree' ' test-scrap-cache-tree && git write-tree && - test_shallow_cache_tree + test_cache_tree ' test_expect_success 'test-scrap-cache-tree works' ' @@ -70,24 +128,94 @@ test_expect_success 'test-scrap-cache-tree works' ' test_expect_success 'second commit has cache-tree' ' test_commit bar && - test_shallow_cache_tree + test_cache_tree +' + +test_expect_success PERL 'commit --interactive gives cache-tree on partial commit' ' + cat <<-\EOT >foo.c && + int foo() + { + return 42; + } + int bar() + { + return 42; + } + EOT + git add foo.c && + test_invalid_cache_tree && + git commit -m "add a file" && + test_cache_tree && + cat <<-\EOT >foo.c && + int foo() + { + return 43; + } + int bar() + { + return 44; + } + EOT + (echo p; echo 1; echo; echo s; echo n; echo y; echo q) | + git commit --interactive -m foo && + test_cache_tree +' + +test_expect_success 'commit in child dir has cache-tree' ' + mkdir dir && + >dir/child.t && + git add dir/child.t && + git commit -m dir/child.t && + test_cache_tree ' test_expect_success 'reset --hard gives cache-tree' ' test-scrap-cache-tree && git reset --hard && - test_shallow_cache_tree + test_cache_tree ' test_expect_success 'reset --hard without index gives cache-tree' ' rm -f .git/index && git reset --hard && - test_shallow_cache_tree + test_cache_tree ' -test_expect_failure 'checkout gives cache-tree' ' +test_expect_success 'checkout gives cache-tree' ' + git tag current && git checkout HEAD^ && - test_shallow_cache_tree + test_cache_tree +' + +test_expect_success 'checkout -b gives cache-tree' ' + git checkout current && + git checkout -b prev HEAD^ && + test_cache_tree +' + +test_expect_success 'checkout -B gives cache-tree' ' + git checkout current && + git checkout -B prev HEAD^ && + test_cache_tree +' + +test_expect_success 'partial commit gives cache-tree' ' + git checkout -b partial no-children && + test_commit one && + test_commit two && + echo "some change" >one.t && + git add one.t && + echo "some other change" >two.t && + git commit two.t -m partial && + test_cache_tree +' + +test_expect_success 'no phantom error when switching trees' ' + mkdir newdir && + >newdir/one && + git add newdir/one && + git checkout 2>errors && + ! test -s errors ' test_done diff --git a/t/t1014-read-tree-confusing.sh b/t/t1014-read-tree-confusing.sh new file mode 100755 index 0000000000..2f5a25d503 --- /dev/null +++ b/t/t1014-read-tree-confusing.sh @@ -0,0 +1,62 @@ +#!/bin/sh + +test_description='check that read-tree rejects confusing paths' +. ./test-lib.sh + +test_expect_success 'create base tree' ' + echo content >file && + git add file && + git commit -m base && + blob=$(git rev-parse HEAD:file) && + tree=$(git rev-parse HEAD^{tree}) +' + +test_expect_success 'enable core.protectHFS for rejection tests' ' + git config core.protectHFS true +' + +test_expect_success 'enable core.protectNTFS for rejection tests' ' + git config core.protectNTFS true +' + +while read path pretty; do + : ${pretty:=$path} + case "$path" in + *SPACE) + path="${path%SPACE} " + ;; + esac + test_expect_success "reject $pretty at end of path" ' + printf "100644 blob %s\t%s" "$blob" "$path" >tree && + bogus=$(git mktree <tree) && + test_must_fail git read-tree $bogus + ' + + test_expect_success "reject $pretty as subtree" ' + printf "040000 tree %s\t%s" "$tree" "$path" >tree && + bogus=$(git mktree <tree) && + test_must_fail git read-tree $bogus + ' +done <<-EOF +. +.. +.git +.GIT +${u200c}.Git {u200c}.Git +.gI${u200c}T .gI{u200c}T +.GiT${u200c} .GiT{u200c} +git~1 +.git.SPACE .git.{space} +.\\\\.GIT\\\\foobar backslashes +.git\\\\foobar backslashes2 +EOF + +test_expect_success 'utf-8 paths allowed with core.protectHFS off' ' + test_when_finished "git read-tree HEAD" && + test_config core.protectHFS false && + printf "100644 blob %s\t%s" "$blob" ".gi${u200c}t" >tree && + ok=$(git mktree <tree) && + git read-tree $ok +' + +test_done diff --git a/t/t1020-subdirectory.sh b/t/t1020-subdirectory.sh index 62c0d25af4..2edb4f2de5 100755 --- a/t/t1020-subdirectory.sh +++ b/t/t1020-subdirectory.sh @@ -118,7 +118,7 @@ test_expect_success 'alias expansion' ' ) ' -test_expect_success NOT_MINGW '!alias expansion' ' +test_expect_success !MINGW '!alias expansion' ' pwd >expect && ( git config alias.test-alias-directory !pwd && diff --git a/t/t1050-large.sh b/t/t1050-large.sh index aea493646e..f5a9119290 100755 --- a/t/t1050-large.sh +++ b/t/t1050-large.sh @@ -13,7 +13,7 @@ test_expect_success setup ' echo X | dd of=large2 bs=1k seek=2000 && echo X | dd of=large3 bs=1k seek=2000 && echo Y | dd of=huge bs=1k seek=2500 && - GIT_ALLOC_LIMIT=1500 && + GIT_ALLOC_LIMIT=1500k && export GIT_ALLOC_LIMIT ' @@ -112,6 +112,20 @@ test_expect_success 'diff --raw' ' git diff --raw HEAD^ ' +test_expect_success 'diff --stat' ' + git diff --stat HEAD^ HEAD +' + +test_expect_success 'diff' ' + git diff HEAD^ HEAD >actual && + grep "Binary files.*differ" actual +' + +test_expect_success 'diff --cached' ' + git diff --cached HEAD^ >actual && + grep "Binary files.*differ" actual +' + test_expect_success 'hash-object' ' git hash-object large1 ' @@ -163,4 +177,10 @@ test_expect_success 'zip achiving, deflate' ' git archive --format=zip HEAD >/dev/null ' +test_expect_success 'fsck' ' + test_must_fail git fsck 2>err && + n=$(grep "error: attempting to allocate .* over limit" err | wc -l) && + test "$n" -gt 1 +' + test_done diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh index 3f80ff0c14..938fc8bfd7 100755 --- a/t/t1300-repo-config.sh +++ b/t/t1300-repo-config.sh @@ -824,14 +824,14 @@ cat >expect <<\EOF trailingtilde = foo~ EOF -test_expect_success NOT_MINGW 'set --path' ' +test_expect_success !MINGW 'set --path' ' rm -f .git/config && git config --path path.home "~/" && git config --path path.normal "/dev/null" && git config --path path.trailingtilde "foo~" && test_cmp expect .git/config' -if test_have_prereq NOT_MINGW && test "${HOME+set}" +if test_have_prereq !MINGW && test "${HOME+set}" then test_set_prereq HOMEVAR fi @@ -854,7 +854,7 @@ cat >expect <<\EOF foo~ EOF -test_expect_success NOT_MINGW 'get --path copes with unset $HOME' ' +test_expect_success !MINGW 'get --path copes with unset $HOME' ' ( unset HOME; test_must_fail git config --get --path path.home \ @@ -1010,6 +1010,17 @@ test_expect_success 'git -c "key=value" support' ' test_must_fail git -c name=value config core.name ' +# We just need a type-specifier here that cares about the +# distinction internally between a NULL boolean and a real +# string (because most of git's internal parsers do care). +# Using "--path" works, but we do not otherwise care about +# its semantics. +test_expect_success 'git -c can represent empty string' ' + echo >expect && + git -c foo.empty= config --path foo.empty >actual && + test_cmp expect actual +' + test_expect_success 'key sanity-checking' ' test_must_fail git config foo=bar && test_must_fail git config foo=.bar && diff --git a/t/t1303-wacky-config.sh b/t/t1303-wacky-config.sh index 3a2c81968c..3b92083e19 100755 --- a/t/t1303-wacky-config.sh +++ b/t/t1303-wacky-config.sh @@ -111,4 +111,24 @@ test_expect_success 'unset many entries' ' test_must_fail git config section.key ' +test_expect_success '--add appends new value after existing empty value' ' + cat >expect <<-\EOF && + + + fool + roll + EOF + cp .git/config .git/config.old && + test_when_finished "mv .git/config.old .git/config" && + cat >.git/config <<-\EOF && + [foo] + baz + baz = + baz = fool + EOF + git config --add foo.baz roll && + git config --get-all foo.baz >output && + test_cmp expect output +' + test_done diff --git a/t/t1304-default-acl.sh b/t/t1304-default-acl.sh index 79045abb51..f5422f1d33 100755 --- a/t/t1304-default-acl.sh +++ b/t/t1304-default-acl.sh @@ -26,7 +26,7 @@ test_expect_success 'checking for a working acl setup' ' if test -z "$LOGNAME" then - LOGNAME=$USER + LOGNAME="${USER:-$(id -u -n)}" fi check_perms_and_acl () { diff --git a/t/t1308-config-set.sh b/t/t1308-config-set.sh new file mode 100755 index 0000000000..91235b76ba --- /dev/null +++ b/t/t1308-config-set.sh @@ -0,0 +1,221 @@ +#!/bin/sh + +test_description='Test git config-set API in different settings' + +. ./test-lib.sh + +# 'check_config get_* section.key value' verifies that the entry for +# section.key is 'value' +check_config () { + if test "$1" = expect_code + then + expect_code="$2" && shift && shift + else + expect_code=0 + fi && + op=$1 key=$2 && shift && shift && + if test $# != 0 + then + printf "%s\n" "$@" + fi >expect && + test_expect_code $expect_code test-config "$op" "$key" >actual && + test_cmp expect actual +} + +test_expect_success 'setup default config' ' + cat >.git/config <<-\EOF + [case] + penguin = very blue + Movie = BadPhysics + UPPERCASE = true + MixedCase = true + my = + foo + baz = sam + [Cores] + WhatEver = Second + baz = bar + [cores] + baz = bat + [CORES] + baz = ball + [my "Foo bAr"] + hi = mixed-case + [my "FOO BAR"] + hi = upper-case + [my "foo bar"] + hi = lower-case + [case] + baz = bat + baz = hask + [lamb] + chop = 65 + head = none + [goat] + legs = 4 + head = true + skin = false + nose = 1 + horns + EOF +' + +test_expect_success 'get value for a simple key' ' + check_config get_value case.penguin "very blue" +' + +test_expect_success 'get value for a key with value as an empty string' ' + check_config get_value case.my "" +' + +test_expect_success 'get value for a key with value as NULL' ' + check_config get_value case.foo "(NULL)" +' + +test_expect_success 'upper case key' ' + check_config get_value case.UPPERCASE "true" && + check_config get_value case.uppercase "true" +' + +test_expect_success 'mixed case key' ' + check_config get_value case.MixedCase "true" && + check_config get_value case.MIXEDCASE "true" && + check_config get_value case.mixedcase "true" +' + +test_expect_success 'key and value with mixed case' ' + check_config get_value case.Movie "BadPhysics" +' + +test_expect_success 'key with case sensitive subsection' ' + check_config get_value "my.Foo bAr.hi" "mixed-case" && + check_config get_value "my.FOO BAR.hi" "upper-case" && + check_config get_value "my.foo bar.hi" "lower-case" +' + +test_expect_success 'key with case insensitive section header' ' + check_config get_value cores.baz "ball" && + check_config get_value Cores.baz "ball" && + check_config get_value CORES.baz "ball" && + check_config get_value coreS.baz "ball" +' + +test_expect_success 'key with case insensitive section header & variable' ' + check_config get_value CORES.BAZ "ball" && + check_config get_value cores.baz "ball" && + check_config get_value cores.BaZ "ball" && + check_config get_value cOreS.bAz "ball" +' + +test_expect_success 'find value with misspelled key' ' + check_config expect_code 1 get_value "my.fOo Bar.hi" "Value not found for \"my.fOo Bar.hi\"" +' + +test_expect_success 'find value with the highest priority' ' + check_config get_value case.baz "hask" +' + +test_expect_success 'find integer value for a key' ' + check_config get_int lamb.chop 65 +' + +test_expect_success 'find string value for a key' ' + check_config get_string case.baz hask && + check_config expect_code 1 get_string case.ba "Value not found for \"case.ba\"" +' + +test_expect_success 'check line error when NULL string is queried' ' + test_expect_code 128 test-config get_string case.foo 2>result && + test_i18ngrep "fatal: .*case\.foo.*\.git/config.*line 7" result +' + +test_expect_success 'find integer if value is non parse-able' ' + check_config expect_code 128 get_int lamb.head +' + +test_expect_success 'find bool value for the entered key' ' + check_config get_bool goat.head 1 && + check_config get_bool goat.skin 0 && + check_config get_bool goat.nose 1 && + check_config get_bool goat.horns 1 && + check_config get_bool goat.legs 1 +' + +test_expect_success 'find multiple values' ' + check_config get_value_multi case.baz sam bat hask +' + +test_expect_success 'find value from a configset' ' + cat >config2 <<-\EOF && + [case] + baz = lama + [my] + new = silk + [case] + baz = ball + EOF + echo silk >expect && + test-config configset_get_value my.new config2 .git/config >actual && + test_cmp expect actual +' + +test_expect_success 'find value with highest priority from a configset' ' + echo hask >expect && + test-config configset_get_value case.baz config2 .git/config >actual && + test_cmp expect actual +' + +test_expect_success 'find value_list for a key from a configset' ' + cat >except <<-\EOF && + sam + bat + hask + lama + ball + EOF + test-config configset_get_value case.baz config2 .git/config >actual && + test_cmp expect actual +' + +test_expect_success 'proper error on non-existent files' ' + echo "Error (-1) reading configuration file non-existent-file." >expect && + test_expect_code 2 test-config configset_get_value foo.bar non-existent-file 2>actual && + test_cmp expect actual +' + +test_expect_success POSIXPERM,SANITY 'proper error on non-accessible files' ' + chmod -r .git/config && + test_when_finished "chmod +r .git/config" && + echo "Error (-1) reading configuration file .git/config." >expect && + test_expect_code 2 test-config configset_get_value foo.bar .git/config 2>actual && + test_cmp expect actual +' + +test_expect_success 'proper error on error in default config files' ' + cp .git/config .git/config.old && + test_when_finished "mv .git/config.old .git/config" && + echo "[" >>.git/config && + echo "fatal: bad config file line 34 in .git/config" >expect && + test_expect_code 128 test-config get_value foo.bar 2>actual && + test_cmp expect actual +' + +test_expect_success 'proper error on error in custom config files' ' + echo "[" >>syntax-error && + echo "fatal: bad config file line 1 in syntax-error" >expect && + test_expect_code 128 test-config configset_get_value foo.bar syntax-error 2>actual && + test_cmp expect actual +' + +test_expect_success 'check line errors for malformed values' ' + mv .git/config .git/config.old && + test_when_finished "mv .git/config.old .git/config" && + cat >.git/config <<-\EOF && + [alias] + br + EOF + test_expect_code 128 git br 2>result && + test_i18ngrep "fatal: .*alias\.br.*\.git/config.*line 2" result +' + +test_done diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index 0218e96366..7b4707b776 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -110,6 +110,32 @@ test_expect_success "delete symref without dereference when the referred ref is cp -f .git/HEAD.orig .git/HEAD git update-ref -d $m +test_expect_success 'update-ref -d is not confused by self-reference' ' + git symbolic-ref refs/heads/self refs/heads/self && + test_when_finished "rm -f .git/refs/heads/self" && + test_path_is_file .git/refs/heads/self && + test_must_fail git update-ref -d refs/heads/self && + test_path_is_file .git/refs/heads/self +' + +test_expect_success 'update-ref --no-deref -d can delete self-reference' ' + git symbolic-ref refs/heads/self refs/heads/self && + test_when_finished "rm -f .git/refs/heads/self" && + test_path_is_file .git/refs/heads/self && + git update-ref --no-deref -d refs/heads/self && + test_path_is_missing .git/refs/heads/self +' + +test_expect_success 'update-ref --no-deref -d can delete reference to bad ref' ' + >.git/refs/heads/bad && + test_when_finished "rm -f .git/refs/heads/bad" && + git symbolic-ref refs/heads/ref-to-bad refs/heads/bad && + test_when_finished "rm -f .git/refs/heads/ref-to-bad" && + test_path_is_file .git/refs/heads/ref-to-bad && + git update-ref --no-deref -d refs/heads/ref-to-bad && + test_path_is_missing .git/refs/heads/ref-to-bad +' + test_expect_success '(not) create HEAD with old sha1' " test_must_fail git update-ref HEAD $A $B " @@ -374,12 +400,6 @@ test_expect_success 'stdin fails create with no ref' ' grep "fatal: create: missing <ref>" err ' -test_expect_success 'stdin fails create with bad ref name' ' - echo "create ~a $m" >stdin && - test_must_fail git update-ref --stdin <stdin 2>err && - grep "fatal: invalid ref format: ~a" err -' - test_expect_success 'stdin fails create with no new value' ' echo "create $a" >stdin && test_must_fail git update-ref --stdin <stdin 2>err && @@ -398,12 +418,6 @@ test_expect_success 'stdin fails update with no ref' ' grep "fatal: update: missing <ref>" err ' -test_expect_success 'stdin fails update with bad ref name' ' - echo "update ~a $m" >stdin && - test_must_fail git update-ref --stdin <stdin 2>err && - grep "fatal: invalid ref format: ~a" err -' - test_expect_success 'stdin fails update with no new value' ' echo "update $a" >stdin && test_must_fail git update-ref --stdin <stdin 2>err && @@ -422,12 +436,6 @@ test_expect_success 'stdin fails delete with no ref' ' grep "fatal: delete: missing <ref>" err ' -test_expect_success 'stdin fails delete with bad ref name' ' - echo "delete ~a $m" >stdin && - test_must_fail git update-ref --stdin <stdin 2>err && - grep "fatal: invalid ref format: ~a" err -' - test_expect_success 'stdin fails delete with too many arguments' ' echo "delete $a $m $m" >stdin && test_must_fail git update-ref --stdin <stdin 2>err && @@ -700,12 +708,6 @@ test_expect_success 'stdin -z fails create with no ref' ' grep "fatal: create: missing <ref>" err ' -test_expect_success 'stdin -z fails create with bad ref name' ' - printf $F "create ~a " "$m" >stdin && - test_must_fail git update-ref -z --stdin <stdin 2>err && - grep "fatal: invalid ref format: ~a " err -' - test_expect_success 'stdin -z fails create with no new value' ' printf $F "create $a" >stdin && test_must_fail git update-ref -z --stdin <stdin 2>err && @@ -730,12 +732,6 @@ test_expect_success 'stdin -z fails update with too few args' ' grep "fatal: update $a: unexpected end of input when reading <oldvalue>" err ' -test_expect_success 'stdin -z fails update with bad ref name' ' - printf $F "update ~a" "$m" "" >stdin && - test_must_fail git update-ref -z --stdin <stdin 2>err && - grep "fatal: invalid ref format: ~a" err -' - test_expect_success 'stdin -z emits warning with empty new value' ' git update-ref $a $m && printf $F "update $a" "" "" >stdin && @@ -768,12 +764,6 @@ test_expect_success 'stdin -z fails delete with no ref' ' grep "fatal: delete: missing <ref>" err ' -test_expect_success 'stdin -z fails delete with bad ref name' ' - printf $F "delete ~a" "$m" >stdin && - test_must_fail git update-ref -z --stdin <stdin 2>err && - grep "fatal: invalid ref format: ~a" err -' - test_expect_success 'stdin -z fails delete with no old value' ' printf $F "delete $a" >stdin && test_must_fail git update-ref -z --stdin <stdin 2>err && diff --git a/t/t1402-check-ref-format.sh b/t/t1402-check-ref-format.sh index 4bc7141226..e5dc62e9ef 100755 --- a/t/t1402-check-ref-format.sh +++ b/t/t1402-check-ref-format.sh @@ -7,7 +7,7 @@ test_description='Test git check-ref-format' valid_ref() { prereq= case $1 in - [A-Z]*) + [A-Z!]*) prereq=$1 shift esac @@ -19,7 +19,7 @@ valid_ref() { invalid_ref() { prereq= case $1 in - [A-Z]*) + [A-Z!]*) prereq=$1 shift esac @@ -30,17 +30,17 @@ invalid_ref() { } invalid_ref '' -invalid_ref NOT_MINGW '/' -invalid_ref NOT_MINGW '/' --allow-onelevel -invalid_ref NOT_MINGW '/' --normalize -invalid_ref NOT_MINGW '/' '--allow-onelevel --normalize' +invalid_ref !MINGW '/' +invalid_ref !MINGW '/' --allow-onelevel +invalid_ref !MINGW '/' --normalize +invalid_ref !MINGW '/' '--allow-onelevel --normalize' valid_ref 'foo/bar/baz' 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 !MINGW '/heads/foo' +valid_ref !MINGW '/heads/foo' --normalize invalid_ref '///heads/foo' valid_ref '///heads/foo' --normalize invalid_ref './foo' @@ -120,14 +120,14 @@ 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' +invalid_ref !MINGW "$ref" +invalid_ref !MINGW "$ref" --allow-onelevel +invalid_ref !MINGW "$ref" --refspec-pattern +invalid_ref !MINGW "$ref" '--refspec-pattern --allow-onelevel' +invalid_ref !MINGW "$ref" --normalize +valid_ref !MINGW "$ref" '--allow-onelevel --normalize' +invalid_ref !MINGW "$ref" '--refspec-pattern --normalize' +valid_ref !MINGW "$ref" '--refspec-pattern --allow-onelevel --normalize' test_expect_success "check-ref-format --branch @{-1}" ' T=$(git write-tree) && @@ -162,7 +162,7 @@ test_expect_success 'check-ref-format --branch from subdir' ' valid_ref_normalized() { prereq= case $1 in - [A-Z]*) + [A-Z!]*) prereq=$1 shift esac @@ -174,7 +174,7 @@ valid_ref_normalized() { invalid_ref_normalized() { prereq= case $1 in - [A-Z]*) + [A-Z!]*) prereq=$1 shift esac @@ -185,10 +185,10 @@ invalid_ref_normalized() { 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 !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 !MINGW '/foo' invalid_ref_normalized 'heads/foo/../bar' invalid_ref_normalized 'heads/./foo' invalid_ref_normalized 'heads\foo' diff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh index 8cab06f90a..779d4e3829 100755 --- a/t/t1410-reflog.sh +++ b/t/t1410-reflog.sh @@ -253,4 +253,68 @@ test_expect_success 'checkout should not delete log for packed ref' ' test $(git reflog master | wc -l) = 4 ' +test_expect_success 'stale dirs do not cause d/f conflicts (reflogs on)' ' + test_when_finished "git branch -d one || git branch -d one/two" && + + git branch one/two master && + echo "one/two@{0} branch: Created from master" >expect && + git log -g --format="%gd %gs" one/two >actual && + test_cmp expect actual && + git branch -d one/two && + + # now logs/refs/heads/one is a stale directory, but + # we should move it out of the way to create "one" reflog + git branch one master && + echo "one@{0} branch: Created from master" >expect && + git log -g --format="%gd %gs" one >actual && + test_cmp expect actual +' + +test_expect_success 'stale dirs do not cause d/f conflicts (reflogs off)' ' + test_when_finished "git branch -d one || git branch -d one/two" && + + git branch one/two master && + echo "one/two@{0} branch: Created from master" >expect && + git log -g --format="%gd %gs" one/two >actual && + test_cmp expect actual && + git branch -d one/two && + + # same as before, but we only create a reflog for "one" if + # it already exists, which it does not + git -c core.logallrefupdates=false branch one master && + : >expect && + git log -g --format="%gd %gs" one >actual && + test_cmp expect actual +' + +# Triggering the bug detected by this test requires a newline to fall +# exactly BUFSIZ-1 bytes from the end of the file. We don't know +# what that value is, since it's platform dependent. However, if +# we choose some value N, we also catch any D which divides N evenly +# (since we will read backwards in chunks of D). So we choose 8K, +# which catches glibc (with an 8K BUFSIZ) and *BSD (1K). +# +# Each line is 114 characters, so we need 75 to still have a few before the +# last 8K. The 89-character padding on the final entry lines up our +# newline exactly. +test_expect_success 'parsing reverse reflogs at BUFSIZ boundaries' ' + git checkout -b reflogskip && + z38=00000000000000000000000000000000000000 && + ident="abc <xyz> 0000000001 +0000" && + for i in $(test_seq 1 75); do + printf "$z38%02d $z38%02d %s\t" $i $(($i+1)) "$ident" && + if test $i = 75; then + for j in $(test_seq 1 89); do + printf X + done + else + printf X + fi && + printf "\n" + done >.git/logs/refs/heads/reflogskip && + git rev-parse reflogskip@{73} >actual && + echo ${z38}03 >expect && + test_cmp expect actual +' + test_done diff --git a/t/t1413-reflog-detach.sh b/t/t1413-reflog-detach.sh new file mode 100755 index 0000000000..c730600d8a --- /dev/null +++ b/t/t1413-reflog-detach.sh @@ -0,0 +1,70 @@ +#!/bin/sh + +test_description='Test reflog interaction with detached HEAD' +. ./test-lib.sh + +reset_state () { + git checkout master && + cp saved_reflog .git/logs/HEAD +} + +test_expect_success setup ' + test_tick && + git commit --allow-empty -m initial && + git branch side && + test_tick && + git commit --allow-empty -m second && + cat .git/logs/HEAD >saved_reflog +' + +test_expect_success baseline ' + reset_state && + git rev-parse master master^ >expect && + git log -g --format=%H >actual && + test_cmp expect actual +' + +test_expect_success 'switch to branch' ' + reset_state && + git rev-parse side master master^ >expect && + git checkout side && + git log -g --format=%H >actual && + test_cmp expect actual +' + +test_expect_success 'detach to other' ' + reset_state && + git rev-parse master side master master^ >expect && + git checkout side && + git checkout master^0 && + git log -g --format=%H >actual && + test_cmp expect actual +' + +test_expect_success 'detach to self' ' + reset_state && + git rev-parse master master master^ >expect && + git checkout master^0 && + git log -g --format=%H >actual && + test_cmp expect actual +' + +test_expect_success 'attach to self' ' + reset_state && + git rev-parse master master master master^ >expect && + git checkout master^0 && + git checkout master && + git log -g --format=%H >actual && + test_cmp expect actual +' + +test_expect_success 'attach to other' ' + reset_state && + git rev-parse side master master master^ >expect && + git checkout master^0 && + git checkout side && + git log -g --format=%H >actual && + test_cmp expect actual +' + +test_done diff --git a/t/t1430-bad-ref-name.sh b/t/t1430-bad-ref-name.sh new file mode 100755 index 0000000000..468e85621a --- /dev/null +++ b/t/t1430-bad-ref-name.sh @@ -0,0 +1,207 @@ +#!/bin/sh + +test_description='Test handling of ref names that check-ref-format rejects' +. ./test-lib.sh + +test_expect_success setup ' + test_commit one && + test_commit two +' + +test_expect_success 'fast-import: fail on invalid branch name ".badbranchname"' ' + test_when_finished "rm -f .git/objects/pack_* .git/objects/index_*" && + cat >input <<-INPUT_END && + commit .badbranchname + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + data <<COMMIT + corrupt + COMMIT + + from refs/heads/master + + INPUT_END + test_must_fail git fast-import <input +' + +test_expect_success 'fast-import: fail on invalid branch name "bad[branch]name"' ' + test_when_finished "rm -f .git/objects/pack_* .git/objects/index_*" && + cat >input <<-INPUT_END && + commit bad[branch]name + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + data <<COMMIT + corrupt + COMMIT + + from refs/heads/master + + INPUT_END + test_must_fail git fast-import <input +' + +test_expect_success 'git branch shows badly named ref' ' + cp .git/refs/heads/master .git/refs/heads/broken...ref && + test_when_finished "rm -f .git/refs/heads/broken...ref" && + git branch >output && + grep -e "broken\.\.\.ref" output +' + +test_expect_success 'branch -d can delete badly named ref' ' + cp .git/refs/heads/master .git/refs/heads/broken...ref && + test_when_finished "rm -f .git/refs/heads/broken...ref" && + git branch -d broken...ref && + git branch >output && + ! grep -e "broken\.\.\.ref" output +' + +test_expect_success 'branch -D can delete badly named ref' ' + cp .git/refs/heads/master .git/refs/heads/broken...ref && + test_when_finished "rm -f .git/refs/heads/broken...ref" && + git branch -D broken...ref && + git branch >output && + ! grep -e "broken\.\.\.ref" output +' + +test_expect_success 'branch -D cannot delete non-ref in .git dir' ' + echo precious >.git/my-private-file && + echo precious >expect && + test_must_fail git branch -D ../../my-private-file && + test_cmp expect .git/my-private-file +' + +test_expect_success 'branch -D cannot delete absolute path' ' + git branch -f extra && + test_must_fail git branch -D "$(pwd)/.git/refs/heads/extra" && + test_cmp_rev HEAD extra +' + +test_expect_success 'git branch cannot create a badly named ref' ' + test_when_finished "rm -f .git/refs/heads/broken...ref" && + test_must_fail git branch broken...ref && + git branch >output && + ! grep -e "broken\.\.\.ref" output +' + +test_expect_success 'branch -m cannot rename to a bad ref name' ' + test_when_finished "rm -f .git/refs/heads/broken...ref" && + test_might_fail git branch -D goodref && + git branch goodref && + test_must_fail git branch -m goodref broken...ref && + test_cmp_rev master goodref && + git branch >output && + ! grep -e "broken\.\.\.ref" output +' + +test_expect_failure 'branch -m can rename from a bad ref name' ' + cp .git/refs/heads/master .git/refs/heads/broken...ref && + test_when_finished "rm -f .git/refs/heads/broken...ref" && + git branch -m broken...ref renamed && + test_cmp_rev master renamed && + git branch >output && + ! grep -e "broken\.\.\.ref" output +' + +test_expect_success 'push cannot create a badly named ref' ' + test_when_finished "rm -f .git/refs/heads/broken...ref" && + test_must_fail git push "file://$(pwd)" HEAD:refs/heads/broken...ref && + git branch >output && + ! grep -e "broken\.\.\.ref" output +' + +test_expect_failure 'push --mirror can delete badly named ref' ' + top=$(pwd) && + git init src && + git init dest && + + ( + cd src && + test_commit one + ) && + ( + cd dest && + test_commit two && + git checkout --detach && + cp .git/refs/heads/master .git/refs/heads/broken...ref + ) && + git -C src push --mirror "file://$top/dest" && + git -C dest branch >output && + ! grep -e "broken\.\.\.ref" output +' + +test_expect_success 'rev-parse skips symref pointing to broken name' ' + test_when_finished "rm -f .git/refs/heads/broken...ref" && + git branch shadow one && + cp .git/refs/heads/master .git/refs/heads/broken...ref && + git symbolic-ref refs/tags/shadow refs/heads/broken...ref && + + git rev-parse --verify one >expect && + git rev-parse --verify shadow >actual 2>err && + test_cmp expect actual && + test_i18ngrep "ignoring.*refs/tags/shadow" err +' + +test_expect_success 'update-ref --no-deref -d can delete reference to broken name' ' + git symbolic-ref refs/heads/badname refs/heads/broken...ref && + test_when_finished "rm -f .git/refs/heads/badname" && + test_path_is_file .git/refs/heads/badname && + git update-ref --no-deref -d refs/heads/badname && + test_path_is_missing .git/refs/heads/badname +' + +test_expect_success 'update-ref -d can delete broken name' ' + cp .git/refs/heads/master .git/refs/heads/broken...ref && + test_when_finished "rm -f .git/refs/heads/broken...ref" && + git update-ref -d refs/heads/broken...ref && + git branch >output && + ! grep -e "broken\.\.\.ref" output +' + +test_expect_success 'update-ref -d cannot delete non-ref in .git dir' ' + echo precious >.git/my-private-file && + echo precious >expect && + test_must_fail git update-ref -d my-private-file && + test_cmp expect .git/my-private-file +' + +test_expect_success 'update-ref -d cannot delete absolute path' ' + git branch -f extra && + test_must_fail git update-ref -d "$(pwd)/.git/refs/heads/extra" && + test_cmp_rev HEAD extra +' + +test_expect_success 'update-ref --stdin fails create with bad ref name' ' + echo "create ~a refs/heads/master" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: invalid ref format: ~a" err +' + +test_expect_success 'update-ref --stdin fails update with bad ref name' ' + echo "update ~a refs/heads/master" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: invalid ref format: ~a" err +' + +test_expect_success 'update-ref --stdin fails delete with bad ref name' ' + echo "delete ~a refs/heads/master" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: invalid ref format: ~a" err +' + +test_expect_success 'update-ref --stdin -z fails create with bad ref name' ' + printf "%s\0" "create ~a " refs/heads/master >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: invalid ref format: ~a " err +' + +test_expect_success 'update-ref --stdin -z fails update with bad ref name' ' + printf "%s\0" "update ~a" refs/heads/master "" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: invalid ref format: ~a" err +' + +test_expect_success 'update-ref --stdin -z fails delete with bad ref name' ' + printf "%s\0" "delete ~a" refs/heads/master >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: invalid ref format: ~a" err +' + +test_done diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index 8c739c9613..793aee9f0b 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -69,7 +69,7 @@ test_expect_success 'object with bad sha1' ' git update-ref refs/heads/bogus $cmt && test_when_finished "git update-ref -d refs/heads/bogus" && - test_might_fail git fsck 2>out && + test_must_fail git fsck 2>out && cat out && grep "$sha.*corrupt" out ' @@ -101,7 +101,7 @@ test_expect_success 'email with embedded > is not okay' ' 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 && + test_must_fail git fsck 2>out && cat out && grep "error in commit $new" out ' @@ -113,7 +113,7 @@ test_expect_success 'missing < email delimiter is reported nicely' ' 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 && + test_must_fail git fsck 2>out && cat out && grep "error in commit $new.* - bad name" out ' @@ -125,7 +125,7 @@ test_expect_success 'missing email is reported nicely' ' 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 && + test_must_fail git fsck 2>out && cat out && grep "error in commit $new.* - missing email" out ' @@ -137,7 +137,7 @@ test_expect_success '> in name is reported' ' 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 && + test_must_fail git fsck 2>out && cat out && grep "error in commit $new" out ' @@ -151,11 +151,31 @@ test_expect_success 'integer overflow in timestamps is reported' ' 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 && + test_must_fail git fsck 2>out && cat out && grep "error in commit $new.*integer overflow" out ' +test_expect_success 'malformatted tree object' ' + test_when_finished "git update-ref -d refs/tags/wrong" && + test_when_finished "remove_object \$T" && + T=$( + GIT_INDEX_FILE=test-index && + export GIT_INDEX_FILE && + rm -f test-index && + >x && + git add x && + T=$(git write-tree) && + ( + git cat-file tree $T && + git cat-file tree $T + ) | + git hash-object -w -t tree --stdin + ) && + test_must_fail git fsck 2>out && + grep "error in tree .*contains duplicate file entries" out +' + test_expect_success 'tag pointing to nonexistent' ' cat >invalid-tag <<-\EOF && object ffffffffffffffffffffffffffffffffffffffff @@ -194,6 +214,44 @@ test_expect_success 'tag pointing to something else than its type' ' test_must_fail git fsck --tags ' +test_expect_success 'tag with incorrect tag name & missing tagger' ' + sha=$(git rev-parse HEAD) && + cat >wrong-tag <<-EOF && + object $sha + type commit + tag wrong name format + + This is an invalid tag. + EOF + + tag=$(git hash-object -t tag -w --stdin <wrong-tag) && + test_when_finished "remove_object $tag" && + echo $tag >.git/refs/tags/wrong && + test_when_finished "git update-ref -d refs/tags/wrong" && + git fsck --tags 2>out && + grep "invalid .tag. name" out && + grep "expected .tagger. line" out +' + +test_expect_success 'tag with bad tagger' ' + sha=$(git rev-parse HEAD) && + cat >wrong-tag <<-EOF && + object $sha + type commit + tag not-quite-wrong + tagger Bad Tagger Name + + This is an invalid tag. + EOF + + tag=$(git hash-object --literally -t tag -w --stdin <wrong-tag) && + test_when_finished "remove_object $tag" && + echo $tag >.git/refs/tags/wrong && + test_when_finished "git update-ref -d refs/tags/wrong" && + test_must_fail git fsck --tags 2>out && + grep "error in tag .*: invalid author/committer" out +' + test_expect_success 'cleaned up' ' git fsck >actual 2>&1 && test_cmp empty actual @@ -251,35 +309,111 @@ test_expect_success 'fsck notices submodule entry pointing to null sha1' ' ) ' -test_expect_success 'fsck notices "." and ".." in trees' ' +while read name path pretty; do + while read mode type; do + : ${pretty:=$path} + test_expect_success "fsck notices $pretty as $type" ' + ( + git init $name-$type && + cd $name-$type && + echo content >file && + git add file && + git commit -m base && + blob=$(git rev-parse :file) && + tree=$(git rev-parse HEAD^{tree}) && + value=$(eval "echo \$$type") && + printf "$mode $type %s\t%s" "$value" "$path" >bad && + bad_tree=$(git mktree <bad) && + git fsck 2>out && + cat out && + grep "warning.*tree $bad_tree" out + )' + done <<-\EOF + 100644 blob + 040000 tree + EOF +done <<-EOF +dot . +dotdot .. +dotgit .git +dotgit-case .GIT +dotgit-unicode .gI${u200c}T .gI{u200c}T +dotgit-case2 .Git +git-tilde1 git~1 +dotgitdot .git. +dot-backslash-case .\\\\.GIT\\\\foobar +dotgit-case-backslash .git\\\\foobar +EOF + +test_expect_success 'fsck allows .Ňit' ' ( - git init dots && - cd dots && - blob=$(echo foo | git hash-object -w --stdin) && - tab=$(printf "\\t") && - git mktree <<-EOF && - 100644 blob $blob$tab. - 100644 blob $blob$tab.. - EOF - git fsck 2>out && - cat out && - grep "warning.*\\." out + git init not-dotgit && + cd not-dotgit && + echo content >file && + git add file && + git commit -m base && + blob=$(git rev-parse :file) && + printf "100644 blob $blob\t.\\305\\207it" >tree && + tree=$(git mktree <tree) && + git fsck 2>err && + test_line_count = 0 err ) ' -test_expect_success 'fsck notices ".git" in trees' ' +# create a static test repo which is broken by omitting +# one particular object ($1, which is looked up via rev-parse +# in the new repository). +create_repo_missing () { + rm -rf missing && + git init missing && ( - git init dotgit && - cd dotgit && - blob=$(echo foo | git hash-object -w --stdin) && - tab=$(printf "\\t") && - git mktree <<-EOF && - 100644 blob $blob$tab.git - EOF - git fsck 2>out && - cat out && - grep "warning.*\\.git" out + cd missing && + git commit -m one --allow-empty && + mkdir subdir && + echo content >subdir/file && + git add subdir/file && + git commit -m two && + unrelated=$(echo unrelated | git hash-object --stdin -w) && + git tag -m foo tag $unrelated && + sha1=$(git rev-parse --verify "$1") && + path=$(echo $sha1 | sed 's|..|&/|') && + rm .git/objects/$path ) +} + +test_expect_success 'fsck notices missing blob' ' + create_repo_missing HEAD:subdir/file && + test_must_fail git -C missing fsck +' + +test_expect_success 'fsck notices missing subtree' ' + create_repo_missing HEAD:subdir && + test_must_fail git -C missing fsck +' + +test_expect_success 'fsck notices missing root tree' ' + create_repo_missing HEAD^{tree} && + test_must_fail git -C missing fsck +' + +test_expect_success 'fsck notices missing parent' ' + create_repo_missing HEAD^ && + test_must_fail git -C missing fsck +' + +test_expect_success 'fsck notices missing tagged object' ' + create_repo_missing tag^{blob} && + test_must_fail git -C missing fsck +' + +test_expect_success 'fsck notices ref pointing to missing commit' ' + create_repo_missing HEAD && + test_must_fail git -C missing fsck +' + +test_expect_success 'fsck notices ref pointing to missing tag' ' + create_repo_missing tag && + test_must_fail git -C missing fsck ' test_done diff --git a/t/t1502-rev-parse-parseopt.sh b/t/t1502-rev-parse-parseopt.sh index 922423e7d0..ebe7c3b87c 100755 --- a/t/t1502-rev-parse-parseopt.sh +++ b/t/t1502-rev-parse-parseopt.sh @@ -19,7 +19,7 @@ sed -e 's/^|//' >expect <<\END_EXPECT | -d, --data[=...] short and long option with an optional argument | |Argument hints -| -b <arg> short option required argument +| -B <arg> short option required argument | --bar2 <arg> long option required argument | -e, --fuz <with-space> | short and long option required argument @@ -51,7 +51,7 @@ sed -e 's/^|//' >optionspec <<\EOF |d,data? short and long option with an optional argument | | Argument hints -|b=arg short option required argument +|B=arg short option required argument |bar2=arg long option required argument |e,fuz=with-space short and long option required argument |s?some short option optional argument diff --git a/t/t1503-rev-parse-verify.sh b/t/t1503-rev-parse-verify.sh index 813cc1b3e2..823fe1d799 100755 --- a/t/t1503-rev-parse-verify.sh +++ b/t/t1503-rev-parse-verify.sh @@ -72,15 +72,42 @@ test_expect_success 'fails with any bad rev or many good revs' ' test_expect_success 'fails silently when using -q' ' test_must_fail git rev-parse --verify --quiet 2>error && - test -z "$(cat error)" && + test_must_be_empty error && test_must_fail git rev-parse -q --verify foo 2>error && - test -z "$(cat error)" && + test_must_be_empty error && test_must_fail git rev-parse --verify -q HEAD bar 2>error && - test -z "$(cat error)" && + test_must_be_empty error && test_must_fail git rev-parse --quiet --verify baz HEAD 2>error && - test -z "$(cat error)" && + test_must_be_empty error && test_must_fail git rev-parse -q --verify $HASH2 HEAD 2>error && - test -z "$(cat error)" + test_must_be_empty error +' + +test_expect_success 'fails silently when using -q with deleted reflogs' ' + ref=$(git rev-parse HEAD) && + : >.git/logs/refs/test && + git update-ref -m "message for refs/test" refs/test "$ref" && + git reflog delete --updateref --rewrite refs/test@{0} && + test_must_fail git rev-parse -q --verify refs/test@{0} >error 2>&1 && + test_must_be_empty error +' + +test_expect_success 'fails silently when using -q with not enough reflogs' ' + ref=$(git rev-parse HEAD) && + : >.git/logs/refs/test2 && + git update-ref -m "message for refs/test2" refs/test2 "$ref" && + test_must_fail git rev-parse -q --verify refs/test2@{999} >error 2>&1 && + test_must_be_empty error +' + +test_expect_success 'succeeds silently with -q and reflogs that do not go far back enough in time' ' + ref=$(git rev-parse HEAD) && + : >.git/logs/refs/test3 && + git update-ref -m "message for refs/test3" refs/test3 "$ref" && + git rev-parse -q --verify refs/test3@{1.year.ago} >actual 2>error && + test_must_be_empty error && + echo "$ref" >expect && + test_cmp expect actual ' test_expect_success 'no stdout output on error' ' diff --git a/t/t2022-checkout-paths.sh b/t/t2022-checkout-paths.sh index 8e3545d868..f46d0499bc 100755 --- a/t/t2022-checkout-paths.sh +++ b/t/t2022-checkout-paths.sh @@ -61,4 +61,21 @@ test_expect_success 'do not touch unmerged entries matching $path but not in $tr test_cmp expect.next0 actual.next0 ' +test_expect_success 'do not touch files that are already up-to-date' ' + git reset --hard && + echo one >file1 && + echo two >file2 && + git add file1 file2 && + git commit -m base && + echo modified >file1 && + test-chmtime =1000000000 file2 && + git update-index -q --refresh && + git checkout HEAD -- file1 file2 && + echo one >expect && + test_cmp expect file1 && + echo "1000000000 file2" >expect && + test-chmtime -v +0 file2 >actual && + test_cmp expect actual +' + test_done diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh index ac31b711f2..432921b6b8 100755 --- a/t/t3200-branch.sh +++ b/t/t3200-branch.sh @@ -285,6 +285,15 @@ test_expect_success 'deleting a dangling symref' ' test_i18ncmp expect actual ' +test_expect_success 'deleting a self-referential symref' ' + git symbolic-ref refs/heads/self-reference refs/heads/self-reference && + test_path_is_file .git/refs/heads/self-reference && + echo "Deleted branch self-reference (was refs/heads/self-reference)." >expect && + git branch -d self-reference >actual && + test_path_is_missing .git/refs/heads/self-reference && + test_i18ncmp expect actual +' + 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 && diff --git a/t/t3201-branch-contains.sh b/t/t3201-branch-contains.sh index 141b0611ea..912a6635a8 100755 --- a/t/t3201-branch-contains.sh +++ b/t/t3201-branch-contains.sh @@ -130,4 +130,33 @@ test_expect_success 'implicit --list conflicts with modification options' ' ' +# We want to set up a case where the walk for the tracking info +# of one branch crosses the tip of another branch (and make sure +# that the latter walk does not mess up our flag to see if it was +# merged). +# +# Here "topic" tracks "master" with one extra commit, and "zzz" points to the +# same tip as master The name "zzz" must come alphabetically after "topic" +# as we process them in that order. +test_expect_success 'branch --merged with --verbose' ' + git branch --track topic master && + git branch zzz topic && + git checkout topic && + test_commit foo && + git branch --merged topic >actual && + cat >expect <<-\EOF && + master + * topic + zzz + EOF + test_cmp expect actual && + git branch --verbose --merged topic >actual && + cat >expect <<-\EOF && + master c77a0a9 second on master + * topic 2c939f4 [ahead 1] foo + zzz c77a0a9 second on master + EOF + test_cmp expect actual +' + test_done diff --git a/t/t3210-pack-refs.sh b/t/t3210-pack-refs.sh index 1a2080e3dc..aa9eb3a3e5 100755 --- a/t/t3210-pack-refs.sh +++ b/t/t3210-pack-refs.sh @@ -11,7 +11,9 @@ semantic is still the same. ' . ./test-lib.sh -echo '[core] logallrefupdates = true' >>.git/config +test_expect_success 'enable reflogs' ' + git config core.logallrefupdates true +' test_expect_success \ 'prepare a trivial repository' \ @@ -151,4 +153,38 @@ test_expect_success 'delete ref while another dangling packed ref' ' test_cmp /dev/null result ' +test_expect_success 'pack ref directly below refs/' ' + git update-ref refs/top HEAD && + git pack-refs --all --prune && + grep refs/top .git/packed-refs && + test_path_is_missing .git/refs/top +' + +test_expect_success 'disable reflogs' ' + git config core.logallrefupdates false && + rm -rf .git/logs +' + +test_expect_success 'create packed foo/bar/baz branch' ' + git branch foo/bar/baz && + git pack-refs --all --prune && + test_path_is_missing .git/refs/heads/foo/bar/baz && + test_path_is_missing .git/logs/refs/heads/foo/bar/baz +' + +test_expect_success 'notice d/f conflict with existing directory' ' + test_must_fail git branch foo && + test_must_fail git branch foo/bar +' + +test_expect_success 'existing directory reports concrete ref' ' + test_must_fail git branch foo 2>stderr && + grep refs/heads/foo/bar/baz stderr +' + +test_expect_success 'notice d/f conflict with existing ref' ' + test_must_fail git branch foo/bar/baz/extra && + test_must_fail git branch foo/bar/baz/lots/of/extra/components +' + test_done diff --git a/t/t3302-notes-index-expensive.sh b/t/t3302-notes-index-expensive.sh index 8d44e04354..7217c5e222 100755 --- a/t/t3302-notes-index-expensive.sh +++ b/t/t3302-notes-index-expensive.sh @@ -7,8 +7,6 @@ test_description='Test commit notes index (expensive!)' . ./test-lib.sh -test -n "$GIT_NOTES_TIMING_TESTS" && test_set_prereq EXPENSIVE - create_repo () { number_of_commits=$1 nr=0 diff --git a/t/t3419-rebase-patch-id.sh b/t/t3419-rebase-patch-id.sh index 9292b499f3..217dd79b2e 100755 --- a/t/t3419-rebase-patch-id.sh +++ b/t/t3419-rebase-patch-id.sh @@ -4,8 +4,6 @@ test_description='git rebase - test patch id computation' . ./test-lib.sh -test -n "$GIT_PATCHID_TIMING_TESTS" && test_set_prereq EXPENSIVE - count () { i=0 while test $i -lt $1 diff --git a/t/t3901-i18n-patch.sh b/t/t3901-i18n-patch.sh index 55c8a2f576..a392f3d1d6 100755 --- a/t/t3901-i18n-patch.sh +++ b/t/t3901-i18n-patch.sh @@ -54,7 +54,7 @@ test_expect_success setup ' git add yours && git commit -s -m "Second on side" && - if test_have_prereq NOT_MINGW + if test_have_prereq !MINGW then # the second one on the side branch is ISO-8859-1 git config i18n.commitencoding ISO8859-1 && @@ -122,7 +122,7 @@ test_expect_success 'rebase (U/L)' ' check_encoding 2 ' -test_expect_success NOT_MINGW 'rebase (L/L)' ' +test_expect_success !MINGW 'rebase (L/L)' ' # In this test we want ISO-8859-1 encoded commits as the result git config i18n.commitencoding ISO8859-1 && git config i18n.logoutputencoding ISO8859-1 && @@ -134,7 +134,7 @@ test_expect_success NOT_MINGW 'rebase (L/L)' ' check_encoding 2 8859 ' -test_expect_success NOT_MINGW 'rebase (L/U)' ' +test_expect_success !MINGW 'rebase (L/U)' ' # This is pathological -- use UTF-8 as intermediate form # to get ISO-8859-1 results. git config i18n.commitencoding ISO8859-1 && @@ -162,7 +162,7 @@ test_expect_success 'cherry-pick(U/U)' ' check_encoding 3 ' -test_expect_success NOT_MINGW 'cherry-pick(L/L)' ' +test_expect_success !MINGW 'cherry-pick(L/L)' ' # Both the commitencoding and logoutputencoding is set to ISO-8859-1 git config i18n.commitencoding ISO8859-1 && @@ -192,7 +192,7 @@ test_expect_success 'cherry-pick(U/L)' ' check_encoding 3 ' -test_expect_success NOT_MINGW 'cherry-pick(L/U)' ' +test_expect_success !MINGW 'cherry-pick(L/U)' ' # Again, the commitencoding is set to ISO-8859-1 but # logoutputencoding is set to UTF-8. diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh index 5b79b216e2..1e29962fad 100755 --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@ -685,4 +685,46 @@ test_expect_success 'handle stash specification with spaces' ' grep pig file ' +test_expect_success 'setup stash with index and worktree changes' ' + git stash clear && + git reset --hard && + echo index >file && + git add file && + echo working >file && + git stash +' + +test_expect_success 'stash list implies --first-parent -m' ' + cat >expect <<-\EOF && + stash@{0}: WIP on master: b27a2bc subdir + + diff --git a/file b/file + index 257cc56..d26b33d 100644 + --- a/file + +++ b/file + @@ -1 +1 @@ + -foo + +working + EOF + git stash list -p >actual && + test_cmp expect actual +' + +test_expect_success 'stash list --cc shows combined diff' ' + cat >expect <<-\EOF && + stash@{0}: WIP on master: b27a2bc subdir + + diff --cc file + index 257cc56,9015a7a..d26b33d + --- a/file + +++ b/file + @@@ -1,1 -1,1 +1,1 @@@ + - foo + -index + ++working + EOF + git stash list -p --cc >actual && + test_cmp expect actual +' + test_done diff --git a/t/t4026-color.sh b/t/t4026-color.sh index 3726a0e201..63e423838f 100755 --- a/t/t4026-color.sh +++ b/t/t4026-color.sh @@ -53,6 +53,14 @@ test_expect_success '256 colors' ' color "254 bold 255" "[1;38;5;254;48;5;255m" ' +test_expect_success '"normal" yields no color at all"' ' + color "normal black" "[40m" +' + +test_expect_success '-1 is a synonym for "normal"' ' + color "-1 black" "[40m" +' + test_expect_success 'color too small' ' invalid_color "-2" ' diff --git a/t/t4038-diff-combined.sh b/t/t4038-diff-combined.sh index 41913c3aa3..0b4f7dfdc6 100755 --- a/t/t4038-diff-combined.sh +++ b/t/t4038-diff-combined.sh @@ -401,4 +401,38 @@ test_expect_success 'combine diff missing delete bug' ' compare_diff_patch expected actual ' +test_expect_success 'combine diff gets tree sorting right' ' + # create a directory and a file that sort differently in trees + # versus byte-wise (implied "/" sorts after ".") + git checkout -f master && + mkdir foo && + echo base >foo/one && + echo base >foo/two && + echo base >foo.ext && + git add foo foo.ext && + git commit -m base && + + # one side modifies a file in the directory, along with the root + # file... + echo master >foo/one && + echo master >foo.ext && + git commit -a -m master && + + # the other side modifies the other file in the directory + git checkout -b other HEAD^ && + echo other >foo/two && + git commit -a -m other && + + # And now we merge. The files in the subdirectory will resolve cleanly, + # meaning that a combined diff will not find them interesting. But it + # will find the tree itself interesting, because it had to be merged. + git checkout master && + git merge other && + + printf "MM\tfoo\n" >expect && + git diff-tree -c --name-status -t HEAD >actual.tmp && + sed 1d <actual.tmp >actual && + test_cmp expect actual +' + test_done diff --git a/t/t4055-diff-context.sh b/t/t4055-diff-context.sh index cd0454356a..741e0803c1 100755 --- a/t/t4055-diff-context.sh +++ b/t/t4055-diff-context.sh @@ -79,7 +79,7 @@ test_expect_success 'non-integer config parsing' ' test_expect_success 'negative integer config parsing' ' git config diff.context -1 && test_must_fail git diff 2>output && - test_i18ngrep "bad config file" output + test_i18ngrep "bad config variable" output ' test_expect_success '-U0 is valid, so is diff.context=0' ' diff --git a/t/t4119-apply-config.sh b/t/t4119-apply-config.sh index c393be691b..a9a0583811 100755 --- a/t/t4119-apply-config.sh +++ b/t/t4119-apply-config.sh @@ -159,4 +159,21 @@ test_expect_success 'same but with traditional patch input of depth 2' ' check_result sub/file1 ' +test_expect_success 'in subdir with traditional patch input' ' + cd "$D" && + git config apply.whitespace strip && + cat >.gitattributes <<-EOF && + /* whitespace=blank-at-eol + sub/* whitespace=-blank-at-eol + EOF + rm -f sub/file1 && + cp saved sub/file1 && + git update-index --refresh && + + cd sub && + git apply ../gpatch.file && + echo "B " >expect && + test_cmp expect file1 +' + test_done diff --git a/t/t4124-apply-ws-rule.sh b/t/t4124-apply-ws-rule.sh index 5d0c598338..c6474de4c8 100755 --- a/t/t4124-apply-ws-rule.sh +++ b/t/t4124-apply-ws-rule.sh @@ -512,4 +512,15 @@ test_expect_success 'whitespace=fix to expand' ' git -c core.whitespace=tab-in-indent apply --whitespace=fix patch ' +test_expect_success 'whitespace check skipped for excluded paths' ' + git config core.whitespace blank-at-eol && + >used && + >unused && + git add used unused && + echo "used" >used && + echo "unused " >unused && + git diff-files -p used unused >patch && + git apply --include=used --stat --whitespace=error <patch +' + test_done diff --git a/t/t4201-shortlog.sh b/t/t4201-shortlog.sh index 565c020c45..7600a3e3e8 100755 --- a/t/t4201-shortlog.sh +++ b/t/t4201-shortlog.sh @@ -93,7 +93,7 @@ test_expect_success 'output from user-defined format is re-wrapped' ' test_cmp expect log.predictable ' -test_expect_success NOT_MINGW 'shortlog wrapping' ' +test_expect_success !MINGW 'shortlog wrapping' ' cat >expect <<\EOF && A U Thor (5): Test @@ -114,7 +114,7 @@ EOF test_cmp expect out ' -test_expect_success NOT_MINGW 'shortlog from non-git directory' ' +test_expect_success !MINGW 'shortlog from non-git directory' ' git log HEAD >log && GIT_DIR=non-existing git shortlog -w <log >out && test_cmp expect out @@ -159,7 +159,7 @@ $DSCHO (2): EOF -test_expect_success NOT_MINGW 'shortlog encoding' ' +test_expect_success !MINGW 'shortlog encoding' ' git reset --hard "$commit" && git config --unset i18n.commitencoding && echo 2 > a1 && diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index 349c531989..7398605e7b 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -431,6 +431,21 @@ EOF test_cmp expected actual ' +test_expect_success 'strbuf_utf8_replace() not producing NUL' ' + git log --color --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)%C(auto)%d" | + test_decode_color | + nul_to_q >actual && + ! grep Q actual +' + +# ISO strict date format +test_expect_success 'ISO and ISO-strict date formats display the same values' ' + git log --format=%ai%n%ci | + sed -e "s/ /T/; s/ //; s/..\$/:&/" >expected && + git log --format=%aI%n%cI >actual && + test_cmp expected actual +' + # get new digests (with no abbreviations) head1=$(git rev-parse --verify HEAD~0) && head2=$(git rev-parse --verify HEAD~1) && @@ -450,4 +465,15 @@ EOF test_cmp expected actual1 ' +test_expect_success 'clean log decoration' ' + git log --no-walk --tags --pretty="%H %D" --decorate=full >actual && + cat >expected <<EOF && +$head1 tag: refs/tags/tag2 +$head2 tag: refs/tags/message-one +$old_head1 tag: refs/tags/message-two +EOF + sort actual >actual1 && + test_cmp expected actual1 +' + test_done diff --git a/t/t4210-log-i18n.sh b/t/t4210-log-i18n.sh index 9110404e55..e585fe6129 100755 --- a/t/t4210-log-i18n.sh +++ b/t/t4210-log-i18n.sh @@ -34,7 +34,7 @@ test_expect_success 'log --grep searches in log output encoding (utf8)' ' test_cmp expect actual ' -test_expect_success NOT_MINGW 'log --grep searches in log output encoding (latin1)' ' +test_expect_success !MINGW 'log --grep searches in log output encoding (latin1)' ' cat >expect <<-\EOF && latin1 utf8 @@ -43,7 +43,7 @@ test_expect_success NOT_MINGW 'log --grep searches in log output encoding (latin test_cmp expect actual ' -test_expect_success NOT_MINGW 'log --grep does not find non-reencoded values (utf8)' ' +test_expect_success !MINGW 'log --grep does not find non-reencoded values (utf8)' ' >expect && git log --encoding=utf8 --format=%s --grep=$latin1_e >actual && test_cmp expect actual diff --git a/t/t4211-line-log.sh b/t/t4211-line-log.sh index 7369d3c517..0901b30982 100755 --- a/t/t4211-line-log.sh +++ b/t/t4211-line-log.sh @@ -94,4 +94,9 @@ test_expect_success '-L ,Y (Y == nlines + 2)' ' test_must_fail git log -L ,$n:b.c ' +test_expect_success '-L with --first-parent and a merge' ' + git checkout parallel-change && + git log --first-parent -L 1,1:b.c +' + test_done diff --git a/t/t4212-log-corrupt.sh b/t/t4212-log-corrupt.sh index 58b792bf20..67bd8ec020 100755 --- a/t/t4212-log-corrupt.sh +++ b/t/t4212-log-corrupt.sh @@ -14,7 +14,7 @@ test_expect_success 'setup' ' ' test_expect_success 'fsck notices broken commit' ' - git fsck 2>actual && + test_must_fail git fsck 2>actual && test_i18ngrep invalid.author actual ' diff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh index 7b8babd89b..d01bbdc968 100755 --- a/t/t5000-tar-tree.sh +++ b/t/t5000-tar-tree.sh @@ -305,4 +305,18 @@ test_expect_success GZIP 'remote tar.gz can be disabled' ' >remote.tar.gz ' +test_expect_success 'archive and :(glob)' ' + git archive -v HEAD -- ":(glob)**/sh" >/dev/null 2>actual && + cat >expect <<EOF && +a/ +a/bin/ +a/bin/sh +EOF + test_cmp expect actual +' + +test_expect_success 'catch non-matching pathspec' ' + test_must_fail git archive -v HEAD -- "*.abc" >/dev/null +' + test_done diff --git a/t/t5100-mailinfo.sh b/t/t5100-mailinfo.sh index 3e64a7a65d..9e1ad1ca21 100755 --- a/t/t5100-mailinfo.sh +++ b/t/t5100-mailinfo.sh @@ -89,4 +89,22 @@ test_expect_success 'mailinfo on from header without name works' ' ' +test_expect_success 'mailinfo finds headers after embedded From line' ' + mkdir embed-from && + git mailsplit -oembed-from "$TEST_DIRECTORY"/t5100/embed-from.in && + test_cmp "$TEST_DIRECTORY"/t5100/embed-from.in embed-from/0001 && + git mailinfo embed-from/msg embed-from/patch \ + <embed-from/0001 >embed-from/out && + test_cmp "$TEST_DIRECTORY"/t5100/embed-from.expect embed-from/out +' + +test_expect_success 'mailinfo on message with quoted >From' ' + mkdir quoted-from && + git mailsplit -oquoted-from "$TEST_DIRECTORY"/t5100/quoted-from.in && + test_cmp "$TEST_DIRECTORY"/t5100/quoted-from.in quoted-from/0001 && + git mailinfo quoted-from/msg quoted-from/patch \ + <quoted-from/0001 >quoted-from/out && + test_cmp "$TEST_DIRECTORY"/t5100/quoted-from.expect quoted-from/msg +' + test_done diff --git a/t/t5100/embed-from.expect b/t/t5100/embed-from.expect new file mode 100644 index 0000000000..06a3a3859a --- /dev/null +++ b/t/t5100/embed-from.expect @@ -0,0 +1,5 @@ +Author: Commit Author +Email: commit@example.com +Subject: patch subject +Date: Sat, 13 Sep 2014 21:13:23 -0400 + diff --git a/t/t5100/embed-from.in b/t/t5100/embed-from.in new file mode 100644 index 0000000000..5f3f84e508 --- /dev/null +++ b/t/t5100/embed-from.in @@ -0,0 +1,13 @@ +From 1234567890123456789012345678901234567890 Mon Sep 17 00:00:00 2001 +From: Email Author <email@example.com> +Date: Sun, 25 May 2008 00:38:18 -0700 +Subject: [PATCH] email subject + +>From 1234567890123456789012345678901234567890 Mon Sep 17 00:00:00 2001 +From: Commit Author <commit@example.com> +Date: Sat, 13 Sep 2014 21:13:23 -0400 +Subject: patch subject + +patch body +--- +patch diff --git a/t/t5100/quoted-from.expect b/t/t5100/quoted-from.expect new file mode 100644 index 0000000000..8c9d48c852 --- /dev/null +++ b/t/t5100/quoted-from.expect @@ -0,0 +1,3 @@ +>From the depths of history, we are stuck with the +flaky mbox format. + diff --git a/t/t5100/quoted-from.in b/t/t5100/quoted-from.in new file mode 100644 index 0000000000..847e1c4d3e --- /dev/null +++ b/t/t5100/quoted-from.in @@ -0,0 +1,10 @@ +From 1234567890123456789012345678901234567890 Mon Sep 17 00:00:00 2001 +From: Author Name <somebody@example.com> +Date: Sun, 25 May 2008 00:38:18 -0700 +Subject: [PATCH] testing quoted >From + +>From the depths of history, we are stuck with the +flaky mbox format. + +--- +patch diff --git a/t/t5302-pack-index.sh b/t/t5302-pack-index.sh index 4bbb718751..61bc8da560 100755 --- a/t/t5302-pack-index.sh +++ b/t/t5302-pack-index.sh @@ -243,4 +243,23 @@ test_expect_success 'running index-pack in the object store' ' test -f .git/objects/pack/pack-${pack1}.idx ' +test_expect_success 'index-pack --strict warns upon missing tagger in tag' ' + sha=$(git rev-parse HEAD) && + cat >wrong-tag <<EOF && +object $sha +type commit +tag guten tag + +This is an invalid tag. +EOF + + tag=$(git hash-object -t tag -w --stdin <wrong-tag) && + pack1=$(echo $tag $sha | git pack-objects tag-test) && + echo remove tag object && + thirtyeight=${tag#??} && + rm -f .git/objects/${tag%$thirtyeight}/$thirtyeight && + git index-pack --strict tag-test-${pack1}.pack 2>err && + grep "^error:.* expected .tagger. line" err +' + test_done diff --git a/t/t5304-prune.sh b/t/t5304-prune.sh index 377d3d3899..e32e46dee1 100755 --- a/t/t5304-prune.sh +++ b/t/t5304-prune.sh @@ -13,8 +13,8 @@ add_blob() { before=$(git count-objects | sed "s/ .*//") && BLOB=$(echo aleph_0 | git hash-object -w --stdin) && BLOB_FILE=.git/objects/$(echo $BLOB | sed "s/^../&\//") && - test $((1 + $before)) = $(git count-objects | sed "s/ .*//") && - test -f $BLOB_FILE && + verbose test $((1 + $before)) = $(git count-objects | sed "s/ .*//") && + test_path_is_file $BLOB_FILE && test-chmtime =+0 $BLOB_FILE } @@ -35,9 +35,9 @@ test_expect_success 'prune stale packs' ' : > .git/objects/tmp_2.pack && test-chmtime =-86501 .git/objects/tmp_1.pack && git prune --expire 1.day && - test -f $orig_pack && - test -f .git/objects/tmp_2.pack && - ! test -f .git/objects/tmp_1.pack + test_path_is_file $orig_pack && + test_path_is_file .git/objects/tmp_2.pack && + test_path_is_missing .git/objects/tmp_1.pack ' @@ -45,12 +45,12 @@ test_expect_success 'prune --expire' ' add_blob && git prune --expire=1.hour.ago && - test $((1 + $before)) = $(git count-objects | sed "s/ .*//") && - test -f $BLOB_FILE && + verbose test $((1 + $before)) = $(git count-objects | sed "s/ .*//") && + test_path_is_file $BLOB_FILE && test-chmtime =-86500 $BLOB_FILE && git prune --expire 1.day && - test $before = $(git count-objects | sed "s/ .*//") && - ! test -f $BLOB_FILE + verbose test $before = $(git count-objects | sed "s/ .*//") && + test_path_is_missing $BLOB_FILE ' @@ -59,12 +59,12 @@ test_expect_success 'gc: implicit prune --expire' ' add_blob && test-chmtime =-$((2*$week-30)) $BLOB_FILE && git gc && - test $((1 + $before)) = $(git count-objects | sed "s/ .*//") && - test -f $BLOB_FILE && + verbose test $((1 + $before)) = $(git count-objects | sed "s/ .*//") && + test_path_is_file $BLOB_FILE && test-chmtime =-$((2*$week+1)) $BLOB_FILE && git gc && - test $before = $(git count-objects | sed "s/ .*//") && - ! test -f $BLOB_FILE + verbose test $before = $(git count-objects | sed "s/ .*//") && + test_path_is_missing $BLOB_FILE ' @@ -104,6 +104,28 @@ test_expect_success 'prune: prune unreachable heads' ' ' +test_expect_success 'prune: do not prune detached HEAD with no reflog' ' + + git checkout --detach --quiet && + git commit --allow-empty -m "detached commit" && + # verify that there is no reflogs + # (should be removed and disabled by previous test) + test_path_is_missing .git/logs && + git prune -n >prune_actual && + : >prune_expected && + test_cmp prune_actual prune_expected + +' + +test_expect_success 'prune: prune former HEAD after checking out branch' ' + + head_sha1=$(git rev-parse HEAD) && + git checkout --quiet master && + git prune -v >prune_actual && + grep "$head_sha1" prune_actual + +' + test_expect_success 'prune: do not prune heads listed as an argument' ' : > file2 && @@ -122,8 +144,8 @@ test_expect_success 'gc --no-prune' ' test-chmtime =-$((5001*$day)) $BLOB_FILE && git config gc.pruneExpire 2.days.ago && git gc --no-prune && - test 1 = $(git count-objects | sed "s/ .*//") && - test -f $BLOB_FILE + verbose test 1 = $(git count-objects | sed "s/ .*//") && + test_path_is_file $BLOB_FILE ' @@ -131,10 +153,10 @@ test_expect_success 'gc respects gc.pruneExpire' ' git config gc.pruneExpire 5002.days.ago && git gc && - test -f $BLOB_FILE && + test_path_is_file $BLOB_FILE && git config gc.pruneExpire 5000.days.ago && git gc && - test ! -f $BLOB_FILE + test_path_is_missing $BLOB_FILE ' @@ -143,9 +165,9 @@ test_expect_success 'gc --prune=<date>' ' add_blob && test-chmtime =-$((5001*$day)) $BLOB_FILE && git gc --prune=5002.days.ago && - test -f $BLOB_FILE && + test_path_is_file $BLOB_FILE && git gc --prune=5000.days.ago && - test ! -f $BLOB_FILE + test_path_is_missing $BLOB_FILE ' @@ -153,9 +175,9 @@ test_expect_success 'gc --prune=never' ' add_blob && git gc --prune=never && - test -f $BLOB_FILE && + test_path_is_file $BLOB_FILE && git gc --prune=now && - test ! -f $BLOB_FILE + test_path_is_missing $BLOB_FILE ' @@ -164,10 +186,10 @@ test_expect_success 'gc respects gc.pruneExpire=never' ' git config gc.pruneExpire never && add_blob && git gc && - test -f $BLOB_FILE && + test_path_is_file $BLOB_FILE && git config gc.pruneExpire now && git gc && - test ! -f $BLOB_FILE + test_path_is_missing $BLOB_FILE ' @@ -175,9 +197,9 @@ test_expect_success 'prune --expire=never' ' add_blob && git prune --expire=never && - test -f $BLOB_FILE && + test_path_is_file $BLOB_FILE && git prune && - test ! -f $BLOB_FILE + test_path_is_missing $BLOB_FILE ' @@ -187,11 +209,11 @@ test_expect_success 'gc: prune old objects after local clone' ' git clone --no-hardlinks . aclone && ( cd aclone && - test 1 = $(git count-objects | sed "s/ .*//") && - test -f $BLOB_FILE && + verbose test 1 = $(git count-objects | sed "s/ .*//") && + test_path_is_file $BLOB_FILE && git gc --prune && - test 0 = $(git count-objects | sed "s/ .*//") && - ! test -f $BLOB_FILE + verbose test 0 = $(git count-objects | sed "s/ .*//") && + test_path_is_missing $BLOB_FILE ) ' @@ -228,7 +250,7 @@ test_expect_success 'prune .git/shallow' ' grep $SHA1 .git/shallow && grep $SHA1 out && git prune && - ! test -f .git/shallow + test_path_is_missing .git/shallow ' test_done diff --git a/t/t5310-pack-bitmaps.sh b/t/t5310-pack-bitmaps.sh index 0580258c91..6003490192 100755 --- a/t/t5310-pack-bitmaps.sh +++ b/t/t5310-pack-bitmaps.sh @@ -170,4 +170,13 @@ test_expect_success JGIT 'jgit can read our bitmaps' ' ) ' +test_expect_success 'splitting packs does not generate bogus bitmaps' ' + test-genrandom foo $((1024 * 1024)) >rand && + git add rand && + git commit -m "commit with big file" && + git -c pack.packSizeLimit=500k repack -adb && + git init --bare no-bitmaps.git && + git -C no-bitmaps.git fetch .. HEAD +' + test_done diff --git a/t/t5311-pack-bitmaps-shallow.sh b/t/t5311-pack-bitmaps-shallow.sh new file mode 100755 index 0000000000..872a95df33 --- /dev/null +++ b/t/t5311-pack-bitmaps-shallow.sh @@ -0,0 +1,39 @@ +#!/bin/sh + +test_description='check bitmap operation with shallow repositories' +. ./test-lib.sh + +# We want to create a situation where the shallow, grafted +# view of reachability does not match reality in a way that +# might cause us to send insufficient objects. +# +# We do this with a history that repeats a state, like: +# +# A -- B -- C +# file=1 file=2 file=1 +# +# and then create a shallow clone to the second commit, B. +# In a non-shallow clone, that would mean we already have +# the tree for A. But in a shallow one, we've grafted away +# A, and fetching A to B requires that the other side send +# us the tree for file=1. +test_expect_success 'setup shallow repo' ' + echo 1 >file && + git add file && + git commit -m orig && + echo 2 >file && + git commit -a -m update && + git clone --no-local --bare --depth=1 . shallow.git && + echo 1 >file && + git commit -a -m repeat +' + +test_expect_success 'turn on bitmaps in the parent' ' + git repack -adb +' + +test_expect_success 'shallow fetch from bitmapped repo' ' + (cd shallow.git && git fetch) +' + +test_done diff --git a/t/t5401-update-hooks.sh b/t/t5401-update-hooks.sh index 17bcb0b040..7f278d8ce9 100755 --- a/t/t5401-update-hooks.sh +++ b/t/t5401-update-hooks.sh @@ -135,4 +135,17 @@ test_expect_success 'send-pack stderr contains hook messages' ' test_cmp expect actual ' +test_expect_success 'pre-receive hook that forgets to read its input' ' + write_script victim.git/hooks/pre-receive <<-\EOF && + exit 0 + EOF + rm -f victim.git/hooks/update victim.git/hooks/post-update && + + for v in $(test_seq 100 999) + do + git branch branch_$v master || return + done && + git push ./victim.git "+refs/heads/*:refs/heads/*" +' + test_done diff --git a/t/t5408-send-pack-stdin.sh b/t/t5408-send-pack-stdin.sh new file mode 100755 index 0000000000..e8737df6f9 --- /dev/null +++ b/t/t5408-send-pack-stdin.sh @@ -0,0 +1,92 @@ +#!/bin/sh + +test_description='send-pack --stdin tests' +. ./test-lib.sh + +create_ref () { + tree=$(git write-tree) && + test_tick && + commit=$(echo "$1" | git commit-tree $tree) && + git update-ref "$1" $commit +} + +clear_remote () { + rm -rf remote.git && + git init --bare remote.git +} + +verify_push () { + git rev-parse "$1" >expect && + git --git-dir=remote.git rev-parse "${2:-$1}" >actual && + test_cmp expect actual +} + +test_expect_success 'setup refs' ' + cat >refs <<-\EOF && + refs/heads/A + refs/heads/C + refs/tags/D + refs/heads/B + refs/tags/E + EOF + for i in $(cat refs); do + create_ref $i || return 1 + done +' + +# sanity check our setup +test_expect_success 'refs on cmdline' ' + clear_remote && + git send-pack remote.git $(cat refs) && + for i in $(cat refs); do + verify_push $i || return 1 + done +' + +test_expect_success 'refs over stdin' ' + clear_remote && + git send-pack remote.git --stdin <refs && + for i in $(cat refs); do + verify_push $i || return 1 + done +' + +test_expect_success 'stdin lines are full refspecs' ' + clear_remote && + echo "A:other" >input && + git send-pack remote.git --stdin <input && + verify_push refs/heads/A refs/heads/other +' + +test_expect_success 'stdin mixed with cmdline' ' + clear_remote && + echo A >input && + git send-pack remote.git --stdin B <input && + verify_push A && + verify_push B +' + +test_expect_success 'cmdline refs written in order' ' + clear_remote && + test_must_fail git send-pack remote.git A:foo B:foo && + verify_push A foo +' + +test_expect_success '--stdin refs come after cmdline' ' + clear_remote && + echo A:foo >input && + test_must_fail git send-pack remote.git --stdin B:foo <input && + verify_push B foo +' + +test_expect_success 'refspecs and --mirror do not mix (cmdline)' ' + clear_remote && + test_must_fail git send-pack remote.git --mirror $(cat refs) +' + +test_expect_success 'refspecs and --mirror do not mix (stdin)' ' + clear_remote && + test_must_fail git send-pack remote.git --mirror --stdin <refs +' + +test_done diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index 67e0ab3462..f4da20aa9b 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -11,6 +11,7 @@ This test checks the following functionality: * hooks * --porcelain output format * hiderefs +* reflogs ' . ./test-lib.sh @@ -1277,4 +1278,56 @@ EOF git push --no-thin --receive-pack="$rcvpck" no-thin/.git refs/heads/master:refs/heads/foo ' +test_expect_success 'pushing a tag pushes the tagged object' ' + rm -rf dst.git && + blob=$(echo unreferenced | git hash-object -w --stdin) && + git tag -m foo tag-of-blob $blob && + git init --bare dst.git && + git push dst.git tag-of-blob && + # the receiving index-pack should have noticed + # any problems, but we double check + echo unreferenced >expect && + git --git-dir=dst.git cat-file blob tag-of-blob >actual && + test_cmp expect actual +' + +test_expect_success 'push into bare respects core.logallrefupdates' ' + rm -rf dst.git && + git init --bare dst.git && + git -C dst.git config core.logallrefupdates true && + + # double push to test both with and without + # the actual pack transfer + git push dst.git master:one && + echo "one@{0} push" >expect && + git -C dst.git log -g --format="%gd %gs" one >actual && + test_cmp expect actual && + + git push dst.git master:two && + echo "two@{0} push" >expect && + git -C dst.git log -g --format="%gd %gs" two >actual && + test_cmp expect actual +' + +test_expect_success 'fetch into bare respects core.logallrefupdates' ' + rm -rf dst.git && + git init --bare dst.git && + ( + cd dst.git && + git config core.logallrefupdates true && + + # as above, we double-fetch to test both + # with and without pack transfer + git fetch .. master:one && + echo "one@{0} fetch .. master:one: storing head" >expect && + git log -g --format="%gd %gs" one >actual && + test_cmp expect actual && + + git fetch .. master:two && + echo "two@{0} fetch .. master:two: storing head" >expect && + git log -g --format="%gd %gs" two >actual && + test_cmp expect actual + ) +' + test_done diff --git a/t/t5528-push-default.sh b/t/t5528-push-default.sh index 6a5ac3add4..cc7451908b 100755 --- a/t/t5528-push-default.sh +++ b/t/t5528-push-default.sh @@ -26,7 +26,7 @@ check_pushed_commit () { # $2 = expected target branch for the push # $3 = [optional] repo to check for actual output (repo1 by default) test_push_success () { - git -c push.default="$1" push && + git ${1:+-c push.default="$1"} push && check_pushed_commit HEAD "$2" "$3" } @@ -34,7 +34,7 @@ test_push_success () { # check that push fails and does not modify any remote branch test_push_failure () { git --git-dir=repo1 log --no-walk --format='%h %s' --all >expect && - test_must_fail git -c push.default="$1" push && + test_must_fail git ${1:+-c push.default="$1"} push && git --git-dir=repo1 log --no-walk --format='%h %s' --all >actual && test_cmp expect actual } @@ -172,4 +172,32 @@ test_pushdefault_workflow success simple master triangular # master is updated (parent2 does not have foo) test_pushdefault_workflow success matching master triangular +# default tests, when no push-default is specified. This +# should behave the same as "simple" in non-triangular +# settings, and as "current" otherwise. + +test_expect_success 'default behavior allows "simple" push' ' + test_config branch.master.remote parent1 && + test_config branch.master.merge refs/heads/master && + test_config remote.pushdefault parent1 && + test_commit default-master-master && + test_push_success "" master +' + +test_expect_success 'default behavior rejects non-simple push' ' + test_config branch.master.remote parent1 && + test_config branch.master.merge refs/heads/foo && + test_config remote.pushdefault parent1 && + test_commit default-master-foo && + test_push_failure "" +' + +test_expect_success 'default triangular behavior acts like "current"' ' + test_config branch.master.remote parent1 && + test_config branch.master.merge refs/heads/foo && + test_config remote.pushdefault parent2 && + test_commit default-triangular && + test_push_success "" master repo2 +' + test_done diff --git a/t/t5534-push-signed.sh b/t/t5534-push-signed.sh new file mode 100755 index 0000000000..ecb8d446a5 --- /dev/null +++ b/t/t5534-push-signed.sh @@ -0,0 +1,171 @@ +#!/bin/sh + +test_description='signed push' + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-gpg.sh + +prepare_dst () { + rm -fr dst && + test_create_repo dst && + + git push dst master:noop master:ff master:noff +} + +test_expect_success setup ' + # master, ff and noff branches pointing at the same commit + test_tick && + git commit --allow-empty -m initial && + + git checkout -b noop && + git checkout -b ff && + git checkout -b noff && + + # noop stays the same, ff advances, noff rewrites + test_tick && + git commit --allow-empty --amend -m rewritten && + git checkout ff && + + test_tick && + git commit --allow-empty -m second +' + +test_expect_success 'unsigned push does not send push certificate' ' + prepare_dst && + mkdir -p dst/.git/hooks && + write_script dst/.git/hooks/post-receive <<-\EOF && + # discard the update list + cat >/dev/null + # record the push certificate + if test -n "${GIT_PUSH_CERT-}" + then + git cat-file blob $GIT_PUSH_CERT >../push-cert + fi + EOF + + git push dst noop ff +noff && + ! test -f dst/push-cert +' + +test_expect_success 'talking with a receiver without push certificate support' ' + prepare_dst && + mkdir -p dst/.git/hooks && + write_script dst/.git/hooks/post-receive <<-\EOF && + # discard the update list + cat >/dev/null + # record the push certificate + if test -n "${GIT_PUSH_CERT-}" + then + git cat-file blob $GIT_PUSH_CERT >../push-cert + fi + EOF + + git push dst noop ff +noff && + ! test -f dst/push-cert +' + +test_expect_success 'push --signed fails with a receiver without push certificate support' ' + prepare_dst && + mkdir -p dst/.git/hooks && + test_must_fail git push --signed dst noop ff +noff 2>err && + test_i18ngrep "the receiving end does not support" err +' + +test_expect_success GPG 'no certificate for a signed push with no update' ' + prepare_dst && + mkdir -p dst/.git/hooks && + write_script dst/.git/hooks/post-receive <<-\EOF && + if test -n "${GIT_PUSH_CERT-}" + then + git cat-file blob $GIT_PUSH_CERT >../push-cert + fi + EOF + git push dst noop && + ! test -f dst/push-cert +' + +test_expect_success GPG 'signed push sends push certificate' ' + prepare_dst && + mkdir -p dst/.git/hooks && + git -C dst config receive.certnonceseed sekrit && + write_script dst/.git/hooks/post-receive <<-\EOF && + # discard the update list + cat >/dev/null + # record the push certificate + if test -n "${GIT_PUSH_CERT-}" + then + git cat-file blob $GIT_PUSH_CERT >../push-cert + fi && + + cat >../push-cert-status <<E_O_F + SIGNER=${GIT_PUSH_CERT_SIGNER-nobody} + KEY=${GIT_PUSH_CERT_KEY-nokey} + STATUS=${GIT_PUSH_CERT_STATUS-nostatus} + NONCE_STATUS=${GIT_PUSH_CERT_NONCE_STATUS-nononcestatus} + NONCE=${GIT_PUSH_CERT_NONCE-nononce} + E_O_F + + EOF + + git push --signed dst noop ff +noff && + + ( + cat <<-\EOF && + SIGNER=C O Mitter <committer@example.com> + KEY=13B6F51ECDDE430D + STATUS=G + NONCE_STATUS=OK + EOF + sed -n -e "s/^nonce /NONCE=/p" -e "/^$/q" dst/push-cert + ) >expect && + + grep "$(git rev-parse noop ff) refs/heads/ff" dst/push-cert && + grep "$(git rev-parse noop noff) refs/heads/noff" dst/push-cert && + test_cmp expect dst/push-cert-status +' + +test_expect_success GPG 'fail without key and heed user.signingkey' ' + prepare_dst && + mkdir -p dst/.git/hooks && + git -C dst config receive.certnonceseed sekrit && + write_script dst/.git/hooks/post-receive <<-\EOF && + # discard the update list + cat >/dev/null + # record the push certificate + if test -n "${GIT_PUSH_CERT-}" + then + git cat-file blob $GIT_PUSH_CERT >../push-cert + fi && + + cat >../push-cert-status <<E_O_F + SIGNER=${GIT_PUSH_CERT_SIGNER-nobody} + KEY=${GIT_PUSH_CERT_KEY-nokey} + STATUS=${GIT_PUSH_CERT_STATUS-nostatus} + NONCE_STATUS=${GIT_PUSH_CERT_NONCE_STATUS-nononcestatus} + NONCE=${GIT_PUSH_CERT_NONCE-nononce} + E_O_F + + EOF + + unset GIT_COMMITTER_EMAIL && + git config user.email hasnokey@nowhere.com && + test_must_fail git push --signed dst noop ff +noff && + git config user.signingkey committer@example.com && + git push --signed dst noop ff +noff && + + ( + cat <<-\EOF && + SIGNER=C O Mitter <committer@example.com> + KEY=13B6F51ECDDE430D + STATUS=G + NONCE_STATUS=OK + EOF + sed -n -e "s/^nonce /NONCE=/p" -e "/^$/q" dst/push-cert + ) >expect && + + grep "$(git rev-parse noop ff) refs/heads/ff" dst/push-cert && + grep "$(git rev-parse noop noff) refs/heads/noff" dst/push-cert && + test_cmp expect dst/push-cert-status +' + +test_done diff --git a/t/t5541-http-push-smart.sh b/t/t5541-http-push-smart.sh index 73af16f481..d2c681ebfd 100755 --- a/t/t5541-http-push-smart.sh +++ b/t/t5541-http-push-smart.sh @@ -12,6 +12,7 @@ if test -n "$NO_CURL"; then fi ROOT_PATH="$PWD" +. "$TEST_DIRECTORY"/lib-gpg.sh . "$TEST_DIRECTORY"/lib-httpd.sh . "$TEST_DIRECTORY"/lib-terminal.sh start_httpd @@ -323,5 +324,60 @@ test_expect_success 'push into half-auth-complete requires password' ' test_cmp expect actual ' +run_with_limited_cmdline () { + (ulimit -s 128 && "$@") +} + +test_lazy_prereq CMDLINE_LIMIT 'run_with_limited_cmdline true' + +test_expect_success CMDLINE_LIMIT 'push 2000 tags over http' ' + sha1=$(git rev-parse HEAD) && + test_seq 2000 | + sort | + sed "s|.*|$sha1 refs/tags/really-long-tag-name-&|" \ + >.git/packed-refs && + run_with_limited_cmdline git push --mirror +' + +test_expect_success GPG 'push with post-receive to inspect certificate' ' + ( + cd "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git && + mkdir -p hooks && + write_script hooks/post-receive <<-\EOF && + # discard the update list + cat >/dev/null + # record the push certificate + if test -n "${GIT_PUSH_CERT-}" + then + git cat-file blob $GIT_PUSH_CERT >../push-cert + fi && + cat >../push-cert-status <<E_O_F + SIGNER=${GIT_PUSH_CERT_SIGNER-nobody} + KEY=${GIT_PUSH_CERT_KEY-nokey} + STATUS=${GIT_PUSH_CERT_STATUS-nostatus} + NONCE_STATUS=${GIT_PUSH_CERT_NONCE_STATUS-nononcestatus} + NONCE=${GIT_PUSH_CERT_NONCE-nononce} + E_O_F + EOF + + git config receive.certnonceseed sekrit && + git config receive.certnonceslop 30 + ) && + cd "$ROOT_PATH/test_repo_clone" && + test_commit cert-test && + git push --signed "$HTTPD_URL/smart/test_repo.git" && + ( + cd "$HTTPD_DOCUMENT_ROOT_PATH" && + cat <<-\EOF && + SIGNER=C O Mitter <committer@example.com> + KEY=13B6F51ECDDE430D + STATUS=G + NONCE_STATUS=OK + EOF + sed -n -e "s/^nonce /NONCE=/p" -e "/^$/q" push-cert + ) >expect && + test_cmp expect "$HTTPD_DOCUMENT_ROOT_PATH/push-cert-status" +' + stop_httpd test_done diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh index 5e67035be8..e4f10c0f68 100755 --- a/t/t5601-clone.sh +++ b/t/t5601-clone.sh @@ -318,7 +318,7 @@ test_expect_success 'clone myhost:src uses ssh' ' expect_ssh myhost src ' -test_expect_success NOT_MINGW,NOT_CYGWIN 'clone local path foo:bar' ' +test_expect_success !MINGW,!CYGWIN 'clone local path foo:bar' ' cp -R src "foo:bar" && git clone "foo:bar" foobar && expect_ssh none @@ -339,7 +339,7 @@ test_clone_url () { expect_ssh "$2" "$3" } -test_expect_success NOT_MINGW 'clone c:temp is ssl' ' +test_expect_success !MINGW 'clone c:temp is ssl' ' test_clone_url c:temp c temp ' diff --git a/t/t5704-bundle.sh b/t/t5704-bundle.sh index a45c31692e..348d9b3bc7 100755 --- a/t/t5704-bundle.sh +++ b/t/t5704-bundle.sh @@ -14,7 +14,10 @@ test_expect_success 'setup' ' git tag -d third ' -test_expect_success 'tags can be excluded by rev-list options' ' +test_expect_success 'annotated tags can be excluded by rev-list options' ' + git bundle create bundle --all --since=7.Apr.2005.15:14:00.-0700 && + git ls-remote bundle > output && + grep tag output && git bundle create bundle --all --since=7.Apr.2005.15:16:00.-0700 && git ls-remote bundle > output && ! grep tag output diff --git a/t/t5705-clone-2gb.sh b/t/t5705-clone-2gb.sh index e9783c341a..191d6d3a78 100755 --- a/t/t5705-clone-2gb.sh +++ b/t/t5705-clone-2gb.sh @@ -46,7 +46,7 @@ test_expect_success CLONE_2GB 'clone - bare' ' test_expect_success CLONE_2GB 'clone - with worktree, file:// protocol' ' - git clone file://. clone-wt + git clone "file://$(pwd)" clone-wt ' diff --git a/t/t6000-rev-list-misc.sh b/t/t6000-rev-list-misc.sh index 3794e4ceaf..2602086303 100755 --- a/t/t6000-rev-list-misc.sh +++ b/t/t6000-rev-list-misc.sh @@ -73,4 +73,27 @@ test_expect_success 'symleft flag bit is propagated down from tag' ' test_cmp expect actual ' +test_expect_success 'rev-list can show index objects' ' + # Of the blobs and trees in the index, note: + # + # - we do not show two/three, because it is the + # same blob as "one", and we show objects only once + # + # - we do show the tree "two", because it has a valid cache tree + # from the last commit + # + # - we do not show the root tree; since we updated the index, it + # does not have a valid cache tree + # + cat >expect <<-\EOF + 8e4020bb5a8d8c873b25de15933e75cc0fc275df one + d9d3a7417b9605cfd88ee6306b28dadc29e6ab08 only-in-index + 9200b628cf9dc883a85a7abc8d6e6730baee589c two + EOF + echo only-in-index >only-in-index && + git add only-in-index && + git rev-list --objects --indexed-objects >actual && + test_cmp expect actual +' + test_done diff --git a/t/t6031-merge-recursive.sh b/t/t6031-merge-recursive.sh index a953f1b55c..6464a16a19 100755 --- a/t/t6031-merge-recursive.sh +++ b/t/t6031-merge-recursive.sh @@ -13,6 +13,7 @@ test_expect_success 'mode change in one branch: keep changed version' ' git commit -m a && git checkout -b b1 master && test_chmod +x file1 && + git add file1 && git commit -m b1 && git checkout a1 && git merge-recursive master -- a1 b1 && diff --git a/t/t6038-merge-text-auto.sh b/t/t6038-merge-text-auto.sh index d9c2d386dd..85c10b0940 100755 --- a/t/t6038-merge-text-auto.sh +++ b/t/t6038-merge-text-auto.sh @@ -72,6 +72,10 @@ test_expect_success 'Merge after setting text=auto' ' same line EOF + if test_have_prereq NATIVE_CRLF; then + append_cr <expected >expected.temp && + mv expected.temp expected + fi && git config merge.renormalize true && git rm -fr . && rm -f .gitattributes && @@ -86,6 +90,10 @@ test_expect_success 'Merge addition of text=auto' ' same line EOF + if test_have_prereq NATIVE_CRLF; then + append_cr <expected >expected.temp && + mv expected.temp expected + fi && git config merge.renormalize true && git rm -fr . && rm -f .gitattributes && @@ -95,16 +103,19 @@ test_expect_success 'Merge addition of text=auto' ' ' test_expect_success 'Detect CRLF/LF conflict after setting text=auto' ' - q_to_cr <<-\EOF >expected && - <<<<<<< - first line - same line - ======= - first lineQ - same lineQ - >>>>>>> - EOF - + echo "<<<<<<<" >expected && + if test_have_prereq NATIVE_CRLF; then + echo first line | append_cr >>expected && + echo same line | append_cr >>expected && + echo ======= | append_cr >>expected + else + echo first line >>expected && + echo same line >>expected && + echo ======= >>expected + fi && + echo first line | append_cr >>expected && + echo same line | append_cr >>expected && + echo ">>>>>>>" >>expected && git config merge.renormalize false && rm -f .gitattributes && git reset --hard a && @@ -114,16 +125,19 @@ test_expect_success 'Detect CRLF/LF conflict after setting text=auto' ' ' test_expect_success 'Detect LF/CRLF conflict from addition of text=auto' ' - q_to_cr <<-\EOF >expected && - <<<<<<< - first lineQ - same lineQ - ======= - first line - same line - >>>>>>> - EOF - + echo "<<<<<<<" >expected && + echo first line | append_cr >>expected && + echo same line | append_cr >>expected && + if test_have_prereq NATIVE_CRLF; then + echo ======= | append_cr >>expected && + echo first line | append_cr >>expected && + echo same line | append_cr >>expected + else + echo ======= >>expected && + echo first line >>expected && + echo same line >>expected + fi && + echo ">>>>>>>" >>expected && git config merge.renormalize false && rm -f .gitattributes && git reset --hard b && diff --git a/t/t6501-freshen-objects.sh b/t/t6501-freshen-objects.sh new file mode 100755 index 0000000000..157f3f91db --- /dev/null +++ b/t/t6501-freshen-objects.sh @@ -0,0 +1,132 @@ +#!/bin/sh +# +# This test covers the handling of objects which might have old +# mtimes in the filesystem (because they were used previously) +# and are just now becoming referenced again. +# +# We're going to do two things that are a little bit "fake" to +# help make our simulation easier: +# +# 1. We'll turn off reflogs. You can still run into +# problems with reflogs on, but your objects +# don't get pruned until both the reflog expiration +# has passed on their references, _and_ they are out +# of prune's expiration period. Dropping reflogs +# means we only have to deal with one variable in our tests, +# but the results generalize. +# +# 2. We'll use a temporary index file to create our +# works-in-progress. Most workflows would mention +# referenced objects in the index, which prune takes +# into account. However, many operations don't. For +# example, a partial commit with "git commit foo" +# will use a temporary index. Or they may not need +# an index at all (e.g., creating a new commit +# to refer to an existing tree). + +test_description='check pruning of dependent objects' +. ./test-lib.sh + +# We care about reachability, so we do not want to use +# the normal test_commit, which creates extra tags. +add () { + echo "$1" >"$1" && + git add "$1" +} +commit () { + test_tick && + add "$1" && + git commit -m "$1" +} + +maybe_repack () { + if test -n "$repack"; then + git repack -ad + fi +} + +for repack in '' true; do + title=${repack:+repack} + title=${title:-loose} + + test_expect_success "make repo completely empty ($title)" ' + rm -rf .git && + git init + ' + + test_expect_success "disable reflogs ($title)" ' + git config core.logallrefupdates false && + rm -rf .git/logs + ' + + test_expect_success "setup basic history ($title)" ' + commit base + ' + + test_expect_success "create and abandon some objects ($title)" ' + git checkout -b experiment && + commit abandon && + maybe_repack && + git checkout master && + git branch -D experiment + ' + + test_expect_success "simulate time passing ($title)" ' + find .git/objects -type f | + xargs test-chmtime -v -86400 + ' + + test_expect_success "start writing new commit with old blob ($title)" ' + tree=$( + GIT_INDEX_FILE=index.tmp && + export GIT_INDEX_FILE && + git read-tree HEAD && + add unrelated && + add abandon && + git write-tree + ) + ' + + test_expect_success "simultaneous gc ($title)" ' + git gc --prune=12.hours.ago + ' + + test_expect_success "finish writing out commit ($title)" ' + commit=$(echo foo | git commit-tree -p HEAD $tree) && + git update-ref HEAD $commit + ' + + # "abandon" blob should have been rescued by reference from new tree + test_expect_success "repository passes fsck ($title)" ' + git fsck + ' + + test_expect_success "abandon objects again ($title)" ' + git reset --hard HEAD^ && + find .git/objects -type f | + xargs test-chmtime -v -86400 + ' + + test_expect_success "start writing new commit with same tree ($title)" ' + tree=$( + GIT_INDEX_FILE=index.tmp && + export GIT_INDEX_FILE && + git read-tree HEAD && + add abandon && + add unrelated && + git write-tree + ) + ' + + test_expect_success "simultaneous gc ($title)" ' + git gc --prune=12.hours.ago + ' + + # tree should have been refreshed by write-tree + test_expect_success "finish writing out commit ($title)" ' + commit=$(echo foo | git commit-tree -p HEAD $tree) && + git update-ref HEAD $commit + ' +done + +test_done diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index 54d78079e8..69f11bd40d 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -350,10 +350,11 @@ test_expect_success 'git mv moves a submodule with a .git directory and .gitmodu ' test_expect_success 'git mv moves a submodule with gitfile' ' - rm -rf mod/sub && + rm -rf mod && git reset --hard && git submodule update && entry="$(git ls-files --stage sub | cut -f 1)" && + mkdir mod && ( cd mod && git mv ../sub/ . @@ -372,11 +373,12 @@ test_expect_success 'git mv moves a submodule with gitfile' ' ' test_expect_success 'mv does not complain when no .gitmodules file is found' ' - rm -rf mod/sub && + rm -rf mod && git reset --hard && git submodule update && git rm .gitmodules && entry="$(git ls-files --stage sub | cut -f 1)" && + mkdir mod && git mv sub mod/sub 2>actual.err && ! test -s actual.err && ! test -e sub && @@ -390,11 +392,12 @@ test_expect_success 'mv does not complain when no .gitmodules file is found' ' ' test_expect_success 'mv will error out on a modified .gitmodules file unless staged' ' - rm -rf mod/sub && + rm -rf mod && git reset --hard && git submodule update && git config -f .gitmodules foo.bar true && entry="$(git ls-files --stage sub | cut -f 1)" && + mkdir mod && test_must_fail git mv sub mod/sub 2>actual.err && test -s actual.err && test -e sub && @@ -413,13 +416,14 @@ test_expect_success 'mv will error out on a modified .gitmodules file unless sta ' test_expect_success 'mv issues a warning when section is not found in .gitmodules' ' - rm -rf mod/sub && + rm -rf mod && git reset --hard && git submodule update && git config -f .gitmodules --remove-section submodule.sub && git add .gitmodules && entry="$(git ls-files --stage sub | cut -f 1)" && echo "warning: Could not find section in .gitmodules where path=sub" >expect.err && + mkdir mod && git mv sub mod/sub 2>actual.err && test_i18ncmp expect.err actual.err && ! test -e sub && @@ -433,9 +437,10 @@ test_expect_success 'mv issues a warning when section is not found in .gitmodule ' test_expect_success 'mv --dry-run does not touch the submodule or .gitmodules' ' - rm -rf mod/sub && + rm -rf mod && git reset --hard && git submodule update && + mkdir mod && git mv -n sub mod/sub 2>actual.err && test -f sub/.git && git diff-index --exit-code HEAD && diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh index 0366653088..796e9f79ea 100755 --- a/t/t7004-tag.sh +++ b/t/t7004-tag.sh @@ -1460,7 +1460,7 @@ test_expect_success 'invalid sort parameter in configuratoin' ' ' run_with_limited_stack () { - (ulimit -s 64 && "$@") + (ulimit -s 128 && "$@") } test_lazy_prereq ULIMIT 'run_with_limited_stack true' @@ -1469,7 +1469,7 @@ test_lazy_prereq ULIMIT 'run_with_limited_stack true' test_expect_success ULIMIT '--contains works in a deep repo' ' >expect && i=1 && - while test $i -lt 4000 + while test $i -lt 8000 do echo "commit refs/heads/master committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200 diff --git a/t/t7201-co.sh b/t/t7201-co.sh index 0c9ec0ad44..eae9e5a937 100755 --- a/t/t7201-co.sh +++ b/t/t7201-co.sh @@ -223,6 +223,23 @@ test_expect_success 'checkout --merge --conflict=diff3 <branch>' ' test_cmp two expect ' +test_expect_success 'switch to another branch while carrying a deletion' ' + + git checkout -f master && git reset --hard && git clean -f && + git rm two && + + test_must_fail git checkout simple 2>errs && + test_i18ngrep overwritten errs && + + git checkout --merge simple 2>errs && + test_i18ngrep ! overwritten errs && + git ls-files -u && + test_must_fail git cat-file -t :0:two && + test "$(git cat-file -t :1:two)" = blob && + test "$(git cat-file -t :2:two)" = blob && + test_must_fail git cat-file -t :3:two +' + test_expect_success 'checkout to detach HEAD (with advice declined)' ' git config advice.detachedHead false && diff --git a/t/t7513-interpret-trailers.sh b/t/t7513-interpret-trailers.sh new file mode 100755 index 0000000000..1efb88051a --- /dev/null +++ b/t/t7513-interpret-trailers.sh @@ -0,0 +1,863 @@ +#!/bin/sh +# +# Copyright (c) 2013, 2014 Christian Couder +# + +test_description='git interpret-trailers' + +. ./test-lib.sh + +# When we want one trailing space at the end of each line, let's use sed +# to make sure that these spaces are not removed by any automatic tool. + +test_expect_success 'setup' ' + : >empty && + cat >basic_message <<-\EOF && + subject + + body + EOF + cat >complex_message_body <<-\EOF && + my subject + + my body which is long + and contains some special + chars like : = ? ! + + EOF + sed -e "s/ Z\$/ /" >complex_message_trailers <<-\EOF && + Fixes: Z + Acked-by: Z + Reviewed-by: Z + Signed-off-by: Z + EOF + cat >basic_patch <<-\EOF + --- + foo.txt | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + + diff --git a/foo.txt b/foo.txt + index 0353767..1d91aa1 100644 + --- a/foo.txt + +++ b/foo.txt + @@ -1,3 +1,3 @@ + + -bar + +baz + + -- + 1.9.rc0.11.ga562ddc + + EOF +' + +test_expect_success 'without config' ' + sed -e "s/ Z\$/ /" >expected <<-\EOF && + + ack: Peff + Reviewed-by: Z + Acked-by: Johan + EOF + git interpret-trailers --trailer "ack = Peff" --trailer "Reviewed-by" \ + --trailer "Acked-by: Johan" empty >actual && + test_cmp expected actual +' + +test_expect_success 'without config in another order' ' + sed -e "s/ Z\$/ /" >expected <<-\EOF && + + Acked-by: Johan + Reviewed-by: Z + ack: Peff + EOF + git interpret-trailers --trailer "Acked-by: Johan" --trailer "Reviewed-by" \ + --trailer "ack = Peff" empty >actual && + test_cmp expected actual +' + +test_expect_success '--trim-empty without config' ' + cat >expected <<-\EOF && + + ack: Peff + Acked-by: Johan + EOF + git interpret-trailers --trim-empty --trailer ack=Peff \ + --trailer "Reviewed-by" --trailer "Acked-by: Johan" \ + --trailer "sob:" empty >actual && + test_cmp expected actual +' + +test_expect_success 'with config option on the command line' ' + cat >expected <<-\EOF && + + Acked-by: Johan + Reviewed-by: Peff + EOF + echo "Acked-by: Johan" | + git -c "trailer.Acked-by.ifexists=addifdifferent" interpret-trailers \ + --trailer "Reviewed-by: Peff" --trailer "Acked-by: Johan" >actual && + test_cmp expected actual +' + +test_expect_success 'with config setup' ' + git config trailer.ack.key "Acked-by: " && + cat >expected <<-\EOF && + + Acked-by: Peff + EOF + git interpret-trailers --trim-empty --trailer "ack = Peff" empty >actual && + test_cmp expected actual && + git interpret-trailers --trim-empty --trailer "Acked-by = Peff" empty >actual && + test_cmp expected actual && + git interpret-trailers --trim-empty --trailer "Acked-by :Peff" empty >actual && + test_cmp expected actual +' + +test_expect_success 'with config setup and ":=" as separators' ' + git config trailer.separators ":=" && + git config trailer.ack.key "Acked-by= " && + cat >expected <<-\EOF && + + Acked-by= Peff + EOF + git interpret-trailers --trim-empty --trailer "ack = Peff" empty >actual && + test_cmp expected actual && + git interpret-trailers --trim-empty --trailer "Acked-by= Peff" empty >actual && + test_cmp expected actual && + git interpret-trailers --trim-empty --trailer "Acked-by : Peff" empty >actual && + test_cmp expected actual +' + +test_expect_success 'with config setup and "%" as separators' ' + git config trailer.separators "%" && + cat >expected <<-\EOF && + + bug% 42 + count% 10 + bug% 422 + EOF + git interpret-trailers --trim-empty --trailer "bug = 42" \ + --trailer count%10 --trailer "test: stuff" \ + --trailer "bug % 422" empty >actual && + test_cmp expected actual +' + +test_expect_success 'with "%" as separators and a message with trailers' ' + cat >special_message <<-\EOF && + Special Message + + bug% 42 + count% 10 + bug% 422 + EOF + cat >expected <<-\EOF && + Special Message + + bug% 42 + count% 10 + bug% 422 + count% 100 + EOF + git interpret-trailers --trailer count%100 \ + special_message >actual && + test_cmp expected actual +' + +test_expect_success 'with config setup and ":=#" as separators' ' + git config trailer.separators ":=#" && + git config trailer.bug.key "Bug #" && + cat >expected <<-\EOF && + + Bug #42 + EOF + git interpret-trailers --trim-empty --trailer "bug = 42" empty >actual && + test_cmp expected actual +' + +test_expect_success 'with commit basic message' ' + cat basic_message >expected && + echo >>expected && + git interpret-trailers <basic_message >actual && + test_cmp expected actual +' + +test_expect_success 'with basic patch' ' + cat basic_message >input && + cat basic_patch >>input && + cat basic_message >expected && + echo >>expected && + cat basic_patch >>expected && + git interpret-trailers <input >actual && + test_cmp expected actual +' + +test_expect_success 'with commit complex message as argument' ' + cat complex_message_body complex_message_trailers >complex_message && + cat complex_message_body >expected && + sed -e "s/ Z\$/ /" >>expected <<-\EOF && + Fixes: Z + Acked-by= Z + Reviewed-by: Z + Signed-off-by: Z + EOF + git interpret-trailers complex_message >actual && + test_cmp expected actual +' + +test_expect_success 'with 2 files arguments' ' + cat basic_message >>expected && + echo >>expected && + cat basic_patch >>expected && + git interpret-trailers complex_message input >actual && + test_cmp expected actual +' + +test_expect_success 'with message that has comments' ' + cat basic_message >>message_with_comments && + sed -e "s/ Z\$/ /" >>message_with_comments <<-\EOF && + # comment + + # other comment + Cc: Z + # yet another comment + Reviewed-by: Johan + Reviewed-by: Z + # last comment + + EOF + cat basic_patch >>message_with_comments && + cat basic_message >expected && + cat >>expected <<-\EOF && + # comment + + Reviewed-by: Johan + Cc: Peff + EOF + cat basic_patch >>expected && + git interpret-trailers --trim-empty --trailer "Cc: Peff" message_with_comments >actual && + test_cmp expected actual +' + +test_expect_success 'with commit complex message and trailer args' ' + cat complex_message_body >expected && + sed -e "s/ Z\$/ /" >>expected <<-\EOF && + Fixes: Z + Acked-by= Z + Reviewed-by: Z + Signed-off-by: Z + Acked-by= Peff + Bug #42 + EOF + git interpret-trailers --trailer "ack: Peff" \ + --trailer "bug: 42" <complex_message >actual && + test_cmp expected actual +' + +test_expect_success 'with complex patch, args and --trim-empty' ' + cat complex_message >complex_patch && + cat basic_patch >>complex_patch && + cat complex_message_body >expected && + cat >>expected <<-\EOF && + Acked-by= Peff + Bug #42 + EOF + cat basic_patch >>expected && + git interpret-trailers --trim-empty --trailer "ack: Peff" \ + --trailer "bug: 42" <complex_patch >actual && + test_cmp expected actual +' + +test_expect_success 'using "where = before"' ' + git config trailer.bug.where "before" && + cat complex_message_body >expected && + sed -e "s/ Z\$/ /" >>expected <<-\EOF && + Bug #42 + Fixes: Z + Acked-by= Z + Reviewed-by: Z + Signed-off-by: Z + Acked-by= Peff + EOF + git interpret-trailers --trailer "ack: Peff" \ + --trailer "bug: 42" complex_message >actual && + test_cmp expected actual +' + +test_expect_success 'using "where = after"' ' + git config trailer.ack.where "after" && + cat complex_message_body >expected && + sed -e "s/ Z\$/ /" >>expected <<-\EOF && + Bug #42 + Fixes: Z + Acked-by= Z + Acked-by= Peff + Reviewed-by: Z + Signed-off-by: Z + EOF + git interpret-trailers --trailer "ack: Peff" \ + --trailer "bug: 42" complex_message >actual && + test_cmp expected actual +' + +test_expect_success 'using "where = end"' ' + git config trailer.review.key "Reviewed-by" && + git config trailer.review.where "end" && + cat complex_message_body >expected && + sed -e "s/ Z\$/ /" >>expected <<-\EOF && + Fixes: Z + Acked-by= Z + Acked-by= Peff + Reviewed-by: Z + Signed-off-by: Z + Reviewed-by: Junio + Reviewed-by: Johannes + EOF + git interpret-trailers --trailer "ack: Peff" \ + --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \ + complex_message >actual && + test_cmp expected actual +' + +test_expect_success 'using "where = start"' ' + git config trailer.review.key "Reviewed-by" && + git config trailer.review.where "start" && + cat complex_message_body >expected && + sed -e "s/ Z\$/ /" >>expected <<-\EOF && + Reviewed-by: Johannes + Reviewed-by: Junio + Fixes: Z + Acked-by= Z + Acked-by= Peff + Reviewed-by: Z + Signed-off-by: Z + EOF + git interpret-trailers --trailer "ack: Peff" \ + --trailer "Reviewed-by: Junio" --trailer "Reviewed-by: Johannes" \ + complex_message >actual && + test_cmp expected actual +' + +test_expect_success 'using "where = before" for a token in the middle of the message' ' + git config trailer.review.key "Reviewed-by:" && + git config trailer.review.where "before" && + cat complex_message_body >expected && + sed -e "s/ Z\$/ /" >>expected <<-\EOF && + Bug #42 + Fixes: Z + Acked-by= Z + Acked-by= Peff + Reviewed-by:Johan + Reviewed-by: + Signed-off-by: Z + EOF + git interpret-trailers --trailer "ack: Peff" --trailer "bug: 42" \ + --trailer "review: Johan" <complex_message >actual && + test_cmp expected actual +' + +test_expect_success 'using "where = before" and --trim-empty' ' + cat complex_message_body >expected && + cat >>expected <<-\EOF && + Bug #46 + Bug #42 + Acked-by= Peff + Reviewed-by:Johan + EOF + git interpret-trailers --trim-empty --trailer "ack: Peff" \ + --trailer "bug: 42" --trailer "review: Johan" \ + --trailer "Bug: 46" <complex_message >actual && + test_cmp expected actual +' + +test_expect_success 'the default is "ifExists = addIfDifferentNeighbor"' ' + cat complex_message_body >expected && + sed -e "s/ Z\$/ /" >>expected <<-\EOF && + Bug #42 + Fixes: Z + Acked-by= Z + Acked-by= Peff + Acked-by= Junio + Acked-by= Peff + Reviewed-by: + Signed-off-by: Z + EOF + git interpret-trailers --trailer "ack: Peff" --trailer "review:" \ + --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \ + --trailer "ack: Peff" <complex_message >actual && + test_cmp expected actual +' + +test_expect_success 'default "ifExists" is now "addIfDifferent"' ' + git config trailer.ifexists "addIfDifferent" && + cat complex_message_body >expected && + sed -e "s/ Z\$/ /" >>expected <<-\EOF && + Bug #42 + Fixes: Z + Acked-by= Z + Acked-by= Peff + Acked-by= Junio + Reviewed-by: + Signed-off-by: Z + EOF + git interpret-trailers --trailer "ack: Peff" --trailer "review:" \ + --trailer "ack: Junio" --trailer "bug: 42" --trailer "ack: Peff" \ + --trailer "ack: Peff" <complex_message >actual && + test_cmp expected actual +' + +test_expect_success 'using "ifExists = addIfDifferent" with "where = end"' ' + git config trailer.ack.ifExists "addIfDifferent" && + git config trailer.ack.where "end" && + cat complex_message_body >expected && + sed -e "s/ Z\$/ /" >>expected <<-\EOF && + Bug #42 + Fixes: Z + Acked-by= Z + Reviewed-by: + Signed-off-by: Z + Acked-by= Peff + EOF + git interpret-trailers --trailer "ack: Peff" --trailer "review:" \ + --trailer "bug: 42" --trailer "ack: Peff" \ + <complex_message >actual && + test_cmp expected actual +' + +test_expect_success 'using "ifExists = addIfDifferent" with "where = before"' ' + git config trailer.ack.ifExists "addIfDifferent" && + git config trailer.ack.where "before" && + cat complex_message_body >expected && + sed -e "s/ Z\$/ /" >>expected <<-\EOF && + Bug #42 + Fixes: Z + Acked-by= Peff + Acked-by= Z + Reviewed-by: + Signed-off-by: Z + EOF + git interpret-trailers --trailer "ack: Peff" --trailer "review:" \ + --trailer "bug: 42" --trailer "ack: Peff" \ + <complex_message >actual && + test_cmp expected actual +' + +test_expect_success 'using "ifExists = addIfDifferentNeighbor" with "where = end"' ' + git config trailer.ack.ifExists "addIfDifferentNeighbor" && + git config trailer.ack.where "end" && + cat complex_message_body >expected && + sed -e "s/ Z\$/ /" >>expected <<-\EOF && + Bug #42 + Fixes: Z + Acked-by= Z + Reviewed-by: + Signed-off-by: Z + Acked-by= Peff + Acked-by= Junio + Tested-by: Jakub + Acked-by= Junio + Acked-by= Peff + EOF + git interpret-trailers --trailer "ack: Peff" --trailer "review:" \ + --trailer "ack: Junio" --trailer "bug: 42" \ + --trailer "Tested-by: Jakub" --trailer "ack: Junio" \ + --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual && + test_cmp expected actual +' + +test_expect_success 'using "ifExists = addIfDifferentNeighbor" with "where = after"' ' + git config trailer.ack.ifExists "addIfDifferentNeighbor" && + git config trailer.ack.where "after" && + cat complex_message_body >expected && + sed -e "s/ Z\$/ /" >>expected <<-\EOF && + Bug #42 + Fixes: Z + Acked-by= Z + Acked-by= Peff + Acked-by= Junio + Acked-by= Peff + Reviewed-by: + Signed-off-by: Z + Tested-by: Jakub + EOF + git interpret-trailers --trailer "ack: Peff" --trailer "review:" \ + --trailer "ack: Junio" --trailer "bug: 42" \ + --trailer "Tested-by: Jakub" --trailer "ack: Junio" \ + --trailer "ack: Junio" --trailer "ack: Peff" <complex_message >actual && + test_cmp expected actual +' + +test_expect_success 'using "ifExists = addIfDifferentNeighbor" and --trim-empty' ' + git config trailer.ack.ifExists "addIfDifferentNeighbor" && + cat complex_message_body >expected && + cat >>expected <<-\EOF && + Bug #42 + Acked-by= Peff + Acked-by= Junio + Acked-by= Peff + EOF + git interpret-trailers --trim-empty --trailer "ack: Peff" \ + --trailer "Acked-by= Peff" --trailer "review:" \ + --trailer "ack: Junio" --trailer "bug: 42" \ + --trailer "ack: Peff" <complex_message >actual && + test_cmp expected actual +' + +test_expect_success 'using "ifExists = add" with "where = end"' ' + git config trailer.ack.ifExists "add" && + git config trailer.ack.where "end" && + cat complex_message_body >expected && + sed -e "s/ Z\$/ /" >>expected <<-\EOF && + Bug #42 + Fixes: Z + Acked-by= Z + Reviewed-by: + Signed-off-by: Z + Acked-by= Peff + Acked-by= Peff + Tested-by: Jakub + Acked-by= Junio + Tested-by: Johannes + Acked-by= Peff + EOF + git interpret-trailers --trailer "ack: Peff" \ + --trailer "Acked-by= Peff" --trailer "review:" \ + --trailer "Tested-by: Jakub" --trailer "ack: Junio" \ + --trailer "bug: 42" --trailer "Tested-by: Johannes" \ + --trailer "ack: Peff" <complex_message >actual && + test_cmp expected actual +' + +test_expect_success 'using "ifExists = add" with "where = after"' ' + git config trailer.ack.ifExists "add" && + git config trailer.ack.where "after" && + cat complex_message_body >expected && + sed -e "s/ Z\$/ /" >>expected <<-\EOF && + Bug #42 + Fixes: Z + Acked-by= Z + Acked-by= Peff + Acked-by= Peff + Acked-by= Junio + Acked-by= Peff + Reviewed-by: + Signed-off-by: Z + EOF + git interpret-trailers --trailer "ack: Peff" \ + --trailer "Acked-by= Peff" --trailer "review:" \ + --trailer "ack: Junio" --trailer "bug: 42" \ + --trailer "ack: Peff" <complex_message >actual && + test_cmp expected actual +' + +test_expect_success 'using "ifExists = replace"' ' + git config trailer.fix.key "Fixes: " && + git config trailer.fix.ifExists "replace" && + cat complex_message_body >expected && + sed -e "s/ Z\$/ /" >>expected <<-\EOF && + Bug #42 + Acked-by= Z + Acked-by= Junio + Acked-by= Peff + Reviewed-by: + Signed-off-by: Z + Fixes: 22 + EOF + git interpret-trailers --trailer "review:" \ + --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \ + --trailer "bug: 42" --trailer "ack: Peff" \ + <complex_message >actual && + test_cmp expected actual +' + +test_expect_success 'using "ifExists = replace" with "where = after"' ' + git config trailer.fix.where "after" && + cat complex_message_body >expected && + sed -e "s/ Z\$/ /" >>expected <<-\EOF && + Bug #42 + Fixes: 22 + Acked-by= Z + Acked-by= Junio + Acked-by= Peff + Reviewed-by: + Signed-off-by: Z + EOF + git interpret-trailers --trailer "review:" \ + --trailer "fix=53" --trailer "ack: Junio" --trailer "fix=22" \ + --trailer "bug: 42" --trailer "ack: Peff" \ + <complex_message >actual && + test_cmp expected actual +' + +test_expect_success 'using "ifExists = doNothing"' ' + git config trailer.fix.ifExists "doNothing" && + cat complex_message_body >expected && + sed -e "s/ Z\$/ /" >>expected <<-\EOF && + Bug #42 + Fixes: Z + Acked-by= Z + Acked-by= Junio + Acked-by= Peff + Reviewed-by: + Signed-off-by: Z + EOF + git interpret-trailers --trailer "review:" --trailer "fix=53" \ + --trailer "ack: Junio" --trailer "fix=22" \ + --trailer "bug: 42" --trailer "ack: Peff" \ + <complex_message >actual && + test_cmp expected actual +' + +test_expect_success 'the default is "ifMissing = add"' ' + git config trailer.cc.key "Cc: " && + git config trailer.cc.where "before" && + cat complex_message_body >expected && + sed -e "s/ Z\$/ /" >>expected <<-\EOF && + Bug #42 + Cc: Linus + Fixes: Z + Acked-by= Z + Acked-by= Junio + Acked-by= Peff + Reviewed-by: + Signed-off-by: Z + EOF + git interpret-trailers --trailer "review:" --trailer "fix=53" \ + --trailer "cc=Linus" --trailer "ack: Junio" \ + --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \ + <complex_message >actual && + test_cmp expected actual +' + +test_expect_success 'when default "ifMissing" is "doNothing"' ' + git config trailer.ifmissing "doNothing" && + cat complex_message_body >expected && + sed -e "s/ Z\$/ /" >>expected <<-\EOF && + Fixes: Z + Acked-by= Z + Acked-by= Junio + Acked-by= Peff + Reviewed-by: + Signed-off-by: Z + EOF + git interpret-trailers --trailer "review:" --trailer "fix=53" \ + --trailer "cc=Linus" --trailer "ack: Junio" \ + --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \ + <complex_message >actual && + test_cmp expected actual && + git config trailer.ifmissing "add" +' + +test_expect_success 'using "ifMissing = add" with "where = end"' ' + git config trailer.cc.key "Cc: " && + git config trailer.cc.where "end" && + git config trailer.cc.ifMissing "add" && + cat complex_message_body >expected && + sed -e "s/ Z\$/ /" >>expected <<-\EOF && + Bug #42 + Fixes: Z + Acked-by= Z + Acked-by= Junio + Acked-by= Peff + Reviewed-by: + Signed-off-by: Z + Cc: Linus + EOF + git interpret-trailers --trailer "review:" --trailer "fix=53" \ + --trailer "ack: Junio" --trailer "fix=22" \ + --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \ + <complex_message >actual && + test_cmp expected actual +' + +test_expect_success 'using "ifMissing = add" with "where = before"' ' + git config trailer.cc.key "Cc: " && + git config trailer.cc.where "before" && + git config trailer.cc.ifMissing "add" && + cat complex_message_body >expected && + sed -e "s/ Z\$/ /" >>expected <<-\EOF && + Cc: Linus + Bug #42 + Fixes: Z + Acked-by= Z + Acked-by= Junio + Acked-by= Peff + Reviewed-by: + Signed-off-by: Z + EOF + git interpret-trailers --trailer "review:" --trailer "fix=53" \ + --trailer "ack: Junio" --trailer "fix=22" \ + --trailer "bug: 42" --trailer "cc=Linus" --trailer "ack: Peff" \ + <complex_message >actual && + test_cmp expected actual +' + +test_expect_success 'using "ifMissing = doNothing"' ' + git config trailer.cc.ifMissing "doNothing" && + cat complex_message_body >expected && + sed -e "s/ Z\$/ /" >>expected <<-\EOF && + Bug #42 + Fixes: Z + Acked-by= Z + Acked-by= Junio + Acked-by= Peff + Reviewed-by: + Signed-off-by: Z + EOF + git interpret-trailers --trailer "review:" --trailer "fix=53" \ + --trailer "cc=Linus" --trailer "ack: Junio" \ + --trailer "fix=22" --trailer "bug: 42" --trailer "ack: Peff" \ + <complex_message >actual && + test_cmp expected actual +' + +test_expect_success 'default "where" is now "after"' ' + git config trailer.where "after" && + git config --unset trailer.ack.where && + cat complex_message_body >expected && + sed -e "s/ Z\$/ /" >>expected <<-\EOF && + Bug #42 + Fixes: Z + Acked-by= Z + Acked-by= Peff + Acked-by= Peff + Acked-by= Junio + Acked-by= Peff + Reviewed-by: + Signed-off-by: Z + Tested-by: Jakub + Tested-by: Johannes + EOF + git interpret-trailers --trailer "ack: Peff" \ + --trailer "Acked-by= Peff" --trailer "review:" \ + --trailer "Tested-by: Jakub" --trailer "ack: Junio" \ + --trailer "bug: 42" --trailer "Tested-by: Johannes" \ + --trailer "ack: Peff" <complex_message >actual && + test_cmp expected actual +' + +test_expect_success 'with simple command' ' + git config trailer.sign.key "Signed-off-by: " && + git config trailer.sign.where "after" && + git config trailer.sign.ifExists "addIfDifferentNeighbor" && + git config trailer.sign.command "echo \"A U Thor <author@example.com>\"" && + cat complex_message_body >expected && + sed -e "s/ Z\$/ /" >>expected <<-\EOF && + Fixes: Z + Acked-by= Z + Reviewed-by: + Signed-off-by: Z + Signed-off-by: A U Thor <author@example.com> + EOF + git interpret-trailers --trailer "review:" --trailer "fix=22" \ + <complex_message >actual && + test_cmp expected actual +' + +test_expect_success 'with command using commiter information' ' + git config trailer.sign.ifExists "addIfDifferent" && + git config trailer.sign.command "echo \"\$GIT_COMMITTER_NAME <\$GIT_COMMITTER_EMAIL>\"" && + cat complex_message_body >expected && + sed -e "s/ Z\$/ /" >>expected <<-\EOF && + Fixes: Z + Acked-by= Z + Reviewed-by: + Signed-off-by: Z + Signed-off-by: C O Mitter <committer@example.com> + EOF + git interpret-trailers --trailer "review:" --trailer "fix=22" \ + <complex_message >actual && + test_cmp expected actual +' + +test_expect_success 'with command using author information' ' + git config trailer.sign.key "Signed-off-by: " && + git config trailer.sign.where "after" && + git config trailer.sign.ifExists "addIfDifferentNeighbor" && + git config trailer.sign.command "echo \"\$GIT_AUTHOR_NAME <\$GIT_AUTHOR_EMAIL>\"" && + cat complex_message_body >expected && + sed -e "s/ Z\$/ /" >>expected <<-\EOF && + Fixes: Z + Acked-by= Z + Reviewed-by: + Signed-off-by: Z + Signed-off-by: A U Thor <author@example.com> + EOF + git interpret-trailers --trailer "review:" --trailer "fix=22" \ + <complex_message >actual && + test_cmp expected actual +' + +test_expect_success 'setup a commit' ' + echo "Content of the first commit." > a.txt && + git add a.txt && + git commit -m "Add file a.txt" +' + +test_expect_success 'with command using $ARG' ' + git config trailer.fix.ifExists "replace" && + git config trailer.fix.command "git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG" && + FIXED=$(git log -1 --oneline --format="%h (%s)" --abbrev-commit --abbrev=14 HEAD) && + cat complex_message_body >expected && + sed -e "s/ Z\$/ /" >>expected <<-EOF && + Fixes: $FIXED + Acked-by= Z + Reviewed-by: + Signed-off-by: Z + Signed-off-by: A U Thor <author@example.com> + EOF + git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \ + <complex_message >actual && + test_cmp expected actual +' + +test_expect_success 'with failing command using $ARG' ' + git config trailer.fix.ifExists "replace" && + git config trailer.fix.command "false \$ARG" && + cat complex_message_body >expected && + sed -e "s/ Z\$/ /" >>expected <<-EOF && + Fixes: Z + Acked-by= Z + Reviewed-by: + Signed-off-by: Z + Signed-off-by: A U Thor <author@example.com> + EOF + git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \ + <complex_message >actual && + test_cmp expected actual +' + +test_expect_success 'with empty tokens' ' + git config --unset trailer.fix.command && + cat >expected <<-EOF && + + Signed-off-by: A U Thor <author@example.com> + EOF + git interpret-trailers --trailer ":" --trailer ":test" >actual <<-EOF && + EOF + test_cmp expected actual +' + +test_expect_success 'with command but no key' ' + git config --unset trailer.sign.key && + cat >expected <<-EOF && + + sign: A U Thor <author@example.com> + EOF + git interpret-trailers >actual <<-EOF && + EOF + test_cmp expected actual +' + +test_expect_success 'with no command and no key' ' + git config --unset trailer.review.key && + cat >expected <<-EOF && + + review: Junio + sign: A U Thor <author@example.com> + EOF + git interpret-trailers --trailer "review:Junio" >actual <<-EOF && + EOF + test_cmp expected actual +' + +test_done diff --git a/t/t7515-status-symlinks.sh b/t/t7515-status-symlinks.sh new file mode 100755 index 0000000000..9f989be01b --- /dev/null +++ b/t/t7515-status-symlinks.sh @@ -0,0 +1,43 @@ +#!/bin/sh + +test_description='git status and symlinks' + +. ./test-lib.sh + +test_expect_success 'setup' ' + echo .gitignore >.gitignore && + echo actual >>.gitignore && + echo expect >>.gitignore && + mkdir dir && + echo x >dir/file1 && + echo y >dir/file2 && + git add dir && + git commit -m initial && + git tag initial +' + +test_expect_success SYMLINKS 'symlink to a directory' ' + test_when_finished "rm symlink" && + ln -s dir symlink && + echo "?? symlink" >expect && + git status --porcelain >actual && + test_cmp expect actual +' + +test_expect_success SYMLINKS 'symlink replacing a directory' ' + test_when_finished "rm -rf copy && git reset --hard initial" && + mkdir copy && + cp dir/file1 copy/file1 && + echo "changed in copy" >copy/file2 && + git add copy && + git commit -m second && + rm -rf copy && + ln -s dir copy && + echo " D copy/file1" >expect && + echo " D copy/file2" >>expect && + echo "?? copy" >>expect && + git status --porcelain >actual && + test_cmp expect actual +' + +test_done diff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh index 05d9db090d..7eeb207b32 100755 --- a/t/t7610-mergetool.sh +++ b/t/t7610-mergetool.sh @@ -14,512 +14,527 @@ Testing basic merge tool invocation' # running mergetool 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 && - echo master file14 >file14 && - mkdir subdir && - echo master sub >subdir/file3 && - test_create_repo submod && - ( - cd submod && - : >foo && - git add foo && - git commit -m "Add foo" - ) && - git submodule add git://example.com/submod 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 both added >both && - echo branch1 change file11 >file11 && - echo branch1 change file13 >file13 && - echo branch1 sub >subdir/file3 && - ( - cd submod && - echo branch1 submodule >bar && - git add bar && - git commit -m "Add bar on branch1" && - git checkout -b submod-branch1 - ) && - git add file1 "spaced name" file11 file13 file2 subdir/file3 submod && - git add both && - git rm file12 && - git commit -m "branch1 changes" && - - git checkout -b stash1 master && - echo stash1 change file11 >file11 && - git add file11 && - git commit -m "stash1 changes" && - - git checkout -b stash2 master && - echo stash2 change file11 >file11 && - git add file11 && - git commit -m "stash2 changes" && - - git checkout master && - git submodule update -N && - echo master updated >file1 && - echo master new >file2 && - echo master updated spaced >"spaced name" && - echo master both added >both && - echo master updated file12 >file12 && - echo master updated file14 >file14 && - echo master new sub >subdir/file3 && - ( - cd submod && - echo master submodule >bar && - git add bar && - git commit -m "Add bar on master" && - git checkout -b submod-master - ) && - git add file1 "spaced name" file12 file14 file2 subdir/file3 submod && - git add both && - git rm file11 && - git commit -m "master updates" && - - git config merge.tool mytool && - git config mergetool.mytool.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" && - git config mergetool.mytool.trustExitCode true && - git config mergetool.mybase.cmd "cat \"\$BASE\" >\"\$MERGED\"" && - git config mergetool.mybase.trustExitCode true + test_config rerere.enabled true && + echo master >file1 && + echo master spaced >"spaced name" && + echo master file11 >file11 && + echo master file12 >file12 && + echo master file13 >file13 && + echo master file14 >file14 && + mkdir subdir && + echo master sub >subdir/file3 && + test_create_repo submod && + ( + cd submod && + : >foo && + git add foo && + git commit -m "Add foo" + ) && + git submodule add git://example.com/submod 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 both added >both && + echo branch1 change file11 >file11 && + echo branch1 change file13 >file13 && + echo branch1 sub >subdir/file3 && + ( + cd submod && + echo branch1 submodule >bar && + git add bar && + git commit -m "Add bar on branch1" && + git checkout -b submod-branch1 + ) && + git add file1 "spaced name" file11 file13 file2 subdir/file3 submod && + git add both && + git rm file12 && + git commit -m "branch1 changes" && + + git checkout -b stash1 master && + echo stash1 change file11 >file11 && + git add file11 && + git commit -m "stash1 changes" && + + git checkout -b stash2 master && + echo stash2 change file11 >file11 && + git add file11 && + git commit -m "stash2 changes" && + + git checkout master && + git submodule update -N && + echo master updated >file1 && + echo master new >file2 && + echo master updated spaced >"spaced name" && + echo master both added >both && + echo master updated file12 >file12 && + echo master updated file14 >file14 && + echo master new sub >subdir/file3 && + ( + cd submod && + echo master submodule >bar && + git add bar && + git commit -m "Add bar on master" && + git checkout -b submod-master + ) && + git add file1 "spaced name" file12 file14 file2 subdir/file3 submod && + git add both && + git rm file11 && + git commit -m "master updates" && + + git config merge.tool mytool && + git config mergetool.mytool.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" && + git config mergetool.mytool.trustExitCode true && + git config mergetool.mybase.cmd "cat \"\$BASE\" >\"\$MERGED\"" && + git config mergetool.mybase.trustExitCode true ' 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 both >/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 ) && - ( yes "l" | git mergetool submod >/dev/null 2>&1 ) && - test "$(cat file1)" = "master updated" && - test "$(cat file2)" = "master new" && - test "$(cat subdir/file3)" = "master new sub" && - test "$(cat submod/bar)" = "branch1 submodule" && - git commit -m "branch1 resolved with mergetool" + git checkout -b test1 branch1 && + git submodule update -N && + test_must_fail git merge master >/dev/null 2>&1 && + ( yes "" | git mergetool both >/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 ) && + ( yes "l" | git mergetool submod >/dev/null 2>&1 ) && + test "$(cat file1)" = "master updated" && + test "$(cat file2)" = "master new" && + test "$(cat subdir/file3)" = "master new sub" && + test "$(cat submod/bar)" = "branch1 submodule" && + git commit -m "branch1 resolved with mergetool" ' test_expect_success 'mergetool crlf' ' - git config core.autocrlf true && - git checkout -b test2 branch1 && - 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 both >/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 ) && - ( yes "r" | git mergetool submod >/dev/null 2>&1 ) && - test "$(printf x | cat file1 -)" = "$(printf "master updated\r\nx")" && - test "$(printf x | cat file2 -)" = "$(printf "master new\r\nx")" && - test "$(printf x | cat subdir/file3 -)" = "$(printf "master new sub\r\nx")" && - git submodule update -N && - test "$(cat submod/bar)" = "master submodule" && - git commit -m "branch1 resolved with mergetool - autocrlf" && - git config core.autocrlf false && - git reset --hard + test_config core.autocrlf true && + git checkout -b test2 branch1 && + 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 both >/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 ) && + ( yes "r" | git mergetool submod >/dev/null 2>&1 ) && + test "$(printf x | cat file1 -)" = "$(printf "master updated\r\nx")" && + test "$(printf x | cat file2 -)" = "$(printf "master new\r\nx")" && + test "$(printf x | cat subdir/file3 -)" = "$(printf "master new sub\r\nx")" && + git submodule update -N && + test "$(cat submod/bar)" = "master submodule" && + git commit -m "branch1 resolved with mergetool - autocrlf" && + test_config core.autocrlf false && + git reset --hard ' test_expect_success 'mergetool in subdir' ' - git checkout -b test3 branch1 && - git submodule update -N && - ( - cd subdir && - test_must_fail git merge master >/dev/null 2>&1 && - ( yes "" | git mergetool file3 >/dev/null 2>&1 ) && - test "$(cat file3)" = "master new sub" - ) + git checkout -b test3 branch1 && + git submodule update -N && + ( + cd subdir && + test_must_fail git merge master >/dev/null 2>&1 && + ( yes "" | git mergetool file3 >/dev/null 2>&1 ) && + test "$(cat file3)" = "master new sub" + ) ' test_expect_success 'mergetool on file in parent dir' ' - ( - cd subdir && - ( yes "" | git mergetool ../file1 >/dev/null 2>&1 ) && - ( yes "" | git mergetool ../file2 ../spaced\ name >/dev/null 2>&1 ) && - ( yes "" | git mergetool ../both >/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 ) && - test "$(cat ../file1)" = "master updated" && - test "$(cat ../file2)" = "master new" && - test "$(cat ../submod/bar)" = "branch1 submodule" && - git commit -m "branch1 resolved with mergetool - subdir" - ) + ( + cd subdir && + ( yes "" | git mergetool ../file1 >/dev/null 2>&1 ) && + ( yes "" | git mergetool ../file2 ../spaced\ name >/dev/null 2>&1 ) && + ( yes "" | git mergetool ../both >/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 ) && + test "$(cat ../file1)" = "master updated" && + test "$(cat ../file2)" = "master new" && + test "$(cat ../submod/bar)" = "branch1 submodule" && + git commit -m "branch1 resolved with mergetool - subdir" + ) ' test_expect_success 'mergetool skips autoresolved' ' - git checkout -b test4 branch1 && - git submodule update -N && - test_must_fail git merge master && - test -n "$(git ls-files -u)" && - ( 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 ) && - output="$(git mergetool --no-prompt)" && - test "$output" = "No files need merging" && - git reset --hard + git checkout -b test4 branch1 && + git submodule update -N && + test_must_fail git merge master && + test -n "$(git ls-files -u)" && + ( 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 ) && + output="$(git mergetool --no-prompt)" && + test "$output" = "No files need merging" && + git reset --hard ' test_expect_success 'mergetool merges all from subdir' ' - ( - cd subdir && - git config rerere.enabled false && - test_must_fail git merge master && - ( yes "r" | git mergetool ../submod ) && - ( yes "d" "d" | git mergetool --no-prompt ) && - test "$(cat ../file1)" = "master updated" && - test "$(cat ../file2)" = "master new" && - test "$(cat file3)" = "master new sub" && - ( cd .. && git submodule update -N ) && - test "$(cat ../submod/bar)" = "master submodule" && - git commit -m "branch2 resolved by mergetool from subdir" - ) + ( + cd subdir && + test_config rerere.enabled false && + test_must_fail git merge master && + ( yes "r" | git mergetool ../submod ) && + ( yes "d" "d" | git mergetool --no-prompt ) && + test "$(cat ../file1)" = "master updated" && + test "$(cat ../file2)" = "master new" && + test "$(cat file3)" = "master new sub" && + ( cd .. && git submodule update -N ) && + test "$(cat ../submod/bar)" = "master submodule" && + git commit -m "branch2 resolved by mergetool from subdir" + ) ' test_expect_success 'mergetool skips resolved paths when rerere is active' ' - git config rerere.enabled true && - rm -rf .git/rr-cache && - git checkout -b test5 branch1 - git submodule update -N && - test_must_fail git merge master >/dev/null 2>&1 && - ( yes "l" | git mergetool --no-prompt submod >/dev/null 2>&1 ) && - ( yes "d" "d" | git mergetool --no-prompt >/dev/null 2>&1 ) && - git submodule update -N && - output="$(yes "n" | git mergetool --no-prompt)" && - test "$output" = "No files need merging" && - git reset --hard + test_config rerere.enabled true && + rm -rf .git/rr-cache && + git checkout -b test5 branch1 && + git submodule update -N && + test_must_fail git merge master >/dev/null 2>&1 && + ( yes "l" | git mergetool --no-prompt submod >/dev/null 2>&1 ) && + ( yes "d" "d" | git mergetool --no-prompt >/dev/null 2>&1 ) && + git submodule update -N && + output="$(yes "n" | git mergetool --no-prompt)" && + test "$output" = "No files need merging" && + git reset --hard ' test_expect_success 'conflicted stash sets up rerere' ' - git config rerere.enabled true && - git checkout stash1 && - echo "Conflicting stash content" >file11 && - git stash && - - git checkout --detach stash2 && - test_must_fail git stash apply && - - test -n "$(git ls-files -u)" && - conflicts="$(git rerere remaining)" && - test "$conflicts" = "file11" && - output="$(git mergetool --no-prompt)" && - test "$output" != "No files need merging" && - - git commit -am "save the stash resolution" && - - git reset --hard stash2 && - test_must_fail git stash apply && - - test -n "$(git ls-files -u)" && - conflicts="$(git rerere remaining)" && - test -z "$conflicts" && - output="$(git mergetool --no-prompt)" && - test "$output" = "No files need merging" + test_config rerere.enabled true && + git checkout stash1 && + echo "Conflicting stash content" >file11 && + git stash && + + git checkout --detach stash2 && + test_must_fail git stash apply && + + test -n "$(git ls-files -u)" && + conflicts="$(git rerere remaining)" && + test "$conflicts" = "file11" && + output="$(git mergetool --no-prompt)" && + test "$output" != "No files need merging" && + + git commit -am "save the stash resolution" && + + git reset --hard stash2 && + test_must_fail git stash apply && + + test -n "$(git ls-files -u)" && + conflicts="$(git rerere remaining)" && + test -z "$conflicts" && + output="$(git mergetool --no-prompt)" && + test "$output" = "No files need merging" ' test_expect_success 'mergetool takes partial path' ' - git reset --hard - git config rerere.enabled false && - git checkout -b test12 branch1 && - git submodule update -N && - test_must_fail git merge master && - - #should not 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 + git reset --hard && + test_config rerere.enabled false && + git checkout -b test12 branch1 && + git submodule update -N && + test_must_fail git merge master && + + ( 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 && - mv submod submod-movedaside && - git rm --cached submod && - git commit -m "Submodule deleted from branch" && - git checkout -b test6.a test6 && - test_must_fail git merge master && - test -n "$(git ls-files -u)" && - ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && - ( yes "" | git mergetool both >/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 && - test "$(cat submod/bar)" = "branch1 submodule" && - git submodule update -N && - test "$(cat submod/bar)" = "master submodule" && - output="$(git mergetool --no-prompt)" && - test "$output" = "No files need merging" && - git commit -m "Merge resolved by keeping module" && - - mv submod submod-movedaside && - git checkout -b test6.b test6 && - git submodule update -N && - test_must_fail git merge master && - test -n "$(git ls-files -u)" && - ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && - ( yes "" | git mergetool both >/dev/null 2>&1 ) && - ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && - ( yes "l" | git mergetool submod ) && - test ! -e submod && - output="$(git mergetool --no-prompt)" && - test "$output" = "No files need merging" && - git commit -m "Merge resolved by deleting module" && - - mv submod-movedaside submod && - git checkout -b test6.c master && - git submodule update -N && - test_must_fail git merge test6 && - test -n "$(git ls-files -u)" && - ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && - ( yes "" | git mergetool both >/dev/null 2>&1 ) && - ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && - ( yes "r" | git mergetool submod ) && - test ! -e submod && - test -d submod.orig && - git submodule update -N && - output="$(git mergetool --no-prompt)" && - test "$output" = "No files need merging" && - git commit -m "Merge resolved by deleting module" && - mv submod.orig submod && - - git checkout -b test6.d master && - git submodule update -N && - test_must_fail git merge test6 && - test -n "$(git ls-files -u)" && - ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && - ( yes "" | git mergetool both >/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" && - git submodule update -N && - test "$(cat submod/bar)" = "master submodule" && - output="$(git mergetool --no-prompt)" && - test "$output" = "No files need merging" && - git commit -m "Merge resolved by keeping module" && - git reset --hard HEAD + git checkout -b test6 branch1 && + git submodule update -N && + mv submod submod-movedaside && + git rm --cached submod && + git commit -m "Submodule deleted from branch" && + git checkout -b test6.a test6 && + test_must_fail git merge master && + test -n "$(git ls-files -u)" && + ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && + ( yes "" | git mergetool both >/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 && + test "$(cat submod/bar)" = "branch1 submodule" && + git submodule update -N && + test "$(cat submod/bar)" = "master submodule" && + output="$(git mergetool --no-prompt)" && + test "$output" = "No files need merging" && + git commit -m "Merge resolved by keeping module" && + + mv submod submod-movedaside && + git checkout -b test6.b test6 && + git submodule update -N && + test_must_fail git merge master && + test -n "$(git ls-files -u)" && + ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && + ( yes "" | git mergetool both >/dev/null 2>&1 ) && + ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && + ( yes "l" | git mergetool submod ) && + test ! -e submod && + output="$(git mergetool --no-prompt)" && + test "$output" = "No files need merging" && + git commit -m "Merge resolved by deleting module" && + + mv submod-movedaside submod && + git checkout -b test6.c master && + git submodule update -N && + test_must_fail git merge test6 && + test -n "$(git ls-files -u)" && + ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && + ( yes "" | git mergetool both >/dev/null 2>&1 ) && + ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && + ( yes "r" | git mergetool submod ) && + test ! -e submod && + test -d submod.orig && + git submodule update -N && + output="$(git mergetool --no-prompt)" && + test "$output" = "No files need merging" && + git commit -m "Merge resolved by deleting module" && + mv submod.orig submod && + + git checkout -b test6.d master && + git submodule update -N && + test_must_fail git merge test6 && + test -n "$(git ls-files -u)" && + ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && + ( yes "" | git mergetool both >/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" && + git submodule update -N && + test "$(cat submod/bar)" = "master submodule" && + output="$(git mergetool --no-prompt)" && + test "$output" = "No files need merging" && + git commit -m "Merge resolved by keeping module" && + git reset --hard HEAD ' test_expect_success 'file vs modified submodule' ' - git checkout -b test7 branch1 && - git submodule update -N && - mv submod submod-movedaside && - git rm --cached submod && - echo not a submodule >submod && - git add submod && - git commit -m "Submodule path becomes file" && - git checkout -b test7.a branch1 && - test_must_fail git merge master && - test -n "$(git ls-files -u)" && - ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && - ( yes "" | git mergetool both >/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 && - test "$(cat submod/bar)" = "branch1 submodule" && - git submodule update -N && - test "$(cat submod/bar)" = "master submodule" && - output="$(git mergetool --no-prompt)" && - test "$output" = "No files need merging" && - git commit -m "Merge resolved by keeping module" && - - mv submod submod-movedaside && - git checkout -b test7.b test7 && - test_must_fail git merge master && - test -n "$(git ls-files -u)" && - ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && - ( yes "" | git mergetool both >/dev/null 2>&1 ) && - ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && - ( yes "l" | git mergetool submod ) && - git submodule update -N && - test "$(cat submod)" = "not a submodule" && - output="$(git mergetool --no-prompt)" && - test "$output" = "No files need merging" && - git commit -m "Merge resolved by keeping file" && - - git checkout -b test7.c master && - rmdir submod && mv submod-movedaside submod && - test ! -e submod.orig && - git submodule update -N && - test_must_fail git merge test7 && - test -n "$(git ls-files -u)" && - ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && - ( yes "" | git mergetool both >/dev/null 2>&1 ) && - ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && - ( yes "r" | git mergetool submod ) && - test -d submod.orig && - git submodule update -N && - test "$(cat submod)" = "not a submodule" && - output="$(git mergetool --no-prompt)" && - test "$output" = "No files need merging" && - git commit -m "Merge resolved by keeping file" && - - git checkout -b test7.d master && - rmdir submod && mv submod.orig submod && - git submodule update -N && - test_must_fail git merge test7 && - test -n "$(git ls-files -u)" && - ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && - ( yes "" | git mergetool both>/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" && - git submodule update -N && - test "$(cat submod/bar)" = "master submodule" && - output="$(git mergetool --no-prompt)" && - test "$output" = "No files need merging" && - git commit -m "Merge resolved by keeping module" + git checkout -b test7 branch1 && + git submodule update -N && + mv submod submod-movedaside && + git rm --cached submod && + echo not a submodule >submod && + git add submod && + git commit -m "Submodule path becomes file" && + git checkout -b test7.a branch1 && + test_must_fail git merge master && + test -n "$(git ls-files -u)" && + ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && + ( yes "" | git mergetool both >/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 && + test "$(cat submod/bar)" = "branch1 submodule" && + git submodule update -N && + test "$(cat submod/bar)" = "master submodule" && + output="$(git mergetool --no-prompt)" && + test "$output" = "No files need merging" && + git commit -m "Merge resolved by keeping module" && + + mv submod submod-movedaside && + git checkout -b test7.b test7 && + test_must_fail git merge master && + test -n "$(git ls-files -u)" && + ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && + ( yes "" | git mergetool both >/dev/null 2>&1 ) && + ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && + ( yes "l" | git mergetool submod ) && + git submodule update -N && + test "$(cat submod)" = "not a submodule" && + output="$(git mergetool --no-prompt)" && + test "$output" = "No files need merging" && + git commit -m "Merge resolved by keeping file" && + + git checkout -b test7.c master && + rmdir submod && mv submod-movedaside submod && + test ! -e submod.orig && + git submodule update -N && + test_must_fail git merge test7 && + test -n "$(git ls-files -u)" && + ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && + ( yes "" | git mergetool both >/dev/null 2>&1 ) && + ( yes "d" | git mergetool file11 file12 >/dev/null 2>&1 ) && + ( yes "r" | git mergetool submod ) && + test -d submod.orig && + git submodule update -N && + test "$(cat submod)" = "not a submodule" && + output="$(git mergetool --no-prompt)" && + test "$output" = "No files need merging" && + git commit -m "Merge resolved by keeping file" && + + git checkout -b test7.d master && + rmdir submod && mv submod.orig submod && + git submodule update -N && + test_must_fail git merge test7 && + test -n "$(git ls-files -u)" && + ( yes "" | git mergetool file1 file2 spaced\ name subdir/file3 >/dev/null 2>&1 ) && + ( yes "" | git mergetool both>/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" && + git submodule update -N && + test "$(cat submod/bar)" = "master submodule" && + output="$(git mergetool --no-prompt)" && + test "$output" = "No files need merging" && + git commit -m "Merge resolved by keeping module" ' test_expect_success 'submodule in subdirectory' ' - git checkout -b test10 branch1 && - git submodule update -N && - ( - cd subdir && - test_create_repo subdir_module && + git checkout -b test10 branch1 && + git submodule update -N && + ( + cd subdir && + test_create_repo subdir_module && + ( + cd subdir_module && + : >file15 && + git add file15 && + git commit -m "add initial versions" + ) + ) && + git submodule add git://example.com/subsubmodule subdir/subdir_module && + git add subdir/subdir_module && + git commit -m "add submodule in subdirectory" && + + git checkout -b test10.a test10 && + git submodule update -N && ( - cd subdir_module && - : >file15 && - git add file15 && - git commit -m "add initial versions" - ) - ) && - git submodule add git://example.com/subsubmodule subdir/subdir_module && - git add subdir/subdir_module && - git commit -m "add submodule in subdirectory" && - - git checkout -b test10.a test10 && - git submodule update -N && - ( - cd subdir/subdir_module && - git checkout -b super10.a && - echo test10.a >file15 && - git add file15 && - git commit -m "on branch 10.a" - ) && - git add subdir/subdir_module && - git commit -m "change submodule in subdirectory on test10.a" && - - git checkout -b test10.b test10 && - git submodule update -N && - ( cd subdir/subdir_module && - git checkout -b super10.b && - echo test10.b >file15 && - git add file15 && - git commit -m "on branch 10.b" - ) && - git add subdir/subdir_module && - git commit -m "change submodule in subdirectory on test10.b" && - - test_must_fail git merge test10.a >/dev/null 2>&1 && - ( - cd subdir && - ( yes "l" | git mergetool subdir_module ) - ) && - test "$(cat subdir/subdir_module/file15)" = "test10.b" && - git submodule update -N && - test "$(cat subdir/subdir_module/file15)" = "test10.b" && - git reset --hard && - git submodule update -N && - - test_must_fail git merge test10.a >/dev/null 2>&1 && - ( yes "r" | git mergetool subdir/subdir_module ) && - test "$(cat subdir/subdir_module/file15)" = "test10.b" && - git submodule update -N && - test "$(cat subdir/subdir_module/file15)" = "test10.a" && - git commit -m "branch1 resolved with mergetool" && - rm -rf subdir/subdir_module + git checkout -b super10.a && + echo test10.a >file15 && + git add file15 && + git commit -m "on branch 10.a" + ) && + git add subdir/subdir_module && + git commit -m "change submodule in subdirectory on test10.a" && + + git checkout -b test10.b test10 && + git submodule update -N && + ( + cd subdir/subdir_module && + git checkout -b super10.b && + echo test10.b >file15 && + git add file15 && + git commit -m "on branch 10.b" + ) && + git add subdir/subdir_module && + git commit -m "change submodule in subdirectory on test10.b" && + + test_must_fail git merge test10.a >/dev/null 2>&1 && + ( + cd subdir && + ( yes "l" | git mergetool subdir_module ) + ) && + test "$(cat subdir/subdir_module/file15)" = "test10.b" && + git submodule update -N && + test "$(cat subdir/subdir_module/file15)" = "test10.b" && + git reset --hard && + git submodule update -N && + + test_must_fail git merge test10.a >/dev/null 2>&1 && + ( yes "r" | git mergetool subdir/subdir_module ) && + test "$(cat subdir/subdir_module/file15)" = "test10.b" && + git submodule update -N && + test "$(cat subdir/subdir_module/file15)" = "test10.a" && + git commit -m "branch1 resolved with mergetool" && + rm -rf subdir/subdir_module ' test_expect_success 'directory vs modified submodule' ' - git checkout -b test11 branch1 && - mv submod submod-movedaside && - git rm --cached submod && - mkdir submod && - echo not a submodule >submod/file16 && - git add submod/file16 && - git commit -m "Submodule path becomes directory" && - - test_must_fail git merge master && - test -n "$(git ls-files -u)" && - ( yes "l" | git mergetool submod ) && - test "$(cat submod/file16)" = "not a submodule" && - rm -rf submod.orig && - - git reset --hard >/dev/null 2>&1 && - test_must_fail git merge master && - test -n "$(git ls-files -u)" && - test ! -e submod.orig && - ( yes "r" | git mergetool submod ) && - test -d submod.orig && - test "$(cat submod.orig/file16)" = "not a submodule" && - rm -r submod.orig && - mv submod-movedaside/.git submod && - ( cd submod && git clean -f && git reset --hard ) && - git submodule update -N && - test "$(cat submod/bar)" = "master submodule" && - git reset --hard >/dev/null 2>&1 && rm -rf submod-movedaside && - - git checkout -b test11.c master && - git submodule update -N && - test_must_fail git merge test11 && - test -n "$(git ls-files -u)" && - ( yes "l" | git mergetool submod ) && - git submodule update -N && - test "$(cat submod/bar)" = "master submodule" && - - git reset --hard >/dev/null 2>&1 && - git submodule update -N && - test_must_fail git merge test11 && - test -n "$(git ls-files -u)" && - test ! -e submod.orig && - ( yes "r" | git mergetool submod ) && - test "$(cat submod/file16)" = "not a submodule" && - - git reset --hard master >/dev/null 2>&1 && - ( cd submod && git clean -f && git reset --hard ) && - git submodule update -N + git checkout -b test11 branch1 && + mv submod submod-movedaside && + git rm --cached submod && + mkdir submod && + echo not a submodule >submod/file16 && + git add submod/file16 && + git commit -m "Submodule path becomes directory" && + + test_must_fail git merge master && + test -n "$(git ls-files -u)" && + ( yes "l" | git mergetool submod ) && + test "$(cat submod/file16)" = "not a submodule" && + rm -rf submod.orig && + + git reset --hard >/dev/null 2>&1 && + test_must_fail git merge master && + test -n "$(git ls-files -u)" && + test ! -e submod.orig && + ( yes "r" | git mergetool submod ) && + test -d submod.orig && + test "$(cat submod.orig/file16)" = "not a submodule" && + rm -r submod.orig && + mv submod-movedaside/.git submod && + ( cd submod && git clean -f && git reset --hard ) && + git submodule update -N && + test "$(cat submod/bar)" = "master submodule" && + git reset --hard >/dev/null 2>&1 && rm -rf submod-movedaside && + + git checkout -b test11.c master && + git submodule update -N && + test_must_fail git merge test11 && + test -n "$(git ls-files -u)" && + ( yes "l" | git mergetool submod ) && + git submodule update -N && + test "$(cat submod/bar)" = "master submodule" && + + git reset --hard >/dev/null 2>&1 && + git submodule update -N && + test_must_fail git merge test11 && + test -n "$(git ls-files -u)" && + test ! -e submod.orig && + ( yes "r" | git mergetool submod ) && + test "$(cat submod/file16)" = "not a submodule" && + + git reset --hard master >/dev/null 2>&1 && + ( cd submod && git clean -f && git reset --hard ) && + git submodule update -N ' test_expect_success 'file with no base' ' - git checkout -b test13 branch1 && - test_must_fail git merge master && - git mergetool --no-prompt --tool mybase -- both && - >expected && - test_cmp both expected && - git reset --hard master >/dev/null 2>&1 + git checkout -b test13 branch1 && + test_must_fail git merge master && + git mergetool --no-prompt --tool mybase -- both && + >expected && + test_cmp both expected && + git reset --hard master >/dev/null 2>&1 ' test_expect_success 'custom commands override built-ins' ' - git checkout -b test14 branch1 && - git config mergetool.defaults.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" && - git config mergetool.defaults.trustExitCode true && - test_must_fail git merge master && - git mergetool --no-prompt --tool defaults -- both && - echo master both added >expected && - test_cmp both expected && - git config --unset mergetool.defaults.cmd && - git config --unset mergetool.defaults.trustExitCode && - git reset --hard master >/dev/null 2>&1 + git checkout -b test14 branch1 && + test_config mergetool.defaults.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" && + test_config mergetool.defaults.trustExitCode true && + test_must_fail git merge master && + git mergetool --no-prompt --tool defaults -- both && + echo master both added >expected && + test_cmp both expected && + git reset --hard master >/dev/null 2>&1 +' + +test_expect_success 'filenames seen by tools start with ./' ' + git checkout -b test15 branch1 && + test_config mergetool.writeToTemp false && + test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" && + test_config mergetool.myecho.trustExitCode true && + test_must_fail git merge master && + git mergetool --no-prompt --tool myecho -- both >actual && + grep ^\./both_LOCAL_ actual >/dev/null && + git reset --hard master >/dev/null 2>&1 +' + +test_expect_success 'temporary filenames are used with mergetool.writeToTemp' ' + git checkout -b test16 branch1 && + test_config mergetool.writeToTemp true && + test_config mergetool.myecho.cmd "echo \"\$LOCAL\"" && + test_config mergetool.myecho.trustExitCode true && + test_must_fail git merge master && + git mergetool --no-prompt --tool myecho -- both >actual && + test_must_fail grep ^\./both_LOCAL_ actual >/dev/null && + grep /both_LOCAL_ actual >/dev/null && + git reset --hard master >/dev/null 2>&1 ' test_done diff --git a/t/t7701-repack-unpack-unreachable.sh b/t/t7701-repack-unpack-unreachable.sh index b8d4cdea8c..aad8a9c64d 100755 --- a/t/t7701-repack-unpack-unreachable.sh +++ b/t/t7701-repack-unpack-unreachable.sh @@ -109,4 +109,17 @@ test_expect_success 'do not bother loosening old objects' ' test_must_fail git cat-file -p $obj2 ' +test_expect_success 'keep packed objects found only in index' ' + echo my-unique-content >file && + git add file && + git commit -m "make it reachable" && + git gc && + git reset HEAD^ && + git reflog expire --expire=now --all && + git add file && + test-chmtime =-86400 .git/objects/pack/* && + git gc --prune=1.hour.ago && + git cat-file blob :file +' + test_done diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh index dc30a514bf..ea35a0241c 100755 --- a/t/t7800-difftool.sh +++ b/t/t7800-difftool.sh @@ -76,6 +76,54 @@ test_expect_success PERL 'difftool forwards arguments to diff' ' rm for-diff ' +test_expect_success PERL 'difftool ignores exit code' ' + test_config difftool.error.cmd false && + git difftool -y -t error branch +' + +test_expect_success PERL 'difftool forwards exit code with --trust-exit-code' ' + test_config difftool.error.cmd false && + test_must_fail git difftool -y --trust-exit-code -t error branch +' + +test_expect_success PERL 'difftool forwards exit code with --trust-exit-code for built-ins' ' + test_config difftool.vimdiff.path false && + test_must_fail git difftool -y --trust-exit-code -t vimdiff branch +' + +test_expect_success PERL 'difftool honors difftool.trustExitCode = true' ' + test_config difftool.error.cmd false && + test_config difftool.trustExitCode true && + test_must_fail git difftool -y -t error branch +' + +test_expect_success PERL 'difftool honors difftool.trustExitCode = false' ' + test_config difftool.error.cmd false && + test_config difftool.trustExitCode false && + git difftool -y -t error branch +' + +test_expect_success PERL 'difftool ignores exit code with --no-trust-exit-code' ' + test_config difftool.error.cmd false && + test_config difftool.trustExitCode true && + git difftool -y --no-trust-exit-code -t error branch +' + +test_expect_success PERL 'difftool stops on error with --trust-exit-code' ' + test_when_finished "rm -f for-diff .git/fail-right-file" && + test_when_finished "git reset -- for-diff" && + write_script .git/fail-right-file <<-\EOF && + echo "$2" + exit 1 + EOF + >for-diff && + git add for-diff && + echo file >expect && + test_must_fail git difftool -y --trust-exit-code \ + --extcmd .git/fail-right-file branch >actual && + test_cmp expect actual +' + test_expect_success PERL 'difftool honors --gui' ' difftool_test_setup && test_config merge.tool bogus-tool && @@ -301,6 +349,14 @@ test_expect_success PERL 'say no to the second file' ' ! grep br2 output ' +test_expect_success PERL 'ending prompt input with EOF' ' + git difftool -x cat branch </dev/null >output && + ! grep master output && + ! grep branch output && + ! grep m2 output && + ! grep br2 output +' + test_expect_success PERL 'difftool --tool-help' ' git difftool --tool-help >output && grep tool output diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh index 40615debc4..028ffe4a05 100755 --- a/t/t7810-grep.sh +++ b/t/t7810-grep.sh @@ -1202,4 +1202,98 @@ test_expect_success LIBPCRE 'grep -P "^ "' ' test_cmp expected actual ' +cat >expected <<EOF +space-line without leading space1 +space: line <RED>with <RESET>leading space1 +space: line <RED>with <RESET>leading <RED>space2<RESET> +space: line <RED>with <RESET>leading space3 +space:line without leading <RED>space2<RESET> +EOF + +test_expect_success 'grep --color -e A -e B with context' ' + test_config color.grep.context normal && + test_config color.grep.filename normal && + test_config color.grep.function normal && + test_config color.grep.linenumber normal && + test_config color.grep.matchContext normal && + test_config color.grep.matchSelected red && + test_config color.grep.selected normal && + test_config color.grep.separator normal && + + git grep --color=always -C2 -e "with " -e space2 space | + test_decode_color >actual && + test_cmp expected actual +' + +cat >expected <<EOF +space-line without leading space1 +space- line with leading space1 +space: line <RED>with <RESET>leading <RED>space2<RESET> +space- line with leading space3 +space-line without leading space2 +EOF + +test_expect_success 'grep --color -e A --and -e B with context' ' + test_config color.grep.context normal && + test_config color.grep.filename normal && + test_config color.grep.function normal && + test_config color.grep.linenumber normal && + test_config color.grep.matchContext normal && + test_config color.grep.matchSelected red && + test_config color.grep.selected normal && + test_config color.grep.separator normal && + + git grep --color=always -C2 -e "with " --and -e space2 space | + test_decode_color >actual && + test_cmp expected actual +' + +cat >expected <<EOF +space-line without leading space1 +space: line <RED>with <RESET>leading space1 +space- line with leading space2 +space: line <RED>with <RESET>leading space3 +space-line without leading space2 +EOF + +test_expect_success 'grep --color -e A --and --not -e B with context' ' + test_config color.grep.context normal && + test_config color.grep.filename normal && + test_config color.grep.function normal && + test_config color.grep.linenumber normal && + test_config color.grep.matchContext normal && + test_config color.grep.matchSelected red && + test_config color.grep.selected normal && + test_config color.grep.separator normal && + + git grep --color=always -C2 -e "with " --and --not -e space2 space | + test_decode_color >actual && + test_cmp expected actual +' + +cat >expected <<EOF +hello.c-#include <stdio.h> +hello.c=int main(int argc, const char **argv) +hello.c-{ +hello.c: pr<RED>int<RESET>f("<RED>Hello<RESET> world.\n"); +hello.c- return 0; +hello.c- /* char ?? */ +hello.c-} +EOF + +test_expect_success 'grep --color -e A --and -e B -p with context' ' + test_config color.grep.context normal && + test_config color.grep.filename normal && + test_config color.grep.function normal && + test_config color.grep.linenumber normal && + test_config color.grep.matchContext normal && + test_config color.grep.matchSelected red && + test_config color.grep.selected normal && + test_config color.grep.separator normal && + + git grep --color=always -p -C3 -e int --and -e Hello --no-index hello.c | + test_decode_color >actual && + test_cmp expected actual +' + test_done diff --git a/t/t8005-blame-i18n.sh b/t/t8005-blame-i18n.sh index a6e73d0635..847d098c09 100755 --- a/t/t8005-blame-i18n.sh +++ b/t/t8005-blame-i18n.sh @@ -33,7 +33,7 @@ author $SJIS_NAME summary $SJIS_MSG EOF -test_expect_success NOT_MINGW \ +test_expect_success !MINGW \ 'blame respects i18n.commitencoding' ' git blame --incremental file | \ egrep "^(author|summary) " > actual && @@ -49,7 +49,7 @@ author $EUC_JAPAN_NAME summary $EUC_JAPAN_MSG EOF -test_expect_success NOT_MINGW \ +test_expect_success !MINGW \ 'blame respects i18n.logoutputencoding' ' git config i18n.logoutputencoding eucJP && git blame --incremental file | \ @@ -66,7 +66,7 @@ author $UTF8_NAME summary $UTF8_MSG EOF -test_expect_success NOT_MINGW \ +test_expect_success !MINGW \ 'blame respects --encoding=UTF-8' ' git blame --incremental --encoding=UTF-8 file | \ egrep "^(author|summary) " > actual && @@ -82,7 +82,7 @@ author $UTF8_NAME summary $UTF8_MSG EOF -test_expect_success NOT_MINGW \ +test_expect_success !MINGW \ 'blame respects --encoding=none' ' git blame --incremental --encoding=none file | \ egrep "^(author|summary) " > actual && diff --git a/t/t9119-git-svn-info.sh b/t/t9119-git-svn-info.sh index ff19695e77..f16f3234a1 100755 --- a/t/t9119-git-svn-info.sh +++ b/t/t9119-git-svn-info.sh @@ -74,6 +74,36 @@ test_expect_success 'info .' " test_cmp_info expected.info-dot actual.info-dot " +test_expect_success 'info $(pwd)' ' + (cd svnwc; svn info "$(pwd)") >expected.info-pwd && + (cd gitwc; git svn info "$(pwd)") >actual.info-pwd && + grep -v ^Path: <expected.info-pwd >expected.info-np && + grep -v ^Path: <actual.info-pwd >actual.info-np && + test_cmp_info expected.info-np actual.info-np && + test "$(sed -ne \"/^Path:/ s!/svnwc!!\" <expected.info-pwd)" = \ + "$(sed -ne \"/^Path:/ s!/gitwc!!\" <actual.info-pwd)" + ' + +test_expect_success 'info $(pwd)/../___wc' ' + (cd svnwc; svn info "$(pwd)/../svnwc") >expected.info-pwd && + (cd gitwc; git svn info "$(pwd)/../gitwc") >actual.info-pwd && + grep -v ^Path: <expected.info-pwd >expected.info-np && + grep -v ^Path: <actual.info-pwd >actual.info-np && + test_cmp_info expected.info-np actual.info-np && + test "$(sed -ne \"/^Path:/ s!/svnwc!!\" <expected.info-pwd)" = \ + "$(sed -ne \"/^Path:/ s!/gitwc!!\" <actual.info-pwd)" + ' + +test_expect_success 'info $(pwd)/../___wc//file' ' + (cd svnwc; svn info "$(pwd)/../svnwc//file") >expected.info-pwd && + (cd gitwc; git svn info "$(pwd)/../gitwc//file") >actual.info-pwd && + grep -v ^Path: <expected.info-pwd >expected.info-np && + grep -v ^Path: <actual.info-pwd >actual.info-np && + test_cmp_info expected.info-np actual.info-np && + test "$(sed -ne \"/^Path:/ s!/svnwc!!\" <expected.info-pwd)" = \ + "$(sed -ne \"/^Path:/ s!/gitwc!!\" <actual.info-pwd)" + ' + test_expect_success 'info --url .' ' test "$(cd gitwc; git svn info --url .)" = "$quoted_svnrepo" ' diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh index 5fc9ef262a..37c2d633f0 100755 --- a/t/t9300-fast-import.sh +++ b/t/t9300-fast-import.sh @@ -347,36 +347,6 @@ test_expect_success 'B: fail on invalid blob sha1' ' rm -f .git/objects/pack_* .git/objects/index_* cat >input <<INPUT_END -commit .badbranchname -committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE -data <<COMMIT -corrupt -COMMIT - -from refs/heads/master - -INPUT_END -test_expect_success 'B: fail on invalid branch name ".badbranchname"' ' - test_must_fail git fast-import <input -' -rm -f .git/objects/pack_* .git/objects/index_* - -cat >input <<INPUT_END -commit bad[branch]name -committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE -data <<COMMIT -corrupt -COMMIT - -from refs/heads/master - -INPUT_END -test_expect_success 'B: fail on invalid branch name "bad[branch]name"' ' - test_must_fail git fast-import <input -' -rm -f .git/objects/pack_* .git/objects/index_* - -cat >input <<INPUT_END commit TEMP_TAG committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <<COMMIT @@ -2336,7 +2306,7 @@ test_expect_success 'R: cat-blob-fd must be a nonnegative integer' ' test_must_fail git fast-import --cat-blob-fd=-1 </dev/null ' -test_expect_success NOT_MINGW 'R: print old blob' ' +test_expect_success !MINGW 'R: print old blob' ' blob=$(echo "yes it can" | git hash-object -w --stdin) && cat >expect <<-EOF && ${blob} blob 11 @@ -2348,7 +2318,7 @@ test_expect_success NOT_MINGW 'R: print old blob' ' test_cmp expect actual ' -test_expect_success NOT_MINGW 'R: in-stream cat-blob-fd not respected' ' +test_expect_success !MINGW 'R: in-stream cat-blob-fd not respected' ' echo hello >greeting && blob=$(git hash-object -w greeting) && cat >expect <<-EOF && @@ -2369,7 +2339,7 @@ test_expect_success NOT_MINGW 'R: in-stream cat-blob-fd not respected' ' test_cmp expect actual.1 ' -test_expect_success NOT_MINGW 'R: print new blob' ' +test_expect_success !MINGW 'R: print new blob' ' blob=$(echo "yep yep yep" | git hash-object --stdin) && cat >expect <<-EOF && ${blob} blob 12 @@ -2387,7 +2357,7 @@ test_expect_success NOT_MINGW 'R: print new blob' ' test_cmp expect actual ' -test_expect_success NOT_MINGW 'R: print new blob by sha1' ' +test_expect_success !MINGW 'R: print new blob by sha1' ' blob=$(echo "a new blob named by sha1" | git hash-object --stdin) && cat >expect <<-EOF && ${blob} blob 25 @@ -2687,7 +2657,7 @@ test_expect_success 'R: verify created pack' ' test_expect_success \ 'R: verify written objects' \ 'git --git-dir=R/.git cat-file blob big-file:big1 >actual && - test_cmp expect actual && + test_cmp_bin expect actual && a=$(git --git-dir=R/.git rev-parse big-file:big1) && b=$(git --git-dir=R/.git rev-parse big-file:big2) && test $a = $b' @@ -2866,7 +2836,7 @@ test_expect_success 'S: notemodify with garbage after sha1 dataref must fail' ' # # notemodify, mark in commit-ish # -test_expect_success 'S: notemodify with garbarge after mark commit-ish must fail' ' +test_expect_success 'S: notemodify with garbage after mark commit-ish must fail' ' test_must_fail git fast-import --import-marks=marks <<-EOF 2>err && commit refs/heads/Snotes committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE @@ -3017,4 +2987,108 @@ test_expect_success 'T: empty reset doesnt delete branch' ' git rev-parse --verify refs/heads/not-to-delete ' +### +### series U (filedelete) +### + +cat >input <<INPUT_END +commit refs/heads/U +committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE +data <<COMMIT +test setup +COMMIT +M 100644 inline hello.c +data <<BLOB +blob 1 +BLOB +M 100644 inline good/night.txt +data <<BLOB +sleep well +BLOB +M 100644 inline good/bye.txt +data <<BLOB +au revoir +BLOB + +INPUT_END + +test_expect_success 'U: initialize for U tests' ' + git fast-import <input +' + +cat >input <<INPUT_END +commit refs/heads/U +committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE +data <<COMMIT +delete good/night.txt +COMMIT +from refs/heads/U^0 +D good/night.txt + +INPUT_END + +test_expect_success 'U: filedelete file succeeds' ' + git fast-import <input +' + +cat >expect <<EOF +:100644 000000 2907ebb4bf85d91bf0716bb3bd8a68ef48d6da76 0000000000000000000000000000000000000000 D good/night.txt +EOF + +git diff-tree -M -r U^1 U >actual + +test_expect_success 'U: validate file delete result' ' + compare_diff_raw expect actual +' + +cat >input <<INPUT_END +commit refs/heads/U +committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE +data <<COMMIT +delete good dir +COMMIT +from refs/heads/U^0 +D good + +INPUT_END + +test_expect_success 'U: filedelete directory succeeds' ' + git fast-import <input +' + +cat >expect <<EOF +:100644 000000 69cb75792f55123d8389c156b0b41c2ff00ed507 0000000000000000000000000000000000000000 D good/bye.txt +EOF + +git diff-tree -M -r U^1 U >actual + +test_expect_success 'U: validate directory delete result' ' + compare_diff_raw expect actual +' + +cat >input <<INPUT_END +commit refs/heads/U +committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE +data <<COMMIT +must succeed +COMMIT +from refs/heads/U^0 +D "" + +INPUT_END + +test_expect_success 'U: filedelete root succeeds' ' + git fast-import <input +' + +cat >expect <<EOF +:100644 000000 c18147dc648481eeb65dc5e66628429a64843327 0000000000000000000000000000000000000000 D hello.c +EOF + +git diff-tree -M -r U^1 U >actual + +test_expect_success 'U: validate root delete result' ' + compare_diff_raw expect actual +' + test_done diff --git a/t/t9351-fast-export-anonymize.sh b/t/t9351-fast-export-anonymize.sh new file mode 100755 index 0000000000..897dc50907 --- /dev/null +++ b/t/t9351-fast-export-anonymize.sh @@ -0,0 +1,112 @@ +#!/bin/sh + +test_description='basic tests for fast-export --anonymize' +. ./test-lib.sh + +test_expect_success 'setup simple repo' ' + test_commit base && + test_commit foo && + git checkout -b other HEAD^ && + mkdir subdir && + test_commit subdir/bar && + test_commit subdir/xyzzy && + git tag -m "annotated tag" mytag +' + +test_expect_success 'export anonymized stream' ' + git fast-export --anonymize --all >stream +' + +# this also covers commit messages +test_expect_success 'stream omits path names' ' + ! grep base stream && + ! grep foo stream && + ! grep subdir stream && + ! grep bar stream && + ! grep xyzzy stream +' + +test_expect_success 'stream allows master as refname' ' + grep master stream +' + +test_expect_success 'stream omits other refnames' ' + ! grep other stream && + ! grep mytag stream +' + +test_expect_success 'stream omits identities' ' + ! grep "$GIT_COMMITTER_NAME" stream && + ! grep "$GIT_COMMITTER_EMAIL" stream && + ! grep "$GIT_AUTHOR_NAME" stream && + ! grep "$GIT_AUTHOR_EMAIL" stream +' + +test_expect_success 'stream omits tag message' ' + ! grep "annotated tag" stream +' + +# NOTE: we chdir to the new, anonymized repository +# after this. All further tests should assume this. +test_expect_success 'import stream to new repository' ' + git init new && + cd new && + git fast-import <../stream +' + +test_expect_success 'result has two branches' ' + git for-each-ref --format="%(refname)" refs/heads >branches && + test_line_count = 2 branches && + other_branch=$(grep -v refs/heads/master branches) +' + +test_expect_success 'repo has original shape and timestamps' ' + shape () { + git log --format="%m %ct" --left-right --boundary "$@" + } && + (cd .. && shape master...other) >expect && + shape master...$other_branch >actual && + test_cmp expect actual +' + +test_expect_success 'root tree has original shape' ' + # the output entries are not necessarily in the same + # order, but we know at least that we will have one tree + # and one blob, so just check the sorted order + cat >expect <<-\EOF && + blob + tree + EOF + git ls-tree $other_branch >root && + cut -d" " -f2 <root | sort >actual && + test_cmp expect actual +' + +test_expect_success 'paths in subdir ended up in one tree' ' + cat >expect <<-\EOF && + blob + blob + EOF + tree=$(grep tree root | cut -f2) && + git ls-tree $other_branch:$tree >tree && + cut -d" " -f2 <tree >actual && + test_cmp expect actual +' + +test_expect_success 'tag points to branch tip' ' + git rev-parse $other_branch >expect && + git for-each-ref --format="%(*objectname)" | grep . >actual && + test_cmp expect actual +' + +test_expect_success 'idents are shared' ' + git log --all --format="%an <%ae>" >authors && + sort -u authors >unique && + test_line_count = 1 unique && + git log --all --format="%cn <%ce>" >committers && + sort -u committers >unique && + test_line_count = 1 unique && + ! test_cmp authors committers +' + +test_done diff --git a/t/t9603-cvsimport-patchsets.sh b/t/t9603-cvsimport-patchsets.sh index 52034c8f77..c4c3c49546 100755 --- a/t/t9603-cvsimport-patchsets.sh +++ b/t/t9603-cvsimport-patchsets.sh @@ -16,7 +16,7 @@ test_description='git cvsimport testing for correct patchset estimation' setup_cvs_test_repository t9603 -test_expect_failure 'import with criss cross times on revisions' ' +test_expect_failure PERL 'import with criss cross times on revisions' ' git cvsimport -p"-x" -C module-git module && (cd module-git && diff --git a/t/t9604-cvsimport-timestamps.sh b/t/t9604-cvsimport-timestamps.sh index 1fd51423ee..a4b3db24bd 100755 --- a/t/t9604-cvsimport-timestamps.sh +++ b/t/t9604-cvsimport-timestamps.sh @@ -5,7 +5,7 @@ test_description='git cvsimport timestamps' setup_cvs_test_repository t9604 -test_expect_success 'check timestamps are UTC (TZ=CST6CDT)' ' +test_expect_success PERL 'check timestamps are UTC (TZ=CST6CDT)' ' TZ=CST6CDT git cvsimport -p"-x" -C module-1 module && git cvsimport -p"-x" -C module-1 module && @@ -34,7 +34,7 @@ test_expect_success 'check timestamps are UTC (TZ=CST6CDT)' ' test_cmp actual-1 expect-1 ' -test_expect_success 'check timestamps with author-specific timezones' ' +test_expect_success PERL 'check timestamps with author-specific timezones' ' cat >cvs-authors <<-EOF && user1=User One <user1@domain.org> diff --git a/t/t9809-git-p4-client-view.sh b/t/t9809-git-p4-client-view.sh index 23a827fa77..897b3c3034 100755 --- a/t/t9809-git-p4-client-view.sh +++ b/t/t9809-git-p4-client-view.sh @@ -365,7 +365,7 @@ test_expect_success 'wildcard files submit back to p4, client-spec case' ' ( cd "$git" && echo git-wild-hash >dir1/git-wild#hash && - if test_have_prereq NOT_MINGW NOT_CYGWIN + if test_have_prereq !MINGW,!CYGWIN then echo git-wild-star >dir1/git-wild\*star fi && @@ -379,7 +379,7 @@ test_expect_success 'wildcard files submit back to p4, client-spec case' ' ( cd "$cli" && test_path_is_file dir1/git-wild#hash && - if test_have_prereq NOT_MINGW NOT_CYGWIN + if test_have_prereq !MINGW,!CYGWIN then test_path_is_file dir1/git-wild\*star fi && diff --git a/t/t9812-git-p4-wildcards.sh b/t/t9812-git-p4-wildcards.sh index c7472cbf54..0206771fbb 100755 --- a/t/t9812-git-p4-wildcards.sh +++ b/t/t9812-git-p4-wildcards.sh @@ -14,7 +14,7 @@ test_expect_success 'add p4 files with wildcards in the names' ' printf "file2\nhas\nsome\nrandom\ntext\n" >file2 && p4 add file2 && echo file-wild-hash >file-wild#hash && - if test_have_prereq NOT_MINGW NOT_CYGWIN + if test_have_prereq !MINGW,!CYGWIN then echo file-wild-star >file-wild\*star fi && @@ -31,7 +31,7 @@ test_expect_success 'wildcard files git p4 clone' ' ( cd "$git" && test -f file-wild#hash && - if test_have_prereq NOT_MINGW NOT_CYGWIN + if test_have_prereq !MINGW,!CYGWIN then test -f file-wild\*star fi && @@ -46,7 +46,7 @@ test_expect_success 'wildcard files submit back to p4, add' ' ( cd "$git" && echo git-wild-hash >git-wild#hash && - if test_have_prereq NOT_MINGW NOT_CYGWIN + if test_have_prereq !MINGW,!CYGWIN then echo git-wild-star >git-wild\*star fi && @@ -60,7 +60,7 @@ test_expect_success 'wildcard files submit back to p4, add' ' ( cd "$cli" && test_path_is_file git-wild#hash && - if test_have_prereq NOT_MINGW NOT_CYGWIN + if test_have_prereq !MINGW,!CYGWIN then test_path_is_file git-wild\*star fi && @@ -75,7 +75,7 @@ test_expect_success 'wildcard files submit back to p4, modify' ' ( cd "$git" && echo new-line >>git-wild#hash && - if test_have_prereq NOT_MINGW NOT_CYGWIN + if test_have_prereq !MINGW,!CYGWIN then echo new-line >>git-wild\*star fi && @@ -89,7 +89,7 @@ test_expect_success 'wildcard files submit back to p4, modify' ' ( cd "$cli" && test_line_count = 2 git-wild#hash && - if test_have_prereq NOT_MINGW NOT_CYGWIN + if test_have_prereq !MINGW,!CYGWIN then test_line_count = 2 git-wild\*star fi && @@ -152,7 +152,7 @@ test_expect_success 'wildcard files submit back to p4, delete' ' ( cd "$cli" && test_path_is_missing git-wild#hash && - if test_have_prereq NOT_MINGW NOT_CYGWIN + if test_have_prereq !MINGW,!CYGWIN then test_path_is_missing git-wild\*star fi && diff --git a/t/t9815-git-p4-submit-fail.sh b/t/t9815-git-p4-submit-fail.sh index 1243d96092..4cff6a760f 100755 --- a/t/t9815-git-p4-submit-fail.sh +++ b/t/t9815-git-p4-submit-fail.sh @@ -417,7 +417,7 @@ test_expect_success 'cleanup chmod after submit cancel' ' ! p4 fstat -T action text && test_path_is_file text+x && ! p4 fstat -T action text+x && - if test_have_prereq NOT_CYGWIN + if test_have_prereq !CYGWIN then stat --format=%A text | egrep ^-r-- && stat --format=%A text+x | egrep ^-r-x diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index dafd6ad21a..0d93e33de4 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -413,7 +413,7 @@ test_external () { # test_run_, but keep its stdout on our stdout even in # non-verbose mode. "$@" 2>&4 - if [ "$?" = 0 ] + if test "$?" = 0 then if test $test_external_has_tap -eq 0; then test_ok_ "$descr" @@ -440,11 +440,12 @@ test_external_without_stderr () { tmp=${TMPDIR:-/tmp} stderr="$tmp/git-external-stderr.$$.tmp" test_external "$@" 4> "$stderr" - [ -f "$stderr" ] || error "Internal error: $stderr disappeared." + test -f "$stderr" || error "Internal error: $stderr disappeared." descr="no stderr: $1" shift say >&3 "# expecting no stderr from previous command" - if [ ! -s "$stderr" ]; then + if test ! -s "$stderr" + then rm "$stderr" if test $test_external_has_tap -eq 0; then @@ -454,8 +455,9 @@ test_external_without_stderr () { test_success=$(($test_success + 1)) fi else - if [ "$verbose" = t ]; then - output=`echo; echo "# Stderr is:"; cat "$stderr"` + if test "$verbose" = t + then + output=$(echo; echo "# Stderr is:"; cat "$stderr") else output= fi @@ -474,7 +476,7 @@ test_external_without_stderr () { # The commands test the existence or non-existence of $1. $2 can be # given to provide a more precise diagnosis. test_path_is_file () { - if ! [ -f "$1" ] + if ! test -f "$1" then echo "File $1 doesn't exist. $*" false @@ -482,7 +484,7 @@ test_path_is_file () { } test_path_is_dir () { - if ! [ -d "$1" ] + if ! test -d "$1" then echo "Directory $1 doesn't exist. $*" false @@ -501,11 +503,12 @@ test_dir_is_empty () { } test_path_is_missing () { - if [ -e "$1" ] + if test -e "$1" then echo "Path exists:" ls -ld "$1" - if [ $# -ge 1 ]; then + if test $# -ge 1 + then echo "$*" fi false @@ -634,6 +637,15 @@ test_cmp_bin() { cmp "$@" } +# Call any command "$@" but be more verbose about its +# failure. This is handy for commands like "test" which do +# not output anything when they fail. +verbose () { + "$@" && return 0 + echo >&2 "command failed: $(git rev-parse --sq-quote "$@")" + return 1 +} + # Check if the file expected to be empty is indeed empty, and barfs # otherwise. @@ -657,9 +669,12 @@ test_cmp_rev () { # similar to GNU seq(1), but the latter might not be available # everywhere (and does not do letters). It may be used like: # -# for i in `test_seq 100`; do -# for j in `test_seq 10 20`; do -# for k in `test_seq a z`; do +# for i in $(test_seq 100) +# do +# for j in $(test_seq 10 20) +# do +# for k in $(test_seq a z) +# do # echo $i-$j-$k # done # done diff --git a/t/test-lib.sh b/t/test-lib.sh index b1bc65bfb5..79e8a33d04 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -169,7 +169,11 @@ _z40=0000000000000000000000000000000000000000 LF=' ' -export _x05 _x40 _z40 LF +# UTF-8 ZERO WIDTH NON-JOINER, which HFS+ ignores +# when case-folding filenames +u200c=$(printf '\342\200\214') + +export _x05 _x40 _z40 LF u200c # Each test should start with something like this, after copyright notices: # @@ -233,6 +237,10 @@ do --root=*) root=$(expr "z$1" : 'z[^=]*=\(.*\)') shift ;; + -x) + trace=t + verbose=t + shift ;; *) echo "error: unknown test option '$1'" >&2; exit 1 ;; esac @@ -517,10 +525,39 @@ maybe_setup_valgrind () { fi } +# This is a separate function because some tests use +# "return" to end a test_expect_success block early +# (and we want to make sure we run any cleanup like +# "set +x"). +test_eval_inner_ () { + # Do not add anything extra (including LF) after '$*' + eval " + test \"$trace\" = t && set -x + $*" +} + test_eval_ () { - # This is a separate function because some tests use - # "return" to end a test_expect_success block early. - eval </dev/null >&3 2>&4 "$*" + # We run this block with stderr redirected to avoid extra cruft + # during a "-x" trace. Once in "set -x" mode, we cannot prevent + # the shell from printing the "set +x" to turn it off (nor the saving + # of $? before that). But we can make sure that the output goes to + # /dev/null. + # + # The test itself is run with stderr put back to &4 (so either to + # /dev/null, or to the original stderr if --verbose was used). + { + test_eval_inner_ "$@" </dev/null >&3 2>&4 + test_eval_ret_=$? + if test "$trace" = t + then + set +x + if test "$test_eval_ret_" != 0 + then + say_color error >&4 "error: last command exited with \$?=$test_eval_ret_" + fi + fi + } 2>/dev/null + return $test_eval_ret_ } test_run_ () { @@ -531,7 +568,8 @@ test_run_ () { eval_ret=$? teardown_malloc_check - if test -z "$immediate" || test $eval_ret = 0 || test -n "$expecting_failure" + if test -z "$immediate" || test $eval_ret = 0 || + test -n "$expecting_failure" && test "$test_cleanup" != ":" then setup_malloc_check test_eval_ "$test_cleanup" @@ -813,7 +851,8 @@ rm -fr "$TRASH_DIRECTORY" || { } HOME="$TRASH_DIRECTORY" -export HOME +GNUPGHOME="$HOME/gnupg-home-not-used" +export HOME GNUPGHOME if test -z "$TEST_NO_CREATE_REPO" then @@ -870,7 +909,7 @@ case $(uname -s) in # backslashes in pathspec are converted to '/' # exec does not inherit the PID test_set_prereq MINGW - test_set_prereq NOT_CYGWIN + test_set_prereq NATIVE_CRLF test_set_prereq SED_STRIPS_CR test_set_prereq GREP_STRIPS_CR GIT_TEST_CMP=mingw_test_cmp @@ -878,7 +917,6 @@ case $(uname -s) in *CYGWIN*) test_set_prereq POSIXPERM test_set_prereq EXECKEEPSPID - test_set_prereq NOT_MINGW test_set_prereq CYGWIN test_set_prereq SED_STRIPS_CR test_set_prereq GREP_STRIPS_CR @@ -887,8 +925,6 @@ case $(uname -s) in test_set_prereq POSIXPERM test_set_prereq BSLASHPSPEC test_set_prereq EXECKEEPSPID - test_set_prereq NOT_MINGW - test_set_prereq NOT_CYGWIN ;; esac |