diff options
Diffstat (limited to 't')
80 files changed, 4963 insertions, 1514 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. @@ -412,7 +418,8 @@ Don't: dies in an unexpected way (e.g. segfault). On the other hand, don't use test_must_fail for running regular - platform commands; just use '! cmd'. + platform commands; just use '! cmd'. We are not in the business + of verifying that the world given to us sanely works. - use perl without spelling it as "$PERL_PATH". This is to help our friends on Windows where the platform Perl often adds CR before 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/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..452320df83 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,68 @@ 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 +} + +check_warning () { + case "$1" in + LF_CRLF) grep "LF will be replaced by CRLF" $2;; + CRLF_LF) grep "CRLF will be replaced by LF" $2;; + '') + >expect + grep "will be replaced by" $2 >actual + test_cmp expect actual + ;; + *) false ;; esac } -create_file_in_repo() -{ +create_file_in_repo () { crlf=$1 - txtbin=$2 - create_gitattributes "$txtbin" && + attr=$2 + lfname=$3 + crlfname=$4 + lfmixcrlf=$5 + lfmixcr=$6 + crlfnul=$7 + create_gitattributes "$attr" && + pfx=crlf_${crlf}_attr_${attr} for f in LF CRLF LF_mix_CR CRLF_mix_LF CRLF_nul do - pfx=crlf_${crlf}_attr_${txtbin}_$f.txt && - cp $f $pfx && git -c core.autocrlf=$crlf add $pfx + fname=${pfx}_$f.txt && + cp $f $fname && + git -c core.autocrlf=$crlf add $fname 2>"${pfx}_$f.err" done && - git commit -m "core.autocrlf $crlf" + git commit -m "core.autocrlf $crlf" && + check_warning "$lfname" ${pfx}_LF.err && + check_warning "$crlfname" ${pfx}_CRLF.err && + check_warning "$lfmixcrlf" ${pfx}_CRLF_mix_LF.err && + check_warning "$lfmixcr" ${pfx}_LF_mix_CR.err && + check_warning "$crlfnul" ${pfx}_CRLF_nul.err } -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 +109,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 +132,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,26 +160,52 @@ 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 "" && - create_file_in_repo true "" && - create_file_in_repo input "" && - create_file_in_repo false "auto" && - create_file_in_repo true "auto" && - create_file_in_repo input "auto" && - create_file_in_repo false "text" && - create_file_in_repo true "text" && - create_file_in_repo input "text" && +warn_LF_CRLF="LF will be replaced by CRLF" +warn_CRLF_LF="CRLF will be replaced by LF" - create_file_in_repo false "-text" && - create_file_in_repo true "-text" && - create_file_in_repo input "-text" && +test_expect_success 'add files empty attr' ' + create_file_in_repo false "" "" "" "" "" "" && + create_file_in_repo true "" "LF_CRLF" "" "LF_CRLF" "" "" && + create_file_in_repo input "" "" "CRLF_LF" "CRLF_LF" "" "" +' + +test_expect_success 'add files attr=auto' ' + create_file_in_repo false "auto" "" "CRLF_LF" "CRLF_LF" "" "" && + create_file_in_repo true "auto" "LF_CRLF" "" "LF_CRLF" "" "" && + create_file_in_repo input "auto" "" "CRLF_LF" "CRLF_LF" "" "" +' + +test_expect_success 'add files attr=text' ' + create_file_in_repo false "text" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF" && + create_file_in_repo true "text" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "" && + create_file_in_repo input "text" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF" +' + +test_expect_success 'add files attr=-text' ' + create_file_in_repo false "-text" "" "" "" "" "" && + create_file_in_repo true "-text" "" "" "" "" "" && + create_file_in_repo input "-text" "" "" "" "" "" +' + +test_expect_success 'add files attr=lf' ' + create_file_in_repo false "lf" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF" && + create_file_in_repo true "lf" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF" && + create_file_in_repo input "lf" "" "CRLF_LF" "CRLF_LF" "" "CRLF_LF" +' + +test_expect_success 'add files attr=crlf' ' + create_file_in_repo false "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "" && + create_file_in_repo true "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "" && + create_file_in_repo input "crlf" "LF_CRLF" "" "LF_CRLF" "LF_CRLF" "" +' + +test_expect_success 'create files cleanup' ' rm -f *.txt && git reset --hard ' @@ -201,7 +237,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 +248,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/t0050-filesystem.sh b/t/t0050-filesystem.sh index 6b3cedcf24..988c3925d5 100755 --- a/t/t0050-filesystem.sh +++ b/t/t0050-filesystem.sh @@ -64,7 +64,7 @@ test_expect_success "setup case tests" ' git checkout -f master ' -$test_case 'rename (case change)' ' +test_expect_success 'rename (case change)' ' git mv camelcase CamelCase && git commit -m "rename" ' 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/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/t0300-credentials.sh b/t/t0300-credentials.sh index 57ea5a10c5..d7ef44b4a2 100755 --- a/t/t0300-credentials.sh +++ b/t/t0300-credentials.sh @@ -289,4 +289,13 @@ test_expect_success 'http paths can be part of context' ' EOF ' +test_expect_success 'helpers can abort the process' ' + test_must_fail git \ + -c credential.helper="!f() { echo quit=1; }; f" \ + -c credential.helper="verbatim foo bar" \ + credential fill >stdout && + >expect && + test_cmp expect stdout +' + 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/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/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 index 7fdf840b00..91235b76ba 100755 --- a/t/t1308-config-set.sh +++ b/t/t1308-config-set.sh @@ -23,7 +23,7 @@ check_config () { } test_expect_success 'setup default config' ' - cat >.git/config <<\EOF + cat >.git/config <<-\EOF [case] penguin = very blue Movie = BadPhysics @@ -119,6 +119,16 @@ 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 ' @@ -185,7 +195,7 @@ 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 35 in .git/config" >expect && + 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 ' @@ -197,4 +207,15 @@ test_expect_success 'proper error on error in custom config files' ' 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/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 7850607783..1f04b8aa3f 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 @@ -217,6 +237,25 @@ test_expect_success 'tag with incorrect tag name & missing tagger' ' test_cmp expect 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 @@ -274,35 +313,96 @@ 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 + +# 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 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 + 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 ".git" in trees' ' - ( - 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 - ) +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/t3102-ls-tree-wildcards.sh b/t/t3102-ls-tree-wildcards.sh index c286854485..4d4b02e760 100755 --- a/t/t3102-ls-tree-wildcards.sh +++ b/t/t3102-ls-tree-wildcards.sh @@ -12,11 +12,25 @@ test_expect_success 'setup' ' ' test_expect_success 'ls-tree a[a] matches literally' ' - cat >expected <<EOF && -100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 a[a]/three -EOF + cat >expect <<-\EOF && + 100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 a[a]/three + EOF git ls-tree -r HEAD "a[a]" >actual && - test_cmp expected actual + test_cmp expect actual +' + +test_expect_success 'ls-tree outside prefix' ' + cat >expect <<-\EOF && + 100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 ../a[a]/three + EOF + ( cd aa && git ls-tree -r HEAD "../a[a]"; ) >actual && + test_cmp expect actual +' + +test_expect_failure 'ls-tree does not yet support negated pathspec' ' + git ls-files ":(exclude)a" "a*" >expect && + git ls-tree --name-only -r HEAD ":(exclude)a" "a*" >actual && + test_cmp expect actual ' test_done diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh index ac31b711f2..ddea49808d 100755 --- a/t/t3200-branch.sh +++ b/t/t3200-branch.sh @@ -97,6 +97,20 @@ test_expect_success 'git branch -m o/o o should fail when o/p exists' ' test_must_fail git branch -m o/o o ' +test_expect_success 'git branch -m o/q o/p should fail when o/p exists' ' + git branch o/q && + test_must_fail git branch -m o/q o/p +' + +test_expect_success 'git branch -M o/q o/p should work when o/p exists' ' + git branch -M o/q o/p +' + +test_expect_success 'git branch -m -f o/q o/p should work when o/p exists' ' + git branch o/q && + git branch -m -f o/q o/p +' + test_expect_success 'git branch -m q r/q should fail when r exists' ' git branch q && git branch r && @@ -285,6 +299,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/t3301-notes.sh b/t/t3301-notes.sh index cfd67ff3df..245406ab97 100755 --- a/t/t3301-notes.sh +++ b/t/t3301-notes.sh @@ -7,28 +7,22 @@ test_description='Test commit notes' . ./test-lib.sh -cat > fake_editor.sh << \EOF -#!/bin/sh -echo "$MSG" > "$1" -echo "$MSG" >& 2 +write_script fake_editor <<\EOF +echo "$MSG" >"$1" +echo "$MSG" >&2 EOF -chmod a+x fake_editor.sh -GIT_EDITOR=./fake_editor.sh +GIT_EDITOR=./fake_editor export GIT_EDITOR +indent=" " + test_expect_success 'cannot annotate non-existing HEAD' ' test_must_fail env MSG=3 git notes add ' -test_expect_success setup ' - : > a1 && - git add a1 && - test_tick && - git commit -m 1st && - : > a2 && - git add a2 && - test_tick && - git commit -m 2nd +test_expect_success 'setup' ' + test_commit 1st && + test_commit 2nd ' test_expect_success 'need valid notes ref' ' @@ -50,206 +44,186 @@ test_expect_success 'handle empty notes gracefully' ' ' test_expect_success 'show non-existent notes entry with %N' ' - for l in A B - do - echo "$l" - done >expect && - git show -s --format='A%n%NB' >output && - test_cmp expect output + test_write_lines A B >expect && + git show -s --format="A%n%NB" >actual && + test_cmp expect actual ' test_expect_success 'create notes' ' - git config core.notesRef refs/notes/commits && MSG=b4 git notes add && - test ! -f .git/NOTES_EDITMSG && - test 1 = $(git ls-tree refs/notes/commits | wc -l) && - test b4 = $(git notes show) && + test_path_is_missing .git/NOTES_EDITMSG && + git ls-tree -r refs/notes/commits >actual && + test_line_count = 1 actual && + test "b4" = "$(git notes show)" && git show HEAD^ && test_must_fail git notes show HEAD^ ' test_expect_success 'show notes entry with %N' ' - for l in A b4 B - do - echo "$l" - done >expect && - git show -s --format='A%n%NB' >output && - test_cmp expect output + test_write_lines A b4 B >expect && + git show -s --format="A%n%NB" >actual && + test_cmp expect actual ' -cat >expect <<EOF -d423f8c refs/notes/commits@{0}: notes: Notes added by 'git notes add' -EOF - test_expect_success 'create reflog entry' ' - git reflog show refs/notes/commits >output && - test_cmp expect output + cat <<-EOF >expect && + a1d8fa6 refs/notes/commits@{0}: notes: Notes added by '\''git notes add'\'' + EOF + git reflog show refs/notes/commits >actual && + test_cmp expect actual ' test_expect_success 'edit existing notes' ' MSG=b3 git notes edit && - test ! -f .git/NOTES_EDITMSG && - test 1 = $(git ls-tree refs/notes/commits | wc -l) && - test b3 = $(git notes show) && + test_path_is_missing .git/NOTES_EDITMSG && + git ls-tree -r refs/notes/commits >actual && + test_line_count = 1 actual && + test "b3" = "$(git notes show)" && git show HEAD^ && test_must_fail git notes show HEAD^ ' test_expect_success 'cannot "git notes add -m" where notes already exists' ' test_must_fail git notes add -m "b2" && - test ! -f .git/NOTES_EDITMSG && - test 1 = $(git ls-tree refs/notes/commits | wc -l) && - test b3 = $(git notes show) && + test_path_is_missing .git/NOTES_EDITMSG && + git ls-tree -r refs/notes/commits >actual && + test_line_count = 1 actual && + test "b3" = "$(git notes show)" && git show HEAD^ && test_must_fail git notes show HEAD^ ' test_expect_success 'can overwrite existing note with "git notes add -f -m"' ' git notes add -f -m "b1" && - test ! -f .git/NOTES_EDITMSG && - test 1 = $(git ls-tree refs/notes/commits | wc -l) && - test b1 = $(git notes show) && + test_path_is_missing .git/NOTES_EDITMSG && + git ls-tree -r refs/notes/commits >actual && + test_line_count = 1 actual && + test "b1" = "$(git notes show)" && git show HEAD^ && test_must_fail git notes show HEAD^ ' test_expect_success 'add w/no options on existing note morphs into edit' ' MSG=b2 git notes add && - test ! -f .git/NOTES_EDITMSG && - test 1 = $(git ls-tree refs/notes/commits | wc -l) && - test b2 = $(git notes show) && + test_path_is_missing .git/NOTES_EDITMSG && + git ls-tree -r refs/notes/commits >actual && + test_line_count = 1 actual && + test "b2" = "$(git notes show)" && git show HEAD^ && test_must_fail git notes show HEAD^ ' test_expect_success 'can overwrite existing note with "git notes add -f"' ' MSG=b1 git notes add -f && - test ! -f .git/NOTES_EDITMSG && - test 1 = $(git ls-tree refs/notes/commits | wc -l) && - test b1 = $(git notes show) && + test_path_is_missing .git/NOTES_EDITMSG && + git ls-tree -r refs/notes/commits >actual && + test_line_count = 1 actual && + test "b1" = "$(git notes show)" && git show HEAD^ && test_must_fail git notes show HEAD^ ' -cat > expect << EOF -commit 268048bfb8a1fb38e703baceb8ab235421bf80c5 -Author: A U Thor <author@example.com> -Date: Thu Apr 7 15:14:13 2005 -0700 - - 2nd +test_expect_success 'show notes' ' + cat >expect <<-EOF && + commit 7a4ca6ee52a974a66cbaa78e33214535dff1d691 + Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:14:13 2005 -0700 -Notes: - b1 -EOF + ${indent}2nd -test_expect_success 'show notes' ' + Notes: + ${indent}b1 + EOF ! (git cat-file commit HEAD | grep b1) && - git log -1 > output && - test_cmp expect output -' - -test_expect_success 'create multi-line notes (setup)' ' - : > a3 && - git add a3 && - test_tick && - git commit -m 3rd && - MSG="b3 -c3c3c3c3 -d3d3d3" git notes add + git log -1 >actual && + test_cmp expect actual ' -cat > expect-multiline << EOF -commit 1584215f1d29c65e99c6c6848626553fdd07fd75 -Author: A U Thor <author@example.com> -Date: Thu Apr 7 15:15:13 2005 -0700 - - 3rd +test_expect_success 'show multi-line notes' ' + test_commit 3rd && + MSG="b3${LF}c3c3c3c3${LF}d3d3d3" git notes add && + cat >expect-multiline <<-EOF && + commit d07d62e5208f22eb5695e7eb47667dc8b9860290 + Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:15:13 2005 -0700 -Notes: - b3 - c3c3c3c3 - d3d3d3 -EOF + ${indent}3rd -printf "\n" >> expect-multiline -cat expect >> expect-multiline + Notes: + ${indent}b3 + ${indent}c3c3c3c3 + ${indent}d3d3d3 -test_expect_success 'show multi-line notes' ' - git log -2 > output && - test_cmp expect-multiline output -' -test_expect_success 'create -F notes (setup)' ' - : > a4 && - git add a4 && - test_tick && - git commit -m 4th && - echo "xyzzy" > note5 && - git notes add -F note5 + EOF + cat expect >>expect-multiline && + git log -2 >actual && + test_cmp expect-multiline actual ' -cat > expect-F << EOF -commit 15023535574ded8b1a89052b32673f84cf9582b8 -Author: A U Thor <author@example.com> -Date: Thu Apr 7 15:16:13 2005 -0700 +test_expect_success 'show -F notes' ' + test_commit 4th && + echo "xyzzy" >note5 && + git notes add -F note5 && + cat >expect-F <<-EOF && + commit 0f7aa3ec6325aeb88b910453bb3eb37c49d75c11 + Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:16:13 2005 -0700 - 4th + ${indent}4th -Notes: - xyzzy -EOF + Notes: + ${indent}xyzzy -printf "\n" >> expect-F -cat expect-multiline >> expect-F - -test_expect_success 'show -F notes' ' - git log -3 > output && - test_cmp expect-F output + EOF + cat expect-multiline >>expect-F && + git log -3 >actual && + test_cmp expect-F actual ' test_expect_success 'Re-adding -F notes without -f fails' ' - echo "zyxxy" > note5 && + echo "zyxxy" >note5 && test_must_fail git notes add -F note5 && - git log -3 > output && - test_cmp expect-F output + git log -3 >actual && + test_cmp expect-F actual ' -cat >expect << EOF -commit 15023535574ded8b1a89052b32673f84cf9582b8 -tree e070e3af51011e47b183c33adf9736736a525709 -parent 1584215f1d29c65e99c6c6848626553fdd07fd75 -author A U Thor <author@example.com> 1112912173 -0700 -committer C O Mitter <committer@example.com> 1112912173 -0700 - - 4th -EOF test_expect_success 'git log --pretty=raw does not show notes' ' - git log -1 --pretty=raw >output && - test_cmp expect output + cat >expect <<-EOF && + commit 0f7aa3ec6325aeb88b910453bb3eb37c49d75c11 + tree 05ac65288c4c4b3b709a020ae94b2ece2f2201ae + parent d07d62e5208f22eb5695e7eb47667dc8b9860290 + author A U Thor <author@example.com> 1112912173 -0700 + committer C O Mitter <committer@example.com> 1112912173 -0700 + + ${indent}4th + EOF + git log -1 --pretty=raw >actual && + test_cmp expect actual ' -cat >>expect <<EOF - -Notes: - xyzzy -EOF test_expect_success 'git log --show-notes' ' - git log -1 --pretty=raw --show-notes >output && - test_cmp expect output + cat >>expect <<-EOF && + + Notes: + ${indent}xyzzy + EOF + git log -1 --pretty=raw --show-notes >actual && + test_cmp expect actual ' test_expect_success 'git log --no-notes' ' - git log -1 --no-notes >output && - ! grep xyzzy output + git log -1 --no-notes >actual && + ! grep xyzzy actual ' test_expect_success 'git format-patch does not show notes' ' - git format-patch -1 --stdout >output && - ! grep xyzzy output + git format-patch -1 --stdout >actual && + ! grep xyzzy actual ' test_expect_success 'git format-patch --show-notes does show notes' ' - git format-patch --show-notes -1 --stdout >output && - grep xyzzy output + git format-patch --show-notes -1 --stdout >actual && + grep xyzzy actual ' for pretty in \ @@ -261,8 +235,8 @@ do ?*) p="$pretty" not=" not" negate="!" ;; esac test_expect_success "git show $pretty does$not show notes" ' - git show $p >output && - eval "$negate grep xyzzy output" + git show $p >actual && + eval "$negate grep xyzzy actual" ' done @@ -271,161 +245,131 @@ test_expect_success 'setup alternate notes ref' ' ' test_expect_success 'git log --notes shows default notes' ' - git log -1 --notes >output && - grep xyzzy output && - ! grep alternate output + git log -1 --notes >actual && + grep xyzzy actual && + ! grep alternate actual ' test_expect_success 'git log --notes=X shows only X' ' - git log -1 --notes=alternate >output && - ! grep xyzzy output && - grep alternate output + git log -1 --notes=alternate >actual && + ! grep xyzzy actual && + grep alternate actual ' test_expect_success 'git log --notes --notes=X shows both' ' - git log -1 --notes --notes=alternate >output && - grep xyzzy output && - grep alternate output + git log -1 --notes --notes=alternate >actual && + grep xyzzy actual && + grep alternate actual ' test_expect_success 'git log --no-notes resets default state' ' git log -1 --notes --notes=alternate \ --no-notes --notes=alternate \ - >output && - ! grep xyzzy output && - grep alternate output + >actual && + ! grep xyzzy actual && + grep alternate actual ' test_expect_success 'git log --no-notes resets ref list' ' git log -1 --notes --notes=alternate \ --no-notes --notes \ - >output && - grep xyzzy output && - ! grep alternate output -' - -test_expect_success 'create -m notes (setup)' ' - : > a5 && - git add a5 && - test_tick && - git commit -m 5th && - git notes add -m spam -m "foo -bar -baz" -' - -whitespace=" " -cat > expect-m << EOF -commit bd1753200303d0a0344be813e504253b3d98e74d -Author: A U Thor <author@example.com> -Date: Thu Apr 7 15:17:13 2005 -0700 - - 5th - -Notes: - spam -$whitespace - foo - bar - baz -EOF - -printf "\n" >> expect-m -cat expect-F >> expect-m - -test_expect_success 'show -m notes' ' - git log -4 > output && - test_cmp expect-m output + >actual && + grep xyzzy actual && + ! grep alternate actual ' -test_expect_success 'remove note with add -f -F /dev/null (setup)' ' - git notes add -f -F /dev/null -' - -cat > expect-rm-F << EOF -commit bd1753200303d0a0344be813e504253b3d98e74d -Author: A U Thor <author@example.com> -Date: Thu Apr 7 15:17:13 2005 -0700 - - 5th -EOF - -printf "\n" >> expect-rm-F -cat expect-F >> expect-rm-F - -test_expect_success 'verify note removal with -F /dev/null' ' - git log -4 > output && - test_cmp expect-rm-F output && +test_expect_success 'show -m notes' ' + test_commit 5th && + git notes add -m spam -m "foo${LF}bar${LF}baz" && + cat >expect-m <<-EOF && + commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361 + Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:17:13 2005 -0700 + + ${indent}5th + + Notes: + ${indent}spam + ${indent} + ${indent}foo + ${indent}bar + ${indent}baz + + EOF + cat expect-F >>expect-m && + git log -4 >actual && + test_cmp expect-m actual +' + +test_expect_success 'remove note with add -f -F /dev/null' ' + git notes add -f -F /dev/null && + cat >expect-rm-F <<-EOF && + commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361 + Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:17:13 2005 -0700 + + ${indent}5th + + EOF + cat expect-F >>expect-rm-F && + git log -4 >actual && + test_cmp expect-rm-F actual && test_must_fail git notes show ' -test_expect_success 'do not create empty note with -m "" (setup)' ' - git notes add -m "" -' - -test_expect_success 'verify non-creation of note with -m ""' ' - git log -4 > output && - test_cmp expect-rm-F output && +test_expect_success 'do not create empty note with -m ""' ' + git notes add -m "" && + git log -4 >actual && + test_cmp expect-rm-F actual && test_must_fail git notes show ' -cat > expect-combine_m_and_F << EOF -foo - -xyzzy +test_expect_success 'create note with combination of -m and -F' ' + cat >expect-combine_m_and_F <<-EOF && + foo -bar + xyzzy -zyxxy + bar -baz -EOF + zyxxy -test_expect_success 'create note with combination of -m and -F' ' - echo "xyzzy" > note_a && - echo "zyxxy" > note_b && + baz + EOF + echo "xyzzy" >note_a && + echo "zyxxy" >note_b && git notes add -m "foo" -F note_a -m "bar" -F note_b -m "baz" && - git notes show > output && - test_cmp expect-combine_m_and_F output + git notes show >actual && + test_cmp expect-combine_m_and_F actual ' -test_expect_success 'remove note with "git notes remove" (setup)' ' +test_expect_success 'remove note with "git notes remove"' ' git notes remove HEAD^ && - git notes remove -' - -cat > expect-rm-remove << EOF -commit bd1753200303d0a0344be813e504253b3d98e74d -Author: A U Thor <author@example.com> -Date: Thu Apr 7 15:17:13 2005 -0700 + git notes remove && + cat >expect-rm-remove <<-EOF && + commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361 + Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:17:13 2005 -0700 - 5th + ${indent}5th -commit 15023535574ded8b1a89052b32673f84cf9582b8 -Author: A U Thor <author@example.com> -Date: Thu Apr 7 15:16:13 2005 -0700 + commit 0f7aa3ec6325aeb88b910453bb3eb37c49d75c11 + Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:16:13 2005 -0700 - 4th -EOF - -printf "\n" >> expect-rm-remove -cat expect-multiline >> expect-rm-remove + ${indent}4th -test_expect_success 'verify note removal with "git notes remove"' ' - git log -4 > output && - test_cmp expect-rm-remove output && + EOF + cat expect-multiline >>expect-rm-remove && + git log -4 >actual && + test_cmp expect-rm-remove actual && test_must_fail git notes show HEAD^ ' -cat > expect << EOF -c18dc024e14f08d18d14eea0d747ff692d66d6a3 1584215f1d29c65e99c6c6848626553fdd07fd75 -c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 268048bfb8a1fb38e703baceb8ab235421bf80c5 -EOF - test_expect_success 'removing non-existing note should not create new commit' ' - git rev-parse --verify refs/notes/commits > before_commit && + git rev-parse --verify refs/notes/commits >before_commit && test_must_fail git notes remove HEAD^ && - git rev-parse --verify refs/notes/commits > after_commit && + git rev-parse --verify refs/notes/commits >after_commit && test_cmp before_commit after_commit ' @@ -505,70 +449,68 @@ test_expect_success 'removing with --stdin --ignore-missing' ' ' test_expect_success 'list notes with "git notes list"' ' - git notes list > output && - test_cmp expect output + cat >expect <<-EOF && + c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 7a4ca6ee52a974a66cbaa78e33214535dff1d691 + c18dc024e14f08d18d14eea0d747ff692d66d6a3 d07d62e5208f22eb5695e7eb47667dc8b9860290 + EOF + git notes list >actual && + test_cmp expect actual ' test_expect_success 'list notes with "git notes"' ' - git notes > output && - test_cmp expect output + git notes >actual && + test_cmp expect actual ' -cat > expect << EOF -c18dc024e14f08d18d14eea0d747ff692d66d6a3 -EOF - test_expect_success 'list specific note with "git notes list <object>"' ' - git notes list HEAD^^ > output && - test_cmp expect output + cat >expect <<-EOF && + c18dc024e14f08d18d14eea0d747ff692d66d6a3 + EOF + git notes list HEAD^^ >actual && + test_cmp expect actual ' -cat > expect << EOF -EOF - test_expect_success 'listing non-existing notes fails' ' - test_must_fail git notes list HEAD > output && - test_cmp expect output + cat >expect <<-EOF && + EOF + test_must_fail git notes list HEAD >actual && + test_cmp expect actual ' -cat > expect << EOF -Initial set of notes - -More notes appended with git notes append -EOF - test_expect_success 'append to existing note with "git notes append"' ' + cat >expect <<-EOF && + Initial set of notes + + More notes appended with git notes append + EOF git notes add -m "Initial set of notes" && git notes append -m "More notes appended with git notes append" && - git notes show > output && - test_cmp expect output + git notes show >actual && + test_cmp expect actual ' -cat > expect_list << EOF -c18dc024e14f08d18d14eea0d747ff692d66d6a3 1584215f1d29c65e99c6c6848626553fdd07fd75 -c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 268048bfb8a1fb38e703baceb8ab235421bf80c5 -4b6ad22357cc8a1296720574b8d2fbc22fab0671 bd1753200303d0a0344be813e504253b3d98e74d -EOF - test_expect_success '"git notes list" does not expand to "git notes list HEAD"' ' - git notes list > output && - test_cmp expect_list output + cat >expect_list <<-EOF && + c9c6af7f78bc47490dbf3e822cf2f3c24d4b9061 7a4ca6ee52a974a66cbaa78e33214535dff1d691 + 4b6ad22357cc8a1296720574b8d2fbc22fab0671 7f9ad8836c775acb134c0a055fc55fb4cd1ba361 + c18dc024e14f08d18d14eea0d747ff692d66d6a3 d07d62e5208f22eb5695e7eb47667dc8b9860290 + EOF + git notes list >actual && + test_cmp expect_list actual ' test_expect_success 'appending empty string does not change existing note' ' git notes append -m "" && - git notes show > output && - test_cmp expect output + git notes show >actual && + test_cmp expect actual ' test_expect_success 'git notes append == add when there is no existing note' ' git notes remove HEAD && test_must_fail git notes list HEAD && - git notes append -m "Initial set of notes - -More notes appended with git notes append" && - git notes show > output && - test_cmp expect output + git notes append -m "Initial set of notes${LF}${LF}More notes appended with git notes append" && + git notes show >actual && + test_cmp expect actual ' test_expect_success 'appending empty string to non-existing note does not create note' ' @@ -579,229 +521,208 @@ test_expect_success 'appending empty string to non-existing note does not create ' test_expect_success 'create other note on a different notes ref (setup)' ' - : > a6 && - git add a6 && - test_tick && - git commit -m 6th && - GIT_NOTES_REF="refs/notes/other" git notes add -m "other note" -' + test_commit 6th && + GIT_NOTES_REF="refs/notes/other" git notes add -m "other note" && + cat >expect-not-other <<-EOF && + commit 2c125331118caba0ff8238b7f4958ac6e93fe39c + Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:18:13 2005 -0700 -cat > expect-other << EOF -commit 387a89921c73d7ed72cd94d179c1c7048ca47756 -Author: A U Thor <author@example.com> -Date: Thu Apr 7 15:18:13 2005 -0700 - - 6th - -Notes (other): - other note -EOF + ${indent}6th + EOF + cp expect-not-other expect-other && + cat >>expect-other <<-EOF -cat > expect-not-other << EOF -commit 387a89921c73d7ed72cd94d179c1c7048ca47756 -Author: A U Thor <author@example.com> -Date: Thu Apr 7 15:18:13 2005 -0700 - - 6th -EOF + Notes (other): + ${indent}other note + EOF +' test_expect_success 'Do not show note on other ref by default' ' - git log -1 > output && - test_cmp expect-not-other output + git log -1 >actual && + test_cmp expect-not-other actual ' test_expect_success 'Do show note when ref is given in GIT_NOTES_REF' ' - GIT_NOTES_REF="refs/notes/other" git log -1 > output && - test_cmp expect-other output + GIT_NOTES_REF="refs/notes/other" git log -1 >actual && + test_cmp expect-other actual ' test_expect_success 'Do show note when ref is given in core.notesRef config' ' - git config core.notesRef "refs/notes/other" && - git log -1 > output && - test_cmp expect-other output + test_config core.notesRef "refs/notes/other" && + git log -1 >actual && + test_cmp expect-other actual ' test_expect_success 'Do not show note when core.notesRef is overridden' ' - GIT_NOTES_REF="refs/notes/wrong" git log -1 > output && - test_cmp expect-not-other output + test_config core.notesRef "refs/notes/other" && + GIT_NOTES_REF="refs/notes/wrong" git log -1 >actual && + test_cmp expect-not-other actual ' -cat > expect-both << EOF -commit 387a89921c73d7ed72cd94d179c1c7048ca47756 -Author: A U Thor <author@example.com> -Date: Thu Apr 7 15:18:13 2005 -0700 - - 6th +test_expect_success 'Show all notes when notes.displayRef=refs/notes/*' ' + cat >expect-both <<-EOF && + commit 2c125331118caba0ff8238b7f4958ac6e93fe39c + Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:18:13 2005 -0700 -Notes: - order test + ${indent}6th -Notes (other): - other note + Notes: + ${indent}order test -commit bd1753200303d0a0344be813e504253b3d98e74d -Author: A U Thor <author@example.com> -Date: Thu Apr 7 15:17:13 2005 -0700 + Notes (other): + ${indent}other note - 5th + commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361 + Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:17:13 2005 -0700 -Notes: - replacement for deleted note -EOF + ${indent}5th -test_expect_success 'Show all notes when notes.displayRef=refs/notes/*' ' + Notes: + ${indent}replacement for deleted note + EOF GIT_NOTES_REF=refs/notes/commits git notes add \ -m"replacement for deleted note" HEAD^ && GIT_NOTES_REF=refs/notes/commits git notes add -m"order test" && - git config --unset core.notesRef && - git config notes.displayRef "refs/notes/*" && - git log -2 > output && - test_cmp expect-both output + test_unconfig core.notesRef && + test_config notes.displayRef "refs/notes/*" && + git log -2 >actual && + test_cmp expect-both actual ' test_expect_success 'core.notesRef is implicitly in notes.displayRef' ' - git config core.notesRef refs/notes/commits && - git config notes.displayRef refs/notes/other && - git log -2 > output && - test_cmp expect-both output + test_config core.notesRef refs/notes/commits && + test_config notes.displayRef refs/notes/other && + git log -2 >actual && + test_cmp expect-both actual ' test_expect_success 'notes.displayRef can be given more than once' ' - git config --unset core.notesRef && - git config notes.displayRef refs/notes/commits && + test_unconfig core.notesRef && + test_config notes.displayRef refs/notes/commits && git config --add notes.displayRef refs/notes/other && - git log -2 > output && - test_cmp expect-both output + git log -2 >actual && + test_cmp expect-both actual ' -cat > expect-both-reversed << EOF -commit 387a89921c73d7ed72cd94d179c1c7048ca47756 -Author: A U Thor <author@example.com> -Date: Thu Apr 7 15:18:13 2005 -0700 - - 6th +test_expect_success 'notes.displayRef respects order' ' + cat >expect-both-reversed <<-EOF && + commit 2c125331118caba0ff8238b7f4958ac6e93fe39c + Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:18:13 2005 -0700 -Notes (other): - other note + ${indent}6th -Notes: - order test -EOF + Notes (other): + ${indent}other note -test_expect_success 'notes.displayRef respects order' ' - git config core.notesRef refs/notes/other && - git config --unset-all notes.displayRef && - git config notes.displayRef refs/notes/commits && - git log -1 > output && - test_cmp expect-both-reversed output + Notes: + ${indent}order test + EOF + test_config core.notesRef refs/notes/other && + test_config notes.displayRef refs/notes/commits && + git log -1 >actual && + test_cmp expect-both-reversed actual ' test_expect_success 'GIT_NOTES_DISPLAY_REF works' ' - git config --unset-all core.notesRef && - git config --unset-all notes.displayRef && GIT_NOTES_DISPLAY_REF=refs/notes/commits:refs/notes/other \ - git log -2 > output && - test_cmp expect-both output + git log -2 >actual && + test_cmp expect-both actual ' -cat > expect-none << EOF -commit 387a89921c73d7ed72cd94d179c1c7048ca47756 -Author: A U Thor <author@example.com> -Date: Thu Apr 7 15:18:13 2005 -0700 - - 6th +test_expect_success 'GIT_NOTES_DISPLAY_REF overrides config' ' + cat >expect-none <<-EOF && + commit 2c125331118caba0ff8238b7f4958ac6e93fe39c + Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:18:13 2005 -0700 -commit bd1753200303d0a0344be813e504253b3d98e74d -Author: A U Thor <author@example.com> -Date: Thu Apr 7 15:17:13 2005 -0700 + ${indent}6th - 5th -EOF + commit 7f9ad8836c775acb134c0a055fc55fb4cd1ba361 + Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:17:13 2005 -0700 -test_expect_success 'GIT_NOTES_DISPLAY_REF overrides config' ' - git config notes.displayRef "refs/notes/*" && - GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log -2 > output && - test_cmp expect-none output + ${indent}5th + EOF + test_config notes.displayRef "refs/notes/*" && + GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log -2 >actual && + test_cmp expect-none actual ' test_expect_success '--show-notes=* adds to GIT_NOTES_DISPLAY_REF' ' - GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log --show-notes=* -2 > output && - test_cmp expect-both output + GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log --show-notes=* -2 >actual && + test_cmp expect-both actual ' -cat > expect-commits << EOF -commit 387a89921c73d7ed72cd94d179c1c7048ca47756 -Author: A U Thor <author@example.com> -Date: Thu Apr 7 15:18:13 2005 -0700 - - 6th +test_expect_success '--no-standard-notes' ' + cat >expect-commits <<EOF + commit 2c125331118caba0ff8238b7f4958ac6e93fe39c + Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:18:13 2005 -0700 -Notes: - order test -EOF + ${indent}6th -test_expect_success '--no-standard-notes' ' - git log --no-standard-notes --show-notes=commits -1 > output && - test_cmp expect-commits output + Notes: + ${indent}order test + EOF + git log --no-standard-notes --show-notes=commits -1 >actual && + test_cmp expect-commits actual ' test_expect_success '--standard-notes' ' + test_config notes.displayRef "refs/notes/*" && git log --no-standard-notes --show-notes=commits \ - --standard-notes -2 > output && - test_cmp expect-both output + --standard-notes -2 >actual && + test_cmp expect-both actual ' test_expect_success '--show-notes=ref accumulates' ' git log --show-notes=other --show-notes=commits \ - --no-standard-notes -1 > output && - test_cmp expect-both-reversed output + --no-standard-notes -1 >actual && + test_cmp expect-both-reversed actual ' test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' ' - git config core.notesRef refs/notes/other && - echo "Note on a tree" > expect && + test_config core.notesRef refs/notes/other && + echo "Note on a tree" >expect && git notes add -m "Note on a tree" HEAD: && - git notes show HEAD: > actual && + git notes show HEAD: >actual && test_cmp expect actual && - echo "Note on a blob" > expect && + echo "Note on a blob" >expect && filename=$(git ls-tree --name-only HEAD | head -n1) && git notes add -m "Note on a blob" HEAD:$filename && - git notes show HEAD:$filename > actual && + git notes show HEAD:$filename >actual && test_cmp expect actual && - echo "Note on a tag" > expect && + echo "Note on a tag" >expect && git tag -a -m "This is an annotated tag" foobar HEAD^ && git notes add -m "Note on a tag" foobar && - git notes show foobar > actual && + git notes show foobar >actual && test_cmp expect actual ' -cat > expect << EOF -commit 2ede89468182a62d0bde2583c736089bcf7d7e92 -Author: A U Thor <author@example.com> -Date: Thu Apr 7 15:19:13 2005 -0700 - - 7th +test_expect_success 'create note from other note with "git notes add -C"' ' + cat >expect <<-EOF && + commit fb01e0ca8c33b6cc0c6451dde747f97df567cb5c + Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:19:13 2005 -0700 -Notes (other): - other note -EOF + ${indent}7th -test_expect_success 'create note from other note with "git notes add -C"' ' - : > a7 && - git add a7 && - test_tick && - git commit -m 7th && + Notes: + ${indent}order test + EOF + test_commit 7th && git notes add -C $(git notes list HEAD^) && - git log -1 > actual && + git log -1 >actual && test_cmp expect actual && test "$(git notes list HEAD)" = "$(git notes list HEAD^)" ' test_expect_success 'create note from non-existing note with "git notes add -C" fails' ' - : > a8 && - git add a8 && - test_tick && - git commit -m 8th && + test_commit 8th && test_must_fail git notes add -C deadbeef && test_must_fail git notes list HEAD ' @@ -814,405 +735,386 @@ test_expect_success 'create note from non-blob with "git notes add -C" fails' ' test_must_fail git notes list HEAD ' -cat > expect << EOF -commit 80d796defacd5db327b7a4e50099663902fbdc5c -Author: A U Thor <author@example.com> -Date: Thu Apr 7 15:20:13 2005 -0700 - - 8th +test_expect_success 'create note from blob with "git notes add -C" reuses blob id' ' + cat >expect <<-EOF && + commit 9a4c31c7f722b5d517e92c64e932dd751e1413bf + Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:20:13 2005 -0700 -Notes (other): - This is a blob object -EOF + ${indent}8th -test_expect_success 'create note from blob with "git notes add -C" reuses blob id' ' + Notes: + ${indent}This is a blob object + EOF blob=$(echo "This is a blob object" | git hash-object -w --stdin) && git notes add -C $blob && - git log -1 > actual && + git log -1 >actual && test_cmp expect actual && test "$(git notes list HEAD)" = "$blob" ' -cat > expect << EOF -commit 016e982bad97eacdbda0fcbd7ce5b0ba87c81f1b -Author: A U Thor <author@example.com> -Date: Thu Apr 7 15:21:13 2005 -0700 - - 9th +test_expect_success 'create note from other note with "git notes add -c"' ' + cat >expect <<-EOF && + commit 2e0db4bc649e174d667a1cde19e725cf897a5bd2 + Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:21:13 2005 -0700 -Notes (other): - yet another note -EOF + ${indent}9th -test_expect_success 'create note from other note with "git notes add -c"' ' - : > a9 && - git add a9 && - test_tick && - git commit -m 9th && + Notes: + ${indent}yet another note + EOF + test_commit 9th && MSG="yet another note" git notes add -c $(git notes list HEAD^^) && - git log -1 > actual && + git log -1 >actual && test_cmp expect actual ' test_expect_success 'create note from non-existing note with "git notes add -c" fails' ' - : > a10 && - git add a10 && - test_tick && - git commit -m 10th && + test_commit 10th && test_must_fail env MSG="yet another note" git notes add -c deadbeef && test_must_fail git notes list HEAD ' -cat > expect << EOF -commit 016e982bad97eacdbda0fcbd7ce5b0ba87c81f1b -Author: A U Thor <author@example.com> -Date: Thu Apr 7 15:21:13 2005 -0700 - - 9th - -Notes (other): - yet another note -$whitespace - yet another note -EOF - test_expect_success 'append to note from other note with "git notes append -C"' ' + cat >expect <<-EOF && + commit 2e0db4bc649e174d667a1cde19e725cf897a5bd2 + Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:21:13 2005 -0700 + + ${indent}9th + + Notes: + ${indent}yet another note + ${indent} + ${indent}yet another note + EOF git notes append -C $(git notes list HEAD^) HEAD^ && - git log -1 HEAD^ > actual && + git log -1 HEAD^ >actual && test_cmp expect actual ' -cat > expect << EOF -commit ffed603236bfa3891c49644257a83598afe8ae5a -Author: A U Thor <author@example.com> -Date: Thu Apr 7 15:22:13 2005 -0700 +test_expect_success 'create note from other note with "git notes append -c"' ' + cat >expect <<-EOF && + commit 7c3b87ab368f81e11b1ea87b2ab99a71ccd25406 + Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:22:13 2005 -0700 - 10th + ${indent}10th -Notes (other): - other note -EOF - -test_expect_success 'create note from other note with "git notes append -c"' ' + Notes: + ${indent}other note + EOF MSG="other note" git notes append -c $(git notes list HEAD^) && - git log -1 > actual && + git log -1 >actual && test_cmp expect actual ' -cat > expect << EOF -commit ffed603236bfa3891c49644257a83598afe8ae5a -Author: A U Thor <author@example.com> -Date: Thu Apr 7 15:22:13 2005 -0700 - - 10th - -Notes (other): - other note -$whitespace - yet another note -EOF - test_expect_success 'append to note from other note with "git notes append -c"' ' + cat >expect <<-EOF && + commit 7c3b87ab368f81e11b1ea87b2ab99a71ccd25406 + Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:22:13 2005 -0700 + + ${indent}10th + + Notes: + ${indent}other note + ${indent} + ${indent}yet another note + EOF MSG="yet another note" git notes append -c $(git notes list HEAD) && - git log -1 > actual && + git log -1 >actual && test_cmp expect actual ' -cat > expect << EOF -commit 6352c5e33dbcab725fe0579be16aa2ba8eb369be -Author: A U Thor <author@example.com> -Date: Thu Apr 7 15:23:13 2005 -0700 - - 11th - -Notes (other): - other note -$whitespace - yet another note -EOF - test_expect_success 'copy note with "git notes copy"' ' - : > a11 && - git add a11 && - test_tick && - git commit -m 11th && + cat >expect <<-EOF && + commit a446fff8777efdc6eb8f4b7c8a5ff699484df0d5 + Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:23:13 2005 -0700 + + ${indent}11th + + Notes: + ${indent}other note + ${indent} + ${indent}yet another note + EOF + test_commit 11th && git notes copy HEAD^ HEAD && - git log -1 > actual && + git log -1 >actual && test_cmp expect actual && test "$(git notes list HEAD)" = "$(git notes list HEAD^)" ' test_expect_success 'prevent overwrite with "git notes copy"' ' test_must_fail git notes copy HEAD~2 HEAD && - git log -1 > actual && + git log -1 >actual && test_cmp expect actual && test "$(git notes list HEAD)" = "$(git notes list HEAD^)" ' -cat > expect << EOF -commit 6352c5e33dbcab725fe0579be16aa2ba8eb369be -Author: A U Thor <author@example.com> -Date: Thu Apr 7 15:23:13 2005 -0700 - - 11th - -Notes (other): - yet another note -$whitespace - yet another note -EOF - test_expect_success 'allow overwrite with "git notes copy -f"' ' + cat >expect <<-EOF && + commit a446fff8777efdc6eb8f4b7c8a5ff699484df0d5 + Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:23:13 2005 -0700 + + ${indent}11th + + Notes: + ${indent}yet another note + ${indent} + ${indent}yet another note + EOF git notes copy -f HEAD~2 HEAD && - git log -1 > actual && + git log -1 >actual && test_cmp expect actual && test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" ' test_expect_success 'cannot copy note from object without notes' ' - : > a12 && - git add a12 && - test_tick && - git commit -m 12th && - : > a13 && - git add a13 && - test_tick && - git commit -m 13th && + test_commit 12th && + test_commit 13th && test_must_fail git notes copy HEAD^ HEAD ' -cat > expect << EOF -commit e5d4fb5698d564ab8c73551538ecaf2b0c666185 -Author: A U Thor <author@example.com> -Date: Thu Apr 7 15:25:13 2005 -0700 - - 13th +test_expect_success 'git notes copy --stdin' ' + cat >expect <<-EOF && + commit e871aa61182b1d95d0a6fb75445d891722863b6b + Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:25:13 2005 -0700 -Notes (other): - yet another note -$whitespace - yet another note + ${indent}13th -commit 7038787dfe22a14c3867ce816dbba39845359719 -Author: A U Thor <author@example.com> -Date: Thu Apr 7 15:24:13 2005 -0700 + Notes: + ${indent}yet another note + ${indent} + ${indent}yet another note - 12th + commit 65e263ded02ae4e8839bc151095113737579dc12 + Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:24:13 2005 -0700 -Notes (other): - other note -$whitespace - yet another note -EOF + ${indent}12th -test_expect_success 'git notes copy --stdin' ' + Notes: + ${indent}other note + ${indent} + ${indent}yet another note + EOF (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \ echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) | git notes copy --stdin && - git log -2 > output && - test_cmp expect output && + git log -2 >actual && + test_cmp expect actual && test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" && test "$(git notes list HEAD^)" = "$(git notes list HEAD~3)" ' -cat > expect << EOF -commit 37a0d4cba38afef96ba54a3ea567e6dac575700b -Author: A U Thor <author@example.com> -Date: Thu Apr 7 15:27:13 2005 -0700 - - 15th +test_expect_success 'git notes copy --for-rewrite (unconfigured)' ' + cat >expect <<-EOF && + commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89 + Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:27:13 2005 -0700 -commit be28d8b4d9951ad940d229ee3b0b9ee3b1ec273d -Author: A U Thor <author@example.com> -Date: Thu Apr 7 15:26:13 2005 -0700 + ${indent}15th - 14th -EOF + commit 07c85d77059393ed0154b8c96906547a59dfcddd + Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:26:13 2005 -0700 -test_expect_success 'git notes copy --for-rewrite (unconfigured)' ' + ${indent}14th + EOF test_commit 14th && test_commit 15th && (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \ echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) | git notes copy --for-rewrite=foo && - git log -2 > output && - test_cmp expect output + git log -2 >actual && + test_cmp expect actual ' -cat > expect << EOF -commit 37a0d4cba38afef96ba54a3ea567e6dac575700b -Author: A U Thor <author@example.com> -Date: Thu Apr 7 15:27:13 2005 -0700 - - 15th - -Notes (other): - yet another note -$whitespace - yet another note - -commit be28d8b4d9951ad940d229ee3b0b9ee3b1ec273d -Author: A U Thor <author@example.com> -Date: Thu Apr 7 15:26:13 2005 -0700 - - 14th - -Notes (other): - other note -$whitespace - yet another note -EOF - test_expect_success 'git notes copy --for-rewrite (enabled)' ' - git config notes.rewriteMode overwrite && - git config notes.rewriteRef "refs/notes/*" && + cat >expect <<-EOF && + commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89 + Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:27:13 2005 -0700 + + ${indent}15th + + Notes: + ${indent}yet another note + ${indent} + ${indent}yet another note + + commit 07c85d77059393ed0154b8c96906547a59dfcddd + Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:26:13 2005 -0700 + + ${indent}14th + + Notes: + ${indent}other note + ${indent} + ${indent}yet another note + EOF + test_config notes.rewriteMode overwrite && + test_config notes.rewriteRef "refs/notes/*" && (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^); \ echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) | git notes copy --for-rewrite=foo && - git log -2 > output && - test_cmp expect output + git log -2 >actual && + test_cmp expect actual ' test_expect_success 'git notes copy --for-rewrite (disabled)' ' - git config notes.rewrite.bar false && + test_config notes.rewrite.bar false && echo $(git rev-parse HEAD~3) $(git rev-parse HEAD) | git notes copy --for-rewrite=bar && - git log -2 > output && - test_cmp expect output + git log -2 >actual && + test_cmp expect actual ' -cat > expect << EOF -commit 37a0d4cba38afef96ba54a3ea567e6dac575700b -Author: A U Thor <author@example.com> -Date: Thu Apr 7 15:27:13 2005 -0700 - - 15th +test_expect_success 'git notes copy --for-rewrite (overwrite)' ' + cat >expect <<-EOF && + commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89 + Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:27:13 2005 -0700 -Notes (other): - a fresh note -EOF + ${indent}15th -test_expect_success 'git notes copy --for-rewrite (overwrite)' ' + Notes: + ${indent}a fresh note + EOF git notes add -f -m"a fresh note" HEAD^ && + test_config notes.rewriteMode overwrite && + test_config notes.rewriteRef "refs/notes/*" && echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | git notes copy --for-rewrite=foo && - git log -1 > output && - test_cmp expect output + git log -1 >actual && + test_cmp expect actual ' test_expect_success 'git notes copy --for-rewrite (ignore)' ' - git config notes.rewriteMode ignore && + test_config notes.rewriteMode ignore && + test_config notes.rewriteRef "refs/notes/*" && echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | git notes copy --for-rewrite=foo && - git log -1 > output && - test_cmp expect output + git log -1 >actual && + test_cmp expect actual ' -cat > expect << EOF -commit 37a0d4cba38afef96ba54a3ea567e6dac575700b -Author: A U Thor <author@example.com> -Date: Thu Apr 7 15:27:13 2005 -0700 - - 15th - -Notes (other): - a fresh note -$whitespace - another fresh note -EOF - test_expect_success 'git notes copy --for-rewrite (append)' ' + cat >expect <<-EOF && + commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89 + Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:27:13 2005 -0700 + + ${indent}15th + + Notes: + ${indent}a fresh note + ${indent} + ${indent}another fresh note + EOF git notes add -f -m"another fresh note" HEAD^ && - git config notes.rewriteMode concatenate && + test_config notes.rewriteMode concatenate && + test_config notes.rewriteRef "refs/notes/*" && echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | git notes copy --for-rewrite=foo && - git log -1 > output && - test_cmp expect output + git log -1 >actual && + test_cmp expect actual ' -cat > expect << EOF -commit 37a0d4cba38afef96ba54a3ea567e6dac575700b -Author: A U Thor <author@example.com> -Date: Thu Apr 7 15:27:13 2005 -0700 - - 15th - -Notes (other): - a fresh note -$whitespace - another fresh note -$whitespace - append 1 -$whitespace - append 2 -EOF - test_expect_success 'git notes copy --for-rewrite (append two to one)' ' + cat >expect <<-EOF && + commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89 + Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:27:13 2005 -0700 + + ${indent}15th + + Notes: + ${indent}a fresh note + ${indent} + ${indent}another fresh note + ${indent} + ${indent}append 1 + ${indent} + ${indent}append 2 + EOF git notes add -f -m"append 1" HEAD^ && git notes add -f -m"append 2" HEAD^^ && + test_config notes.rewriteMode concatenate && + test_config notes.rewriteRef "refs/notes/*" && (echo $(git rev-parse HEAD^) $(git rev-parse HEAD); echo $(git rev-parse HEAD^^) $(git rev-parse HEAD)) | git notes copy --for-rewrite=foo && - git log -1 > output && - test_cmp expect output + git log -1 >actual && + test_cmp expect actual ' test_expect_success 'git notes copy --for-rewrite (append empty)' ' git notes remove HEAD^ && + test_config notes.rewriteMode concatenate && + test_config notes.rewriteRef "refs/notes/*" && echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | git notes copy --for-rewrite=foo && - git log -1 > output && - test_cmp expect output + git log -1 >actual && + test_cmp expect actual ' -cat > expect << EOF -commit 37a0d4cba38afef96ba54a3ea567e6dac575700b -Author: A U Thor <author@example.com> -Date: Thu Apr 7 15:27:13 2005 -0700 - - 15th - -Notes (other): - replacement note 1 -EOF - test_expect_success 'GIT_NOTES_REWRITE_MODE works' ' + cat >expect <<-EOF && + commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89 + Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:27:13 2005 -0700 + + ${indent}15th + + Notes: + ${indent}replacement note 1 + EOF + test_config notes.rewriteMode concatenate && + test_config notes.rewriteRef "refs/notes/*" && git notes add -f -m"replacement note 1" HEAD^ && echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo && - git log -1 > output && - test_cmp expect output + git log -1 >actual && + test_cmp expect actual ' -cat > expect << EOF -commit 37a0d4cba38afef96ba54a3ea567e6dac575700b -Author: A U Thor <author@example.com> -Date: Thu Apr 7 15:27:13 2005 -0700 +test_expect_success 'GIT_NOTES_REWRITE_REF works' ' + cat >expect <<-EOF && + commit 4acf42e847e7fffbbf89ee365c20ac7caf40de89 + Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:27:13 2005 -0700 - 15th + ${indent}15th -Notes (other): - replacement note 2 -EOF - -test_expect_success 'GIT_NOTES_REWRITE_REF works' ' - git config notes.rewriteMode overwrite && + Notes: + ${indent}replacement note 2 + EOF git notes add -f -m"replacement note 2" HEAD^ && - git config --unset-all notes.rewriteRef && + test_config notes.rewriteMode overwrite && + test_unconfig notes.rewriteRef && echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | GIT_NOTES_REWRITE_REF=refs/notes/commits:refs/notes/other \ git notes copy --for-rewrite=foo && - git log -1 > output && - test_cmp expect output + git log -1 >actual && + test_cmp expect actual ' test_expect_success 'GIT_NOTES_REWRITE_REF overrides config' ' - git config notes.rewriteRef refs/notes/other && git notes add -f -m"replacement note 3" HEAD^ && + test_config notes.rewriteMode overwrite && + test_config notes.rewriteRef refs/notes/other && echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | GIT_NOTES_REWRITE_REF= git notes copy --for-rewrite=foo && - git log -1 > output && - test_cmp expect output + git log -1 >actual && + test_cmp expect actual ' test_expect_success 'git notes copy diagnoses too many or too few parameters' ' @@ -1221,13 +1123,13 @@ test_expect_success 'git notes copy diagnoses too many or too few parameters' ' ' test_expect_success 'git notes get-ref (no overrides)' ' - git config --unset core.notesRef && + test_unconfig core.notesRef && sane_unset GIT_NOTES_REF && test "$(git notes get-ref)" = "refs/notes/commits" ' test_expect_success 'git notes get-ref (core.notesRef)' ' - git config core.notesRef refs/notes/foo && + test_config core.notesRef refs/notes/foo && test "$(git notes get-ref)" = "refs/notes/foo" ' @@ -1239,4 +1141,51 @@ test_expect_success 'git notes get-ref (--ref)' ' test "$(GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref)" = "refs/notes/baz" ' +test_expect_success 'setup testing of empty notes' ' + test_unconfig core.notesRef && + test_commit 16th && + empty_blob=$(git hash-object -w /dev/null) && + echo "$empty_blob" >expect_empty +' + +while read cmd +do + test_expect_success "'git notes $cmd' removes empty note" " + test_might_fail git notes remove HEAD && + MSG= git notes $cmd && + test_must_fail git notes list HEAD + " + + test_expect_success "'git notes $cmd --allow-empty' stores empty note" " + test_might_fail git notes remove HEAD && + MSG= git notes $cmd --allow-empty && + git notes list HEAD >actual && + test_cmp expect_empty actual + " +done <<\EOF +add +add -F /dev/null +add -m "" +add -c "$empty_blob" +add -C "$empty_blob" +append +append -F /dev/null +append -m "" +append -c "$empty_blob" +append -C "$empty_blob" +edit +EOF + +test_expect_success 'empty notes are displayed by git log' ' + test_commit 17th && + git log -1 >expect && + cat >>expect <<-EOF && + + Notes: + EOF + git notes add -C "$empty_blob" --allow-empty && + git log -1 >actual && + test_cmp expect actual +' + 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/t3507-cherry-pick-conflict.sh b/t/t3507-cherry-pick-conflict.sh index 223b98433c..7c5ad08626 100755 --- a/t/t3507-cherry-pick-conflict.sh +++ b/t/t3507-cherry-pick-conflict.sh @@ -351,19 +351,45 @@ test_expect_success 'commit after failed cherry-pick does not add duplicated -s' test_expect_success 'commit after failed cherry-pick adds -s at the right place' ' pristine_detach initial && test_must_fail git cherry-pick picked && + git commit -a -s && - pwd && - cat <<EOF > expected && -picked -Signed-off-by: C O Mitter <committer@example.com> + # Do S-o-b and Conflicts appear in the right order? + cat <<-\EOF >expect && + Signed-off-by: C O Mitter <committer@example.com> + # Conflicts: + EOF + grep -e "^# Conflicts:" -e '^Signed-off-by' <.git/COMMIT_EDITMSG >actual && + test_cmp expect actual && + + cat <<-\EOF >expected && + picked -Conflicts: - foo -EOF + Signed-off-by: C O Mitter <committer@example.com> + EOF - git show -s --pretty=format:%B > actual && + git show -s --pretty=format:%B >actual && test_cmp expected actual ' +test_expect_success 'commit --amend -s places the sign-off at the right place' ' + pristine_detach initial && + test_must_fail git cherry-pick picked && + + # emulate old-style conflicts block + mv .git/MERGE_MSG .git/MERGE_MSG+ && + sed -e "/^# Conflicts:/,\$s/^# *//" <.git/MERGE_MSG+ >.git/MERGE_MSG && + + git commit -a && + git commit --amend -s && + + # Do S-o-b and Conflicts appear in the right order? + cat <<-\EOF >expect && + Signed-off-by: C O Mitter <committer@example.com> + Conflicts: + EOF + grep -e "^Conflicts:" -e '^Signed-off-by' <.git/COMMIT_EDITMSG >actual && + test_cmp expect actual +' + test_done diff --git a/t/t3700-add.sh b/t/t3700-add.sh index fe274e2fb1..f7ff1f555d 100755 --- a/t/t3700-add.sh +++ b/t/t3700-add.sh @@ -91,6 +91,13 @@ test_expect_success 'error out when attempting to add ignored ones without -f' ' ! (git ls-files | grep "\\.ig") ' +test_expect_success 'error out when attempting to add ignored ones but add others' ' + touch a.if && + test_must_fail git add a.?? && + ! (git ls-files | grep "\\.ig") && + (git ls-files | grep a.if) +' + test_expect_success 'add ignored ones with -f' ' git add -f a.?? && git ls-files --error-unmatch a.ig @@ -311,7 +318,6 @@ cat >expect.err <<\EOF The following paths are ignored by one of your .gitignore files: ignored-file Use -f if you really want to add them. -fatal: no files added EOF cat >expect.out <<\EOF add 'track-this' 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/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/t4150-am.sh b/t/t4150-am.sh index 5edb79a058..306e6f39ac 100755 --- a/t/t4150-am.sh +++ b/t/t4150-am.sh @@ -85,6 +85,7 @@ test_expect_success setup ' git format-patch --stdout first >patch1 && { + echo "Message-Id: <1226501681-24923-1-git-send-email-bda@mnsspb.ru>" && echo "X-Fake-Field: Line One" && echo "X-Fake-Field: Line Two" && echo "X-Fake-Field: Line Three" && @@ -536,4 +537,26 @@ test_expect_success 'am empty-file does not infloop' ' test_i18ncmp expected actual ' +test_expect_success 'am --message-id really adds the message id' ' + rm -fr .git/rebase-apply && + git reset --hard && + git checkout HEAD^ && + git am --message-id patch1.eml && + test_path_is_missing .git/rebase-apply && + git cat-file commit HEAD | tail -n1 >actual && + grep Message-Id patch1.eml >expected && + test_cmp expected actual +' + +test_expect_success 'am --message-id -s signs off after the message id' ' + rm -fr .git/rebase-apply && + git reset --hard && + git checkout HEAD^ && + git am -s --message-id patch1.eml && + test_path_is_missing .git/rebase-apply && + git cat-file commit HEAD | tail -n2 | head -n1 >actual && + grep Message-Id patch1.eml >expected && + test_cmp expected actual +' + test_done diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index de0cc4a0fd..7398605e7b 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -438,6 +438,14 @@ test_expect_success 'strbuf_utf8_replace() not producing NUL' ' ! 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) && @@ -457,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/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..4b68bbafbe 100755 --- a/t/t5000-tar-tree.sh +++ b/t/t5000-tar-tree.sh @@ -101,7 +101,7 @@ test_expect_success \ ten=0123456789 && hundred=$ten$ten$ten$ten$ten$ten$ten$ten$ten$ten && echo long filename >a/four$hundred && mkdir a/bin && - cp /bin/sh a/bin && + test-genrandom "frotz" 500000 >a/bin/sh && printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 && printf "A not substituted O" >a/substfile2 && if test_have_prereq SYMLINKS; then @@ -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/t5004-archive-corner-cases.sh b/t/t5004-archive-corner-cases.sh index 83d20c4ba9..305bcac6b7 100755 --- a/t/t5004-archive-corner-cases.sh +++ b/t/t5004-archive-corner-cases.sh @@ -113,9 +113,4 @@ test_expect_success 'archive empty subtree by direct pathspec' ' check_dir extract sub ' -test_expect_success 'archive applies umask even for pax headers' ' - git archive --format=tar HEAD >archive.tar && - ! grep 0666 archive.tar -' - test_done diff --git a/t/t5100-mailinfo.sh b/t/t5100-mailinfo.sh index 3e64a7a65d..60df10f46a 100755 --- a/t/t5100-mailinfo.sh +++ b/t/t5100-mailinfo.sh @@ -35,6 +35,10 @@ do then check_mailinfo $mail --no-inbody-headers fi + if test -f "$TEST_DIRECTORY"/t5100/msg$mail--message-id + then + check_mailinfo $mail --message-id + fi ' done @@ -89,4 +93,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/info0012--message-id b/t/t5100/info0012--message-id new file mode 100644 index 0000000000..ac1216ff75 --- /dev/null +++ b/t/t5100/info0012--message-id @@ -0,0 +1,5 @@ +Author: Dmitriy Blinov +Email: bda@mnsspb.ru +Subject: Изменён список пакетов необходимых для сборки +Date: Wed, 12 Nov 2008 17:54:41 +0300 + diff --git a/t/t5100/msg0012--message-id b/t/t5100/msg0012--message-id new file mode 100644 index 0000000000..376e26e9ae --- /dev/null +++ b/t/t5100/msg0012--message-id @@ -0,0 +1,8 @@ +textlive-* исправлены на texlive-* +docutils заменён на python-docutils + +Действительно, оказалось, что rest2web вытягивает за собой +python-docutils. В то время как сам rest2web не нужен. + +Signed-off-by: Dmitriy Blinov <bda@mnsspb.ru> +Message-Id: <1226501681-24923-1-git-send-email-bda@mnsspb.ru> diff --git a/t/t5100/patch0012--message-id b/t/t5100/patch0012--message-id new file mode 100644 index 0000000000..36a0b68161 --- /dev/null +++ b/t/t5100/patch0012--message-id @@ -0,0 +1,30 @@ +--- + howto/build_navy.txt | 6 +++--- + 1 files changed, 3 insertions(+), 3 deletions(-) + +diff --git a/howto/build_navy.txt b/howto/build_navy.txt +index 3fd3afb..0ee807e 100644 +--- a/howto/build_navy.txt ++++ b/howto/build_navy.txt +@@ -119,8 +119,8 @@ + - libxv-dev + - libusplash-dev + - latex-make +- - textlive-lang-cyrillic +- - textlive-latex-extra ++ - texlive-lang-cyrillic ++ - texlive-latex-extra + - dia + - python-pyrex + - libtool +@@ -128,7 +128,7 @@ + - sox + - cython + - imagemagick +- - docutils ++ - python-docutils + + #. на машине dinar: добавить свой открытый ssh-ключ в authorized_keys2 пользователя ddev + #. на своей машине: отредактировать /etc/sudoers (команда ``visudo``) примерно следующим образом:: +-- +1.5.6.5 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/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/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..85c7fecd22 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,160 @@ 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_expect_success 'receive.denyCurrentBranch = updateInstead' ' + git push testrepo master && + ( + cd testrepo && + git reset --hard && + git config receive.denyCurrentBranch updateInstead + ) && + test_commit third path2 && + + # Try pushing into a repository with pristine working tree + git push testrepo master && + ( + cd testrepo && + git update-index -q --refresh && + git diff-files --quiet -- && + git diff-index --quiet --cached HEAD -- && + test third = "$(cat path2)" && + test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD) + ) && + + # Try pushing into a repository with working tree needing a refresh + ( + cd testrepo && + git reset --hard HEAD^ && + test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) && + test-chmtime +100 path1 + ) && + git push testrepo master && + ( + cd testrepo && + git update-index -q --refresh && + git diff-files --quiet -- && + git diff-index --quiet --cached HEAD -- && + test_cmp ../path1 path1 && + test third = "$(cat path2)" && + test $(git -C .. rev-parse HEAD) = $(git rev-parse HEAD) + ) && + + # Update what is to be pushed + test_commit fourth path2 && + + # Try pushing into a repository with a dirty working tree + # (1) the working tree updated + ( + cd testrepo && + echo changed >path1 + ) && + test_must_fail git push testrepo master && + ( + cd testrepo && + test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) && + git diff --quiet --cached && + test changed = "$(cat path1)" + ) && + + # (2) the index updated + ( + cd testrepo && + echo changed >path1 && + git add path1 + ) && + test_must_fail git push testrepo master && + ( + cd testrepo && + test $(git -C .. rev-parse HEAD^) = $(git rev-parse HEAD) && + git diff --quiet && + test changed = "$(cat path1)" + ) && + + # Introduce a new file in the update + test_commit fifth path3 && + + # (3) the working tree has an untracked file that would interfere + ( + cd testrepo && + git reset --hard && + echo changed >path3 + ) && + test_must_fail git push testrepo master && + ( + cd testrepo && + test $(git -C .. rev-parse HEAD^^) = $(git rev-parse HEAD) && + git diff --quiet && + git diff --quiet --cached && + test changed = "$(cat path3)" + ) && + + # (4) the target changes to what gets pushed but it still is a change + ( + cd testrepo && + git reset --hard && + echo fifth >path3 && + git add path3 + ) && + test_must_fail git push testrepo master && + ( + cd testrepo && + test $(git -C .. rev-parse HEAD^^) = $(git rev-parse HEAD) && + git diff --quiet && + test fifth = "$(cat path3)" + ) + +' + 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/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..bd0ab46750 --- /dev/null +++ b/t/t7513-interpret-trailers.sh @@ -0,0 +1,895 @@ +#!/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 + # last comment + + 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 message that has an old style conflict block' ' + 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 + + Conflicts: + + EOF + cat basic_message >expected && + cat >>expected <<-\EOF && + # comment + + Reviewed-by: Johan + Cc: Peff + # last comment + + Conflicts: + + EOF + 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/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/t9001-send-email.sh b/t/t9001-send-email.sh index 19a3ced600..e5016f4573 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -1298,6 +1298,163 @@ test_expect_success $PREREQ '--8bit-encoding also treats subject' ' test_cmp expected actual ' +test_expect_success $PREREQ 'setup expect' ' +cat >email-using-8bit <<EOF +From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001 +Message-Id: <bogus-message-id@example.com> +From: A U Thor <author@example.com> +Date: Sat, 12 Jun 2010 15:53:58 +0200 +Content-Type: text/plain; charset=UTF-8 +Subject: Nothing to see here. + +Dieser Betreff enthält auch einen Umlaut! +EOF +' + +test_expect_success $PREREQ 'sendemail.transferencoding=7bit fails on 8bit data' ' + clean_fake_sendmail && + git config sendemail.transferEncoding 7bit && + test_must_fail git send-email \ + --transfer-encoding=7bit \ + --smtp-server="$(pwd)/fake.sendmail" \ + email-using-8bit \ + 2>errors >out && + grep "cannot send message as 7bit" errors && + test -z "$(ls msgtxt*)" +' + +test_expect_success $PREREQ '--transfer-encoding overrides sendemail.transferEncoding' ' + clean_fake_sendmail && + git config sendemail.transferEncoding 8bit + test_must_fail git send-email \ + --transfer-encoding=7bit \ + --smtp-server="$(pwd)/fake.sendmail" \ + email-using-8bit \ + 2>errors >out && + grep "cannot send message as 7bit" errors && + test -z "$(ls msgtxt*)" +' + +test_expect_success $PREREQ 'sendemail.transferencoding=8bit' ' + clean_fake_sendmail && + git send-email \ + --transfer-encoding=8bit \ + --smtp-server="$(pwd)/fake.sendmail" \ + email-using-8bit \ + 2>errors >out && + sed '1,/^$/d' msgtxt1 >actual && + sed '1,/^$/d' email-using-8bit >expected && + test_cmp expected actual +' + +test_expect_success $PREREQ 'setup expect' ' +cat >expected <<EOF +Dieser Betreff enth=C3=A4lt auch einen Umlaut! +EOF +' + +test_expect_success $PREREQ '8-bit and sendemail.transferencoding=quoted-printable' ' + clean_fake_sendmail && + git send-email \ + --transfer-encoding=quoted-printable \ + --smtp-server="$(pwd)/fake.sendmail" \ + email-using-8bit \ + 2>errors >out && + sed '1,/^$/d' msgtxt1 >actual && + test_cmp expected actual +' + +test_expect_success $PREREQ 'setup expect' ' +cat >expected <<EOF +RGllc2VyIEJldHJlZmYgZW50aMOkbHQgYXVjaCBlaW5lbiBVbWxhdXQhCg== +EOF +' + +test_expect_success $PREREQ '8-bit and sendemail.transferencoding=base64' ' + clean_fake_sendmail && + git send-email \ + --transfer-encoding=base64 \ + --smtp-server="$(pwd)/fake.sendmail" \ + email-using-8bit \ + 2>errors >out && + sed '1,/^$/d' msgtxt1 >actual && + test_cmp expected actual +' + +test_expect_success $PREREQ 'setup expect' ' +cat >email-using-qp <<EOF +From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001 +Message-Id: <bogus-message-id@example.com> +From: A U Thor <author@example.com> +Date: Sat, 12 Jun 2010 15:53:58 +0200 +MIME-Version: 1.0 +Content-Transfer-Encoding: quoted-printable +Content-Type: text/plain; charset=UTF-8 +Subject: Nothing to see here. + +Dieser Betreff enth=C3=A4lt auch einen Umlaut! +EOF +' + +test_expect_success $PREREQ 'convert from quoted-printable to base64' ' + clean_fake_sendmail && + git send-email \ + --transfer-encoding=base64 \ + --smtp-server="$(pwd)/fake.sendmail" \ + email-using-qp \ + 2>errors >out && + sed '1,/^$/d' msgtxt1 >actual && + test_cmp expected actual +' + +test_expect_success $PREREQ 'setup expect' " +tr -d '\\015' | tr '%' '\\015' > email-using-crlf <<EOF +From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001 +Message-Id: <bogus-message-id@example.com> +From: A U Thor <author@example.com> +Date: Sat, 12 Jun 2010 15:53:58 +0200 +Content-Type: text/plain; charset=UTF-8 +Subject: Nothing to see here. + +Look, I have a CRLF and an = sign!% +EOF +" + +test_expect_success $PREREQ 'setup expect' ' +cat >expected <<EOF +Look, I have a CRLF and an =3D sign!=0D +EOF +' + +test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=quoted-printable' ' + clean_fake_sendmail && + git send-email \ + --transfer-encoding=quoted-printable \ + --smtp-server="$(pwd)/fake.sendmail" \ + email-using-crlf \ + 2>errors >out && + sed '1,/^$/d' msgtxt1 >actual && + test_cmp expected actual +' + +test_expect_success $PREREQ 'setup expect' ' +cat >expected <<EOF +TG9vaywgSSBoYXZlIGEgQ1JMRiBhbmQgYW4gPSBzaWduIQ0K +EOF +' + +test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=base64' ' + clean_fake_sendmail && + git send-email \ + --transfer-encoding=base64 \ + --smtp-server="$(pwd)/fake.sendmail" \ + email-using-crlf \ + 2>errors >out && + sed '1,/^$/d' msgtxt1 >actual && + test_cmp expected actual +' + + # Note that the patches in this test are deliberately out of order; we # want to make sure it works even if the cover-letter is not in the # first mail. 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 99f51614ad..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 @@ -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/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 2b525a8e1d..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,6 +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 NATIVE_CRLF test_set_prereq SED_STRIPS_CR test_set_prereq GREP_STRIPS_CR GIT_TEST_CMP=mingw_test_cmp |