diff options
Diffstat (limited to 't')
258 files changed, 8916 insertions, 2120 deletions
diff --git a/t/.gitattributes b/t/.gitattributes index 1b97c5465b..2d44088f56 100644 --- a/t/.gitattributes +++ b/t/.gitattributes @@ -1 +1,2 @@ t[0-9][0-9][0-9][0-9]/* -whitespace +t0110/url-* binary diff --git a/t/Git-SVN/00compile.t b/t/Git-SVN/00compile.t index c92fee453f..c92fee453f 100644..100755 --- a/t/Git-SVN/00compile.t +++ b/t/Git-SVN/00compile.t diff --git a/t/Git-SVN/Utils/add_path_to_url.t b/t/Git-SVN/Utils/add_path_to_url.t index bfbd87845f..bfbd87845f 100644..100755 --- a/t/Git-SVN/Utils/add_path_to_url.t +++ b/t/Git-SVN/Utils/add_path_to_url.t diff --git a/t/Git-SVN/Utils/can_compress.t b/t/Git-SVN/Utils/can_compress.t index d7b49b8d54..d7b49b8d54 100644..100755 --- a/t/Git-SVN/Utils/can_compress.t +++ b/t/Git-SVN/Utils/can_compress.t diff --git a/t/Git-SVN/Utils/canonicalize_url.t b/t/Git-SVN/Utils/canonicalize_url.t index 05795ab636..05795ab636 100644..100755 --- a/t/Git-SVN/Utils/canonicalize_url.t +++ b/t/Git-SVN/Utils/canonicalize_url.t diff --git a/t/Git-SVN/Utils/collapse_dotdot.t b/t/Git-SVN/Utils/collapse_dotdot.t index 1da1cce156..1da1cce156 100644..100755 --- a/t/Git-SVN/Utils/collapse_dotdot.t +++ b/t/Git-SVN/Utils/collapse_dotdot.t diff --git a/t/Git-SVN/Utils/fatal.t b/t/Git-SVN/Utils/fatal.t index 49e1438295..49e1438295 100644..100755 --- a/t/Git-SVN/Utils/fatal.t +++ b/t/Git-SVN/Utils/fatal.t diff --git a/t/Git-SVN/Utils/join_paths.t b/t/Git-SVN/Utils/join_paths.t index d4488e7162..d4488e7162 100644..100755 --- a/t/Git-SVN/Utils/join_paths.t +++ b/t/Git-SVN/Utils/join_paths.t @@ -340,7 +340,11 @@ Don't: - use perl without spelling it as "$PERL_PATH". This is to help our friends on Windows where the platform Perl often adds CR before the end of line, and they bundle Git with a version of Perl that - does not do so, whose path is specified with $PERL_PATH. + does not do so, whose path is specified with $PERL_PATH. Note that we + provide a "perl" function which uses $PERL_PATH under the hood, so + you do not need to worry when simply running perl in the test scripts + (but you do, for example, on a shebang line or in a sub script + created via "write_script"). - use sh without spelling it as "$SHELL_PATH", when the script can be misinterpreted by broken platform shell (e.g. Solaris). @@ -387,7 +391,7 @@ of the test_* functions (see the "Test harness library" section below), e.g.: test_expect_success PERL 'I need Perl' ' - "$PERL_PATH" -e "hlagh() if unf_unf()" + perl -e "hlagh() if unf_unf()" ' The advantage of skipping tests like this is that platforms that don't @@ -520,7 +524,7 @@ library for your script to use. test_external \ 'GitwebCache::*FileCache*' \ - "$PERL_PATH" "$TEST_DIRECTORY"/t9503/test_cache_interface.pl + perl "$TEST_DIRECTORY"/t9503/test_cache_interface.pl If the test is outputting its own TAP you should set the test_external_has_tap variable somewhere before calling the first @@ -536,7 +540,7 @@ library for your script to use. test_external_without_stderr \ 'Perl API' \ - "$PERL_PATH" "$TEST_DIRECTORY"/t9700/test.pl + perl "$TEST_DIRECTORY"/t9700/test.pl - test_expect_code <exit-code> <command> @@ -629,11 +633,18 @@ See the prereq argument to the test_* functions in the "Test harness library" section above and the "test_have_prereq" function for how to use these, and "test_set_prereq" for how to define your own. - - PERL & PYTHON + - PYTHON - Git wasn't compiled with NO_PERL=YesPlease or - NO_PYTHON=YesPlease. Wrap any tests that need Perl or Python in - these. + Git wasn't compiled with NO_PYTHON=YesPlease. Wrap any tests that + need Python with this. + + - PERL + + Git wasn't compiled with NO_PERL=YesPlease. + + Even without the PERL prerequisite, tests can assume there is a + usable perl interpreter at $PERL_PATH, though it need not be + particularly modern. - POSIXPERM diff --git a/t/annotate-tests.sh b/t/annotate-tests.sh index d4e7f4736f..304c7b7d87 100644 --- a/t/annotate-tests.sh +++ b/t/annotate-tests.sh @@ -92,7 +92,7 @@ test_expect_success 'blame 2 authors + 1 branch2 author' ' ' test_expect_success 'merge branch1 & branch2' ' - git pull . branch1 + git merge branch1 ' test_expect_success 'blame 2 authors + 2 merged-in authors' ' @@ -116,6 +116,27 @@ test_expect_success 'blame evil merge' ' check_count A 2 B 1 B1 2 B2 1 "A U Thor" 1 ' +test_expect_success 'blame huge graft' ' + test_when_finished "git checkout branch2" && + test_when_finished "rm -f .git/info/grafts" && + graft= && + for i in 0 1 2 + do + for j in 0 1 2 3 4 5 6 7 8 9 + do + git checkout --orphan "$i$j" && + printf "%s\n" "$i" "$j" >file && + test_tick && + GIT_AUTHOR_NAME=$i$j GIT_AUTHOR_EMAIL=$i$j@test.git \ + git commit -a -m "$i$j" && + commit=$(git rev-parse --verify HEAD) && + graft="$graft$commit " + done + done && + printf "%s " $graft >.git/info/grafts && + check_count -h 00 01 1 10 1 +' + test_expect_success 'setup incomplete line' ' echo "incomplete" | tr -d "\\012" >>file && GIT_AUTHOR_NAME="C" GIT_AUTHOR_EMAIL="C@test.git" \ @@ -185,6 +206,26 @@ test_expect_success 'blame -L Y,X (undocumented)' ' check_count -L6,3 B 1 B1 1 B2 1 D 1 ' +test_expect_success 'blame -L -X' ' + test_must_fail $PROG -L-1 file +' + +test_expect_success 'blame -L 0' ' + test_must_fail $PROG -L0 file +' + +test_expect_success 'blame -L ,0' ' + test_must_fail $PROG -L,0 file +' + +test_expect_success 'blame -L ,+0' ' + test_must_fail $PROG -L,+0 file +' + +test_expect_success 'blame -L X,+0' ' + test_must_fail $PROG -L1,+0 file +' + test_expect_success 'blame -L X,+1' ' check_count -L3,+1 B2 1 ' @@ -193,6 +234,14 @@ test_expect_success 'blame -L X,+N' ' check_count -L3,+4 B 1 B1 1 B2 1 D 1 ' +test_expect_success 'blame -L ,-0' ' + test_must_fail $PROG -L,-0 file +' + +test_expect_success 'blame -L X,-0' ' + test_must_fail $PROG -L1,-0 file +' + test_expect_success 'blame -L X,-1' ' check_count -L3,-1 B2 1 ' @@ -225,14 +274,105 @@ test_expect_success 'blame -L /RE/,-N' ' check_count -L/99/,-3 B 1 B2 1 D 1 ' +# 'file' ends with an incomplete line, so 'wc' reports one fewer lines than +# git-blame sees, hence the last line is actually $(wc...)+1. +test_expect_success 'blame -L X (X == nlines)' ' + n=$(expr $(wc -l <file) + 1) && + check_count -L$n C 1 +' + +test_expect_success 'blame -L X (X == nlines + 1)' ' + n=$(expr $(wc -l <file) + 2) && + test_must_fail $PROG -L$n file +' + test_expect_success 'blame -L X (X > nlines)' ' test_must_fail $PROG -L12345 file ' +test_expect_success 'blame -L ,Y (Y == nlines)' ' + n=$(expr $(wc -l <file) + 1) && + check_count -L,$n A 1 B 1 B1 1 B2 1 "A U Thor" 1 C 1 D 1 E 1 +' + +test_expect_success 'blame -L ,Y (Y == nlines + 1)' ' + n=$(expr $(wc -l <file) + 2) && + test_must_fail $PROG -L,$n file +' + test_expect_success 'blame -L ,Y (Y > nlines)' ' test_must_fail $PROG -L,12345 file ' +test_expect_success 'blame -L multiple (disjoint)' ' + check_count -L2,3 -L6,7 A 1 B1 1 B2 1 "A U Thor" 1 +' + +test_expect_success 'blame -L multiple (disjoint: unordered)' ' + check_count -L6,7 -L2,3 A 1 B1 1 B2 1 "A U Thor" 1 +' + +test_expect_success 'blame -L multiple (adjacent)' ' + check_count -L2,3 -L4,5 A 1 B 1 B2 1 D 1 +' + +test_expect_success 'blame -L multiple (adjacent: unordered)' ' + check_count -L4,5 -L2,3 A 1 B 1 B2 1 D 1 +' + +test_expect_success 'blame -L multiple (overlapping)' ' + check_count -L2,4 -L3,5 A 1 B 1 B2 1 D 1 +' + +test_expect_success 'blame -L multiple (overlapping: unordered)' ' + check_count -L3,5 -L2,4 A 1 B 1 B2 1 D 1 +' + +test_expect_success 'blame -L multiple (superset/subset)' ' + check_count -L2,8 -L3,5 A 1 B 1 B1 1 B2 1 C 1 D 1 "A U Thor" 1 +' + +test_expect_success 'blame -L multiple (superset/subset: unordered)' ' + check_count -L3,5 -L2,8 A 1 B 1 B1 1 B2 1 C 1 D 1 "A U Thor" 1 +' + +test_expect_success 'blame -L /RE/ (relative)' ' + check_count -L3,3 -L/fox/ B1 1 B2 1 C 1 D 1 "A U Thor" 1 +' + +test_expect_success 'blame -L /RE/ (relative: no preceding range)' ' + check_count -L/dog/ A 1 B 1 B1 1 B2 1 C 1 D 1 "A U Thor" 1 +' + +test_expect_success 'blame -L /RE/ (relative: adjacent)' ' + check_count -L1,1 -L/dog/,+1 A 1 E 1 +' + +test_expect_success 'blame -L /RE/ (relative: not found)' ' + test_must_fail $PROG -L4,4 -L/dog/ file +' + +test_expect_success 'blame -L /RE/ (relative: end-of-file)' ' + test_must_fail $PROG -L, -L/$/ file +' + +test_expect_success 'blame -L ^/RE/ (absolute)' ' + check_count -L3,3 -L^/dog/,+2 A 1 B2 1 +' + +test_expect_success 'blame -L ^/RE/ (absolute: no preceding range)' ' + check_count -L^/dog/,+2 A 1 B2 1 +' + +test_expect_success 'blame -L ^/RE/ (absolute: not found)' ' + test_must_fail $PROG -L4,4 -L^/tambourine/ file +' + +test_expect_success 'blame -L ^/RE/ (absolute: end-of-file)' ' + n=$(expr $(wc -l <file) + 1) && + check_count -L$n -L^/$/,+2 A 1 C 1 E 1 +' + test_expect_success 'setup -L :regex' ' tr Q "\\t" >hello.c <<-\EOF && int main(int argc, const char *argv[]) @@ -275,12 +415,139 @@ test_expect_success 'blame -L :nomatch' ' test_must_fail $PROG -L:nomatch hello.c ' -test_expect_success 'blame -L bogus' ' - test_must_fail $PROG -L file && - test_must_fail $PROG -L1,+ file && - test_must_fail $PROG -L1,- file && - test_must_fail $PROG -LX file && - test_must_fail $PROG -L1,X file && - test_must_fail $PROG -L1,+N file && +test_expect_success 'blame -L :RE (relative)' ' + check_count -f hello.c -L3,3 -L:ma.. F 1 H 4 +' + +test_expect_success 'blame -L :RE (relative: no preceding range)' ' + check_count -f hello.c -L:ma.. F 4 G 1 +' + +test_expect_success 'blame -L :RE (relative: not found)' ' + test_must_fail $PROG -L3,3 -L:tambourine hello.c +' + +test_expect_success 'blame -L :RE (relative: end-of-file)' ' + test_must_fail $PROG -L, -L:main hello.c +' + +test_expect_success 'blame -L ^:RE (absolute)' ' + check_count -f hello.c -L3,3 -L^:ma.. F 4 G 1 +' + +test_expect_success 'blame -L ^:RE (absolute: no preceding range)' ' + check_count -f hello.c -L^:ma.. F 4 G 1 +' + +test_expect_success 'blame -L ^:RE (absolute: not found)' ' + test_must_fail $PROG -L4,4 -L^:tambourine hello.c +' + +test_expect_success 'blame -L ^:RE (absolute: end-of-file)' ' + n=$(printf "%d" $(wc -l <hello.c)) && + check_count -f hello.c -L$n -L^:ma.. F 4 G 1 H 1 +' + +test_expect_success 'setup incremental' ' + ( + GIT_AUTHOR_NAME=I && + export GIT_AUTHOR_NAME && + GIT_AUTHOR_EMAIL=I@test.git && + export GIT_AUTHOR_EMAIL && + >incremental && + git add incremental && + git commit -m "step 0" && + printf "partial" >>incremental && + git commit -a -m "step 0.5" && + echo >>incremental && + git commit -a -m "step 1" + ) +' + +test_expect_success 'blame empty' ' + check_count -h HEAD^^ -f incremental +' + +test_expect_success 'blame -L 0 empty' ' + test_must_fail $PROG -L0 incremental HEAD^^ +' + +test_expect_success 'blame -L 1 empty' ' + test_must_fail $PROG -L1 incremental HEAD^^ +' + +test_expect_success 'blame -L 2 empty' ' + test_must_fail $PROG -L2 incremental HEAD^^ +' + +test_expect_success 'blame half' ' + check_count -h HEAD^ -f incremental I 1 +' + +test_expect_success 'blame -L 0 half' ' + test_must_fail $PROG -L0 incremental HEAD^ +' + +test_expect_success 'blame -L 1 half' ' + check_count -h HEAD^ -f incremental -L1 I 1 +' + +test_expect_success 'blame -L 2 half' ' + test_must_fail $PROG -L2 incremental HEAD^ +' + +test_expect_success 'blame -L 3 half' ' + test_must_fail $PROG -L3 incremental HEAD^ +' + +test_expect_success 'blame full' ' + check_count -f incremental I 1 +' + +test_expect_success 'blame -L 0 full' ' + test_must_fail $PROG -L0 incremental +' + +test_expect_success 'blame -L 1 full' ' + check_count -f incremental -L1 I 1 +' + +test_expect_success 'blame -L 2 full' ' + test_must_fail $PROG -L2 incremental +' + +test_expect_success 'blame -L 3 full' ' + test_must_fail $PROG -L3 incremental +' + +test_expect_success 'blame -L' ' + test_must_fail $PROG -L file +' + +test_expect_success 'blame -L X,+' ' + test_must_fail $PROG -L1,+ file +' + +test_expect_success 'blame -L X,-' ' + test_must_fail $PROG -L1,- file +' + +test_expect_success 'blame -L X (non-numeric X)' ' + test_must_fail $PROG -LX file +' + +test_expect_success 'blame -L X,Y (non-numeric Y)' ' + test_must_fail $PROG -L1,Y file +' + +test_expect_success 'blame -L X,+N (non-numeric N)' ' + test_must_fail $PROG -L1,+N file +' + +test_expect_success 'blame -L X,-N (non-numeric N)' ' test_must_fail $PROG -L1,-N file ' + +test_expect_success 'blame -L ,^/RE/' ' + test_must_fail $PROG -L1,^/99/ file +' diff --git a/t/gitweb-lib.sh b/t/gitweb-lib.sh index 9e381e000f..d5dab5a94f 100644 --- a/t/gitweb-lib.sh +++ b/t/gitweb-lib.sh @@ -1,4 +1,5 @@ -#!/bin/sh +# Initialization and helpers for Gitweb tests, which source this +# shell library instead of test-lib.sh. # # Copyright (c) 2007 Jakub Narebski # @@ -69,7 +70,7 @@ gitweb_run () { # written to web server logs, so we are not interested in that: # we are interested only in properly formatted errors/warnings rm -f gitweb.log && - "$PERL_PATH" -- "$SCRIPT_NAME" \ + perl -- "$SCRIPT_NAME" \ >gitweb.output 2>gitweb.log && perl -w -e ' open O, ">gitweb.headers"; diff --git a/t/lib-bash.sh b/t/lib-bash.sh index 11397f747b..2be955fafb 100644 --- a/t/lib-bash.sh +++ b/t/lib-bash.sh @@ -1,7 +1,6 @@ -#!/bin/sh -# -# Ensures that tests are run under Bash; primarily intended for running tests -# of the completion script. +# Shell library sourced instead of ./test-lib.sh by tests that need +# to run under Bash; primarily intended for tests of the completion +# script. if test -n "$BASH" && test -z "$POSIXLY_CORRECT"; then # we are in full-on bash mode diff --git a/t/lib-credential.sh b/t/lib-credential.sh index 3c43ff11b3..957ae936e8 100755 --- a/t/lib-credential.sh +++ b/t/lib-credential.sh @@ -18,10 +18,6 @@ check() { cat stderr && false fi && - if test_have_prereq MINGW - then - dos2unix -q stderr - fi && test_cmp expect-stdout stdout && test_cmp expect-stderr stderr } diff --git a/t/lib-cvs.sh b/t/lib-cvs.sh index 44263ade25..5076718916 100644 --- a/t/lib-cvs.sh +++ b/t/lib-cvs.sh @@ -1,4 +1,4 @@ -#!/bin/sh +# Shell library sourced instead of ./test-lib.sh by cvsimport tests. . ./test-lib.sh diff --git a/t/lib-diff-alternative.sh b/t/lib-diff-alternative.sh index 75ffd9174f..8b4dbf22d2 100644 --- a/t/lib-diff-alternative.sh +++ b/t/lib-diff-alternative.sh @@ -1,4 +1,5 @@ -#!/bin/sh +# Helpers shared by the test scripts for diff algorithms (patience, +# histogram, etc). test_diff_frobnitz() { cat >file1 <<\EOF diff --git a/t/lib-gettext.sh b/t/lib-gettext.sh index ae8883a075..eec757f104 100644 --- a/t/lib-gettext.sh +++ b/t/lib-gettext.sh @@ -1,4 +1,5 @@ -#!/bin/sh +# Initialization and Icelandic locale for basic git i18n tests, +# which source this scriptlet instead of ./test-lib.sh. # # Copyright (c) 2010 Ævar Arnfjörð Bjarmason # diff --git a/t/lib-git-daemon.sh b/t/lib-git-daemon.sh index 87f0ad8f41..bc4b3412fb 100644 --- a/t/lib-git-daemon.sh +++ b/t/lib-git-daemon.sh @@ -1,12 +1,29 @@ -#!/bin/sh +# Shell library to run git-daemon in tests. Ends the test early if +# GIT_TEST_GIT_DAEMON is not set. +# +# Usage: +# +# . ./test-lib.sh +# . "$TEST_DIRECTORY"/lib-git-daemon.sh +# start_git_daemon +# +# test_expect_success '...' ' +# ... +# ' +# +# test_expect_success ... +# +# stop_git_daemon +# test_done -if test -z "$GIT_TEST_GIT_DAEMON" +test_tristate GIT_TEST_GIT_DAEMON +if test "$GIT_TEST_GIT_DAEMON" = false then - skip_all="git-daemon testing disabled (define GIT_TEST_GIT_DAEMON to enable)" + skip_all="git-daemon testing disabled (unset GIT_TEST_GIT_DAEMON to enable)" test_done fi -LIB_GIT_DAEMON_PORT=${LIB_GIT_DAEMON_PORT-'8121'} +LIB_GIT_DAEMON_PORT=${LIB_GIT_DAEMON_PORT-${this_test#t}} GIT_DAEMON_PID= GIT_DAEMON_DOCUMENT_ROOT_PATH="$PWD"/repo @@ -42,7 +59,8 @@ start_git_daemon() { kill "$GIT_DAEMON_PID" wait "$GIT_DAEMON_PID" trap 'die' EXIT - error "git daemon failed to start" + test_skip_or_die $GIT_TEST_GIT_DAEMON \ + "git daemon failed to start" fi } diff --git a/t/lib-git-p4.sh b/t/lib-git-p4.sh index 2098b9ba05..5aa8adcf9c 100644 --- a/t/lib-git-p4.sh +++ b/t/lib-git-p4.sh @@ -47,14 +47,22 @@ P4DPORT=$((10669 + ($testid - $git_p4_test_start))) P4PORT=localhost:$P4DPORT P4CLIENT=client -P4EDITOR=: -export P4PORT P4CLIENT P4EDITOR +P4USER=author +P4EDITOR=true +unset P4CHARSET +export P4PORT P4CLIENT P4USER P4EDITOR P4CHARSET db="$TRASH_DIRECTORY/db" cli="$TRASH_DIRECTORY/cli" git="$TRASH_DIRECTORY/git" pidfile="$TRASH_DIRECTORY/p4d.pid" +# git p4 submit generates a temp file, which will +# not get cleaned up if the submission fails. Don't +# clutter up /tmp on the test machine. +TMPDIR="$TRASH_DIRECTORY" +export TMPDIR + start_p4d() { mkdir -p "$db" "$cli" "$git" && rm -f "$pidfile" && @@ -95,12 +103,24 @@ start_p4d() { return 1 fi + # build a p4 user so author@example.com has an entry + p4_add_user author + # build a client client_view "//depot/... //client/..." && return 0 } +p4_add_user() { + name=$1 && + p4 user -f -i <<-EOF + User: $name + Email: $name@example.com + FullName: Dr. $name + EOF +} + kill_p4d() { pid=$(cat "$pidfile") # it had better exist for the first kill diff --git a/t/lib-git-svn.sh b/t/lib-git-svn.sh index c5e55b190b..b0ec12ff6c 100644 --- a/t/lib-git-svn.sh +++ b/t/lib-git-svn.sh @@ -29,7 +29,7 @@ export svnrepo svnconf=$PWD/svnconf export svnconf -"$PERL_PATH" -w -e " +perl -w -e " use SVN::Core; use SVN::Repos; \$SVN::Core::VERSION gt '1.1.0' or exit(42); @@ -146,7 +146,7 @@ stop_httpd () { } convert_to_rev_db () { - "$PERL_PATH" -w -- - "$@" <<\EOF + perl -w -- - "$@" <<\EOF use strict; @ARGV == 2 or die "usage: convert_to_rev_db <input> <output>"; open my $wr, '+>', $ARGV[1] or die "$!: couldn't open: $ARGV[1]"; diff --git a/t/lib-httpd.sh b/t/lib-httpd.sh index 895b9258b0..252cbf163b 100644 --- a/t/lib-httpd.sh +++ b/t/lib-httpd.sh @@ -1,11 +1,39 @@ -#!/bin/sh +# Shell library to run an HTTP server for use in tests. +# Ends the test early if httpd tests should not be run, +# for example because the user has not enabled them. +# +# Usage: +# +# . ./test-lib.sh +# . "$TEST_DIRECTORY"/lib-httpd.sh +# start_httpd +# +# test_expect_success '...' ' +# ... +# ' +# +# test_expect_success ... +# +# stop_httpd +# test_done +# +# Can be configured using the following variables. +# +# GIT_TEST_HTTPD enable HTTPD tests +# LIB_HTTPD_PATH web server path +# LIB_HTTPD_MODULE_PATH web server modules path +# LIB_HTTPD_PORT listening port +# LIB_HTTPD_DAV enable DAV +# LIB_HTTPD_SVN enable SVN +# LIB_HTTPD_SSL enable SSL # # Copyright (c) 2008 Clemens Buchacher <drizzd@aon.at> # -if test -z "$GIT_TEST_HTTPD" +test_tristate GIT_TEST_HTTPD +if test "$GIT_TEST_HTTPD" = false then - skip_all="Network testing disabled (define GIT_TEST_HTTPD to enable)" + skip_all="Network testing disabled (unset GIT_TEST_HTTPD to enable)" test_done fi @@ -37,7 +65,7 @@ case $(uname) in esac LIB_HTTPD_PATH=${LIB_HTTPD_PATH-"$DEFAULT_HTTPD_PATH"} -LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'8111'} +LIB_HTTPD_PORT=${LIB_HTTPD_PORT-${this_test#t}} TEST_PATH="$TEST_DIRECTORY"/lib-httpd HTTPD_ROOT_PATH="$PWD"/httpd @@ -49,8 +77,7 @@ GIT_VALGRIND_OPTIONS=$GIT_VALGRIND_OPTIONS; export GIT_VALGRIND_OPTIONS if ! test -x "$LIB_HTTPD_PATH" then - skip_all="skipping test, no web server found at '$LIB_HTTPD_PATH'" - test_done + test_skip_or_die $GIT_TEST_HTTPD "no web server found at '$LIB_HTTPD_PATH'" fi HTTPD_VERSION=`$LIB_HTTPD_PATH -v | \ @@ -62,19 +89,20 @@ then then if ! test $HTTPD_VERSION -ge 2 then - skip_all="skipping test, at least Apache version 2 is required" - test_done + test_skip_or_die $GIT_TEST_HTTPD \ + "at least Apache version 2 is required" fi if ! test -d "$DEFAULT_HTTPD_MODULE_PATH" then - skip_all="Apache module directory not found. Skipping tests." - test_done + test_skip_or_die $GIT_TEST_HTTPD \ + "Apache module directory not found" fi LIB_HTTPD_MODULE_PATH="$DEFAULT_HTTPD_MODULE_PATH" fi else - error "Could not identify web server at '$LIB_HTTPD_PATH'" + test_skip_or_die $GIT_TEST_HTTPD \ + "Could not identify web server at '$LIB_HTTPD_PATH'" fi prepare_httpd() { @@ -102,7 +130,7 @@ prepare_httpd() { HTTPD_DEST=127.0.0.1:$LIB_HTTPD_PORT HTTPD_URL=$HTTPD_PROTO://$HTTPD_DEST HTTPD_URL_USER=$HTTPD_PROTO://user%40host@$HTTPD_DEST - HTTPD_URL_USER_PASS=$HTTPD_PROTO://user%40host:user%40host@$HTTPD_DEST + HTTPD_URL_USER_PASS=$HTTPD_PROTO://user%40host:pass%40host@$HTTPD_DEST if test -n "$LIB_HTTPD_DAV" -o -n "$LIB_HTTPD_SVN" then @@ -128,9 +156,8 @@ start_httpd() { >&3 2>&4 if test $? -ne 0 then - skip_all="skipping test, web server setup failed" trap 'die' EXIT - test_done + test_skip_or_die $GIT_TEST_HTTPD "web server setup failed" fi } @@ -141,10 +168,11 @@ stop_httpd() { -f "$TEST_PATH/apache.conf" $HTTPD_PARA -k stop } -test_http_push_nonff() { +test_http_push_nonff () { REMOTE_REPO=$1 LOCAL_REPO=$2 BRANCH=$3 + EXPECT_CAS_RESULT=${4-failure} test_expect_success 'non-fast-forward push fails' ' cd "$REMOTE_REPO" && @@ -167,13 +195,37 @@ test_http_push_nonff() { test_expect_success 'non-fast-forward push shows help message' ' test_i18ngrep "Updates were rejected because" output ' + + test_expect_${EXPECT_CAS_RESULT} 'force with lease aka cas' ' + HEAD=$( cd "$REMOTE_REPO" && git rev-parse --verify HEAD ) && + test_when_finished '\'' + (cd "$REMOTE_REPO" && git update-ref HEAD "$HEAD") + '\'' && + ( + cd "$LOCAL_REPO" && + git push -v --force-with-lease=$BRANCH:$HEAD origin + ) && + git rev-parse --verify "$BRANCH" >expect && + ( + cd "$REMOTE_REPO" && git rev-parse --verify HEAD + ) >actual && + test_cmp expect actual + ' } setup_askpass_helper() { test_expect_success 'setup askpass helper' ' write_script "$TRASH_DIRECTORY/askpass" <<-\EOF && echo >>"$TRASH_DIRECTORY/askpass-query" "askpass: $*" && - cat "$TRASH_DIRECTORY/askpass-response" + case "$*" in + *Username*) + what=user + ;; + *Password*) + what=pass + ;; + esac && + cat "$TRASH_DIRECTORY/askpass-$what" EOF GIT_ASKPASS="$TRASH_DIRECTORY/askpass" && export GIT_ASKPASS && @@ -183,11 +235,13 @@ setup_askpass_helper() { set_askpass() { >"$TRASH_DIRECTORY/askpass-query" && - echo "$*" >"$TRASH_DIRECTORY/askpass-response" + echo "$1" >"$TRASH_DIRECTORY/askpass-user" && + echo "$2" >"$TRASH_DIRECTORY/askpass-pass" } expect_askpass() { - dest=$HTTPD_DEST + dest=$HTTPD_DEST${3+/$3} + { case "$1" in none) diff --git a/t/lib-httpd/apache.conf b/t/lib-httpd/apache.conf index dd17e3a09d..3a03e8263d 100644 --- a/t/lib-httpd/apache.conf +++ b/t/lib-httpd/apache.conf @@ -22,6 +22,9 @@ ErrorLog error.log <IfModule !mod_version.c> LoadModule version_module modules/mod_version.so </IfModule> +<IfModule !mod_headers.c> + LoadModule headers_module modules/mod_headers.so +</IfModule> <IfVersion < 2.4> LockFile accept.lock @@ -87,6 +90,11 @@ Alias /auth/dumb/ www/auth/dumb/ SetEnv GIT_HTTP_EXPORT_ALL SetEnv GIT_NAMESPACE ns </LocationMatch> +<LocationMatch /smart_cookies/> + SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH} + SetEnv GIT_HTTP_EXPORT_ALL + Header set Set-Cookie name=value +</LocationMatch> ScriptAliasMatch /smart_*[^/]*/(.*) ${GIT_EXEC_PATH}/git-http-backend/$1 ScriptAlias /broken_smart/ broken-smart-http.sh/ <Directory ${GIT_EXEC_PATH}> @@ -102,6 +110,8 @@ ScriptAlias /broken_smart/ broken-smart-http.sh/ RewriteEngine on RewriteRule ^/smart-redir-perm/(.*)$ /smart/$1 [R=301] RewriteRule ^/smart-redir-temp/(.*)$ /smart/$1 [R=302] +RewriteRule ^/smart-redir-auth/(.*)$ /auth/smart/$1 [R=301] +RewriteRule ^/smart-redir-limited/(.*)/info/refs$ /smart/$1/info/refs [R=301] <IfDefine SSL> LoadModule ssl_module modules/mod_ssl.so diff --git a/t/lib-httpd/passwd b/t/lib-httpd/passwd index f2fbcad33e..99a34d6487 100644 --- a/t/lib-httpd/passwd +++ b/t/lib-httpd/passwd @@ -1 +1 @@ -user@host:nKpa8pZUHx/ic +user@host:xb4E8pqD81KQs diff --git a/t/lib-pack.sh b/t/lib-pack.sh new file mode 100644 index 0000000000..7509846571 --- /dev/null +++ b/t/lib-pack.sh @@ -0,0 +1,98 @@ +# Support routines for hand-crafting weird or malicious packs. +# +# You can make a complete pack like: +# +# pack_header 2 >foo.pack && +# pack_obj e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 >>foo.pack && +# pack_obj e68fe8129b546b101aee9510c5328e7f21ca1d18 >>foo.pack && +# pack_trailer foo.pack + +# Print the big-endian 4-byte octal representation of $1 +uint32_octal () { + n=$1 + printf '\\%o' $(($n / 16777216)); n=$((n % 16777216)) + printf '\\%o' $(($n / 65536)); n=$((n % 65536)) + printf '\\%o' $(($n / 256)); n=$((n % 256)) + printf '\\%o' $(($n )); +} + +# Print the big-endian 4-byte binary representation of $1 +uint32_binary () { + printf "$(uint32_octal "$1")" +} + +# Print a pack header, version 2, for a pack with $1 objects +pack_header () { + printf 'PACK' && + printf '\0\0\0\2' && + uint32_binary "$1" +} + +# Print the pack data for object $1, as a delta against object $2 (or as a full +# object if $2 is missing or empty). The output is suitable for including +# directly in the packfile, and represents the entirety of the object entry. +# Doing this on the fly (especially picking your deltas) is quite tricky, so we +# have hardcoded some well-known objects. See the case statements below for the +# complete list. +pack_obj () { + case "$1" in + # empty blob + e69de29bb2d1d6434b8b29ae775ad8c2e48c5391) + case "$2" in + '') + printf '\060\170\234\003\0\0\0\0\1' + return + ;; + esac + ;; + + # blob containing "\7\76" + e68fe8129b546b101aee9510c5328e7f21ca1d18) + case "$2" in + '') + printf '\062\170\234\143\267\3\0\0\116\0\106' + return + ;; + 01d7713666f4de822776c7622c10f1b07de280dc) + printf '\165\1\327\161\66\146\364\336\202\47\166' && + printf '\307\142\54\20\361\260\175\342\200\334\170' && + printf '\234\143\142\142\142\267\003\0\0\151\0\114' + return + ;; + esac + ;; + + # blob containing "\7\0" + 01d7713666f4de822776c7622c10f1b07de280dc) + case "$2" in + '') + printf '\062\170\234\143\147\0\0\0\20\0\10' + return + ;; + e68fe8129b546b101aee9510c5328e7f21ca1d18) + printf '\165\346\217\350\22\233\124\153\20\32\356' && + printf '\225\20\305\62\216\177\41\312\35\30\170\234' && + printf '\143\142\142\142\147\0\0\0\53\0\16' + return + ;; + esac + ;; + esac + + echo >&2 "BUG: don't know how to print $1${2:+ (from $2)}" + return 1 +} + +# Compute and append pack trailer to "$1" +pack_trailer () { + test-sha1 -b <"$1" >trailer.tmp && + cat trailer.tmp >>"$1" && + rm -f trailer.tmp +} + +# Remove any existing packs to make sure that +# whatever we index next will be the pack that we +# actually use. +clear_packs () { + rm -f .git/objects/pack/* +} diff --git a/t/lib-pager.sh b/t/lib-pager.sh index ba03eab14f..3aa7a3ffd8 100644 --- a/t/lib-pager.sh +++ b/t/lib-pager.sh @@ -1,4 +1,4 @@ -#!/bin/sh +# Helpers for tests of git's choice of pager. test_expect_success 'determine default pager' ' test_might_fail git config --unset core.pager && diff --git a/t/lib-prereq-FILEMODE.sh b/t/lib-prereq-FILEMODE.sh deleted file mode 100644 index bce5a4c8bd..0000000000 --- a/t/lib-prereq-FILEMODE.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh -# -# Copyright (c) 2010 Ævar Arnfjörð Bjarmason -# - -if test "$(git config --bool core.filemode)" = false -then - say 'filemode disabled on the filesystem' -else - test_set_prereq FILEMODE -fi diff --git a/t/lib-read-tree.sh b/t/lib-read-tree.sh index abc2c6f57f..b95f485606 100644 --- a/t/lib-read-tree.sh +++ b/t/lib-read-tree.sh @@ -1,43 +1,41 @@ -#!/bin/sh -# # Helper functions to check if read-tree would succeed/fail as expected with # and without the dry-run option. They also test that the dry-run does not # write the index and that together with -u it doesn't touch the work tree. # read_tree_must_succeed () { - git ls-files -s >pre-dry-run && - git read-tree -n "$@" && - git ls-files -s >post-dry-run && - test_cmp pre-dry-run post-dry-run && - git read-tree "$@" + git ls-files -s >pre-dry-run && + git read-tree -n "$@" && + git ls-files -s >post-dry-run && + test_cmp pre-dry-run post-dry-run && + git read-tree "$@" } read_tree_must_fail () { - git ls-files -s >pre-dry-run && - test_must_fail git read-tree -n "$@" && - git ls-files -s >post-dry-run && - test_cmp pre-dry-run post-dry-run && - test_must_fail git read-tree "$@" + git ls-files -s >pre-dry-run && + test_must_fail git read-tree -n "$@" && + git ls-files -s >post-dry-run && + test_cmp pre-dry-run post-dry-run && + test_must_fail git read-tree "$@" } read_tree_u_must_succeed () { - git ls-files -s >pre-dry-run && - git diff-files -p >pre-dry-run-wt && - git read-tree -n "$@" && - git ls-files -s >post-dry-run && - git diff-files -p >post-dry-run-wt && - test_cmp pre-dry-run post-dry-run && - test_cmp pre-dry-run-wt post-dry-run-wt && - git read-tree "$@" + git ls-files -s >pre-dry-run && + git diff-files -p >pre-dry-run-wt && + git read-tree -n "$@" && + git ls-files -s >post-dry-run && + git diff-files -p >post-dry-run-wt && + test_cmp pre-dry-run post-dry-run && + test_cmp pre-dry-run-wt post-dry-run-wt && + git read-tree "$@" } read_tree_u_must_fail () { - git ls-files -s >pre-dry-run && - git diff-files -p >pre-dry-run-wt && - test_must_fail git read-tree -n "$@" && - git ls-files -s >post-dry-run && - git diff-files -p >post-dry-run-wt && - test_cmp pre-dry-run post-dry-run && - test_cmp pre-dry-run-wt post-dry-run-wt && - test_must_fail git read-tree "$@" + git ls-files -s >pre-dry-run && + git diff-files -p >pre-dry-run-wt && + test_must_fail git read-tree -n "$@" && + git ls-files -s >post-dry-run && + git diff-files -p >post-dry-run-wt && + test_cmp pre-dry-run post-dry-run && + test_cmp pre-dry-run-wt post-dry-run-wt && + test_must_fail git read-tree "$@" } diff --git a/t/lib-rebase.sh b/t/lib-rebase.sh index 8ff87fb3f9..6bd252212a 100644 --- a/t/lib-rebase.sh +++ b/t/lib-rebase.sh @@ -1,4 +1,4 @@ -#!/bin/sh +# Helper functions used by interactive rebase tests. # After setting the fake editor with this function, you can # diff --git a/t/lib-terminal.sh b/t/lib-terminal.sh index 58d911d21b..51845491bb 100644 --- a/t/lib-terminal.sh +++ b/t/lib-terminal.sh @@ -1,6 +1,20 @@ -#!/bin/sh +# Helpers for terminal output tests. + +# Catch tests which should depend on TTY but forgot to. There's no need +# to aditionally check that the TTY prereq is set here. If the test declared +# it and we are running the test, then it must have been set. +test_terminal () { + if ! test_declared_prereq TTY + then + echo >&4 "test_terminal: need to declare TTY prerequisite" + return 127 + fi + perl "$TEST_DIRECTORY"/test-terminal.perl "$@" +} + +test_lazy_prereq TTY ' + test_have_prereq PERL && -test_expect_success PERL 'set up terminal for tests' ' # Reading from the pty master seems to get stuck _sometimes_ # on Mac OS X 10.5.0, using Perl 5.10.0 or 5.8.9. # @@ -15,21 +29,8 @@ test_expect_success PERL 'set up terminal for tests' ' # After 2000 iterations or so it hangs. # https://rt.cpan.org/Ticket/Display.html?id=65692 # - if test "$(uname -s)" = Darwin - then - : - elif - "$PERL_PATH" "$TEST_DIRECTORY"/test-terminal.perl \ - sh -c "test -t 1 && test -t 2" - then - test_set_prereq TTY && - test_terminal () { - if ! test_declared_prereq TTY - then - echo >&4 "test_terminal: need to declare TTY prerequisite" - return 127 - fi - "$PERL_PATH" "$TEST_DIRECTORY"/test-terminal.perl "$@" - } - fi + test "$(uname -s)" != Darwin && + + perl "$TEST_DIRECTORY"/test-terminal.perl \ + sh -c "test -t 1 && test -t 2" ' diff --git a/t/perf/p0001-rev-list.sh b/t/perf/p0001-rev-list.sh index 4f71a63b0a..16359d51ae 100755 --- a/t/perf/p0001-rev-list.sh +++ b/t/perf/p0001-rev-list.sh @@ -14,4 +14,16 @@ test_perf 'rev-list --all --objects' ' git rev-list --all --objects >/dev/null ' +test_expect_success 'create new unreferenced commit' ' + commit=$(git commit-tree HEAD^{tree} -p HEAD) +' + +test_perf 'rev-list $commit --not --all' ' + git rev-list $commit --not --all >/dev/null +' + +test_perf 'rev-list --objects $commit --not --all' ' + git rev-list --objects $commit --not --all >/dev/null +' + test_done diff --git a/t/perf/p4001-diff-no-index.sh b/t/perf/p4001-diff-no-index.sh new file mode 100755 index 0000000000..683be6984f --- /dev/null +++ b/t/perf/p4001-diff-no-index.sh @@ -0,0 +1,22 @@ +#!/bin/sh + +test_description="Test diff --no-index performance" + +. ./perf-lib.sh + +test_perf_large_repo +test_checkout_worktree + +file1=$(git ls-files | tail -n 2 | head -1) +file2=$(git ls-files | tail -n 1 | head -1) + +test_expect_success "empty files, so they take no time to diff" " + echo >$file1 && + echo >$file2 +" + +test_perf "diff --no-index" " + git diff --no-index $file1 $file2 >/dev/null +" + +test_done diff --git a/t/perf/p5310-pack-bitmaps.sh b/t/perf/p5310-pack-bitmaps.sh new file mode 100755 index 0000000000..685d46f8b7 --- /dev/null +++ b/t/perf/p5310-pack-bitmaps.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +test_description='Tests pack performance using bitmaps' +. ./perf-lib.sh + +test_perf_large_repo + +# note that we do everything through config, +# since we want to be able to compare bitmap-aware +# git versus non-bitmap git +test_expect_success 'setup bitmap config' ' + git config pack.writebitmaps true && + git config pack.writebitmaphashcache true +' + +test_perf 'repack to disk' ' + git repack -ad +' + +test_perf 'simulated clone' ' + git pack-objects --stdout --all </dev/null >/dev/null +' + +test_perf 'simulated fetch' ' + have=$(git rev-list HEAD~100 -1) && + { + echo HEAD && + echo ^$have + } | git pack-objects --revs --stdout >/dev/null +' + +test_expect_success 'create partial bitmap state' ' + # pick a commit to represent the repo tip in the past + cutoff=$(git rev-list HEAD~100 -1) && + orig_tip=$(git rev-parse HEAD) && + + # now kill off all of the refs and pretend we had + # just the one tip + rm -rf .git/logs .git/refs/* .git/packed-refs + git update-ref HEAD $cutoff + + # and then repack, which will leave us with a nice + # big bitmap pack of the "old" history, and all of + # the new history will be loose, as if it had been pushed + # up incrementally and exploded via unpack-objects + git repack -Ad + + # and now restore our original tip, as if the pushes + # had happened + git update-ref HEAD $orig_tip +' + +test_perf 'partial bitmap' ' + git pack-objects --stdout --all </dev/null >/dev/null +' + +test_done diff --git a/t/perf/perf-lib.sh b/t/perf/perf-lib.sh index f4eecaa171..a8c9574291 100644 --- a/t/perf/perf-lib.sh +++ b/t/perf/perf-lib.sh @@ -1,4 +1,6 @@ -#!/bin/sh +# Performance testing framework. Each perf script starts much like +# a normal test script, except it sources this library instead of +# test-lib.sh. See t/perf/README for documentation. # # Copyright (c) 2011 Thomas Rast # diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index 10be52beed..a2bb63ce8e 100755 --- a/t/t0000-basic.sh +++ b/t/t0000-basic.sh @@ -41,20 +41,17 @@ test_expect_success '.git/objects should have 3 subdirectories' ' test_expect_success 'success is reported like this' ' : ' -test_expect_failure 'pretend we have a known breakage' ' - false -' run_sub_test_lib_test () { name="$1" descr="$2" # stdin is the body of the test code shift 2 mkdir "$name" && ( - # Pretend we're a test harness. This prevents - # test-lib from writing the counts to a file that will - # later be summarized, showing spurious "failed" tests - HARNESS_ACTIVE=t && - export HARNESS_ACTIVE && + # Pretend we're not running under a test harness, whether we + # are or not. The test-lib output depends on the setting of + # this variable, so we need a stable setting under which to run + # the sub-test. + sane_unset HARNESS_ACTIVE && cd "$name" && cat >"$name.sh" <<-EOF && #!$SHELL_PATH @@ -71,6 +68,8 @@ run_sub_test_lib_test () { cat >>"$name.sh" && chmod +x "$name.sh" && export TEST_DIRECTORY && + TEST_OUTPUT_DIRECTORY=$(pwd) && + export TEST_OUTPUT_DIRECTORY && ./"$name.sh" "$@" >out 2>err ) } @@ -233,16 +232,13 @@ test_expect_success 'test --verbose' ' grep -v "^Initialized empty" test-verbose/out+ >test-verbose/out && check_sub_test_lib_test test-verbose <<-\EOF > expecting success: true - > Z > ok 1 - passing test > Z > expecting success: echo foo > foo - > Z > ok 2 - test with output > Z > expecting success: false - > Z > not ok 3 - failing test > # false > Z @@ -265,7 +261,6 @@ test_expect_success 'test --verbose-only' ' > Z > expecting success: echo foo > foo - > Z > ok 2 - test with output > Z > not ok 3 - failing test diff --git a/t/t0001-init.sh b/t/t0001-init.sh index ad66410564..9fb582b192 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -379,6 +379,10 @@ test_expect_success 'init with separate gitdir' ' test -d realgitdir/refs ' +test_expect_success 're-init on .git file' ' + ( cd newdir && git init ) +' + test_expect_success 're-init to update git link' ' ( cd newdir && diff --git a/t/t0002-gitfile.sh b/t/t0002-gitfile.sh index cb144258cc..37e9396e5d 100755 --- a/t/t0002-gitfile.sh +++ b/t/t0002-gitfile.sh @@ -7,7 +7,7 @@ Verify that plumbing commands work when .git is a file . ./test-lib.sh objpath() { - echo "$1" | sed -e 's|\(..\)|\1/|' + echo "$1" | sed -e 's|\(..\)|\1/|' } objck() { @@ -19,7 +19,6 @@ objck() { fi } - test_expect_success 'initial setup' ' REAL="$(pwd)/.real" && mv .git "$REAL" diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh index 0b98b6f8d0..f0fbb42554 100755 --- a/t/t0003-attributes.sh +++ b/t/t0003-attributes.sh @@ -13,7 +13,6 @@ attr_check () { test_line_count = 0 err } - test_expect_success 'setup' ' mkdir -p a/b/d a/c b && ( @@ -244,40 +243,58 @@ EOF test_line_count = 0 err ' +test_expect_success 'using --git-dir and --work-tree' ' + mkdir unreal real && + git init real && + echo "file test=in-real" >real/.gitattributes && + ( + cd unreal && + attr_check file in-real "--git-dir ../real/.git --work-tree ../real" + ) +' + test_expect_success 'setup bare' ' - git clone --bare . bare.git && - cd bare.git + git clone --bare . bare.git ' test_expect_success 'bare repository: check that .gitattribute is ignored' ' ( - echo "f test=f" - echo "a/i test=a/i" - ) >.gitattributes && - attr_check f unspecified && - attr_check a/f unspecified && - attr_check a/c/f unspecified && - attr_check a/i unspecified && - attr_check subdir/a/i unspecified + cd bare.git && + ( + echo "f test=f" + echo "a/i test=a/i" + ) >.gitattributes && + attr_check f unspecified && + attr_check a/f unspecified && + attr_check a/c/f unspecified && + attr_check a/i unspecified && + attr_check subdir/a/i unspecified + ) ' test_expect_success 'bare repository: check that --cached honors index' ' - GIT_INDEX_FILE=../.git/index \ - git check-attr --cached --stdin --all <../stdin-all | - sort >actual && - test_cmp ../specified-all actual + ( + cd bare.git && + GIT_INDEX_FILE=../.git/index \ + git check-attr --cached --stdin --all <../stdin-all | + sort >actual && + test_cmp ../specified-all actual + ) ' test_expect_success 'bare repository: test info/attributes' ' ( - echo "f test=f" - echo "a/i test=a/i" - ) >info/attributes && - attr_check f f && - attr_check a/f f && - attr_check a/c/f f && - attr_check a/i a/i && - attr_check subdir/a/i unspecified + cd bare.git && + ( + echo "f test=f" + echo "a/i test=a/i" + ) >info/attributes && + attr_check f f && + attr_check a/f f && + attr_check a/c/f f && + attr_check a/i a/i && + attr_check subdir/a/i unspecified + ) ' test_done diff --git a/t/t0008-ignores.sh b/t/t0008-ignores.sh index c29342d6bc..63beb99828 100755 --- a/t/t0008-ignores.sh +++ b/t/t0008-ignores.sh @@ -37,6 +37,14 @@ test_stderr () { test_cmp "$HOME/expected-stderr" "$HOME/stderr" } +broken_c_unquote () { + "$PERL_PATH" -pe 's/^"//; s/\\//; s/"$//; tr/\n/\0/' "$@" +} + +broken_c_unquote_verbose () { + "$PERL_PATH" -pe 's/ "/ /; s/\\//; s/"$//; tr/:\t\n/\0/' "$@" +} + stderr_contains () { regexp="$1" if grep "$regexp" "$HOME/stderr" @@ -66,11 +74,11 @@ test_check_ignore () { init_vars && rm -f "$HOME/stdout" "$HOME/stderr" "$HOME/cmd" && - echo git $global_args check-ignore $quiet_opt $verbose_opt $non_matching_opt $args \ + echo git $global_args check-ignore $quiet_opt $verbose_opt $non_matching_opt $no_index_opt $args \ >"$HOME/cmd" && echo "$expect_code" >"$HOME/expected-exit-code" && test_expect_code "$expect_code" \ - git $global_args check-ignore $quiet_opt $verbose_opt $non_matching_opt $args \ + git $global_args check-ignore $quiet_opt $verbose_opt $non_matching_opt $no_index_opt $args \ >"$HOME/stdout" 2>"$HOME/stderr" && test_cmp "$HOME/expected-stdout" "$HOME/stdout" && stderr_empty_on_success "$expect_code" @@ -87,6 +95,9 @@ test_check_ignore () { # check-ignore --verbose output is the same as normal output except # for the extra first column. # +# A parameter is used to determine if the tests are run with the +# normal case (using the index), or with the --no-index option. +# # Arguments: # - (optional) prereqs for this test, e.g. 'SYMLINKS' # - test name @@ -94,19 +105,26 @@ test_check_ignore () { # from the other verbosity modes is automatically inferred # from this value) # - code to run (should invoke test_check_ignore) -test_expect_success_multi () { +# - index option: --index or --no-index +test_expect_success_multiple () { prereq= - if test $# -eq 4 + if test $# -eq 5 then prereq=$1 shift fi + if test "$4" = "--index" + then + no_index_opt= + else + no_index_opt=$4 + fi testname="$1" expect_all="$2" code="$3" expect_verbose=$( echo "$expect_all" | grep -v '^:: ' ) expect=$( echo "$expect_verbose" | sed -e 's/.* //' ) - test_expect_success $prereq "$testname" ' + test_expect_success $prereq "$testname${no_index_opt:+ with $no_index_opt}" ' expect "$expect" && eval "$code" ' @@ -116,7 +134,8 @@ test_expect_success_multi () { then for quiet_opt in '-q' '--quiet' do - test_expect_success $prereq "$testname${quiet_opt:+ with $quiet_opt}" " + opts="${no_index_opt:+$no_index_opt }$quiet_opt" + test_expect_success $prereq "$testname${opts:+ with $opts}" " expect '' && $code " @@ -126,7 +145,7 @@ test_expect_success_multi () { for verbose_opt in '-v' '--verbose' do - for non_matching_opt in '' ' -n' ' --non-matching' + for non_matching_opt in '' '-n' '--non-matching' do if test -n "$non_matching_opt" then @@ -139,12 +158,21 @@ test_expect_success_multi () { expect '$my_expect' && $code " - opts="$verbose_opt$non_matching_opt" + opts="${no_index_opt:+$no_index_opt }$verbose_opt${non_matching_opt:+ $non_matching_opt}" test_expect_success $prereq "$testname${opts:+ with $opts}" "$test_code" done done verbose_opt= non_matching_opt= + no_index_opt= +} + +test_expect_success_multi () { + test_expect_success_multiple "$@" "--index" +} + +test_expect_success_no_index_multi () { + test_expect_success_multiple "$@" "--no-index" } test_expect_success 'setup' ' @@ -288,7 +316,7 @@ test_expect_success_multi 'needs work tree' '' ' # First make sure that the presence of a file in the working tree # does not impact results, but that the presence of a file in the -# index does. +# index does unless the --no-index option is used. for subdir in '' 'a/' do @@ -303,22 +331,42 @@ do ":: ${subdir}non-existent" \ "test_check_ignore '${subdir}non-existent' 1" + test_expect_success_no_index_multi "non-existent file $where not ignored" \ + ":: ${subdir}non-existent" \ + "test_check_ignore '${subdir}non-existent' 1" + test_expect_success_multi "non-existent file $where ignored" \ ".gitignore:1:one ${subdir}one" \ "test_check_ignore '${subdir}one'" + test_expect_success_no_index_multi "non-existent file $where ignored" \ + ".gitignore:1:one ${subdir}one" \ + "test_check_ignore '${subdir}one'" + test_expect_success_multi "existing untracked file $where not ignored" \ ":: ${subdir}not-ignored" \ "test_check_ignore '${subdir}not-ignored' 1" + test_expect_success_no_index_multi "existing untracked file $where not ignored" \ + ":: ${subdir}not-ignored" \ + "test_check_ignore '${subdir}not-ignored' 1" + test_expect_success_multi "existing tracked file $where not ignored" \ ":: ${subdir}ignored-but-in-index" \ "test_check_ignore '${subdir}ignored-but-in-index' 1" + test_expect_success_no_index_multi "existing tracked file $where shown as ignored" \ + ".gitignore:2:ignored-* ${subdir}ignored-but-in-index" \ + "test_check_ignore '${subdir}ignored-but-in-index'" + test_expect_success_multi "existing untracked file $where ignored" \ ".gitignore:2:ignored-* ${subdir}ignored-and-untracked" \ "test_check_ignore '${subdir}ignored-and-untracked'" + test_expect_success_no_index_multi "existing untracked file $where ignored" \ + ".gitignore:2:ignored-* ${subdir}ignored-and-untracked" \ + "test_check_ignore '${subdir}ignored-and-untracked'" + test_expect_success_multi "mix of file types $where" \ ":: ${subdir}non-existent .gitignore:1:one ${subdir}one @@ -332,6 +380,20 @@ do ${subdir}ignored-but-in-index ${subdir}ignored-and-untracked' " + + test_expect_success_no_index_multi "mix of file types $where" \ +":: ${subdir}non-existent +.gitignore:1:one ${subdir}one +:: ${subdir}not-ignored +.gitignore:2:ignored-* ${subdir}ignored-but-in-index +.gitignore:2:ignored-* ${subdir}ignored-and-untracked" \ + "test_check_ignore ' + ${subdir}non-existent + ${subdir}one + ${subdir}not-ignored + ${subdir}ignored-but-in-index + ${subdir}ignored-and-untracked' + " done # Having established the above, from now on we mostly test against @@ -432,7 +494,7 @@ test_expect_success_multi SYMLINKS 'symlink' ':: a/symlink' ' test_expect_success_multi SYMLINKS 'beyond a symlink' '' ' test_check_ignore "a/symlink/foo" 128 && - test_stderr "fatal: '\''a/symlink/foo'\'' is beyond a symbolic link" + test_stderr "fatal: pathspec '\''a/symlink/foo'\'' is beyond a symbolic link" ' test_expect_success_multi SYMLINKS 'beyond a symlink from subdirectory' '' ' @@ -440,7 +502,7 @@ test_expect_success_multi SYMLINKS 'beyond a symlink from subdirectory' '' ' cd a && test_check_ignore "symlink/foo" 128 ) && - test_stderr "fatal: '\''symlink/foo'\'' is beyond a symbolic link" + test_stderr "fatal: pathspec '\''symlink/foo'\'' is beyond a symbolic link" ' ############################################################################ @@ -449,7 +511,7 @@ test_expect_success_multi SYMLINKS 'beyond a symlink from subdirectory' '' ' test_expect_success_multi 'submodule' '' ' test_check_ignore "a/submodule/one" 128 && - test_stderr "fatal: Path '\''a/submodule/one'\'' is in submodule '\''a/submodule'\''" + test_stderr "fatal: Pathspec '\''a/submodule/one'\'' is in submodule '\''a/submodule'\''" ' test_expect_success_multi 'submodule from subdirectory' '' ' @@ -457,7 +519,7 @@ test_expect_success_multi 'submodule from subdirectory' '' ' cd a && test_check_ignore "submodule/one" 128 ) && - test_stderr "fatal: Path '\''a/submodule/one'\'' is in submodule '\''a/submodule'\''" + test_stderr "fatal: Pathspec '\''submodule/one'\'' is in submodule '\''a/submodule'\''" ' ############################################################################ @@ -552,12 +614,11 @@ cat <<-EOF >expected-verbose $global_excludes:2:!globaltwo b/globaltwo EOF -sed -e 's/^"//' -e 's/\\//' -e 's/"$//' stdin | \ - tr "\n" "\0" >stdin0 -sed -e 's/^"//' -e 's/\\//' -e 's/"$//' expected-default | \ - tr "\n" "\0" >expected-default0 -sed -e 's/ "/ /' -e 's/\\//' -e 's/"$//' expected-verbose | \ - tr ":\t\n" "\0" >expected-verbose0 +broken_c_unquote stdin >stdin0 + +broken_c_unquote expected-default >expected-default0 + +broken_c_unquote_verbose expected-verbose >expected-verbose0 test_expect_success '--stdin' ' expect_from_stdin <expected-default && @@ -638,12 +699,11 @@ EOF grep -v '^:: ' expected-all >expected-verbose sed -e 's/.* //' expected-verbose >expected-default -sed -e 's/^"//' -e 's/\\//' -e 's/"$//' stdin | \ - tr "\n" "\0" >stdin0 -sed -e 's/^"//' -e 's/\\//' -e 's/"$//' expected-default | \ - tr "\n" "\0" >expected-default0 -sed -e 's/ "/ /' -e 's/\\//' -e 's/"$//' expected-verbose | \ - tr ":\t\n" "\0" >expected-verbose0 +broken_c_unquote stdin >stdin0 + +broken_c_unquote expected-default >expected-default0 + +broken_c_unquote_verbose expected-verbose >expected-verbose0 test_expect_success '--stdin from subdirectory' ' expect_from_stdin <expected-default && @@ -715,4 +775,35 @@ test_expect_success PIPE 'streaming support for --stdin' ' echo "$response" | grep "^:: two" ' +############################################################################ +# +# test whitespace handling + +test_expect_success 'trailing whitespace is ignored' ' + mkdir whitespace && + >whitespace/trailing && + >whitespace/untracked && + echo "whitespace/trailing " >ignore && + cat >expect <<EOF && +whitespace/untracked +EOF + : >err.expect && + git ls-files -o -X ignore whitespace >actual 2>err && + test_cmp expect actual && + test_cmp err.expect err +' + +test_expect_success !MINGW 'quoting allows trailing whitespace' ' + rm -rf whitespace && + mkdir whitespace && + >"whitespace/trailing " && + >whitespace/untracked && + echo "whitespace/trailing\\ \\ " >ignore && + echo whitespace/untracked >expect && + : >err.expect && + git ls-files -o -X ignore whitespace >actual 2>err && + test_cmp expect actual && + test_cmp err.expect err +' + test_done diff --git a/t/t0011-hashmap.sh b/t/t0011-hashmap.sh new file mode 100755 index 0000000000..391e2b6492 --- /dev/null +++ b/t/t0011-hashmap.sh @@ -0,0 +1,240 @@ +#!/bin/sh + +test_description='test hashmap and string hash functions' +. ./test-lib.sh + +test_hashmap() { + echo "$1" | test-hashmap $3 > actual && + echo "$2" > expect && + test_cmp expect actual +} + +test_expect_success 'hash functions' ' + +test_hashmap "hash key1" "2215982743 2215982743 116372151 116372151" && +test_hashmap "hash key2" "2215982740 2215982740 116372148 116372148" && +test_hashmap "hash fooBarFrotz" "1383912807 1383912807 3189766727 3189766727" && +test_hashmap "hash foobarfrotz" "2862305959 2862305959 3189766727 3189766727" + +' + +test_expect_success 'put' ' + +test_hashmap "put key1 value1 +put key2 value2 +put fooBarFrotz value3 +put foobarfrotz value4 +size" "NULL +NULL +NULL +NULL +64 4" + +' + +test_expect_success 'put (case insensitive)' ' + +test_hashmap "put key1 value1 +put key2 value2 +put fooBarFrotz value3 +size" "NULL +NULL +NULL +64 3" ignorecase + +' + +test_expect_success 'replace' ' + +test_hashmap "put key1 value1 +put key1 value2 +put fooBarFrotz value3 +put fooBarFrotz value4 +size" "NULL +value1 +NULL +value3 +64 2" + +' + +test_expect_success 'replace (case insensitive)' ' + +test_hashmap "put key1 value1 +put Key1 value2 +put fooBarFrotz value3 +put foobarfrotz value4 +size" "NULL +value1 +NULL +value3 +64 2" ignorecase + +' + +test_expect_success 'get' ' + +test_hashmap "put key1 value1 +put key2 value2 +put fooBarFrotz value3 +put foobarfrotz value4 +get key1 +get key2 +get fooBarFrotz +get notInMap" "NULL +NULL +NULL +NULL +value1 +value2 +value3 +NULL" + +' + +test_expect_success 'get (case insensitive)' ' + +test_hashmap "put key1 value1 +put key2 value2 +put fooBarFrotz value3 +get Key1 +get keY2 +get foobarfrotz +get notInMap" "NULL +NULL +NULL +value1 +value2 +value3 +NULL" ignorecase + +' + +test_expect_success 'add' ' + +test_hashmap "add key1 value1 +add key1 value2 +add fooBarFrotz value3 +add fooBarFrotz value4 +get key1 +get fooBarFrotz +get notInMap" "value2 +value1 +value4 +value3 +NULL" + +' + +test_expect_success 'add (case insensitive)' ' + +test_hashmap "add key1 value1 +add Key1 value2 +add fooBarFrotz value3 +add foobarfrotz value4 +get key1 +get Foobarfrotz +get notInMap" "value2 +value1 +value4 +value3 +NULL" ignorecase + +' + +test_expect_success 'remove' ' + +test_hashmap "put key1 value1 +put key2 value2 +put fooBarFrotz value3 +remove key1 +remove key2 +remove notInMap +size" "NULL +NULL +NULL +value1 +value2 +NULL +64 1" + +' + +test_expect_success 'remove (case insensitive)' ' + +test_hashmap "put key1 value1 +put key2 value2 +put fooBarFrotz value3 +remove Key1 +remove keY2 +remove notInMap +size" "NULL +NULL +NULL +value1 +value2 +NULL +64 1" ignorecase + +' + +test_expect_success 'iterate' ' + +test_hashmap "put key1 value1 +put key2 value2 +put fooBarFrotz value3 +iterate" "NULL +NULL +NULL +key2 value2 +key1 value1 +fooBarFrotz value3" + +' + +test_expect_success 'iterate (case insensitive)' ' + +test_hashmap "put key1 value1 +put key2 value2 +put fooBarFrotz value3 +iterate" "NULL +NULL +NULL +fooBarFrotz value3 +key2 value2 +key1 value1" ignorecase + +' + +test_expect_success 'grow / shrink' ' + + rm -f in && + rm -f expect && + for n in $(test_seq 51) + do + echo put key$n value$n >> in && + echo NULL >> expect + done && + echo size >> in && + echo 64 51 >> expect && + echo put key52 value52 >> in && + echo NULL >> expect + echo size >> in && + echo 256 52 >> expect && + for n in $(test_seq 12) + do + echo remove key$n >> in && + echo value$n >> expect + done && + echo size >> in && + echo 256 40 >> expect && + echo remove key40 >> in && + echo value40 >> expect && + echo size >> in && + echo 64 39 >> expect && + cat in | test-hashmap > out && + test_cmp expect out + +' + +test_done diff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh index e50f0f742f..b92e6cb046 100755 --- a/t/t0021-conversion.sh +++ b/t/t0021-conversion.sh @@ -190,4 +190,18 @@ test_expect_success 'required filter clean failure' ' test_must_fail git add test.fc ' +test -n "$GIT_TEST_LONG" && test_set_prereq EXPENSIVE + +test_expect_success EXPENSIVE 'filter large file' ' + git config filter.largefile.smudge cat && + git config filter.largefile.clean cat && + for i in $(test_seq 1 2048); do printf "%1048576d" 1; done >2GB && + echo "2GB filter=largefile" >.gitattributes && + git add 2GB 2>err && + ! test -s err && + rm -f 2GB && + git checkout -- 2GB 2>err && + ! test -s err +' + test_done diff --git a/t/t0050-filesystem.sh b/t/t0050-filesystem.sh index 05d78d22a6..6b3cedcf24 100755 --- a/t/t0050-filesystem.sh +++ b/t/t0050-filesystem.sh @@ -91,6 +91,7 @@ test_expect_failure CASE_INSENSITIVE_FS 'add (with different case)' ' test_expect_success "setup unicode normalization tests" ' test_create_repo unicode && cd unicode && + git config core.precomposeunicode false && touch "$aumlcdiar" && git add "$aumlcdiar" && git commit -m initial && diff --git a/t/t0056-git-C.sh b/t/t0056-git-C.sh new file mode 100755 index 0000000000..99c037703a --- /dev/null +++ b/t/t0056-git-C.sh @@ -0,0 +1,84 @@ +#!/bin/sh + +test_description='"-C <path>" option and its effects on other path-related options' + +. ./test-lib.sh + +test_expect_success '"git -C <path>" runs git from the directory <path>' ' + test_create_repo dir1 && + echo 1 >dir1/a.txt && + msg="initial in dir1" && + (cd dir1 && git add a.txt && git commit -m "$msg") && + echo "$msg" >expected && + git -C dir1 log --format=%s >actual && + test_cmp expected actual +' + +test_expect_success 'Multiple -C options: "-C dir1 -C dir2" is equivalent to "-C dir1/dir2"' ' + test_create_repo dir1/dir2 && + echo 1 >dir1/dir2/b.txt && + git -C dir1/dir2 add b.txt && + msg="initial in dir1/dir2" && + echo "$msg" >expected && + git -C dir1/dir2 commit -m "$msg" && + git -C dir1 -C dir2 log --format=%s >actual && + test_cmp expected actual +' + +test_expect_success 'Effect on --git-dir option: "-C c --git-dir=a.git" is equivalent to "--git-dir c/a.git"' ' + mkdir c && + mkdir c/a && + mkdir c/a.git && + (cd c/a.git && git init --bare) && + echo 1 >c/a/a.txt && + git --git-dir c/a.git --work-tree=c/a add a.txt && + git --git-dir c/a.git --work-tree=c/a commit -m "initial" && + git --git-dir=c/a.git log -1 --format=%s >expected && + git -C c --git-dir=a.git log -1 --format=%s >actual && + test_cmp expected actual +' + +test_expect_success 'Order should not matter: "--git-dir=a.git -C c" is equivalent to "-C c --git-dir=a.git"' ' + git -C c --git-dir=a.git log -1 --format=%s >expected && + git --git-dir=a.git -C c log -1 --format=%s >actual && + test_cmp expected actual +' + +test_expect_success 'Effect on --work-tree option: "-C c/a.git --work-tree=../a" is equivalent to "--work-tree=c/a --git-dir=c/a.git"' ' + rm c/a/a.txt && + git --git-dir=c/a.git --work-tree=c/a status >expected && + git -C c/a.git --work-tree=../a status >actual && + test_cmp expected actual +' + +test_expect_success 'Order should not matter: "--work-tree=../a -C c/a.git" is equivalent to "-C c/a.git --work-tree=../a"' ' + git -C c/a.git --work-tree=../a status >expected && + git --work-tree=../a -C c/a.git status >actual && + test_cmp expected actual +' + +test_expect_success 'Effect on --git-dir and --work-tree options - "-C c --git-dir=a.git --work-tree=a" is equivalent to "--git-dir=c/a.git --work-tree=c/a"' ' + git --git-dir=c/a.git --work-tree=c/a status >expected && + git -C c --git-dir=a.git --work-tree=a status >actual && + test_cmp expected actual +' + +test_expect_success 'Order should not matter: "-C c --git-dir=a.git --work-tree=a" is equivalent to "--git-dir=a.git -C c --work-tree=a"' ' + git -C c --git-dir=a.git --work-tree=a status >expected && + git --git-dir=a.git -C c --work-tree=a status >actual && + test_cmp expected actual +' + +test_expect_success 'Order should not matter: "-C c --git-dir=a.git --work-tree=a" is equivalent to "--git-dir=a.git --work-tree=a -C c"' ' + git -C c --git-dir=a.git --work-tree=a status >expected && + git --git-dir=a.git --work-tree=a -C c status >actual && + test_cmp expected actual +' + +test_expect_success 'Relative followed by fullpath: "-C ./here -C /there" is equivalent to "-C /there"' ' + echo "initial in dir1/dir2" >expected && + git -C dir1 -C "$(pwd)/dir1/dir2" log --format=%s >actual && + test_cmp expected actual +' + +test_done diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh index 3a48de20d8..c0143a0a70 100755 --- a/t/t0060-path-utils.sh +++ b/t/t0060-path-utils.sh @@ -8,13 +8,13 @@ test_description='Test various path utilities' . ./test-lib.sh norm_path() { - expected=$(test-path-utils mingw_path "$2") + expected=$(test-path-utils print_path "$2") test_expect_success $3 "normalize path: $1 => $2" \ "test \"\$(test-path-utils normalize_path_copy '$1')\" = '$expected'" } relative_path() { - expected=$(test-path-utils mingw_path "$3") + expected=$(test-path-utils print_path "$3") test_expect_success $4 "relative path: $1 $2 => $3" \ "test \"\$(test-path-utils relative_path '$1' '$2')\" = '$expected'" } @@ -190,33 +190,58 @@ test_expect_success SYMLINKS 'real path works on symlinks' ' test "$sym" = "$(test-path-utils real_path "$dir2/syml")" ' -relative_path /a/b/c/ /a/b/ c/ -relative_path /a/b/c/ /a/b c/ -relative_path /a//b//c/ //a/b// c/ POSIX -relative_path /a/b /a/b ./ -relative_path /a/b/ /a/b ./ -relative_path /a /a/b ../ -relative_path / /a/b/ ../../ -relative_path /a/c /a/b/ ../c -relative_path /a/c /a/b ../c -relative_path /x/y /a/b/ ../../x/y -relative_path /a/b "<empty>" /a/b -relative_path /a/b "<null>" /a/b -relative_path a/b/c/ a/b/ c/ -relative_path a/b/c/ a/b c/ -relative_path a/b//c a//b c -relative_path a/b/ a/b/ ./ -relative_path a/b/ a/b ./ -relative_path a a/b ../ -relative_path x/y a/b ../../x/y -relative_path a/c a/b ../c -relative_path a/b "<empty>" a/b -relative_path a/b "<null>" a/b -relative_path "<empty>" /a/b ./ -relative_path "<empty>" "<empty>" ./ -relative_path "<empty>" "<null>" ./ -relative_path "<null>" "<empty>" ./ -relative_path "<null>" "<null>" ./ -relative_path "<null>" /a/b ./ +test_expect_success SYMLINKS 'prefix_path works with absolute paths to work tree symlinks' ' + ln -s target symlink && + test "$(test-path-utils prefix_path prefix "$(pwd)/symlink")" = "symlink" +' + +test_expect_success 'prefix_path works with only absolute path to work tree' ' + echo "" >expected && + test-path-utils prefix_path prefix "$(pwd)" >actual && + test_cmp expected actual +' + +test_expect_success 'prefix_path rejects absolute path to dir with same beginning as work tree' ' + test_must_fail test-path-utils prefix_path prefix "$(pwd)a" +' + +test_expect_success SYMLINKS 'prefix_path works with absolute path to a symlink to work tree having same beginning as work tree' ' + git init repo && + ln -s repo repolink && + test "a" = "$(cd repo && test-path-utils prefix_path prefix "$(pwd)/../repolink/a")" +' + +relative_path /foo/a/b/c/ /foo/a/b/ c/ +relative_path /foo/a/b/c/ /foo/a/b c/ +relative_path /foo/a//b//c/ ///foo/a/b// c/ POSIX +relative_path /foo/a/b /foo/a/b ./ +relative_path /foo/a/b/ /foo/a/b ./ +relative_path /foo/a /foo/a/b ../ +relative_path / /foo/a/b/ ../../../ +relative_path /foo/a/c /foo/a/b/ ../c +relative_path /foo/a/c /foo/a/b ../c +relative_path /foo/x/y /foo/a/b/ ../../x/y +relative_path /foo/a/b "<empty>" /foo/a/b +relative_path /foo/a/b "<null>" /foo/a/b +relative_path foo/a/b/c/ foo/a/b/ c/ +relative_path foo/a/b/c/ foo/a/b c/ +relative_path foo/a/b//c foo/a//b c +relative_path foo/a/b/ foo/a/b/ ./ +relative_path foo/a/b/ foo/a/b ./ +relative_path foo/a foo/a/b ../ +relative_path foo/x/y foo/a/b ../../x/y +relative_path foo/a/c foo/a/b ../c +relative_path foo/a/b /foo/x/y foo/a/b +relative_path /foo/a/b foo/x/y /foo/a/b +relative_path d:/a/b D:/a/c ../b MINGW +relative_path C:/a/b D:/a/c C:/a/b MINGW +relative_path foo/a/b "<empty>" foo/a/b +relative_path foo/a/b "<null>" foo/a/b +relative_path "<empty>" /foo/a/b ./ +relative_path "<empty>" "<empty>" ./ +relative_path "<empty>" "<null>" ./ +relative_path "<null>" "<empty>" ./ +relative_path "<null>" "<null>" ./ +relative_path "<null>" /foo/a/b ./ test_done diff --git a/t/t0070-fundamental.sh b/t/t0070-fundamental.sh index 986b2a8f26..5ed69a6f56 100755 --- a/t/t0070-fundamental.sh +++ b/t/t0070-fundamental.sh @@ -25,6 +25,10 @@ test_expect_success POSIXPERM,SANITY 'mktemp to unwritable directory prints file grep "cannotwrite/test" err ' +test_expect_success 'git_mkstemps_mode does not fail if fd 0 is not open' ' + git commit --allow-empty -m message <&- +' + test_expect_success 'check for a bug in the regex routines' ' # if this test fails, re-build git with NO_REGEX=1 test-regex diff --git a/t/t0110-urlmatch-normalization.sh b/t/t0110-urlmatch-normalization.sh new file mode 100755 index 0000000000..8d6096d4d1 --- /dev/null +++ b/t/t0110-urlmatch-normalization.sh @@ -0,0 +1,177 @@ +#!/bin/sh + +test_description='urlmatch URL normalization' +. ./test-lib.sh + +# The base name of the test url files +tu="$TEST_DIRECTORY/t0110/url" + +# Note that only file: URLs should be allowed without a host + +test_expect_success 'url scheme' ' + ! test-urlmatch-normalization "" && + ! test-urlmatch-normalization "_" && + ! test-urlmatch-normalization "scheme" && + ! test-urlmatch-normalization "scheme:" && + ! test-urlmatch-normalization "scheme:/" && + ! test-urlmatch-normalization "scheme://" && + ! test-urlmatch-normalization "file" && + ! test-urlmatch-normalization "file:" && + ! test-urlmatch-normalization "file:/" && + test-urlmatch-normalization "file://" && + ! test-urlmatch-normalization "://acme.co" && + ! test-urlmatch-normalization "x_test://acme.co" && + ! test-urlmatch-normalization "-test://acme.co" && + ! test-urlmatch-normalization "0test://acme.co" && + ! test-urlmatch-normalization "+test://acme.co" && + ! test-urlmatch-normalization ".test://acme.co" && + ! test-urlmatch-normalization "schem%6e://" && + test-urlmatch-normalization "x-Test+v1.0://acme.co" && + test "$(test-urlmatch-normalization -p "AbCdeF://x.Y")" = "abcdef://x.y/" +' + +test_expect_success 'url authority' ' + ! test-urlmatch-normalization "scheme://user:pass@" && + ! test-urlmatch-normalization "scheme://?" && + ! test-urlmatch-normalization "scheme://#" && + ! test-urlmatch-normalization "scheme:///" && + ! test-urlmatch-normalization "scheme://:" && + ! test-urlmatch-normalization "scheme://:555" && + test-urlmatch-normalization "file://user:pass@" && + test-urlmatch-normalization "file://?" && + test-urlmatch-normalization "file://#" && + test-urlmatch-normalization "file:///" && + test-urlmatch-normalization "file://:" && + ! test-urlmatch-normalization "file://:555" && + test-urlmatch-normalization "scheme://user:pass@host" && + test-urlmatch-normalization "scheme://@host" && + test-urlmatch-normalization "scheme://%00@host" && + ! test-urlmatch-normalization "scheme://%%@host" && + ! test-urlmatch-normalization "scheme://host_" && + test-urlmatch-normalization "scheme://user:pass@host/" && + test-urlmatch-normalization "scheme://@host/" && + test-urlmatch-normalization "scheme://host/" && + test-urlmatch-normalization "scheme://host?x" && + test-urlmatch-normalization "scheme://host#x" && + test-urlmatch-normalization "scheme://host/@" && + test-urlmatch-normalization "scheme://host?@x" && + test-urlmatch-normalization "scheme://host#@x" && + test-urlmatch-normalization "scheme://[::1]" && + test-urlmatch-normalization "scheme://[::1]/" && + ! test-urlmatch-normalization "scheme://hos%41/" && + test-urlmatch-normalization "scheme://[invalid....:/" && + test-urlmatch-normalization "scheme://invalid....:]/" && + ! test-urlmatch-normalization "scheme://invalid....:[/" && + ! test-urlmatch-normalization "scheme://invalid....:[" +' + +test_expect_success 'url port checks' ' + test-urlmatch-normalization "xyz://q@some.host:" && + test-urlmatch-normalization "xyz://q@some.host:456/" && + ! test-urlmatch-normalization "xyz://q@some.host:0" && + ! test-urlmatch-normalization "xyz://q@some.host:0000000" && + test-urlmatch-normalization "xyz://q@some.host:0000001?" && + test-urlmatch-normalization "xyz://q@some.host:065535#" && + test-urlmatch-normalization "xyz://q@some.host:65535" && + ! test-urlmatch-normalization "xyz://q@some.host:65536" && + ! test-urlmatch-normalization "xyz://q@some.host:99999" && + ! test-urlmatch-normalization "xyz://q@some.host:100000" && + ! test-urlmatch-normalization "xyz://q@some.host:100001" && + test-urlmatch-normalization "http://q@some.host:80" && + test-urlmatch-normalization "https://q@some.host:443" && + test-urlmatch-normalization "http://q@some.host:80/" && + test-urlmatch-normalization "https://q@some.host:443?" && + ! test-urlmatch-normalization "http://q@:8008" && + ! test-urlmatch-normalization "http://:8080" && + ! test-urlmatch-normalization "http://:" && + test-urlmatch-normalization "xyz://q@some.host:456/" && + test-urlmatch-normalization "xyz://[::1]:456/" && + test-urlmatch-normalization "xyz://[::1]:/" && + ! test-urlmatch-normalization "xyz://[::1]:000/" && + ! test-urlmatch-normalization "xyz://[::1]:0%300/" && + ! test-urlmatch-normalization "xyz://[::1]:0x80/" && + ! test-urlmatch-normalization "xyz://[::1]:4294967297/" && + ! test-urlmatch-normalization "xyz://[::1]:030f/" +' + +test_expect_success 'url port normalization' ' + test "$(test-urlmatch-normalization -p "http://x:800")" = "http://x:800/" && + test "$(test-urlmatch-normalization -p "http://x:0800")" = "http://x:800/" && + test "$(test-urlmatch-normalization -p "http://x:00000800")" = "http://x:800/" && + test "$(test-urlmatch-normalization -p "http://x:065535")" = "http://x:65535/" && + test "$(test-urlmatch-normalization -p "http://x:1")" = "http://x:1/" && + test "$(test-urlmatch-normalization -p "http://x:80")" = "http://x/" && + test "$(test-urlmatch-normalization -p "http://x:080")" = "http://x/" && + test "$(test-urlmatch-normalization -p "http://x:000000080")" = "http://x/" && + test "$(test-urlmatch-normalization -p "https://x:443")" = "https://x/" && + test "$(test-urlmatch-normalization -p "https://x:0443")" = "https://x/" && + test "$(test-urlmatch-normalization -p "https://x:000000443")" = "https://x/" +' + +test_expect_success 'url general escapes' ' + ! test-urlmatch-normalization "http://x.y?%fg" && + test "$(test-urlmatch-normalization -p "X://W/%7e%41^%3a")" = "x://w/~A%5E%3A" && + test "$(test-urlmatch-normalization -p "X://W/:/?#[]@")" = "x://w/:/?#[]@" && + test "$(test-urlmatch-normalization -p "X://W/$&()*+,;=")" = "x://w/$&()*+,;=" && + test "$(test-urlmatch-normalization -p "X://W/'\''")" = "x://w/'\''" && + test "$(test-urlmatch-normalization -p "X://W?'\!'")" = "x://w/?'\!'" +' + +test_expect_success 'url high-bit escapes' ' + test "$(test-urlmatch-normalization -p "$(cat "$tu-1")")" = "x://q/%01%02%03%04%05%06%07%08%0E%0F%10%11%12" && + test "$(test-urlmatch-normalization -p "$(cat "$tu-2")")" = "x://q/%13%14%15%16%17%18%19%1B%1C%1D%1E%1F%7F" && + test "$(test-urlmatch-normalization -p "$(cat "$tu-3")")" = "x://q/%80%81%82%83%84%85%86%87%88%89%8A%8B%8C%8D%8E%8F" && + test "$(test-urlmatch-normalization -p "$(cat "$tu-4")")" = "x://q/%90%91%92%93%94%95%96%97%98%99%9A%9B%9C%9D%9E%9F" && + test "$(test-urlmatch-normalization -p "$(cat "$tu-5")")" = "x://q/%A0%A1%A2%A3%A4%A5%A6%A7%A8%A9%AA%AB%AC%AD%AE%AF" && + test "$(test-urlmatch-normalization -p "$(cat "$tu-6")")" = "x://q/%B0%B1%B2%B3%B4%B5%B6%B7%B8%B9%BA%BB%BC%BD%BE%BF" && + test "$(test-urlmatch-normalization -p "$(cat "$tu-7")")" = "x://q/%C0%C1%C2%C3%C4%C5%C6%C7%C8%C9%CA%CB%CC%CD%CE%CF" && + test "$(test-urlmatch-normalization -p "$(cat "$tu-8")")" = "x://q/%D0%D1%D2%D3%D4%D5%D6%D7%D8%D9%DA%DB%DC%DD%DE%DF" && + test "$(test-urlmatch-normalization -p "$(cat "$tu-9")")" = "x://q/%E0%E1%E2%E3%E4%E5%E6%E7%E8%E9%EA%EB%EC%ED%EE%EF" && + test "$(test-urlmatch-normalization -p "$(cat "$tu-10")")" = "x://q/%F0%F1%F2%F3%F4%F5%F6%F7%F8%F9%FA%FB%FC%FD%FE%FF" && + test "$(test-urlmatch-normalization -p "$(cat "$tu-11")")" = "x://q/%C2%80%DF%BF%E0%A0%80%EF%BF%BD%F0%90%80%80%F0%AF%BF%BD" +' + +test_expect_success 'url username/password escapes' ' + test "$(test-urlmatch-normalization -p "x://%41%62(^):%70+d@foo")" = "x://Ab(%5E):p+d@foo/" +' + +test_expect_success 'url normalized lengths' ' + test "$(test-urlmatch-normalization -l "Http://%4d%65:%4d^%70@The.Host")" = 25 && + test "$(test-urlmatch-normalization -l "http://%41:%42@x.y/%61/")" = 17 && + test "$(test-urlmatch-normalization -l "http://@x.y/^")" = 15 +' + +test_expect_success 'url . and .. segments' ' + test "$(test-urlmatch-normalization -p "x://y/.")" = "x://y/" && + test "$(test-urlmatch-normalization -p "x://y/./")" = "x://y/" && + test "$(test-urlmatch-normalization -p "x://y/a/.")" = "x://y/a" && + test "$(test-urlmatch-normalization -p "x://y/a/./")" = "x://y/a/" && + test "$(test-urlmatch-normalization -p "x://y/.?")" = "x://y/?" && + test "$(test-urlmatch-normalization -p "x://y/./?")" = "x://y/?" && + test "$(test-urlmatch-normalization -p "x://y/a/.?")" = "x://y/a?" && + test "$(test-urlmatch-normalization -p "x://y/a/./?")" = "x://y/a/?" && + test "$(test-urlmatch-normalization -p "x://y/a/./b/.././../c")" = "x://y/c" && + test "$(test-urlmatch-normalization -p "x://y/a/./b/../.././c/")" = "x://y/c/" && + test "$(test-urlmatch-normalization -p "x://y/a/./b/.././../c/././.././.")" = "x://y/" && + ! test-urlmatch-normalization "x://y/a/./b/.././../c/././.././.." && + test "$(test-urlmatch-normalization -p "x://y/a/./?/././..")" = "x://y/a/?/././.." && + test "$(test-urlmatch-normalization -p "x://y/%2e/")" = "x://y/" && + test "$(test-urlmatch-normalization -p "x://y/%2E/")" = "x://y/" && + test "$(test-urlmatch-normalization -p "x://y/a/%2e./")" = "x://y/" && + test "$(test-urlmatch-normalization -p "x://y/b/.%2E/")" = "x://y/" && + test "$(test-urlmatch-normalization -p "x://y/c/%2e%2E/")" = "x://y/" +' + +# http://@foo specifies an empty user name but does not specify a password +# http://foo specifies neither a user name nor a password +# So they should not be equivalent +test_expect_success 'url equivalents' ' + test-urlmatch-normalization "httP://x" "Http://X/" && + test-urlmatch-normalization "Http://%4d%65:%4d^%70@The.Host" "hTTP://Me:%4D^p@the.HOST:80/" && + ! test-urlmatch-normalization "https://@x.y/^" "httpS://x.y:443/^" && + test-urlmatch-normalization "https://@x.y/^" "httpS://@x.y:0443/^" && + test-urlmatch-normalization "https://@x.y/^/../abc" "httpS://@x.y:0443/abc" && + test-urlmatch-normalization "https://@x.y/^/.." "httpS://@x.y:0443/" +' + +test_done diff --git a/t/t0110/README b/t/t0110/README new file mode 100644 index 0000000000..ad4a50ecd8 --- /dev/null +++ b/t/t0110/README @@ -0,0 +1,9 @@ +The url data files in this directory contain URLs with characters +in the range 0x01-0x1f and 0x7f-0xff to test the proper normalization +of unprintable characters. + +A select few characters in the 0x01-0x1f range are skipped to help +avoid problems running the test itself. + +The urls are in test files in this directory rather than being +embedded in the test script for portability. diff --git a/t/t0110/url-1 b/t/t0110/url-1 new file mode 100644 index 0000000000..519019c5ce --- /dev/null +++ b/t/t0110/url-1 @@ -0,0 +1 @@ +x://q/ diff --git a/t/t0110/url-10 b/t/t0110/url-10 new file mode 100644 index 0000000000..b9965de6a5 --- /dev/null +++ b/t/t0110/url-10 @@ -0,0 +1 @@ +x://q/ðñòóôõö÷øùúûüýþÿ diff --git a/t/t0110/url-11 b/t/t0110/url-11 new file mode 100644 index 0000000000..f0a50f1009 --- /dev/null +++ b/t/t0110/url-11 @@ -0,0 +1 @@ +x://q/Â€ß¿à €ï¿½ð€€ð¯¿½ diff --git a/t/t0110/url-2 b/t/t0110/url-2 new file mode 100644 index 0000000000..43334b05b2 --- /dev/null +++ b/t/t0110/url-2 @@ -0,0 +1 @@ +x://q/ diff --git a/t/t0110/url-3 b/t/t0110/url-3 new file mode 100644 index 0000000000..7378c7bec2 --- /dev/null +++ b/t/t0110/url-3 @@ -0,0 +1 @@ +x://q/€‚ƒ„…†‡ˆ‰Š‹ŒŽ diff --git a/t/t0110/url-4 b/t/t0110/url-4 new file mode 100644 index 0000000000..220b198c97 --- /dev/null +++ b/t/t0110/url-4 @@ -0,0 +1 @@ +x://q/‘’“”•–—˜™š›œžŸ diff --git a/t/t0110/url-5 b/t/t0110/url-5 new file mode 100644 index 0000000000..1ccd927779 --- /dev/null +++ b/t/t0110/url-5 @@ -0,0 +1 @@ +x://q/ ¡¢£¤¥¦§¨©ª«¬®¯ diff --git a/t/t0110/url-6 b/t/t0110/url-6 new file mode 100644 index 0000000000..e8283aac6d --- /dev/null +++ b/t/t0110/url-6 @@ -0,0 +1 @@ +x://q/°±²³´µ¶·¸¹º»¼½¾¿ diff --git a/t/t0110/url-7 b/t/t0110/url-7 new file mode 100644 index 0000000000..fa7c10b615 --- /dev/null +++ b/t/t0110/url-7 @@ -0,0 +1 @@ +x://q/ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏ diff --git a/t/t0110/url-8 b/t/t0110/url-8 new file mode 100644 index 0000000000..79a0ba836f --- /dev/null +++ b/t/t0110/url-8 @@ -0,0 +1 @@ +x://q/ÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞß diff --git a/t/t0110/url-9 b/t/t0110/url-9 new file mode 100644 index 0000000000..8b44bec48b --- /dev/null +++ b/t/t0110/url-9 @@ -0,0 +1 @@ +x://q/àáâãäåæçèéêëìíîï diff --git a/t/t0202-gettext-perl.sh b/t/t0202-gettext-perl.sh index 428ebb0080..a29d166e00 100755 --- a/t/t0202-gettext-perl.sh +++ b/t/t0202-gettext-perl.sh @@ -12,7 +12,7 @@ if ! test_have_prereq PERL; then test_done fi -"$PERL_PATH" -MTest::More -e 0 2>/dev/null || { +perl -MTest::More -e 0 2>/dev/null || { skip_all="Perl Test::More unavailable, skipping test" test_done } @@ -22,6 +22,6 @@ test_external_has_tap=1 test_external_without_stderr \ 'Perl Git::I18N API' \ - "$PERL_PATH" "$TEST_DIRECTORY"/t0202/test.pl + perl "$TEST_DIRECTORY"/t0202/test.pl test_done diff --git a/t/t0202/test.pl b/t/t0202/test.pl index 2c10cb4693..2c10cb4693 100644..100755 --- a/t/t0202/test.pl +++ b/t/t0202/test.pl diff --git a/t/t1005-read-tree-reset.sh b/t/t1005-read-tree-reset.sh index f53de79e56..074568500a 100755 --- a/t/t1005-read-tree-reset.sh +++ b/t/t1005-read-tree-reset.sh @@ -8,84 +8,99 @@ test_description='read-tree -u --reset' # two-tree test test_expect_success 'setup' ' - git init && - mkdir df && - echo content >df/file && - git add df/file && - git commit -m one && - git ls-files >expect && - rm -rf df && - echo content >df && - git add df && - echo content >new && - git add new && - git commit -m two + git init && + mkdir df && + echo content >df/file && + git add df/file && + git commit -m one && + git ls-files >expect && + rm -rf df && + echo content >df && + git add df && + echo content >new && + git add new && + git commit -m two ' test_expect_success 'reset should work' ' - read_tree_u_must_succeed -u --reset HEAD^ && - git ls-files >actual && - test_cmp expect actual + read_tree_u_must_succeed -u --reset HEAD^ && + git ls-files >actual && + test_cmp expect actual ' test_expect_success 'reset should remove remnants from a failed merge' ' - read_tree_u_must_succeed --reset -u HEAD && - git ls-files -s >expect && - sha1=$(git rev-parse :new) && - ( - echo "100644 $sha1 1 old" - echo "100644 $sha1 3 old" - ) | git update-index --index-info && - >old && - git ls-files -s && - read_tree_u_must_succeed --reset -u HEAD && - git ls-files -s >actual && - ! test -f old + read_tree_u_must_succeed --reset -u HEAD && + git ls-files -s >expect && + sha1=$(git rev-parse :new) && + ( + echo "100644 $sha1 1 old" + echo "100644 $sha1 3 old" + ) | git update-index --index-info && + >old && + git ls-files -s && + read_tree_u_must_succeed --reset -u HEAD && + git ls-files -s >actual && + ! test -f old +' + +test_expect_success 'two-way reset should remove remnants too' ' + read_tree_u_must_succeed --reset -u HEAD && + git ls-files -s >expect && + sha1=$(git rev-parse :new) && + ( + echo "100644 $sha1 1 old" + echo "100644 $sha1 3 old" + ) | git update-index --index-info && + >old && + git ls-files -s && + read_tree_u_must_succeed --reset -u HEAD HEAD && + git ls-files -s >actual && + ! test -f old ' test_expect_success 'Porcelain reset should remove remnants too' ' - read_tree_u_must_succeed --reset -u HEAD && - git ls-files -s >expect && - sha1=$(git rev-parse :new) && - ( - echo "100644 $sha1 1 old" - echo "100644 $sha1 3 old" - ) | git update-index --index-info && - >old && - git ls-files -s && - git reset --hard && - git ls-files -s >actual && - ! test -f old + read_tree_u_must_succeed --reset -u HEAD && + git ls-files -s >expect && + sha1=$(git rev-parse :new) && + ( + echo "100644 $sha1 1 old" + echo "100644 $sha1 3 old" + ) | git update-index --index-info && + >old && + git ls-files -s && + git reset --hard && + git ls-files -s >actual && + ! test -f old ' test_expect_success 'Porcelain checkout -f should remove remnants too' ' - read_tree_u_must_succeed --reset -u HEAD && - git ls-files -s >expect && - sha1=$(git rev-parse :new) && - ( - echo "100644 $sha1 1 old" - echo "100644 $sha1 3 old" - ) | git update-index --index-info && - >old && - git ls-files -s && - git checkout -f && - git ls-files -s >actual && - ! test -f old + read_tree_u_must_succeed --reset -u HEAD && + git ls-files -s >expect && + sha1=$(git rev-parse :new) && + ( + echo "100644 $sha1 1 old" + echo "100644 $sha1 3 old" + ) | git update-index --index-info && + >old && + git ls-files -s && + git checkout -f && + git ls-files -s >actual && + ! test -f old ' test_expect_success 'Porcelain checkout -f HEAD should remove remnants too' ' - read_tree_u_must_succeed --reset -u HEAD && - git ls-files -s >expect && - sha1=$(git rev-parse :new) && - ( - echo "100644 $sha1 1 old" - echo "100644 $sha1 3 old" - ) | git update-index --index-info && - >old && - git ls-files -s && - git checkout -f HEAD && - git ls-files -s >actual && - ! test -f old + read_tree_u_must_succeed --reset -u HEAD && + git ls-files -s >expect && + sha1=$(git rev-parse :new) && + ( + echo "100644 $sha1 1 old" + echo "100644 $sha1 3 old" + ) | git update-index --index-info && + >old && + git ls-files -s && + git checkout -f HEAD && + git ls-files -s >actual && + ! test -f old ' test_done diff --git a/t/t1006-cat-file.sh b/t/t1006-cat-file.sh index 4e911fb43d..a72e700ae4 100755 --- a/t/t1006-cat-file.sh +++ b/t/t1006-cat-file.sh @@ -78,6 +78,35 @@ $content" echo $sha1 | git cat-file --batch-check="%(objecttype) %(objectname)" >actual && test_cmp expect actual ' + + test_expect_success '--batch-check with %(rest)' ' + echo "$type this is some extra content" >expect && + echo "$sha1 this is some extra content" | + git cat-file --batch-check="%(objecttype) %(rest)" >actual && + test_cmp expect actual + ' + + test -z "$content" || + test_expect_success "--batch without type ($type)" ' + { + echo "$size" && + maybe_remove_timestamp "$content" $no_ts + } >expect && + echo $sha1 | git cat-file --batch="%(objectsize)" >actual.full && + maybe_remove_timestamp "$(cat actual.full)" $no_ts >actual && + test_cmp expect actual + ' + + test -z "$content" || + test_expect_success "--batch without size ($type)" ' + { + echo "$type" && + maybe_remove_timestamp "$content" $no_ts + } >expect && + echo $sha1 | git cat-file --batch="%(objecttype)" >actual.full && + maybe_remove_timestamp "$(cat actual.full)" $no_ts >actual && + test_cmp expect actual + ' } hello_content="Hello World" @@ -91,6 +120,14 @@ test_expect_success "setup" ' run_tests 'blob' $hello_sha1 $hello_size "$hello_content" "$hello_content" +test_expect_success '--batch-check without %(rest) considers whole line' ' + echo "$hello_sha1 blob $hello_size" >expect && + git update-index --add --cacheinfo 100644 $hello_sha1 "white space" && + test_when_finished "git update-index --remove \"white space\"" && + echo ":white space" | git cat-file --batch-check >actual && + test_cmp expect actual +' + tree_sha1=$(git write-tree) tree_size=33 tree_pretty_content="100644 blob $hello_sha1 hello" @@ -179,6 +216,12 @@ test_expect_success "--batch-check for an emtpy line" ' test " missing" = "$(echo | git cat-file --batch-check)" ' +test_expect_success 'empty --batch-check notices missing object' ' + echo "$_z40 missing" >expect && + echo "$_z40" | git cat-file --batch-check="" >actual && + test_cmp expect actual +' + batch_input="$hello_sha1 $commit_sha1 $tag_sha1 @@ -219,4 +262,38 @@ test_expect_success "--batch-check with multiple sha1s gives correct format" ' "$(echo_without_newline "$batch_check_input" | git cat-file --batch-check)" ' +test_expect_success 'setup blobs which are likely to delta' ' + test-genrandom foo 10240 >foo && + { cat foo; echo plus; } >foo-plus && + git add foo foo-plus && + git commit -m foo && + cat >blobs <<-\EOF + HEAD:foo + HEAD:foo-plus + EOF +' + +test_expect_success 'confirm that neither loose blob is a delta' ' + cat >expect <<-EOF + $_z40 + $_z40 + EOF + git cat-file --batch-check="%(deltabase)" <blobs >actual && + test_cmp expect actual +' + +# To avoid relying too much on the current delta heuristics, +# we will check only that one of the two objects is a delta +# against the other, but not the order. We can do so by just +# asking for the base of both, and checking whether either +# sha1 appears in the output. +test_expect_success '%(deltabase) reports packed delta bases' ' + git repack -ad && + git cat-file --batch-check="%(deltabase)" <blobs >actual && + { + grep "$(git rev-parse HEAD:foo)" actual || + grep "$(git rev-parse HEAD:foo-plus)" actual + } +' + test_done diff --git a/t/t1010-mktree.sh b/t/t1010-mktree.sh index df573c4978..b946f87686 100755 --- a/t/t1010-mktree.sh +++ b/t/t1010-mktree.sh @@ -42,13 +42,13 @@ test_expect_success 'ls-tree piped to mktree (2)' ' ' test_expect_success 'ls-tree output in wrong order given to mktree (1)' ' - "$PERL_PATH" -e "print reverse <>" <top | + perl -e "print reverse <>" <top | git mktree >actual && test_cmp tree actual ' test_expect_success 'ls-tree output in wrong order given to mktree (2)' ' - "$PERL_PATH" -e "print reverse <>" <top.withsub | + perl -e "print reverse <>" <top.withsub | git mktree >actual && test_cmp tree.withsub actual ' diff --git a/t/t1013-loose-object-format.sh b/t/t1013-loose-object-format.sh deleted file mode 100755 index fbf5f2fc00..0000000000 --- a/t/t1013-loose-object-format.sh +++ /dev/null @@ -1,66 +0,0 @@ -#!/bin/sh -# -# Copyright (c) 2011 Roberto Tyley -# - -test_description='Correctly identify and parse loose object headers - -There are two file formats for loose objects - the original standard -format, and the experimental format introduced with Git v1.4.3, later -deprecated with v1.5.3. Although Git no longer writes the -experimental format, objects in both formats must be read, with the -format for a given file being determined by the header. - -Detecting file format based on header is not entirely trivial, not -least because the first byte of a zlib-deflated stream will vary -depending on how much memory was allocated for the deflation window -buffer when the object was written out (for example 4KB on Android, -rather that 32KB on a normal PC). - -The loose objects used as test vectors have been generated with the -following Git versions: - -standard format: Git v1.7.4.1 -experimental format: Git v1.4.3 (legacyheaders=false) -standard format, deflated with 4KB window size: Agit/JGit on Android -' - -. ./test-lib.sh - -assert_blob_equals() { - printf "%s" "$2" >expected && - git cat-file -p "$1" >actual && - test_cmp expected actual -} - -test_expect_success setup ' - cp -R "$TEST_DIRECTORY/t1013/objects" .git/ && - git --version -' - -test_expect_success 'read standard-format loose objects' ' - git cat-file tag 8d4e360d6c70fbd72411991c02a09c442cf7a9fa && - git cat-file commit 6baee0540ea990d9761a3eb9ab183003a71c3696 && - git ls-tree 7a37b887a73791d12d26c0d3e39568a8fb0fa6e8 && - assert_blob_equals "257cc5642cb1a054f08cc83f2d943e56fd3ebe99" "foo$LF" -' - -test_expect_success 'read experimental-format loose objects' ' - git cat-file tag 76e7fa9941f4d5f97f64fea65a2cba436bc79cbb && - git cat-file commit 7875c6237d3fcdd0ac2f0decc7d3fa6a50b66c09 && - git ls-tree 95b1625de3ba8b2214d1e0d0591138aea733f64f && - assert_blob_equals "2e65efe2a145dda7ee51d1741299f848e5bf752e" "a" && - assert_blob_equals "9ae9e86b7bd6cb1472d9373702d8249973da0832" "ab" && - assert_blob_equals "85df50785d62d3b05ab03d9cbf7e4a0b49449730" "abcd" && - assert_blob_equals "1656f9233d999f61ef23ef390b9c71d75399f435" "abcdefgh" && - assert_blob_equals "1e72a6b2c4a577ab0338860fa9fe87f761fc9bbd" "abcdefghi" && - assert_blob_equals "70e6a83d8dcb26fc8bc0cf702e2ddeb6adca18fd" "abcdefghijklmnop" && - assert_blob_equals "bd15045f6ce8ff75747562173640456a394412c8" "abcdefghijklmnopqrstuvwx" -' - -test_expect_success 'read standard-format objects deflated with smaller window buffer' ' - git cat-file tag f816d5255855ac160652ee5253b06cd8ee14165a && - git cat-file tag 149cedb5c46929d18e0f118e9fa31927487af3b6 -' - -test_done diff --git a/t/t1013/objects/14/9cedb5c46929d18e0f118e9fa31927487af3b6 b/t/t1013/objects/14/9cedb5c46929d18e0f118e9fa31927487af3b6 Binary files differdeleted file mode 100644 index 472fd1458e..0000000000 --- a/t/t1013/objects/14/9cedb5c46929d18e0f118e9fa31927487af3b6 +++ /dev/null diff --git a/t/t1013/objects/16/56f9233d999f61ef23ef390b9c71d75399f435 b/t/t1013/objects/16/56f9233d999f61ef23ef390b9c71d75399f435 Binary files differdeleted file mode 100644 index c379d74ae2..0000000000 --- a/t/t1013/objects/16/56f9233d999f61ef23ef390b9c71d75399f435 +++ /dev/null diff --git a/t/t1013/objects/1e/72a6b2c4a577ab0338860fa9fe87f761fc9bbd b/t/t1013/objects/1e/72a6b2c4a577ab0338860fa9fe87f761fc9bbd Binary files differdeleted file mode 100644 index 93706305bc..0000000000 --- a/t/t1013/objects/1e/72a6b2c4a577ab0338860fa9fe87f761fc9bbd +++ /dev/null diff --git a/t/t1013/objects/25/7cc5642cb1a054f08cc83f2d943e56fd3ebe99 b/t/t1013/objects/25/7cc5642cb1a054f08cc83f2d943e56fd3ebe99 Binary files differdeleted file mode 100644 index bdcf704c9e..0000000000 --- a/t/t1013/objects/25/7cc5642cb1a054f08cc83f2d943e56fd3ebe99 +++ /dev/null diff --git a/t/t1013/objects/2e/65efe2a145dda7ee51d1741299f848e5bf752e b/t/t1013/objects/2e/65efe2a145dda7ee51d1741299f848e5bf752e Binary files differdeleted file mode 100644 index ad62c43e41..0000000000 --- a/t/t1013/objects/2e/65efe2a145dda7ee51d1741299f848e5bf752e +++ /dev/null diff --git a/t/t1013/objects/6b/aee0540ea990d9761a3eb9ab183003a71c3696 b/t/t1013/objects/6b/aee0540ea990d9761a3eb9ab183003a71c3696 Binary files differdeleted file mode 100644 index 3d2f0337db..0000000000 --- a/t/t1013/objects/6b/aee0540ea990d9761a3eb9ab183003a71c3696 +++ /dev/null diff --git a/t/t1013/objects/70/e6a83d8dcb26fc8bc0cf702e2ddeb6adca18fd b/t/t1013/objects/70/e6a83d8dcb26fc8bc0cf702e2ddeb6adca18fd Binary files differdeleted file mode 100644 index b3f71a6ee5..0000000000 --- a/t/t1013/objects/70/e6a83d8dcb26fc8bc0cf702e2ddeb6adca18fd +++ /dev/null diff --git a/t/t1013/objects/76/e7fa9941f4d5f97f64fea65a2cba436bc79cbb b/t/t1013/objects/76/e7fa9941f4d5f97f64fea65a2cba436bc79cbb deleted file mode 100644 index af4e9a7b0c..0000000000 --- a/t/t1013/objects/76/e7fa9941f4d5f97f64fea65a2cba436bc79cbb +++ /dev/null @@ -1,2 +0,0 @@ -Âxœ%ÌA‚0@Ñ}O1{cSZ(˜ãνáÃthª”’ZŒÜÞ Ëÿ?
¦m×6dµiÉ9…¤Gå˜h´Ø¨ÁZR'Q¶…RŒ¡ˆ‚ø³p‘ç‚ÓqL9âÏ=g¸§sIÐoopÎÿ”eÏ«_1»€³¤$×ç*Si«ëNwpP•RBôûÅÁú -³‡[(ð®d-øÁL9á
\ No newline at end of file diff --git a/t/t1013/objects/78/75c6237d3fcdd0ac2f0decc7d3fa6a50b66c09 b/t/t1013/objects/78/75c6237d3fcdd0ac2f0decc7d3fa6a50b66c09 Binary files differdeleted file mode 100644 index 3dd28be5c6..0000000000 --- a/t/t1013/objects/78/75c6237d3fcdd0ac2f0decc7d3fa6a50b66c09 +++ /dev/null diff --git a/t/t1013/objects/7a/37b887a73791d12d26c0d3e39568a8fb0fa6e8 b/t/t1013/objects/7a/37b887a73791d12d26c0d3e39568a8fb0fa6e8 Binary files differdeleted file mode 100644 index 2b97b264c3..0000000000 --- a/t/t1013/objects/7a/37b887a73791d12d26c0d3e39568a8fb0fa6e8 +++ /dev/null diff --git a/t/t1013/objects/85/df50785d62d3b05ab03d9cbf7e4a0b49449730 b/t/t1013/objects/85/df50785d62d3b05ab03d9cbf7e4a0b49449730 Binary files differdeleted file mode 100644 index 6dff746876..0000000000 --- a/t/t1013/objects/85/df50785d62d3b05ab03d9cbf7e4a0b49449730 +++ /dev/null diff --git a/t/t1013/objects/8d/4e360d6c70fbd72411991c02a09c442cf7a9fa b/t/t1013/objects/8d/4e360d6c70fbd72411991c02a09c442cf7a9fa Binary files differdeleted file mode 100644 index cb41e92d07..0000000000 --- a/t/t1013/objects/8d/4e360d6c70fbd72411991c02a09c442cf7a9fa +++ /dev/null diff --git a/t/t1013/objects/95/b1625de3ba8b2214d1e0d0591138aea733f64f b/t/t1013/objects/95/b1625de3ba8b2214d1e0d0591138aea733f64f Binary files differdeleted file mode 100644 index 7ac46b4f70..0000000000 --- a/t/t1013/objects/95/b1625de3ba8b2214d1e0d0591138aea733f64f +++ /dev/null diff --git a/t/t1013/objects/9a/e9e86b7bd6cb1472d9373702d8249973da0832 b/t/t1013/objects/9a/e9e86b7bd6cb1472d9373702d8249973da0832 Binary files differdeleted file mode 100644 index 9d8316d4e5..0000000000 --- a/t/t1013/objects/9a/e9e86b7bd6cb1472d9373702d8249973da0832 +++ /dev/null diff --git a/t/t1013/objects/bd/15045f6ce8ff75747562173640456a394412c8 b/t/t1013/objects/bd/15045f6ce8ff75747562173640456a394412c8 Binary files differdeleted file mode 100644 index eebf23956e..0000000000 --- a/t/t1013/objects/bd/15045f6ce8ff75747562173640456a394412c8 +++ /dev/null diff --git a/t/t1013/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 b/t/t1013/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 Binary files differdeleted file mode 100644 index 134cf19379..0000000000 --- a/t/t1013/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391 +++ /dev/null diff --git a/t/t1013/objects/f8/16d5255855ac160652ee5253b06cd8ee14165a b/t/t1013/objects/f8/16d5255855ac160652ee5253b06cd8ee14165a deleted file mode 100644 index 26b75aec56..0000000000 --- a/t/t1013/objects/f8/16d5255855ac160652ee5253b06cd8ee14165a +++ /dev/null @@ -1 +0,0 @@ -H‰ÌÁ‚0€aÏ{ŠÞ
I»e&Æø*¥ˆG°ß^¸ýù¿ËDåÒ†wU‡Ò—¬S±4ªŠÆªž ,fÅ[ðßVAÛºÎüxÈÇö6[wtG§Lu¸?—¦²¼Ú×@‰"gì{†+by¾%M
\ No newline at end of file diff --git a/t/t1020-subdirectory.sh b/t/t1020-subdirectory.sh index 1e2945ec7e..6902320e81 100755 --- a/t/t1020-subdirectory.sh +++ b/t/t1020-subdirectory.sh @@ -148,7 +148,7 @@ test_expect_success 'GIT_PREFIX for built-ins' ' ( cd dir && printf "change" >two && - env GIT_EXTERNAL_DIFF=./diff git diff >../actual + GIT_EXTERNAL_DIFF=./diff git diff >../actual git checkout -- two ) && test_cmp expect actual diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh index c4a7d84f46..3e3f77b59b 100755 --- a/t/t1300-repo-config.sh +++ b/t/t1300-repo-config.sh @@ -475,15 +475,28 @@ ein.bahn=strasse EOF test_expect_success 'alternative GIT_CONFIG' ' - GIT_CONFIG=other-config git config -l >output && + GIT_CONFIG=other-config git config --list >output && test_cmp expect output ' test_expect_success 'alternative GIT_CONFIG (--file)' ' - git config --file other-config -l > output && + git config --file other-config --list >output && test_cmp expect output ' +test_expect_success 'alternative GIT_CONFIG (--file=-)' ' + git config --file - --list <other-config >output && + test_cmp expect output +' + +test_expect_success 'setting a value in stdin is an error' ' + test_must_fail git config --file - some.value foo +' + +test_expect_success 'editing stdin is an error' ' + test_must_fail git config --file - --edit +' + test_expect_success 'refer config from subdirectory' ' mkdir x && ( @@ -652,16 +665,23 @@ test_expect_success numbers ' test_cmp expect actual ' +test_expect_success '--int is at least 64 bits' ' + git config giga.watts 121g && + echo 129922760704 >expect && + git config --int --get giga.watts >actual && + test_cmp expect actual +' + test_expect_success 'invalid unit' ' git config aninvalid.unit "1auto" && echo 1auto >expect && git config aninvalid.unit >actual && test_cmp expect actual && - cat > expect <<-\EOF - fatal: bad config value for '\''aninvalid.unit'\'' in .git/config + cat >expect <<-\EOF + fatal: bad numeric config value '\''1auto'\'' for '\''aninvalid.unit'\'' in .git/config: invalid unit EOF test_must_fail git config --int --get aninvalid.unit 2>actual && - test_cmp actual expect + test_i18ncmp expect actual ' cat > expect << EOF @@ -954,24 +974,15 @@ test_expect_success SYMLINKS 'symlinked configuration' ' ' test_expect_success 'nonexistent configuration' ' - ( - GIT_CONFIG=doesnotexist && - export GIT_CONFIG && - test_must_fail git config --list && - test_must_fail git config test.xyzzy - ) + test_must_fail env GIT_CONFIG=doesnotexist git config --list && + test_must_fail env GIT_CONFIG=doesnotexist git config test.xyzzy ' test_expect_success SYMLINKS 'symlink to nonexistent configuration' ' ln -s doesnotexist linktonada && ln -s linktonada linktolinktonada && - ( - GIT_CONFIG=linktonada && - export GIT_CONFIG && - test_must_fail git config --list && - GIT_CONFIG=linktolinktonada && - test_must_fail git config --list - ) + test_must_fail env GIT_CONFIG=linktonada git config --list && + test_must_fail env GIT_CONFIG=linktolinktonada git config --list ' test_expect_success 'check split_cmdline return' " @@ -1087,6 +1098,31 @@ test_expect_success 'barf on incomplete string' ' grep " line 3 " error ' +test_expect_success 'urlmatch' ' + cat >.git/config <<-\EOF && + [http] + sslVerify + [http "https://weak.example.com"] + sslVerify = false + cookieFile = /tmp/cookie.txt + EOF + + echo true >expect && + git config --bool --get-urlmatch http.SSLverify https://good.example.com >actual && + test_cmp expect actual && + + echo false >expect && + git config --bool --get-urlmatch http.sslverify https://weak.example.com >actual && + test_cmp expect actual && + + { + echo http.cookiefile /tmp/cookie.txt && + echo http.sslverify false + } >expect && + git config --get-urlmatch HTTP https://weak.example.com >actual && + test_cmp expect actual +' + # good section hygiene test_expect_failure 'unsetting the last key in a section removes header' ' cat >.git/config <<-\EOF && diff --git a/t/t1303-wacky-config.sh b/t/t1303-wacky-config.sh index 46103a1591..3a2c81968c 100755 --- a/t/t1303-wacky-config.sh +++ b/t/t1303-wacky-config.sh @@ -3,17 +3,28 @@ test_description='Test wacky input to git config' . ./test-lib.sh +# Leaving off the newline is intentional! setup() { (printf "[section]\n" && printf " key = foo") >.git/config } +# 'check section.key value' verifies that the entry for section.key is +# 'value' check() { echo "$2" >expected git config --get "$1" >actual 2>&1 test_cmp actual expected } +# 'check section.key regex value' verifies that the entry for +# section.key *that matches 'regex'* is 'value' +check_regex() { + echo "$3" >expected + git config --get "$1" "$2" >actual 2>&1 + test_cmp actual expected +} + test_expect_success 'modify same key' ' setup && git config section.key bar && @@ -47,4 +58,57 @@ test_expect_success 'do not crash on special long config line' ' check section.key "$LONG_VALUE" ' +setup_many() { + setup && + # This time we want the newline so that we can tack on more + # entries. + echo >>.git/config && + # Semi-efficient way of concatenating 5^5 = 3125 lines. Note + # that because 'setup' already put one line, this means 3126 + # entries for section.key in the config file. + cat >5to1 <<-\EOF && + key = foo + key = foo + key = foo + key = foo + key = foo + EOF + cat 5to1 5to1 5to1 5to1 5to1 >5to2 && # 25 + cat 5to2 5to2 5to2 5to2 5to2 >5to3 && # 125 + cat 5to3 5to3 5to3 5to3 5to3 >5to4 && # 635 + cat 5to4 5to4 5to4 5to4 5to4 >>.git/config # 3125 +} + +test_expect_success 'get many entries' ' + setup_many && + git config --get-all section.key >actual && + test_line_count = 3126 actual +' + +test_expect_success 'get many entries by regex' ' + setup_many && + git config --get-regexp "sec.*ke." >actual && + test_line_count = 3126 actual +' + +test_expect_success 'add and replace one of many entries' ' + setup_many && + git config --add section.key bar && + check_regex section.key "b.*r" bar && + git config section.key beer "b.*r" && + check_regex section.key "b.*r" beer +' + +test_expect_success 'replace many entries' ' + setup_many && + git config --replace-all section.key bar && + check section.key bar +' + +test_expect_success 'unset many entries' ' + setup_many && + git config --unset-all section.key && + test_must_fail git config section.key +' + test_done diff --git a/t/t1305-config-include.sh b/t/t1305-config-include.sh index a70707620f..9ba2ba11c3 100755 --- a/t/t1305-config-include.sh +++ b/t/t1305-config-include.sh @@ -113,7 +113,7 @@ test_expect_success 'missing include files are ignored' ' test_expect_success 'absolute includes from command line work' ' echo "[test]one = 1" >one && echo 1 >expect && - git -c include.path="$PWD/one" config test.one >actual && + git -c include.path="$(pwd)/one" config test.one >actual && test_cmp expect actual ' @@ -122,6 +122,36 @@ test_expect_success 'relative includes from command line fail' ' test_must_fail git -c include.path=one config test.one ' +test_expect_success 'absolute includes from blobs work' ' + echo "[test]one = 1" >one && + echo "[include]path=$(pwd)/one" >blob && + blob=$(git hash-object -w blob) && + echo 1 >expect && + git config --blob=$blob test.one >actual && + test_cmp expect actual +' + +test_expect_success 'relative includes from blobs fail' ' + echo "[test]one = 1" >one && + echo "[include]path=one" >blob && + blob=$(git hash-object -w blob) && + test_must_fail git config --blob=$blob test.one +' + +test_expect_success 'absolute includes from stdin work' ' + echo "[test]one = 1" >one && + echo 1 >expect && + echo "[include]path=\"$(pwd)/one\"" | + git config --file - test.one >actual && + test_cmp expect actual +' + +test_expect_success 'relative includes from stdin line fail' ' + echo "[test]one = 1" >one && + echo "[include]path=one" | + test_must_fail git config --file - test.one +' + test_expect_success 'include cycles are detected' ' cat >.gitconfig <<-\EOF && [test]value = gitconfig diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index e415ee0bbf..6ffd82fe32 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -302,4 +302,636 @@ test_expect_success \ 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER)' \ 'test OTHER = $(git cat-file blob "master@{2005-05-26 23:42}:F")' +a=refs/heads/a +b=refs/heads/b +c=refs/heads/c +E='""' +F='%s\0' +pws='path with space' + +test_expect_success 'stdin test setup' ' + echo "$pws" >"$pws" && + git add -- "$pws" && + git commit -m "$pws" +' + +test_expect_success '-z fails without --stdin' ' + test_must_fail git update-ref -z $m $m $m 2>err && + grep "usage: git update-ref" err +' + +test_expect_success 'stdin works with no input' ' + >stdin && + git update-ref --stdin <stdin && + git rev-parse --verify -q $m +' + +test_expect_success 'stdin fails on empty line' ' + echo "" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: empty command in input" err +' + +test_expect_success 'stdin fails on only whitespace' ' + echo " " >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: whitespace before command: " err +' + +test_expect_success 'stdin fails on leading whitespace' ' + echo " create $a $m" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: whitespace before command: create $a $m" err +' + +test_expect_success 'stdin fails on unknown command' ' + echo "unknown $a" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: unknown command: unknown $a" err +' + +test_expect_success 'stdin fails on badly quoted input' ' + echo "create $a \"master" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: badly quoted argument: \\\"master" err +' + +test_expect_success 'stdin fails on arguments not separated by space' ' + echo "create \"$a\"master" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: expected SP but got: master" err +' + +test_expect_success 'stdin fails create with no ref' ' + echo "create " >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: create line 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 && + grep "fatal: create $a missing <newvalue>" err +' + +test_expect_success 'stdin fails create with too many arguments' ' + echo "create $a $m $m" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: create $a has extra input: $m" err +' + +test_expect_success 'stdin fails update with no ref' ' + echo "update " >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: update line 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 && + grep "fatal: update $a missing <newvalue>" err +' + +test_expect_success 'stdin fails update with too many arguments' ' + echo "update $a $m $m $m" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: update $a has extra input: $m" err +' + +test_expect_success 'stdin fails delete with no ref' ' + echo "delete " >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: delete line 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 && + grep "fatal: delete $a has extra input: $m" err +' + +test_expect_success 'stdin fails verify with too many arguments' ' + echo "verify $a $m $m" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: verify $a has extra input: $m" err +' + +test_expect_success 'stdin fails option with unknown name' ' + echo "option unknown" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: option unknown: unknown" err +' + +test_expect_success 'stdin fails with duplicate refs' ' + cat >stdin <<-EOF && + create $a $m + create $b $m + create $a $m + EOF + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: Multiple updates for ref '"'"'$a'"'"' not allowed." err +' + +test_expect_success 'stdin create ref works' ' + echo "create $a $m" >stdin && + git update-ref --stdin <stdin && + git rev-parse $m >expect && + git rev-parse $a >actual && + test_cmp expect actual +' + +test_expect_success 'stdin update ref creates with zero old value' ' + echo "update $b $m $Z" >stdin && + git update-ref --stdin <stdin && + git rev-parse $m >expect && + git rev-parse $b >actual && + test_cmp expect actual && + git update-ref -d $b +' + +test_expect_success 'stdin update ref creates with empty old value' ' + echo "update $b $m $E" >stdin && + git update-ref --stdin <stdin && + git rev-parse $m >expect && + git rev-parse $b >actual && + test_cmp expect actual +' + +test_expect_success 'stdin create ref works with path with space to blob' ' + echo "create refs/blobs/pws \"$m:$pws\"" >stdin && + git update-ref --stdin <stdin && + git rev-parse "$m:$pws" >expect && + git rev-parse refs/blobs/pws >actual && + test_cmp expect actual && + git update-ref -d refs/blobs/pws +' + +test_expect_success 'stdin update ref fails with wrong old value' ' + echo "update $c $m $m~1" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err && + test_must_fail git rev-parse --verify -q $c +' + +test_expect_success 'stdin update ref fails with bad old value' ' + echo "update $c $m does-not-exist" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: invalid old value for ref $c: does-not-exist" err && + test_must_fail git rev-parse --verify -q $c +' + +test_expect_success 'stdin create ref fails with bad new value' ' + echo "create $c does-not-exist" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: invalid new value for ref $c: does-not-exist" err && + test_must_fail git rev-parse --verify -q $c +' + +test_expect_success 'stdin create ref fails with zero new value' ' + echo "create $c " >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: create $c given zero new value" err && + test_must_fail git rev-parse --verify -q $c +' + +test_expect_success 'stdin update ref works with right old value' ' + echo "update $b $m~1 $m" >stdin && + git update-ref --stdin <stdin && + git rev-parse $m~1 >expect && + git rev-parse $b >actual && + test_cmp expect actual +' + +test_expect_success 'stdin delete ref fails with wrong old value' ' + echo "delete $a $m~1" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: Cannot lock the ref '"'"'$a'"'"'" err && + git rev-parse $m >expect && + git rev-parse $a >actual && + test_cmp expect actual +' + +test_expect_success 'stdin delete ref fails with zero old value' ' + echo "delete $a " >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: delete $a given zero old value" err && + git rev-parse $m >expect && + git rev-parse $a >actual && + test_cmp expect actual +' + +test_expect_success 'stdin update symref works option no-deref' ' + git symbolic-ref TESTSYMREF $b && + cat >stdin <<-EOF && + option no-deref + update TESTSYMREF $a $b + EOF + git update-ref --stdin <stdin && + git rev-parse TESTSYMREF >expect && + git rev-parse $a >actual && + test_cmp expect actual && + git rev-parse $m~1 >expect && + git rev-parse $b >actual && + test_cmp expect actual +' + +test_expect_success 'stdin delete symref works option no-deref' ' + git symbolic-ref TESTSYMREF $b && + cat >stdin <<-EOF && + option no-deref + delete TESTSYMREF $b + EOF + git update-ref --stdin <stdin && + test_must_fail git rev-parse --verify -q TESTSYMREF && + git rev-parse $m~1 >expect && + git rev-parse $b >actual && + test_cmp expect actual +' + +test_expect_success 'stdin delete ref works with right old value' ' + echo "delete $b $m~1" >stdin && + git update-ref --stdin <stdin && + test_must_fail git rev-parse --verify -q $b +' + +test_expect_success 'stdin update/create/verify combination works' ' + cat >stdin <<-EOF && + update $a $m + create $b $m + verify $c + EOF + git update-ref --stdin <stdin && + git rev-parse $m >expect && + git rev-parse $a >actual && + test_cmp expect actual && + git rev-parse $b >actual && + test_cmp expect actual && + test_must_fail git rev-parse --verify -q $c +' + +test_expect_success 'stdin update refs works with identity updates' ' + cat >stdin <<-EOF && + update $a $m $m + update $b $m $m + update $c $Z $E + EOF + git update-ref --stdin <stdin && + git rev-parse $m >expect && + git rev-parse $a >actual && + test_cmp expect actual && + git rev-parse $b >actual && + test_cmp expect actual && + test_must_fail git rev-parse --verify -q $c +' + +test_expect_success 'stdin update refs fails with wrong old value' ' + git update-ref $c $m && + cat >stdin <<-EOF && + update $a $m $m + update $b $m $m + update $c '' + EOF + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err && + git rev-parse $m >expect && + git rev-parse $a >actual && + test_cmp expect actual && + git rev-parse $b >actual && + test_cmp expect actual && + git rev-parse $c >actual && + test_cmp expect actual +' + +test_expect_success 'stdin delete refs works with packed and loose refs' ' + git pack-refs --all && + git update-ref $c $m~1 && + cat >stdin <<-EOF && + delete $a $m + update $b $Z $m + update $c $E $m~1 + EOF + git update-ref --stdin <stdin && + test_must_fail git rev-parse --verify -q $a && + test_must_fail git rev-parse --verify -q $b && + test_must_fail git rev-parse --verify -q $c +' + +test_expect_success 'stdin -z works on empty input' ' + >stdin && + git update-ref -z --stdin <stdin && + git rev-parse --verify -q $m +' + +test_expect_success 'stdin -z fails on empty line' ' + echo "" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: whitespace before command: " err +' + +test_expect_success 'stdin -z fails on empty command' ' + printf $F "" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: empty command in input" err +' + +test_expect_success 'stdin -z fails on only whitespace' ' + printf $F " " >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: whitespace before command: " err +' + +test_expect_success 'stdin -z fails on leading whitespace' ' + printf $F " create $a" "$m" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: whitespace before command: create $a" err +' + +test_expect_success 'stdin -z fails on unknown command' ' + printf $F "unknown $a" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: unknown command: unknown $a" err +' + +test_expect_success 'stdin -z fails create with no ref' ' + printf $F "create " >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: create line 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 && + grep "fatal: create $a missing <newvalue>" err +' + +test_expect_success 'stdin -z fails create with too many arguments' ' + printf $F "create $a" "$m" "$m" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: unknown command: $m" err +' + +test_expect_success 'stdin -z fails update with no ref' ' + printf $F "update " >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: update line missing <ref>" 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 fails update with no new value' ' + printf $F "update $a" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: update $a missing <newvalue>" err +' + +test_expect_success 'stdin -z fails update with no old value' ' + printf $F "update $a" "$m" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: update $a missing \\[<oldvalue>\\] NUL" err +' + +test_expect_success 'stdin -z fails update with too many arguments' ' + printf $F "update $a" "$m" "$m" "$m" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: unknown command: $m" err +' + +test_expect_success 'stdin -z fails delete with no ref' ' + printf $F "delete " >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: delete line 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 && + grep "fatal: delete $a missing \\[<oldvalue>\\] NUL" err +' + +test_expect_success 'stdin -z fails delete with too many arguments' ' + printf $F "delete $a" "$m" "$m" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: unknown command: $m" err +' + +test_expect_success 'stdin -z fails verify with too many arguments' ' + printf $F "verify $a" "$m" "$m" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: unknown command: $m" err +' + +test_expect_success 'stdin -z fails verify with no old value' ' + printf $F "verify $a" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: verify $a missing \\[<oldvalue>\\] NUL" err +' + +test_expect_success 'stdin -z fails option with unknown name' ' + printf $F "option unknown" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: option unknown: unknown" err +' + +test_expect_success 'stdin -z fails with duplicate refs' ' + printf $F "create $a" "$m" "create $b" "$m" "create $a" "$m" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: Multiple updates for ref '"'"'$a'"'"' not allowed." err +' + +test_expect_success 'stdin -z create ref works' ' + printf $F "create $a" "$m" >stdin && + git update-ref -z --stdin <stdin && + git rev-parse $m >expect && + git rev-parse $a >actual && + test_cmp expect actual +' + +test_expect_success 'stdin -z update ref creates with zero old value' ' + printf $F "update $b" "$m" "$Z" >stdin && + git update-ref -z --stdin <stdin && + git rev-parse $m >expect && + git rev-parse $b >actual && + test_cmp expect actual && + git update-ref -d $b +' + +test_expect_success 'stdin -z update ref creates with empty old value' ' + printf $F "update $b" "$m" "" >stdin && + git update-ref -z --stdin <stdin && + git rev-parse $m >expect && + git rev-parse $b >actual && + test_cmp expect actual +' + +test_expect_success 'stdin -z create ref works with path with space to blob' ' + printf $F "create refs/blobs/pws" "$m:$pws" >stdin && + git update-ref -z --stdin <stdin && + git rev-parse "$m:$pws" >expect && + git rev-parse refs/blobs/pws >actual && + test_cmp expect actual && + git update-ref -d refs/blobs/pws +' + +test_expect_success 'stdin -z update ref fails with wrong old value' ' + printf $F "update $c" "$m" "$m~1" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err && + test_must_fail git rev-parse --verify -q $c +' + +test_expect_success 'stdin -z update ref fails with bad old value' ' + printf $F "update $c" "$m" "does-not-exist" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: invalid old value for ref $c: does-not-exist" err && + test_must_fail git rev-parse --verify -q $c +' + +test_expect_success 'stdin -z create ref fails with bad new value' ' + printf $F "create $c" "does-not-exist" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: invalid new value for ref $c: does-not-exist" err && + test_must_fail git rev-parse --verify -q $c +' + +test_expect_success 'stdin -z create ref fails with zero new value' ' + printf $F "create $c" "" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: create $c given zero new value" err && + test_must_fail git rev-parse --verify -q $c +' + +test_expect_success 'stdin -z update ref works with right old value' ' + printf $F "update $b" "$m~1" "$m" >stdin && + git update-ref -z --stdin <stdin && + git rev-parse $m~1 >expect && + git rev-parse $b >actual && + test_cmp expect actual +' + +test_expect_success 'stdin -z delete ref fails with wrong old value' ' + printf $F "delete $a" "$m~1" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: Cannot lock the ref '"'"'$a'"'"'" err && + git rev-parse $m >expect && + git rev-parse $a >actual && + test_cmp expect actual +' + +test_expect_success 'stdin -z delete ref fails with zero old value' ' + printf $F "delete $a" "$Z" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: delete $a given zero old value" err && + git rev-parse $m >expect && + git rev-parse $a >actual && + test_cmp expect actual +' + +test_expect_success 'stdin -z update symref works option no-deref' ' + git symbolic-ref TESTSYMREF $b && + printf $F "option no-deref" "update TESTSYMREF" "$a" "$b" >stdin && + git update-ref -z --stdin <stdin && + git rev-parse TESTSYMREF >expect && + git rev-parse $a >actual && + test_cmp expect actual && + git rev-parse $m~1 >expect && + git rev-parse $b >actual && + test_cmp expect actual +' + +test_expect_success 'stdin -z delete symref works option no-deref' ' + git symbolic-ref TESTSYMREF $b && + printf $F "option no-deref" "delete TESTSYMREF" "$b" >stdin && + git update-ref -z --stdin <stdin && + test_must_fail git rev-parse --verify -q TESTSYMREF && + git rev-parse $m~1 >expect && + git rev-parse $b >actual && + test_cmp expect actual +' + +test_expect_success 'stdin -z delete ref works with right old value' ' + printf $F "delete $b" "$m~1" >stdin && + git update-ref -z --stdin <stdin && + test_must_fail git rev-parse --verify -q $b +' + +test_expect_success 'stdin -z update/create/verify combination works' ' + printf $F "update $a" "$m" "" "create $b" "$m" "verify $c" "" >stdin && + git update-ref -z --stdin <stdin && + git rev-parse $m >expect && + git rev-parse $a >actual && + test_cmp expect actual && + git rev-parse $b >actual && + test_cmp expect actual && + test_must_fail git rev-parse --verify -q $c +' + +test_expect_success 'stdin -z update refs works with identity updates' ' + printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$Z" "" >stdin && + git update-ref -z --stdin <stdin && + git rev-parse $m >expect && + git rev-parse $a >actual && + test_cmp expect actual && + git rev-parse $b >actual && + test_cmp expect actual && + test_must_fail git rev-parse --verify -q $c +' + +test_expect_success 'stdin -z update refs fails with wrong old value' ' + git update-ref $c $m && + printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "" "$Z" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err && + git rev-parse $m >expect && + git rev-parse $a >actual && + test_cmp expect actual && + git rev-parse $b >actual && + test_cmp expect actual && + git rev-parse $c >actual && + test_cmp expect actual +' + +test_expect_success 'stdin -z delete refs works with packed and loose refs' ' + git pack-refs --all && + git update-ref $c $m~1 && + printf $F "delete $a" "$m" "update $b" "$Z" "$m" "update $c" "" "$m~1" >stdin && + git update-ref -z --stdin <stdin && + test_must_fail git rev-parse --verify -q $a && + test_must_fail git rev-parse --verify -q $b && + test_must_fail git rev-parse --verify -q $c +' + test_done diff --git a/t/t1411-reflog-show.sh b/t/t1411-reflog-show.sh index 9a105fe21f..6f47c0dd0e 100755 --- a/t/t1411-reflog-show.sh +++ b/t/t1411-reflog-show.sh @@ -144,4 +144,26 @@ test_expect_success 'empty reflog file' ' test_cmp expect actual ' +# This guards against the alternative of showing the diffs vs. the +# reflog ancestor. The reflog used is designed to list the commits +# more than once, so as to exercise the corresponding logic. +test_expect_success 'git log -g -p shows diffs vs. parents' ' + test_commit two && + git branch flipflop && + git update-ref refs/heads/flipflop -m flip1 HEAD^ && + git update-ref refs/heads/flipflop -m flop1 HEAD && + git update-ref refs/heads/flipflop -m flip2 HEAD^ && + git log -g -p flipflop >reflog && + grep -v ^Reflog reflog >actual && + git log -1 -p HEAD^ >log.one && + git log -1 -p HEAD >log.two && + ( + cat log.one; echo + cat log.two; echo + cat log.one; echo + cat log.two + ) >expect && + test_cmp expect actual +' + test_done diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index d730734fde..8c739c9613 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -142,6 +142,20 @@ test_expect_success '> in name is reported' ' grep "error in commit $new" out ' +# date is 2^64 + 1 +test_expect_success 'integer overflow in timestamps is reported' ' + git cat-file commit HEAD >basis && + sed "s/^\\(author .*>\\) [0-9]*/\\1 18446744073709551617/" \ + <basis >bad-timestamp && + new=$(git hash-object -t commit -w --stdin <bad-timestamp) && + test_when_finished "remove_object $new" && + git update-ref refs/heads/bogus "$new" && + test_when_finished "git update-ref -d refs/heads/bogus" && + git fsck 2>out && + cat out && + grep "error in commit $new.*integer overflow" out +' + test_expect_success 'tag pointing to nonexistent' ' cat >invalid-tag <<-\EOF && object ffffffffffffffffffffffffffffffffffffffff diff --git a/t/t1502-rev-parse-parseopt.sh b/t/t1502-rev-parse-parseopt.sh index 13c88c9aae..83b1300cef 100755 --- a/t/t1502-rev-parse-parseopt.sh +++ b/t/t1502-rev-parse-parseopt.sh @@ -12,9 +12,11 @@ usage: some-command [options] <args>... -h, --help show the help --foo some nifty option --foo --bar ... some cool option --bar with an argument + -b, --baz a short and long option An option group Header -C[...] option C with an optional argument + -d, --data[=...] short and long option with an optional argument Extras --extra1 line above used to cause a segfault but no longer does @@ -31,9 +33,11 @@ h,help show the help foo some nifty option --foo bar= some cool option --bar with an argument +b,baz a short and long option An option group Header C? option C with an optional argument +d,data? short and long option with an optional argument Extras extra1 line above used to cause a segfault but no longer does @@ -45,16 +49,16 @@ test_expect_success 'test --parseopt help output' ' ' cat > expect <<EOF -set -- --foo --bar 'ham' -- 'arg' +set -- --foo --bar 'ham' -b -- 'arg' EOF test_expect_success 'test --parseopt' ' - git rev-parse --parseopt -- --foo --bar=ham arg < optionspec > output && + git rev-parse --parseopt -- --foo --bar=ham --baz arg < optionspec > output && test_cmp expect output ' test_expect_success 'test --parseopt with mixed options and arguments' ' - git rev-parse --parseopt -- --foo arg --bar=ham < optionspec > output && + git rev-parse --parseopt -- --foo arg --bar=ham --baz < optionspec > output && test_cmp expect output ' @@ -99,4 +103,36 @@ test_expect_success 'test --parseopt --keep-dashdash --stop-at-non-option withou test_cmp expect output ' +cat > expect <<EOF +set -- --foo --bar='z' --baz -C'Z' --data='A' -- 'arg' +EOF + +test_expect_success 'test --parseopt --stuck-long' ' + git rev-parse --parseopt --stuck-long -- --foo --bar=z -b arg -CZ -dA <optionspec >output && + test_cmp expect output +' + +cat > expect <<EOF +set -- --data='' -C --baz -- 'arg' +EOF + +test_expect_success 'test --parseopt --stuck-long and empty optional argument' ' + git rev-parse --parseopt --stuck-long -- --data= arg -C -b <optionspec >output && + test_cmp expect output +' + +cat > expect <<EOF +set -- --data --baz -- 'arg' +EOF + +test_expect_success 'test --parseopt --stuck-long and long option with unset optional argument' ' + git rev-parse --parseopt --stuck-long -- --data arg -b <optionspec >output && + test_cmp expect output +' + +test_expect_success 'test --parseopt --stuck-long and short option with unset optional argument' ' + git rev-parse --parseopt --stuck-long -- -d arg -b <optionspec >output && + test_cmp expect output +' + test_done diff --git a/t/t1506-rev-parse-diagnosis.sh b/t/t1506-rev-parse-diagnosis.sh index f950c10128..613d9bfe1b 100755 --- a/t/t1506-rev-parse-diagnosis.sh +++ b/t/t1506-rev-parse-diagnosis.sh @@ -196,4 +196,28 @@ test_expect_success 'dotdot is not an empty set' ' test_cmp expect actual ' +test_expect_success 'arg before dashdash must be a revision (missing)' ' + test_must_fail git rev-parse foobar -- 2>stderr && + test_i18ngrep "bad revision" stderr +' + +test_expect_success 'arg before dashdash must be a revision (file)' ' + >foobar && + test_must_fail git rev-parse foobar -- 2>stderr && + test_i18ngrep "bad revision" stderr +' + +test_expect_success 'arg before dashdash must be a revision (ambiguous)' ' + >foobar && + git update-ref refs/heads/foobar HEAD && + { + # we do not want to use rev-parse here, because + # we are testing it + cat .git/refs/heads/foobar && + printf "%s\n" -- + } >expect && + git rev-parse foobar -- >actual && + test_cmp expect actual +' + test_done diff --git a/t/t1507-rev-parse-upstream.sh b/t/t1507-rev-parse-upstream.sh index 2a19e797eb..178694ee63 100755 --- a/t/t1507-rev-parse-upstream.sh +++ b/t/t1507-rev-parse-upstream.sh @@ -17,6 +17,9 @@ test_expect_success 'setup' ' test_commit 4 && git branch --track my-side origin/side && git branch --track local-master master && + git branch --track fun@ny origin/side && + git branch --track @funny origin/side && + git branch --track funny@ origin/side && git remote add -t master master-only .. && git fetch master-only && git branch bad-upstream && @@ -54,6 +57,24 @@ test_expect_success 'my-side@{upstream} resolves to correct full name' ' test refs/remotes/origin/side = "$(full_name my-side@{u})" ' +test_expect_success 'upstream of branch with @ in middle' ' + full_name fun@ny@{u} >actual && + echo refs/remotes/origin/side >expect && + test_cmp expect actual +' + +test_expect_success 'upstream of branch with @ at start' ' + full_name @funny@{u} >actual && + echo refs/remotes/origin/side >expect && + test_cmp expect actual +' + +test_expect_success 'upstream of branch with @ at end' ' + full_name funny@@{u} >actual && + echo refs/remotes/origin/side >expect && + test_cmp expect actual +' + test_expect_success 'refs/heads/my-side@{upstream} does not resolve to my-side{upstream}' ' test_must_fail full_name refs/heads/my-side@{upstream} ' @@ -210,4 +231,20 @@ test_expect_success 'log -g other@{u}@{now}' ' test_cmp expect actual ' +test_expect_success '@{reflog}-parsing does not look beyond colon' ' + echo content >@{yesterday} && + git add @{yesterday} && + git commit -m "funny reflog file" && + git hash-object @{yesterday} >expect && + git rev-parse HEAD:@{yesterday} >actual +' + +test_expect_success '@{upstream}-parsing does not look beyond colon' ' + echo content >@{upstream} && + git add @{upstream} && + git commit -m "funny upstream file" && + git hash-object @{upstream} >expect && + git rev-parse HEAD:@{upstream} >actual +' + test_done diff --git a/t/t1508-at-combinations.sh b/t/t1508-at-combinations.sh index e5aea3b896..078e1195df 100755 --- a/t/t1508-at-combinations.sh +++ b/t/t1508-at-combinations.sh @@ -9,8 +9,11 @@ check() { if test '$2' = 'commit' then git log -1 --format=%s '$1' >actual - else + elif test '$2' = 'ref' + then git rev-parse --symbolic-full-name '$1' >actual + else + git cat-file -p '$1' >actual fi && test_cmp expect actual " @@ -32,6 +35,9 @@ test_expect_success 'setup' ' git checkout -b upstream-branch && test_commit upstream-one && test_commit upstream-two && + git checkout -b @/at-test && + git checkout -b @@/at-test && + git checkout -b @at-test && git checkout -b old-branch && test_commit old-one && test_commit old-two && @@ -55,6 +61,11 @@ check "HEAD@{u}" ref refs/heads/upstream-branch check "@{u}@{1}" commit upstream-one check "@{-1}@{u}" ref refs/heads/master check "@{-1}@{u}@{1}" commit master-one +check "@" commit new-two +check "@@{u}" ref refs/heads/upstream-branch +check "@@/at-test" ref refs/heads/@@/at-test +check "@/at-test" ref refs/heads/@/at-test +check "@at-test" ref refs/heads/@at-test nonsense "@{u}@{-1}" nonsense "@{0}@{0}" nonsense "@{1}@{u}" @@ -74,4 +85,14 @@ check HEAD ref refs/heads/old-branch check "HEAD@{1}" commit new-two check "@{1}" commit old-one +test_expect_success 'create path with @' ' + echo content >normal && + echo content >fun@ny && + git add normal fun@ny && + git commit -m "funny path" +' + +check "@:normal" blob content +check "@:fun@ny" blob content + test_done diff --git a/t/t1510-repo-setup.sh b/t/t1510-repo-setup.sh index cf2ee7885a..e1b2a99f10 100755 --- a/t/t1510-repo-setup.sh +++ b/t/t1510-repo-setup.sh @@ -777,9 +777,7 @@ test_expect_success '#30: core.worktree and core.bare conflict (gitfile version) setup_repo 30 "$here/30" gitfile true && ( cd 30 && - GIT_DIR=.git && - export GIT_DIR && - test_must_fail git symbolic-ref HEAD 2>result + test_must_fail env GIT_DIR=.git git symbolic-ref HEAD 2>result ) && grep "core.bare and core.worktree" 30/result ' diff --git a/t/t1511-rev-parse-caret.sh b/t/t1511-rev-parse-caret.sh index eaefc777bd..15973f2094 100755 --- a/t/t1511-rev-parse-caret.sh +++ b/t/t1511-rev-parse-caret.sh @@ -54,6 +54,13 @@ test_expect_success 'ref^{tree}' ' test_must_fail git rev-parse blob-tag^{tree} ' +test_expect_success 'ref^{tag}' ' + test_must_fail git rev-parse HEAD^{tag} && + git rev-parse commit-tag >expected && + git rev-parse commit-tag^{tag} >actual && + test_cmp expected actual +' + test_expect_success 'ref^{/.}' ' git rev-parse master >expected && git rev-parse master^{/.} >actual && diff --git a/t/t1600-index.sh b/t/t1600-index.sh new file mode 100755 index 0000000000..079d241145 --- /dev/null +++ b/t/t1600-index.sh @@ -0,0 +1,76 @@ +#!/bin/sh + +test_description='index file specific tests' + +. ./test-lib.sh + +test_expect_success 'setup' ' + echo 1 >a +' + +test_expect_success 'bogus GIT_INDEX_VERSION issues warning' ' + ( + rm -f .git/index && + GIT_INDEX_VERSION=2bogus && + export GIT_INDEX_VERSION && + git add a 2>&1 | sed "s/[0-9]//" >actual.err && + sed -e "s/ Z$/ /" <<-\EOF >expect.err && + warning: GIT_INDEX_VERSION set, but the value is invalid. + Using version Z + EOF + test_i18ncmp expect.err actual.err + ) +' + +test_expect_success 'out of bounds GIT_INDEX_VERSION issues warning' ' + ( + rm -f .git/index && + GIT_INDEX_VERSION=1 && + export GIT_INDEX_VERSION && + git add a 2>&1 | sed "s/[0-9]//" >actual.err && + sed -e "s/ Z$/ /" <<-\EOF >expect.err && + warning: GIT_INDEX_VERSION set, but the value is invalid. + Using version Z + EOF + test_i18ncmp expect.err actual.err + ) +' + +test_expect_success 'no warning with bogus GIT_INDEX_VERSION and existing index' ' + ( + GIT_INDEX_VERSION=1 && + export GIT_INDEX_VERSION && + git add a 2>actual.err && + >expect.err && + test_i18ncmp expect.err actual.err + ) +' + +test_expect_success 'out of bounds index.version issues warning' ' + ( + sane_unset GIT_INDEX_VERSION && + rm -f .git/index && + git config --add index.version 1 && + git add a 2>&1 | sed "s/[0-9]//" >actual.err && + sed -e "s/ Z$/ /" <<-\EOF >expect.err && + warning: index.version set, but the value is invalid. + Using version Z + EOF + test_i18ncmp expect.err actual.err + ) +' + +test_expect_success 'GIT_INDEX_VERSION takes precedence over config' ' + ( + rm -f .git/index && + GIT_INDEX_VERSION=4 && + export GIT_INDEX_VERSION && + git config --add index.version 2 && + git add a 2>&1 && + echo 4 >expect && + test-index-version <.git/index >actual && + test_cmp expect actual + ) +' + +test_done diff --git a/t/t2008-checkout-subdir.sh b/t/t2008-checkout-subdir.sh index 3e098ab31e..eadb9434ae 100755 --- a/t/t2008-checkout-subdir.sh +++ b/t/t2008-checkout-subdir.sh @@ -58,13 +58,13 @@ test_expect_success 'checkout with simple prefix' ' ' -# This is not expected to work as ls-files was not designed -# to deal with such. Enable it when ls-files is updated. -: test_expect_success 'checkout with complex relative path' ' - - rm file1 && - git checkout HEAD -- ../dir1/../dir1/file1 && test -f ./file1 - +test_expect_success 'checkout with complex relative path' ' + ( + cd dir1 && + rm file1 && + git checkout HEAD -- ../dir1/../dir1/file1 && + test "hello" = "$(cat file1)" + ) ' test_expect_success 'relative path outside tree should fail' \ diff --git a/t/t2010-checkout-ambiguous.sh b/t/t2010-checkout-ambiguous.sh index 7cc0a3582e..87bdf9c96b 100755 --- a/t/t2010-checkout-ambiguous.sh +++ b/t/t2010-checkout-ambiguous.sh @@ -47,4 +47,10 @@ test_expect_success 'disambiguate checking out from a tree-ish' ' git diff --exit-code --quiet ' +test_expect_success 'accurate error message with more than one ref' ' + test_must_fail git checkout HEAD master -- 2>actual && + grep 2 actual && + test_i18ngrep "one reference expected, 2 given" actual +' + test_done diff --git a/t/t2024-checkout-dwim.sh b/t/t2024-checkout-dwim.sh index dee55e428f..6ecb559465 100755 --- a/t/t2024-checkout-dwim.sh +++ b/t/t2024-checkout-dwim.sh @@ -104,7 +104,7 @@ test_expect_success 'setup more remotes with unconventional refspecs' ' cd repo_c && test_commit c_master && git checkout -b bar && - test_commit c_bar + test_commit c_bar && git checkout -b spam && test_commit c_spam ) && @@ -113,9 +113,9 @@ test_expect_success 'setup more remotes with unconventional refspecs' ' cd repo_d && test_commit d_master && git checkout -b baz && - test_commit f_baz + test_commit d_baz && git checkout -b eggs && - test_commit c_eggs + test_commit d_eggs ) && git remote add repo_c repo_c && git config remote.repo_c.fetch \ @@ -164,4 +164,25 @@ test_expect_success 'checkout of branch from a single remote succeeds #4' ' test_branch_upstream eggs repo_d eggs ' +test_expect_success 'checkout of branch with a file having the same name fails' ' + git checkout -B master && + test_might_fail git branch -D spam && + + >spam && + test_must_fail git checkout spam && + test_must_fail git rev-parse --verify refs/heads/spam && + test_branch master +' + +test_expect_success 'checkout <branch> -- succeeds, even if a file with the same name exists' ' + git checkout -B master && + test_might_fail git branch -D spam && + + >spam && + git checkout spam -- && + test_branch spam && + test_cmp_rev refs/remotes/extra_dir/repo_c/extra_dir/spam HEAD && + test_branch_upstream spam repo_c spam +' + test_done diff --git a/t/t2104-update-index-skip-worktree.sh b/t/t2104-update-index-skip-worktree.sh index 1d0879be06..29c1fb10ca 100755 --- a/t/t2104-update-index-skip-worktree.sh +++ b/t/t2104-update-index-skip-worktree.sh @@ -7,6 +7,8 @@ test_description='skip-worktree bit test' . ./test-lib.sh +test_set_index_version 3 + cat >expect.full <<EOF H 1 H 2 diff --git a/t/t2200-add-update.sh b/t/t2200-add-update.sh index 9bf2bdffd2..e16b15d3e5 100755 --- a/t/t2200-add-update.sh +++ b/t/t2200-add-update.sh @@ -80,18 +80,13 @@ test_expect_success 'change gets noticed' ' ' -# Note that this is scheduled to change in Git 2.0, when -# "git add -u" will become full-tree by default. -test_expect_success 'non-limited update in subdir leaves root alone' ' +test_expect_success 'non-qualified update in subdir updates from the root' ' ( cd dir1 && echo even more >>sub2 && git add -u ) && - cat >expect <<-\EOF && - check - top - EOF + : >expect && git diff-files --name-only >actual && test_cmp expect actual ' diff --git a/t/t3004-ls-files-basic.sh b/t/t3004-ls-files-basic.sh index 8d9bc3c2af..9c7adbdbe1 100755 --- a/t/t3004-ls-files-basic.sh +++ b/t/t3004-ls-files-basic.sh @@ -36,4 +36,21 @@ test_expect_success 'ls-files -h in corrupt repository' ' test_i18ngrep "[Uu]sage: git ls-files " broken/usage ' +test_expect_success SYMLINKS 'ls-files with absolute paths to symlinks' ' + mkdir subs && + ln -s nosuch link && + ln -s ../nosuch subs/link && + git add link subs/link && + git ls-files -s link subs/link >expect && + git ls-files -s "$(pwd)/link" "$(pwd)/subs/link" >actual && + test_cmp expect actual && + + ( + cd subs && + git ls-files -s link >../expect && + git ls-files -s "$(pwd)/link" >../actual + ) && + test_cmp expect actual +' + test_done diff --git a/t/t3010-ls-files-killed-modified.sh b/t/t3010-ls-files-killed-modified.sh index f611d799b6..6d3b828a95 100755 --- a/t/t3010-ls-files-killed-modified.sh +++ b/t/t3010-ls-files-killed-modified.sh @@ -11,6 +11,7 @@ This test prepares the following in the cache: path1 - a symlink path2/file2 - a file in a directory path3/file3 - a file in a directory + pathx/ju - a file in a directory submod1/ - a submodule submod2/ - another submodule @@ -23,6 +24,7 @@ and the following on the filesystem: path4 - a file path5 - a symlink path6/file6 - a file in a directory + pathx/ju/nk - a file in a directory to be killed submod1/ - a submodule (modified from the cache) submod2/ - a submodule (matches the cache) @@ -44,14 +46,15 @@ modified without reporting path9 and path10. submod1 is also modified. test_expect_success 'git update-index --add to add various paths.' ' date >path0 && test_ln_s_add xyzzy path1 && - mkdir path2 path3 && + mkdir path2 path3 pathx && date >path2/file2 && date >path3/file3 && + >pathx/ju && : >path7 && date >path8 && : >path9 && date >path10 && - git update-index --add -- path0 path?/file? path7 path8 path9 path10 && + git update-index --add -- path0 path?/file? pathx/ju path7 path8 path9 path10 && for i in 1 2 do git init submod$i && @@ -77,7 +80,7 @@ test_expect_success 'git ls-files -k to show killed files.' ' date >path3 && date >path5 fi && - mkdir path0 path1 path6 && + mkdir -p path0 path1 path6 pathx/ju && date >path0/file0 && date >path1/file1 && date >path6/file6 && @@ -85,16 +88,23 @@ test_expect_success 'git ls-files -k to show killed files.' ' : >path8 && : >path9 && touch path10 && - git ls-files -k >.output -' - -test_expect_success 'validate git ls-files -k output.' ' - cat >.expected <<-\EOF && + >pathx/ju/nk && + cat >.expected <<-\EOF path0/file0 path1/file1 path2 path3 + pathx/ju/nk EOF +' + +test_expect_success 'git ls-files -k output (w/o icase)' ' + git ls-files -k >.output + test_cmp .expected .output +' + +test_expect_success 'git ls-files -k output (w/ icase)' ' + git -c core.ignorecase=true ls-files -k >.output test_cmp .expected .output ' @@ -110,6 +120,7 @@ test_expect_success 'validate git ls-files -m output.' ' path3/file3 path7 path8 + pathx/ju submod1 EOF test_cmp .expected .output diff --git a/t/t3030-merge-recursive.sh b/t/t3030-merge-recursive.sh index 2f96100a5f..82e18548c3 100755 --- a/t/t3030-merge-recursive.sh +++ b/t/t3030-merge-recursive.sh @@ -257,6 +257,7 @@ test_expect_success 'setup 8' ' git add e && test_tick && git commit -m "rename a->e" && + c7=$(git rev-parse --verify HEAD) && git checkout rename-ln && git mv a e && test_ln_s_add e a && @@ -517,6 +518,52 @@ test_expect_success 'reset and bind merge' ' ' +test_expect_success 'merge-recursive w/ empty work tree - ours has rename' ' + ( + GIT_WORK_TREE="$PWD/ours-has-rename-work" && + export GIT_WORK_TREE && + GIT_INDEX_FILE="$PWD/ours-has-rename-index" && + export GIT_INDEX_FILE && + mkdir "$GIT_WORK_TREE" && + git read-tree -i -m $c7 && + git update-index --ignore-missing --refresh && + git merge-recursive $c0 -- $c7 $c3 && + git ls-files -s >actual-files + ) 2>actual-err && + >expected-err && + cat >expected-files <<-EOF && + 100644 $o3 0 b/c + 100644 $o0 0 c + 100644 $o0 0 d/e + 100644 $o0 0 e + EOF + test_cmp expected-files actual-files && + test_cmp expected-err actual-err +' + +test_expect_success 'merge-recursive w/ empty work tree - theirs has rename' ' + ( + GIT_WORK_TREE="$PWD/theirs-has-rename-work" && + export GIT_WORK_TREE && + GIT_INDEX_FILE="$PWD/theirs-has-rename-index" && + export GIT_INDEX_FILE && + mkdir "$GIT_WORK_TREE" && + git read-tree -i -m $c3 && + git update-index --ignore-missing --refresh && + git merge-recursive $c0 -- $c3 $c7 && + git ls-files -s >actual-files + ) 2>actual-err && + >expected-err && + cat >expected-files <<-EOF && + 100644 $o3 0 b/c + 100644 $o0 0 c + 100644 $o0 0 d/e + 100644 $o0 0 e + EOF + test_cmp expected-files actual-files && + test_cmp expected-err actual-err +' + test_expect_success 'merge removes empty directories' ' git reset --hard master && diff --git a/t/t3070-wildmatch.sh b/t/t3070-wildmatch.sh index 38446a0e87..ef509df351 100755 --- a/t/t3070-wildmatch.sh +++ b/t/t3070-wildmatch.sh @@ -14,19 +14,6 @@ match() { ! test-wildmatch wildmatch '$3' '$4' " fi - if [ $2 = 1 ]; then - test_expect_success "fnmatch: match '$3' '$4'" " - test-wildmatch fnmatch '$3' '$4' - " - elif [ $2 = 0 ]; then - test_expect_success "fnmatch: no match '$3' '$4'" " - ! test-wildmatch fnmatch '$3' '$4' - " -# else -# test_expect_success BROKEN_FNMATCH "fnmatch: '$3' '$4'" " -# ! test-wildmatch fnmatch '$3' '$4' -# " - fi } imatch() { diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh index 44ec6a45f4..ac31b711f2 100755 --- a/t/t3200-branch.sh +++ b/t/t3200-branch.sh @@ -14,10 +14,11 @@ test_expect_success 'prepare a trivial repository' ' echo World >>A && git update-index --add A && git commit -m "Second commit." && - HEAD=$(git rev-parse --verify HEAD)' + HEAD=$(git rev-parse --verify HEAD) +' test_expect_success 'git branch --help should not have created a bogus branch' ' - test_might_fail git branch --help </dev/null >/dev/null 2>/dev/null && + test_might_fail git branch --man --help </dev/null >/dev/null 2>&1 && test_path_is_missing .git/refs/heads/--help ' @@ -319,8 +320,9 @@ test_expect_success 'test tracking setup (non-wildcard, matching)' ' test_expect_success 'tracking setup fails on non-matching refspec' ' git config remote.local.url . && - git config remote.local.fetch refs/heads/s:refs/remotes/local/s && + git config remote.local.fetch refs/heads/*:refs/remotes/local/* && (git show-ref -q refs/remotes/local/master || git fetch local) && + git config remote.local.fetch refs/heads/s:refs/remotes/local/s && test_must_fail git branch --track my5 local/master && test_must_fail git config branch.my5.remote && test_must_fail git config branch.my5.merge @@ -350,7 +352,7 @@ test_expect_success 'test overriding tracking setup via --no-track' ' test_expect_success 'no tracking without .fetch entries' ' git config branch.autosetupmerge true && git branch my6 s && - git config branch.automsetupmerge false && + git config branch.autosetupmerge false && test -z "$(git config branch.my6.remote)" && test -z "$(git config branch.my6.merge)" ' @@ -424,14 +426,14 @@ test_expect_success '--set-upstream-to fails on a non-ref' ' test_expect_success 'use --set-upstream-to modify HEAD' ' test_config branch.master.remote foo && test_config branch.master.merge foo && - git branch my12 + git branch my12 && git branch --set-upstream-to my12 && test "$(git config branch.master.remote)" = "." && test "$(git config branch.master.merge)" = "refs/heads/my12" ' test_expect_success 'use --set-upstream-to modify a particular branch' ' - git branch my13 + git branch my13 && git branch --set-upstream-to master my13 && test "$(git config branch.my13.remote)" = "." && test "$(git config branch.my13.merge)" = "refs/heads/master" @@ -442,7 +444,7 @@ test_expect_success '--unset-upstream should fail if given a non-existent branch ' test_expect_success 'test --unset-upstream on HEAD' ' - git branch my14 + git branch my14 && test_config branch.master.remote foo && test_config branch.master.merge foo && git branch --set-upstream-to my14 && @@ -464,7 +466,7 @@ test_expect_success '--unset-upstream should fail on detached HEAD' ' ' test_expect_success 'test --unset-upstream on a particular branch' ' - git branch my15 + git branch my15 && git branch --set-upstream-to master my14 && git branch --unset-upstream my14 && test_must_fail git config branch.my14.remote && @@ -505,6 +507,16 @@ EOF test_cmp expected actual ' +test_expect_success '--set-upstream-to notices an error to set branch as own upstream' ' + git branch --set-upstream-to refs/heads/my13 my13 2>actual && + cat >expected <<-\EOF && + warning: Not setting branch my13 as its own upstream. + EOF + test_expect_code 1 git config branch.my13.remote && + test_expect_code 1 git config branch.my13.merge && + test_i18ncmp expected actual +' + # Keep this test last, as it changes the current branch cat >expect <<EOF $_z40 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master @@ -847,11 +859,7 @@ test_expect_success 'detect typo in branch name when using --edit-description' ' write_script editor <<-\EOF && echo "New contents" >"$1" EOF - ( - EDITOR=./editor && - export EDITOR && - test_must_fail git branch --edit-description no-such-branch - ) + test_must_fail env EDITOR=./editor git branch --edit-description no-such-branch ' test_expect_success 'refuse --edit-description on unborn branch for now' ' @@ -859,15 +867,46 @@ test_expect_success 'refuse --edit-description on unborn branch for now' ' echo "New contents" >"$1" EOF git checkout --orphan unborn && - ( - EDITOR=./editor && - export EDITOR && - test_must_fail git branch --edit-description - ) + test_must_fail env EDITOR=./editor git branch --edit-description ' test_expect_success '--merged catches invalid object names' ' test_must_fail git branch --merged 0000000000000000000000000000000000000000 ' +test_expect_success 'tracking with unexpected .fetch refspec' ' + rm -rf a b c d && + git init a && + ( + cd a && + test_commit a + ) && + git init b && + ( + cd b && + test_commit b + ) && + git init c && + ( + cd c && + test_commit c && + git remote add a ../a && + git remote add b ../b && + git fetch --all + ) && + git init d && + ( + cd d && + git remote add c ../c && + git config remote.c.fetch "+refs/remotes/*:refs/remotes/*" && + git fetch c && + git branch --track local/a/master remotes/a/master && + test "$(git config branch.local/a/master.remote)" = "c" && + test "$(git config branch.local/a/master.merge)" = "refs/remotes/a/master" && + git rev-parse --verify a >expect && + git rev-parse --verify local/a/master >actual && + test_cmp expect actual + ) +' + test_done diff --git a/t/t3300-funny-names.sh b/t/t3300-funny-names.sh index 7480d6e7c2..9a146f1335 100755 --- a/t/t3300-funny-names.sh +++ b/t/t3300-funny-names.sh @@ -69,7 +69,7 @@ test_expect_success 'ls-files -z does not quote funny filename' ' tabs ," (dq) and spaces EOF git ls-files -z >ls-files.z && - "$PERL_PATH" -pe "y/\000/\012/" <ls-files.z >current && + perl -pe "y/\000/\012/" <ls-files.z >current && test_cmp expected current ' @@ -106,7 +106,7 @@ test_expect_success 'diff-index -z does not quote funny filename' ' tabs ," (dq) and spaces EOF git diff-index -z --name-status $t0 >diff-index.z && - "$PERL_PATH" -pe "y/\000/\012/" <diff-index.z >current && + perl -pe "y/\000/\012/" <diff-index.z >current && test_cmp expected current ' @@ -116,7 +116,7 @@ test_expect_success 'diff-tree -z does not quote funny filename' ' tabs ," (dq) and spaces EOF git diff-tree -z --name-status $t0 $t1 >diff-tree.z && - "$PERL_PATH" -pe y/\\000/\\012/ <diff-tree.z >current && + perl -pe y/\\000/\\012/ <diff-tree.z >current && test_cmp expected current ' diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh index 16de05aff9..cfd67ff3df 100755 --- a/t/t3301-notes.sh +++ b/t/t3301-notes.sh @@ -17,7 +17,7 @@ GIT_EDITOR=./fake_editor.sh export GIT_EDITOR test_expect_success 'cannot annotate non-existing HEAD' ' - (MSG=3 && export MSG && test_must_fail git notes add) + test_must_fail env MSG=3 git notes add ' test_expect_success setup ' @@ -32,22 +32,16 @@ test_expect_success setup ' ' test_expect_success 'need valid notes ref' ' - (MSG=1 GIT_NOTES_REF=/ && export MSG GIT_NOTES_REF && - test_must_fail git notes add) && - (MSG=2 GIT_NOTES_REF=/ && export MSG GIT_NOTES_REF && - test_must_fail git notes show) + test_must_fail env MSG=1 GIT_NOTES_REF=/ git notes show && + test_must_fail env MSG=2 GIT_NOTES_REF=/ git notes show ' test_expect_success 'refusing to add notes in refs/heads/' ' - (MSG=1 GIT_NOTES_REF=refs/heads/bogus && - export MSG GIT_NOTES_REF && - test_must_fail git notes add) + test_must_fail env MSG=1 GIT_NOTES_REF=refs/heads/bogus git notes add ' test_expect_success 'refusing to edit notes in refs/remotes/' ' - (MSG=1 GIT_NOTES_REF=refs/remotes/bogus && - export MSG GIT_NOTES_REF && - test_must_fail git notes edit) + test_must_fail env MSG=1 GIT_NOTES_REF=refs/heads/bogus git notes edit ' # 1 indicates caught gracefully by die, 128 means git-show barked @@ -812,6 +806,33 @@ test_expect_success 'create note from non-existing note with "git notes add -C" test_must_fail git notes list HEAD ' +test_expect_success 'create note from non-blob with "git notes add -C" fails' ' + commit=$(git rev-parse --verify HEAD) && + tree=$(git rev-parse --verify HEAD:) && + test_must_fail git notes add -C $commit && + test_must_fail git notes add -C $tree && + 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 + +Notes (other): + This is a blob object +EOF + +test_expect_success 'create note from blob with "git notes add -C" reuses blob id' ' + blob=$(echo "This is a blob object" | git hash-object -w --stdin) && + git notes add -C $blob && + 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> @@ -838,11 +859,7 @@ test_expect_success 'create note from non-existing note with "git notes add -c" git add a10 && test_tick && git commit -m 10th && - ( - MSG="yet another note" && - export MSG && - test_must_fail git notes add -c deadbeef - ) && + test_must_fail env MSG="yet another note" git notes add -c deadbeef && test_must_fail git notes list HEAD ' diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh index ebf93b0695..80e0a951ea 100755 --- a/t/t3400-rebase.sh +++ b/t/t3400-rebase.sh @@ -88,6 +88,23 @@ test_expect_success 'rebase from ambiguous branch name' ' git rebase master ' +test_expect_success 'rebase off of the previous branch using "-"' ' + git checkout master && + git checkout HEAD^ && + git rebase @{-1} >expect.messages && + git merge-base master HEAD >expect.forkpoint && + + git checkout master && + git checkout HEAD^ && + git rebase - >actual.messages && + git merge-base master HEAD >actual.forkpoint && + + test_cmp expect.forkpoint actual.forkpoint && + # the next one is dubious---we may want to say "-", + # instead of @{-1}, in the message + test_i18ncmp expect.messages actual.messages +' + test_expect_success 'rebase a single mode change' ' git checkout master && git branch -D topic && @@ -134,12 +151,22 @@ test_expect_success 'fail when upstream arg is missing and not configured' ' test_must_fail git rebase ' -test_expect_success 'default to @{upstream} when upstream arg is missing' ' +test_expect_success 'default to common base in @{upstream}s reflog if no upstream arg' ' + git checkout -b default-base master && git checkout -b default topic && git config branch.default.remote . && - git config branch.default.merge refs/heads/master && + git config branch.default.merge refs/heads/default-base && + git rebase && + git rev-parse --verify default-base >expect && + git rev-parse default~1 >actual && + test_cmp expect actual && + git checkout default-base && + git reset --hard HEAD^ && + git checkout default && git rebase && - test "$(git rev-parse default~1)" = "$(git rev-parse master)" + git rev-parse --verify default-base >expect && + git rev-parse default~1 >actual && + test_cmp expect actual ' test_expect_success 'rebase -q is quiet' ' diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index 49ccb38f88..c0023a5b4f 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -29,8 +29,6 @@ Initial setup: . "$TEST_DIRECTORY"/lib-rebase.sh -set_fake_editor - # WARNING: Modifications to the initial repository can change the SHA ID used # in the expect2 file for the 'stop on conflicting pick' test. @@ -72,6 +70,7 @@ export SHELL test_expect_success 'rebase -i with the exec command' ' git checkout master && ( + set_fake_editor && FAKE_LINES="1 exec_>touch-one 2 exec_>touch-two exec_false exec_>touch-three 3 4 exec_>\"touch-file__name_with_spaces\";_>touch-after-semicolon 5" && @@ -93,6 +92,7 @@ test_expect_success 'rebase -i with the exec command' ' test_expect_success 'rebase -i with the exec command runs from tree root' ' git checkout master && mkdir subdir && (cd subdir && + set_fake_editor && FAKE_LINES="1 exec_>touch-subdir" \ git rebase -i HEAD^ ) && @@ -102,11 +102,8 @@ test_expect_success 'rebase -i with the exec command runs from tree root' ' test_expect_success 'rebase -i with the exec command checks tree cleanness' ' git checkout master && - ( - FAKE_LINES="exec_echo_foo_>file1 1" && - export FAKE_LINES && - test_must_fail git rebase -i HEAD^ - ) && + set_fake_editor && + test_must_fail env FAKE_LINES="exec_echo_foo_>file1 1" git rebase -i HEAD^ && test_cmp_rev master^ HEAD && git reset --hard && git rebase --continue @@ -115,16 +112,15 @@ test_expect_success 'rebase -i with the exec command checks tree cleanness' ' test_expect_success 'rebase -i with exec of inexistent command' ' git checkout master && test_when_finished "git rebase --abort" && - ( - FAKE_LINES="exec_this-command-does-not-exist 1" && - export FAKE_LINES && - test_must_fail git rebase -i HEAD^ >actual 2>&1 - ) && + set_fake_editor && + test_must_fail env FAKE_LINES="exec_this-command-does-not-exist 1" \ + git rebase -i HEAD^ >actual 2>&1 && ! grep "Maybe git-rebase is broken" actual ' test_expect_success 'no changes are a nop' ' git checkout branch2 && + set_fake_editor && git rebase -i F && test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" && test $(git rev-parse I) = $(git rev-parse HEAD) @@ -134,6 +130,7 @@ test_expect_success 'test the [branch] option' ' git checkout -b dead-end && git rm file6 && git commit -m "stop here" && + set_fake_editor && git rebase -i F branch2 && test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch2" && test $(git rev-parse I) = $(git rev-parse branch2) && @@ -142,6 +139,7 @@ test_expect_success 'test the [branch] option' ' test_expect_success 'test --onto <branch>' ' git checkout -b test-onto branch2 && + set_fake_editor && git rebase -i --onto branch1 F && test "$(git symbolic-ref -q HEAD)" = "refs/heads/test-onto" && test $(git rev-parse HEAD^) = $(git rev-parse branch1) && @@ -151,6 +149,7 @@ test_expect_success 'test --onto <branch>' ' test_expect_success 'rebase on top of a non-conflicting commit' ' git checkout branch1 && git tag original-branch1 && + set_fake_editor && git rebase -i branch2 && test file6 = $(git diff --name-only original-branch1) && test "$(git symbolic-ref -q HEAD)" = "refs/heads/branch1" && @@ -163,6 +162,7 @@ test_expect_success 'reflog for the branch shows state before rebase' ' ' test_expect_success 'exchange two commits' ' + set_fake_editor && FAKE_LINES="2 1" git rebase -i HEAD~2 && test H = $(git cat-file commit HEAD^ | sed -ne \$p) && test G = $(git cat-file commit HEAD | sed -ne \$p) @@ -188,6 +188,7 @@ EOF test_expect_success 'stop on conflicting pick' ' git tag new-branch1 && + set_fake_editor && test_must_fail git rebase -i master && test "$(git rev-parse HEAD~3)" = "$(git rev-parse master)" && test_cmp expect .git/rebase-merge/patch && @@ -208,6 +209,7 @@ test_expect_success 'abort' ' test_expect_success 'abort with error when new base cannot be checked out' ' git rm --cached file1 && git commit -m "remove file in base" && + set_fake_editor && test_must_fail git rebase -i master > output 2>&1 && grep "The following untracked working tree files would be overwritten by checkout:" \ output && @@ -222,6 +224,7 @@ test_expect_success 'retain authorship' ' test_tick && GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" && git tag twerp && + set_fake_editor && git rebase -i --onto master HEAD^ && git show HEAD | grep "^Author: Twerp Snog" ' @@ -232,6 +235,7 @@ test_expect_success 'squash' ' test_tick && GIT_AUTHOR_NAME="Nitfol" git commit -m "nitfol" file7 && echo "******************************" && + set_fake_editor && FAKE_LINES="1 squash 2" EXPECT_HEADER_COUNT=2 \ git rebase -i --onto master HEAD~2 && test B = $(cat file7) && @@ -244,6 +248,7 @@ test_expect_success 'retain authorship when squashing' ' test_expect_success '-p handles "no changes" gracefully' ' HEAD=$(git rev-parse HEAD) && + set_fake_editor && git rebase -i -p HEAD^ && git update-index --refresh && git diff-files --quiet && @@ -253,6 +258,7 @@ test_expect_success '-p handles "no changes" gracefully' ' test_expect_failure 'exchange two commits with -p' ' git checkout H && + set_fake_editor && FAKE_LINES="2 1" git rebase -i -p HEAD~2 && test H = $(git cat-file commit HEAD^ | sed -ne \$p) && test G = $(git cat-file commit HEAD | sed -ne \$p) @@ -287,6 +293,7 @@ test_expect_success 'preserve merges with -p' ' git commit -m M file1 && git checkout -b to-be-rebased && test_tick && + set_fake_editor && git rebase -i -p --onto branch1 master && git update-index --refresh && git diff-files --quiet && @@ -301,6 +308,7 @@ test_expect_success 'preserve merges with -p' ' ' test_expect_success 'edit ancestor with -p' ' + set_fake_editor && FAKE_LINES="1 2 edit 3 4" git rebase -i -p HEAD~3 && echo 2 > unrelated-file && test_tick && @@ -314,6 +322,7 @@ test_expect_success 'edit ancestor with -p' ' test_expect_success '--continue tries to commit' ' test_tick && + set_fake_editor && test_must_fail git rebase -i --onto new-branch1 HEAD^ && echo resolved > file1 && git add file1 && @@ -325,6 +334,7 @@ test_expect_success '--continue tries to commit' ' test_expect_success 'verbose flag is heeded, even after --continue' ' git reset --hard master@{1} && test_tick && + set_fake_editor && test_must_fail git rebase -v -i --onto new-branch1 HEAD^ && echo resolved > file1 && git add file1 && @@ -334,6 +344,7 @@ test_expect_success 'verbose flag is heeded, even after --continue' ' test_expect_success 'multi-squash only fires up editor once' ' base=$(git rev-parse HEAD~4) && + set_fake_editor && FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 squash 2 squash 3 squash 4" \ EXPECT_HEADER_COUNT=4 \ git rebase -i $base && @@ -344,6 +355,7 @@ test_expect_success 'multi-squash only fires up editor once' ' test_expect_success 'multi-fixup does not fire up editor' ' git checkout -b multi-fixup E && base=$(git rev-parse HEAD~4) && + set_fake_editor && FAKE_COMMIT_AMEND="NEVER" FAKE_LINES="1 fixup 2 fixup 3 fixup 4" \ git rebase -i $base && test $base = $(git rev-parse HEAD^) && @@ -355,11 +367,8 @@ test_expect_success 'multi-fixup does not fire up editor' ' test_expect_success 'commit message used after conflict' ' git checkout -b conflict-fixup conflict-branch && base=$(git rev-parse HEAD~4) && - ( - FAKE_LINES="1 fixup 3 fixup 4" && - export FAKE_LINES && - test_must_fail git rebase -i $base - ) && + set_fake_editor && + test_must_fail env FAKE_LINES="1 fixup 3 fixup 4" git rebase -i $base && echo three > conflict && git add conflict && FAKE_COMMIT_AMEND="ONCE" EXPECT_HEADER_COUNT=2 \ @@ -373,11 +382,8 @@ test_expect_success 'commit message used after conflict' ' test_expect_success 'commit message retained after conflict' ' git checkout -b conflict-squash conflict-branch && base=$(git rev-parse HEAD~4) && - ( - FAKE_LINES="1 fixup 3 squash 4" && - export FAKE_LINES && - test_must_fail git rebase -i $base - ) && + set_fake_editor && + test_must_fail env FAKE_LINES="1 fixup 3 squash 4" git rebase -i $base && echo three > conflict && git add conflict && FAKE_COMMIT_AMEND="TWICE" EXPECT_HEADER_COUNT=2 \ @@ -399,6 +405,7 @@ EOF test_expect_success 'squash and fixup generate correct log messages' ' git checkout -b squash-fixup E && base=$(git rev-parse HEAD~4) && + set_fake_editor && FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="1 fixup 2 squash 3 fixup 4" \ EXPECT_HEADER_COUNT=4 \ git rebase -i $base && @@ -411,6 +418,7 @@ test_expect_success 'squash and fixup generate correct log messages' ' test_expect_success 'squash ignores comments' ' git checkout -b skip-comments E && base=$(git rev-parse HEAD~4) && + set_fake_editor && FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="# 1 # squash 2 # squash 3 # squash 4 #" \ EXPECT_HEADER_COUNT=4 \ git rebase -i $base && @@ -423,6 +431,7 @@ test_expect_success 'squash ignores comments' ' test_expect_success 'squash ignores blank lines' ' git checkout -b skip-blank-lines E && base=$(git rev-parse HEAD~4) && + set_fake_editor && FAKE_COMMIT_AMEND="ONCE" FAKE_LINES="> 1 > squash 2 > squash 3 > squash 4 >" \ EXPECT_HEADER_COUNT=4 \ git rebase -i $base && @@ -435,6 +444,7 @@ test_expect_success 'squash ignores blank lines' ' test_expect_success 'squash works as expected' ' git checkout -b squash-works no-conflict-branch && one=$(git rev-parse HEAD~3) && + set_fake_editor && FAKE_LINES="1 squash 3 2" EXPECT_HEADER_COUNT=2 \ git rebase -i HEAD~3 && test $one = $(git rev-parse HEAD~2) @@ -443,11 +453,8 @@ test_expect_success 'squash works as expected' ' test_expect_success 'interrupted squash works as expected' ' git checkout -b interrupted-squash conflict-branch && one=$(git rev-parse HEAD~3) && - ( - FAKE_LINES="1 squash 3 2" && - export FAKE_LINES && - test_must_fail git rebase -i HEAD~3 - ) && + set_fake_editor && + test_must_fail env FAKE_LINES="1 squash 3 2" git rebase -i HEAD~3 && (echo one; echo two; echo four) > conflict && git add conflict && test_must_fail git rebase --continue && @@ -460,11 +467,8 @@ test_expect_success 'interrupted squash works as expected' ' test_expect_success 'interrupted squash works as expected (case 2)' ' git checkout -b interrupted-squash2 conflict-branch && one=$(git rev-parse HEAD~3) && - ( - FAKE_LINES="3 squash 1 2" && - export FAKE_LINES && - test_must_fail git rebase -i HEAD~3 - ) && + set_fake_editor && + test_must_fail env FAKE_LINES="3 squash 1 2" git rebase -i HEAD~3 && (echo one; echo four) > conflict && git add conflict && test_must_fail git rebase --continue && @@ -484,6 +488,7 @@ test_expect_success '--continue tries to commit, even for "edit"' ' git commit -m "unrelated change" && parent=$(git rev-parse HEAD^) && test_tick && + set_fake_editor && FAKE_LINES="edit 1" git rebase -i HEAD^ && echo edited > file7 && git add file7 && @@ -496,20 +501,18 @@ test_expect_success '--continue tries to commit, even for "edit"' ' test_expect_success 'aborted --continue does not squash commits after "edit"' ' old=$(git rev-parse HEAD) && test_tick && + set_fake_editor && FAKE_LINES="edit 1" git rebase -i HEAD^ && echo "edited again" > file7 && git add file7 && - ( - FAKE_COMMIT_MESSAGE=" " && - export FAKE_COMMIT_MESSAGE && - test_must_fail git rebase --continue - ) && + test_must_fail env FAKE_COMMIT_MESSAGE=" " git rebase --continue && test $old = $(git rev-parse HEAD) && git rebase --abort ' test_expect_success 'auto-amend only edited commits after "edit"' ' test_tick && + set_fake_editor && FAKE_LINES="edit 1" git rebase -i HEAD^ && echo "edited again" > file7 && git add file7 && @@ -517,22 +520,15 @@ test_expect_success 'auto-amend only edited commits after "edit"' ' echo "and again" > file7 && git add file7 && test_tick && - ( - FAKE_COMMIT_MESSAGE="and again" && - export FAKE_COMMIT_MESSAGE && - test_must_fail git rebase --continue - ) && + test_must_fail env FAKE_COMMIT_MESSAGE="and again" git rebase --continue && git rebase --abort ' test_expect_success 'clean error after failed "exec"' ' test_tick && test_when_finished "git rebase --abort || :" && - ( - FAKE_LINES="1 exec_false" && - export FAKE_LINES && - test_must_fail git rebase -i HEAD^ - ) && + set_fake_editor && + test_must_fail env FAKE_LINES="1 exec_false" git rebase -i HEAD^ && echo "edited again" > file7 && git add file7 && test_must_fail git rebase --continue 2>error && @@ -543,6 +539,7 @@ test_expect_success 'rebase a detached HEAD' ' grandparent=$(git rev-parse HEAD~2) && git checkout $(git rev-parse HEAD) && test_tick && + set_fake_editor && FAKE_LINES="2 1" git rebase -i HEAD~2 && test $grandparent = $(git rev-parse HEAD~2) ' @@ -559,6 +556,7 @@ test_expect_success 'rebase a commit violating pre-commit' ' test_must_fail git commit -m doesnt-verify file1 && git commit -m doesnt-verify --no-verify file1 && test_tick && + set_fake_editor && FAKE_LINES=2 git rebase -i HEAD~2 ' @@ -580,6 +578,7 @@ test_expect_success 'rebase with a file named HEAD in worktree' ' git commit -m "Add body" ) && + set_fake_editor && FAKE_LINES="1 squash 2" git rebase -i to-be-rebased && test "$(git show -s --pretty=format:%an)" = "Squashed Away" @@ -591,6 +590,7 @@ test_expect_success 'do "noop" when there is nothing to cherry-pick' ' GIT_EDITOR=: git commit --amend \ --author="Somebody else <somebody@else.com>" && test $(git rev-parse branch3) != $(git rev-parse branch4) && + set_fake_editor && git rebase -i branch3 && test $(git rev-parse branch3) = $(git rev-parse branch4) @@ -615,10 +615,12 @@ test_expect_success 'submodule rebase setup' ' git commit -a -m "submodule second" ) && test_tick && + set_fake_editor && git commit -a -m "Three changes submodule" ' test_expect_success 'submodule rebase -i' ' + set_fake_editor && FAKE_LINES="1 squash 2 3" git rebase -i A ' @@ -636,6 +638,7 @@ test_expect_success 'submodule conflict setup' ' ' test_expect_success 'rebase -i continue with only submodule staged' ' + set_fake_editor && test_must_fail git rebase -i submodule-base && git add sub && git rebase --continue && @@ -645,6 +648,7 @@ test_expect_success 'rebase -i continue with only submodule staged' ' test_expect_success 'rebase -i continue with unstaged submodule' ' git checkout submodule-topic && git reset --hard && + set_fake_editor && test_must_fail git rebase -i submodule-base && git reset && git rebase --continue && @@ -657,6 +661,7 @@ test_expect_success 'avoid unnecessary reset' ' test-chmtime =123456789 file3 && git update-index --refresh && HEAD=$(git rev-parse HEAD) && + set_fake_editor && git rebase -i HEAD~4 && test $HEAD = $(git rev-parse HEAD) && MTIME=$(test-chmtime -v +0 file3 | sed 's/[^0-9].*$//') && @@ -665,6 +670,7 @@ test_expect_success 'avoid unnecessary reset' ' test_expect_success 'reword' ' git checkout -b reword-branch master && + set_fake_editor && FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" git rebase -i A && git show HEAD | grep "E changed" && test $(git rev-parse master) != $(git rev-parse HEAD) && @@ -684,6 +690,7 @@ test_expect_success 'rebase -i can copy notes' ' test_commit n2 && test_commit n3 && git notes add -m"a note" n3 && + set_fake_editor && git rebase -i --onto n1 n2 && test "a note" = "$(git notes show HEAD)" ' @@ -697,6 +704,7 @@ EOF test_expect_success 'rebase -i can copy notes over a fixup' ' git reset --hard n3 && git notes add -m"an earlier note" n2 && + set_fake_editor && GIT_NOTES_REWRITE_MODE=concatenate FAKE_LINES="1 fixup 2" git rebase -i n1 && git notes show > output && test_cmp expect output @@ -706,6 +714,7 @@ test_expect_success 'rebase while detaching HEAD' ' git symbolic-ref HEAD && grandparent=$(git rev-parse HEAD~2) && test_tick && + set_fake_editor && FAKE_LINES="2 1" git rebase -i HEAD~2 HEAD^0 && test $grandparent = $(git rev-parse HEAD~2) && test_must_fail git symbolic-ref HEAD @@ -715,6 +724,7 @@ test_tick # Ensure that the rebased commits get a different timestamp. test_expect_success 'always cherry-pick with --no-ff' ' git checkout no-ff-branch && git tag original-no-ff-branch && + set_fake_editor && git rebase -i --no-ff A && touch empty && for p in 0 1 2 @@ -747,6 +757,7 @@ test_expect_success 'set up commits with funny messages' ' test_expect_success 'rebase-i history with funny messages' ' git rev-list A..funny >expect && test_tick && + set_fake_editor && FAKE_LINES="1 2 3 4" git rebase -i A && git rev-list A.. >actual && test_cmp expect actual @@ -763,6 +774,7 @@ test_expect_success 'prepare for rebase -i --exec' ' test_expect_success 'running "git rebase -i --exec git show HEAD"' ' + set_fake_editor && git rebase -i --exec "git show HEAD" HEAD~2 >actual && ( FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" && @@ -776,6 +788,7 @@ test_expect_success 'running "git rebase -i --exec git show HEAD"' ' test_expect_success 'running "git rebase --exec git show HEAD -i"' ' git reset --hard execute && + set_fake_editor && git rebase --exec "git show HEAD" -i HEAD~2 >actual && ( FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" && @@ -789,6 +802,7 @@ test_expect_success 'running "git rebase --exec git show HEAD -i"' ' test_expect_success 'running "git rebase -ix git show HEAD"' ' git reset --hard execute && + set_fake_editor && git rebase -ix "git show HEAD" HEAD~2 >actual && ( FAKE_LINES="1 exec_git_show_HEAD 2 exec_git_show_HEAD" && @@ -802,6 +816,7 @@ test_expect_success 'running "git rebase -ix git show HEAD"' ' test_expect_success 'rebase -ix with several <CMD>' ' git reset --hard execute && + set_fake_editor && git rebase -ix "git show HEAD; pwd" HEAD~2 >actual && ( FAKE_LINES="1 exec_git_show_HEAD;_pwd 2 exec_git_show_HEAD;_pwd" && @@ -815,6 +830,7 @@ test_expect_success 'rebase -ix with several <CMD>' ' test_expect_success 'rebase -ix with several instances of --exec' ' git reset --hard execute && + set_fake_editor && git rebase -i --exec "git show HEAD" --exec "pwd" HEAD~2 >actual && ( FAKE_LINES="1 exec_git_show_HEAD exec_pwd 2 @@ -836,6 +852,7 @@ test_expect_success 'rebase -ix with --autosquash' ' echo bis >bis.txt && git add bis.txt && git commit -m "fixup! two_exec" && + set_fake_editor && ( git checkout -b autosquash_actual && git rebase -i --exec "git show HEAD" --autosquash HEAD~4 >actual @@ -854,6 +871,7 @@ test_expect_success 'rebase -ix with --autosquash' ' test_expect_success 'rebase --exec without -i shows error message' ' git reset --hard execute && + set_fake_editor && test_must_fail git rebase --exec "git show HEAD" HEAD~2 2>actual && echo "The --exec option must be used with the --interactive option" >expected && test_i18ncmp expected actual @@ -862,6 +880,7 @@ test_expect_success 'rebase --exec without -i shows error message' ' test_expect_success 'rebase -i --exec without <CMD>' ' git reset --hard execute && + set_fake_editor && test_must_fail git rebase -i --exec 2>tmp && sed -e "1d" tmp >actual && test_must_fail git rebase -h >expected && @@ -871,6 +890,7 @@ test_expect_success 'rebase -i --exec without <CMD>' ' test_expect_success 'rebase -i --root re-order and drop commits' ' git checkout E && + set_fake_editor && FAKE_LINES="3 1 2 5" git rebase -i --root && test E = $(git cat-file commit HEAD | sed -ne \$p) && test B = $(git cat-file commit HEAD^ | sed -ne \$p) && @@ -884,6 +904,7 @@ test_expect_success 'rebase -i --root retain root commit author and message' ' echo B >file7 && git add file7 && GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" && + set_fake_editor && FAKE_LINES="2" git rebase -i --root && git cat-file commit HEAD | grep -q "^author Twerp Snog" && git cat-file commit HEAD | grep -q "^different author$" @@ -891,17 +912,15 @@ test_expect_success 'rebase -i --root retain root commit author and message' ' test_expect_success 'rebase -i --root temporary sentinel commit' ' git checkout B && - ( - FAKE_LINES="2" && - export FAKE_LINES && - test_must_fail git rebase -i --root - ) && + set_fake_editor && + test_must_fail env FAKE_LINES="2" git rebase -i --root && git cat-file commit HEAD | grep "^tree 4b825dc642cb" && git rebase --abort ' test_expect_success 'rebase -i --root fixup root commit' ' git checkout B && + set_fake_editor && FAKE_LINES="1 fixup 2" git rebase -i --root && test A = $(git cat-file commit HEAD | sed -ne \$p) && test B = $(git show HEAD:file1) && @@ -911,6 +930,7 @@ test_expect_success 'rebase -i --root fixup root commit' ' test_expect_success 'rebase --edit-todo does not works on non-interactive rebase' ' git reset --hard && git checkout conflict-branch && + set_fake_editor && test_must_fail git rebase --onto HEAD~2 HEAD~ && test_must_fail git rebase --edit-todo && git rebase --abort @@ -919,6 +939,7 @@ test_expect_success 'rebase --edit-todo does not works on non-interactive rebase test_expect_success 'rebase --edit-todo can be used to modify todo' ' git reset --hard && git checkout no-conflict-branch^0 && + set_fake_editor && FAKE_LINES="edit 1 2 3" git rebase -i HEAD~3 && FAKE_LINES="2 1" git rebase --edit-todo && git rebase --continue @@ -929,6 +950,7 @@ test_expect_success 'rebase --edit-todo can be used to modify todo' ' test_expect_success 'rebase -i produces readable reflog' ' git reset --hard && git branch -f branch-reflog-test H && + set_fake_editor && git rebase -i --onto I F branch-reflog-test && cat >expect <<-\EOF && rebase -i (start): checkout I @@ -976,4 +998,37 @@ test_expect_success 'rebase -i with --strategy and -X' ' test $(cat file1) = Z ' +test_expect_success 'rebase -i error on commits with \ in message' ' + current_head=$(git rev-parse HEAD) + test_when_finished "git rebase --abort; git reset --hard $current_head; rm -f error" && + test_commit TO-REMOVE will-conflict old-content && + test_commit "\temp" will-conflict new-content dummy && + test_must_fail env EDITOR=true git rebase -i HEAD^ --onto HEAD^^ 2>error && + test_expect_code 1 grep " emp" error +' + +test_expect_success 'short SHA-1 setup' ' + test_when_finished "git checkout master" && + git checkout --orphan collide && + git rm -rf . && + ( + unset test_tick && + test_commit collide1 collide && + test_commit --notick collide2 collide && + test_commit --notick collide3 collide + ) +' + +test_expect_success 'short SHA-1 collide' ' + test_when_finished "reset_rebase && git checkout master" && + git checkout collide && + ( + unset test_tick && + test_tick && + set_fake_editor && + FAKE_COMMIT_MESSAGE="collide2 ac4f2ee" \ + FAKE_LINES="reword 1 2" git rebase -i HEAD~2 + ) +' + test_done diff --git a/t/t3409-rebase-preserve-merges.sh b/t/t3409-rebase-preserve-merges.sh index 2e0c36415f..8c251c57a6 100755 --- a/t/t3409-rebase-preserve-merges.sh +++ b/t/t3409-rebase-preserve-merges.sh @@ -28,6 +28,8 @@ export GIT_AUTHOR_EMAIL # \--A3 <-- topic2 # \ # B2 <-- origin/topic +# +# Clone 4 (same as Clone 3) test_expect_success 'setup for merge-preserving rebase' \ 'echo First > A && @@ -64,6 +66,16 @@ test_expect_success 'setup for merge-preserving rebase' \ git merge --no-ff topic2 ) && + git clone ./. clone4 && + ( + cd clone4 && + git checkout -b topic2 origin/topic && + echo Sixth > A && + git commit -a -m "Modify A3" && + git checkout -b topic origin/topic && + git merge --no-ff topic2 + ) && + git checkout topic && echo Fourth >> B && git commit -a -m "Modify B2" @@ -96,4 +108,15 @@ test_expect_success 'rebase -p preserves no-ff merges' ' ) ' +test_expect_success 'rebase -p ignores merge.log config' ' + ( + cd clone4 && + git fetch && + git -c merge.log=1 rebase -p origin/topic && + echo >expected && + git log --format="%b" -1 >current && + test_cmp expected current + ) +' + test_done diff --git a/t/t3413-rebase-hook.sh b/t/t3413-rebase-hook.sh index 098b75507b..b6833e9a5f 100755 --- a/t/t3413-rebase-hook.sh +++ b/t/t3413-rebase-hook.sh @@ -118,11 +118,7 @@ test_expect_success 'pre-rebase hook stops rebase (1)' ' test_expect_success 'pre-rebase hook stops rebase (2)' ' git checkout test && git reset --hard side && - ( - EDITOR=: - export EDITOR - test_must_fail git rebase -i master - ) && + test_must_fail env EDITOR=: git rebase -i master && test "z$(git symbolic-ref HEAD)" = zrefs/heads/test && test 0 = $(git rev-list HEAD...side | wc -l) ' diff --git a/t/t3501-revert-cherry-pick.sh b/t/t3501-revert-cherry-pick.sh index 6f489e20ee..51f3bbb8af 100755 --- a/t/t3501-revert-cherry-pick.sh +++ b/t/t3501-revert-cherry-pick.sh @@ -100,7 +100,7 @@ test_expect_success 'revert forbidden on dirty working tree' ' ' -test_expect_success 'chery-pick on unborn branch' ' +test_expect_success 'cherry-pick on unborn branch' ' git checkout --orphan unborn && git rm --cached -r . && rm -rf * && @@ -109,4 +109,36 @@ test_expect_success 'chery-pick on unborn branch' ' ! test_cmp_rev initial HEAD ' +test_expect_success 'cherry-pick "-" to pick from previous branch' ' + git checkout unborn && + test_commit to-pick actual content && + git checkout master && + git cherry-pick - && + echo content >expect && + test_cmp expect actual +' + +test_expect_success 'cherry-pick "-" is meaningless without checkout' ' + test_create_repo afresh && + ( + cd afresh && + test_commit one && + test_commit two && + test_commit three && + test_must_fail git cherry-pick - + ) +' + +test_expect_success 'cherry-pick "-" works with arguments' ' + git checkout -b side-branch && + test_commit change actual change && + git checkout master && + git cherry-pick -s - && + echo "Signed-off-by: C O Mitter <committer@example.com>" >expect && + git cat-file commit HEAD | grep ^Signed-off-by: >signoff && + test_cmp expect signoff && + echo change >expect && + test_cmp expect actual +' + test_done diff --git a/t/t3506-cherry-pick-ff.sh b/t/t3506-cherry-pick-ff.sh index 373aad623c..fb889ac6f0 100755 --- a/t/t3506-cherry-pick-ff.sh +++ b/t/t3506-cherry-pick-ff.sh @@ -105,7 +105,7 @@ test_expect_success 'cherry pick a root commit with --ff' ' test "$(git rev-parse --verify HEAD)" = "1df192cd8bc58a2b275d842cede4d221ad9000d1" ' -test_expect_success 'chery-pick --ff on unborn branch' ' +test_expect_success 'cherry-pick --ff on unborn branch' ' git checkout --orphan unborn && git rm --cached -r . && rm -rf * && diff --git a/t/t3509-cherry-pick-merge-df.sh b/t/t3509-cherry-pick-merge-df.sh index a5b6a5f331..1e5b3948df 100755 --- a/t/t3509-cherry-pick-merge-df.sh +++ b/t/t3509-cherry-pick-merge-df.sh @@ -74,7 +74,7 @@ test_expect_success 'Setup rename with file on one side matching different dirna echo content > sub/file && echo foo > othersub/whatever && git add -A && - git commit -m "Common commmit" && + git commit -m "Common commit" && git rm -rf othersub && git mv sub/file othersub && diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh index 5c87b55645..3d305814b9 100755 --- a/t/t3600-rm.sh +++ b/t/t3600-rm.sh @@ -240,18 +240,15 @@ test_expect_success 'refresh index before checking if it is up-to-date' ' test_expect_success 'choking "git rm" should not let it die with cruft' ' git reset -q --hard && + test_when_finished "rm -f .git/index.lock && git reset -q --hard" && i=0 && while test $i -lt 12000 do - echo "100644 $_z40 0 some-file-$i" + echo "100644 1234567890123456789012345678901234567890 0 some-file-$i" i=$(( $i + 1 )) done | git update-index --index-info && - git rm -n "some-file-*" | :; - test -f .git/index.lock - status=$? - rm -f .git/index.lock - git reset -q --hard - test "$status" != 0 + git rm -n "some-file-*" | : && + test_path_is_missing .git/index.lock ' test_expect_success 'rm removes subdirectories recursively' ' @@ -263,6 +260,7 @@ test_expect_success 'rm removes subdirectories recursively' ' ' cat >expect <<EOF +M .gitmodules D submod EOF @@ -270,6 +268,15 @@ cat >expect.modified <<EOF M submod EOF +cat >expect.cached <<EOF +D submod +EOF + +cat >expect.both_deleted<<EOF +D .gitmodules +D submod +EOF + test_expect_success 'rm removes empty submodules from work tree' ' mkdir submod && git update-index --add --cacheinfo 160000 $(git rev-parse HEAD) submod && @@ -281,16 +288,20 @@ test_expect_success 'rm removes empty submodules from work tree' ' git rm submod && test ! -e submod && git status -s -uno --ignore-submodules=none > actual && - test_cmp expect actual + test_cmp expect actual && + test_must_fail git config -f .gitmodules submodule.sub.url && + test_must_fail git config -f .gitmodules submodule.sub.path ' -test_expect_success 'rm removes removed submodule from index' ' +test_expect_success 'rm removes removed submodule from index and .gitmodules' ' git reset --hard && git submodule update && rm -rf submod && git rm submod && git status -s -uno --ignore-submodules=none > actual && - test_cmp expect actual + test_cmp expect actual && + test_must_fail git config -f .gitmodules submodule.sub.url && + test_must_fail git config -f .gitmodules submodule.sub.path ' test_expect_success 'rm removes work tree of unmodified submodules' ' @@ -299,7 +310,9 @@ test_expect_success 'rm removes work tree of unmodified submodules' ' git rm submod && test ! -d submod && git status -s -uno --ignore-submodules=none > actual && - test_cmp expect actual + test_cmp expect actual && + test_must_fail git config -f .gitmodules submodule.sub.url && + test_must_fail git config -f .gitmodules submodule.sub.path ' test_expect_success 'rm removes a submodule with a trailing /' ' @@ -333,6 +346,72 @@ test_expect_success 'rm of a populated submodule with different HEAD fails unles git rm -f submod && test ! -d submod && git status -s -uno --ignore-submodules=none > actual && + test_cmp expect actual && + test_must_fail git config -f .gitmodules submodule.sub.url && + test_must_fail git config -f .gitmodules submodule.sub.path +' + +test_expect_success 'rm --cached leaves work tree of populated submodules and .gitmodules alone' ' + git reset --hard && + git submodule update && + git rm --cached submod && + test -d submod && + test -f submod/.git && + git status -s -uno >actual && + test_cmp expect.cached actual && + git config -f .gitmodules submodule.sub.url && + git config -f .gitmodules submodule.sub.path +' + +test_expect_success 'rm --dry-run does not touch the submodule or .gitmodules' ' + git reset --hard && + git submodule update && + git rm -n submod && + test -f submod/.git && + git diff-index --exit-code HEAD +' + +test_expect_success 'rm does not complain when no .gitmodules file is found' ' + git reset --hard && + git submodule update && + git rm .gitmodules && + git rm submod >actual 2>actual.err && + ! test -s actual.err && + ! test -d submod && + ! test -f submod/.git && + git status -s -uno >actual && + test_cmp expect.both_deleted actual +' + +test_expect_success 'rm will error out on a modified .gitmodules file unless staged' ' + git reset --hard && + git submodule update && + git config -f .gitmodules foo.bar true && + test_must_fail git rm submod >actual 2>actual.err && + test -s actual.err && + test -d submod && + test -f submod/.git && + git diff-files --quiet -- submod && + git add .gitmodules && + git rm submod >actual 2>actual.err && + ! test -s actual.err && + ! test -d submod && + ! test -f submod/.git && + git status -s -uno >actual && + test_cmp expect actual +' + +test_expect_success 'rm issues a warning when section is not found in .gitmodules' ' + git reset --hard && + git submodule update && + git config -f .gitmodules --remove-section submodule.sub && + git add .gitmodules && + echo "warning: Could not find section in .gitmodules where path=submod" >expect.err && + git rm submod >actual 2>actual.err && + test_i18ncmp expect.err actual.err && + ! test -d submod && + ! test -f submod/.git && + git status -s -uno >actual && test_cmp expect actual ' @@ -427,7 +506,9 @@ test_expect_success 'rm of a conflicted populated submodule with different HEAD git rm -f submod && test ! -d submod && git status -s -uno --ignore-submodules=none > actual && - test_cmp expect actual + test_cmp expect actual && + test_must_fail git config -f .gitmodules submodule.sub.url && + test_must_fail git config -f .gitmodules submodule.sub.path ' test_expect_success 'rm of a conflicted populated submodule with modifications fails unless forced' ' @@ -446,7 +527,9 @@ test_expect_success 'rm of a conflicted populated submodule with modifications f git rm -f submod && test ! -d submod && git status -s -uno --ignore-submodules=none > actual && - test_cmp expect actual + test_cmp expect actual && + test_must_fail git config -f .gitmodules submodule.sub.url && + test_must_fail git config -f .gitmodules submodule.sub.path ' test_expect_success 'rm of a conflicted populated submodule with untracked files fails unless forced' ' @@ -622,6 +705,22 @@ test_expect_success 'rm of a populated nested submodule with a nested .git direc rm -rf submod ' +test_expect_success 'checking out a commit after submodule removal needs manual updates' ' + git commit -m "submodule removal" submod && + git checkout HEAD^ && + git submodule update && + git checkout -q HEAD^ 2>actual && + git checkout -q master 2>actual && + echo "warning: unable to rmdir submod: Directory not empty" >expected && + test_i18ncmp expected actual && + git status -s submod >actual && + echo "?? submod/" >expected && + test_cmp expected actual && + rm -rf submod && + git status -s -uno --ignore-submodules=none > actual && + ! test -s actual +' + test_expect_success 'rm of d/f when d has become a non-directory' ' rm -rf d && mkdir d && diff --git a/t/t3700-add.sh b/t/t3700-add.sh index aab86e838b..fe274e2fb1 100755 --- a/t/t3700-add.sh +++ b/t/t3700-add.sh @@ -272,6 +272,25 @@ test_expect_success '"add non-existent" should fail' ' ! (git ls-files | grep "non-existent") ' +test_expect_success 'git add -A on empty repo does not error out' ' + rm -fr empty && + git init empty && + ( + cd empty && + git add -A . && + git add -A + ) +' + +test_expect_success '"git add ." in empty repo' ' + rm -fr empty && + git init empty && + ( + cd empty && + git add . + ) +' + test_expect_success 'git add --dry-run of existing changed file' " echo new >>track-this && git add --dry-run track-this >actual 2>&1 && diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index 9fab25cc96..24ddd8a704 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -2,20 +2,25 @@ test_description='add -i basic tests' . ./test-lib.sh -. "$TEST_DIRECTORY"/lib-prereq-FILEMODE.sh -test_expect_success PERL 'setup (initial)' ' +if ! test_have_prereq PERL +then + skip_all='skipping add -i tests, perl not available' + test_done +fi + +test_expect_success 'setup (initial)' ' echo content >file && git add file && echo more >>file && echo lines >>file ' -test_expect_success PERL 'status works (initial)' ' +test_expect_success 'status works (initial)' ' git add -i </dev/null >output && grep "+1/-0 *+2/-0 file" output ' -test_expect_success PERL 'setup expected' ' +test_expect_success 'setup expected' ' cat >expected <<EOF new file mode 100644 index 0000000..d95f3ad @@ -26,19 +31,19 @@ index 0000000..d95f3ad EOF ' -test_expect_success PERL 'diff works (initial)' ' +test_expect_success 'diff works (initial)' ' (echo d; echo 1) | git add -i >output && sed -ne "/new file/,/content/p" <output >diff && test_cmp expected diff ' -test_expect_success PERL 'revert works (initial)' ' +test_expect_success 'revert works (initial)' ' git add file && (echo r; echo 1) | git add -i && git ls-files >output && ! grep . output ' -test_expect_success PERL 'setup (commit)' ' +test_expect_success 'setup (commit)' ' echo baseline >file && git add file && git commit -m commit && @@ -47,12 +52,12 @@ test_expect_success PERL 'setup (commit)' ' echo more >>file && echo lines >>file ' -test_expect_success PERL 'status works (commit)' ' +test_expect_success 'status works (commit)' ' git add -i </dev/null >output && grep "+1/-0 *+2/-0 file" output ' -test_expect_success PERL 'setup expected' ' +test_expect_success 'setup expected' ' cat >expected <<EOF index 180b47c..b6f2c08 100644 --- a/file @@ -63,12 +68,12 @@ index 180b47c..b6f2c08 100644 EOF ' -test_expect_success PERL 'diff works (commit)' ' +test_expect_success 'diff works (commit)' ' (echo d; echo 1) | git add -i >output && sed -ne "/^index/,/content/p" <output >diff && test_cmp expected diff ' -test_expect_success PERL 'revert works (commit)' ' +test_expect_success 'revert works (commit)' ' git add file && (echo r; echo 1) | git add -i && git add -i </dev/null >output && @@ -76,24 +81,24 @@ test_expect_success PERL 'revert works (commit)' ' ' -test_expect_success PERL 'setup expected' ' +test_expect_success 'setup expected' ' cat >expected <<EOF EOF ' -test_expect_success PERL 'setup fake editor' ' +test_expect_success 'setup fake editor' ' >fake_editor.sh && chmod a+x fake_editor.sh && test_set_editor "$(pwd)/fake_editor.sh" ' -test_expect_success PERL 'dummy edit works' ' +test_expect_success 'dummy edit works' ' (echo e; echo a) | git add -p && git diff > diff && test_cmp expected diff ' -test_expect_success PERL 'setup patch' ' +test_expect_success 'setup patch' ' cat >patch <<EOF @@ -1,1 +1,4 @@ this @@ -103,7 +108,7 @@ cat >patch <<EOF EOF ' -test_expect_success PERL 'setup fake editor' ' +test_expect_success 'setup fake editor' ' echo "#!$SHELL_PATH" >fake_editor.sh && cat >>fake_editor.sh <<\EOF && mv -f "$1" oldpatch && @@ -113,26 +118,26 @@ EOF test_set_editor "$(pwd)/fake_editor.sh" ' -test_expect_success PERL 'bad edit rejected' ' +test_expect_success 'bad edit rejected' ' git reset && (echo e; echo n; echo d) | git add -p >output && grep "hunk does not apply" output ' -test_expect_success PERL 'setup patch' ' +test_expect_success 'setup patch' ' cat >patch <<EOF this patch is garbage EOF ' -test_expect_success PERL 'garbage edit rejected' ' +test_expect_success 'garbage edit rejected' ' git reset && (echo e; echo n; echo d) | git add -p >output && grep "hunk does not apply" output ' -test_expect_success PERL 'setup patch' ' +test_expect_success 'setup patch' ' cat >patch <<EOF @@ -1,0 +1,0 @@ baseline @@ -142,7 +147,7 @@ cat >patch <<EOF EOF ' -test_expect_success PERL 'setup expected' ' +test_expect_success 'setup expected' ' cat >expected <<EOF diff --git a/file b/file index b5dd6c9..f910ae9 100644 @@ -157,13 +162,13 @@ index b5dd6c9..f910ae9 100644 EOF ' -test_expect_success PERL 'real edit works' ' +test_expect_success 'real edit works' ' (echo e; echo n; echo d) | git add -p && git diff >output && test_cmp expected output ' -test_expect_success PERL 'skip files similarly as commit -a' ' +test_expect_success 'skip files similarly as commit -a' ' git reset && echo file >.gitignore && echo changed >file && @@ -177,7 +182,7 @@ test_expect_success PERL 'skip files similarly as commit -a' ' ' rm -f .gitignore -test_expect_success PERL,FILEMODE 'patch does not affect mode' ' +test_expect_success FILEMODE 'patch does not affect mode' ' git reset --hard && echo content >>file && chmod +x file && @@ -186,7 +191,7 @@ test_expect_success PERL,FILEMODE 'patch does not affect mode' ' git diff file | grep "new mode" ' -test_expect_success PERL,FILEMODE 'stage mode but not hunk' ' +test_expect_success FILEMODE 'stage mode but not hunk' ' git reset --hard && echo content >>file && chmod +x file && @@ -196,7 +201,7 @@ test_expect_success PERL,FILEMODE 'stage mode but not hunk' ' ' -test_expect_success PERL,FILEMODE 'stage mode and hunk' ' +test_expect_success FILEMODE 'stage mode and hunk' ' git reset --hard && echo content >>file && chmod +x file && @@ -208,14 +213,14 @@ test_expect_success PERL,FILEMODE 'stage mode and hunk' ' # end of tests disabled when filemode is not usable -test_expect_success PERL 'setup again' ' +test_expect_success 'setup again' ' git reset --hard && test_chmod +x file && echo content >>file ' # Write the patch file with a new line at the top and bottom -test_expect_success PERL 'setup patch' ' +test_expect_success 'setup patch' ' cat >patch <<EOF index 180b47c..b6f2c08 100644 --- a/file @@ -229,7 +234,7 @@ EOF ' # Expected output, similar to the patch but w/ diff at the top -test_expect_success PERL 'setup expected' ' +test_expect_success 'setup expected' ' cat >expected <<EOF diff --git a/file b/file index b6f2c08..61b9053 100755 @@ -244,7 +249,7 @@ EOF ' # Test splitting the first patch, then adding both -test_expect_success PERL 'add first line works' ' +test_expect_success 'add first line works' ' git commit -am "clear local changes" && git apply patch && (echo s; echo y; echo y) | git add -p file && @@ -252,7 +257,7 @@ test_expect_success PERL 'add first line works' ' test_cmp expected diff ' -test_expect_success PERL 'setup expected' ' +test_expect_success 'setup expected' ' cat >expected <<EOF diff --git a/non-empty b/non-empty deleted file mode 100644 @@ -264,7 +269,7 @@ index d95f3ad..0000000 EOF ' -test_expect_success PERL 'deleting a non-empty file' ' +test_expect_success 'deleting a non-empty file' ' git reset --hard && echo content >non-empty && git add non-empty && @@ -275,7 +280,7 @@ test_expect_success PERL 'deleting a non-empty file' ' test_cmp expected diff ' -test_expect_success PERL 'setup expected' ' +test_expect_success 'setup expected' ' cat >expected <<EOF diff --git a/empty b/empty deleted file mode 100644 @@ -283,7 +288,7 @@ index e69de29..0000000 EOF ' -test_expect_success PERL 'deleting an empty file' ' +test_expect_success 'deleting an empty file' ' git reset --hard && > empty && git add empty && @@ -294,7 +299,7 @@ test_expect_success PERL 'deleting an empty file' ' test_cmp expected diff ' -test_expect_success PERL 'split hunk setup' ' +test_expect_success 'split hunk setup' ' git reset --hard && for i in 10 20 30 40 50 60 do @@ -310,7 +315,7 @@ test_expect_success PERL 'split hunk setup' ' done >test ' -test_expect_success PERL 'split hunk "add -p (edit)"' ' +test_expect_success 'split hunk "add -p (edit)"' ' # Split, say Edit and do nothing. Then: # # 1. Broken version results in a patch that does not apply and diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh index debda7a678..5b79b216e2 100755 --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@ -673,4 +673,16 @@ test_expect_success 'store updates stash ref and reflog' ' grep quux bazzy ' +test_expect_success 'handle stash specification with spaces' ' + git stash clear && + echo pig >file && + git stash && + stamp=$(git log -g --format="%cd" -1 refs/stash) && + test_tick && + echo cow >file && + git stash && + git stash apply "stash@{$stamp}" && + grep pig file +' + test_done diff --git a/t/t3910-mac-os-precompose.sh b/t/t3910-mac-os-precompose.sh index 5fe57c5438..e4ba6013e4 100755 --- a/t/t3910-mac-os-precompose.sh +++ b/t/t3910-mac-os-precompose.sh @@ -36,7 +36,7 @@ Alongc=$Alongc$AEligatu$AEligatu #254 Byte test_expect_success "detect if nfd needed" ' precomposeunicode=`git config core.precomposeunicode` && - test "$precomposeunicode" = false && + test "$precomposeunicode" = true && git config core.precomposeunicode true ' test_expect_success "setup" ' diff --git a/t/t4010-diff-pathspec.sh b/t/t4010-diff-pathspec.sh index af5134b70c..2bb973655b 100755 --- a/t/t4010-diff-pathspec.sh +++ b/t/t4010-diff-pathspec.sh @@ -110,4 +110,40 @@ test_expect_success 'diff-tree -r with wildcard' ' test_cmp expected result ' +test_expect_success 'setup submodules' ' + test_tick && + git init submod && + ( cd submod && test_commit first; ) && + git add submod && + git commit -m first && + ( cd submod && test_commit second; ) && + git add submod && + git commit -m second +' + +test_expect_success 'diff-tree ignores trailing slash on submodule path' ' + git diff --name-only HEAD^ HEAD submod >expect && + git diff --name-only HEAD^ HEAD submod/ >actual && + test_cmp expect actual +' + +test_expect_success 'diff multiple wildcard pathspecs' ' + mkdir path2 && + echo rezrov >path2/file1 && + git update-index --add path2/file1 && + tree3=`git write-tree` && + git diff --name-only $tree $tree3 -- "path2*1" "path1*1" >actual && + cat <<-\EOF >expect && + path1/file1 + path2/file1 + EOF + test_cmp expect actual +' + +test_expect_success 'diff-cache ignores trailing slash on submodule path' ' + git diff --name-only HEAD^ submod >expect && + git diff --name-only HEAD^ submod/ >actual && + test_cmp expect actual +' + test_done diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index 668933bfb2..9c80633146 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -293,7 +293,7 @@ check_threading () { (git format-patch --stdout "$@"; echo $? > status.out) | # Prints everything between the Message-ID and In-Reply-To, # and replaces all Message-ID-lookalikes by a sequence number - "$PERL_PATH" -ne ' + perl -ne ' if (/^(message-id|references|in-reply-to)/i) { $printing = 1; } elsif (/^\S/) { @@ -764,22 +764,14 @@ test_expect_success 'format-patch --signature="" suppresses signatures' ' test_expect_success TTY 'format-patch --stdout paginates' ' rm -f pager_used && - ( - GIT_PAGER="wc >pager_used" && - export GIT_PAGER && - test_terminal git format-patch --stdout --all - ) && + test_terminal env GIT_PAGER="wc >pager_used" git format-patch --stdout --all && test_path_is_file pager_used ' test_expect_success TTY 'format-patch --stdout pagination can be disabled' ' rm -f pager_used && - ( - GIT_PAGER="wc >pager_used" && - export GIT_PAGER && - test_terminal git --no-pager format-patch --stdout --all && - test_terminal git -c "pager.format-patch=false" format-patch --stdout --all - ) && + test_terminal env GIT_PAGER="wc >pager_used" git --no-pager format-patch --stdout --all && + test_terminal env GIT_PAGER="wc >pager_used" git -c "pager.format-patch=false" format-patch --stdout --all && test_path_is_missing pager_used && test_path_is_missing .git/pager_used ' @@ -1000,6 +992,16 @@ test_expect_success '--from uses committer ident' ' test_cmp expect patch.head ' +test_expect_success '--from omits redundant in-body header' ' + git format-patch -1 --stdout --from="A U Thor <author@example.com>" >patch && + cat >expect <<-\EOF && + From: A U Thor <author@example.com> + + EOF + sed -ne "/^From:/p; /^$/p; /^---$/q" <patch >patch.head && + test_cmp expect patch.head +' + test_expect_success 'in-body headers trigger content encoding' ' GIT_AUTHOR_NAME="éxötìc" test_commit exotic && test_when_finished "git reset --hard HEAD^" && diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh index 3fb4b976a2..604a838c1a 100755 --- a/t/t4015-diff-whitespace.sh +++ b/t/t4015-diff-whitespace.sh @@ -145,7 +145,7 @@ test_expect_success 'another test, with --ignore-space-at-eol' 'test_cmp expect test_expect_success 'ignore-blank-lines: only new lines' ' test_seq 5 >x && git update-index x && - test_seq 5 | sed "/3/i \\ + test_seq 5 | sed "/3/i\\ " >x && git diff --ignore-blank-lines >out && >expect && @@ -155,7 +155,8 @@ test_expect_success 'ignore-blank-lines: only new lines' ' test_expect_success 'ignore-blank-lines: only new lines with space' ' test_seq 5 >x && git update-index x && - test_seq 5 | sed "/3/i \ " >x && + test_seq 5 | sed "/3/i\\ + " >x && git diff -w --ignore-blank-lines >out && >expect && test_cmp out expect diff --git a/t/t4020-diff-external.sh b/t/t4020-diff-external.sh index 2e7d73f090..044620186d 100755 --- a/t/t4020-diff-external.sh +++ b/t/t4020-diff-external.sh @@ -177,7 +177,7 @@ test_expect_success 'no diff with -diff' ' git diff | grep Binary ' -echo NULZbetweenZwords | "$PERL_PATH" -pe 'y/Z/\000/' > file +echo NULZbetweenZwords | perl -pe 'y/Z/\000/' > file test_expect_success 'force diff with "diff"' ' echo >.gitattributes "file diff" && @@ -193,6 +193,19 @@ test_expect_success 'GIT_EXTERNAL_DIFF with more than one changed files' ' GIT_EXTERNAL_DIFF=echo git diff ' +test_expect_success 'GIT_EXTERNAL_DIFF path counter/total' ' + write_script external-diff.sh <<-\EOF && + echo $GIT_DIFF_PATH_COUNTER of $GIT_DIFF_PATH_TOTAL >>counter.txt + EOF + >counter.txt && + cat >expect <<-\EOF && + 1 of 2 + 2 of 2 + EOF + GIT_EXTERNAL_DIFF=./external-diff.sh git diff && + test_cmp expect counter.txt +' + test_expect_success 'GIT_EXTERNAL_DIFF generates pretty paths' ' touch file.ext && git add file.ext && @@ -213,12 +226,13 @@ keep_only_cr () { } test_expect_success 'external diff with autocrlf = true' ' - git config core.autocrlf true && + test_config core.autocrlf true && GIT_EXTERNAL_DIFF=./fake-diff.sh git diff && test $(wc -l < crlfed.txt) = $(cat crlfed.txt | keep_only_cr | wc -c) ' test_expect_success 'diff --cached' ' + test_config core.autocrlf true && git add file && git update-index --assume-unchanged file && echo second >file && @@ -226,4 +240,31 @@ test_expect_success 'diff --cached' ' test_cmp "$TEST_DIRECTORY"/t4020/diff.NUL actual ' +test_expect_success 'clean up crlf leftovers' ' + git update-index --no-assume-unchanged file && + rm -f file* && + git reset --hard +' + +test_expect_success 'submodule diff' ' + git init sub && + ( cd sub && test_commit sub1 ) && + git add sub && + test_tick && + git commit -m "add submodule" && + ( cd sub && test_commit sub2 ) && + write_script gather_pre_post.sh <<-\EOF && + echo "$1 $4" # path, mode + cat "$2" # old file + cat "$5" # new file + EOF + GIT_EXTERNAL_DIFF=./gather_pre_post.sh git diff >actual && + cat >expected <<-EOF && + sub 160000 + Subproject commit $(git rev-parse HEAD:sub) + Subproject commit $(cd sub && git rev-parse HEAD) + EOF + test_cmp expected actual +' + test_done diff --git a/t/t4029-diff-trailing-space.sh b/t/t4029-diff-trailing-space.sh index 36e2f075c9..3ccc237a8d 100755 --- a/t/t4029-diff-trailing-space.sh +++ b/t/t4029-diff-trailing-space.sh @@ -27,7 +27,7 @@ test_expect_success \ git config --bool diff.suppressBlankEmpty true && git diff f > actual && test_cmp exp actual && - "$PERL_PATH" -i.bak -p -e "s/^\$/ /" exp && + perl -i.bak -p -e "s/^\$/ /" exp && git config --bool diff.suppressBlankEmpty false && git diff f > actual && test_cmp exp actual && diff --git a/t/t4030-diff-textconv.sh b/t/t4030-diff-textconv.sh index f75f46f92d..aad6c7f78d 100755 --- a/t/t4030-diff-textconv.sh +++ b/t/t4030-diff-textconv.sh @@ -58,6 +58,12 @@ test_expect_success 'diff produces text' ' test_cmp expect.text actual ' +test_expect_success 'show commit produces text' ' + git show HEAD >diff && + find_diff <diff >actual && + test_cmp expect.text actual +' + test_expect_success 'diff-tree produces binary' ' git diff-tree -p HEAD^ HEAD >diff && find_diff <diff >actual && @@ -84,6 +90,24 @@ test_expect_success 'status -v produces text' ' git reset --soft HEAD@{1} ' +test_expect_success 'show blob produces binary' ' + git show HEAD:file >actual && + printf "\\0\\n\\01\\n" >expect && + test_cmp expect actual +' + +test_expect_success 'show --textconv blob produces text' ' + git show --textconv HEAD:file >actual && + printf "0\\n1\\n" >expect && + test_cmp expect actual +' + +test_expect_success 'show --no-textconv blob produces binary' ' + git show --no-textconv HEAD:file >actual && + printf "\\0\\n\\01\\n" >expect && + test_cmp expect actual +' + test_expect_success 'grep-diff (-G) operates on textconv data (add)' ' echo one >expect && git log --root --format=%s -G0 >actual && diff --git a/t/t4034/ada/expect b/t/t4034/ada/expect index be2376e904..a682d288b2 100644 --- a/t/t4034/ada/expect +++ b/t/t4034/ada/expect @@ -4,7 +4,7 @@ <BOLD>+++ b/post<RESET> <CYAN>@@ -1,13 +1,13 @@<RESET> Ada.Text_IO.Put_Line("Hello World<RED>!<RESET><GREEN>?<RESET>"); -1 1e<RED>-<RESET>10 16#FE12#E2 3.141_592 '<RED>x<RESET><GREEN>y<RESET>' +1 <RED>1e-10<RESET><GREEN>1e10<RESET> 16#FE12#E2 3.141_592 '<RED>x<RESET><GREEN>y<RESET>' <RED>a<RESET><GREEN>x<RESET>+<RED>b a<RESET><GREEN>y x<RESET>-<RED>b<RESET> <RED>a<RESET><GREEN>y<RESET> <GREEN>x<RESET>*<RED>b a<RESET><GREEN>y x<RESET>/<RED>b<RESET> diff --git a/t/t4035-diff-quiet.sh b/t/t4035-diff-quiet.sh index 231412d100..e8ae2a03fd 100755 --- a/t/t4035-diff-quiet.sh +++ b/t/t4035-diff-quiet.sh @@ -148,4 +148,10 @@ test_expect_success 'git diff --ignore-all-space, both files outside repo' ' ) ' +test_expect_success 'git diff --quiet ignores stat-change only entries' ' + test-chmtime +10 a && + echo modified >>b && + test_expect_code 1 git diff --quiet +' + test_done diff --git a/t/t4053-diff-no-index.sh b/t/t4053-diff-no-index.sh index 979e98398b..2ab3c48734 100755 --- a/t/t4053-diff-no-index.sh +++ b/t/t4053-diff-no-index.sh @@ -29,4 +29,30 @@ test_expect_success 'git diff --no-index relative path outside repo' ' ) ' +test_expect_success 'git diff --no-index with broken index' ' + ( + cd repo && + echo broken >.git/index && + git diff --no-index a ../non/git/a + ) +' + +test_expect_success 'git diff outside repo with broken index' ' + ( + cd repo && + git diff ../non/git/a ../non/git/b + ) +' + +test_expect_success 'git diff --no-index executed outside repo gives correct error message' ' + ( + GIT_CEILING_DIRECTORIES=$TRASH_DIRECTORY/non && + export GIT_CEILING_DIRECTORIES && + cd non/git && + test_must_fail git diff --no-index a 2>actual.err && + echo "usage: git diff --no-index <path> <path>" >expect.err && + test_cmp expect.err actual.err + ) +' + test_done diff --git a/t/t4055-diff-context.sh b/t/t4055-diff-context.sh index 97172b46b2..cd0454356a 100755 --- a/t/t4055-diff-context.sh +++ b/t/t4055-diff-context.sh @@ -73,7 +73,7 @@ test_expect_success 'plumbing not affected' ' test_expect_success 'non-integer config parsing' ' git config diff.context no && test_must_fail git diff 2>output && - test_i18ngrep "bad config value" output + test_i18ngrep "bad numeric config value" output ' test_expect_success 'negative integer config parsing' ' diff --git a/t/t4056-diff-order.sh b/t/t4056-diff-order.sh new file mode 100755 index 0000000000..c0460bb0e5 --- /dev/null +++ b/t/t4056-diff-order.sh @@ -0,0 +1,121 @@ +#!/bin/sh + +test_description='diff order' + +. ./test-lib.sh + +create_files () { + echo "$1" >a.h && + echo "$1" >b.c && + echo "$1" >c/Makefile && + echo "$1" >d.txt && + git add a.h b.c c/Makefile d.txt && + git commit -m"$1" +} + +test_expect_success 'setup' ' + mkdir c && + create_files 1 && + create_files 2 && + + cat >order_file_1 <<-\EOF && + *Makefile + *.txt + *.h + EOF + + cat >order_file_2 <<-\EOF && + *Makefile + *.h + *.c + EOF + + cat >expect_none <<-\EOF && + a.h + b.c + c/Makefile + d.txt + EOF + + cat >expect_1 <<-\EOF && + c/Makefile + d.txt + a.h + b.c + EOF + + cat >expect_2 <<-\EOF + c/Makefile + a.h + b.c + d.txt + EOF +' + +test_expect_success "no order (=tree object order)" ' + git diff --name-only HEAD^..HEAD >actual && + test_cmp expect_none actual +' + +test_expect_success 'missing orderfile' ' + rm -f bogus_file && + test_must_fail git diff -Obogus_file --name-only HEAD^..HEAD +' + +test_expect_success POSIXPERM,SANITY 'unreadable orderfile' ' + >unreadable_file && + chmod -r unreadable_file && + test_must_fail git diff -Ounreadable_file --name-only HEAD^..HEAD +' + +for i in 1 2 +do + test_expect_success "orderfile using option ($i)" ' + git diff -Oorder_file_$i --name-only HEAD^..HEAD >actual && + test_cmp expect_$i actual + ' + + test_expect_success PIPE "orderfile is fifo ($i)" ' + rm -f order_fifo && + mkfifo order_fifo && + { + cat order_file_$i >order_fifo & + } && + git diff -O order_fifo --name-only HEAD^..HEAD >actual && + wait && + test_cmp expect_$i actual + ' + + test_expect_success "orderfile using config ($i)" ' + git -c diff.orderfile=order_file_$i diff --name-only HEAD^..HEAD >actual && + test_cmp expect_$i actual + ' + + test_expect_success "cancelling configured orderfile ($i)" ' + git -c diff.orderfile=order_file_$i diff -O/dev/null --name-only HEAD^..HEAD >actual && + test_cmp expect_none actual + ' +done + +test_expect_success 'setup for testing combine-diff order' ' + git checkout -b tmp HEAD~ && + create_files 3 && + git checkout master && + git merge --no-commit -s ours tmp && + create_files 5 +' + +test_expect_success "combine-diff: no order (=tree object order)" ' + git diff --name-only HEAD HEAD^ HEAD^2 >actual && + test_cmp expect_none actual +' + +for i in 1 2 +do + test_expect_success "combine-diff: orderfile using option ($i)" ' + git diff -Oorder_file_$i --name-only HEAD HEAD^ HEAD^2 >actual && + test_cmp expect_$i actual + ' +done + +test_done diff --git a/t/t4057-diff-combined-paths.sh b/t/t4057-diff-combined-paths.sh new file mode 100755 index 0000000000..097e63215e --- /dev/null +++ b/t/t4057-diff-combined-paths.sh @@ -0,0 +1,106 @@ +#!/bin/sh + +test_description='combined diff show only paths that are different to all parents' + +. ./test-lib.sh + +# verify that diffc.expect matches output of +# `git diff -c --name-only HEAD HEAD^ HEAD^2` +diffc_verify () { + git diff -c --name-only HEAD HEAD^ HEAD^2 >diffc.actual && + test_cmp diffc.expect diffc.actual +} + +test_expect_success 'trivial merge - combine-diff empty' ' + for i in $(test_seq 1 9) + do + echo $i >$i.txt && + git add $i.txt + done && + git commit -m "init" && + git checkout -b side && + for i in $(test_seq 2 9) + do + echo $i/2 >>$i.txt + done && + git commit -a -m "side 2-9" && + git checkout master && + echo 1/2 >1.txt && + git commit -a -m "master 1" && + git merge side && + >diffc.expect && + diffc_verify +' + + +test_expect_success 'only one trully conflicting path' ' + git checkout side && + for i in $(test_seq 2 9) + do + echo $i/3 >>$i.txt + done && + echo "4side" >>4.txt && + git commit -a -m "side 2-9 +4" && + git checkout master && + for i in $(test_seq 1 9) + do + echo $i/3 >>$i.txt + done && + echo "4master" >>4.txt && + git commit -a -m "master 1-9 +4" && + test_must_fail git merge side && + cat <<-\EOF >4.txt && + 4 + 4/2 + 4/3 + 4master + 4side + EOF + git add 4.txt && + git commit -m "merge side (2)" && + echo 4.txt >diffc.expect && + diffc_verify +' + +test_expect_success 'merge introduces new file' ' + git checkout side && + for i in $(test_seq 5 9) + do + echo $i/4 >>$i.txt + done && + git commit -a -m "side 5-9" && + git checkout master && + for i in $(test_seq 1 3) + do + echo $i/4 >>$i.txt + done && + git commit -a -m "master 1-3 +4hello" && + git merge side && + echo "Hello World" >4hello.txt && + git add 4hello.txt && + git commit --amend && + echo 4hello.txt >diffc.expect && + diffc_verify +' + +test_expect_success 'merge removed a file' ' + git checkout side && + for i in $(test_seq 5 9) + do + echo $i/5 >>$i.txt + done && + git commit -a -m "side 5-9" && + git checkout master && + for i in $(test_seq 1 3) + do + echo $i/4 >>$i.txt + done && + git commit -a -m "master 1-3" && + git merge side && + git rm 4.txt && + git commit --amend && + echo 4.txt >diffc.expect && + diffc_verify +' + +test_done diff --git a/t/t4102-apply-rename.sh b/t/t4102-apply-rename.sh index e3ea3d5114..49e2d6c349 100755 --- a/t/t4102-apply-rename.sh +++ b/t/t4102-apply-rename.sh @@ -7,7 +7,6 @@ test_description='git apply handling copy/rename patch. ' . ./test-lib.sh -. "$TEST_DIRECTORY"/lib-prereq-FILEMODE.sh # setup diff --git a/t/t4103-apply-binary.sh b/t/t4103-apply-binary.sh index b1b906b1bb..1b420e3b5f 100755 --- a/t/t4103-apply-binary.sh +++ b/t/t4103-apply-binary.sh @@ -23,10 +23,10 @@ test_expect_success 'setup' ' git commit -m "Initial Version" 2>/dev/null && git checkout -b binary && - "$PERL_PATH" -pe "y/x/\000/" <file1 >file3 && + perl -pe "y/x/\000/" <file1 >file3 && cat file3 >file4 && git add file2 && - "$PERL_PATH" -pe "y/\000/v/" <file3 >file1 && + perl -pe "y/\000/v/" <file3 >file1 && rm -f file2 && git update-index --add --remove file1 file2 file3 file4 && git commit -m "Second Version" && diff --git a/t/t4116-apply-reverse.sh b/t/t4116-apply-reverse.sh index fca815392e..1e4d4380bf 100755 --- a/t/t4116-apply-reverse.sh +++ b/t/t4116-apply-reverse.sh @@ -12,14 +12,14 @@ test_description='git apply in reverse test_expect_success setup ' for i in a b c d e f g h i j k l m n; do echo $i; done >file1 && - "$PERL_PATH" -pe "y/ijk/\\000\\001\\002/" <file1 >file2 && + perl -pe "y/ijk/\\000\\001\\002/" <file1 >file2 && git add file1 file2 && git commit -m initial && git tag initial && for i in a b c g h i J K L m o n p q; do echo $i; done >file1 && - "$PERL_PATH" -pe "y/mon/\\000\\001\\002/" <file1 >file2 && + perl -pe "y/mon/\\000\\001\\002/" <file1 >file2 && git commit -a -m second && git tag second && @@ -48,12 +48,12 @@ test_expect_success 'apply in reverse' ' test_expect_success 'setup separate repository lacking postimage' ' - git tar-tree initial initial | $TAR xf - && + git archive --format=tar --prefix=initial/ initial | $TAR xf - && ( cd initial && git init && git add . ) && - git tar-tree second second | $TAR xf - && + git archive --format=tar --prefix=second/ second | $TAR xf - && ( cd second && git init && git add . ) diff --git a/t/t4120-apply-popt.sh b/t/t4120-apply-popt.sh index c5fecdfed4..497b62868d 100755 --- a/t/t4120-apply-popt.sh +++ b/t/t4120-apply-popt.sh @@ -6,7 +6,6 @@ test_description='git apply -p handling.' . ./test-lib.sh -. "$TEST_DIRECTORY"/lib-prereq-FILEMODE.sh test_expect_success setup ' mkdir sub && diff --git a/t/t4129-apply-samemode.sh b/t/t4129-apply-samemode.sh index 0d36ebdc86..c268298eaf 100755 --- a/t/t4129-apply-samemode.sh +++ b/t/t4129-apply-samemode.sh @@ -3,7 +3,6 @@ test_description='applying patch with mode bits' . ./test-lib.sh -. "$TEST_DIRECTORY"/lib-prereq-FILEMODE.sh test_expect_success setup ' echo original >file && diff --git a/t/t4200-rerere.sh b/t/t4200-rerere.sh index 7f6666fcd3..ed9c91e25b 100755 --- a/t/t4200-rerere.sh +++ b/t/t4200-rerere.sh @@ -78,7 +78,7 @@ test_expect_success 'activate rerere, old style (conflicting merge)' ' test_might_fail git config --unset rerere.enabled && test_must_fail git merge first && - sha1=$("$PERL_PATH" -pe "s/ .*//" .git/MERGE_RR) && + sha1=$(perl -pe "s/ .*//" .git/MERGE_RR) && rr=.git/rr-cache/$sha1 && grep "^=======\$" $rr/preimage && ! test -f $rr/postimage && @@ -91,7 +91,7 @@ test_expect_success 'rerere.enabled works, too' ' git reset --hard && test_must_fail git merge first && - sha1=$("$PERL_PATH" -pe "s/ .*//" .git/MERGE_RR) && + sha1=$(perl -pe "s/ .*//" .git/MERGE_RR) && rr=.git/rr-cache/$sha1 && grep ^=======$ $rr/preimage ' @@ -101,7 +101,7 @@ test_expect_success 'set up rr-cache' ' git config rerere.enabled true && git reset --hard && test_must_fail git merge first && - sha1=$("$PERL_PATH" -pe "s/ .*//" .git/MERGE_RR) && + sha1=$(perl -pe "s/ .*//" .git/MERGE_RR) && rr=.git/rr-cache/$sha1 ' @@ -172,7 +172,7 @@ test_expect_success 'first postimage wins' ' git show second^:a1 | sed "s/To die: t/To die! T/" >a1 && git commit -q -a -m third && - test_must_fail git pull . first && + test_must_fail git merge first && # rerere kicked in ! grep "^=======\$" a1 && test_cmp expect a1 @@ -185,7 +185,7 @@ test_expect_success 'rerere updates postimage timestamp' ' test_expect_success 'rerere clear' ' rm $rr/postimage && - echo "$sha1 a1" | "$PERL_PATH" -pe "y/\012/\000/" >.git/MERGE_RR && + echo "$sha1 a1" | perl -pe "y/\012/\000/" >.git/MERGE_RR && git rerere clear && ! test -d $rr ' diff --git a/t/t4201-shortlog.sh b/t/t4201-shortlog.sh index 5493500ef1..42866992cf 100755 --- a/t/t4201-shortlog.sh +++ b/t/t4201-shortlog.sh @@ -172,4 +172,20 @@ test_expect_success 'shortlog encoding' ' git shortlog HEAD~2.. > out && test_cmp expect out' +test_expect_success 'shortlog ignores commits with missing authors' ' + git commit --allow-empty -m normal && + git commit --allow-empty -m soon-to-be-broken && + git cat-file commit HEAD >commit.tmp && + sed "/^author/d" commit.tmp >broken.tmp && + commit=$(git hash-object -w -t commit --stdin <broken.tmp) && + git update-ref HEAD $commit && + cat >expect <<-\EOF && + A U Thor (1): + normal + + EOF + git shortlog HEAD~2.. >actual && + test_cmp expect actual +' + test_done diff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh index baa4685dcc..0dd8b65d7c 100755 --- a/t/t4203-mailmap.sh +++ b/t/t4203-mailmap.sh @@ -202,7 +202,8 @@ test_expect_success 'setup mailmap blob tests' ' Blob Guy <author@example.com> Blob Guy <bugs@company.xx> EOF - git add just-bugs both && + printf "Tricky Guy <author@example.com>" >no-newline && + git add just-bugs both no-newline && git commit -m "my mailmaps" && echo "Repo Guy <author@example.com>" >.mailmap && echo "Internal Guy <author@example.com>" >internal.map @@ -286,6 +287,19 @@ test_expect_success 'mailmap.blob defaults to HEAD:.mailmap in bare repo' ' ) ' +test_expect_success 'mailmap.blob can handle blobs without trailing newline' ' + cat >expect <<-\EOF && + Tricky Guy (1): + initial + + nick1 (1): + second + + EOF + git -c mailmap.blob=map:no-newline shortlog HEAD >actual && + test_cmp expect actual +' + test_expect_success 'cleanup after mailmap.blob tests' ' rm -f .mailmap ' @@ -470,4 +484,15 @@ test_expect_success 'Blame output (complex mapping)' ' test_cmp expect actual.fuzz ' +cat >expect <<\EOF +Some Dude <some@dude.xx> +EOF + +test_expect_success 'commit --author honors mailmap' ' + test_must_fail git commit --author "nick" --allow-empty -meight && + git commit --author "Some Dude" --allow-empty -meight && + git show --pretty=format:"%an <%ae>%n" >actual && + test_cmp expect actual +' + test_done diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index fb00041139..2a6278bb33 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -310,4 +310,19 @@ EOF test_cmp expected actual ' +test_expect_success 'log decoration properly follows tag chain' ' + git tag -a tag1 -m tag1 && + git tag -a tag2 -m tag2 tag1 && + git tag -d tag1 && + git commit --amend -m shorter && + git log --no-walk --tags --pretty="%H %d" --decorate=full >actual && + cat <<EOF >expected && +6a908c10688b2503073c39c9ba26322c73902bb5 (tag: refs/tags/tag2) +9f716384d92283fb915a4eee5073f030638e05f9 (tag: refs/tags/message-one) +b87e4cccdb77336ea79d89224737be7ea8e95367 (tag: refs/tags/message-two) +EOF + sort actual >actual1 && + test_cmp expected actual1 +' + test_done diff --git a/t/t4208-log-magic-pathspec.sh b/t/t4208-log-magic-pathspec.sh index 72300b5f24..d8f23f488e 100755 --- a/t/t4208-log-magic-pathspec.sh +++ b/t/t4208-log-magic-pathspec.sh @@ -46,4 +46,19 @@ test_expect_success 'git log HEAD -- :/' ' test_cmp expected actual ' +test_expect_success 'command line pathspec parsing for "git log"' ' + git reset --hard && + >a && + git add a && + git commit -m "add an empty a" --allow-empty && + echo 1 >a && + git commit -a -m "update a to 1" && + git checkout HEAD^ && + echo 2 >a && + git commit -a -m "update a to 2" && + test_must_fail git merge master && + git add a && + git log --merge -- a +' + test_done diff --git a/t/t4211-line-log.sh b/t/t4211-line-log.sh index 7665d6785c..7369d3c517 100755 --- a/t/t4211-line-log.sh +++ b/t/t4211-line-log.sh @@ -48,7 +48,7 @@ canned_test "-M -L '/long f/,/^}/:b.c' move-support" move-support-f canned_test "-M -L ':f:b.c' parallel-change" parallel-change-f-to-main canned_test "-L 4,12:a.c -L :main:a.c simple" multiple -canned_test "-L 4,18:a.c -L :main:a.c simple" multiple-overlapping +canned_test "-L 4,18:a.c -L ^:main:a.c simple" multiple-overlapping canned_test "-L :main:a.c -L 4,18:a.c simple" multiple-overlapping canned_test "-L 4:a.c -L 8,12:a.c simple" multiple-superset canned_test "-L 8,12:a.c -L 4:a.c simple" multiple-superset @@ -64,17 +64,34 @@ test_bad_opts "-L 1,1000:b.c" "has only.*lines" test_bad_opts "-L :b.c" "argument.*not of the form" test_bad_opts "-L :foo:b.c" "no match" -# There is a separate bug when an empty -L range is the first -L encountered, -# thus to demonstrate this particular bug, the empty -L range must follow a -# non-empty -L range. -test_expect_success '-L {empty-range} (any -L)' ' +test_expect_success '-L X (X == nlines)' ' + n=$(wc -l <b.c) && + git log -L $n:b.c +' + +test_expect_success '-L X (X == nlines + 1)' ' n=$(expr $(wc -l <b.c) + 1) && - git log -L1,1:b.c -L$n:b.c + test_must_fail git log -L $n:b.c +' + +test_expect_success '-L X (X == nlines + 2)' ' + n=$(expr $(wc -l <b.c) + 2) && + test_must_fail git log -L $n:b.c ' -test_expect_success '-L {empty-range} (first -L)' ' +test_expect_success '-L ,Y (Y == nlines)' ' + n=$(printf "%d" $(wc -l <b.c)) && + git log -L ,$n:b.c +' + +test_expect_success '-L ,Y (Y == nlines + 1)' ' n=$(expr $(wc -l <b.c) + 1) && - git log -L$n:b.c + test_must_fail git log -L ,$n:b.c +' + +test_expect_success '-L ,Y (Y == nlines + 2)' ' + n=$(expr $(wc -l <b.c) + 2) && + test_must_fail git log -L ,$n:b.c ' test_done diff --git a/t/t4212-log-corrupt.sh b/t/t4212-log-corrupt.sh index ec5099b83d..3fa171541a 100755 --- a/t/t4212-log-corrupt.sh +++ b/t/t4212-log-corrupt.sh @@ -13,11 +13,16 @@ test_expect_success 'setup' ' git update-ref refs/heads/broken_email $(cat broken_email.hash) ' +test_expect_success 'fsck notices broken commit' ' + git fsck 2>actual && + test_i18ngrep invalid.author actual +' + test_expect_success 'git log with broken author email' ' { echo commit $(cat broken_email.hash) echo "Author: A U Thor <author@example.com>" - echo "Date: Thu Jan 1 00:00:00 1970 +0000" + echo "Date: Thu Apr 7 15:13:13 2005 -0700" echo echo " foo" } >expect.out && @@ -30,7 +35,7 @@ test_expect_success 'git log with broken author email' ' ' test_expect_success 'git log --format with broken author email' ' - echo "A U Thor+author@example.com+" >expect.out && + echo "A U Thor+author@example.com+Thu Apr 7 15:13:13 2005 -0700" >expect.out && : >expect.err && git log --format="%an+%ae+%ad" broken_email >actual.out 2>actual.err && @@ -39,4 +44,49 @@ test_expect_success 'git log --format with broken author email' ' test_cmp expect.err actual.err ' +munge_author_date () { + git cat-file commit "$1" >commit.orig && + sed "s/^\(author .*>\) [0-9]*/\1 $2/" <commit.orig >commit.munge && + git hash-object -w -t commit commit.munge +} + +test_expect_success 'unparsable dates produce sentinel value' ' + commit=$(munge_author_date HEAD totally_bogus) && + echo "Date: Thu Jan 1 00:00:00 1970 +0000" >expect && + git log -1 $commit >actual.full && + grep Date <actual.full >actual && + test_cmp expect actual +' + +test_expect_success 'unparsable dates produce sentinel value (%ad)' ' + commit=$(munge_author_date HEAD totally_bogus) && + echo >expect && + git log -1 --format=%ad $commit >actual + test_cmp expect actual +' + +# date is 2^64 + 1 +test_expect_success 'date parser recognizes integer overflow' ' + commit=$(munge_author_date HEAD 18446744073709551617) && + echo "Thu Jan 1 00:00:00 1970 +0000" >expect && + git log -1 --format=%ad $commit >actual && + test_cmp expect actual +' + +# date is 2^64 - 2 +test_expect_success 'date parser recognizes time_t overflow' ' + commit=$(munge_author_date HEAD 18446744073709551614) && + echo "Thu Jan 1 00:00:00 1970 +0000" >expect && + git log -1 --format=%ad $commit >actual && + test_cmp expect actual +' + +# date is within 2^63-1, but enough to choke glibc's gmtime +test_expect_success 'absurdly far-in-future dates produce sentinel' ' + commit=$(munge_author_date HEAD 999999999999999999) && + echo "Thu Jan 1 00:00:00 1970 +0000" >expect && + git log -1 --format=%ad $commit >actual && + test_cmp expect actual +' + test_done diff --git a/t/t4254-am-corrupt.sh b/t/t4254-am-corrupt.sh index b7da95fac5..85716dd6ec 100755 --- a/t/t4254-am-corrupt.sh +++ b/t/t4254-am-corrupt.sh @@ -3,20 +3,19 @@ test_description='git am with corrupt input' . ./test-lib.sh -# Note the missing "+++" line: -cat > bad-patch.diff <<'EOF' -From: A U Thor <au.thor@example.com> -diff --git a/f b/f -index 7898192..6178079 100644 ---- a/f -@@ -1 +1 @@ --a -+b -EOF - test_expect_success setup ' - test $? = 0 && - echo a > f && + # Note the missing "+++" line: + cat >bad-patch.diff <<-\EOF && + From: A U Thor <au.thor@example.com> + diff --git a/f b/f + index 7898192..6178079 100644 + --- a/f + @@ -1 +1 @@ + -a + +b + EOF + + echo a >f && git add f && test_tick && git commit -m initial @@ -26,17 +25,12 @@ test_expect_success setup ' # fatal: unable to write file '(null)' mode 100644: Bad address # Also, it had the unwanted side-effect of deleting f. test_expect_success 'try to apply corrupted patch' ' - git am bad-patch.diff 2> actual - test $? = 1 + test_must_fail git am bad-patch.diff 2>actual ' -cat > expected <<EOF -fatal: git diff header lacks filename information (line 4) -EOF - test_expect_success 'compare diagnostic; ensure file is still here' ' - test $? = 0 && - test -f f && + echo "fatal: git diff header lacks filename information (line 4)" >expected && + test_path_is_file f && test_cmp expected actual ' diff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh index c2023b1a3d..1cf0a4e103 100755 --- a/t/t5000-tar-tree.sh +++ b/t/t5000-tar-tree.sh @@ -3,7 +3,7 @@ # Copyright (C) 2005 Rene Scharfe # -test_description='git tar-tree and git get-tar-commit-id test +test_description='git archive and git get-tar-commit-id test This test covers the topics of file contents, commit date handling and commit id embedding: @@ -13,11 +13,11 @@ commit id embedding: binary file (/bin/sh). Only paths shorter than 99 characters are used. - git tar-tree applies the commit date to every file in the archive it + git archive applies the commit date to every file in the archive it creates. The test sets the commit date to a specific value and checks if the tar archive contains that value. - When giving git tar-tree a commit id (in contrast to a tree id) it + When giving git archive a commit id (in contrast to a tree id) it embeds this commit id into the tar archive as a comment. The test checks the ability of git get-tar-commit-id to figure it out from the tar file. @@ -25,8 +25,6 @@ commit id embedding: ' . ./test-lib.sh -GZIP=${GZIP:-gzip} -GUNZIP=${GUNZIP:-gzip -d} SUBSTFORMAT=%H%n @@ -39,6 +37,8 @@ test_lazy_prereq TAR_NEEDS_PAX_FALLBACK ' ) ' +test_lazy_prereq GZIP 'gzip --version' + get_pax_header() { file=$1 header=$2= @@ -196,16 +196,6 @@ test_expect_success \ 'git get-tar-commit-id <b.tar >b.commitid && test_cmp .git/$(git symbolic-ref HEAD) b.commitid' -test_expect_success 'git tar-tree' ' - git tar-tree HEAD >tar-tree.tar && - test_cmp b.tar tar-tree.tar -' - -test_expect_success 'git tar-tree with prefix' ' - git tar-tree HEAD prefix >tar-tree_with_prefix.tar && - test_cmp with_prefix.tar tar-tree_with_prefix.tar -' - test_expect_success 'git archive with --output, override inferred format' ' git archive --format=tar --output=d4.zip HEAD && test_cmp b.tar d4.zip @@ -223,6 +213,15 @@ test_expect_success 'clients cannot access unreachable commits' ' test_must_fail git archive --remote=. $sha1 >remote.tar ' +test_expect_success 'upload-archive can allow unreachable commits' ' + test_commit unreachable1 && + sha1=`git rev-parse HEAD` && + git reset --hard HEAD^ && + git archive $sha1 >remote.tar && + test_config uploadarchive.allowUnreachable true && + git archive --remote=. $sha1 >remote.tar +' + test_expect_success 'setup tar filters' ' git config tar.tar.foo.command "tr ab ba" && git config tar.bar.command "tr ab ba" && @@ -275,12 +274,6 @@ test_expect_success 'only enabled filters are available remotely' ' test_cmp remote.bar config.bar ' -if $GZIP --version >/dev/null 2>&1; then - test_set_prereq GZIP -else - say "Skipping some tar.gz tests because gzip not found" -fi - test_expect_success GZIP 'git archive --format=tgz' ' git archive --format=tgz HEAD >j.tgz ' @@ -300,14 +293,8 @@ test_expect_success GZIP 'infer tgz from .tar.gz filename' ' test_cmp j.tgz j3.tar.gz ' -if $GUNZIP --version >/dev/null 2>&1; then - test_set_prereq GUNZIP -else - say "Skipping some tar.gz tests because gunzip was not found" -fi - -test_expect_success GZIP,GUNZIP 'extract tgz file' ' - $GUNZIP -c <j.tgz >j.tar && +test_expect_success GZIP 'extract tgz file' ' + gzip -d -c <j.tgz >j.tar && test_cmp b.tar j.tar ' diff --git a/t/t5001-archive-attr.sh b/t/t5001-archive-attr.sh index f47d8717fd..51dedab29b 100755 --- a/t/t5001-archive-attr.sh +++ b/t/t5001-archive-attr.sh @@ -87,14 +87,4 @@ test_expect_success 'export-subst' ' test_cmp substfile2 archive/substfile2 ' -test_expect_success 'git tar-tree vs. git archive with worktree attributes' ' - git tar-tree HEAD >tar-tree.tar && - test_cmp worktree.tar tar-tree.tar -' - -test_expect_success 'git tar-tree vs. git archive with worktree attrs, bare' ' - (cd bare && git tar-tree HEAD) >bare-tar-tree.tar && - test_cmp bare-worktree.tar bare-tar-tree.tar -' - test_done diff --git a/t/t5150-request-pull.sh b/t/t5150-request-pull.sh index 1afa0d5c44..75d6b3843a 100755 --- a/t/t5150-request-pull.sh +++ b/t/t5150-request-pull.sh @@ -86,7 +86,7 @@ test_expect_success 'setup: two scripts for reading pull requests' ' s/[-0-9]\{10\} [:0-9]\{8\} [-+][0-9]\{4\}/DATE/g s/ [^ ].*/ SUBJECT/g s/ [^ ].* (DATE)/ SUBJECT (DATE)/g - s/for-upstream/BRANCH/g + s|tags/full|BRANCH|g s/mnemonic.txt/FILENAME/g s/^version [0-9]/VERSION/ /^ FILENAME | *[0-9]* [-+]*\$/ b diffstat @@ -127,7 +127,7 @@ test_expect_success 'pull request when forgot to push' ' test_must_fail git request-pull initial "$downstream_url" \ 2>../err ) && - grep "No branch of.*is at:\$" err && + grep "No match for commit .*" err && grep "Are you sure you pushed" err ' @@ -141,7 +141,7 @@ test_expect_success 'pull request after push' ' git checkout initial && git merge --ff-only master && git push origin master:for-upstream && - git request-pull initial origin >../request + git request-pull initial origin master:for-upstream >../request ) && sed -nf read-request.sed <request >digest && cat digest && @@ -160,7 +160,7 @@ test_expect_success 'pull request after push' ' ' -test_expect_success 'request names an appropriate branch' ' +test_expect_success 'request asks HEAD to be pulled' ' rm -fr downstream.git && git init --bare downstream.git && @@ -179,7 +179,7 @@ test_expect_success 'request names an appropriate branch' ' read repository && read branch } <digest && - test "$branch" = tags/full + test -z "$branch" ' @@ -212,12 +212,18 @@ test_expect_success 'pull request format' ' cd local && git checkout initial && git merge --ff-only master && - git push origin master:for-upstream && - git request-pull initial "$downstream_url" >../request + git push origin tags/full && + git request-pull initial "$downstream_url" tags/full >../request ) && <request sed -nf fuzz.sed >request.fuzzy && - test_i18ncmp expect request.fuzzy + test_i18ncmp expect request.fuzzy && + ( + cd local && + git request-pull initial "$downstream_url" tags/full:refs/tags/full + ) >request && + sed -nf fuzz.sed <request >request.fuzzy && + test_i18ncmp expect request.fuzzy ' test_expect_success 'request-pull ignores OPTIONS_KEEPDASHDASH poison' ' @@ -229,7 +235,7 @@ test_expect_success 'request-pull ignores OPTIONS_KEEPDASHDASH poison' ' git checkout initial && git merge --ff-only master && git push origin master:for-upstream && - git request-pull -- initial "$downstream_url" >../request + git request-pull -- initial "$downstream_url" master:for-upstream >../request ) ' diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh index a07c871797..20c1961515 100755 --- a/t/t5300-pack-object.sh +++ b/t/t5300-pack-object.sh @@ -13,9 +13,9 @@ TRASH=`pwd` test_expect_success \ 'setup' \ 'rm -f .git/index* && - "$PERL_PATH" -e "print \"a\" x 4096;" > a && - "$PERL_PATH" -e "print \"b\" x 4096;" > b && - "$PERL_PATH" -e "print \"c\" x 4096;" > c && + perl -e "print \"a\" x 4096;" > a && + perl -e "print \"b\" x 4096;" > b && + perl -e "print \"c\" x 4096;" > c && test-genrandom "seed a" 2097152 > a_big && test-genrandom "seed b" 2097152 > b_big && git update-index --add a a_big b b_big c && @@ -129,7 +129,7 @@ test_expect_success \ cd "$TRASH" test_expect_success 'compare delta flavors' ' - "$PERL_PATH" -e '\'' + perl -e '\'' defined($_ = -s $_) or die for @ARGV; exit 1 if $ARGV[0] <= $ARGV[1]; '\'' test-2-$packname_2.pack test-3-$packname_3.pack @@ -151,7 +151,7 @@ test_expect_success \ git cat-file $t $object || return 1 done <obj-list } >current && - test_cmp expect current' + cmp expect current' test_expect_success \ 'use packed deltified (REF_DELTA) objects' \ @@ -166,7 +166,7 @@ test_expect_success \ git cat-file $t $object || return 1 done <obj-list } >current && - test_cmp expect current' + cmp expect current' test_expect_success \ 'use packed deltified (OFS_DELTA) objects' \ @@ -181,7 +181,7 @@ test_expect_success \ git cat-file $t $object || return 1 done <obj-list } >current && - test_cmp expect current' + cmp expect current' unset GIT_OBJECT_DIRECTORY @@ -195,9 +195,9 @@ test_expect_success 'survive missing objects/pack directory' ' rm -fr $GOP && git index-pack --stdin --keep=test <../test-3-${packname_3}.pack && test -f $GOP/pack-${packname_3}.pack && - test_cmp $GOP/pack-${packname_3}.pack ../test-3-${packname_3}.pack && + cmp $GOP/pack-${packname_3}.pack ../test-3-${packname_3}.pack && test -f $GOP/pack-${packname_3}.idx && - test_cmp $GOP/pack-${packname_3}.idx ../test-3-${packname_3}.idx && + cmp $GOP/pack-${packname_3}.idx ../test-3-${packname_3}.idx && test -f $GOP/pack-${packname_3}.keep ) ' diff --git a/t/t5302-pack-index.sh b/t/t5302-pack-index.sh index fe82025d4a..4bbb718751 100755 --- a/t/t5302-pack-index.sh +++ b/t/t5302-pack-index.sh @@ -174,11 +174,11 @@ test_expect_success \ test_expect_success \ '[index v1] 5) pack-objects happily reuses corrupted data' \ 'pack4=$(git pack-objects test-4 <obj-list) && - test -f "test-4-${pack1}.pack"' + test -f "test-4-${pack4}.pack"' test_expect_success \ '[index v1] 6) newly created pack is BAD !' \ - 'test_must_fail git verify-pack -v "test-4-${pack1}.pack"' + 'test_must_fail git verify-pack -v "test-4-${pack4}.pack"' test_expect_success \ '[index v2] 1) stream pack to repository' \ diff --git a/t/t5303-pack-corruption-resilience.sh b/t/t5303-pack-corruption-resilience.sh index 35926debe3..663b02bbb1 100755 --- a/t/t5303-pack-corruption-resilience.sh +++ b/t/t5303-pack-corruption-resilience.sh @@ -98,7 +98,7 @@ test_expect_success \ 'create_new_pack && git prune-packed && chmod +w ${pack}.pack && - "$PERL_PATH" -i.bak -pe "s/ base /abcdef/" ${pack}.pack && + perl -i.bak -pe "s/ base /abcdef/" ${pack}.pack && test_must_fail git cat-file blob $blob_1 > /dev/null && test_must_fail git cat-file blob $blob_2 > /dev/null && test_must_fail git cat-file blob $blob_3 > /dev/null' @@ -155,7 +155,7 @@ test_expect_success \ 'create_new_pack && git prune-packed && chmod +w ${pack}.pack && - "$PERL_PATH" -i.bak -pe "s/ delta1 /abcdefgh/" ${pack}.pack && + perl -i.bak -pe "s/ delta1 /abcdefgh/" ${pack}.pack && git cat-file blob $blob_1 > /dev/null && test_must_fail git cat-file blob $blob_2 > /dev/null && test_must_fail git cat-file blob $blob_3 > /dev/null' diff --git a/t/t5304-prune.sh b/t/t5304-prune.sh index e4bb3a1457..66c9a41739 100755 --- a/t/t5304-prune.sh +++ b/t/t5304-prune.sh @@ -221,4 +221,14 @@ EOF test_cmp expected actual ' +test_expect_success 'prune .git/shallow' ' + SHA1=`echo hi|git commit-tree HEAD^{tree}` && + echo $SHA1 >.git/shallow && + git prune --dry-run >out && + grep $SHA1 .git/shallow && + grep $SHA1 out && + git prune && + ! test -f .git/shallow +' + test_done diff --git a/t/t5305-include-tag.sh b/t/t5305-include-tag.sh index b061864a87..21517c70cd 100755 --- a/t/t5305-include-tag.sh +++ b/t/t5305-include-tag.sh @@ -45,9 +45,7 @@ test_expect_success 'unpack objects' ' test_expect_success 'check unpacked result (have commit, no tag)' ' git rev-list --objects $commit >list.expect && ( - GIT_DIR=clone.git && - export GIT_DIR && - test_must_fail git cat-file -e $tag && + test_must_fail env GIT_DIR=clone.git git cat-file -e $tag && git rev-list --objects $commit ) >list.actual && test_cmp list.expect list.actual diff --git a/t/t5308-pack-detect-duplicates.sh b/t/t5308-pack-detect-duplicates.sh new file mode 100755 index 0000000000..9c5a8766ab --- /dev/null +++ b/t/t5308-pack-detect-duplicates.sh @@ -0,0 +1,80 @@ +#!/bin/sh + +test_description='handling of duplicate objects in incoming packfiles' +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-pack.sh + +# The sha1s we have in our pack. It's important that these have the same +# starting byte, so that they end up in the same fanout section of the index. +# That lets us make sure we are exercising the binary search with both sets. +LO_SHA1=e68fe8129b546b101aee9510c5328e7f21ca1d18 +HI_SHA1=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 + +# And here's a "missing sha1" which will produce failed lookups. It must also +# be in the same fanout section, and should be between the two (so that during +# our binary search, we are sure to end up looking at one or the other of the +# duplicate runs). +MISSING_SHA1='e69d000000000000000000000000000000000000' + +# git will never intentionally create packfiles with +# duplicate objects, so we have to construct them by hand. +# +# $1 is the name of the packfile to create +# +# $2 is the number of times to duplicate each object +create_pack () { + pack_header "$((2 * $2))" >"$1" && + for i in $(test_seq 1 "$2"); do + pack_obj $LO_SHA1 && + pack_obj $HI_SHA1 + done >>"$1" && + pack_trailer "$1" +} + +# double-check that create_pack actually works +test_expect_success 'pack with no duplicates' ' + create_pack no-dups.pack 1 && + git index-pack --stdin <no-dups.pack +' + +test_expect_success 'index-pack will allow duplicate objects by default' ' + clear_packs && + create_pack dups.pack 100 && + git index-pack --stdin <dups.pack +' + +test_expect_success 'create batch-check test vectors' ' + cat >input <<-EOF && + $LO_SHA1 + $HI_SHA1 + $MISSING_SHA1 + EOF + cat >expect <<-EOF + $LO_SHA1 blob 2 + $HI_SHA1 blob 0 + $MISSING_SHA1 missing + EOF +' + +test_expect_success 'lookup in duplicated pack (binary search)' ' + git cat-file --batch-check <input >actual && + test_cmp expect actual +' + +test_expect_success 'lookup in duplicated pack (GIT_USE_LOOKUP)' ' + ( + GIT_USE_LOOKUP=1 && + export GIT_USE_LOOKUP && + git cat-file --batch-check <input >actual + ) && + test_cmp expect actual +' + +test_expect_success 'index-pack can reject packs with duplicates' ' + clear_packs && + create_pack dups.pack 2 && + test_must_fail git index-pack --strict --stdin <dups.pack && + test_expect_code 1 git cat-file -e $LO_SHA1 +' + +test_done diff --git a/t/t5309-pack-delta-cycles.sh b/t/t5309-pack-delta-cycles.sh new file mode 100755 index 0000000000..3e7861b075 --- /dev/null +++ b/t/t5309-pack-delta-cycles.sh @@ -0,0 +1,77 @@ +#!/bin/sh + +test_description='test index-pack handling of delta cycles in packfiles' +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-pack.sh + +# Two similar-ish objects that we have computed deltas between. +A=01d7713666f4de822776c7622c10f1b07de280dc +B=e68fe8129b546b101aee9510c5328e7f21ca1d18 + +# double-check our hand-constucted packs +test_expect_success 'index-pack works with a single delta (A->B)' ' + clear_packs && + { + pack_header 2 && + pack_obj $A $B && + pack_obj $B + } >ab.pack && + pack_trailer ab.pack && + git index-pack --stdin <ab.pack && + git cat-file -t $A && + git cat-file -t $B +' + +test_expect_success 'index-pack works with a single delta (B->A)' ' + clear_packs && + { + pack_header 2 && + pack_obj $A && + pack_obj $B $A + } >ba.pack && + pack_trailer ba.pack && + git index-pack --stdin <ba.pack && + git cat-file -t $A && + git cat-file -t $B +' + +test_expect_success 'index-pack detects missing base objects' ' + clear_packs && + { + pack_header 1 && + pack_obj $A $B + } >missing.pack && + pack_trailer missing.pack && + test_must_fail git index-pack --fix-thin --stdin <missing.pack +' + +test_expect_success 'index-pack detects REF_DELTA cycles' ' + clear_packs && + { + pack_header 2 && + pack_obj $A $B && + pack_obj $B $A + } >cycle.pack && + pack_trailer cycle.pack && + test_must_fail git index-pack --fix-thin --stdin <cycle.pack +' + +test_expect_failure 'failover to an object in another pack' ' + clear_packs && + git index-pack --stdin <ab.pack && + git index-pack --stdin --fix-thin <cycle.pack +' + +test_expect_failure 'failover to a duplicate object in the same pack' ' + clear_packs && + { + pack_header 3 && + pack_obj $A $B && + pack_obj $B $A && + pack_obj $A + } >recoverable.pack && + pack_trailer recoverable.pack && + git index-pack --fix-thin --stdin <recoverable.pack +' + +test_done diff --git a/t/t5310-pack-bitmaps.sh b/t/t5310-pack-bitmaps.sh new file mode 100755 index 0000000000..f13525caa3 --- /dev/null +++ b/t/t5310-pack-bitmaps.sh @@ -0,0 +1,142 @@ +#!/bin/sh + +test_description='exercise basic bitmap functionality' +. ./test-lib.sh + +test_expect_success 'setup repo with moderate-sized history' ' + for i in $(test_seq 1 10); do + test_commit $i + done && + git checkout -b other HEAD~5 && + for i in $(test_seq 1 10); do + test_commit side-$i + done && + git checkout master && + blob=$(echo tagged-blob | git hash-object -w --stdin) && + git tag tagged-blob $blob && + git config pack.writebitmaps true && + git config pack.writebitmaphashcache true +' + +test_expect_success 'full repack creates bitmaps' ' + git repack -ad && + ls .git/objects/pack/ | grep bitmap >output && + test_line_count = 1 output +' + +test_expect_success 'rev-list --test-bitmap verifies bitmaps' ' + git rev-list --test-bitmap HEAD +' + +rev_list_tests() { + state=$1 + + test_expect_success "counting commits via bitmap ($state)" ' + git rev-list --count HEAD >expect && + git rev-list --use-bitmap-index --count HEAD >actual && + test_cmp expect actual + ' + + test_expect_success "counting partial commits via bitmap ($state)" ' + git rev-list --count HEAD~5..HEAD >expect && + git rev-list --use-bitmap-index --count HEAD~5..HEAD >actual && + test_cmp expect actual + ' + + test_expect_success "counting non-linear history ($state)" ' + git rev-list --count other...master >expect && + git rev-list --use-bitmap-index --count other...master >actual && + test_cmp expect actual + ' + + test_expect_success "enumerate --objects ($state)" ' + git rev-list --objects --use-bitmap-index HEAD >tmp && + cut -d" " -f1 <tmp >tmp2 && + sort <tmp2 >actual && + git rev-list --objects HEAD >tmp && + cut -d" " -f1 <tmp >tmp2 && + sort <tmp2 >expect && + test_cmp expect actual + ' + + test_expect_success "bitmap --objects handles non-commit objects ($state)" ' + git rev-list --objects --use-bitmap-index HEAD tagged-blob >actual && + grep $blob actual + ' +} + +rev_list_tests 'full bitmap' + +test_expect_success 'clone from bitmapped repository' ' + git clone --no-local --bare . clone.git && + git rev-parse HEAD >expect && + git --git-dir=clone.git rev-parse HEAD >actual && + test_cmp expect actual +' + +test_expect_success 'setup further non-bitmapped commits' ' + for i in $(test_seq 1 10); do + test_commit further-$i + done +' + +rev_list_tests 'partial bitmap' + +test_expect_success 'fetch (partial bitmap)' ' + git --git-dir=clone.git fetch origin master:master && + git rev-parse HEAD >expect && + git --git-dir=clone.git rev-parse HEAD >actual && + test_cmp expect actual +' + +test_expect_success 'incremental repack cannot create bitmaps' ' + test_commit more-1 && + find .git/objects/pack -name "*.bitmap" >expect && + git repack -d && + find .git/objects/pack -name "*.bitmap" >actual && + test_cmp expect actual +' + +test_expect_success 'incremental repack can disable bitmaps' ' + test_commit more-2 && + git repack -d --no-write-bitmap-index +' + +test_expect_success 'full repack, reusing previous bitmaps' ' + git repack -ad && + ls .git/objects/pack/ | grep bitmap >output && + test_line_count = 1 output +' + +test_expect_success 'fetch (full bitmap)' ' + git --git-dir=clone.git fetch origin master:master && + git rev-parse HEAD >expect && + git --git-dir=clone.git rev-parse HEAD >actual && + test_cmp expect actual +' + +test_lazy_prereq JGIT ' + type jgit +' + +test_expect_success JGIT 'we can read jgit bitmaps' ' + git clone . compat-jgit && + ( + cd compat-jgit && + rm -f .git/objects/pack/*.bitmap && + jgit gc && + git rev-list --test-bitmap HEAD + ) +' + +test_expect_success JGIT 'jgit can read our bitmaps' ' + git clone . compat-us && + ( + cd compat-us && + git repack -adb && + # jgit gc will barf if it does not like our bitmaps + jgit gc + ) +' + +test_done diff --git a/t/t5400-send-pack.sh b/t/t5400-send-pack.sh index 129fc88bd2..0736bcbcd5 100755 --- a/t/t5400-send-pack.sh +++ b/t/t5400-send-pack.sh @@ -164,6 +164,7 @@ test_expect_success 'receive-pack runs auto-gc in remote repo' ' # Set the child to auto-pack if more than one pack exists cd child && git config gc.autopacklimit 1 && + git config gc.autodetach false && git branch test_auto_gc && # And create a file that follows the temporary object naming # convention for the auto-gc to remove diff --git a/t/t5500-fetch-pack.sh b/t/t5500-fetch-pack.sh index fd2598e601..5b2b1c2c13 100755 --- a/t/t5500-fetch-pack.sh +++ b/t/t5500-fetch-pack.sh @@ -393,6 +393,17 @@ test_expect_success 'fetch in shallow repo unreachable shallow objects' ' git fsck --no-dangling ) ' +test_expect_success 'fetch creating new shallow root' ' + ( + git clone "file://$(pwd)/." shallow10 && + git commit --allow-empty -m empty && + cd shallow10 && + git fetch --depth=1 --progress 2>actual && + # This should fetch only the empty commit, no tree or + # blob objects + grep "remote: Total 1" actual + ) +' test_expect_success 'setup tests for the --stdin parameter' ' for head in C D E F @@ -505,4 +516,107 @@ test_expect_success 'test --all, --depth, and explicit tag' ' ) >out-adt 2>error-adt ' +test_expect_success 'shallow fetch with tags does not break the repository' ' + mkdir repo1 && + ( + cd repo1 && + git init && + test_commit 1 && + test_commit 2 && + test_commit 3 && + mkdir repo2 && + cd repo2 && + git init && + git fetch --depth=2 ../.git master:branch && + git fsck + ) +' +check_prot_path () { + cat >expected <<-EOF && + Diag: url=$1 + Diag: protocol=$2 + Diag: path=$3 + EOF + git fetch-pack --diag-url "$1" | grep -v hostandport= >actual && + test_cmp expected actual +} + +check_prot_host_path () { + cat >expected <<-EOF && + Diag: url=$1 + Diag: protocol=$2 + Diag: hostandport=$3 + Diag: path=$4 + EOF + git fetch-pack --diag-url "$1" >actual && + test_cmp expected actual +} + +for r in repo re:po re/po +do + # git or ssh with scheme + for p in "ssh+git" "git+ssh" git ssh + do + for h in host host:12 [::1] [::1]:23 + do + case "$p" in + *ssh*) + pp=ssh + ;; + *) + pp=$p + ;; + esac + test_expect_success "fetch-pack --diag-url $p://$h/$r" ' + check_prot_host_path $p://$h/$r $pp "$h" "/$r" + ' + # "/~" -> "~" conversion + test_expect_success "fetch-pack --diag-url $p://$h/~$r" ' + check_prot_host_path $p://$h/~$r $pp "$h" "~$r" + ' + done + done + # file with scheme + for p in file + do + test_expect_success "fetch-pack --diag-url $p://$h/$r" ' + check_prot_path $p://$h/$r $p "/$r" + ' + # No "/~" -> "~" conversion for file + test_expect_success "fetch-pack --diag-url $p://$h/~$r" ' + check_prot_path $p://$h/~$r $p "/~$r" + ' + done + # file without scheme + for h in nohost nohost:12 [::1] [::1]:23 [ [:aa + do + test_expect_success "fetch-pack --diag-url ./$h:$r" ' + check_prot_path ./$h:$r $p "./$h:$r" + ' + # No "/~" -> "~" conversion for file + test_expect_success "fetch-pack --diag-url ./$p:$h/~$r" ' + check_prot_path ./$p:$h/~$r $p "./$p:$h/~$r" + ' + done + #ssh without scheme + p=ssh + for h in host [::1] + do + test_expect_success "fetch-pack --diag-url $h:$r" ' + check_prot_path $h:$r $p "$r" + ' + # Do "/~" -> "~" conversion + test_expect_success "fetch-pack --diag-url $h:/~$r" ' + check_prot_host_path $h:/~$r $p "$h" "~$r" + ' + done +done + +test_expect_success MINGW 'fetch-pack --diag-url file://c:/repo' ' + check_prot_path file://c:/repo file c:/repo +' +test_expect_success MINGW 'fetch-pack --diag-url c:repo' ' + check_prot_path c:repo file c:repo +' + test_done diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index 8f6e3922dc..ac79dd915d 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -160,9 +160,7 @@ cat >test/expect <<EOF * remote two Fetch URL: ../two Push URL: ../three - HEAD branch (remote HEAD is ambiguous, may be one of the following): - another - master + HEAD branch: master Local refs configured for 'git push': ahead forces to master (fast-forwardable) master pushes to another (up to date) @@ -262,16 +260,12 @@ test_expect_success 'set-head --auto' ' ) ' -cat >test/expect <<\EOF -error: Multiple remote HEAD branches. Please choose one explicitly with: - git remote set-head two another - git remote set-head two master -EOF - -test_expect_success 'set-head --auto fails w/multiple HEADs' ' +test_expect_success 'set-head --auto has no problem w/multiple HEADs' ' ( cd test && - test_must_fail git remote set-head --auto two >output 2>&1 && + git fetch two "refs/heads/*:refs/remotes/two/*" && + git remote set-head --auto two >output 2>&1 && + echo "two/HEAD set to master" >expect && test_i18ncmp expect output ) ' diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh index fde689166a..5acd753dcf 100755 --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@ -88,7 +88,7 @@ test_expect_success 'fetch --prune on its own works as expected' ' cd "$D" && git clone . prune && cd prune && - git fetch origin refs/heads/master:refs/remotes/origin/extrabranch && + git update-ref refs/remotes/origin/extrabranch master && git fetch --prune origin && test_must_fail git rev-parse origin/extrabranch @@ -98,7 +98,7 @@ test_expect_success 'fetch --prune with a branch name keeps branches' ' cd "$D" && git clone . prune-branch && cd prune-branch && - git fetch origin refs/heads/master:refs/remotes/origin/extrabranch && + git update-ref refs/remotes/origin/extrabranch master && git fetch --prune origin master && git rev-parse origin/extrabranch @@ -113,25 +113,45 @@ test_expect_success 'fetch --prune with a namespace keeps other namespaces' ' git rev-parse origin/master ' -test_expect_success 'fetch --prune --tags does not delete the remote-tracking branches' ' +test_expect_success 'fetch --prune --tags prunes branches but not tags' ' cd "$D" && git clone . prune-tags && cd prune-tags && - git fetch origin refs/heads/master:refs/tags/sometag && + git tag sometag master && + # Create what looks like a remote-tracking branch from an earlier + # fetch that has since been deleted from the remote: + git update-ref refs/remotes/origin/fake-remote master && git fetch --prune --tags origin && git rev-parse origin/master && - test_must_fail git rev-parse somebranch + test_must_fail git rev-parse origin/fake-remote && + git rev-parse sometag ' -test_expect_success 'fetch --prune --tags with branch does not delete other remote-tracking branches' ' +test_expect_success 'fetch --prune --tags with branch does not prune other things' ' cd "$D" && git clone . prune-tags-branch && cd prune-tags-branch && - git fetch origin refs/heads/master:refs/remotes/origin/extrabranch && + git tag sometag master && + git update-ref refs/remotes/origin/extrabranch master && git fetch --prune --tags origin master && - git rev-parse origin/extrabranch + git rev-parse origin/extrabranch && + git rev-parse sometag +' + +test_expect_success 'fetch --prune --tags with refspec prunes based on refspec' ' + cd "$D" && + git clone . prune-tags-refspec && + cd prune-tags-refspec && + git tag sometag master && + git update-ref refs/remotes/origin/foo/otherbranch master && + git update-ref refs/remotes/origin/extrabranch master && + + git fetch --prune --tags origin refs/heads/foo/*:refs/remotes/origin/foo/* && + test_must_fail git rev-parse refs/remotes/origin/foo/otherbranch && + git rev-parse origin/extrabranch && + git rev-parse sometag ' test_expect_success 'fetch tags when there is no tags' ' @@ -281,7 +301,7 @@ test_expect_success 'fetch via rsync' ' mkdir rsynced && (cd rsynced && git init --bare && - git fetch "rsync:$(pwd)/../.git" master:refs/heads/master && + git fetch "rsync:../.git" master:refs/heads/master && git gc --prune && test $(git rev-parse master) = $(cd .. && git rev-parse master) && git fsck --full) @@ -292,7 +312,7 @@ test_expect_success 'push via rsync' ' (cd rsynced2 && git init) && (cd rsynced && - git push "rsync:$(pwd)/../rsynced2/.git" master) && + git push "rsync:../rsynced2/.git" master) && (cd rsynced2 && git gc --prune && test $(git rev-parse master) = $(cd .. && git rev-parse master) && @@ -303,7 +323,7 @@ test_expect_success 'push via rsync' ' mkdir rsynced3 && (cd rsynced3 && git init) && - git push --all "rsync:$(pwd)/rsynced3/.git" && + git push --all "rsync:rsynced3/.git" && (cd rsynced3 && test $(git rev-parse master) = $(cd .. && git rev-parse master) && git fsck --full) @@ -497,6 +517,88 @@ test_expect_success "should be able to fetch with duplicate refspecs" ' ) ' +# configured prune tests + +set_config_tristate () { + # var=$1 val=$2 + case "$2" in + unset) test_unconfig "$1" ;; + *) git config "$1" "$2" ;; + esac +} + +test_configured_prune () { + fetch_prune=$1 remote_origin_prune=$2 cmdline=$3 expected=$4 + + test_expect_success "prune fetch.prune=$1 remote.origin.prune=$2${3:+ $3}; $4" ' + # make sure a newbranch is there in . and also in one + git branch -f newbranch && + ( + cd one && + test_unconfig fetch.prune && + test_unconfig remote.origin.prune && + git fetch && + git rev-parse --verify refs/remotes/origin/newbranch + ) + + # now remove it + git branch -d newbranch && + + # then test + ( + cd one && + set_config_tristate fetch.prune $fetch_prune && + set_config_tristate remote.origin.prune $remote_origin_prune && + + git fetch $cmdline && + case "$expected" in + pruned) + test_must_fail git rev-parse --verify refs/remotes/origin/newbranch + ;; + kept) + git rev-parse --verify refs/remotes/origin/newbranch + ;; + esac + ) + ' +} + +test_configured_prune unset unset "" kept +test_configured_prune unset unset "--no-prune" kept +test_configured_prune unset unset "--prune" pruned + +test_configured_prune false unset "" kept +test_configured_prune false unset "--no-prune" kept +test_configured_prune false unset "--prune" pruned + +test_configured_prune true unset "" pruned +test_configured_prune true unset "--prune" pruned +test_configured_prune true unset "--no-prune" kept + +test_configured_prune unset false "" kept +test_configured_prune unset false "--no-prune" kept +test_configured_prune unset false "--prune" pruned + +test_configured_prune false false "" kept +test_configured_prune false false "--no-prune" kept +test_configured_prune false false "--prune" pruned + +test_configured_prune true false "" kept +test_configured_prune true false "--prune" pruned +test_configured_prune true false "--no-prune" kept + +test_configured_prune unset true "" pruned +test_configured_prune unset true "--no-prune" kept +test_configured_prune unset true "--prune" pruned + +test_configured_prune false true "" pruned +test_configured_prune false true "--no-prune" kept +test_configured_prune false true "--prune" pruned + +test_configured_prune true true "" pruned +test_configured_prune true true "--prune" pruned +test_configured_prune true true "--no-prune" kept + test_expect_success 'all boundary commits are excluded' ' test_commit base && test_commit oneside && @@ -512,4 +614,41 @@ test_expect_success 'all boundary commits are excluded' ' test_bundle_object_count .git/objects/pack/pack-${pack##pack }.pack 3 ' +test_expect_success 'fetch --prune prints the remotes url' ' + git branch goodbye && + git clone . only-prunes && + git branch -D goodbye && + ( + cd only-prunes && + git fetch --prune origin 2>&1 | head -n1 >../actual + ) && + echo "From ${D}/." >expect && + test_cmp expect actual +' + +test_expect_success 'branchname D/F conflict resolved by --prune' ' + git branch dir/file && + git clone . prune-df-conflict && + git branch -D dir/file && + git branch dir && + ( + cd prune-df-conflict && + git fetch --prune && + git rev-parse origin/dir >../actual + ) && + git rev-parse dir >expect && + test_cmp expect actual +' + +test_expect_success 'fetching a one-level ref works' ' + test_commit extra && + git reset --hard HEAD^ && + git update-ref refs/foo extra && + git init one-level && + ( + cd one-level && + git fetch .. HEAD refs/foo + ) +' + test_done diff --git a/t/t5515/fetch.br-unconfig_--tags_.._.git b/t/t5515/fetch.br-unconfig_--tags_.._.git index 1669cc4af0..0f70f66c70 100644 --- a/t/t5515/fetch.br-unconfig_--tags_.._.git +++ b/t/t5515/fetch.br-unconfig_--tags_.._.git @@ -1,4 +1,5 @@ # br-unconfig --tags ../.git +0567da4d5edd2ff4bb292a465ba9e64dcad9536b ../ 6c9dec2b923228c9ff994c6cfe4ae16c12408dc5 not-for-merge tag 'tag-master' of ../ 8e32a6d901327a23ef831511badce7bf3bf46689 not-for-merge tag 'tag-one' of ../ 22feea448b023a2d864ef94b013735af34d238ba not-for-merge tag 'tag-one-tree' of ../ diff --git a/t/t5515/fetch.master_--tags_.._.git b/t/t5515/fetch.master_--tags_.._.git index 8a7493537b..ab473a6e1f 100644 --- a/t/t5515/fetch.master_--tags_.._.git +++ b/t/t5515/fetch.master_--tags_.._.git @@ -1,4 +1,5 @@ # master --tags ../.git +0567da4d5edd2ff4bb292a465ba9e64dcad9536b ../ 6c9dec2b923228c9ff994c6cfe4ae16c12408dc5 not-for-merge tag 'tag-master' of ../ 8e32a6d901327a23ef831511badce7bf3bf46689 not-for-merge tag 'tag-one' of ../ 22feea448b023a2d864ef94b013735af34d238ba not-for-merge tag 'tag-one-tree' of ../ diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index 4691d51b8c..67e0ab3462 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -536,6 +536,19 @@ test_expect_success 'push with config branch.*.pushremote' ' check_push_result down_repo $the_commit heads/master ' +test_expect_success 'branch.*.pushremote config order is irrelevant' ' + mk_test one_repo heads/master && + mk_test two_repo heads/master && + test_config remote.one.url one_repo && + test_config remote.two.url two_repo && + test_config branch.master.pushremote two_repo && + test_config remote.pushdefault one_repo && + test_config push.default matching && + git push && + check_push_result one_repo $the_first_commit heads/master && + check_push_result two_repo $the_commit heads/master +' + test_expect_success 'push with dry-run' ' mk_test testrepo heads/master && @@ -1126,6 +1139,81 @@ test_expect_success 'fetch follows tags by default' ' test_cmp expect actual ' +test_expect_success 'pushing a specific ref applies remote.$name.push as refmap' ' + mk_test testrepo heads/master && + rm -fr src dst && + git init src && + git init --bare dst && + ( + cd src && + git pull ../testrepo master && + git branch next && + git config remote.dst.url ../dst && + git config remote.dst.push "+refs/heads/*:refs/remotes/src/*" && + git push dst master && + git show-ref refs/heads/master | + sed -e "s|refs/heads/|refs/remotes/src/|" >../dst/expect + ) && + ( + cd dst && + test_must_fail git show-ref refs/heads/next && + test_must_fail git show-ref refs/heads/master && + git show-ref refs/remotes/src/master >actual + ) && + test_cmp dst/expect dst/actual +' + +test_expect_success 'with no remote.$name.push, it is not used as refmap' ' + mk_test testrepo heads/master && + rm -fr src dst && + git init src && + git init --bare dst && + ( + cd src && + git pull ../testrepo master && + git branch next && + git config remote.dst.url ../dst && + git config push.default matching && + git push dst master && + git show-ref refs/heads/master >../dst/expect + ) && + ( + cd dst && + test_must_fail git show-ref refs/heads/next && + git show-ref refs/heads/master >actual + ) && + test_cmp dst/expect dst/actual +' + +test_expect_success 'with no remote.$name.push, upstream mapping is used' ' + mk_test testrepo heads/master && + rm -fr src dst && + git init src && + git init --bare dst && + ( + cd src && + git pull ../testrepo master && + git branch next && + git config remote.dst.url ../dst && + git config remote.dst.fetch "+refs/heads/*:refs/remotes/dst/*" && + git config push.default upstream && + + git config branch.master.merge refs/heads/trunk && + git config branch.master.remote dst && + + git push dst master && + git show-ref refs/heads/master | + sed -e "s|refs/heads/master|refs/heads/trunk|" >../dst/expect + ) && + ( + cd dst && + test_must_fail git show-ref refs/heads/master && + test_must_fail git show-ref refs/heads/next && + git show-ref refs/heads/trunk >actual + ) && + test_cmp dst/expect dst/actual +' + test_expect_success 'push does not follow tags by default' ' mk_test testrepo heads/master && rm -fr src dst && @@ -1172,4 +1260,21 @@ test_expect_success 'push --follow-tag only pushes relevant tags' ' test_cmp expect actual ' +test_expect_success 'push --no-thin must produce non-thin pack' ' + cat >>path1 <<\EOF && +keep base version of path1 big enough, compared to the new changes +later, in order to pass size heuristics in +builtin/pack-objects.c:try_delta() +EOF + git commit -am initial && + git init no-thin && + git --git-dir=no-thin/.git config receive.unpacklimit 0 && + git push no-thin/.git refs/heads/master:refs/heads/foo && + echo modified >> path1 && + git commit -am modified && + git repack -adf && + rcvpck="git receive-pack --reject-thin-pack-for-testing" && + git push --no-thin --receive-pack="$rcvpck" no-thin/.git refs/heads/master:refs/heads/foo +' + test_done diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh index ed4d9c8318..227d293350 100755 --- a/t/t5520-pull.sh +++ b/t/t5520-pull.sh @@ -148,6 +148,95 @@ test_expect_success 'branch.to-rebase.rebase should override pull.rebase' ' test new = $(git show HEAD:file2) ' +# add a feature branch, keep-merge, that is merged into master, so the +# test can try preserving the merge commit (or not) with various +# --rebase flags/pull.rebase settings. +test_expect_success 'preserve merge setup' ' + git reset --hard before-rebase && + git checkout -b keep-merge second^ && + test_commit file3 && + git checkout to-rebase && + git merge keep-merge && + git tag before-preserve-rebase +' + +test_expect_success 'pull.rebase=false create a new merge commit' ' + git reset --hard before-preserve-rebase && + test_config pull.rebase false && + git pull . copy && + test $(git rev-parse HEAD^1) = $(git rev-parse before-preserve-rebase) && + test $(git rev-parse HEAD^2) = $(git rev-parse copy) && + test file3 = $(git show HEAD:file3.t) +' + +test_expect_success 'pull.rebase=true flattens keep-merge' ' + git reset --hard before-preserve-rebase && + test_config pull.rebase true && + git pull . copy && + test $(git rev-parse HEAD^^) = $(git rev-parse copy) && + test file3 = $(git show HEAD:file3.t) +' + +test_expect_success 'pull.rebase=1 is treated as true and flattens keep-merge' ' + git reset --hard before-preserve-rebase && + test_config pull.rebase 1 && + git pull . copy && + test $(git rev-parse HEAD^^) = $(git rev-parse copy) && + test file3 = $(git show HEAD:file3.t) +' + +test_expect_success 'pull.rebase=preserve rebases and merges keep-merge' ' + git reset --hard before-preserve-rebase && + test_config pull.rebase preserve && + git pull . copy && + test $(git rev-parse HEAD^^) = $(git rev-parse copy) && + test $(git rev-parse HEAD^2) = $(git rev-parse keep-merge) +' + +test_expect_success 'pull.rebase=invalid fails' ' + git reset --hard before-preserve-rebase && + test_config pull.rebase invalid && + ! git pull . copy +' + +test_expect_success '--rebase=false create a new merge commit' ' + git reset --hard before-preserve-rebase && + test_config pull.rebase true && + git pull --rebase=false . copy && + test $(git rev-parse HEAD^1) = $(git rev-parse before-preserve-rebase) && + test $(git rev-parse HEAD^2) = $(git rev-parse copy) && + test file3 = $(git show HEAD:file3.t) +' + +test_expect_success '--rebase=true rebases and flattens keep-merge' ' + git reset --hard before-preserve-rebase && + test_config pull.rebase preserve && + git pull --rebase=true . copy && + test $(git rev-parse HEAD^^) = $(git rev-parse copy) && + test file3 = $(git show HEAD:file3.t) +' + +test_expect_success '--rebase=preserve rebases and merges keep-merge' ' + git reset --hard before-preserve-rebase && + test_config pull.rebase true && + git pull --rebase=preserve . copy && + test $(git rev-parse HEAD^^) = $(git rev-parse copy) && + test $(git rev-parse HEAD^2) = $(git rev-parse keep-merge) +' + +test_expect_success '--rebase=invalid fails' ' + git reset --hard before-preserve-rebase && + ! git pull --rebase=invalid . copy +' + +test_expect_success '--rebase overrides pull.rebase=preserve and flattens keep-merge' ' + git reset --hard before-preserve-rebase && + test_config pull.rebase preserve && + git pull --rebase . copy && + test $(git rev-parse HEAD^^) = $(git rev-parse copy) && + test file3 = $(git show HEAD:file3.t) +' + test_expect_success '--rebase with rebased upstream' ' git remote add -f me . && diff --git a/t/t5525-fetch-tagopt.sh b/t/t5525-fetch-tagopt.sh index 4fbf7a120f..45815f7378 100755 --- a/t/t5525-fetch-tagopt.sh +++ b/t/t5525-fetch-tagopt.sh @@ -8,7 +8,8 @@ setup_clone () { git clone --mirror . $1 && git remote add remote_$1 $1 && (cd $1 && - git tag tag_$1) + git tag tag_$1 && + git branch branch_$1) } test_expect_success setup ' @@ -21,21 +22,33 @@ test_expect_success setup ' test_expect_success "fetch with tagopt=--no-tags does not get tag" ' git fetch remote_one && - test_must_fail git show-ref tag_one + test_must_fail git show-ref tag_one && + git show-ref remote_one/branch_one ' test_expect_success "fetch --tags with tagopt=--no-tags gets tag" ' + ( + cd one && + git branch second_branch_one + ) && git fetch --tags remote_one && - git show-ref tag_one + git show-ref tag_one && + git show-ref remote_one/second_branch_one ' test_expect_success "fetch --no-tags with tagopt=--tags does not get tag" ' git fetch --no-tags remote_two && - test_must_fail git show-ref tag_two + test_must_fail git show-ref tag_two && + git show-ref remote_two/branch_two ' test_expect_success "fetch with tagopt=--tags gets tag" ' + ( + cd two && + git branch second_branch_two + ) && git fetch remote_two && - git show-ref tag_two + git show-ref tag_two && + git show-ref remote_two/second_branch_two ' test_done diff --git a/t/t5529-push-errors.sh b/t/t5529-push-errors.sh new file mode 100755 index 0000000000..9871307fd4 --- /dev/null +++ b/t/t5529-push-errors.sh @@ -0,0 +1,48 @@ +#!/bin/sh + +test_description='detect some push errors early (before contacting remote)' +. ./test-lib.sh + +test_expect_success 'setup commits' ' + test_commit one +' + +test_expect_success 'setup remote' ' + git init --bare remote.git && + git remote add origin remote.git +' + +test_expect_success 'setup fake receive-pack' ' + FAKE_RP_ROOT=$(pwd) && + export FAKE_RP_ROOT && + write_script fake-rp <<-\EOF && + echo yes >"$FAKE_RP_ROOT"/rp-ran + exit 1 + EOF + git config remote.origin.receivepack "\"\$FAKE_RP_ROOT/fake-rp\"" +' + +test_expect_success 'detect missing branches early' ' + echo no >rp-ran && + echo no >expect && + test_must_fail git push origin missing && + test_cmp expect rp-ran +' + +test_expect_success 'detect missing sha1 expressions early' ' + echo no >rp-ran && + echo no >expect && + test_must_fail git push origin master~2:master && + test_cmp expect rp-ran +' + +test_expect_success 'detect ambiguous refs early' ' + git branch foo && + git tag foo && + echo no >rp-ran && + echo no >expect && + test_must_fail git push origin foo && + test_cmp expect rp-ran +' + +test_done diff --git a/t/t5530-upload-pack-error.sh b/t/t5530-upload-pack-error.sh index c983d3694c..3932e797f7 100755 --- a/t/t5530-upload-pack-error.sh +++ b/t/t5530-upload-pack-error.sh @@ -54,9 +54,6 @@ test_expect_success 'upload-pack fails due to error in rev-list' ' printf "0032want %s\n0034shallow %s00000009done\n0000" \ $(git rev-parse HEAD) $(git rev-parse HEAD^) >input && test_must_fail git upload-pack . <input >/dev/null 2>output.err && - # pack-objects survived - grep "Total.*, reused" output.err && - # but there was an error, which must have been in rev-list grep "bad tree object" output.err ' diff --git a/t/t5531-deep-submodule-push.sh b/t/t5531-deep-submodule-push.sh index 8c16e045a0..445bb5fe26 100755 --- a/t/t5531-deep-submodule-push.sh +++ b/t/t5531-deep-submodule-push.sh @@ -12,6 +12,7 @@ test_expect_success setup ' ( cd work && git init && + git config push.default matching && mkdir -p gar/bage && ( cd gar/bage && diff --git a/t/t5533-push-cas.sh b/t/t5533-push-cas.sh new file mode 100755 index 0000000000..ba20d83333 --- /dev/null +++ b/t/t5533-push-cas.sh @@ -0,0 +1,189 @@ +#!/bin/sh + +test_description='compare & swap push force/delete safety' + +. ./test-lib.sh + +setup_srcdst_basic () { + rm -fr src dst && + git clone --no-local . src && + git clone --no-local src dst && + ( + cd src && git checkout HEAD^0 + ) +} + +test_expect_success setup ' + : create template repository + test_commit A && + test_commit B && + test_commit C +' + +test_expect_success 'push to update (protected)' ' + setup_srcdst_basic && + ( + cd dst && + test_commit D && + test_must_fail git push --force-with-lease=master:master origin master + ) && + git ls-remote . refs/heads/master >expect && + git ls-remote src refs/heads/master >actual && + test_cmp expect actual +' + +test_expect_success 'push to update (protected, forced)' ' + setup_srcdst_basic && + ( + cd dst && + test_commit D && + git push --force --force-with-lease=master:master origin master + ) && + git ls-remote dst refs/heads/master >expect && + git ls-remote src refs/heads/master >actual && + test_cmp expect actual +' + +test_expect_success 'push to update (protected, tracking)' ' + setup_srcdst_basic && + ( + cd src && + git checkout master && + test_commit D && + git checkout HEAD^0 + ) && + git ls-remote src refs/heads/master >expect && + ( + cd dst && + test_commit E && + git ls-remote . refs/remotes/origin/master >expect && + test_must_fail git push --force-with-lease=master origin master && + git ls-remote . refs/remotes/origin/master >actual && + test_cmp expect actual + ) && + git ls-remote src refs/heads/master >actual && + test_cmp expect actual +' + +test_expect_success 'push to update (protected, tracking, forced)' ' + setup_srcdst_basic && + ( + cd src && + git checkout master && + test_commit D && + git checkout HEAD^0 + ) && + ( + cd dst && + test_commit E && + git ls-remote . refs/remotes/origin/master >expect && + git push --force --force-with-lease=master origin master + ) && + git ls-remote dst refs/heads/master >expect && + git ls-remote src refs/heads/master >actual && + test_cmp expect actual +' + +test_expect_success 'push to update (allowed)' ' + setup_srcdst_basic && + ( + cd dst && + test_commit D && + git push --force-with-lease=master:master^ origin master + ) && + git ls-remote dst refs/heads/master >expect && + git ls-remote src refs/heads/master >actual && + test_cmp expect actual +' + +test_expect_success 'push to update (allowed, tracking)' ' + setup_srcdst_basic && + ( + cd dst && + test_commit D && + git push --force-with-lease=master origin master + ) && + git ls-remote dst refs/heads/master >expect && + git ls-remote src refs/heads/master >actual && + test_cmp expect actual +' + +test_expect_success 'push to update (allowed even though no-ff)' ' + setup_srcdst_basic && + ( + cd dst && + git reset --hard HEAD^ && + test_commit D && + git push --force-with-lease=master origin master + ) && + git ls-remote dst refs/heads/master >expect && + git ls-remote src refs/heads/master >actual && + test_cmp expect actual +' + +test_expect_success 'push to delete (protected)' ' + setup_srcdst_basic && + git ls-remote src refs/heads/master >expect && + ( + cd dst && + test_must_fail git push --force-with-lease=master:master^ origin :master + ) && + git ls-remote src refs/heads/master >actual && + test_cmp expect actual +' + +test_expect_success 'push to delete (protected, forced)' ' + setup_srcdst_basic && + ( + cd dst && + git push --force --force-with-lease=master:master^ origin :master + ) && + >expect && + git ls-remote src refs/heads/master >actual && + test_cmp expect actual +' + +test_expect_success 'push to delete (allowed)' ' + setup_srcdst_basic && + ( + cd dst && + git push --force-with-lease=master origin :master + ) && + >expect && + git ls-remote src refs/heads/master >actual && + test_cmp expect actual +' + +test_expect_success 'cover everything with default force-with-lease (protected)' ' + setup_srcdst_basic && + ( + cd src && + git branch naster master^ + ) + git ls-remote src refs/heads/\* >expect && + ( + cd dst && + test_must_fail git push --force-with-lease origin master master:naster + ) && + git ls-remote src refs/heads/\* >actual && + test_cmp expect actual +' + +test_expect_success 'cover everything with default force-with-lease (allowed)' ' + setup_srcdst_basic && + ( + cd src && + git branch naster master^ + ) + ( + cd dst && + git fetch && + git push --force-with-lease origin master master:naster + ) && + git ls-remote dst refs/heads/master | + sed -e "s/master/naster/" >expect && + git ls-remote src refs/heads/naster >actual && + test_cmp expect actual +' + +test_done diff --git a/t/t5536-fetch-conflicts.sh b/t/t5536-fetch-conflicts.sh new file mode 100755 index 0000000000..6c5d3a4ce0 --- /dev/null +++ b/t/t5536-fetch-conflicts.sh @@ -0,0 +1,100 @@ +#!/bin/sh + +test_description='fetch handles conflicting refspecs correctly' + +. ./test-lib.sh + +D=$(pwd) + +setup_repository () { + git init "$1" && ( + cd "$1" && + git config remote.origin.url "$D" && + shift && + for refspec in "$@" + do + git config --add remote.origin.fetch "$refspec" + done + ) +} + +verify_stderr () { + cat >expected && + # We're not interested in the error + # "fatal: The remote end hung up unexpectedly": + grep -E '^(fatal|warning):' <error | grep -v 'hung up' >actual | sort && + test_cmp expected actual +} + +test_expect_success 'setup' ' + git commit --allow-empty -m "Initial" && + git branch branch1 && + git tag tag1 && + git commit --allow-empty -m "First" && + git branch branch2 && + git tag tag2 +' + +test_expect_success 'fetch with no conflict' ' + setup_repository ok "+refs/heads/*:refs/remotes/origin/*" && ( + cd ok && + git fetch origin + ) +' + +test_expect_success 'fetch conflict: config vs. config' ' + setup_repository ccc \ + "+refs/heads/branch1:refs/remotes/origin/branch1" \ + "+refs/heads/branch2:refs/remotes/origin/branch1" && ( + cd ccc && + test_must_fail git fetch origin 2>error && + verify_stderr <<-\EOF + fatal: Cannot fetch both refs/heads/branch1 and refs/heads/branch2 to refs/remotes/origin/branch1 + EOF + ) +' + +test_expect_success 'fetch duplicate: config vs. config' ' + setup_repository dcc \ + "+refs/heads/*:refs/remotes/origin/*" \ + "+refs/heads/branch1:refs/remotes/origin/branch1" && ( + cd dcc && + git fetch origin + ) +' + +test_expect_success 'fetch conflict: arg overrides config' ' + setup_repository aoc \ + "+refs/heads/*:refs/remotes/origin/*" && ( + cd aoc && + git fetch origin refs/heads/branch2:refs/remotes/origin/branch1 + ) +' + +test_expect_success 'fetch conflict: arg vs. arg' ' + setup_repository caa && ( + cd caa && + test_must_fail git fetch origin \ + refs/heads/*:refs/remotes/origin/* \ + refs/heads/branch2:refs/remotes/origin/branch1 2>error && + verify_stderr <<-\EOF + fatal: Cannot fetch both refs/heads/branch1 and refs/heads/branch2 to refs/remotes/origin/branch1 + EOF + ) +' + +test_expect_success 'fetch conflict: criss-cross args' ' + setup_repository xaa \ + "+refs/heads/*:refs/remotes/origin/*" && ( + cd xaa && + git fetch origin \ + refs/heads/branch1:refs/remotes/origin/branch2 \ + refs/heads/branch2:refs/remotes/origin/branch1 2>error && + verify_stderr <<-\EOF + warning: refs/remotes/origin/branch1 usually tracks refs/heads/branch1, not refs/heads/branch2 + warning: refs/remotes/origin/branch2 usually tracks refs/heads/branch2, not refs/heads/branch1 + EOF + ) +' + +test_done diff --git a/t/t5537-fetch-shallow.sh b/t/t5537-fetch-shallow.sh new file mode 100755 index 0000000000..be951a4679 --- /dev/null +++ b/t/t5537-fetch-shallow.sh @@ -0,0 +1,217 @@ +#!/bin/sh + +test_description='fetch/clone from a shallow clone' + +. ./test-lib.sh + +commit() { + echo "$1" >tracked && + git add tracked && + git commit -m "$1" +} + +test_expect_success 'setup' ' + commit 1 && + commit 2 && + commit 3 && + commit 4 && + git config --global transfer.fsckObjects true +' + +test_expect_success 'setup shallow clone' ' + git clone --no-local --depth=2 .git shallow && + git --git-dir=shallow/.git log --format=%s >actual && + cat <<EOF >expect && +4 +3 +EOF + test_cmp expect actual +' + +test_expect_success 'clone from shallow clone' ' + git clone --no-local shallow shallow2 && + ( + cd shallow2 && + git fsck && + git log --format=%s >actual && + cat <<EOF >expect && +4 +3 +EOF + test_cmp expect actual + ) +' + +test_expect_success 'fetch from shallow clone' ' + ( + cd shallow && + commit 5 + ) && + ( + cd shallow2 && + git fetch && + git fsck && + git log --format=%s origin/master >actual && + cat <<EOF >expect && +5 +4 +3 +EOF + test_cmp expect actual + ) +' + +test_expect_success 'fetch --depth from shallow clone' ' + ( + cd shallow && + commit 6 + ) && + ( + cd shallow2 && + git fetch --depth=2 && + git fsck && + git log --format=%s origin/master >actual && + cat <<EOF >expect && +6 +5 +EOF + test_cmp expect actual + ) +' + +test_expect_success 'fetch --unshallow from shallow clone' ' + ( + cd shallow2 && + git fetch --unshallow && + git fsck && + git log --format=%s origin/master >actual && + cat <<EOF >expect && +6 +5 +4 +3 +EOF + test_cmp expect actual + ) +' + +test_expect_success 'fetch something upstream has but hidden by clients shallow boundaries' ' + # the blob "1" is available in .git but hidden by the + # shallow2/.git/shallow and it should be resent + ! git --git-dir=shallow2/.git cat-file blob `echo 1|git hash-object --stdin` >/dev/null && + echo 1 >1.t && + git add 1.t && + git commit -m add-1-back && + ( + cd shallow2 && + git fetch ../.git +refs/heads/master:refs/remotes/top/master && + git fsck && + git log --format=%s top/master >actual && + cat <<EOF >expect && +add-1-back +4 +3 +EOF + test_cmp expect actual + ) && + git --git-dir=shallow2/.git cat-file blob `echo 1|git hash-object --stdin` >/dev/null + +' + +test_expect_success 'fetch that requires changes in .git/shallow is filtered' ' + ( + cd shallow && + git checkout --orphan no-shallow && + commit no-shallow + ) && + git init notshallow && + ( + cd notshallow && + git fetch ../shallow/.git refs/heads/*:refs/remotes/shallow/*&& + git for-each-ref --format="%(refname)" >actual.refs && + cat <<EOF >expect.refs && +refs/remotes/shallow/no-shallow +EOF + test_cmp expect.refs actual.refs && + git log --format=%s shallow/no-shallow >actual && + cat <<EOF >expect && +no-shallow +EOF + test_cmp expect actual + ) +' + +test_expect_success 'fetch --update-shallow' ' + ( + cd shallow && + git checkout master && + commit 7 && + git tag -m foo heavy-tag HEAD^ && + git tag light-tag HEAD^:tracked + ) && + ( + cd notshallow && + git fetch --update-shallow ../shallow/.git refs/heads/*:refs/remotes/shallow/* && + git fsck && + git for-each-ref --sort=refname --format="%(refname)" >actual.refs && + cat <<EOF >expect.refs && +refs/remotes/shallow/master +refs/remotes/shallow/no-shallow +refs/tags/heavy-tag +refs/tags/light-tag +EOF + test_cmp expect.refs actual.refs && + git log --format=%s shallow/master >actual && + cat <<EOF >expect && +7 +6 +5 +4 +3 +EOF + test_cmp expect actual + ) +' + +if test -n "$NO_CURL" -o -z "$GIT_TEST_HTTPD"; then + say 'skipping remaining tests, git built without http support' + test_done +fi + +LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5537'} +. "$TEST_DIRECTORY"/lib-httpd.sh +start_httpd + +test_expect_success 'clone http repository' ' + git clone --bare --no-local shallow "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && + git clone $HTTPD_URL/smart/repo.git clone && + ( + cd clone && + git fsck && + git log --format=%s origin/master >actual && + cat <<EOF >expect && +7 +6 +5 +4 +3 +EOF + test_cmp expect actual + ) +' + +test_expect_success POSIXPERM,SANITY 'shallow fetch from a read-only repo' ' + cp -R .git read-only.git && + find read-only.git -print | xargs chmod -w && + test_when_finished "find read-only.git -type d -print | xargs chmod +w" && + git clone --no-local --depth=2 read-only.git from-read-only && + git --git-dir=from-read-only/.git log --format=%s >actual && + cat >expect <<EOF && +add-1-back +4 +EOF + test_cmp expect actual +' + +stop_httpd +test_done diff --git a/t/t5538-push-shallow.sh b/t/t5538-push-shallow.sh new file mode 100755 index 0000000000..8e54ac5746 --- /dev/null +++ b/t/t5538-push-shallow.sh @@ -0,0 +1,182 @@ +#!/bin/sh + +test_description='push from/to a shallow clone' + +. ./test-lib.sh + +commit() { + echo "$1" >tracked && + git add tracked && + git commit -m "$1" +} + +test_expect_success 'setup' ' + git config --global transfer.fsckObjects true && + commit 1 && + commit 2 && + commit 3 && + commit 4 && + git clone . full && + ( + git init full-abc && + cd full-abc && + commit a && + commit b && + commit c + ) && + git clone --no-local --depth=2 .git shallow && + git --git-dir=shallow/.git log --format=%s >actual && + cat <<EOF >expect && +4 +3 +EOF + test_cmp expect actual && + git clone --no-local --depth=2 full-abc/.git shallow2 && + git --git-dir=shallow2/.git log --format=%s >actual && + cat <<EOF >expect && +c +b +EOF + test_cmp expect actual +' + +test_expect_success 'push from shallow clone' ' + ( + cd shallow && + commit 5 && + git push ../.git +master:refs/remotes/shallow/master + ) && + git log --format=%s shallow/master >actual && + git fsck && + cat <<EOF >expect && +5 +4 +3 +2 +1 +EOF + test_cmp expect actual +' + +test_expect_success 'push from shallow clone, with grafted roots' ' + ( + cd shallow2 && + test_must_fail git push ../.git +master:refs/remotes/shallow2/master 2>err && + grep "shallow2/master.*shallow update not allowed" err + ) && + test_must_fail git rev-parse shallow2/master && + git fsck +' + +test_expect_success 'add new shallow root with receive.updateshallow on' ' + test_config receive.shallowupdate true && + ( + cd shallow2 && + git push ../.git +master:refs/remotes/shallow2/master + ) && + git log --format=%s shallow2/master >actual && + git fsck && + cat <<EOF >expect && +c +b +EOF + test_cmp expect actual +' + +test_expect_success 'push from shallow to shallow' ' + ( + cd shallow && + git --git-dir=../shallow2/.git config receive.shallowupdate true && + git push ../shallow2/.git +master:refs/remotes/shallow/master && + git --git-dir=../shallow2/.git config receive.shallowupdate false + ) && + ( + cd shallow2 && + git log --format=%s shallow/master >actual && + git fsck && + cat <<EOF >expect && +5 +4 +3 +EOF + test_cmp expect actual + ) +' + +test_expect_success 'push from full to shallow' ' + ! git --git-dir=shallow2/.git cat-file blob `echo 1|git hash-object --stdin` && + commit 1 && + git push shallow2/.git +master:refs/remotes/top/master && + ( + cd shallow2 && + git log --format=%s top/master >actual && + git fsck && + cat <<EOF >expect && +1 +4 +3 +EOF + test_cmp expect actual && + git cat-file blob `echo 1|git hash-object --stdin` >/dev/null + ) +' + +if test -n "$NO_CURL" -o -z "$GIT_TEST_HTTPD"; then + say 'skipping remaining tests, git built without http support' + test_done +fi + +. "$TEST_DIRECTORY"/lib-httpd.sh +start_httpd + +test_expect_success 'push to shallow repo via http' ' + git clone --bare --no-local shallow "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && + ( + cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && + git config http.receivepack true + ) && + ( + cd full && + commit 9 && + git push $HTTPD_URL/smart/repo.git +master:refs/remotes/top/master + ) && + ( + cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && + git fsck && + git log --format=%s top/master >actual && + cat <<EOF >expect && +9 +4 +3 +EOF + test_cmp expect actual + ) +' + +test_expect_success 'push from shallow repo via http' ' + mv "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" shallow-upstream.git && + git clone --bare --no-local full "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && + ( + cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && + git config http.receivepack true + ) && + commit 10 && + git push $HTTPD_URL/smart/repo.git +master:refs/remotes/top/master && + ( + cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && + git fsck && + git log --format=%s top/master >actual && + cat <<EOF >expect && +10 +1 +4 +3 +2 +1 +EOF + test_cmp expect actual + ) +' + +stop_httpd +test_done diff --git a/t/t5539-fetch-http-shallow.sh b/t/t5539-fetch-http-shallow.sh new file mode 100755 index 0000000000..94553e1039 --- /dev/null +++ b/t/t5539-fetch-http-shallow.sh @@ -0,0 +1,82 @@ +#!/bin/sh + +test_description='fetch/clone from a shallow clone over http' + +. ./test-lib.sh + +if test -n "$NO_CURL"; then + skip_all='skipping test, git built without http support' + test_done +fi + +. "$TEST_DIRECTORY"/lib-httpd.sh +start_httpd + +commit() { + echo "$1" >tracked && + git add tracked && + git commit -m "$1" +} + +test_expect_success 'setup shallow clone' ' + commit 1 && + commit 2 && + commit 3 && + commit 4 && + commit 5 && + commit 6 && + commit 7 && + git clone --no-local --depth=5 .git shallow && + git config --global transfer.fsckObjects true +' + +test_expect_success 'clone http repository' ' + git clone --bare --no-local shallow "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && + git clone $HTTPD_URL/smart/repo.git clone && + ( + cd clone && + git fsck && + git log --format=%s origin/master >actual && + cat <<EOF >expect && +7 +6 +5 +4 +3 +EOF + test_cmp expect actual + ) +' + +# This test is tricky. We need large enough "have"s that fetch-pack +# will put pkt-flush in between. Then we need a "have" the server +# does not have, it'll send "ACK %s ready" +test_expect_success 'no shallow lines after receiving ACK ready' ' + ( + cd shallow && + for i in $(test_seq 15) + do + git checkout --orphan unrelated$i && + test_commit unrelated$i && + git push -q "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \ + refs/heads/unrelated$i:refs/heads/unrelated$i && + git push -q ../clone/.git \ + refs/heads/unrelated$i:refs/heads/unrelated$i || + exit 1 + done && + git checkout master && + test_commit new && + git push "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" master + ) && + ( + cd clone && + git checkout --orphan newnew && + test_commit new-too && + GIT_TRACE_PACKET="$TRASH_DIRECTORY/trace" git fetch --depth=2 && + grep "fetch-pack< ACK .* ready" ../trace && + ! grep "fetch-pack> done" ../trace + ) +' + +stop_httpd +test_done diff --git a/t/t5540-http-push.sh b/t/t5540-http-push-webdav.sh index 01d0d95b4d..8d7b3c57e3 100755 --- a/t/t5540-http-push.sh +++ b/t/t5540-http-push-webdav.sh @@ -16,7 +16,6 @@ then fi LIB_HTTPD_DAV=t -LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5540'} . "$TEST_DIRECTORY"/lib-httpd.sh ROOT_PATH="$PWD" start_httpd @@ -154,7 +153,7 @@ test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \ test_expect_success 'push to password-protected repository (user in URL)' ' test_commit pw-user && - set_askpass user@host && + set_askpass user@host pass@host && git push "$HTTPD_URL_USER/auth/dumb/test_repo.git" HEAD && git rev-parse --verify HEAD >expect && git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/test_repo.git" \ @@ -168,7 +167,7 @@ test_expect_failure 'user was prompted only once for password' ' test_expect_failure 'push to password-protected repository (no user in URL)' ' test_commit pw-nouser && - set_askpass user@host && + set_askpass user@host pass@host && git push "$HTTPD_URL/auth/dumb/test_repo.git" HEAD && expect_askpass both user@host git rev-parse --verify HEAD >expect && diff --git a/t/t5541-http-push.sh b/t/t5541-http-push-smart.sh index beb00be4b1..73af16f481 100755 --- a/t/t5541-http-push.sh +++ b/t/t5541-http-push-smart.sh @@ -12,7 +12,6 @@ if test -n "$NO_CURL"; then fi ROOT_PATH="$PWD" -LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5541'} . "$TEST_DIRECTORY"/lib-httpd.sh . "$TEST_DIRECTORY"/lib-terminal.sh start_httpd @@ -153,7 +152,7 @@ test_expect_success 'used receive-pack service' ' ' test_http_push_nonff "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo.git \ - "$ROOT_PATH"/test_repo_clone master + "$ROOT_PATH"/test_repo_clone master success test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper' ' # create a dissimilarly-named remote ref so that git is unable to match the @@ -274,7 +273,7 @@ test_expect_success 'push over smart http with auth' ' cd "$ROOT_PATH/test_repo_clone" && echo push-auth-test >expect && test_commit push-auth-test && - set_askpass user@host && + set_askpass user@host pass@host && git push "$HTTPD_URL"/auth/smart/test_repo.git && git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \ log -1 --format=%s >actual && @@ -286,7 +285,7 @@ test_expect_success 'push to auth-only-for-push repo' ' cd "$ROOT_PATH/test_repo_clone" && echo push-half-auth >expect && test_commit push-half-auth && - set_askpass user@host && + set_askpass user@host pass@host && git push "$HTTPD_URL"/auth-push/smart/test_repo.git && git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/test_repo.git" \ log -1 --format=%s >actual && @@ -316,7 +315,7 @@ test_expect_success 'push into half-auth-complete requires password' ' cd "$ROOT_PATH/half-auth-clone" && echo two >expect && test_commit two && - set_askpass user@host && + set_askpass user@host pass@host && git push "$HTTPD_URL/half-auth-complete/smart/half-auth.git" && git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/half-auth.git" \ log -1 --format=%s >actual && diff --git a/t/t5550-http-fetch.sh b/t/t5550-http-fetch-dumb.sh index f7d0f146f0..1a3a2b6c1a 100755 --- a/t/t5550-http-fetch.sh +++ b/t/t5550-http-fetch-dumb.sh @@ -8,7 +8,6 @@ if test -n "$NO_CURL"; then test_done fi -LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5550'} . "$TEST_DIRECTORY"/lib-httpd.sh start_httpd @@ -62,13 +61,13 @@ test_expect_success 'http auth can use user/pass in URL' ' ' test_expect_success 'http auth can use just user in URL' ' - set_askpass user@host && + set_askpass wrong pass@host && git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-pass && expect_askpass pass user@host ' test_expect_success 'http auth can request both user and pass' ' - set_askpass user@host && + set_askpass user@host pass@host && git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-both && expect_askpass both user@host ' @@ -77,7 +76,7 @@ test_expect_success 'http auth respects credential helper config' ' test_config_global credential.helper "!f() { cat >/dev/null echo username=user@host - echo password=user@host + echo password=pass@host }; f" && set_askpass wrong && git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-helper && @@ -86,14 +85,14 @@ test_expect_success 'http auth respects credential helper config' ' test_expect_success 'http auth can get username from config' ' test_config_global "credential.$HTTPD_URL.username" user@host && - set_askpass user@host && + set_askpass wrong pass@host && git clone "$HTTPD_URL/auth/dumb/repo.git" clone-auth-user && expect_askpass pass user@host ' test_expect_success 'configured username does not override URL' ' test_config_global "credential.$HTTPD_URL.username" wrong && - set_askpass user@host && + set_askpass wrong pass@host && git clone "$HTTPD_URL_USER/auth/dumb/repo.git" clone-auth-user2 && expect_askpass pass user@host ' diff --git a/t/t5551-http-fetch.sh b/t/t5551-http-fetch-smart.sh index 55a866af80..e07eaf35f1 100755 --- a/t/t5551-http-fetch.sh +++ b/t/t5551-http-fetch-smart.sh @@ -8,7 +8,6 @@ if test -n "$NO_CURL"; then test_done fi -LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5551'} . "$TEST_DIRECTORY"/lib-httpd.sh start_httpd @@ -113,9 +112,13 @@ test_expect_success 'follow redirects (302)' ' git clone $HTTPD_URL/smart-redir-temp/repo.git --quiet repo-t ' +test_expect_success 'redirects re-root further requests' ' + git clone $HTTPD_URL/smart-redir-limited/repo.git repo-redir-limited +' + test_expect_success 'clone from password-protected repository' ' echo two >expect && - set_askpass user@host && + set_askpass user@host pass@host && git clone --bare "$HTTPD_URL/auth/smart/repo.git" smart-auth && expect_askpass both user@host && git --git-dir=smart-auth log -1 --format=%s >actual && @@ -133,7 +136,7 @@ test_expect_success 'clone from auth-only-for-push repository' ' test_expect_success 'clone from auth-only-for-objects repository' ' echo two >expect && - set_askpass user@host && + set_askpass user@host pass@host && git clone --bare "$HTTPD_URL/auth-fetch/smart/repo.git" half-auth && expect_askpass both user@host && git --git-dir=half-auth log -1 --format=%s >actual && @@ -146,6 +149,13 @@ test_expect_success 'no-op half-auth fetch does not require a password' ' expect_askpass none ' +test_expect_success 'redirects send auth to new location' ' + set_askpass user@host pass@host && + git -c credential.useHttpPath=true \ + clone $HTTPD_URL/smart-redir-auth/repo.git repo-redir-auth && + expect_askpass both user@host auth/smart/repo.git +' + test_expect_success 'disable dumb http on server' ' git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \ config http.getanyfile false @@ -187,6 +197,22 @@ test_expect_success 'dumb clone via http-backend respects namespace' ' test_cmp expect actual ' +cat >cookies.txt <<EOF +127.0.0.1 FALSE /smart_cookies/ FALSE 0 othername othervalue +EOF +cat >expect_cookies.txt <<EOF + +127.0.0.1 FALSE /smart_cookies/ FALSE 0 othername othervalue +127.0.0.1 FALSE /smart_cookies/repo.git/info/ FALSE 0 name value +EOF +test_expect_success 'cookies stored in http.cookiefile when http.savecookies set' ' + git config http.cookiefile cookies.txt && + git config http.savecookies true && + git ls-remote $HTTPD_URL/smart_cookies/repo.git master && + tail -3 cookies.txt > cookies_tail.txt + test_cmp expect_cookies.txt cookies_tail.txt +' + test -n "$GIT_TEST_LONG" && test_set_prereq EXPENSIVE test_expect_success EXPENSIVE 'create 50,000 tags in the repo' ' @@ -208,7 +234,7 @@ test_expect_success EXPENSIVE 'create 50,000 tags in the repo' ' done | git fast-import --export-marks=marks && # now assign tags to all the dangling commits we created above - tag=$("$PERL_PATH" -e "print \"bla\" x 30") && + tag=$(perl -e "print \"bla\" x 30") && sed -e "s|^:\([^ ]*\) \(.*\)$|\2 refs/tags/$tag-\1|" <marks >>packed-refs ) ' diff --git a/t/t5561-http-backend.sh b/t/t5561-http-backend.sh index b5d7fbc381..d23fb02384 100755 --- a/t/t5561-http-backend.sh +++ b/t/t5561-http-backend.sh @@ -8,7 +8,6 @@ if test -n "$NO_CURL"; then test_done fi -LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5561'} . "$TEST_DIRECTORY"/lib-httpd.sh start_httpd diff --git a/t/t5570-git-daemon.sh b/t/t5570-git-daemon.sh index f01edffa3c..6b16379951 100755 --- a/t/t5570-git-daemon.sh +++ b/t/t5570-git-daemon.sh @@ -3,7 +3,6 @@ test_description='test fetching over git protocol' . ./test-lib.sh -LIB_GIT_DAEMON_PORT=${LIB_GIT_DAEMON_PORT-5570} . "$TEST_DIRECTORY"/lib-git-daemon.sh start_git_daemon @@ -37,7 +36,7 @@ test_expect_success 'fetch changes via git protocol' ' test_cmp file clone/file ' -test_expect_failure 'remote detects correct HEAD' ' +test_expect_success 'remote detects correct HEAD' ' git push public master:other && (cd clone && git remote set-head -d origin && @@ -122,8 +121,7 @@ test_remote_error() fi test_must_fail git "$cmd" "$GIT_DAEMON_URL/$repo" "$@" 2>output && - echo "fatal: remote error: $msg: /$repo" >expect && - test_cmp expect output + test_i18ngrep "fatal: remote error: $msg: /$repo" output && ret=$? chmod +x "$GIT_DAEMON_DOCUMENT_ROOT_PATH/repo.git" (exit $ret) diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh index 0629149edd..5e67035be8 100755 --- a/t/t5601-clone.sh +++ b/t/t5601-clone.sh @@ -36,7 +36,7 @@ test_expect_success 'clone with excess parameters (2)' ' test_expect_success C_LOCALE_OUTPUT 'output from clone' ' rm -fr dst && - git clone -n "file://$(pwd)/src" dst >output && + git clone -n "file://$(pwd)/src" dst >output 2>&1 && test $(grep Clon output | wc -l) = 1 ' @@ -280,9 +280,161 @@ test_expect_success 'clone checking out a tag' ' test_cmp fetch.expected fetch.actual ' +setup_ssh_wrapper () { + test_expect_success 'setup ssh wrapper' ' + write_script "$TRASH_DIRECTORY/ssh-wrapper" <<-\EOF && + echo >>"$TRASH_DIRECTORY/ssh-output" "ssh: $*" && + # throw away all but the last argument, which should be the + # command + while test $# -gt 1; do shift; done + eval "$1" + EOF + GIT_SSH="$TRASH_DIRECTORY/ssh-wrapper" && + export GIT_SSH && + export TRASH_DIRECTORY && + >"$TRASH_DIRECTORY"/ssh-output + ' +} + +expect_ssh () { + test_when_finished ' + (cd "$TRASH_DIRECTORY" && rm -f ssh-expect && >ssh-output) + ' && + { + case "$1" in + none) + ;; + *) + echo "ssh: $1 git-upload-pack '$2'" + esac + } >"$TRASH_DIRECTORY/ssh-expect" && + (cd "$TRASH_DIRECTORY" && test_cmp ssh-expect ssh-output) +} + +setup_ssh_wrapper + +test_expect_success 'clone myhost:src uses ssh' ' + git clone myhost:src ssh-clone && + expect_ssh myhost src +' + test_expect_success NOT_MINGW,NOT_CYGWIN 'clone local path foo:bar' ' cp -R src "foo:bar" && - git clone "./foo:bar" foobar + git clone "foo:bar" foobar && + expect_ssh none +' + +test_expect_success 'bracketed hostnames are still ssh' ' + git clone "[myhost:123]:src" ssh-bracket-clone && + expect_ssh myhost:123 src +' + +counter=0 +# $1 url +# $2 none|host +# $3 path +test_clone_url () { + counter=$(($counter + 1)) + test_might_fail git clone "$1" tmp$counter && + expect_ssh "$2" "$3" +} + +test_expect_success NOT_MINGW 'clone c:temp is ssl' ' + test_clone_url c:temp c temp +' + +test_expect_success MINGW 'clone c:temp is dos drive' ' + test_clone_url c:temp none +' + +#ip v4 +for repo in rep rep/home/project 123 +do + test_expect_success "clone host:$repo" ' + test_clone_url host:$repo host $repo + ' +done + +#ipv6 +for repo in rep rep/home/project 123 +do + test_expect_success "clone [::1]:$repo" ' + test_clone_url [::1]:$repo ::1 $repo + ' +done +#home directory +test_expect_success "clone host:/~repo" ' + test_clone_url host:/~repo host "~repo" +' + +test_expect_success "clone [::1]:/~repo" ' + test_clone_url [::1]:/~repo ::1 "~repo" +' + +# Corner cases +for url in foo/bar:baz [foo]bar/baz:qux [foo/bar]:baz +do + test_expect_success "clone $url is not ssh" ' + test_clone_url $url none + ' +done + +#with ssh:// scheme +test_expect_success 'clone ssh://host.xz/home/user/repo' ' + test_clone_url "ssh://host.xz/home/user/repo" host.xz "/home/user/repo" +' + +# from home directory +test_expect_success 'clone ssh://host.xz/~repo' ' + test_clone_url "ssh://host.xz/~repo" host.xz "~repo" +' + +# with port number +test_expect_success 'clone ssh://host.xz:22/home/user/repo' ' + test_clone_url "ssh://host.xz:22/home/user/repo" "-p 22 host.xz" "/home/user/repo" +' + +# from home directory with port number +test_expect_success 'clone ssh://host.xz:22/~repo' ' + test_clone_url "ssh://host.xz:22/~repo" "-p 22 host.xz" "~repo" +' + +#IPv6 +test_expect_success 'clone ssh://[::1]/home/user/repo' ' + test_clone_url "ssh://[::1]/home/user/repo" "::1" "/home/user/repo" +' + +#IPv6 from home directory +test_expect_success 'clone ssh://[::1]/~repo' ' + test_clone_url "ssh://[::1]/~repo" "::1" "~repo" +' + +#IPv6 with port number +test_expect_success 'clone ssh://[::1]:22/home/user/repo' ' + test_clone_url "ssh://[::1]:22/home/user/repo" "-p 22 ::1" "/home/user/repo" +' + +#IPv6 from home directory with port number +test_expect_success 'clone ssh://[::1]:22/~repo' ' + test_clone_url "ssh://[::1]:22/~repo" "-p 22 ::1" "~repo" +' + +test_expect_success 'clone from a repository with two identical branches' ' + + ( + cd src && + git checkout -b another master + ) && + git clone src target-11 && + test "z$( cd target-11 && git symbolic-ref HEAD )" = zrefs/heads/another + +' + +test_expect_success 'shallow clone locally' ' + git clone --depth=1 --no-local src ssrrcc && + git clone ssrrcc ddsstt && + test_cmp ssrrcc/.git/shallow ddsstt/.git/shallow && + ( cd ddsstt && git fsck ) ' test_done diff --git a/t/t5602-clone-remote-exec.sh b/t/t5602-clone-remote-exec.sh index 3f353d99e8..cbcceab9d5 100755 --- a/t/t5602-clone-remote-exec.sh +++ b/t/t5602-clone-remote-exec.sh @@ -12,21 +12,14 @@ test_expect_success setup ' ' test_expect_success 'clone calls git upload-pack unqualified with no -u option' ' - ( - GIT_SSH=./not_ssh && - export GIT_SSH && - test_must_fail git clone localhost:/path/to/repo junk - ) && + test_must_fail env GIT_SSH=./not_ssh git clone localhost:/path/to/repo junk && echo "localhost git-upload-pack '\''/path/to/repo'\''" >expected && test_cmp expected not_ssh_output ' test_expect_success 'clone calls specified git upload-pack with -u option' ' - ( - GIT_SSH=./not_ssh && - export GIT_SSH && - test_must_fail git clone -u ./something/bin/git-upload-pack localhost:/path/to/repo junk - ) && + test_must_fail env GIT_SSH=./not_ssh \ + git clone -u ./something/bin/git-upload-pack localhost:/path/to/repo junk && echo "localhost ./something/bin/git-upload-pack '\''/path/to/repo'\''" >expected && test_cmp expected not_ssh_output ' diff --git a/t/t5701-clone-local.sh b/t/t5701-clone-local.sh index 7ff6e0e16c..c4903687fb 100755 --- a/t/t5701-clone-local.sh +++ b/t/t5701-clone-local.sh @@ -134,4 +134,8 @@ test_expect_success 'cloning a local path with --no-local does not hardlink' ' ! repo_is_hardlinked force-nonlocal ' +test_expect_success 'cloning locally respects "-u" for fetching refs' ' + test_must_fail git clone --bare -u false a should_not_work.git +' + test_done diff --git a/t/t5702-clone-options.sh b/t/t5702-clone-options.sh index 85cadfad6d..9e24ec88e6 100755 --- a/t/t5702-clone-options.sh +++ b/t/t5702-clone-options.sh @@ -19,17 +19,19 @@ test_expect_success 'clone -o' ' ' -test_expect_success 'redirected clone' ' +test_expect_success 'redirected clone does not show progress' ' git clone "file://$(pwd)/parent" clone-redirected >out 2>err && - test_must_be_empty err + ! grep % err && + test_i18ngrep ! "Checking connectivity" err ' -test_expect_success 'redirected clone -v' ' + +test_expect_success 'redirected clone -v does show progress' ' git clone --progress "file://$(pwd)/parent" clone-redirected-progress \ >out 2>err && - test -s err + grep % err ' diff --git a/t/t5706-clone-branch.sh b/t/t5706-clone-branch.sh index 56be67e07e..6e7a7be052 100755 --- a/t/t5706-clone-branch.sh +++ b/t/t5706-clone-branch.sh @@ -20,7 +20,9 @@ test_expect_success 'setup' ' echo one >file && git add file && git commit -m one && git checkout -b two && echo two >file && git add file && git commit -m two && - git checkout master) + git checkout master) && + mkdir empty && + (cd empty && git init) ' test_expect_success 'vanilla clone chooses HEAD' ' @@ -61,4 +63,8 @@ test_expect_success 'clone -b with bogus branch' ' test_must_fail git clone -b bogus parent clone-bogus ' +test_expect_success 'clone -b not allowed with empty repos' ' + test_must_fail git clone -b branch empty clone-branch-empty +' + test_done diff --git a/t/t5800-remote-testpy.sh b/t/t5800-remote-testpy.sh deleted file mode 100755 index 1e683d4220..0000000000 --- a/t/t5800-remote-testpy.sh +++ /dev/null @@ -1,169 +0,0 @@ -#!/bin/sh -# -# Copyright (c) 2010 Sverre Rabbelier -# - -test_description='Test python remote-helper framework' - -. ./test-lib.sh - -if ! test_have_prereq PYTHON ; then - skip_all='skipping python remote-helper tests, python not available' - test_done -fi - -"$PYTHON_PATH" -c ' -import sys -if sys.hexversion < 0x02040000: - sys.exit(1) -' || { - skip_all='skipping python remote-helper tests, python version < 2.4' - test_done -} - -compare_refs() { - git --git-dir="$1/.git" rev-parse --verify $2 >expect && - git --git-dir="$3/.git" rev-parse --verify $4 >actual && - test_cmp expect actual -} - -test_expect_success 'setup repository' ' - git init --bare server/.git && - git clone server public && - (cd public && - echo content >file && - git add file && - git commit -m one && - git push origin master) -' - -test_expect_success 'cloning from local repo' ' - git clone "testpy::${PWD}/server" localclone && - test_cmp public/file localclone/file -' - -test_expect_success 'cloning from remote repo' ' - git clone "testpy::file://${PWD}/server" clone && - test_cmp public/file clone/file -' - -test_expect_success 'create new commit on remote' ' - (cd public && - echo content >>file && - git commit -a -m two && - git push) -' - -test_expect_success 'pulling from local repo' ' - (cd localclone && git pull) && - test_cmp public/file localclone/file -' - -test_expect_success 'pulling from remote remote' ' - (cd clone && git pull) && - test_cmp public/file clone/file -' - -test_expect_success 'pushing to local repo' ' - (cd localclone && - echo content >>file && - git commit -a -m three && - git push) && - compare_refs localclone HEAD server HEAD -' - -# Generally, skip this test. It demonstrates a now-fixed race in -# git-remote-testpy, but is too slow to leave in for general use. -: test_expect_success 'racily pushing to local repo' ' - test_when_finished "rm -rf server2 localclone2" && - cp -R server server2 && - git clone "testpy::${PWD}/server2" localclone2 && - (cd localclone2 && - echo content >>file && - git commit -a -m three && - GIT_REMOTE_TESTGIT_SLEEPY=2 git push) && - compare_refs localclone2 HEAD server2 HEAD -' - -test_expect_success 'synch with changes from localclone' ' - (cd clone && - git pull) -' - -test_expect_success 'pushing remote local repo' ' - (cd clone && - echo content >>file && - git commit -a -m four && - git push) && - compare_refs clone HEAD server HEAD -' - -test_expect_success 'fetch new branch' ' - (cd public && - git checkout -b new && - echo content >>file && - git commit -a -m five && - git push origin new - ) && - (cd localclone && - git fetch origin new - ) && - compare_refs public HEAD localclone FETCH_HEAD -' - -test_expect_success 'fetch multiple branches' ' - (cd localclone && - git fetch - ) && - compare_refs server master localclone refs/remotes/origin/master && - compare_refs server new localclone refs/remotes/origin/new -' - -test_expect_success 'push when remote has extra refs' ' - (cd clone && - echo content >>file && - git commit -a -m six && - git push - ) && - compare_refs clone master server master -' - -test_expect_success 'push new branch by name' ' - (cd clone && - git checkout -b new-name && - echo content >>file && - git commit -a -m seven && - git push origin new-name - ) && - compare_refs clone HEAD server refs/heads/new-name -' - -test_expect_failure 'push new branch with old:new refspec' ' - (cd clone && - git push origin new-name:new-refspec - ) && - compare_refs clone HEAD server refs/heads/new-refspec -' - -test_expect_success 'proper failure checks for fetching' ' - (GIT_REMOTE_TESTGIT_FAILURE=1 && - export GIT_REMOTE_TESTGIT_FAILURE && - cd localclone && - test_must_fail git fetch 2>&1 | \ - grep "Error while running fast-import" - ) -' - -# We sleep to give fast-export a chance to catch the SIGPIPE -test_expect_failure 'proper failure checks for pushing' ' - (GIT_REMOTE_TESTGIT_FAILURE=1 && - export GIT_REMOTE_TESTGIT_FAILURE && - GIT_REMOTE_TESTGIT_SLEEPY=1 && - export GIT_REMOTE_TESTGIT_SLEEPY && - cd localclone && - test_must_fail git push --all 2>&1 | \ - grep "Error while running fast-export" - ) -' - -test_done diff --git a/t/t5801-remote-helpers.sh b/t/t5801-remote-helpers.sh index 8c4c5396a8..25fd2e7f46 100755 --- a/t/t5801-remote-helpers.sh +++ b/t/t5801-remote-helpers.sh @@ -94,6 +94,19 @@ test_expect_failure 'push new branch with old:new refspec' ' compare_refs local HEAD server refs/heads/new-refspec ' +test_expect_success 'forced push' ' + (cd local && + git checkout -b force-test && + echo content >> file && + git commit -a -m eight && + git push origin force-test && + echo content >> file && + git commit -a --amend -m eight-modified && + git push --force origin force-test + ) && + compare_refs local refs/heads/force-test server refs/heads/force-test +' + test_expect_success 'cloning without refspec' ' GIT_REMOTE_TESTGIT_REFSPEC="" \ git clone "testgit::${PWD}/server" local2 2>error && @@ -182,6 +195,17 @@ test_expect_success 'push update refs' ' ) ' +test_expect_success 'push update refs disabled by no-private-update' ' + (cd local && + echo more-update >>file && + git commit -a -m more-update && + git rev-parse --verify testgit/origin/heads/update >expect && + GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE=t git push origin update && + git rev-parse --verify testgit/origin/heads/update >actual && + test_cmp expect actual + ) +' + test_expect_success 'push update refs failure' ' (cd local && git checkout update && @@ -207,10 +231,8 @@ test_expect_success 'proper failure checks for fetching' ' ' test_expect_success 'proper failure checks for pushing' ' - (GIT_REMOTE_TESTGIT_FAILURE=1 && - export GIT_REMOTE_TESTGIT_FAILURE && - cd local && - test_must_fail git push --all + (cd local && + test_must_fail env GIT_REMOTE_TESTGIT_FAILURE=1 git push --all ) ' diff --git a/t/t5802-connect-helper.sh b/t/t5802-connect-helper.sh new file mode 100755 index 0000000000..878faf2b63 --- /dev/null +++ b/t/t5802-connect-helper.sh @@ -0,0 +1,72 @@ +#!/bin/sh + +test_description='ext::cmd remote "connect" helper' +. ./test-lib.sh + +test_expect_success setup ' + test_tick && + git commit --allow-empty -m initial && + test_tick && + git commit --allow-empty -m second && + test_tick && + git commit --allow-empty -m third && + test_tick && + git tag -a -m "tip three" three && + + test_tick && + git commit --allow-empty -m fourth +' + +test_expect_success clone ' + cmd=$(echo "echo >&2 ext::sh invoked && %S .." | sed -e "s/ /% /g") && + git clone "ext::sh -c %S% ." dst && + git for-each-ref refs/heads/ refs/tags/ >expect && + ( + cd dst && + git config remote.origin.url "ext::sh -c $cmd" && + git for-each-ref refs/heads/ refs/tags/ + ) >actual && + test_cmp expect actual +' + +test_expect_success 'update following tag' ' + test_tick && + git commit --allow-empty -m fifth && + test_tick && + git tag -a -m "tip five" five && + git for-each-ref refs/heads/ refs/tags/ >expect && + ( + cd dst && + git pull && + git for-each-ref refs/heads/ refs/tags/ >../actual + ) && + test_cmp expect actual +' + +test_expect_success 'update backfilled tag' ' + test_tick && + git commit --allow-empty -m sixth && + test_tick && + git tag -a -m "tip two" two three^1 && + git for-each-ref refs/heads/ refs/tags/ >expect && + ( + cd dst && + git pull && + git for-each-ref refs/heads/ refs/tags/ >../actual + ) && + test_cmp expect actual +' + +test_expect_success 'update backfilled tag without primary transfer' ' + test_tick && + git tag -a -m "tip one " one two^1 && + git for-each-ref refs/heads/ refs/tags/ >expect && + ( + cd dst && + git pull && + git for-each-ref refs/heads/ refs/tags/ >../actual + ) && + test_cmp expect actual +' + +test_done diff --git a/t/t6000-rev-list-misc.sh b/t/t6000-rev-list-misc.sh index b10685af4e..3794e4ceaf 100755 --- a/t/t6000-rev-list-misc.sh +++ b/t/t6000-rev-list-misc.sh @@ -48,4 +48,29 @@ test_expect_success 'rev-list --objects with pathspecs and copied files' ' ! grep one output ' +test_expect_success 'rev-list A..B and rev-list ^A B are the same' ' + git commit --allow-empty -m another && + git tag -a -m "annotated" v1.0 && + git rev-list --objects ^v1.0^ v1.0 >expect && + git rev-list --objects v1.0^..v1.0 >actual && + test_cmp expect actual +' + +test_expect_success 'propagate uninteresting flag down correctly' ' + git rev-list --objects ^HEAD^{tree} HEAD^{tree} >actual && + >expect && + test_cmp expect actual +' + +test_expect_success 'symleft flag bit is propagated down from tag' ' + git log --format="%m %s" --left-right v1.0...master >actual && + cat >expect <<-\EOF && + > two + > one + < another + < that + EOF + test_cmp expect actual +' + test_done diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh index 98744038ec..9d9d9de08e 100755 --- a/t/t6006-rev-list-format.sh +++ b/t/t6006-rev-list-format.sh @@ -190,12 +190,9 @@ test_expect_success '%C(auto) respects --no-color' ' ' test_expect_success TTY '%C(auto) respects --color=auto (stdout is tty)' ' - ( - TERM=vt100 && export TERM && - test_terminal \ - git log --format=$AUTO_COLOR -1 --color=auto >actual && - has_color actual - ) + test_terminal env TERM=vt100 \ + git log --format=$AUTO_COLOR -1 --color=auto >actual && + has_color actual ' test_expect_success '%C(auto) respects --color=auto (stdout not tty)' ' diff --git a/t/t6010-merge-base.sh b/t/t6010-merge-base.sh index f80bba871c..39b3238da2 100755 --- a/t/t6010-merge-base.sh +++ b/t/t6010-merge-base.sh @@ -230,4 +230,71 @@ test_expect_success 'criss-cross merge-base for octopus-step' ' test_cmp expected.sorted actual.sorted ' +test_expect_success 'using reflog to find the fork point' ' + git reset --hard && + git checkout -b base $E && + + ( + for count in 1 2 3 + do + git commit --allow-empty -m "Base commit #$count" && + git rev-parse HEAD >expect$count && + git checkout -B derived && + git commit --allow-empty -m "Derived #$count" && + git rev-parse HEAD >derived$count && + git checkout -B base $E || exit 1 + done + + for count in 1 2 3 + do + git merge-base --fork-point base $(cat derived$count) >actual && + test_cmp expect$count actual || exit 1 + done + + ) && + # check that we correctly default to HEAD + git checkout derived && + git merge-base --fork-point base >actual && + test_cmp expect3 actual +' + +test_expect_success 'merge-base --octopus --all for complex tree' ' + # Best common ancestor for JE, JAA and JDD is JC + # JE + # / | + # / | + # / | + # JAA / | + # |\ / | + # | \ | JDD | + # | \ |/ | | + # | JC JD | + # | | /| | + # | |/ | | + # JA | | | + # |\ /| | | + # X JB | X X + # \ \ | / / + # \__\|/___/ + # J + test_commit J && + test_commit JB && + git reset --hard J && + test_commit JC && + git reset --hard J && + test_commit JTEMP1 && + test_merge JA JB && + test_merge JAA JC && + git reset --hard J && + test_commit JTEMP2 && + test_merge JD JB && + test_merge JDD JC && + git reset --hard J && + test_commit JTEMP3 && + test_merge JE JC && + git rev-parse JC >expected && + git merge-base --all --octopus JAA JDD JE >actual && + test_cmp expected actual +' + test_done diff --git a/t/t6011-rev-list-with-bad-commit.sh b/t/t6011-rev-list-with-bad-commit.sh index bbb0581f88..e51eb41f4b 100755 --- a/t/t6011-rev-list-with-bad-commit.sh +++ b/t/t6011-rev-list-with-bad-commit.sh @@ -37,7 +37,7 @@ test_expect_success 'verify number of revisions' \ test_expect_success 'corrupt second commit object' \ ' - "$PERL_PATH" -i.bak -pe "s/second commit/socond commit/" .git/objects/pack/*.pack && + perl -i.bak -pe "s/second commit/socond commit/" .git/objects/pack/*.pack && test_must_fail git fsck --full ' diff --git a/t/t6012-rev-list-simplify.sh b/t/t6012-rev-list-simplify.sh index 57ce2395d6..fde5e712eb 100755 --- a/t/t6012-rev-list-simplify.sh +++ b/t/t6012-rev-list-simplify.sh @@ -127,4 +127,10 @@ test_expect_success 'full history simplification without parent' ' } ' +test_expect_success '--full-diff is not affected by --parents' ' + git log -p --pretty="%H" --full-diff -- file >expected && + git log -p --pretty="%H" --full-diff --parents -- file >actual && + test_cmp expected actual +' + test_done diff --git a/t/t6013-rev-list-reverse-parents.sh b/t/t6013-rev-list-reverse-parents.sh index 892a537989..59fc2f06e0 100755 --- a/t/t6013-rev-list-reverse-parents.sh +++ b/t/t6013-rev-list-reverse-parents.sh @@ -25,7 +25,7 @@ test_expect_success 'set up --reverse example' ' test_expect_success '--reverse --parents --full-history combines correctly' ' git rev-list --parents --full-history master -- foo | - "$PERL_PATH" -e "print reverse <>" > expected && + perl -e "print reverse <>" > expected && git rev-list --reverse --parents --full-history master -- foo \ > actual && test_cmp actual expected @@ -33,7 +33,7 @@ test_expect_success '--reverse --parents --full-history combines correctly' ' test_expect_success '--boundary does too' ' git rev-list --boundary --parents --full-history master ^root -- foo | - "$PERL_PATH" -e "print reverse <>" > expected && + perl -e "print reverse <>" > expected && git rev-list --boundary --reverse --parents --full-history \ master ^root -- foo > actual && test_cmp actual expected diff --git a/t/t6018-rev-list-glob.sh b/t/t6018-rev-list-glob.sh index f00cebff3e..d00f7db868 100755 --- a/t/t6018-rev-list-glob.sh +++ b/t/t6018-rev-list-glob.sh @@ -129,6 +129,18 @@ test_expect_success 'rev-parse --remotes=foo' ' ' +test_expect_success 'rev-parse --exclude with --branches' ' + compare rev-parse "--exclude=*/* --branches" "master someref subspace-x" +' + +test_expect_success 'rev-parse --exclude with --all' ' + compare rev-parse "--exclude=refs/remotes/* --all" "--branches --tags" +' + +test_expect_success 'rev-parse accumulates multiple --exclude' ' + compare rev-parse "--exclude=refs/remotes/* --exclude=refs/tags/* --all" --branches +' + test_expect_success 'rev-list --glob=refs/heads/subspace/*' ' compare rev-list "subspace/one subspace/two" "--glob=refs/heads/subspace/*" @@ -231,6 +243,48 @@ test_expect_success 'rev-list --remotes=foo' ' ' +test_expect_success 'rev-list --exclude with --branches' ' + compare rev-list "--exclude=*/* --branches" "master someref subspace-x" +' + +test_expect_success 'rev-list --exclude with --all' ' + compare rev-list "--exclude=refs/remotes/* --all" "--branches --tags" +' + +test_expect_success 'rev-list accumulates multiple --exclude' ' + compare rev-list "--exclude=refs/remotes/* --exclude=refs/tags/* --all" --branches +' + + +# "git rev-list<ENTER>" is likely to be a bug in the calling script and may +# deserve an error message, but do cases where set of refs programatically +# given using globbing and/or --stdin need to fail with the same error, or +# are we better off reporting a success with no output? The following few +# tests document the current behaviour to remind us that we might want to +# think about this issue. + +test_expect_failure 'rev-list may want to succeed with empty output on no input (1)' ' + >expect && + git rev-list --stdin <expect >actual && + test_cmp expect actual +' + +test_expect_failure 'rev-list may want to succeed with empty output on no input (2)' ' + >expect && + git rev-list --exclude=* --all >actual && + test_cmp expect actual +' + +test_expect_failure 'rev-list may want to succeed with empty output on no input (3)' ' + ( + test_create_repo empty && + cd empty && + >expect && + git rev-list --all >actual && + test_cmp expect actual + ) +' + test_expect_success 'shortlog accepts --glob/--tags/--remotes' ' compare shortlog "subspace/one subspace/two" --branches=subspace && diff --git a/t/t6022-merge-rename.sh b/t/t6022-merge-rename.sh index c680f789a7..a89dfbef08 100755 --- a/t/t6022-merge-rename.sh +++ b/t/t6022-merge-rename.sh @@ -259,7 +259,7 @@ test_expect_success 'setup for rename + d/f conflicts' ' printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >sub/file && echo foo >dir/file-in-the-way && git add -A && - git commit -m "Common commmit" && + git commit -m "Common commit" && echo 11 >>sub/file && echo more >>dir/file-in-the-way && @@ -439,7 +439,7 @@ test_expect_success 'setup both rename source and destination involved in D/F co mkdir one && echo stuff >one/file && git add -A && - git commit -m "Common commmit" && + git commit -m "Common commit" && git mv one/file destdir && git commit -m "Renamed to destdir" && @@ -479,7 +479,7 @@ test_expect_success 'setup pair rename to parent of other (D/F conflicts)' ' echo stuff >one/file && echo other >two/file && git add -A && - git commit -m "Common commmit" && + git commit -m "Common commit" && git rm -rf one && git mv two/file one && @@ -539,7 +539,7 @@ test_expect_success 'setup rename of one file to two, with directories in the wa echo stuff >original && git add -A && - git commit -m "Common commmit" && + git commit -m "Common commit" && mkdir two && >two/file && @@ -583,7 +583,7 @@ test_expect_success 'setup rename one file to two; directories moving out of the mkdir one two && touch one/file two/file && git add -A && - git commit -m "Common commmit" && + git commit -m "Common commit" && git rm -rf one && git mv original one && @@ -618,7 +618,7 @@ test_expect_success 'setup avoid unnecessary update, normal rename' ' printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >original && git add -A && - git commit -m "Common commmit" && + git commit -m "Common commit" && git mv original rename && echo 11 >>rename && @@ -649,7 +649,7 @@ test_expect_success 'setup to test avoiding unnecessary update, with D/F conflic mkdir df && printf "1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n" >df/file && git add -A && - git commit -m "Common commmit" && + git commit -m "Common commit" && git mv df/file temp && rm -rf df && diff --git a/t/t6031-merge-recursive.sh b/t/t6031-merge-recursive.sh index 1cd649e245..a953f1b55c 100755 --- a/t/t6031-merge-recursive.sh +++ b/t/t6031-merge-recursive.sh @@ -2,7 +2,6 @@ test_description='merge-recursive: handle file mode' . ./test-lib.sh -. "$TEST_DIRECTORY"/lib-prereq-FILEMODE.sh test_expect_success 'mode change in one branch: keep changed version' ' : >file1 && diff --git a/t/t6040-tracking-info.sh b/t/t6040-tracking-info.sh index ec2b516c3f..7ac8fd06c3 100755 --- a/t/t6040-tracking-info.sh +++ b/t/t6040-tracking-info.sh @@ -28,18 +28,25 @@ test_expect_success setup ' git reset --hard HEAD^ && git checkout -b b4 origin && advance e && - advance f + advance f && + git checkout -b brokenbase origin && + git checkout -b b5 --track brokenbase && + advance g && + git branch -d brokenbase && + git checkout -b b6 origin ) && git checkout -b follower --track master && - advance g + advance h ' -script='s/^..\(b.\)[ 0-9a-f]*\[\([^]]*\)\].*/\1 \2/p' +script='s/^..\(b.\) *[0-9a-f]* \(.*\)$/\1 \2/p' cat >expect <<\EOF -b1 ahead 1, behind 1 -b2 ahead 1, behind 1 -b3 behind 1 -b4 ahead 2 +b1 [ahead 1, behind 1] d +b2 [ahead 1, behind 1] d +b3 [behind 1] b +b4 [ahead 2] f +b5 g +b6 c EOF test_expect_success 'branch -v' ' @@ -52,10 +59,12 @@ test_expect_success 'branch -v' ' ' cat >expect <<\EOF -b1 origin/master: ahead 1, behind 1 -b2 origin/master: ahead 1, behind 1 -b3 origin/master: behind 1 -b4 origin/master: ahead 2 +b1 [origin/master: ahead 1, behind 1] d +b2 [origin/master: ahead 1, behind 1] d +b3 [origin/master: behind 1] b +b4 [origin/master: ahead 2] f +b5 [brokenbase: gone] g +b6 [origin/master] c EOF test_expect_success 'branch -vv' ' @@ -67,7 +76,7 @@ test_expect_success 'branch -vv' ' test_i18ncmp expect actual ' -test_expect_success 'checkout' ' +test_expect_success 'checkout (diverged from upstream)' ' ( cd test && git checkout b1 ) >actual && @@ -80,7 +89,22 @@ test_expect_success 'checkout with local tracked branch' ' test_i18ngrep "is ahead of" actual ' -test_expect_success 'status' ' +test_expect_success 'checkout (upstream is gone)' ' + ( + cd test && + git checkout b5 + ) >actual && + test_i18ngrep "is based on .*, but the upstream is gone." actual +' + +test_expect_success 'checkout (up-to-date with upstream)' ' + ( + cd test && git checkout b6 + ) >actual && + test_i18ngrep "Your branch is up-to-date with .origin/master" actual +' + +test_expect_success 'status (diverged from upstream)' ' ( cd test && git checkout b1 >/dev/null && @@ -90,6 +114,65 @@ test_expect_success 'status' ' test_i18ngrep "have 1 and 1 different" actual ' +test_expect_success 'status (upstream is gone)' ' + ( + cd test && + git checkout b5 >/dev/null && + # reports nothing to commit + test_must_fail git commit --dry-run + ) >actual && + test_i18ngrep "is based on .*, but the upstream is gone." actual +' + +test_expect_success 'status (up-to-date with upstream)' ' + ( + cd test && + git checkout b6 >/dev/null && + # reports nothing to commit + test_must_fail git commit --dry-run + ) >actual && + test_i18ngrep "Your branch is up-to-date with .origin/master" actual +' + +cat >expect <<\EOF +## b1...origin/master [ahead 1, behind 1] +EOF + +test_expect_success 'status -s -b (diverged from upstream)' ' + ( + cd test && + git checkout b1 >/dev/null && + git status -s -b | head -1 + ) >actual && + test_i18ncmp expect actual +' + +cat >expect <<\EOF +## b5...brokenbase [gone] +EOF + +test_expect_success 'status -s -b (upstream is gone)' ' + ( + cd test && + git checkout b5 >/dev/null && + git status -s -b | head -1 + ) >actual && + test_i18ncmp expect actual +' + +cat >expect <<\EOF +## b6...origin/master +EOF + +test_expect_success 'status -s -b (up-to-date with upstream)' ' + ( + cd test && + git checkout b6 >/dev/null && + git status -s -b | head -1 + ) >actual && + test_i18ncmp expect actual +' + test_expect_success 'fail to track lightweight tags' ' git checkout master && git tag light && diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh index decdc33c52..719a11673b 100755 --- a/t/t6050-replace.sh +++ b/t/t6050-replace.sh @@ -122,9 +122,9 @@ test_expect_success '"git replace" listing and deleting' ' test "$HASH2" = "$(git replace -l)" && test "$HASH2" = "$(git replace)" && aa=${HASH2%??????????????????????????????????????} && - test "$HASH2" = "$(git replace -l "$aa*")" && + test "$HASH2" = "$(git replace --list "$aa*")" && test_must_fail git replace -d $R && - test_must_fail git replace -d && + test_must_fail git replace --delete && test_must_fail git replace -l -d $HASH2 && git replace -d $HASH2 && git show $HASH2 | grep "A U Thor" && @@ -147,7 +147,7 @@ test_expect_success '"git replace" resolves sha1' ' git show $HASH2 | grep "O Thor" && test_must_fail git replace $HASH2 $R && git replace -f $HASH2 $R && - test_must_fail git replace -f && + test_must_fail git replace --force && test "$HASH2" = "$(git replace)" ' @@ -263,4 +263,65 @@ test_expect_success 'not just commits' ' test_cmp file.replaced file ' +test_expect_success 'replaced and replacement objects must be of the same type' ' + test_must_fail git replace mytag $HASH1 && + test_must_fail git replace HEAD^{tree} HEAD~1 && + BLOB=$(git rev-parse :file) && + test_must_fail git replace HEAD^ $BLOB +' + +test_expect_success '-f option bypasses the type check' ' + git replace -f mytag $HASH1 && + git replace --force HEAD^{tree} HEAD~1 && + git replace -f HEAD^ $BLOB +' + +test_expect_success 'git cat-file --batch works on replace objects' ' + git replace | grep $PARA3 && + echo $PARA3 | git cat-file --batch +' + +test_expect_success 'test --format bogus' ' + test_must_fail git replace --format bogus >/dev/null 2>&1 +' + +test_expect_success 'test --format short' ' + git replace --format=short >actual && + git replace >expected && + test_cmp expected actual +' + +test_expect_success 'test --format medium' ' + H1=$(git --no-replace-objects rev-parse HEAD~1) && + HT=$(git --no-replace-objects rev-parse HEAD^{tree}) && + MYTAG=$(git --no-replace-objects rev-parse mytag) && + { + echo "$H1 -> $BLOB" && + echo "$BLOB -> $REPLACED" && + echo "$HT -> $H1" && + echo "$PARA3 -> $S" && + echo "$MYTAG -> $HASH1" + } | sort >expected && + git replace -l --format medium | sort > actual && + test_cmp expected actual +' + +test_expect_success 'test --format long' ' + { + echo "$H1 (commit) -> $BLOB (blob)" && + echo "$BLOB (blob) -> $REPLACED (blob)" && + echo "$HT (tree) -> $H1 (commit)" && + echo "$PARA3 (commit) -> $S (commit)" && + echo "$MYTAG (tag) -> $HASH1 (commit)" + } | sort >expected && + git replace --format=long | sort > actual && + test_cmp expected actual +' + +test_expect_success 'replace ref cleanup' ' + test -n "$(git replace)" && + git replace -d $(git replace) && + test -z "$(git replace)" +' + test_done diff --git a/t/t6101-rev-parse-parents.sh b/t/t6101-rev-parse-parents.sh index e673c25e94..10b1452766 100755 --- a/t/t6101-rev-parse-parents.sh +++ b/t/t6101-rev-parse-parents.sh @@ -6,39 +6,100 @@ test_description='Test git rev-parse with different parent options' . ./test-lib.sh -. "$TEST_DIRECTORY"/lib-t6000.sh # t6xxx specific functions - -date >path0 -git update-index --add path0 -save_tag tree git write-tree -hide_error save_tag start unique_commit "start" tree -save_tag second unique_commit "second" tree -p start -hide_error save_tag start2 unique_commit "start2" tree -save_tag two_parents unique_commit "next" tree -p second -p start2 -save_tag final unique_commit "final" tree -p two_parents - -test_expect_success 'start is valid' 'git rev-parse start | grep "^[0-9a-f]\{40\}$"' -test_expect_success 'start^0' "test $(cat .git/refs/tags/start) = $(git rev-parse start^0)" -test_expect_success 'start^1 not valid' "if git rev-parse --verify start^1; then false; else :; fi" -test_expect_success 'second^1 = second^' "test $(git rev-parse second^1) = $(git rev-parse second^)" -test_expect_success 'final^1^1^1' "test $(git rev-parse start) = $(git rev-parse final^1^1^1)" -test_expect_success 'final^1^1^1 = final^^^' "test $(git rev-parse final^1^1^1) = $(git rev-parse final^^^)" -test_expect_success 'final^1^2' "test $(git rev-parse start2) = $(git rev-parse final^1^2)" -test_expect_success 'final^1^2 != final^1^1' "test $(git rev-parse final^1^2) != $(git rev-parse final^1^1)" -test_expect_success 'final^1^3 not valid' "if git rev-parse --verify final^1^3; then false; else :; fi" -test_expect_success '--verify start2^1' 'test_must_fail git rev-parse --verify start2^1' -test_expect_success '--verify start2^0' 'git rev-parse --verify start2^0' -test_expect_success 'final^1^@ = final^1^1 final^1^2' "test \"$(git rev-parse final^1^@)\" = \"$(git rev-parse final^1^1 final^1^2)\"" -test_expect_success 'final^1^! = final^1 ^final^1^1 ^final^1^2' "test \"$(git rev-parse final^1^\!)\" = \"$(git rev-parse final^1 ^final^1^1 ^final^1^2)\"" - -test_expect_success 'repack for next test' 'git repack -a -d' + +test_cmp_rev_output () { + git rev-parse --verify "$1" >expect && + eval "$2" >actual && + test_cmp expect actual +} + +test_expect_success 'setup' ' + test_commit start && + test_commit second && + git checkout --orphan tmp && + test_commit start2 && + git checkout master && + git merge -m next start2 && + test_commit final && + + test_seq 40 | + while read i + do + git checkout --orphan "b$i" && + test_tick && + git commit --allow-empty -m "$i" && + commit=$(git rev-parse --verify HEAD) && + printf "$commit " >>.git/info/grafts + done +' + +test_expect_success 'start is valid' ' + git rev-parse start | grep "^[0-9a-f]\{40\}$" +' + +test_expect_success 'start^0' ' + test_cmp_rev_output tags/start "git rev-parse start^0" +' + +test_expect_success 'start^1 not valid' ' + test_must_fail git rev-parse --verify start^1 +' + +test_expect_success 'second^1 = second^' ' + test_cmp_rev_output second^ "git rev-parse second^1" +' + +test_expect_success 'final^1^1^1' ' + test_cmp_rev_output start "git rev-parse final^1^1^1" +' + +test_expect_success 'final^1^1^1 = final^^^' ' + test_cmp_rev_output final^^^ "git rev-parse final^1^1^1" +' + +test_expect_success 'final^1^2' ' + test_cmp_rev_output start2 "git rev-parse final^1^2" +' + +test_expect_success 'final^1^2 != final^1^1' ' + test $(git rev-parse final^1^2) != $(git rev-parse final^1^1) +' + +test_expect_success 'final^1^3 not valid' ' + test_must_fail git rev-parse --verify final^1^3 +' + +test_expect_success '--verify start2^1' ' + test_must_fail git rev-parse --verify start2^1 +' + +test_expect_success '--verify start2^0' ' + git rev-parse --verify start2^0 +' + +test_expect_success 'final^1^@ = final^1^1 final^1^2' ' + git rev-parse final^1^1 final^1^2 >expect && + git rev-parse final^1^@ >actual && + test_cmp expect actual +' + +test_expect_success 'final^1^! = final^1 ^final^1^1 ^final^1^2' ' + git rev-parse final^1 ^final^1^1 ^final^1^2 >expect && + git rev-parse final^1^! >actual && + test_cmp expect actual +' + +test_expect_success 'large graft octopus' ' + test_cmp_rev_output b31 "git rev-parse --verify b1^30" +' + +test_expect_success 'repack for next test' ' + git repack -a -d +' + test_expect_success 'short SHA-1 works' ' - start=`git rev-parse --verify start` && - echo $start && - abbrv=`echo $start | sed s/.\$//` && - echo $abbrv && - abbrv=`git rev-parse --verify $abbrv` && - echo $abbrv && - test $start = $abbrv' + start=$(git rev-parse --verify start) && + test_cmp_rev_output start "git rev-parse ${start%?}" +' test_done diff --git a/t/t6130-pathspec-noglob.sh b/t/t6130-pathspec-noglob.sh index 39ef61994f..658353277e 100755 --- a/t/t6130-pathspec-noglob.sh +++ b/t/t6130-pathspec-noglob.sh @@ -32,6 +32,16 @@ test_expect_success 'star pathspec globs' ' test_cmp expect actual ' +test_expect_success 'star pathspec globs' ' + cat >expect <<-\EOF && + bracket + star + vanilla + EOF + git log --format=%s -- ":(glob)f*" >actual && + test_cmp expect actual +' + test_expect_success 'bracket pathspec globs and matches literal brackets' ' cat >expect <<-\EOF && bracket @@ -41,28 +51,112 @@ test_expect_success 'bracket pathspec globs and matches literal brackets' ' test_cmp expect actual ' +test_expect_success 'bracket pathspec globs and matches literal brackets' ' + cat >expect <<-\EOF && + bracket + vanilla + EOF + git log --format=%s -- ":(glob)f[o][o]" >actual && + test_cmp expect actual +' + test_expect_success 'no-glob option matches literally (vanilla)' ' echo vanilla >expect && git --literal-pathspecs log --format=%s -- foo >actual && test_cmp expect actual ' +test_expect_success 'no-glob option matches literally (vanilla)' ' + echo vanilla >expect && + git log --format=%s -- ":(literal)foo" >actual && + test_cmp expect actual +' + test_expect_success 'no-glob option matches literally (star)' ' echo star >expect && git --literal-pathspecs log --format=%s -- "f*" >actual && test_cmp expect actual ' +test_expect_success 'no-glob option matches literally (star)' ' + echo star >expect && + git log --format=%s -- ":(literal)f*" >actual && + test_cmp expect actual +' + test_expect_success 'no-glob option matches literally (bracket)' ' echo bracket >expect && git --literal-pathspecs log --format=%s -- "f[o][o]" >actual && test_cmp expect actual ' +test_expect_success 'no-glob option matches literally (bracket)' ' + echo bracket >expect && + git log --format=%s -- ":(literal)f[o][o]" >actual && + test_cmp expect actual +' + +test_expect_success 'no-glob option disables :(literal)' ' + : >expect && + git --literal-pathspecs log --format=%s -- ":(literal)foo" >actual && + test_cmp expect actual +' + test_expect_success 'no-glob environment variable works' ' echo star >expect && GIT_LITERAL_PATHSPECS=1 git log --format=%s -- "f*" >actual && test_cmp expect actual ' +test_expect_success 'blame takes global pathspec flags' ' + git --literal-pathspecs blame -- foo && + git --icase-pathspecs blame -- foo && + git --glob-pathspecs blame -- foo && + git --noglob-pathspecs blame -- foo +' + +test_expect_success 'setup xxx/bar' ' + mkdir xxx && + test_commit xxx xxx/bar +' + +test_expect_success '**/ works with :(glob)' ' + cat >expect <<-\EOF && + xxx + unrelated + EOF + git log --format=%s -- ":(glob)**/bar" >actual && + test_cmp expect actual +' + +test_expect_success '**/ does not work with --noglob-pathspecs' ' + : >expect && + git --noglob-pathspecs log --format=%s -- "**/bar" >actual && + test_cmp expect actual +' + +test_expect_success '**/ works with :(glob) and --noglob-pathspecs' ' + cat >expect <<-\EOF && + xxx + unrelated + EOF + git --noglob-pathspecs log --format=%s -- ":(glob)**/bar" >actual && + test_cmp expect actual +' + +test_expect_success '**/ works with --glob-pathspecs' ' + cat >expect <<-\EOF && + xxx + unrelated + EOF + git --glob-pathspecs log --format=%s -- "**/bar" >actual && + test_cmp expect actual +' + +test_expect_success '**/ does not work with :(literal) and --glob-pathspecs' ' + : >expect && + git --glob-pathspecs log --format=%s -- ":(literal)**/bar" >actual && + test_cmp expect actual +' + test_done diff --git a/t/t6131-pathspec-icase.sh b/t/t6131-pathspec-icase.sh new file mode 100755 index 0000000000..39fc3f6769 --- /dev/null +++ b/t/t6131-pathspec-icase.sh @@ -0,0 +1,109 @@ +#!/bin/sh + +test_description='test case insensitive pathspec limiting' +. ./test-lib.sh + +if test_have_prereq CASE_INSENSITIVE_FS +then + skip_all='skipping case sensitive tests - case insensitive file system' + test_done +fi + +test_expect_success 'create commits with glob characters' ' + test_commit bar bar && + test_commit bAr bAr && + test_commit BAR BAR && + mkdir foo && + test_commit foo/bar foo/bar && + test_commit foo/bAr foo/bAr && + test_commit foo/BAR foo/BAR && + mkdir fOo && + test_commit fOo/bar fOo/bar && + test_commit fOo/bAr fOo/bAr && + test_commit fOo/BAR fOo/BAR && + mkdir FOO && + test_commit FOO/bar FOO/bar && + test_commit FOO/bAr FOO/bAr && + test_commit FOO/BAR FOO/BAR +' + +test_expect_success 'tree_entry_interesting matches bar' ' + echo bar >expect && + git log --format=%s -- "bar" >actual && + test_cmp expect actual +' + +test_expect_success 'tree_entry_interesting matches :(icase)bar' ' + cat <<-EOF >expect && + BAR + bAr + bar + EOF + git log --format=%s -- ":(icase)bar" >actual && + test_cmp expect actual +' + +test_expect_success 'tree_entry_interesting matches :(icase)bar with prefix' ' + cat <<-EOF >expect && + fOo/BAR + fOo/bAr + fOo/bar + EOF + ( cd fOo && git log --format=%s -- ":(icase)bar" ) >actual && + test_cmp expect actual +' + +test_expect_success 'tree_entry_interesting matches :(icase)bar with empty prefix' ' + cat <<-EOF >expect && + FOO/BAR + FOO/bAr + FOO/bar + fOo/BAR + fOo/bAr + fOo/bar + foo/BAR + foo/bAr + foo/bar + EOF + ( cd fOo && git log --format=%s -- ":(icase)../foo/bar" ) >actual && + test_cmp expect actual +' + +test_expect_success 'match_pathspec matches :(icase)bar' ' + cat <<-EOF >expect && + BAR + bAr + bar + EOF + git ls-files ":(icase)bar" >actual && + test_cmp expect actual +' + +test_expect_success 'match_pathspec matches :(icase)bar with prefix' ' + cat <<-EOF >expect && + fOo/BAR + fOo/bAr + fOo/bar + EOF + ( cd fOo && git ls-files --full-name ":(icase)bar" ) >actual && + test_cmp expect actual +' + +test_expect_success 'match_pathspec matches :(icase)bar with empty prefix' ' + cat <<-EOF >expect && + bar + fOo/BAR + fOo/bAr + fOo/bar + EOF + ( cd fOo && git ls-files --full-name ":(icase)bar" ../bar ) >actual && + test_cmp expect actual +' + +test_expect_success '"git diff" can take magic :(icase) pathspec' ' + echo FOO/BAR >expect && + git diff --name-only HEAD^ HEAD -- ":(icase)foo/bar" >actual && + test_cmp expect actual +' + +test_done diff --git a/t/t6132-pathspec-exclude.sh b/t/t6132-pathspec-exclude.sh new file mode 100755 index 0000000000..62049be0c7 --- /dev/null +++ b/t/t6132-pathspec-exclude.sh @@ -0,0 +1,184 @@ +#!/bin/sh + +test_description='test case exclude pathspec' + +. ./test-lib.sh + +test_expect_success 'setup' ' + for p in file sub/file sub/sub/file sub/file2 sub/sub/sub/file sub2/file; do + if echo $p | grep /; then + mkdir -p `dirname $p` + fi && + : >$p && + git add $p && + git commit -m $p + done && + git log --oneline --format=%s >actual && + cat <<EOF >expect && +sub2/file +sub/sub/sub/file +sub/file2 +sub/sub/file +sub/file +file +EOF + test_cmp expect actual +' + +test_expect_success 'exclude only should error out' ' + test_must_fail git log --oneline --format=%s -- ":(exclude)sub" +' + +test_expect_success 't_e_i() exclude sub' ' + git log --oneline --format=%s -- . ":(exclude)sub" >actual + cat <<EOF >expect && +sub2/file +file +EOF + test_cmp expect actual +' + +test_expect_success 't_e_i() exclude sub/sub/file' ' + git log --oneline --format=%s -- . ":(exclude)sub/sub/file" >actual + cat <<EOF >expect && +sub2/file +sub/sub/sub/file +sub/file2 +sub/file +file +EOF + test_cmp expect actual +' + +test_expect_success 't_e_i() exclude sub using mnemonic' ' + git log --oneline --format=%s -- . ":!sub" >actual + cat <<EOF >expect && +sub2/file +file +EOF + test_cmp expect actual +' + +test_expect_success 't_e_i() exclude :(icase)SUB' ' + git log --oneline --format=%s -- . ":(exclude,icase)SUB" >actual + cat <<EOF >expect && +sub2/file +file +EOF + test_cmp expect actual +' + +test_expect_success 't_e_i() exclude sub2 from sub' ' + ( + cd sub && + git log --oneline --format=%s -- :/ ":/!sub2" >actual + cat <<EOF >expect && +sub/sub/sub/file +sub/file2 +sub/sub/file +sub/file +file +EOF + test_cmp expect actual + ) +' + +test_expect_success 't_e_i() exclude sub/*file' ' + git log --oneline --format=%s -- . ":(exclude)sub/*file" >actual + cat <<EOF >expect && +sub2/file +sub/file2 +file +EOF + test_cmp expect actual +' + +test_expect_success 't_e_i() exclude :(glob)sub/*/file' ' + git log --oneline --format=%s -- . ":(exclude,glob)sub/*/file" >actual + cat <<EOF >expect && +sub2/file +sub/sub/sub/file +sub/file2 +sub/file +file +EOF + test_cmp expect actual +' + +test_expect_success 'm_p_d() exclude sub' ' + git ls-files -- . ":(exclude)sub" >actual + cat <<EOF >expect && +file +sub2/file +EOF + test_cmp expect actual +' + +test_expect_success 'm_p_d() exclude sub/sub/file' ' + git ls-files -- . ":(exclude)sub/sub/file" >actual + cat <<EOF >expect && +file +sub/file +sub/file2 +sub/sub/sub/file +sub2/file +EOF + test_cmp expect actual +' + +test_expect_success 'm_p_d() exclude sub using mnemonic' ' + git ls-files -- . ":!sub" >actual + cat <<EOF >expect && +file +sub2/file +EOF + test_cmp expect actual +' + +test_expect_success 'm_p_d() exclude :(icase)SUB' ' + git ls-files -- . ":(exclude,icase)SUB" >actual + cat <<EOF >expect && +file +sub2/file +EOF + test_cmp expect actual +' + +test_expect_success 'm_p_d() exclude sub2 from sub' ' + ( + cd sub && + git ls-files -- :/ ":/!sub2" >actual + cat <<EOF >expect && +../file +file +file2 +sub/file +sub/sub/file +EOF + test_cmp expect actual + ) +' + +test_expect_success 'm_p_d() exclude sub/*file' ' + git ls-files -- . ":(exclude)sub/*file" >actual + cat <<EOF >expect && +file +sub/file2 +sub2/file +EOF + test_cmp expect actual +' + +test_expect_success 'm_p_d() exclude :(glob)sub/*/file' ' + git ls-files -- . ":(exclude,glob)sub/*/file" >actual + cat <<EOF >expect && +file +sub/file +sub/file2 +sub/sub/sub/file +sub2/file +EOF + test_cmp expect actual +' + +test_done diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh index 752f5cb7d0..bda354c1c4 100755 --- a/t/t6300-for-each-ref.sh +++ b/t/t6300-for-each-ref.sh @@ -18,16 +18,13 @@ setdate_and_increment () { export GIT_COMMITTER_DATE GIT_AUTHOR_DATE } -test_expect_success 'Create sample commit with known timestamp' ' +test_expect_success setup ' setdate_and_increment && echo "Using $datestamp" > one && git add one && git commit -m "Initial" && setdate_and_increment && - git tag -a -m "Tagging at $datestamp" testtag -' - -test_expect_success 'Create upstream config' ' + git tag -a -m "Tagging at $datestamp" testtag && git update-ref refs/remotes/origin/master master && git remote add origin nowhere && git config branch.master.remote origin && @@ -52,12 +49,14 @@ test_atom head refname refs/heads/master test_atom head upstream refs/remotes/origin/master test_atom head objecttype commit test_atom head objectsize 171 -test_atom head objectname 67a36f10722846e891fbada1ba48ed035de75581 -test_atom head tree 0e51c00fcb93dffc755546f27593d511e1bdb46f +test_atom head objectname $(git rev-parse refs/heads/master) +test_atom head tree $(git rev-parse refs/heads/master^{tree}) test_atom head parent '' test_atom head numparent 0 test_atom head object '' test_atom head type '' +test_atom head '*objectname' '' +test_atom head '*objecttype' '' test_atom head author 'A U Thor <author@example.com> 1151939924 +0200' test_atom head authorname 'A U Thor' test_atom head authoremail '<author@example.com>' @@ -80,17 +79,20 @@ test_atom head contents:body '' test_atom head contents:signature '' test_atom head contents 'Initial ' +test_atom head HEAD '*' test_atom tag refname refs/tags/testtag test_atom tag upstream '' test_atom tag objecttype tag test_atom tag objectsize 154 -test_atom tag objectname 98b46b1d36e5b07909de1b3886224e3e81e87322 +test_atom tag objectname $(git rev-parse refs/tags/testtag) test_atom tag tree '' test_atom tag parent '' test_atom tag numparent '' -test_atom tag object '67a36f10722846e891fbada1ba48ed035de75581' +test_atom tag object $(git rev-parse refs/tags/testtag^0) test_atom tag type 'commit' +test_atom tag '*objectname' '67a36f10722846e891fbada1ba48ed035de75581' +test_atom tag '*objecttype' 'commit' test_atom tag author '' test_atom tag authorname '' test_atom tag authoremail '' @@ -113,6 +115,7 @@ test_atom tag contents:body '' test_atom tag contents:signature '' test_atom tag contents 'Tagging at 1151939927 ' +test_atom tag HEAD ' ' test_expect_success 'Check invalid atoms names are errors' ' test_must_fail git for-each-ref --format="%(INVALID)" refs/heads @@ -304,8 +307,35 @@ test_expect_success 'Check short upstream format' ' test_cmp expected actual ' +test_expect_success 'setup for upstream:track[short]' ' + test_commit two +' + +cat >expected <<EOF +[ahead 1] +EOF + +test_expect_success 'Check upstream:track format' ' + git for-each-ref --format="%(upstream:track)" refs/heads >actual && + test_cmp expected actual +' + +cat >expected <<EOF +> +EOF + +test_expect_success 'Check upstream:trackshort format' ' + git for-each-ref --format="%(upstream:trackshort)" refs/heads >actual && + test_cmp expected actual +' + +test_expect_success 'Check that :track[short] cannot be used with other atoms' ' + test_must_fail git for-each-ref --format="%(refname:track)" 2>/dev/null && + test_must_fail git for-each-ref --format="%(refname:trackshort)" 2>/dev/null +' + cat >expected <<EOF -67a36f1 +$(git rev-parse --short HEAD) EOF test_expect_success 'Check short objectname format' ' @@ -317,6 +347,23 @@ test_expect_success 'Check for invalid refname format' ' test_must_fail git for-each-ref --format="%(refname:INVALID)" ' +get_color () +{ + git config --get-color no.such.slot "$1" +} + +cat >expected <<EOF +$(git rev-parse --short refs/heads/master) $(get_color green)master$(get_color reset) +$(git rev-parse --short refs/remotes/origin/master) $(get_color green)origin/master$(get_color reset) +$(git rev-parse --short refs/tags/testtag) $(get_color green)testtag$(get_color reset) +$(git rev-parse --short refs/tags/two) $(get_color green)two$(get_color reset) +EOF + +test_expect_success 'Check %(color:...) ' ' + git for-each-ref --format="%(objectname:short) %(color:green)%(refname:short)" >actual && + test_cmp expected actual +' + cat >expected <<\EOF heads/master tags/master @@ -456,9 +503,9 @@ test_atom refs/tags/signed-long contents "subject line body contents $sig" -cat >expected <<\EOF -408fe76d02a785a006c2e9c669b7be5589ede96d <committer@example.com> refs/tags/master -90b5ebede4899eda64893bc2a4c8f1d6fb6dfc40 <committer@example.com> refs/tags/bogo +cat >expected <<EOF +$(git rev-parse refs/tags/master) <committer@example.com> refs/tags/master +$(git rev-parse refs/tags/bogo) <committer@example.com> refs/tags/bogo EOF test_expect_success 'Verify sort with multiple keys' ' diff --git a/t/t6500-gc.sh b/t/t6500-gc.sh index b1a63655f9..63194d819e 100755 --- a/t/t6500-gc.sh +++ b/t/t6500-gc.sh @@ -9,6 +9,11 @@ test_expect_success 'gc empty repository' ' git gc ' +test_expect_success 'gc does not leave behind pid file' ' + git gc && + test_path_is_missing .git/gc.pid +' + test_expect_success 'gc --gobbledegook' ' test_expect_code 129 git gc --nonsense 2>err && test_i18ngrep "[Uu]sage: git gc" err diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index 101816e718..215d43d6a6 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -70,6 +70,35 @@ test_expect_success \ rm -f idontexist untracked1 untracked2 \ path0/idontexist path0/untracked1 path0/untracked2 \ .git/index.lock +rmdir path1 + +test_expect_success \ + 'moving to absent target with trailing slash' \ + 'test_must_fail git mv path0/COPYING no-such-dir/ && + test_must_fail git mv path0/COPYING no-such-dir// && + git mv path0/ no-such-dir/ && + test_path_is_dir no-such-dir' + +test_expect_success \ + 'clean up' \ + 'git reset --hard' + +test_expect_success \ + 'moving to existing untracked target with trailing slash' \ + 'mkdir path1 && + git mv path0/ path1/ && + test_path_is_dir path1/path0/' + +test_expect_success \ + 'moving to existing tracked target with trailing slash' \ + 'mkdir path2 && + >path2/file && git add path2/file && + git mv path1/path0/ path2/ && + test_path_is_dir path2/path0/' + +test_expect_success \ + 'clean up' \ + 'git reset --hard' test_expect_success \ 'adding another file' \ @@ -259,4 +288,190 @@ test_expect_success SYMLINKS 'check moved symlink' ' rm -f moved symlink +test_expect_success 'setup submodule' ' + git commit -m initial && + git reset --hard && + git submodule add ./. sub && + echo content >file && + git add file && + git commit -m "added sub and file" && + git branch submodule +' + +test_expect_success 'git mv cannot move a submodule in a file' ' + test_must_fail git mv sub file +' + +test_expect_success 'git mv moves a submodule with a .git directory and no .gitmodules' ' + entry="$(git ls-files --stage sub | cut -f 1)" && + git rm .gitmodules && + ( + cd sub && + rm -f .git && + cp -a ../.git/modules/sub .git && + GIT_WORK_TREE=. git config --unset core.worktree + ) && + mkdir mod && + git mv sub mod/sub && + ! test -e sub && + [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] && + ( + cd mod/sub && + git status + ) && + git update-index --refresh && + git diff-files --quiet +' + +test_expect_success 'git mv moves a submodule with a .git directory and .gitmodules' ' + rm -rf mod && + git reset --hard && + git submodule update && + entry="$(git ls-files --stage sub | cut -f 1)" && + ( + cd sub && + rm -f .git && + cp -a ../.git/modules/sub .git && + GIT_WORK_TREE=. git config --unset core.worktree + ) && + mkdir mod && + git mv sub mod/sub && + ! test -e sub && + [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] && + ( + cd mod/sub && + git status + ) && + echo mod/sub >expected && + git config -f .gitmodules submodule.sub.path >actual && + test_cmp expected actual && + git update-index --refresh && + git diff-files --quiet +' + +test_expect_success 'git mv moves a submodule with gitfile' ' + rm -rf mod/sub && + git reset --hard && + git submodule update && + entry="$(git ls-files --stage sub | cut -f 1)" && + ( + cd mod && + git mv ../sub/ . + ) && + ! test -e sub && + [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] && + ( + cd mod/sub && + git status + ) && + echo mod/sub >expected && + git config -f .gitmodules submodule.sub.path >actual && + test_cmp expected actual && + git update-index --refresh && + git diff-files --quiet +' + +test_expect_success 'mv does not complain when no .gitmodules file is found' ' + rm -rf mod/sub && + git reset --hard && + git submodule update && + git rm .gitmodules && + entry="$(git ls-files --stage sub | cut -f 1)" && + git mv sub mod/sub 2>actual.err && + ! test -s actual.err && + ! test -e sub && + [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] && + ( + cd mod/sub && + git status + ) && + git update-index --refresh && + git diff-files --quiet +' + +test_expect_success 'mv will error out on a modified .gitmodules file unless staged' ' + rm -rf mod/sub && + git reset --hard && + git submodule update && + git config -f .gitmodules foo.bar true && + entry="$(git ls-files --stage sub | cut -f 1)" && + test_must_fail git mv sub mod/sub 2>actual.err && + test -s actual.err && + test -e sub && + git diff-files --quiet -- sub && + git add .gitmodules && + git mv sub mod/sub 2>actual.err && + ! test -s actual.err && + ! test -e sub && + [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] && + ( + cd mod/sub && + git status + ) && + git update-index --refresh && + git diff-files --quiet +' + +test_expect_success 'mv issues a warning when section is not found in .gitmodules' ' + rm -rf mod/sub && + 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 && + git mv sub mod/sub 2>actual.err && + test_i18ncmp expect.err actual.err && + ! test -e sub && + [ "$entry" = "$(git ls-files --stage mod/sub | cut -f 1)" ] && + ( + cd mod/sub && + git status + ) && + git update-index --refresh && + git diff-files --quiet +' + +test_expect_success 'mv --dry-run does not touch the submodule or .gitmodules' ' + rm -rf mod/sub && + git reset --hard && + git submodule update && + git mv -n sub mod/sub 2>actual.err && + test -f sub/.git && + git diff-index --exit-code HEAD && + git update-index --refresh && + git diff-files --quiet -- sub .gitmodules +' + +test_expect_success 'checking out a commit before submodule moved needs manual updates' ' + git mv sub sub2 && + git commit -m "moved sub to sub2" && + git checkout -q HEAD^ 2>actual && + echo "warning: unable to rmdir sub2: Directory not empty" >expected && + test_i18ncmp expected actual && + git status -s sub2 >actual && + echo "?? sub2/" >expected && + test_cmp expected actual && + ! test -f sub/.git && + test -f sub2/.git && + git submodule update && + test -f sub/.git && + rm -rf sub2 && + git diff-index --exit-code HEAD && + git update-index --refresh && + git diff-files --quiet -- sub .gitmodules && + git status -s sub2 >actual && + ! test -s actual +' + +test_expect_success 'mv -k does not accidentally destroy submodules' ' + git checkout submodule && + mkdir dummy dest && + git mv -k dummy sub dest && + git status --porcelain >actual && + grep "^R sub -> dest/sub" actual && + git reset --hard && + git checkout . +' + test_done diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh index c8d6e9f88c..143a8ea605 100755 --- a/t/t7004-tag.sh +++ b/t/t7004-tag.sh @@ -1380,4 +1380,47 @@ test_expect_success 'multiple --points-at are OR-ed together' ' test_cmp expect actual ' +test_expect_success 'lexical sort' ' + git tag foo1.3 && + git tag foo1.6 && + git tag foo1.10 && + git tag -l --sort=refname "foo*" >actual && + cat >expect <<EOF && +foo1.10 +foo1.3 +foo1.6 +EOF + test_cmp expect actual +' + +test_expect_success 'version sort' ' + git tag -l --sort=version:refname "foo*" >actual && + cat >expect <<EOF && +foo1.3 +foo1.6 +foo1.10 +EOF + test_cmp expect actual +' + +test_expect_success 'reverse version sort' ' + git tag -l --sort=-version:refname "foo*" >actual && + cat >expect <<EOF && +foo1.10 +foo1.6 +foo1.3 +EOF + test_cmp expect actual +' + +test_expect_success 'reverse lexical sort' ' + git tag -l --sort=-refname "foo*" >actual && + cat >expect <<EOF && +foo1.6 +foo1.3 +foo1.10 +EOF + test_cmp expect actual +' + test_done diff --git a/t/t7006-pager.sh b/t/t7006-pager.sh index ff2590849d..da958a8b56 100755 --- a/t/t7006-pager.sh +++ b/t/t7006-pager.sh @@ -37,6 +37,18 @@ test_expect_failure TTY 'pager runs from subdir' ' test_cmp expected actual ' +test_expect_success TTY 'LESS and LV envvars are set for pagination' ' + ( + sane_unset LESS LV && + PAGER="env >pager-env.out; wc" && + export PAGER && + + test_terminal git log + ) && + grep ^LESS= pager-env.out && + grep ^LV= pager-env.out +' + test_expect_success TTY 'some commands do not use a pager' ' rm -f paginated.out && test_terminal git rev-list HEAD && @@ -134,11 +146,7 @@ test_expect_success 'no color when stdout is a regular file' ' test_expect_success TTY 'color when writing to a pager' ' rm -f paginated.out && test_config color.ui auto && - ( - TERM=vt100 && - export TERM && - test_terminal git log - ) && + test_terminal env TERM=vt100 git log && colorful paginated.out ' @@ -146,11 +154,7 @@ test_expect_success TTY 'colors are suppressed by color.pager' ' rm -f paginated.out && test_config color.ui auto && test_config color.pager false && - ( - TERM=vt100 && - export TERM && - test_terminal git log - ) && + test_terminal env TERM=vt100 git log && ! colorful paginated.out ' @@ -169,11 +173,7 @@ test_expect_success 'color when writing to a file intended for a pager' ' test_expect_success TTY 'colors are sent to pager for external commands' ' test_config alias.externallog "!git log" && test_config color.ui auto && - ( - TERM=vt100 && - export TERM && - test_terminal git -p externallog - ) && + test_terminal env TERM=vt100 git -p externallog && colorful paginated.out ' diff --git a/t/t7008-grep-binary.sh b/t/t7008-grep-binary.sh index 26f831984d..b146406e9c 100755 --- a/t/t7008-grep-binary.sh +++ b/t/t7008-grep-binary.sh @@ -145,4 +145,35 @@ test_expect_success 'grep respects not-binary diff attribute' ' test_cmp expect actual ' +cat >nul_to_q_textconv <<'EOF' +#!/bin/sh +"$PERL_PATH" -pe 'y/\000/Q/' < "$1" +EOF +chmod +x nul_to_q_textconv + +test_expect_success 'setup textconv filters' ' + echo a diff=foo >.gitattributes && + git config diff.foo.textconv "\"$(pwd)\""/nul_to_q_textconv +' + +test_expect_success 'grep does not honor textconv' ' + test_must_fail git grep Qfile +' + +test_expect_success 'grep --textconv honors textconv' ' + echo "a:binaryQfile" >expect && + git grep --textconv Qfile >actual && + test_cmp expect actual +' + +test_expect_success 'grep --no-textconv does not honor textconv' ' + test_must_fail git grep --no-textconv Qfile +' + +test_expect_success 'grep --textconv blob honors textconv' ' + echo "HEAD:a:binaryQfile" >expect && + git grep --textconv Qfile HEAD:a >actual && + test_cmp expect actual +' + test_done diff --git a/t/t7009-filter-branch-null-sha1.sh b/t/t7009-filter-branch-null-sha1.sh new file mode 100755 index 0000000000..a997f7ac3a --- /dev/null +++ b/t/t7009-filter-branch-null-sha1.sh @@ -0,0 +1,49 @@ +#!/bin/sh + +test_description='filter-branch removal of trees with null sha1' +. ./test-lib.sh + +test_expect_success 'setup: base commits' ' + test_commit one && + test_commit two && + test_commit three +' + +test_expect_success 'setup: a commit with a bogus null sha1 in the tree' ' + { + git ls-tree HEAD && + printf "160000 commit $_z40\\tbroken\\n" + } >broken-tree + echo "add broken entry" >msg && + + tree=$(git mktree <broken-tree) && + test_tick && + commit=$(git commit-tree $tree -p HEAD <msg) && + git update-ref HEAD "$commit" +' + +# we have to make one more commit on top removing the broken +# entry, since otherwise our index does not match HEAD (and filter-branch will +# complain). We could make the index match HEAD, but doing so would involve +# writing a null sha1 into the index. +test_expect_success 'setup: bring HEAD and index in sync' ' + test_tick && + git commit -a -m "back to normal" +' + +test_expect_success 'filter commands are still checked' ' + test_must_fail git filter-branch \ + --force --prune-empty \ + --index-filter "git rm --cached --ignore-unmatch three.t" +' + +test_expect_success 'removing the broken entry works' ' + echo three >expect && + git filter-branch \ + --force --prune-empty \ + --index-filter "git rm --cached --ignore-unmatch broken" && + git log -1 --format=%s >actual && + test_cmp expect actual +' + +test_done diff --git a/t/t7060-wtstatus.sh b/t/t7060-wtstatus.sh index 5ecafac99b..741ec08576 100755 --- a/t/t7060-wtstatus.sh +++ b/t/t7060-wtstatus.sh @@ -4,10 +4,6 @@ test_description='basic work tree status reporting' . ./test-lib.sh -test_expect_success 'use status.displayCommentPrefix by default ' ' - git config --global status.displayCommentPrefix true -' - test_expect_success setup ' git config --global advice.statusuoption false && test_commit A && @@ -33,20 +29,19 @@ test_expect_success 'Report new path with conflict' ' test_cmp expect actual ' -cat >expect <<EOF -# On branch side -# You have unmerged paths. -# (fix conflicts and run "git commit") -# -# Unmerged paths: -# (use "git add/rm <file>..." as appropriate to mark resolution) -# -# deleted by us: foo -# +test_expect_success 'M/D conflict does not segfault' ' + cat >expect <<EOF && +On branch side +You have unmerged paths. + (fix conflicts and run "git commit") + +Unmerged paths: + (use "git add/rm <file>..." as appropriate to mark resolution) + + deleted by us: foo + no changes added to commit (use "git add" and/or "git commit -a") EOF - -test_expect_success 'M/D conflict does not segfault' ' mkdir mdconflict && ( cd mdconflict && @@ -139,19 +134,19 @@ test_expect_success 'status when conflicts with add and rm advice (deleted by th test_commit on_second main.txt on_second && test_commit master conflict.txt master && test_must_fail git merge second_branch && - cat >expected <<-\EOF && - # On branch master - # You have unmerged paths. - # (fix conflicts and run "git commit") - # - # Unmerged paths: - # (use "git add/rm <file>..." as appropriate to mark resolution) - # - # both added: conflict.txt - # deleted by them: main.txt - # - no changes added to commit (use "git add" and/or "git commit -a") - EOF + cat >expected <<\EOF && +On branch master +You have unmerged paths. + (fix conflicts and run "git commit") + +Unmerged paths: + (use "git add/rm <file>..." as appropriate to mark resolution) + + both added: conflict.txt + deleted by them: main.txt + +no changes added to commit (use "git add" and/or "git commit -a") +EOF git status --untracked-files=no >actual && test_i18ncmp expected actual ' @@ -172,20 +167,20 @@ test_expect_success 'prepare for conflicts' ' test_expect_success 'status when conflicts with add and rm advice (both deleted)' ' test_must_fail git merge conflict && - cat >expected <<-\EOF && - # On branch conflict_second - # You have unmerged paths. - # (fix conflicts and run "git commit") - # - # Unmerged paths: - # (use "git add/rm <file>..." as appropriate to mark resolution) - # - # both deleted: main.txt - # added by them: sub_master.txt - # added by us: sub_second.txt - # - no changes added to commit (use "git add" and/or "git commit -a") - EOF + cat >expected <<\EOF && +On branch conflict_second +You have unmerged paths. + (fix conflicts and run "git commit") + +Unmerged paths: + (use "git add/rm <file>..." as appropriate to mark resolution) + + both deleted: main.txt + added by them: sub_master.txt + added by us: sub_second.txt + +no changes added to commit (use "git add" and/or "git commit -a") +EOF git status --untracked-files=no >actual && test_i18ncmp expected actual ' @@ -196,22 +191,22 @@ test_expect_success 'status when conflicts with only rm advice (both deleted)' ' test_must_fail git merge conflict && git add sub_master.txt && git add sub_second.txt && - cat >expected <<-\EOF && - # On branch conflict_second - # You have unmerged paths. - # (fix conflicts and run "git commit") - # - # Changes to be committed: - # - # new file: sub_master.txt - # - # Unmerged paths: - # (use "git rm <file>..." to mark resolution) - # - # both deleted: main.txt - # - # Untracked files not listed (use -u option to show untracked files) - EOF + cat >expected <<\EOF && +On branch conflict_second +You have unmerged paths. + (fix conflicts and run "git commit") + +Changes to be committed: + + new file: sub_master.txt + +Unmerged paths: + (use "git rm <file>..." to mark resolution) + + both deleted: main.txt + +Untracked files not listed (use -u option to show untracked files) +EOF git status --untracked-files=no >actual && test_i18ncmp expected actual && git reset --hard && diff --git a/t/t7101-reset.sh b/t/t7101-reset-empty-subdirs.sh index 96e163f084..96e163f084 100755 --- a/t/t7101-reset.sh +++ b/t/t7101-reset-empty-subdirs.sh diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh index 8d4b50d1b5..450529404c 100755 --- a/t/t7102-reset.sh +++ b/t/t7102-reset.sh @@ -535,4 +535,30 @@ test_expect_success 'reset with paths accepts tree' ' git diff HEAD --exit-code ' +test_expect_success 'reset -N keeps removed files as intent-to-add' ' + echo new-file >new-file && + git add new-file && + git reset -N HEAD && + + tree=$(git write-tree) && + git ls-tree $tree new-file >actual && + >expect && + test_cmp expect actual && + + git diff --name-only >actual && + echo new-file >expect && + test_cmp expect actual +' + +test_expect_success 'reset --mixed sets up work tree' ' + git init mixed_worktree && + ( + cd mixed_worktree && + test_commit dummy + ) && + : >expect && + git --git-dir=mixed_worktree/.git --work-tree=mixed_worktree reset >actual && + test_cmp expect actual +' + test_done diff --git a/t/t7104-reset.sh b/t/t7104-reset-hard.sh index f136ee7bb5..f136ee7bb5 100755 --- a/t/t7104-reset.sh +++ b/t/t7104-reset-hard.sh diff --git a/t/t7105-reset-patch.sh b/t/t7105-reset-patch.sh index 95fab20361..98b7d7b969 100755 --- a/t/t7105-reset-patch.sh +++ b/t/t7105-reset-patch.sh @@ -25,15 +25,17 @@ test_expect_success PERL 'saying "n" does nothing' ' ' test_expect_success PERL 'git reset -p' ' - (echo n; echo y) | git reset -p && + (echo n; echo y) | git reset -p >output && verify_state dir/foo work head && - verify_saved_state bar + verify_saved_state bar && + test_i18ngrep "Unstage" output ' test_expect_success PERL 'git reset -p HEAD^' ' - (echo n; echo y) | git reset -p HEAD^ && + (echo n; echo y) | git reset -p HEAD^ >output && verify_state dir/foo work parent && - verify_saved_state bar + verify_saved_state bar && + test_i18ngrep "Apply" output ' # The idea in the rest is that bar sorts first, so we always say 'y' diff --git a/t/t7106-reset-unborn-branch.sh b/t/t7106-reset-unborn-branch.sh index 8062cf502b..0f95f00477 100755 --- a/t/t7106-reset-unborn-branch.sh +++ b/t/t7106-reset-unborn-branch.sh @@ -11,7 +11,10 @@ test_expect_success 'setup' ' test_expect_success 'reset' ' git add a b && git reset && - test "$(git ls-files)" = "" + + >expect && + git ls-files >actual && + test_cmp expect actual ' test_expect_success 'reset HEAD' ' @@ -24,28 +27,43 @@ test_expect_success 'reset $file' ' rm .git/index && git add a b && git reset a && - test "$(git ls-files)" = "b" + + echo b >expect && + git ls-files >actual && + test_cmp expect actual ' -test_expect_success 'reset -p' ' +test_expect_success PERL 'reset -p' ' rm .git/index && git add a && - echo y | git reset -p && - test "$(git ls-files)" = "" + echo y >yes && + git reset -p <yes >output && + + >expect && + git ls-files >actual && + test_cmp expect actual && + test_i18ngrep "Unstage" output ' test_expect_success 'reset --soft is a no-op' ' rm .git/index && git add a && - git reset --soft - test "$(git ls-files)" = "a" + git reset --soft && + + echo a >expect && + git ls-files >actual && + test_cmp expect actual ' test_expect_success 'reset --hard' ' rm .git/index && git add a && + test_when_finished "echo a >a" && git reset --hard && - test "$(git ls-files)" = "" && + + >expect && + git ls-files >actual && + test_cmp expect actual && test_path_is_missing a ' diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh index 710be90489..74de814aec 100755 --- a/t/t7300-clean.sh +++ b/t/t7300-clean.sh @@ -511,4 +511,20 @@ test_expect_success SANITY 'git clean -d with an unreadable empty directory' ' ! test -d foo ' +test_expect_success 'git clean -d respects pathspecs (dir is prefix of pathspec)' ' + mkdir -p foo && + mkdir -p foobar && + git clean -df foobar && + test_path_is_dir foo && + test_path_is_missing foobar +' + +test_expect_success 'git clean -d respects pathspecs (pathspec is prefix of dir)' ' + mkdir -p foo && + mkdir -p foobar && + git clean -df foo && + test_path_is_missing foo && + test_path_is_dir foobar +' + test_done diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index 5ee97b003a..c28e8d8ada 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -18,6 +18,16 @@ test_expect_success 'setup - initial commit' ' git branch initial ' +test_expect_success 'configuration parsing' ' + test_when_finished "rm -f .gitmodules" && + cat >.gitmodules <<-\EOF && + [submodule "s"] + path + ignore + EOF + test_must_fail git status +' + test_expect_success 'setup - repository in init subdirectory' ' mkdir init && ( @@ -471,7 +481,7 @@ test_expect_success 'do not add files from a submodule' ' ' -test_expect_success 'gracefully add submodule with a trailing slash' ' +test_expect_success 'gracefully add/reset submodule with a trailing slash' ' git reset --hard && git commit -m "commit subproject" init && @@ -485,7 +495,9 @@ test_expect_success 'gracefully add submodule with a trailing slash' ' git add init/ && test_must_fail git diff --exit-code --cached init && test $commit = $(git ls-files --stage | - sed -n "s/^160000 \([^ ]*\).*/\1/p") + sed -n "s/^160000 \([^ ]*\).*/\1/p") && + git reset init/ && + git diff --exit-code --cached init ' @@ -773,13 +785,11 @@ test_expect_success 'submodule add --name allows to replace a submodule with ano test_cmp expect .git ) && echo "repo" >expect && - git config -f .gitmodules submodule.repo.path >actual && - test_cmp expect actual && + test_must_fail git config -f .gitmodules submodule.repo.path && git config -f .gitmodules submodule.repo_new.path >actual && test_cmp expect actual&& echo "$submodurl/repo" >expect && - git config -f .gitmodules submodule.repo.url >actual && - test_cmp expect actual && + test_must_fail git config -f .gitmodules submodule.repo.url && echo "$submodurl/bare.git" >expect && git config -f .gitmodules submodule.repo_new.url >actual && test_cmp expect actual && @@ -799,12 +809,8 @@ test_expect_success 'submodule add with an existing name fails unless forced' ' git rm repo && test_must_fail git submodule add -q --name repo_new "$submodurl/repo.git" repo && test ! -d repo && - echo "repo" >expect && - git config -f .gitmodules submodule.repo_new.path >actual && - test_cmp expect actual&& - echo "$submodurl/bare.git" >expect && - git config -f .gitmodules submodule.repo_new.url >actual && - test_cmp expect actual && + test_must_fail git config -f .gitmodules submodule.repo_new.path && + test_must_fail git config -f .gitmodules submodule.repo_new.url && echo "$submodurl/bare.git" >expect && git config submodule.repo_new.url >actual && test_cmp expect actual && @@ -958,7 +964,6 @@ test_expect_success 'submodule with UTF-8 name' ' git add sub && git commit -m "init sub" ) && - test_config core.precomposeunicode true && git submodule add ./"$svname" && git submodule >&2 && test -n "$(git submodule | grep "$svname")" diff --git a/t/t7401-submodule-summary.sh b/t/t7401-submodule-summary.sh index 5a6d6d62eb..366746f0d4 100755 --- a/t/t7401-submodule-summary.sh +++ b/t/t7401-submodule-summary.sh @@ -104,6 +104,24 @@ EOF test_cmp expected actual " +test_expect_success 'no ignore=all setting has any effect' " + git config -f .gitmodules submodule.sm1.path sm1 && + git config -f .gitmodules submodule.sm1.ignore all && + git config submodule.sm1.ignore all && + git config diff.ignoreSubmodules all && + git submodule summary >actual && + cat >expected <<-EOF && +* sm1 $head1...$head2 (1): + > Add foo3 + +EOF + test_cmp expected actual && + git config --unset diff.ignoreSubmodules && + git config --remove-section submodule.sm1 && + git config -f .gitmodules --remove-section submodule.sm1 +" + + commit_file sm1 && head3=$( cd sm1 && diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh index b192f936bc..28ca76384f 100755 --- a/t/t7406-submodule-update.sh +++ b/t/t7406-submodule-update.sh @@ -58,11 +58,14 @@ test_expect_success 'setup a submodule tree' ' git submodule add ../merging merging && test_tick && git commit -m "rebasing" - ) + ) && (cd super && git submodule add ../none none && test_tick && git commit -m "none" + ) && + (cd super && + git tag initial-setup ) ' @@ -323,6 +326,21 @@ test_expect_success 'submodule update - command in .git/config catches failure' ) ' +test_expect_success 'submodule init does not copy command into .git/config' ' + (cd super && + H=$(git ls-files -s submodule | cut -d" " -f2) && + mkdir submodule1 && + git update-index --add --cacheinfo 160000 $H submodule1 && + git config -f .gitmodules submodule.submodule1.path submodule1 && + git config -f .gitmodules submodule.submodule1.url ../submodule && + git config -f .gitmodules submodule.submodule1.update !false && + git submodule init submodule1 && + echo "none" >expect && + git config submodule.submodule1.update >actual && + test_cmp expect actual + ) +' + test_expect_success 'submodule init picks up rebase' ' (cd super && git config -f .gitmodules submodule.rebasing.update rebase && @@ -688,7 +706,7 @@ test_expect_success 'submodule update places git-dir in superprojects git-dir re git clone super_update_r super_update_r2 && (cd super_update_r2 && git submodule update --init --recursive >actual && - test_i18ngrep "Submodule path .submodule/subsubmodule.: checked out" actual && + test_i18ngrep "Submodule path .submodule/subsubmodule.: .git reset --hard -q" actual && (cd submodule/subsubmodule && git log > ../../expected ) && @@ -747,6 +765,50 @@ test_expect_success 'submodule update clone shallow submodule' ' (cd submodule && test 1 = $(git log --oneline | wc -l) ) +) +' + +test_expect_success 'submodule update --recursive drops module name before recursing' ' + (cd super2 && + (cd deeper/submodule/subsubmodule && + git checkout HEAD^ + ) && + git submodule update --recursive deeper/submodule >actual && + test_i18ngrep "Submodule path .deeper/submodule/subsubmodule.: checked out" actual ) ' + +test_expect_success 'submodule update --checkout clones detached HEAD' ' + git clone super super4 && + echo "detached HEAD" >expected && + (cd super4 && + git reset --hard initial-setup && + git submodule init submodule && + git submodule update >> /tmp/log 2>&1 && + (cd submodule && + git symbolic-ref HEAD > ../../actual || + echo "detached HEAD" > ../../actual + ) + ) && + test_cmp actual expected && + rm -rf super4 +' + +test_expect_success 'submodule update --merge clones attached HEAD' ' + git clone super super4 && + echo "refs/heads/master" >expected && + (cd super4 && + git reset --hard initial-setup && + git submodule init submodule && + git config submodule.submodule.update merge && + git submodule update --merge && + (cd submodule && + git symbolic-ref HEAD > ../../actual || + echo "detached HEAD" > ../../actual + ) + ) && + test_cmp actual expected && + rm -rf super4 +' + test_done diff --git a/t/t7407-submodule-foreach.sh b/t/t7407-submodule-foreach.sh index be93f10cf0..7ca10b8606 100755 --- a/t/t7407-submodule-foreach.sh +++ b/t/t7407-submodule-foreach.sh @@ -254,10 +254,6 @@ test_expect_success 'ensure "status --cached --recursive" preserves the --cached ) && git submodule status --cached --recursive -- nested1 > ../actual ) && - if test_have_prereq MINGW - then - dos2unix actual - fi && test_cmp expect actual ' @@ -329,4 +325,13 @@ test_expect_success 'command passed to foreach --recursive retains notion of std test_cmp expected actual ' +test_expect_success 'multi-argument command passed to foreach is not shell-evaluated twice' ' + ( + cd super && + git submodule foreach "echo \\\"quoted\\\"" > ../expected && + git submodule foreach echo \"quoted\" > ../actual + ) && + test_cmp expected actual +' + test_done diff --git a/t/t7501-commit.sh b/t/t7501-commit.sh index 99ce36f5ef..d58b097ff3 100755 --- a/t/t7501-commit.sh +++ b/t/t7501-commit.sh @@ -53,18 +53,55 @@ test_expect_success PERL 'can use paths with --interactive' ' ' test_expect_success 'using invalid commit with -C' ' - test_must_fail git commit -C bogus + test_must_fail git commit --allow-empty -C bogus ' test_expect_success 'nothing to commit' ' + git reset --hard && test_must_fail git commit -m initial ' +test_expect_success '--dry-run fails with nothing to commit' ' + test_must_fail git commit -m initial --dry-run +' + +test_expect_success '--short fails with nothing to commit' ' + test_must_fail git commit -m initial --short +' + +test_expect_success '--porcelain fails with nothing to commit' ' + test_must_fail git commit -m initial --porcelain +' + +test_expect_success '--long fails with nothing to commit' ' + test_must_fail git commit -m initial --long +' + test_expect_success 'setup: non-initial commit' ' echo bongo bongo bongo >file && git commit -m next -a ' +test_expect_success '--dry-run with stuff to commit returns ok' ' + echo bongo bongo bongo >>file && + git commit -m next -a --dry-run +' + +test_expect_failure '--short with stuff to commit returns ok' ' + echo bongo bongo bongo >>file && + git commit -m next -a --short +' + +test_expect_failure '--porcelain with stuff to commit returns ok' ' + echo bongo bongo bongo >>file && + git commit -m next -a --porcelain +' + +test_expect_success '--long with stuff to commit returns ok' ' + echo bongo bongo bongo >>file && + git commit -m next -a --long +' + test_expect_success 'commit message from non-existing file' ' echo more bongo: bongo bongo bongo bongo >file && test_must_fail git commit -F gah -a diff --git a/t/t7502-commit.sh b/t/t7502-commit.sh index 6313da2cdd..9a3f3a1b41 100755 --- a/t/t7502-commit.sh +++ b/t/t7502-commit.sh @@ -223,6 +223,22 @@ test_expect_success 'cleanup commit messages (whitespace option,-F)' ' ' +test_expect_success 'cleanup commit messages (scissors option,-F,-e)' ' + + echo >>negative && + cat >text <<EOF && + +# to be kept +# ------------------------ >8 ------------------------ +to be removed +EOF + echo "# to be kept" >expect && + git commit --cleanup=scissors -e -F text -a && + git cat-file -p HEAD |sed -e "1,/^\$/d">actual && + test_cmp expect actual + +' + test_expect_success 'cleanup commit messages (strip option,-F)' ' echo >>negative && diff --git a/t/t7505-prepare-commit-msg-hook.sh b/t/t7505-prepare-commit-msg-hook.sh index 357375151d..03dce09cfe 100755 --- a/t/t7505-prepare-commit-msg-hook.sh +++ b/t/t7505-prepare-commit-msg-hook.sh @@ -134,14 +134,26 @@ test_expect_success 'with hook (-c)' ' test_expect_success 'with hook (merge)' ' - head=`git rev-parse HEAD` && - git checkout -b other HEAD@{1} && - echo "more" >> file && + test_when_finished "git checkout -f master" && + git checkout -B other HEAD@{1} && + echo "more" >>file && + git add file && + git commit -m other && + git checkout - && + git merge --no-ff other && + test "`git log -1 --pretty=format:%s`" = "merge (no editor)" +' + +test_expect_success 'with hook and editor (merge)' ' + + test_when_finished "git checkout -f master" && + git checkout -B other HEAD@{1} && + echo "more" >>file && git add file && git commit -m other && git checkout - && - git merge other && - test "`git log -1 --pretty=format:%s`" = merge + env GIT_EDITOR="\"\$FAKE_EDITOR\"" git merge --no-ff -e other && + test "`git log -1 --pretty=format:%s`" = "merge" ' cat > "$HOOK" <<'EOF' @@ -151,34 +163,37 @@ EOF test_expect_success 'with failing hook' ' + test_when_finished "git checkout -f master" && head=`git rev-parse HEAD` && echo "more" >> file && git add file && - ! GIT_EDITOR="\"\$FAKE_EDITOR\"" git commit -c $head + test_must_fail env GIT_EDITOR="\"\$FAKE_EDITOR\"" git commit -c $head ' test_expect_success 'with failing hook (--no-verify)' ' + test_when_finished "git checkout -f master" && head=`git rev-parse HEAD` && echo "more" >> file && git add file && - ! GIT_EDITOR="\"\$FAKE_EDITOR\"" git commit --no-verify -c $head + test_must_fail env GIT_EDITOR="\"\$FAKE_EDITOR\"" git commit --no-verify -c $head ' test_expect_success 'with failing hook (merge)' ' + test_when_finished "git checkout -f master" && git checkout -B other HEAD@{1} && echo "more" >> file && git add file && rm -f "$HOOK" && git commit -m other && - write_script "$HOOK" <<-EOF + write_script "$HOOK" <<-EOF && exit 1 EOF git checkout - && - test_must_fail git merge other + test_must_fail git merge --no-ff other ' diff --git a/t/t7507-commit-verbose.sh b/t/t7507-commit-verbose.sh index da5bd3b5a5..2ddf28c984 100755 --- a/t/t7507-commit-verbose.sh +++ b/t/t7507-commit-verbose.sh @@ -65,9 +65,35 @@ test_expect_success 'diff in message is retained without -v' ' check_message diff ' -test_expect_failure 'diff in message is retained with -v' ' +test_expect_success 'diff in message is retained with -v' ' git commit --amend -F diff -v && check_message diff ' +test_expect_success 'submodule log is stripped out too with -v' ' + git config diff.submodule log && + git submodule add ./. sub && + git commit -m "sub added" && + ( + cd sub && + echo "more" >>file && + git commit -a -m "submodule commit" + ) && + ( + GIT_EDITOR=cat && + export GIT_EDITOR && + test_must_fail git commit -a -v 2>err + ) && + test_i18ngrep "Aborting commit due to empty commit message." err +' + +test_expect_success 'verbose diff is stripped out with set core.commentChar' ' + ( + GIT_EDITOR=cat && + export GIT_EDITOR && + test_must_fail git -c core.commentchar=";" commit -a -v 2>err + ) && + test_i18ngrep "Aborting commit due to empty commit message." err +' + test_done diff --git a/t/t7508-status.sh b/t/t7508-status.sh index 8d28280235..c987b5ed65 100755 --- a/t/t7508-status.sh +++ b/t/t7508-status.sh @@ -7,10 +7,6 @@ test_description='git status' . ./test-lib.sh -test_expect_success 'use status.displayCommentPrefix by default ' ' - git config --global status.displayCommentPrefix true -' - test_expect_success 'status -h in broken repository' ' git config --global advice.statusuoption false && mkdir broken && @@ -65,7 +61,8 @@ test_expect_success 'status (1)' ' ' strip_comments () { - sed "s/^\# //; s/^\#$//; s/^#\t/\t/" <"$1" >"$1".tmp && + tab=' ' + sed "s/^\# //; s/^\#$//; s/^#$tab/$tab/" <"$1" >"$1".tmp && rm "$1" && mv "$1".tmp "$1" } @@ -88,6 +85,7 @@ test_expect_success 'status --column' ' # # dir1/untracked dir2/untracked output # dir2/modified expect untracked +# EOF COLUMNS=50 git -c status.displayCommentPrefix=true status --column="column dense" >output && test_i18ncmp expect output @@ -121,6 +119,7 @@ cat >expect <<\EOF # expect # output # untracked +# EOF test_expect_success 'status with status.displayCommentPrefix=true' ' @@ -157,20 +156,21 @@ test_expect_success 'commit ignores status.displayCommentPrefix=false in COMMIT_ ' cat >expect <<\EOF -# On branch master -# Changes to be committed: -# new file: dir2/added -# -# Changes not staged for commit: -# modified: dir1/modified -# -# Untracked files: -# dir1/untracked -# dir2/modified -# dir2/untracked -# expect -# output -# untracked +On branch master +Changes to be committed: + new file: dir2/added + +Changes not staged for commit: + modified: dir1/modified + +Untracked files: + dir1/untracked + dir2/modified + dir2/untracked + expect + output + untracked + EOF test_expect_success 'status (advice.statusHints false)' ' @@ -228,33 +228,35 @@ test_expect_success 'status with gitignore' ' git status -s --ignored >output && test_cmp expect output && - cat >expect <<-\EOF && - # On branch master - # Changes to be committed: - # (use "git reset HEAD <file>..." to unstage) - # - # new file: dir2/added - # - # Changes not staged for commit: - # (use "git add <file>..." to update what will be committed) - # (use "git checkout -- <file>..." to discard changes in working directory) - # - # modified: dir1/modified - # - # Untracked files: - # (use "git add <file>..." to include in what will be committed) - # - # dir2/modified - # Ignored files: - # (use "git add -f <file>..." to include in what will be committed) - # - # .gitignore - # dir1/untracked - # dir2/untracked - # expect - # output - # untracked - EOF + cat >expect <<\EOF && +On branch master +Changes to be committed: + (use "git reset HEAD <file>..." to unstage) + + new file: dir2/added + +Changes not staged for commit: + (use "git add <file>..." to update what will be committed) + (use "git checkout -- <file>..." to discard changes in working directory) + + modified: dir1/modified + +Untracked files: + (use "git add <file>..." to include in what will be committed) + + dir2/modified + +Ignored files: + (use "git add -f <file>..." to include in what will be committed) + + .gitignore + dir1/untracked + dir2/untracked + expect + output + untracked + +EOF git status --ignored >output && test_i18ncmp expect output ' @@ -289,30 +291,31 @@ test_expect_success 'status with gitignore (nothing untracked)' ' git status -s --ignored >output && test_cmp expect output && - cat >expect <<-\EOF && - # On branch master - # Changes to be committed: - # (use "git reset HEAD <file>..." to unstage) - # - # new file: dir2/added - # - # Changes not staged for commit: - # (use "git add <file>..." to update what will be committed) - # (use "git checkout -- <file>..." to discard changes in working directory) - # - # modified: dir1/modified - # - # Ignored files: - # (use "git add -f <file>..." to include in what will be committed) - # - # .gitignore - # dir1/untracked - # dir2/modified - # dir2/untracked - # expect - # output - # untracked - EOF + cat >expect <<\EOF && +On branch master +Changes to be committed: + (use "git reset HEAD <file>..." to unstage) + + new file: dir2/added + +Changes not staged for commit: + (use "git add <file>..." to update what will be committed) + (use "git checkout -- <file>..." to discard changes in working directory) + + modified: dir1/modified + +Ignored files: + (use "git add -f <file>..." to include in what will be committed) + + .gitignore + dir1/untracked + dir2/modified + dir2/untracked + expect + output + untracked + +EOF git status --ignored >output && test_i18ncmp expect output ' @@ -353,22 +356,22 @@ test_expect_success 'setup dir3' ' : >dir3/untracked2 ' -cat >expect <<EOF -# On branch master -# Changes to be committed: -# (use "git reset HEAD <file>..." to unstage) -# -# new file: dir2/added -# -# Changes not staged for commit: -# (use "git add <file>..." to update what will be committed) -# (use "git checkout -- <file>..." to discard changes in working directory) -# -# modified: dir1/modified -# -# Untracked files not listed (use -u option to show untracked files) -EOF test_expect_success 'status -uno' ' + cat >expect <<EOF && +On branch master +Changes to be committed: + (use "git reset HEAD <file>..." to unstage) + + new file: dir2/added + +Changes not staged for commit: + (use "git add <file>..." to update what will be committed) + (use "git checkout -- <file>..." to discard changes in working directory) + + modified: dir1/modified + +Untracked files not listed (use -u option to show untracked files) +EOF git status -uno >output && test_i18ncmp expect output ' @@ -379,17 +382,17 @@ test_expect_success 'status (status.showUntrackedFiles no)' ' test_i18ncmp expect output ' -cat >expect <<EOF -# On branch master -# Changes to be committed: -# new file: dir2/added -# -# Changes not staged for commit: -# modified: dir1/modified -# -# Untracked files not listed -EOF test_expect_success 'status -uno (advice.statusHints false)' ' + cat >expect <<EOF && +On branch master +Changes to be committed: + new file: dir2/added + +Changes not staged for commit: + modified: dir1/modified + +Untracked files not listed +EOF test_config advice.statusHints false && git status -uno >output && test_i18ncmp expect output @@ -410,31 +413,32 @@ test_expect_success 'status -s (status.showUntrackedFiles no)' ' test_cmp expect output ' -cat >expect <<EOF -# On branch master -# Changes to be committed: -# (use "git reset HEAD <file>..." to unstage) -# -# new file: dir2/added -# -# Changes not staged for commit: -# (use "git add <file>..." to update what will be committed) -# (use "git checkout -- <file>..." to discard changes in working directory) -# -# modified: dir1/modified -# -# Untracked files: -# (use "git add <file>..." to include in what will be committed) -# -# dir1/untracked -# dir2/modified -# dir2/untracked -# dir3/ -# expect -# output -# untracked -EOF test_expect_success 'status -unormal' ' + cat >expect <<EOF && +On branch master +Changes to be committed: + (use "git reset HEAD <file>..." to unstage) + + new file: dir2/added + +Changes not staged for commit: + (use "git add <file>..." to update what will be committed) + (use "git checkout -- <file>..." to discard changes in working directory) + + modified: dir1/modified + +Untracked files: + (use "git add <file>..." to include in what will be committed) + + dir1/untracked + dir2/modified + dir2/untracked + dir3/ + expect + output + untracked + +EOF git status -unormal >output && test_i18ncmp expect output ' @@ -467,32 +471,33 @@ test_expect_success 'status -s (status.showUntrackedFiles normal)' ' test_cmp expect output ' -cat >expect <<EOF -# On branch master -# Changes to be committed: -# (use "git reset HEAD <file>..." to unstage) -# -# new file: dir2/added -# -# Changes not staged for commit: -# (use "git add <file>..." to update what will be committed) -# (use "git checkout -- <file>..." to discard changes in working directory) -# -# modified: dir1/modified -# -# Untracked files: -# (use "git add <file>..." to include in what will be committed) -# -# dir1/untracked -# dir2/modified -# dir2/untracked -# dir3/untracked1 -# dir3/untracked2 -# expect -# output -# untracked -EOF test_expect_success 'status -uall' ' + cat >expect <<EOF && +On branch master +Changes to be committed: + (use "git reset HEAD <file>..." to unstage) + + new file: dir2/added + +Changes not staged for commit: + (use "git add <file>..." to update what will be committed) + (use "git checkout -- <file>..." to discard changes in working directory) + + modified: dir1/modified + +Untracked files: + (use "git add <file>..." to include in what will be committed) + + dir1/untracked + dir2/modified + dir2/untracked + dir3/untracked1 + dir3/untracked2 + expect + output + untracked + +EOF git status -uall >output && test_i18ncmp expect output ' @@ -529,31 +534,31 @@ test_expect_success 'status -s (status.showUntrackedFiles all)' ' test_cmp expect output ' -cat >expect <<\EOF -# On branch master -# Changes to be committed: -# (use "git reset HEAD <file>..." to unstage) -# -# new file: ../dir2/added -# -# Changes not staged for commit: -# (use "git add <file>..." to update what will be committed) -# (use "git checkout -- <file>..." to discard changes in working directory) -# -# modified: modified -# -# Untracked files: -# (use "git add <file>..." to include in what will be committed) -# -# untracked -# ../dir2/modified -# ../dir2/untracked -# ../expect -# ../output -# ../untracked -EOF - test_expect_success 'status with relative paths' ' + cat >expect <<\EOF && +On branch master +Changes to be committed: + (use "git reset HEAD <file>..." to unstage) + + new file: ../dir2/added + +Changes not staged for commit: + (use "git add <file>..." to update what will be committed) + (use "git checkout -- <file>..." to discard changes in working directory) + + modified: modified + +Untracked files: + (use "git add <file>..." to include in what will be committed) + + untracked + ../dir2/modified + ../dir2/untracked + ../expect + ../output + ../untracked + +EOF (cd dir1 && git status) >output && test_i18ncmp expect output ' @@ -600,31 +605,31 @@ test_expect_success 'setup unique colors' ' ' -cat >expect <<\EOF -# On branch <GREEN>master<RESET> -# Changes to be committed: -# (use "git reset HEAD <file>..." to unstage) -# -# <GREEN>new file: dir2/added<RESET> -# -# Changes not staged for commit: -# (use "git add <file>..." to update what will be committed) -# (use "git checkout -- <file>..." to discard changes in working directory) -# -# <RED>modified: dir1/modified<RESET> -# -# Untracked files: -# (use "git add <file>..." to include in what will be committed) -# -# <BLUE>dir1/untracked<RESET> -# <BLUE>dir2/modified<RESET> -# <BLUE>dir2/untracked<RESET> -# <BLUE>expect<RESET> -# <BLUE>output<RESET> -# <BLUE>untracked<RESET> -EOF - test_expect_success 'status with color.ui' ' + cat >expect <<\EOF && +On branch <GREEN>master<RESET> +Changes to be committed: + (use "git reset HEAD <file>..." to unstage) + + <GREEN>new file: dir2/added<RESET> + +Changes not staged for commit: + (use "git add <file>..." to update what will be committed) + (use "git checkout -- <file>..." to discard changes in working directory) + + <RED>modified: dir1/modified<RESET> + +Untracked files: + (use "git add <file>..." to include in what will be committed) + + <BLUE>dir1/untracked<RESET> + <BLUE>dir2/modified<RESET> + <BLUE>dir2/untracked<RESET> + <BLUE>expect<RESET> + <BLUE>output<RESET> + <BLUE>untracked<RESET> + +EOF test_config color.ui always && git status | test_decode_color >output && test_i18ncmp expect output @@ -728,33 +733,33 @@ test_expect_success 'status --porcelain respects -b' ' ' -cat >expect <<\EOF -# On branch master -# Changes to be committed: -# (use "git reset HEAD <file>..." to unstage) -# -# new file: dir2/added -# -# Changes not staged for commit: -# (use "git add <file>..." to update what will be committed) -# (use "git checkout -- <file>..." to discard changes in working directory) -# -# modified: dir1/modified -# -# Untracked files: -# (use "git add <file>..." to include in what will be committed) -# -# dir1/untracked -# dir2/modified -# dir2/untracked -# expect -# output -# untracked -EOF test_expect_success 'status without relative paths' ' + cat >expect <<\EOF && +On branch master +Changes to be committed: + (use "git reset HEAD <file>..." to unstage) + new file: dir2/added + +Changes not staged for commit: + (use "git add <file>..." to update what will be committed) + (use "git checkout -- <file>..." to discard changes in working directory) + + modified: dir1/modified + +Untracked files: + (use "git add <file>..." to include in what will be committed) + + dir1/untracked + dir2/modified + dir2/untracked + expect + output + untracked + +EOF test_config status.relativePaths false && (cd dir1 && git status) >output && test_i18ncmp expect output @@ -780,23 +785,24 @@ test_expect_success 'status -s without relative paths' ' ' -cat <<EOF >expect -# On branch master -# Changes to be committed: -# (use "git reset HEAD <file>..." to unstage) -# -# modified: dir1/modified -# -# Untracked files: -# (use "git add <file>..." to include in what will be committed) -# -# dir1/untracked -# dir2/ -# expect -# output -# untracked -EOF test_expect_success 'dry-run of partial commit excluding new file in index' ' + cat >expect <<EOF && +On branch master +Changes to be committed: + (use "git reset HEAD <file>..." to unstage) + + modified: dir1/modified + +Untracked files: + (use "git add <file>..." to include in what will be committed) + + dir1/untracked + dir2/ + expect + output + untracked + +EOF git commit --dry-run dir1/modified >output && test_i18ncmp expect output ' @@ -821,31 +827,32 @@ test_expect_success 'setup status submodule summary' ' git add sm ' -cat >expect <<EOF -# On branch master -# Changes to be committed: -# (use "git reset HEAD <file>..." to unstage) -# -# new file: dir2/added -# new file: sm -# -# Changes not staged for commit: -# (use "git add <file>..." to update what will be committed) -# (use "git checkout -- <file>..." to discard changes in working directory) -# -# modified: dir1/modified -# -# Untracked files: -# (use "git add <file>..." to include in what will be committed) -# -# dir1/untracked -# dir2/modified -# dir2/untracked -# expect -# output -# untracked -EOF test_expect_success 'status submodule summary is disabled by default' ' + cat >expect <<EOF && +On branch master +Changes to be committed: + (use "git reset HEAD <file>..." to unstage) + + new file: dir2/added + new file: sm + +Changes not staged for commit: + (use "git add <file>..." to update what will be committed) + (use "git checkout -- <file>..." to discard changes in working directory) + + modified: dir1/modified + +Untracked files: + (use "git add <file>..." to include in what will be committed) + + dir1/untracked + dir2/modified + dir2/untracked + expect + output + untracked + +EOF git status >output && test_i18ncmp expect output ' @@ -880,36 +887,37 @@ test_expect_success 'status -s --untracked-files=all does not show submodule' ' head=$(cd sm && git rev-parse --short=7 --verify HEAD) -cat >expect <<EOF -# On branch master -# Changes to be committed: -# (use "git reset HEAD <file>..." to unstage) -# -# new file: dir2/added -# new file: sm -# -# Changes not staged for commit: -# (use "git add <file>..." to update what will be committed) -# (use "git checkout -- <file>..." to discard changes in working directory) -# -# modified: dir1/modified -# -# Submodule changes to be committed: -# -# * sm 0000000...$head (1): -# > Add foo -# -# Untracked files: -# (use "git add <file>..." to include in what will be committed) -# -# dir1/untracked -# dir2/modified -# dir2/untracked -# expect -# output -# untracked -EOF test_expect_success 'status submodule summary' ' + cat >expect <<EOF && +On branch master +Changes to be committed: + (use "git reset HEAD <file>..." to unstage) + + new file: dir2/added + new file: sm + +Changes not staged for commit: + (use "git add <file>..." to update what will be committed) + (use "git checkout -- <file>..." to discard changes in working directory) + + modified: dir1/modified + +Submodule changes to be committed: + +* sm 0000000...$head (1): + > Add foo + +Untracked files: + (use "git add <file>..." to include in what will be committed) + + dir1/untracked + dir2/modified + dir2/untracked + expect + output + untracked + +EOF git config status.submodulesummary 10 && git status >output && test_i18ncmp expect output @@ -941,26 +949,27 @@ test_expect_success 'status -s submodule summary' ' test_cmp expect output ' -cat >expect <<EOF -# On branch master -# Changes not staged for commit: -# (use "git add <file>..." to update what will be committed) -# (use "git checkout -- <file>..." to discard changes in working directory) -# -# modified: dir1/modified -# -# Untracked files: -# (use "git add <file>..." to include in what will be committed) -# -# dir1/untracked -# dir2/modified -# dir2/untracked -# expect -# output -# untracked +test_expect_success 'status submodule summary (clean submodule): commit' ' + cat >expect <<EOF && +On branch master +Changes not staged for commit: + (use "git add <file>..." to update what will be committed) + (use "git checkout -- <file>..." to discard changes in working directory) + + modified: dir1/modified + +Untracked files: + (use "git add <file>..." to include in what will be committed) + + dir1/untracked + dir2/modified + dir2/untracked + expect + output + untracked + no changes added to commit (use "git add" and/or "git commit -a") EOF -test_expect_success 'status submodule summary (clean submodule): commit' ' git commit -m "commit submodule" && git config status.submodulesummary 10 && test_must_fail git commit --dry-run >output && @@ -985,41 +994,42 @@ test_expect_success 'status -s submodule summary (clean submodule)' ' test_expect_success 'status -z implies porcelain' ' git status --porcelain | - "$PERL_PATH" -pe "s/\012/\000/g" >expect && + perl -pe "s/\012/\000/g" >expect && git status -z >output && test_cmp expect output ' -cat >expect <<EOF -# On branch master -# Changes to be committed: -# (use "git reset HEAD^1 <file>..." to unstage) -# -# new file: dir2/added -# new file: sm -# -# Changes not staged for commit: -# (use "git add <file>..." to update what will be committed) -# (use "git checkout -- <file>..." to discard changes in working directory) -# -# modified: dir1/modified -# -# Submodule changes to be committed: -# -# * sm 0000000...$head (1): -# > Add foo -# -# Untracked files: -# (use "git add <file>..." to include in what will be committed) -# -# dir1/untracked -# dir2/modified -# dir2/untracked -# expect -# output -# untracked -EOF test_expect_success 'commit --dry-run submodule summary (--amend)' ' + cat >expect <<EOF && +On branch master +Changes to be committed: + (use "git reset HEAD^1 <file>..." to unstage) + + new file: dir2/added + new file: sm + +Changes not staged for commit: + (use "git add <file>..." to update what will be committed) + (use "git checkout -- <file>..." to discard changes in working directory) + + modified: dir1/modified + +Submodule changes to be committed: + +* sm 0000000...$head (1): + > Add foo + +Untracked files: + (use "git add <file>..." to include in what will be committed) + + dir1/untracked + dir2/modified + dir2/untracked + expect + output + untracked + +EOF git config status.submodulesummary 10 && git commit --dry-run --amend >output && test_i18ncmp expect output @@ -1044,37 +1054,37 @@ test_expect_success POSIXPERM,SANITY 'status succeeds in a read-only repository' new_head=$(cd sm && git rev-parse --short=7 --verify HEAD) touch .gitmodules -cat > expect << EOF -# On branch master -# Changes to be committed: -# (use "git reset HEAD <file>..." to unstage) -# -# modified: sm -# -# Changes not staged for commit: -# (use "git add <file>..." to update what will be committed) -# (use "git checkout -- <file>..." to discard changes in working directory) -# -# modified: dir1/modified -# -# Submodule changes to be committed: -# -# * sm $head...$new_head (1): -# > Add bar -# -# Untracked files: -# (use "git add <file>..." to include in what will be committed) -# -# .gitmodules -# dir1/untracked -# dir2/modified -# dir2/untracked -# expect -# output -# untracked -EOF - test_expect_success '--ignore-submodules=untracked suppresses submodules with untracked content' ' + cat > expect << EOF && +On branch master +Changes to be committed: + (use "git reset HEAD <file>..." to unstage) + + modified: sm + +Changes not staged for commit: + (use "git add <file>..." to update what will be committed) + (use "git checkout -- <file>..." to discard changes in working directory) + + modified: dir1/modified + +Submodule changes to be committed: + +* sm $head...$new_head (1): + > Add bar + +Untracked files: + (use "git add <file>..." to include in what will be committed) + + .gitmodules + dir1/untracked + dir2/modified + dir2/untracked + expect + output + untracked + +EOF echo modified sm/untracked && git status --ignore-submodules=untracked >output && test_i18ncmp expect output @@ -1154,39 +1164,39 @@ test_expect_success '.git/config ignore=dirty suppresses submodules with modifie git config -f .gitmodules --remove-section submodule.subname ' -cat > expect << EOF -# On branch master -# Changes to be committed: -# (use "git reset HEAD <file>..." to unstage) -# -# modified: sm -# -# Changes not staged for commit: -# (use "git add <file>..." to update what will be committed) -# (use "git checkout -- <file>..." to discard changes in working directory) -# (commit or discard the untracked or modified content in submodules) -# -# modified: dir1/modified -# modified: sm (modified content) -# -# Submodule changes to be committed: -# -# * sm $head...$new_head (1): -# > Add bar -# -# Untracked files: -# (use "git add <file>..." to include in what will be committed) -# -# .gitmodules -# dir1/untracked -# dir2/modified -# dir2/untracked -# expect -# output -# untracked -EOF - test_expect_success "--ignore-submodules=untracked doesn't suppress submodules with modified content" ' + cat > expect << EOF && +On branch master +Changes to be committed: + (use "git reset HEAD <file>..." to unstage) + + modified: sm + +Changes not staged for commit: + (use "git add <file>..." to update what will be committed) + (use "git checkout -- <file>..." to discard changes in working directory) + (commit or discard the untracked or modified content in submodules) + + modified: dir1/modified + modified: sm (modified content) + +Submodule changes to be committed: + +* sm $head...$new_head (1): + > Add bar + +Untracked files: + (use "git add <file>..." to include in what will be committed) + + .gitmodules + dir1/untracked + dir2/modified + dir2/untracked + expect + output + untracked + +EOF git status --ignore-submodules=untracked > output && test_i18ncmp expect output ' @@ -1212,43 +1222,43 @@ test_expect_success ".git/config ignore=untracked doesn't suppress submodules wi head2=$(cd sm && git commit -q -m "2nd commit" foo && git rev-parse --short=7 --verify HEAD) -cat > expect << EOF -# On branch master -# Changes to be committed: -# (use "git reset HEAD <file>..." to unstage) -# -# modified: sm -# -# Changes not staged for commit: -# (use "git add <file>..." to update what will be committed) -# (use "git checkout -- <file>..." to discard changes in working directory) -# -# modified: dir1/modified -# modified: sm (new commits) -# -# Submodule changes to be committed: -# -# * sm $head...$new_head (1): -# > Add bar -# -# Submodules changed but not updated: -# -# * sm $new_head...$head2 (1): -# > 2nd commit -# -# Untracked files: -# (use "git add <file>..." to include in what will be committed) -# -# .gitmodules -# dir1/untracked -# dir2/modified -# dir2/untracked -# expect -# output -# untracked -EOF - test_expect_success "--ignore-submodules=untracked doesn't suppress submodule summary" ' + cat > expect << EOF && +On branch master +Changes to be committed: + (use "git reset HEAD <file>..." to unstage) + + modified: sm + +Changes not staged for commit: + (use "git add <file>..." to update what will be committed) + (use "git checkout -- <file>..." to discard changes in working directory) + + modified: dir1/modified + modified: sm (new commits) + +Submodule changes to be committed: + +* sm $head...$new_head (1): + > Add bar + +Submodules changed but not updated: + +* sm $new_head...$head2 (1): + > 2nd commit + +Untracked files: + (use "git add <file>..." to include in what will be committed) + + .gitmodules + dir1/untracked + dir2/modified + dir2/untracked + expect + output + untracked + +EOF git status --ignore-submodules=untracked > output && test_i18ncmp expect output ' @@ -1329,47 +1339,48 @@ cat > expect << EOF ; expect ; output ; untracked +; EOF test_expect_success "status (core.commentchar with submodule summary)" ' test_config core.commentchar ";" && - git status >output && + git -c status.displayCommentPrefix=true status >output && test_i18ncmp expect output ' test_expect_success "status (core.commentchar with two chars with submodule summary)" ' test_config core.commentchar ";;" && - git status >output && + git -c status.displayCommentPrefix=true status >output && test_i18ncmp expect output ' -cat > expect << EOF -# On branch master -# Changes not staged for commit: -# (use "git add <file>..." to update what will be committed) -# (use "git checkout -- <file>..." to discard changes in working directory) -# -# modified: dir1/modified -# -# Untracked files: -# (use "git add <file>..." to include in what will be committed) -# -# .gitmodules -# dir1/untracked -# dir2/modified -# dir2/untracked -# expect -# output -# untracked +test_expect_success "--ignore-submodules=all suppresses submodule summary" ' + cat > expect << EOF && +On branch master +Changes not staged for commit: + (use "git add <file>..." to update what will be committed) + (use "git checkout -- <file>..." to discard changes in working directory) + + modified: dir1/modified + +Untracked files: + (use "git add <file>..." to include in what will be committed) + + .gitmodules + dir1/untracked + dir2/modified + dir2/untracked + expect + output + untracked + no changes added to commit (use "git add" and/or "git commit -a") EOF - -test_expect_success "--ignore-submodules=all suppresses submodule summary" ' git status --ignore-submodules=all > output && test_i18ncmp expect output ' -test_expect_failure '.gitmodules ignore=all suppresses submodule summary' ' +test_expect_success '.gitmodules ignore=all suppresses submodule summary' ' git config --add -f .gitmodules submodule.subname.ignore all && git config --add -f .gitmodules submodule.subname.path sm && git status > output && @@ -1377,7 +1388,7 @@ test_expect_failure '.gitmodules ignore=all suppresses submodule summary' ' git config -f .gitmodules --remove-section submodule.subname ' -test_expect_failure '.git/config ignore=all suppresses submodule summary' ' +test_expect_success '.git/config ignore=all suppresses submodule summary' ' git config --add -f .gitmodules submodule.subname.ignore none && git config --add -f .gitmodules submodule.subname.path sm && git config --add submodule.subname.ignore all && diff --git a/t/t7510-signed-commit.sh b/t/t7510-signed-commit.sh index 1d3c56fe61..5ddac1a9f7 100755 --- a/t/t7510-signed-commit.sh +++ b/t/t7510-signed-commit.sh @@ -5,6 +5,8 @@ test_description='signed commit tests' . "$TEST_DIRECTORY/lib-gpg.sh" test_expect_success GPG 'create signed commits' ' + test_when_finished "test_unconfig commit.gpgsign" && + echo 1 >file && git add file && test_tick && git commit -S -m initial && git tag initial && @@ -25,12 +27,27 @@ test_expect_success GPG 'create signed commits' ' git tag fourth-unsigned && test_tick && git commit --amend -S -m "fourth signed" && - git tag fourth-signed + git tag fourth-signed && + + git config commit.gpgsign true && + echo 5 >file && test_tick && git commit -a -m "fifth signed" && + git tag fifth-signed && + + git config commit.gpgsign false && + echo 6 >file && test_tick && git commit -a -m "sixth" && + git tag sixth-unsigned && + + git config commit.gpgsign true && + echo 7 >file && test_tick && git commit -a -m "seventh" --no-gpg-sign && + git tag seventh-unsigned && + + test_tick && git rebase -f HEAD^^ && git tag sixth-signed HEAD^ && + git tag seventh-signed ' test_expect_success GPG 'show signatures' ' ( - for commit in initial second merge master + for commit in initial second merge fourth-signed fifth-signed sixth-signed master do git show --pretty=short --show-signature $commit >actual && grep "Good signature from" actual || exit 1 @@ -39,7 +56,7 @@ test_expect_success GPG 'show signatures' ' done ) && ( - for commit in merge^2 fourth-unsigned + for commit in merge^2 fourth-unsigned sixth-unsigned seventh-unsigned do git show --pretty=short --show-signature $commit >actual && grep "Good signature from" actual && exit 1 @@ -52,7 +69,7 @@ test_expect_success GPG 'show signatures' ' test_expect_success GPG 'detect fudged signature' ' git cat-file commit master >raw && - sed -e "s/fourth signed/4th forged/" raw >forged1 && + sed -e "s/seventh/7th forged/" raw >forged1 && git hash-object -w -t commit forged1 >forged1.commit && git show --pretty=short --show-signature $(cat forged1.commit) >actual1 && grep "BAD signature from" actual1 && diff --git a/t/t7512-status-help.sh b/t/t7512-status-help.sh index 312f41765f..68ad2d7454 100755 --- a/t/t7512-status-help.sh +++ b/t/t7512-status-help.sh @@ -13,10 +13,6 @@ test_description='git status advice' set_fake_editor -test_expect_success 'use status.displayCommentPrefix by default ' ' - git config --global status.displayCommentPrefix true -' - test_expect_success 'prepare for conflicts' ' git config --global advice.statusuoption false && test_commit init main.txt init && @@ -29,18 +25,18 @@ test_expect_success 'prepare for conflicts' ' test_expect_success 'status when conflicts unresolved' ' test_must_fail git merge master && - cat >expected <<-\EOF && - # On branch conflicts - # You have unmerged paths. - # (fix conflicts and run "git commit") - # - # Unmerged paths: - # (use "git add <file>..." to mark resolution) - # - # both modified: main.txt - # - no changes added to commit (use "git add" and/or "git commit -a") - EOF + cat >expected <<\EOF && +On branch conflicts +You have unmerged paths. + (fix conflicts and run "git commit") + +Unmerged paths: + (use "git add <file>..." to mark resolution) + + both modified: main.txt + +no changes added to commit (use "git add" and/or "git commit -a") +EOF git status --untracked-files=no >actual && test_i18ncmp expected actual ' @@ -51,17 +47,17 @@ test_expect_success 'status when conflicts resolved before commit' ' test_must_fail git merge master && echo one >main.txt && git add main.txt && - cat >expected <<-\EOF && - # On branch conflicts - # All conflicts fixed but you are still merging. - # (use "git commit" to conclude merge) - # - # Changes to be committed: - # - # modified: main.txt - # - # Untracked files not listed (use -u option to show untracked files) - EOF + cat >expected <<\EOF && +On branch conflicts +All conflicts fixed but you are still merging. + (use "git commit" to conclude merge) + +Changes to be committed: + + modified: main.txt + +Untracked files not listed (use -u option to show untracked files) +EOF git status --untracked-files=no >actual && test_i18ncmp expected actual ' @@ -80,21 +76,21 @@ test_expect_success 'status when rebase in progress before resolving conflicts' test_when_finished "git rebase --abort" && ONTO=$(git rev-parse --short HEAD^^) && test_must_fail git rebase HEAD^ --onto HEAD^^ && - cat >expected <<-EOF && - # rebase in progress; onto $ONTO - # You are currently rebasing branch '\''rebase_conflicts'\'' on '\''$ONTO'\''. - # (fix conflicts and then run "git rebase --continue") - # (use "git rebase --skip" to skip this patch) - # (use "git rebase --abort" to check out the original branch) - # - # Unmerged paths: - # (use "git reset HEAD <file>..." to unstage) - # (use "git add <file>..." to mark resolution) - # - # both modified: main.txt - # - no changes added to commit (use "git add" and/or "git commit -a") - EOF + cat >expected <<EOF && +rebase in progress; onto $ONTO +You are currently rebasing branch '\''rebase_conflicts'\'' on '\''$ONTO'\''. + (fix conflicts and then run "git rebase --continue") + (use "git rebase --skip" to skip this patch) + (use "git rebase --abort" to check out the original branch) + +Unmerged paths: + (use "git reset HEAD <file>..." to unstage) + (use "git add <file>..." to mark resolution) + + both modified: main.txt + +no changes added to commit (use "git add" and/or "git commit -a") +EOF git status --untracked-files=no >actual && test_i18ncmp expected actual ' @@ -107,18 +103,18 @@ test_expect_success 'status when rebase in progress before rebase --continue' ' test_must_fail git rebase HEAD^ --onto HEAD^^ && echo three >main.txt && git add main.txt && - cat >expected <<-EOF && - # rebase in progress; onto $ONTO - # You are currently rebasing branch '\''rebase_conflicts'\'' on '\''$ONTO'\''. - # (all conflicts fixed: run "git rebase --continue") - # - # Changes to be committed: - # (use "git reset HEAD <file>..." to unstage) - # - # modified: main.txt - # - # Untracked files not listed (use -u option to show untracked files) - EOF + cat >expected <<EOF && +rebase in progress; onto $ONTO +You are currently rebasing branch '\''rebase_conflicts'\'' on '\''$ONTO'\''. + (all conflicts fixed: run "git rebase --continue") + +Changes to be committed: + (use "git reset HEAD <file>..." to unstage) + + modified: main.txt + +Untracked files not listed (use -u option to show untracked files) +EOF git status --untracked-files=no >actual && test_i18ncmp expected actual ' @@ -139,21 +135,21 @@ test_expect_success 'status during rebase -i when conflicts unresolved' ' test_when_finished "git rebase --abort" && ONTO=$(git rev-parse --short rebase_i_conflicts) && test_must_fail git rebase -i rebase_i_conflicts && - cat >expected <<-EOF && - # rebase in progress; onto $ONTO - # You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''. - # (fix conflicts and then run "git rebase --continue") - # (use "git rebase --skip" to skip this patch) - # (use "git rebase --abort" to check out the original branch) - # - # Unmerged paths: - # (use "git reset HEAD <file>..." to unstage) - # (use "git add <file>..." to mark resolution) - # - # both modified: main.txt - # - no changes added to commit (use "git add" and/or "git commit -a") - EOF + cat >expected <<EOF && +rebase in progress; onto $ONTO +You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''. + (fix conflicts and then run "git rebase --continue") + (use "git rebase --skip" to skip this patch) + (use "git rebase --abort" to check out the original branch) + +Unmerged paths: + (use "git reset HEAD <file>..." to unstage) + (use "git add <file>..." to mark resolution) + + both modified: main.txt + +no changes added to commit (use "git add" and/or "git commit -a") +EOF git status --untracked-files=no >actual && test_i18ncmp expected actual ' @@ -165,18 +161,18 @@ test_expect_success 'status during rebase -i after resolving conflicts' ' ONTO=$(git rev-parse --short rebase_i_conflicts) && test_must_fail git rebase -i rebase_i_conflicts && git add main.txt && - cat >expected <<-EOF && - # rebase in progress; onto $ONTO - # You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''. - # (all conflicts fixed: run "git rebase --continue") - # - # Changes to be committed: - # (use "git reset HEAD <file>..." to unstage) - # - # modified: main.txt - # - # Untracked files not listed (use -u option to show untracked files) - EOF + cat >expected <<EOF && +rebase in progress; onto $ONTO +You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''. + (all conflicts fixed: run "git rebase --continue") + +Changes to be committed: + (use "git reset HEAD <file>..." to unstage) + + modified: main.txt + +Untracked files not listed (use -u option to show untracked files) +EOF git status --untracked-files=no >actual && test_i18ncmp expected actual ' @@ -193,14 +189,14 @@ test_expect_success 'status when rebasing -i in edit mode' ' test_when_finished "git rebase --abort" && ONTO=$(git rev-parse --short HEAD~2) && git rebase -i HEAD~2 && - cat >expected <<-EOF && - # rebase in progress; onto $ONTO - # You are currently editing a commit while rebasing branch '\''rebase_i_edit'\'' on '\''$ONTO'\''. - # (use "git commit --amend" to amend the current commit) - # (use "git rebase --continue" once you are satisfied with your changes) - # - nothing to commit (use -u to show untracked files) - EOF + cat >expected <<EOF && +rebase in progress; onto $ONTO +You are currently editing a commit while rebasing branch '\''rebase_i_edit'\'' on '\''$ONTO'\''. + (use "git commit --amend" to amend the current commit) + (use "git rebase --continue" once you are satisfied with your changes) + +nothing to commit (use -u to show untracked files) +EOF git status --untracked-files=no >actual && test_i18ncmp expected actual ' @@ -219,19 +215,19 @@ test_expect_success 'status when splitting a commit' ' ONTO=$(git rev-parse --short HEAD~3) && git rebase -i HEAD~3 && git reset HEAD^ && - cat >expected <<-EOF && - # rebase in progress; onto $ONTO - # You are currently splitting a commit while rebasing branch '\''split_commit'\'' on '\''$ONTO'\''. - # (Once your working directory is clean, run "git rebase --continue") - # - # Changes not staged for commit: - # (use "git add <file>..." to update what will be committed) - # (use "git checkout -- <file>..." to discard changes in working directory) - # - # modified: main.txt - # - no changes added to commit (use "git add" and/or "git commit -a") - EOF + cat >expected <<EOF && +rebase in progress; onto $ONTO +You are currently splitting a commit while rebasing branch '\''split_commit'\'' on '\''$ONTO'\''. + (Once your working directory is clean, run "git rebase --continue") + +Changes not staged for commit: + (use "git add <file>..." to update what will be committed) + (use "git checkout -- <file>..." to discard changes in working directory) + + modified: main.txt + +no changes added to commit (use "git add" and/or "git commit -a") +EOF git status --untracked-files=no >actual && test_i18ncmp expected actual ' @@ -250,14 +246,14 @@ test_expect_success 'status after editing the last commit with --amend during a ONTO=$(git rev-parse --short HEAD~3) && git rebase -i HEAD~3 && git commit --amend -m "foo" && - cat >expected <<-EOF && - # rebase in progress; onto $ONTO - # You are currently editing a commit while rebasing branch '\''amend_last'\'' on '\''$ONTO'\''. - # (use "git commit --amend" to amend the current commit) - # (use "git rebase --continue" once you are satisfied with your changes) - # - nothing to commit (use -u to show untracked files) - EOF + cat >expected <<EOF && +rebase in progress; onto $ONTO +You are currently editing a commit while rebasing branch '\''amend_last'\'' on '\''$ONTO'\''. + (use "git commit --amend" to amend the current commit) + (use "git rebase --continue" once you are satisfied with your changes) + +nothing to commit (use -u to show untracked files) +EOF git status --untracked-files=no >actual && test_i18ncmp expected actual ' @@ -280,14 +276,14 @@ test_expect_success 'status: (continue first edit) second edit' ' ONTO=$(git rev-parse --short HEAD~3) && git rebase -i HEAD~3 && git rebase --continue && - cat >expected <<-EOF && - # rebase in progress; onto $ONTO - # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''. - # (use "git commit --amend" to amend the current commit) - # (use "git rebase --continue" once you are satisfied with your changes) - # - nothing to commit (use -u to show untracked files) - EOF + cat >expected <<EOF && +rebase in progress; onto $ONTO +You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''. + (use "git commit --amend" to amend the current commit) + (use "git rebase --continue" once you are satisfied with your changes) + +nothing to commit (use -u to show untracked files) +EOF git status --untracked-files=no >actual && test_i18ncmp expected actual ' @@ -302,19 +298,19 @@ test_expect_success 'status: (continue first edit) second edit and split' ' git rebase -i HEAD~3 && git rebase --continue && git reset HEAD^ && - cat >expected <<-EOF && - # rebase in progress; onto $ONTO - # You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''. - # (Once your working directory is clean, run "git rebase --continue") - # - # Changes not staged for commit: - # (use "git add <file>..." to update what will be committed) - # (use "git checkout -- <file>..." to discard changes in working directory) - # - # modified: main.txt - # - no changes added to commit (use "git add" and/or "git commit -a") - EOF + cat >expected <<EOF && +rebase in progress; onto $ONTO +You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''. + (Once your working directory is clean, run "git rebase --continue") + +Changes not staged for commit: + (use "git add <file>..." to update what will be committed) + (use "git checkout -- <file>..." to discard changes in working directory) + + modified: main.txt + +no changes added to commit (use "git add" and/or "git commit -a") +EOF git status --untracked-files=no >actual && test_i18ncmp expected actual ' @@ -329,14 +325,14 @@ test_expect_success 'status: (continue first edit) second edit and amend' ' git rebase -i HEAD~3 && git rebase --continue && git commit --amend -m "foo" && - cat >expected <<-EOF && - # rebase in progress; onto $ONTO - # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''. - # (use "git commit --amend" to amend the current commit) - # (use "git rebase --continue" once you are satisfied with your changes) - # - nothing to commit (use -u to show untracked files) - EOF + cat >expected <<EOF && +rebase in progress; onto $ONTO +You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''. + (use "git commit --amend" to amend the current commit) + (use "git rebase --continue" once you are satisfied with your changes) + +nothing to commit (use -u to show untracked files) +EOF git status --untracked-files=no >actual && test_i18ncmp expected actual ' @@ -351,14 +347,14 @@ test_expect_success 'status: (amend first edit) second edit' ' git rebase -i HEAD~3 && git commit --amend -m "a" && git rebase --continue && - cat >expected <<-EOF && - # rebase in progress; onto $ONTO - # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''. - # (use "git commit --amend" to amend the current commit) - # (use "git rebase --continue" once you are satisfied with your changes) - # - nothing to commit (use -u to show untracked files) - EOF + cat >expected <<EOF && +rebase in progress; onto $ONTO +You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''. + (use "git commit --amend" to amend the current commit) + (use "git rebase --continue" once you are satisfied with your changes) + +nothing to commit (use -u to show untracked files) +EOF git status --untracked-files=no >actual && test_i18ncmp expected actual ' @@ -374,19 +370,19 @@ test_expect_success 'status: (amend first edit) second edit and split' ' git commit --amend -m "b" && git rebase --continue && git reset HEAD^ && - cat >expected <<-EOF && - # rebase in progress; onto $ONTO - # You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''. - # (Once your working directory is clean, run "git rebase --continue") - # - # Changes not staged for commit: - # (use "git add <file>..." to update what will be committed) - # (use "git checkout -- <file>..." to discard changes in working directory) - # - # modified: main.txt - # - no changes added to commit (use "git add" and/or "git commit -a") - EOF + cat >expected <<EOF && +rebase in progress; onto $ONTO +You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''. + (Once your working directory is clean, run "git rebase --continue") + +Changes not staged for commit: + (use "git add <file>..." to update what will be committed) + (use "git checkout -- <file>..." to discard changes in working directory) + + modified: main.txt + +no changes added to commit (use "git add" and/or "git commit -a") +EOF git status --untracked-files=no >actual && test_i18ncmp expected actual ' @@ -402,14 +398,14 @@ test_expect_success 'status: (amend first edit) second edit and amend' ' git commit --amend -m "c" && git rebase --continue && git commit --amend -m "d" && - cat >expected <<-EOF && - # rebase in progress; onto $ONTO - # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''. - # (use "git commit --amend" to amend the current commit) - # (use "git rebase --continue" once you are satisfied with your changes) - # - nothing to commit (use -u to show untracked files) - EOF + cat >expected <<EOF && +rebase in progress; onto $ONTO +You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''. + (use "git commit --amend" to amend the current commit) + (use "git rebase --continue" once you are satisfied with your changes) + +nothing to commit (use -u to show untracked files) +EOF git status --untracked-files=no >actual && test_i18ncmp expected actual ' @@ -426,14 +422,14 @@ test_expect_success 'status: (split first edit) second edit' ' git add main.txt && git commit -m "e" && git rebase --continue && - cat >expected <<-EOF && - # rebase in progress; onto $ONTO - # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''. - # (use "git commit --amend" to amend the current commit) - # (use "git rebase --continue" once you are satisfied with your changes) - # - nothing to commit (use -u to show untracked files) - EOF + cat >expected <<EOF && +rebase in progress; onto $ONTO +You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''. + (use "git commit --amend" to amend the current commit) + (use "git rebase --continue" once you are satisfied with your changes) + +nothing to commit (use -u to show untracked files) +EOF git status --untracked-files=no >actual && test_i18ncmp expected actual ' @@ -451,19 +447,19 @@ test_expect_success 'status: (split first edit) second edit and split' ' git commit --amend -m "f" && git rebase --continue && git reset HEAD^ && - cat >expected <<-EOF && - # rebase in progress; onto $ONTO - # You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''. - # (Once your working directory is clean, run "git rebase --continue") - # - # Changes not staged for commit: - # (use "git add <file>..." to update what will be committed) - # (use "git checkout -- <file>..." to discard changes in working directory) - # - # modified: main.txt - # - no changes added to commit (use "git add" and/or "git commit -a") - EOF + cat >expected <<EOF && +rebase in progress; onto $ONTO +You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''. + (Once your working directory is clean, run "git rebase --continue") + +Changes not staged for commit: + (use "git add <file>..." to update what will be committed) + (use "git checkout -- <file>..." to discard changes in working directory) + + modified: main.txt + +no changes added to commit (use "git add" and/or "git commit -a") +EOF git status --untracked-files=no >actual && test_i18ncmp expected actual ' @@ -481,14 +477,14 @@ test_expect_success 'status: (split first edit) second edit and amend' ' git commit --amend -m "g" && git rebase --continue && git commit --amend -m "h" && - cat >expected <<-EOF && - # rebase in progress; onto $ONTO - # You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''. - # (use "git commit --amend" to amend the current commit) - # (use "git rebase --continue" once you are satisfied with your changes) - # - nothing to commit (use -u to show untracked files) - EOF + cat >expected <<EOF && +rebase in progress; onto $ONTO +You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''. + (use "git commit --amend" to amend the current commit) + (use "git rebase --continue" once you are satisfied with your changes) + +nothing to commit (use -u to show untracked files) +EOF git status --untracked-files=no >actual && test_i18ncmp expected actual ' @@ -508,15 +504,15 @@ test_expect_success 'status in an am session: file already exists' ' test_when_finished "rm Maildir/* && git am --abort" && git format-patch -1 -oMaildir && test_must_fail git am Maildir/*.patch && - cat >expected <<-\EOF && - # On branch am_already_exists - # You are in the middle of an am session. - # (fix conflicts and then run "git am --continue") - # (use "git am --skip" to skip this patch) - # (use "git am --abort" to restore the original branch) - # - nothing to commit (use -u to show untracked files) - EOF + cat >expected <<\EOF && +On branch am_already_exists +You are in the middle of an am session. + (fix conflicts and then run "git am --continue") + (use "git am --skip" to skip this patch) + (use "git am --abort" to restore the original branch) + +nothing to commit (use -u to show untracked files) +EOF git status --untracked-files=no >actual && test_i18ncmp expected actual ' @@ -530,15 +526,15 @@ test_expect_success 'status in an am session: file does not exist' ' test_when_finished "rm Maildir/* && git am --abort" && git format-patch -1 -oMaildir && test_must_fail git am Maildir/*.patch && - cat >expected <<-\EOF && - # On branch am_not_exists - # You are in the middle of an am session. - # (fix conflicts and then run "git am --continue") - # (use "git am --skip" to skip this patch) - # (use "git am --abort" to restore the original branch) - # - nothing to commit (use -u to show untracked files) - EOF + cat >expected <<\EOF && +On branch am_not_exists +You are in the middle of an am session. + (fix conflicts and then run "git am --continue") + (use "git am --skip" to skip this patch) + (use "git am --abort" to restore the original branch) + +nothing to commit (use -u to show untracked files) +EOF git status --untracked-files=no >actual && test_i18ncmp expected actual ' @@ -553,15 +549,15 @@ test_expect_success 'status in an am session: empty patch' ' git commit -m "delete all am_empty" && echo error >Maildir/0002-two_am.patch && test_must_fail git am Maildir/*.patch && - cat >expected <<-\EOF && - # On branch am_empty - # You are in the middle of an am session. - # The current patch is empty. - # (use "git am --skip" to skip this patch) - # (use "git am --abort" to restore the original branch) - # - nothing to commit (use -u to show untracked files) - EOF + cat >expected <<\EOF && +On branch am_empty +You are in the middle of an am session. +The current patch is empty. + (use "git am --skip" to skip this patch) + (use "git am --abort" to restore the original branch) + +nothing to commit (use -u to show untracked files) +EOF git status --untracked-files=no >actual && test_i18ncmp expected actual ' @@ -578,13 +574,13 @@ test_expect_success 'status when bisecting' ' git bisect bad && git bisect good one_bisect && TGT=$(git rev-parse --short two_bisect) && - cat >expected <<-EOF && - # HEAD detached at $TGT - # You are currently bisecting, started from branch '\''bisect'\''. - # (use "git bisect reset" to get back to the original branch) - # - nothing to commit (use -u to show untracked files) - EOF + cat >expected <<EOF && +HEAD detached at $TGT +You are currently bisecting, started from branch '\''bisect'\''. + (use "git bisect reset" to get back to the original branch) + +nothing to commit (use -u to show untracked files) +EOF git status --untracked-files=no >actual && test_i18ncmp expected actual ' @@ -601,15 +597,15 @@ test_expect_success 'status when rebase conflicts with statushints disabled' ' test_when_finished "git rebase --abort" && ONTO=$(git rev-parse --short HEAD^^) && test_must_fail git rebase HEAD^ --onto HEAD^^ && - cat >expected <<-EOF && - # rebase in progress; onto $ONTO - # You are currently rebasing branch '\''statushints_disabled'\'' on '\''$ONTO'\''. - # - # Unmerged paths: - # both modified: main.txt - # - no changes added to commit - EOF + cat >expected <<EOF && +rebase in progress; onto $ONTO +You are currently rebasing branch '\''statushints_disabled'\'' on '\''$ONTO'\''. + +Unmerged paths: + both modified: main.txt + +no changes added to commit +EOF git status --untracked-files=no >actual && test_i18ncmp expected actual ' @@ -630,19 +626,20 @@ test_expect_success 'prepare for cherry-pick conflicts' ' test_expect_success 'status when cherry-picking before resolving conflicts' ' test_when_finished "git cherry-pick --abort" && test_must_fail git cherry-pick cherry_branch_second && - cat >expected <<-\EOF && - # On branch cherry_branch - # You are currently cherry-picking. - # (fix conflicts and run "git cherry-pick --continue") - # (use "git cherry-pick --abort" to cancel the cherry-pick operation) - # - # Unmerged paths: - # (use "git add <file>..." to mark resolution) - # - # both modified: main.txt - # - no changes added to commit (use "git add" and/or "git commit -a") - EOF + TO_CHERRY_PICK=$(git rev-parse --short CHERRY_PICK_HEAD) && + cat >expected <<EOF && +On branch cherry_branch +You are currently cherry-picking commit $TO_CHERRY_PICK. + (fix conflicts and run "git cherry-pick --continue") + (use "git cherry-pick --abort" to cancel the cherry-pick operation) + +Unmerged paths: + (use "git add <file>..." to mark resolution) + + both modified: main.txt + +no changes added to commit (use "git add" and/or "git commit -a") +EOF git status --untracked-files=no >actual && test_i18ncmp expected actual ' @@ -652,20 +649,21 @@ test_expect_success 'status when cherry-picking after resolving conflicts' ' git reset --hard cherry_branch && test_when_finished "git cherry-pick --abort" && test_must_fail git cherry-pick cherry_branch_second && + TO_CHERRY_PICK=$(git rev-parse --short CHERRY_PICK_HEAD) && echo end >main.txt && git add main.txt && - cat >expected <<-\EOF && - # On branch cherry_branch - # You are currently cherry-picking. - # (all conflicts fixed: run "git cherry-pick --continue") - # (use "git cherry-pick --abort" to cancel the cherry-pick operation) - # - # Changes to be committed: - # - # modified: main.txt - # - # Untracked files not listed (use -u option to show untracked files) - EOF + cat >expected <<EOF && +On branch cherry_branch +You are currently cherry-picking commit $TO_CHERRY_PICK. + (all conflicts fixed: run "git cherry-pick --continue") + (use "git cherry-pick --abort" to cancel the cherry-pick operation) + +Changes to be committed: + + modified: main.txt + +Untracked files not listed (use -u option to show untracked files) +EOF git status --untracked-files=no >actual && test_i18ncmp expected actual ' @@ -673,18 +671,18 @@ test_expect_success 'status when cherry-picking after resolving conflicts' ' test_expect_success 'status showing detached at and from a tag' ' test_commit atag tagging && git checkout atag && - cat >expected <<-\EOF - # HEAD detached at atag - nothing to commit (use -u to show untracked files) - EOF + cat >expected <<\EOF && +HEAD detached at atag +nothing to commit (use -u to show untracked files) +EOF git status --untracked-files=no >actual && test_i18ncmp expected actual && git reset --hard HEAD^ && - cat >expected <<-\EOF - # HEAD detached from atag - nothing to commit (use -u to show untracked files) - EOF + cat >expected <<\EOF && +HEAD detached from atag +nothing to commit (use -u to show untracked files) +EOF git status --untracked-files=no >actual && test_i18ncmp expected actual ' @@ -699,20 +697,20 @@ test_expect_success 'status while reverting commit (conflicts)' ' test_commit new to-revert.txt && TO_REVERT=$(git rev-parse --short HEAD^) && test_must_fail git revert $TO_REVERT && - cat >expected <<-EOF - # On branch master - # You are currently reverting commit $TO_REVERT. - # (fix conflicts and run "git revert --continue") - # (use "git revert --abort" to cancel the revert operation) - # - # Unmerged paths: - # (use "git reset HEAD <file>..." to unstage) - # (use "git add <file>..." to mark resolution) - # - # both modified: to-revert.txt - # - no changes added to commit (use "git add" and/or "git commit -a") - EOF + cat >expected <<EOF && +On branch master +You are currently reverting commit $TO_REVERT. + (fix conflicts and run "git revert --continue") + (use "git revert --abort" to cancel the revert operation) + +Unmerged paths: + (use "git reset HEAD <file>..." to unstage) + (use "git add <file>..." to mark resolution) + + both modified: to-revert.txt + +no changes added to commit (use "git add" and/or "git commit -a") +EOF git status --untracked-files=no >actual && test_i18ncmp expected actual ' @@ -720,29 +718,29 @@ test_expect_success 'status while reverting commit (conflicts)' ' test_expect_success 'status while reverting commit (conflicts resolved)' ' echo reverted >to-revert.txt && git add to-revert.txt && - cat >expected <<-EOF - # On branch master - # You are currently reverting commit $TO_REVERT. - # (all conflicts fixed: run "git revert --continue") - # (use "git revert --abort" to cancel the revert operation) - # - # Changes to be committed: - # (use "git reset HEAD <file>..." to unstage) - # - # modified: to-revert.txt - # - # Untracked files not listed (use -u option to show untracked files) - EOF + cat >expected <<EOF && +On branch master +You are currently reverting commit $TO_REVERT. + (all conflicts fixed: run "git revert --continue") + (use "git revert --abort" to cancel the revert operation) + +Changes to be committed: + (use "git reset HEAD <file>..." to unstage) + + modified: to-revert.txt + +Untracked files not listed (use -u option to show untracked files) +EOF git status --untracked-files=no >actual && test_i18ncmp expected actual ' test_expect_success 'status after reverting commit' ' git revert --continue && - cat >expected <<-\EOF - # On branch master - nothing to commit (use -u to show untracked files) - EOF + cat >expected <<\EOF && +On branch master +nothing to commit (use -u to show untracked files) +EOF git status --untracked-files=no >actual && test_i18ncmp expected actual ' diff --git a/t/t7514-commit-patch.sh b/t/t7514-commit-patch.sh new file mode 100755 index 0000000000..998a2103c7 --- /dev/null +++ b/t/t7514-commit-patch.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +test_description='hunk edit with "commit -p -m"' +. ./test-lib.sh + +if ! test_have_prereq PERL +then + skip_all="skipping '$test_description' tests, perl not available" + test_done +fi + +test_expect_success 'setup (initial)' ' + echo line1 >file && + git add file && + git commit -m commit1 +' + +test_expect_success 'edit hunk "commit -p -m message"' ' + test_when_finished "rm -f editor_was_started" && + rm -f editor_was_started && + echo more >>file && + echo e | env GIT_EDITOR=": >editor_was_started" git commit -p -m commit2 file && + test -r editor_was_started +' + +test_expect_success 'edit hunk "commit --dry-run -p -m message"' ' + test_when_finished "rm -f editor_was_started" && + rm -f editor_was_started && + echo more >>file && + echo e | env GIT_EDITOR=": >editor_was_started" git commit -p -m commit3 file && + test -r editor_was_started +' + +test_done diff --git a/t/t7601-merge-pull-config.sh b/t/t7601-merge-pull-config.sh index 830a4c3e9d..f768c900ab 100755 --- a/t/t7601-merge-pull-config.sh +++ b/t/t7601-merge-pull-config.sh @@ -38,6 +38,27 @@ test_expect_success 'merge c1 with c2' ' test -f c2.c ' +test_expect_success 'fast-forward pull succeeds with "true" in pull.ff' ' + git reset --hard c0 && + test_config pull.ff true && + git pull . c1 && + test "$(git rev-parse HEAD)" = "$(git rev-parse c1)" +' + +test_expect_success 'fast-forward pull creates merge with "false" in pull.ff' ' + git reset --hard c0 && + test_config pull.ff false && + git pull . c1 && + test "$(git rev-parse HEAD^1)" = "$(git rev-parse c0)" && + test "$(git rev-parse HEAD^2)" = "$(git rev-parse c1)" +' + +test_expect_success 'pull prevents non-fast-forward with "only" in pull.ff' ' + git reset --hard c1 && + test_config pull.ff only && + test_must_fail git pull . c3 +' + test_expect_success 'merge c1 with c2 (ours in pull.twohead)' ' git reset --hard c1 && git config pull.twohead ours && diff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh index d526b1d96a..05d9db090d 100755 --- a/t/t7610-mergetool.sh +++ b/t/t7610-mergetool.sh @@ -253,7 +253,7 @@ test_expect_success 'deleted vs modified submodule' ' git checkout -b test6 branch1 && git submodule update -N && mv submod submod-movedaside && - git rm submod && + git rm --cached submod && git commit -m "Submodule deleted from branch" && git checkout -b test6.a test6 && test_must_fail git merge master && @@ -322,7 +322,7 @@ test_expect_success 'file vs modified submodule' ' git checkout -b test7 branch1 && git submodule update -N && mv submod submod-movedaside && - git rm submod && + git rm --cached submod && echo not a submodule >submod && git add submod && git commit -m "Submodule path becomes file" && @@ -453,7 +453,7 @@ test_expect_success 'submodule in subdirectory' ' test_expect_success 'directory vs modified submodule' ' git checkout -b test11 branch1 && mv submod submod-movedaside && - git rm submod && + git rm --cached submod && mkdir submod && echo not a submodule >submod/file16 && git add submod/file16 && diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index d954b846a1..284018e3cd 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -17,11 +17,11 @@ test_expect_success 'objects in packs marked .keep are not repacked' ' # The second pack will contain the excluded object packsha1=$(git rev-list --objects --all | grep file2 | git pack-objects pack) && - touch -r pack-$packsha1.pack pack-$packsha1.keep && + >pack-$packsha1.keep && objsha1=$(git verify-pack -v pack-$packsha1.idx | head -n 1 | sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") && mv pack-* .git/objects/pack/ && - git repack -A -d -l && + git repack --no-pack-kept-objects -A -d -l && git prune-packed && for p in .git/objects/pack/*.idx; do idx=$(basename $p) @@ -35,6 +35,22 @@ test_expect_success 'objects in packs marked .keep are not repacked' ' test -z "$found_duplicate_object" ' +test_expect_success 'writing bitmaps can duplicate .keep objects' ' + # build on $objsha1, $packsha1, and .keep state from previous + git repack -Adl && + test_when_finished "found_duplicate_object=" && + for p in .git/objects/pack/*.idx; do + idx=$(basename $p) + test "pack-$packsha1.idx" = "$idx" && continue + if git verify-pack -v $p | egrep "^$objsha1"; then + found_duplicate_object=1 + echo "DUPLICATE OBJECT FOUND" + break + fi + done && + test "$found_duplicate_object" = 1 +' + test_expect_success 'loose objects in alternate ODB are not repacked' ' mkdir alt_objects && echo `pwd`/alt_objects > .git/objects/info/alternates && diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh index 2418528487..5a193c500d 100755 --- a/t/t7800-difftool.sh +++ b/t/t7800-difftool.sh @@ -434,4 +434,18 @@ test_expect_success PERL 'difftool --no-symlinks detects conflict ' ' ) ' +test_expect_success PERL 'difftool properly honors gitlink and core.worktree' ' + git submodule add ./. submod/ule && + ( + cd submod/ule && + test_config diff.tool checktrees && + test_config difftool.checktrees.cmd '\'' + test -d "$LOCAL" && test -d "$REMOTE" && echo good + '\'' && + echo good >expect && + git difftool --tool=checktrees --dir-diff HEAD~ >actual && + test_cmp expect actual + ) +' + test_done diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh index f698001c99..63b3039243 100755 --- a/t/t7810-grep.sh +++ b/t/t7810-grep.sh @@ -105,7 +105,7 @@ do test_expect_success "grep -w $L (w)" ' : >expected && - test_must_fail git grep -n -w -e "^w" >actual && + test_must_fail git grep -n -w -e "^w" $H >actual && test_cmp expected actual ' @@ -240,92 +240,104 @@ do test_cmp expected actual ' test_expect_success "grep $L with grep.extendedRegexp=false" ' - echo "ab:a+bc" >expected && - git -c grep.extendedRegexp=false grep "a+b*c" ab >actual && + echo "${HC}ab:a+bc" >expected && + git -c grep.extendedRegexp=false grep "a+b*c" $H ab >actual && test_cmp expected actual ' test_expect_success "grep $L with grep.extendedRegexp=true" ' - echo "ab:abc" >expected && - git -c grep.extendedRegexp=true grep "a+b*c" ab >actual && + echo "${HC}ab:abc" >expected && + git -c grep.extendedRegexp=true grep "a+b*c" $H ab >actual && test_cmp expected actual ' test_expect_success "grep $L with grep.patterntype=basic" ' - echo "ab:a+bc" >expected && - git -c grep.patterntype=basic grep "a+b*c" ab >actual && + echo "${HC}ab:a+bc" >expected && + git -c grep.patterntype=basic grep "a+b*c" $H ab >actual && test_cmp expected actual ' test_expect_success "grep $L with grep.patterntype=extended" ' - echo "ab:abc" >expected && - git -c grep.patterntype=extended grep "a+b*c" ab >actual && + echo "${HC}ab:abc" >expected && + git -c grep.patterntype=extended grep "a+b*c" $H ab >actual && test_cmp expected actual ' test_expect_success "grep $L with grep.patterntype=fixed" ' - echo "ab:a+b*c" >expected && - git -c grep.patterntype=fixed grep "a+b*c" ab >actual && + echo "${HC}ab:a+b*c" >expected && + git -c grep.patterntype=fixed grep "a+b*c" $H ab >actual && test_cmp expected actual ' test_expect_success LIBPCRE "grep $L with grep.patterntype=perl" ' - echo "ab:a+b*c" >expected && - git -c grep.patterntype=perl grep "a\x{2b}b\x{2a}c" ab >actual && + echo "${HC}ab:a+b*c" >expected && + git -c grep.patterntype=perl grep "a\x{2b}b\x{2a}c" $H ab >actual && test_cmp expected actual ' test_expect_success "grep $L with grep.patternType=default and grep.extendedRegexp=true" ' - echo "ab:abc" >expected && + echo "${HC}ab:abc" >expected && git \ -c grep.patternType=default \ -c grep.extendedRegexp=true \ - grep "a+b*c" ab >actual && + grep "a+b*c" $H ab >actual && test_cmp expected actual ' test_expect_success "grep $L with grep.extendedRegexp=true and grep.patternType=default" ' - echo "ab:abc" >expected && + echo "${HC}ab:abc" >expected && git \ -c grep.extendedRegexp=true \ -c grep.patternType=default \ - grep "a+b*c" ab >actual && + grep "a+b*c" $H ab >actual && test_cmp expected actual ' - test_expect_success 'grep $L with grep.patternType=extended and grep.extendedRegexp=false' ' - echo "ab:abc" >expected && + test_expect_success "grep $L with grep.patternType=extended and grep.extendedRegexp=false" ' + echo "${HC}ab:abc" >expected && git \ -c grep.patternType=extended \ -c grep.extendedRegexp=false \ - grep "a+b*c" ab >actual && + grep "a+b*c" $H ab >actual && test_cmp expected actual ' - test_expect_success 'grep $L with grep.patternType=basic and grep.extendedRegexp=true' ' - echo "ab:a+bc" >expected && + test_expect_success "grep $L with grep.patternType=basic and grep.extendedRegexp=true" ' + echo "${HC}ab:a+bc" >expected && git \ -c grep.patternType=basic \ -c grep.extendedRegexp=true \ - grep "a+b*c" ab >actual && + grep "a+b*c" $H ab >actual && test_cmp expected actual ' - test_expect_success 'grep $L with grep.extendedRegexp=false and grep.patternType=extended' ' - echo "ab:abc" >expected && + test_expect_success "grep $L with grep.extendedRegexp=false and grep.patternType=extended" ' + echo "${HC}ab:abc" >expected && git \ -c grep.extendedRegexp=false \ -c grep.patternType=extended \ - grep "a+b*c" ab >actual && + grep "a+b*c" $H ab >actual && test_cmp expected actual ' - test_expect_success 'grep $L with grep.extendedRegexp=true and grep.patternType=basic' ' - echo "ab:a+bc" >expected && + test_expect_success "grep $L with grep.extendedRegexp=true and grep.patternType=basic" ' + echo "${HC}ab:a+bc" >expected && git \ -c grep.extendedRegexp=true \ -c grep.patternType=basic \ - grep "a+b*c" ab >actual && + grep "a+b*c" $H ab >actual && + test_cmp expected actual + ' + + test_expect_success "grep --count $L" ' + echo ${HC}ab:3 >expected && + git grep --count -e b $H -- ab >actual && + test_cmp expected actual + ' + + test_expect_success "grep --count -h $L" ' + echo 3 >expected && + git grep --count -h -e b $H -- ab >actual && test_cmp expected actual ' done diff --git a/t/t8007-cat-file-textconv.sh b/t/t8007-cat-file-textconv.sh index b95e102891..eacd49ade6 100755 --- a/t/t8007-cat-file-textconv.sh +++ b/t/t8007-cat-file-textconv.sh @@ -20,11 +20,11 @@ test_expect_success 'setup ' ' ' cat >expected <<EOF -fatal: git cat-file --textconv: unable to run textconv on :one.bin +bin: test version 2 EOF test_expect_success 'no filter specified' ' - git cat-file --textconv :one.bin 2>result + git cat-file --textconv :one.bin >result && test_cmp expected result ' @@ -34,10 +34,6 @@ test_expect_success 'setup textconv filters' ' git config diff.test.cachetextconv false ' -cat >expected <<EOF -bin: test version 2 -EOF - test_expect_success 'cat-file without --textconv' ' git cat-file blob :one.bin >result && test_cmp expected result @@ -71,25 +67,19 @@ test_expect_success 'cat-file --textconv on previous commit' ' ' test_expect_success 'cat-file without --textconv (symlink)' ' + printf "%s" "one.bin" >expected && git cat-file blob :symlink.bin >result && - printf "%s" "one.bin" >expected test_cmp expected result ' test_expect_success 'cat-file --textconv on index (symlink)' ' - ! git cat-file --textconv :symlink.bin 2>result && - cat >expected <<\EOF && -fatal: git cat-file --textconv: unable to run textconv on :symlink.bin -EOF + git cat-file --textconv :symlink.bin >result && test_cmp expected result ' test_expect_success 'cat-file --textconv on HEAD (symlink)' ' - ! git cat-file --textconv HEAD:symlink.bin 2>result && - cat >expected <<EOF && -fatal: git cat-file --textconv: unable to run textconv on HEAD:symlink.bin -EOF + git cat-file --textconv HEAD:symlink.bin >result && test_cmp expected result ' diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index 2813aa9a61..1ecdacb6fd 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -23,7 +23,6 @@ test_expect_success $PREREQ \ echo do echo " echo \"!\$a!\"" echo "done >commandline\$output" - test_have_prereq MINGW && echo "dos2unix commandline\$output" echo "cat > msgtxt\$output" ) >fake.sendmail && chmod +x ./fake.sendmail && @@ -410,7 +409,7 @@ test_expect_success $PREREQ 'Valid In-Reply-To when prompting' ' (echo "From Example <from@example.com>" echo "To Example <to@example.com>" echo "" - ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \ + ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \ --smtp-server="$(pwd)/fake.sendmail" \ $patches 2>errors && ! grep "^In-Reply-To: < *>" msgtxt1 diff --git a/t/t9114-git-svn-dcommit-merge.sh b/t/t9114-git-svn-dcommit-merge.sh index f524d2f383..d33d714006 100755 --- a/t/t9114-git-svn-dcommit-merge.sh +++ b/t/t9114-git-svn-dcommit-merge.sh @@ -62,7 +62,7 @@ test_expect_success 'setup git mirror and merge' ' echo friend > README && cat tmp >> README && git commit -a -m "friend" && - git pull . merge + git merge merge ' test_debug 'gitk --all & sleep 1' diff --git a/t/t9117-git-svn-init-clone.sh b/t/t9117-git-svn-init-clone.sh index b7ef9e2589..69e9c0db5d 100755 --- a/t/t9117-git-svn-init-clone.sh +++ b/t/t9117-git-svn-init-clone.sh @@ -52,4 +52,71 @@ test_expect_success 'clone to target directory with --stdlayout' ' rm -rf target ' +test_expect_success 'init without -s/-T/-b/-t does not warn' ' + test ! -d trunk && + git svn init "$svnrepo"/project/trunk trunk 2>warning && + test_must_fail grep -q prefix warning && + rm -rf trunk && + rm -f warning + ' + +test_expect_success 'clone without -s/-T/-b/-t does not warn' ' + test ! -d trunk && + git svn clone "$svnrepo"/project/trunk 2>warning && + test_must_fail grep -q prefix warning && + rm -rf trunk && + rm -f warning + ' + +test_svn_configured_prefix () { + prefix=$1 && + cat >expect <<EOF && +project/trunk:refs/remotes/${prefix}trunk +project/branches/*:refs/remotes/${prefix}* +project/tags/*:refs/remotes/${prefix}tags/* +EOF + test ! -f actual && + git --git-dir=project/.git config svn-remote.svn.fetch >>actual && + git --git-dir=project/.git config svn-remote.svn.branches >>actual && + git --git-dir=project/.git config svn-remote.svn.tags >>actual && + test_cmp expect actual && + rm -f expect actual +} + +test_expect_success 'init with -s/-T/-b/-t without --prefix warns' ' + test ! -d project && + git svn init -s "$svnrepo"/project project 2>warning && + grep -q prefix warning && + test_svn_configured_prefix "" && + rm -rf project && + rm -f warning + ' + +test_expect_success 'clone with -s/-T/-b/-t without --prefix warns' ' + test ! -d project && + git svn clone -s "$svnrepo"/project 2>warning && + grep -q prefix warning && + test_svn_configured_prefix "" && + rm -rf project && + rm -f warning + ' + +test_expect_success 'init with -s/-T/-b/-t and --prefix does not warn' ' + test ! -d project && + git svn init -s "$svnrepo"/project project --prefix="" 2>warning && + test_must_fail grep -q prefix warning && + test_svn_configured_prefix "" && + rm -rf project && + rm -f warning + ' + +test_expect_success 'clone with -s/-T/-b/-t and --prefix does not warn' ' + test ! -d project && + git svn clone -s "$svnrepo"/project --prefix="" 2>warning && + test_must_fail grep -q prefix warning && + test_svn_configured_prefix "" && + rm -rf project && + rm -f warning + ' + test_done diff --git a/t/t9129-git-svn-i18n-commitencoding.sh b/t/t9129-git-svn-i18n-commitencoding.sh index 9a40f1e199..8cfdfe790f 100755 --- a/t/t9129-git-svn-i18n-commitencoding.sh +++ b/t/t9129-git-svn-i18n-commitencoding.sh @@ -29,7 +29,7 @@ fi compare_svn_head_with () { # extract just the log message and strip out committer info. # don't use --limit here since svn 1.1.x doesn't have it, - LC_ALL="$a_utf8_locale" svn log `git svn info --url` | "$PERL_PATH" -w -e ' + LC_ALL="$a_utf8_locale" svn log `git svn info --url` | perl -w -e ' use bytes; $/ = ("-"x72) . "\n"; my @x = <STDIN>; diff --git a/t/t9137-git-svn-dcommit-clobber-series.sh b/t/t9137-git-svn-dcommit-clobber-series.sh index c17aa3186f..d60da63f7a 100755 --- a/t/t9137-git-svn-dcommit-clobber-series.sh +++ b/t/t9137-git-svn-dcommit-clobber-series.sh @@ -20,8 +20,8 @@ test_expect_success '(supposedly) non-conflicting change from SVN' ' test x"`sed -n -e 61p < file`" = x61 && svn_cmd co "$svnrepo" tmp && (cd tmp && - "$PERL_PATH" -i.bak -p -e "s/^58$/5588/" file && - "$PERL_PATH" -i.bak -p -e "s/^61$/6611/" file && + perl -i.bak -p -e "s/^58$/5588/" file && + perl -i.bak -p -e "s/^61$/6611/" file && poke file && test x"`sed -n -e 58p < file`" = x5588 && test x"`sed -n -e 61p < file`" = x6611 && @@ -40,8 +40,8 @@ test_expect_success 'some unrelated changes to git' " test_expect_success 'change file but in unrelated area' " test x\"\`sed -n -e 4p < file\`\" = x4 && test x\"\`sed -n -e 7p < file\`\" = x7 && - "$PERL_PATH" -i.bak -p -e 's/^4\$/4444/' file && - "$PERL_PATH" -i.bak -p -e 's/^7\$/7777/' file && + perl -i.bak -p -e 's/^4\$/4444/' file && + perl -i.bak -p -e 's/^7\$/7777/' file && test x\"\`sed -n -e 4p < file\`\" = x4444 && test x\"\`sed -n -e 7p < file\`\" = x7777 && git commit -m '4 => 4444, 7 => 7777' file && diff --git a/t/t9150/make-svk-dump b/t/t9150/make-svk-dump index 2242f14ebe..2242f14ebe 100644..100755 --- a/t/t9150/make-svk-dump +++ b/t/t9150/make-svk-dump diff --git a/t/t9151/make-svnmerge-dump b/t/t9151/make-svnmerge-dump index e1e138cb1a..e1e138cb1a 100644..100755 --- a/t/t9151/make-svnmerge-dump +++ b/t/t9151/make-svnmerge-dump diff --git a/t/t9200-git-cvsexportcommit.sh b/t/t9200-git-cvsexportcommit.sh index 3fb3368903..812c9cd462 100755 --- a/t/t9200-git-cvsexportcommit.sh +++ b/t/t9200-git-cvsexportcommit.sh @@ -5,7 +5,6 @@ test_description='Test export of commits to CVS' . ./test-lib.sh -. "$TEST_DIRECTORY"/lib-prereq-FILEMODE.sh if ! test_have_prereq PERL; then skip_all='skipping git cvsexportcommit tests, perl not available' diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh index ac6f3b6af2..27263dfb80 100755 --- a/t/t9300-fast-import.sh +++ b/t/t9300-fast-import.sh @@ -12,7 +12,7 @@ test_description='test git fast-import utility' # This could be written as "head -c $1", but IRIX "head" does not # support the -c option. head_c () { - "$PERL_PATH" -e ' + perl -e ' my $len = $ARGV[1]; while ($len > 0) { my $s; @@ -1031,6 +1031,32 @@ test_expect_success \ git diff-tree -M -r M3^ M3 >actual && compare_diff_raw expect actual' +cat >input <<INPUT_END +commit refs/heads/M4 +committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE +data <<COMMIT +rename root +COMMIT + +from refs/heads/M2^0 +R "" sub + +INPUT_END + +cat >expect <<EOF +:100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 R100 file2/oldf sub/file2/oldf +:100755 100755 85df50785d62d3b05ab03d9cbf7e4a0b49449730 85df50785d62d3b05ab03d9cbf7e4a0b49449730 R100 file4 sub/file4 +:100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc R100 i/am/new/to/you sub/i/am/new/to/you +:100755 100755 e74b7d465e52746be2b4bae983670711e6e66657 e74b7d465e52746be2b4bae983670711e6e66657 R100 newdir/exec.sh sub/newdir/exec.sh +:100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 R100 newdir/interesting sub/newdir/interesting +EOF +test_expect_success \ + 'M: rename root to subdirectory' \ + 'git fast-import <input && + git diff-tree -M -r M4^ M4 >actual && + cat actual && + compare_diff_raw expect actual' + ### ### series N ### @@ -1228,6 +1254,29 @@ test_expect_success \ compare_diff_raw expect actual' test_expect_success \ + 'N: copy root by path' \ + 'cat >expect <<-\EOF && + :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf oldroot/file2/newf + :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf oldroot/file2/oldf + :100755 100755 85df50785d62d3b05ab03d9cbf7e4a0b49449730 85df50785d62d3b05ab03d9cbf7e4a0b49449730 C100 file4 oldroot/file4 + :100755 100755 e74b7d465e52746be2b4bae983670711e6e66657 e74b7d465e52746be2b4bae983670711e6e66657 C100 newdir/exec.sh oldroot/newdir/exec.sh + :100644 100644 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 fcf778cda181eaa1cbc9e9ce3a2e15ee9f9fe791 C100 newdir/interesting oldroot/newdir/interesting + EOF + cat >input <<-INPUT_END && + commit refs/heads/N-copy-root-path + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + data <<COMMIT + copy root directory by (empty) path + COMMIT + + from refs/heads/branch^0 + C "" oldroot + INPUT_END + git fast-import <input && + git diff-tree -C --find-copies-harder -r branch N-copy-root-path >actual && + compare_diff_raw expect actual' + +test_expect_success \ 'N: delete directory by copying' \ 'cat >expect <<-\EOF && OBJID @@ -2815,14 +2864,14 @@ test_expect_success 'S: notemodify with garbage after sha1 dataref must fail' ' ' # -# notemodify, mark in committish +# notemodify, mark in commit-ish # -test_expect_success 'S: notemodify with garbarge after mark committish must fail' ' +test_expect_success 'S: notemodify with garbarge 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 data <<COMMIT - commit S note committish + commit S note commit-ish COMMIT N :202 :302x EOF @@ -2934,4 +2983,20 @@ test_expect_success 'S: ls with garbage after sha1 must fail' ' test_i18ngrep "space after tree-ish" err ' +### +### series T (ls) +### +# Setup is carried over from series S. + +test_expect_success 'T: ls root tree' ' + sed -e "s/Z\$//" >expect <<-EOF && + 040000 tree $(git rev-parse S^{tree}) Z + EOF + sha1=$(git rev-parse --verify S) && + git fast-import --import-marks=marks <<-EOF >actual && + ls $sha1 "" + EOF + test_cmp expect actual +' + test_done diff --git a/t/t9350-fast-export.sh b/t/t9350-fast-export.sh index 34c2d8f49a..2312dec8f0 100755 --- a/t/t9350-fast-export.sh +++ b/t/t9350-fast-export.sh @@ -429,7 +429,7 @@ test_expect_success 'fast-export quotes pathnames' ' --cacheinfo 100644 $blob "path with \\backslash" \ --cacheinfo 100644 $blob "path with space" && git commit -m addition && - git ls-files -z -s | "$PERL_PATH" -0pe "s{\\t}{$&subdir/}" >index && + git ls-files -z -s | perl -0pe "s{\\t}{$&subdir/}" >index && git read-tree --empty && git update-index -z --index-info <index && git commit -m rename && diff --git a/t/t9400-git-cvsserver-server.sh b/t/t9400-git-cvsserver-server.sh index 043138631b..3edc4086d8 100755 --- a/t/t9400-git-cvsserver-server.sh +++ b/t/t9400-git-cvsserver-server.sh @@ -20,7 +20,7 @@ then skip_all='skipping git-cvsserver tests, cvs not found' test_done fi -"$PERL_PATH" -e 'use DBI; use DBD::SQLite' >/dev/null 2>&1 || { +perl -e 'use DBI; use DBD::SQLite' >/dev/null 2>&1 || { skip_all='skipping git-cvsserver tests, Perl SQLite interface unavailable' test_done } diff --git a/t/t9401-git-cvsserver-crlf.sh b/t/t9401-git-cvsserver-crlf.sh index 8c3db76301..5a4ed28e49 100755 --- a/t/t9401-git-cvsserver-crlf.sh +++ b/t/t9401-git-cvsserver-crlf.sh @@ -68,7 +68,7 @@ then skip_all='skipping git-cvsserver tests, perl not available' test_done fi -"$PERL_PATH" -e 'use DBI; use DBD::SQLite' >/dev/null 2>&1 || { +perl -e 'use DBI; use DBD::SQLite' >/dev/null 2>&1 || { skip_all='skipping git-cvsserver tests, Perl SQLite interface unavailable' test_done } diff --git a/t/t9402-git-cvsserver-refs.sh b/t/t9402-git-cvsserver-refs.sh index db69af2cff..1e266effff 100755 --- a/t/t9402-git-cvsserver-refs.sh +++ b/t/t9402-git-cvsserver-refs.sh @@ -76,7 +76,7 @@ then skip_all='skipping git-cvsserver tests, perl not available' test_done fi -"$PERL_PATH" -e 'use DBI; use DBD::SQLite' >/dev/null 2>&1 || { +perl -e 'use DBI; use DBD::SQLite' >/dev/null 2>&1 || { skip_all='skipping git-cvsserver tests, Perl SQLite interface unavailable' test_done } diff --git a/t/t9500-gitweb-standalone-no-errors.sh b/t/t9500-gitweb-standalone-no-errors.sh index 6fca19353d..e74b9ab1e1 100755 --- a/t/t9500-gitweb-standalone-no-errors.sh +++ b/t/t9500-gitweb-standalone-no-errors.sh @@ -328,7 +328,7 @@ test_expect_success \ git add b && git commit -a -m "On branch" && git checkout master && - git pull . b && + git merge b && git tag merge_commit' test_expect_success \ @@ -683,9 +683,11 @@ test_expect_success \ # syntax highlighting -highlight --version >/dev/null 2>&1 +highlight_version=$(highlight --version </dev/null 2>/dev/null) if [ $? -eq 127 ]; then - say "Skipping syntax highlighting test, because 'highlight' was not found" + say "Skipping syntax highlighting tests: 'highlight' not found" +elif test -z "$highlight_version"; then + say "Skipping syntax highlighting tests: incorrect 'highlight' found" else test_set_prereq HIGHLIGHT cat >>gitweb_config.perl <<-\EOF diff --git a/t/t9700-perl-git.sh b/t/t9700-perl-git.sh index 435d896476..102c133112 100755 --- a/t/t9700-perl-git.sh +++ b/t/t9700-perl-git.sh @@ -11,7 +11,7 @@ if ! test_have_prereq PERL; then test_done fi -"$PERL_PATH" -MTest::More -e 0 2>/dev/null || { +perl -MTest::More -e 0 2>/dev/null || { skip_all="Perl Test::More unavailable, skipping test" test_done } @@ -55,6 +55,6 @@ test_external_has_tap=1 test_external_without_stderr \ 'Perl API' \ - "$PERL_PATH" "$TEST_DIRECTORY"/t9700/test.pl + perl "$TEST_DIRECTORY"/t9700/test.pl test_done diff --git a/t/t9802-git-p4-filetype.sh b/t/t9802-git-p4-filetype.sh index a82744bab0..66d3fc91a7 100755 --- a/t/t9802-git-p4-filetype.sh +++ b/t/t9802-git-p4-filetype.sh @@ -250,6 +250,89 @@ test_expect_success 'ignore apple' ' ) ' +test_expect_success SYMLINKS 'create p4 symlink' ' + cd "$cli" && + ln -s symlink-target symlink && + p4 add symlink && + p4 submit -d "add symlink" +' + +test_expect_success SYMLINKS 'ensure p4 symlink parsed correctly' ' + test_when_finished cleanup_git && + git p4 clone --dest="$git" //depot@all && + ( + cd "$git" && + test -L symlink && + test $(readlink symlink) = symlink-target + ) +' + +test_expect_success SYMLINKS 'empty symlink target' ' + ( + # first create the file as a file + cd "$cli" && + >empty-symlink && + p4 add empty-symlink && + p4 submit -d "add empty-symlink as a file" + ) && + ( + # now change it to be a symlink to "target1" + cd "$cli" && + p4 edit empty-symlink && + p4 reopen -t symlink empty-symlink && + rm empty-symlink && + ln -s target1 empty-symlink && + p4 add empty-symlink && + p4 submit -d "make empty-symlink point to target1" + ) && + ( + # Hack the p4 depot to make the symlink point to nothing; + # this should not happen in reality, but shows up + # in p4 repos in the wild. + # + # The sed expression changes this: + # @@ + # text + # @target1 + # @ + # to this: + # @@ + # text + # @@ + # + cd "$db/depot" && + sed "/@target1/{; s/target1/@/; n; d; }" \ + empty-symlink,v >empty-symlink,v.tmp && + mv empty-symlink,v.tmp empty-symlink,v + ) && + ( + # Make sure symlink really is empty. Asking + # p4 to sync here will make it generate errors. + cd "$cli" && + p4 print -q //depot/empty-symlink#2 >out && + test ! -s out + ) && + test_when_finished cleanup_git && + + # make sure git p4 handles it without error + git p4 clone --dest="$git" //depot@all && + + # fix the symlink, make it point to "target2" + ( + cd "$cli" && + p4 open empty-symlink && + rm empty-symlink && + ln -s target2 empty-symlink && + p4 submit -d "make empty-symlink point to target2" + ) && + cleanup_git && + git p4 clone --dest="$git" //depot@all && + ( + cd "$git" && + test $(readlink empty-symlink) = target2 + ) +' + test_expect_success 'kill p4d' ' kill_p4d ' diff --git a/t/t9805-git-p4-skip-submit-edit.sh b/t/t9805-git-p4-skip-submit-edit.sh index ff2cc79701..89311886db 100755 --- a/t/t9805-git-p4-skip-submit-edit.sh +++ b/t/t9805-git-p4-skip-submit-edit.sh @@ -17,7 +17,7 @@ test_expect_success 'init depot' ' ) ' -# this works because EDITOR is set to : +# this works because P4EDITOR is set to true test_expect_success 'no config, unedited, say yes' ' git p4 clone --dest="$git" //depot && test_when_finished cleanup_git && @@ -90,7 +90,9 @@ test_expect_success 'no config, edited' ' cd "$git" && echo line >>file1 && git commit -a -m "change 5" && - P4EDITOR="" EDITOR="\"$TRASH_DIRECTORY/ed.sh\"" git p4 submit && + P4EDITOR="$TRASH_DIRECTORY/ed.sh" && + export P4EDITOR && + git p4 submit && p4 changes //depot/... >wc && test_line_count = 5 wc ) diff --git a/t/t9807-git-p4-submit.sh b/t/t9807-git-p4-submit.sh index 1fb7bc7cf9..4caf36e006 100755 --- a/t/t9807-git-p4-submit.sh +++ b/t/t9807-git-p4-submit.sh @@ -17,7 +17,7 @@ test_expect_success 'init depot' ' ) ' -test_expect_failure 'is_cli_file_writeable function' ' +test_expect_success 'is_cli_file_writeable function' ' ( cd "$cli" && echo a >a && diff --git a/t/t9809-git-p4-client-view.sh b/t/t9809-git-p4-client-view.sh index 77f63492d9..23a827fa77 100755 --- a/t/t9809-git-p4-client-view.sh +++ b/t/t9809-git-p4-client-view.sh @@ -76,28 +76,28 @@ test_expect_success 'init depot' ' ' # double % for printf -test_expect_success 'unsupported view wildcard %%n' ' +test_expect_success 'view wildcard %%n' ' client_view "//depot/%%%%1/sub/... //client/sub/%%%%1/..." && test_when_finished cleanup_git && - test_must_fail git p4 clone --use-client-spec --dest="$git" //depot + git p4 clone --use-client-spec --dest="$git" //depot ' -test_expect_success 'unsupported view wildcard *' ' +test_expect_success 'view wildcard *' ' client_view "//depot/*/bar/... //client/*/bar/..." && test_when_finished cleanup_git && - test_must_fail git p4 clone --use-client-spec --dest="$git" //depot + git p4 clone --use-client-spec --dest="$git" //depot ' -test_expect_success 'wildcard ... only supported at end of spec 1' ' +test_expect_success 'wildcard ... in the middle' ' client_view "//depot/.../file11 //client/.../file11" && test_when_finished cleanup_git && - test_must_fail git p4 clone --use-client-spec --dest="$git" //depot + git p4 clone --use-client-spec --dest="$git" //depot ' -test_expect_success 'wildcard ... only supported at end of spec 2' ' +test_expect_success 'wildcard ... in the middle and at the end' ' client_view "//depot/.../a/... //client/.../a/..." && test_when_finished cleanup_git && - test_must_fail git p4 clone --use-client-spec --dest="$git" //depot + git p4 clone --use-client-spec --dest="$git" //depot ' test_expect_success 'basic map' ' diff --git a/t/t9810-git-p4-rcs.sh b/t/t9810-git-p4-rcs.sh index 34fbc90005..8134ab439b 100755 --- a/t/t9810-git-p4-rcs.sh +++ b/t/t9810-git-p4-rcs.sh @@ -263,7 +263,7 @@ test_expect_success 'cope with rcs keyword expansion damage' ' git config git-p4.attemptRCSCleanup true && (cd "$cli" && p4_append_to_file kwfile1.c) && old_lines=$(wc -l <kwfile1.c) && - "$PERL_PATH" -n -i -e "print unless m/Revision:/" kwfile1.c && + perl -n -i -e "print unless m/Revision:/" kwfile1.c && new_lines=$(wc -l <kwfile1.c) && test $new_lines = $(($old_lines - 1)) && diff --git a/t/t9812-git-p4-wildcards.sh b/t/t9812-git-p4-wildcards.sh index 67633257f3..c7472cbf54 100755 --- a/t/t9812-git-p4-wildcards.sh +++ b/t/t9812-git-p4-wildcards.sh @@ -161,6 +161,56 @@ test_expect_success 'wildcard files submit back to p4, delete' ' ) ' +test_expect_success 'p4 deleted a wildcard file' ' + ( + cd "$cli" && + echo "wild delete test" >wild@delete && + p4 add -f wild@delete && + p4 submit -d "add wild@delete" + ) && + test_when_finished cleanup_git && + git p4 clone --dest="$git" //depot && + ( + cd "$git" && + test_path_is_file wild@delete + ) && + ( + cd "$cli" && + # must use its encoded name + p4 delete wild%40delete && + p4 submit -d "delete wild@delete" + ) && + ( + cd "$git" && + git p4 sync && + git merge --ff-only p4/master && + test_path_is_missing wild@delete + ) +' + +test_expect_success 'wildcard files requiring keyword scrub' ' + ( + cd "$cli" && + cat <<-\EOF >scrub@wild && + $Id$ + line2 + EOF + p4 add -t text+k -f scrub@wild && + p4 submit -d "scrub at wild" + ) && + test_when_finished cleanup_git && + git p4 clone --dest="$git" //depot && + ( + cd "$git" && + git config git-p4.skipSubmitEdit true && + git config git-p4.attemptRCSCleanup true && + sed "s/^line2/line2 edit/" <scrub@wild >scrub@wild.tmp && + mv -f scrub@wild.tmp scrub@wild && + git commit -m "scrub at wild line2 edit" scrub@wild && + git p4 submit + ) +' + test_expect_success 'kill p4d' ' kill_p4d ' diff --git a/t/t9813-git-p4-preserve-users.sh b/t/t9813-git-p4-preserve-users.sh index f2e85e518b..166b840bfa 100755 --- a/t/t9813-git-p4-preserve-users.sh +++ b/t/t9813-git-p4-preserve-users.sh @@ -19,16 +19,6 @@ test_expect_success 'create files' ' ) ' -p4_add_user() { - name=$1 fullname=$2 && - p4 user -f -i <<-EOF && - User: $name - Email: $name@localhost - FullName: $fullname - EOF - p4 passwd -P secret $name -} - p4_grant_admin() { name=$1 && { @@ -51,8 +41,8 @@ make_change_by_user() { # Test username support, submitting as user 'alice' test_expect_success 'preserve users' ' - p4_add_user alice Alice && - p4_add_user bob Bob && + p4_add_user alice && + p4_add_user bob && p4_grant_admin alice && git p4 clone --dest="$git" //depot && test_when_finished cleanup_git && @@ -60,8 +50,8 @@ test_expect_success 'preserve users' ' cd "$git" && echo "username: a change by alice" >>file1 && echo "username: a change by bob" >>file2 && - git commit --author "Alice <alice@localhost>" -m "a change by alice" file1 && - git commit --author "Bob <bob@localhost>" -m "a change by bob" file2 && + git commit --author "Alice <alice@example.com>" -m "a change by alice" file1 && + git commit --author "Bob <bob@example.com>" -m "a change by bob" file2 && git config git-p4.skipSubmitEditCheck true && P4EDITOR=touch P4USER=alice P4PASSWD=secret git p4 commit --preserve-user && p4_check_commit_author file1 alice && @@ -78,7 +68,7 @@ test_expect_success 'refuse to preserve users without perms' ' cd "$git" && git config git-p4.skipSubmitEditCheck true && echo "username-noperms: a change by alice" >>file1 && - git commit --author "Alice <alice@localhost>" -m "perms: a change by alice" file1 && + git commit --author "Alice <alice@example.com>" -m "perms: a change by alice" file1 && P4EDITOR=touch P4USER=bob P4PASSWD=secret && export P4EDITOR P4USER P4PASSWD && test_must_fail git p4 commit --preserve-user && @@ -94,9 +84,9 @@ test_expect_success 'preserve user where author is unknown to p4' ' cd "$git" && git config git-p4.skipSubmitEditCheck true && echo "username-bob: a change by bob" >>file1 && - git commit --author "Bob <bob@localhost>" -m "preserve: a change by bob" file1 && + git commit --author "Bob <bob@example.com>" -m "preserve: a change by bob" file1 && echo "username-unknown: a change by charlie" >>file1 && - git commit --author "Charlie <charlie@localhost>" -m "preserve: a change by charlie" file1 && + git commit --author "Charlie <charlie@example.com>" -m "preserve: a change by charlie" file1 && P4EDITOR=touch P4USER=alice P4PASSWD=secret && export P4EDITOR P4USER P4PASSWD && test_must_fail git p4 commit --preserve-user && @@ -121,24 +111,24 @@ test_expect_success 'not preserving user with mixed authorship' ' ( cd "$git" && git config git-p4.skipSubmitEditCheck true && - p4_add_user derek Derek && + p4_add_user derek && - make_change_by_user usernamefile3 Derek derek@localhost && + make_change_by_user usernamefile3 Derek derek@example.com && P4EDITOR=cat P4USER=alice P4PASSWD=secret && export P4EDITOR P4USER P4PASSWD && git p4 commit |\ - grep "git author derek@localhost does not match" && + grep "git author derek@example.com does not match" && - make_change_by_user usernamefile3 Charlie charlie@localhost && + make_change_by_user usernamefile3 Charlie charlie@example.com && git p4 commit |\ - grep "git author charlie@localhost does not match" && + grep "git author charlie@example.com does not match" && - make_change_by_user usernamefile3 alice alice@localhost && + make_change_by_user usernamefile3 alice alice@example.com && git p4 commit |\ test_must_fail grep "git author.*does not match" && git config git-p4.skipUserNameCheck true && - make_change_by_user usernamefile3 Charlie charlie@localhost && + make_change_by_user usernamefile3 Charlie charlie@example.com && git p4 commit |\ test_must_fail grep "git author.*does not match" && diff --git a/t/t9816-git-p4-locked.sh b/t/t9816-git-p4-locked.sh new file mode 100755 index 0000000000..e71e543343 --- /dev/null +++ b/t/t9816-git-p4-locked.sh @@ -0,0 +1,145 @@ +#!/bin/sh + +test_description='git p4 locked file behavior' + +. ./lib-git-p4.sh + +test_expect_success 'start p4d' ' + start_p4d +' + +# See +# http://www.perforce.com/perforce/doc.current/manuals/p4sag/03_superuser.html#1088563 +# for suggestions on how to configure "sitewide pessimistic locking" +# where only one person can have a file open for edit at a time. +test_expect_success 'init depot' ' + ( + cd "$cli" && + echo "TypeMap: +l //depot/..." | p4 typemap -i && + echo file1 >file1 && + p4 add file1 && + p4 submit -d "add file1" + ) +' + +test_expect_success 'edit with lock not taken' ' + test_when_finished cleanup_git && + git p4 clone --dest="$git" //depot && + ( + cd "$git" && + echo line2 >>file1 && + git add file1 && + git commit -m "line2 in file1" && + git config git-p4.skipSubmitEdit true && + git p4 submit + ) +' + +test_expect_failure 'add with lock not taken' ' + test_when_finished cleanup_git && + git p4 clone --dest="$git" //depot && + ( + cd "$git" && + echo line1 >>add-lock-not-taken && + git add file2 && + git commit -m "add add-lock-not-taken" && + git config git-p4.skipSubmitEdit true && + git p4 submit --verbose + ) +' + +lock_in_another_client() { + # build a different client + cli2="$TRASH_DIRECTORY/cli2" && + mkdir -p "$cli2" && + test_when_finished "p4 client -f -d client2 && rm -rf \"$cli2\"" && + ( + cd "$cli2" && + P4CLIENT=client2 && + cli="$cli2" && + client_view "//depot/... //client2/..." && + p4 sync && + p4 open file1 + ) +} + +test_expect_failure 'edit with lock taken' ' + lock_in_another_client && + test_when_finished cleanup_git && + test_when_finished "cd \"$cli\" && p4 sync -f file1" && + git p4 clone --dest="$git" //depot && + ( + cd "$git" && + echo line3 >>file1 && + git add file1 && + git commit -m "line3 in file1" && + git config git-p4.skipSubmitEdit true && + git p4 submit --verbose + ) +' + +test_expect_failure 'delete with lock taken' ' + lock_in_another_client && + test_when_finished cleanup_git && + test_when_finished "cd \"$cli\" && p4 sync -f file1" && + git p4 clone --dest="$git" //depot && + ( + cd "$git" && + git rm file1 && + git commit -m "delete file1" && + git config git-p4.skipSubmitEdit true && + git p4 submit --verbose + ) +' + +test_expect_failure 'chmod with lock taken' ' + lock_in_another_client && + test_when_finished cleanup_git && + test_when_finished "cd \"$cli\" && p4 sync -f file1" && + git p4 clone --dest="$git" //depot && + ( + cd "$git" && + chmod +x file1 && + git add file1 && + git commit -m "chmod +x file1" && + git config git-p4.skipSubmitEdit true && + git p4 submit --verbose + ) +' + +test_expect_failure 'copy with lock taken' ' + lock_in_another_client && + test_when_finished cleanup_git && + test_when_finished "cd \"$cli\" && p4 revert file2 && rm -f file2" && + git p4 clone --dest="$git" //depot && + ( + cd "$git" && + cp file1 file2 && + git add file2 && + git commit -m "cp file1 to file2" && + git config git-p4.skipSubmitEdit true && + git config git-p4.detectCopies true && + git p4 submit --verbose + ) +' + +test_expect_failure 'move with lock taken' ' + lock_in_another_client && + test_when_finished cleanup_git && + test_when_finished "cd \"$cli\" && p4 sync file1 && rm -f file2" && + git p4 clone --dest="$git" //depot && + ( + cd "$git" && + git mv file1 file2 && + git commit -m "mv file1 to file2" && + git config git-p4.skipSubmitEdit true && + git config git-p4.detectRenames true && + git p4 submit --verbose + ) +' + +test_expect_success 'kill p4d' ' + kill_p4d +' + +test_done diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 272a071e85..2d4beb5e50 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -69,7 +69,7 @@ run_completion () local -a COMPREPLY _words local _cword _words=( $1 ) - test "${1: -1}" = ' ' && _words+=('') + test "${1: -1}" = ' ' && _words[${#_words[@]}+1]='' (( _cword = ${#_words[@]} - 1 )) __git_wrap__git_main && print_comp } diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh index 3c3e4e8c38..59f875e830 100755 --- a/t/t9903-bash-prompt.sh +++ b/t/t9903-bash-prompt.sh @@ -61,6 +61,29 @@ test_expect_success 'prompt - unborn branch' ' test_cmp expected "$actual" ' +repo_with_newline='repo +with +newline' + +if mkdir "$repo_with_newline" 2>/dev/null +then + test_set_prereq FUNNYNAMES +else + say 'Your filesystem does not allow newlines in filenames.' +fi + +test_expect_success FUNNYNAMES 'prompt - with newline in path' ' + printf " (master)" >expected && + git init "$repo_with_newline" && + test_when_finished "rm -rf \"$repo_with_newline\"" && + mkdir "$repo_with_newline"/subdir && + ( + cd "$repo_with_newline/subdir" && + __git_ps1 >"$actual" + ) && + test_cmp expected "$actual" +' + test_expect_success 'prompt - detached head' ' printf " ((%s...))" $(git log -1 --format="%h" --abbrev=13 b1^) >expected && test_config core.abbrev 13 && diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index a7e9aacbb2..158e10a67e 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -1,4 +1,5 @@ -#!/bin/sh +# Library of functions shared by all tests scripts, included by +# test-lib.sh. # # Copyright (c) 2005 Junio C Hamano # @@ -31,6 +32,11 @@ test_set_editor () { export EDITOR } +test_set_index_version () { + GIT_INDEX_VERSION="$1" + export GIT_INDEX_VERSION +} + test_decode_color () { awk ' function name(n) { @@ -76,11 +82,11 @@ test_decode_color () { } nul_to_q () { - "$PERL_PATH" -pe 'y/\000/Q/' + perl -pe 'y/\000/Q/' } q_to_nul () { - "$PERL_PATH" -pe 'y/Q/\000/' + perl -pe 'y/Q/\000/' } q_to_cr () { @@ -648,7 +654,7 @@ test_seq () { 2) ;; *) error "bug in the test script: not 1 or 2 parameters to test_seq" ;; esac - "$PERL_PATH" -le 'print for $ARGV[0]..$ARGV[1]' -- "$@" + perl -le 'print for $ARGV[0]..$ARGV[1]' -- "$@" } # This function can be used to schedule some commands to be run @@ -710,3 +716,131 @@ test_ln_s_add () { git update-index --add --cacheinfo 120000 $ln_s_obj "$2" fi } + +perl () { + command "$PERL_PATH" "$@" +} + +# Is the value one of the various ways to spell a boolean true/false? +test_normalize_bool () { + git -c magic.variable="$1" config --bool magic.variable 2>/dev/null +} + +# Given a variable $1, normalize the value of it to one of "true", +# "false", or "auto" and store the result to it. +# +# test_tristate GIT_TEST_HTTPD +# +# A variable set to an empty string is set to 'false'. +# A variable set to 'false' or 'auto' keeps its value. +# Anything else is set to 'true'. +# An unset variable defaults to 'auto'. +# +# The last rule is to allow people to set the variable to an empty +# string and export it to decline testing the particular feature +# for versions both before and after this change. We used to treat +# both unset and empty variable as a signal for "do not test" and +# took any non-empty string as "please test". + +test_tristate () { + if eval "test x\"\${$1+isset}\" = xisset" + then + # explicitly set + eval " + case \"\$$1\" in + '') $1=false ;; + auto) ;; + *) $1=\$(test_normalize_bool \$$1 || echo true) ;; + esac + " + else + eval "$1=auto" + fi +} + +# Exit the test suite, either by skipping all remaining tests or by +# exiting with an error. If "$1" is "auto", we then we assume we were +# opportunistically trying to set up some tests and we skip. If it is +# "true", then we report a failure. +# +# The error/skip message should be given by $2. +# +test_skip_or_die () { + case "$1" in + auto) + skip_all=$2 + test_done + ;; + true) + error "$2" + ;; + *) + error "BUG: test tristate is '$1' (real error: $2)" + esac +} + +# The following mingw_* functions obey POSIX shell syntax, but are actually +# bash scripts, and are meant to be used only with bash on Windows. + +# A test_cmp function that treats LF and CRLF equal and avoids to fork +# diff when possible. +mingw_test_cmp () { + # Read text into shell variables and compare them. If the results + # are different, use regular diff to report the difference. + local test_cmp_a= test_cmp_b= + + # When text came from stdin (one argument is '-') we must feed it + # to diff. + local stdin_for_diff= + + # Since it is difficult to detect the difference between an + # empty input file and a failure to read the files, we go straight + # to diff if one of the inputs is empty. + if test -s "$1" && test -s "$2" + then + # regular case: both files non-empty + mingw_read_file_strip_cr_ test_cmp_a <"$1" + mingw_read_file_strip_cr_ test_cmp_b <"$2" + elif test -s "$1" && test "$2" = - + then + # read 2nd file from stdin + mingw_read_file_strip_cr_ test_cmp_a <"$1" + mingw_read_file_strip_cr_ test_cmp_b + stdin_for_diff='<<<"$test_cmp_b"' + elif test "$1" = - && test -s "$2" + then + # read 1st file from stdin + mingw_read_file_strip_cr_ test_cmp_a + mingw_read_file_strip_cr_ test_cmp_b <"$2" + stdin_for_diff='<<<"$test_cmp_a"' + fi + test -n "$test_cmp_a" && + test -n "$test_cmp_b" && + test "$test_cmp_a" = "$test_cmp_b" || + eval "diff -u \"\$@\" $stdin_for_diff" +} + +# $1 is the name of the shell variable to fill in +mingw_read_file_strip_cr_ () { + # Read line-wise using LF as the line separator + # and use IFS to strip CR. + local line + while : + do + if IFS=$'\r' read -r -d $'\n' line + then + # good + line=$line$'\n' + else + # we get here at EOF, but also if the last line + # was not terminated by LF; in the latter case, + # some text was read + if test -z "$line" + then + # EOF, really + break + fi + fi + eval "$1=\$$1\$line" + done +} diff --git a/t/test-lib.sh b/t/test-lib.sh index 1aa27bdbbf..87f327ff8b 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -1,4 +1,4 @@ -#!/bin/sh +# Test framework for git. See t/README for usage. # # Copyright (c) 2005 Junio C Hamano # @@ -26,6 +26,10 @@ then # outside of t/, e.g. for running tests on the test library # itself. TEST_DIRECTORY=$(pwd) +else + # ensure that TEST_DIRECTORY is an absolute path so that it + # is valid even if the current working directory is changed + TEST_DIRECTORY=$(cd "$TEST_DIRECTORY" && pwd) || exit 1 fi if test -z "$TEST_OUTPUT_DIRECTORY" then @@ -104,6 +108,12 @@ export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME export EDITOR +if test -n "${TEST_GIT_INDEX_VERSION:+isset}" +then + GIT_INDEX_VERSION="$TEST_GIT_INDEX_VERSION" + export GIT_INDEX_VERSION +fi + # Add libc MALLOC and MALLOC_PERTURB test # only if we are not executing the test with valgrind if expr " $GIT_TEST_OPTS " : ".* --valgrind " >/dev/null || @@ -205,29 +215,17 @@ do --valgrind-only=*) valgrind_only=$(expr "z$1" : 'z[^=]*=\(.*\)') shift ;; - --valgrind-parallel=*) - valgrind_parallel=$(expr "z$1" : 'z[^=]*=\(.*\)') - shift ;; - --valgrind-only-stride=*) - valgrind_only_stride=$(expr "z$1" : 'z[^=]*=\(.*\)') - shift ;; - --valgrind-only-offset=*) - valgrind_only_offset=$(expr "z$1" : 'z[^=]*=\(.*\)') - shift ;; --tee) shift ;; # was handled already --root=*) root=$(expr "z$1" : 'z[^=]*=\(.*\)') shift ;; - --statusprefix=*) - statusprefix=$(expr "z$1" : 'z[^=]*=\(.*\)') - shift ;; *) echo "error: unknown test option '$1'" >&2; exit 1 ;; esac done -if test -n "$valgrind_only" || test -n "$valgrind_only_stride" +if test -n "$valgrind_only" then test -z "$valgrind" && valgrind=memcheck test -z "$verbose" && verbose_only="$valgrind_only" @@ -285,7 +283,7 @@ error "Test script did not set test_description." if test "$help" = "t" then - echo "$test_description" + printf '%s\n' "$test_description" exit 0 fi @@ -325,29 +323,29 @@ trap 'die' EXIT . "$TEST_DIRECTORY/test-lib-functions.sh" # You are not expected to call test_ok_ and test_failure_ directly, use -# the text_expect_* functions instead. +# the test_expect_* functions instead. test_ok_ () { test_success=$(($test_success + 1)) - say_color "" "${statusprefix}ok $test_count - $@" + say_color "" "ok $test_count - $@" } test_failure_ () { test_failure=$(($test_failure + 1)) - say_color error "${statusprefix}not ok $test_count - $1" + say_color error "not ok $test_count - $1" shift - echo "$@" | sed -e 's/^/# /' + printf '%s\n' "$*" | sed -e 's/^/# /' test "$immediate" = "" || { GIT_EXIT_OK=t; exit 1; } } test_known_broken_ok_ () { test_fixed=$(($test_fixed+1)) - say_color error "${statusprefix}ok $test_count - $@ # TODO known breakage vanished" + say_color error "ok $test_count - $@ # TODO known breakage vanished" } test_known_broken_failure_ () { test_broken=$(($test_broken+1)) - say_color warn "${statusprefix}not ok $test_count - $@ # TODO known breakage" + say_color warn "not ok $test_count - $@ # TODO known breakage" } test_debug () { @@ -377,9 +375,7 @@ maybe_teardown_verbose () { last_verbose=t maybe_setup_verbose () { test -z "$verbose_only" && return - if match_pattern_list $test_count $verbose_only || - { test -n "$valgrind_only_stride" && - expr $test_count "%" $valgrind_only_stride - $valgrind_only_offset = 0 >/dev/null; } + if match_pattern_list $test_count $verbose_only then exec 4>&2 3>&1 # Emit a delimiting blank line when going from @@ -403,7 +399,7 @@ maybe_teardown_valgrind () { maybe_setup_valgrind () { test -z "$GIT_VALGRIND" && return - if test -z "$valgrind_only" && test -z "$valgrind_only_stride" + if test -z "$valgrind_only" then GIT_VALGRIND_ENABLED=t return @@ -412,10 +408,6 @@ maybe_setup_valgrind () { if match_pattern_list $test_count $valgrind_only then GIT_VALGRIND_ENABLED=t - elif test -n "$valgrind_only_stride" && - expr $test_count "%" $valgrind_only_stride - $valgrind_only_offset = 0 >/dev/null - then - GIT_VALGRIND_ENABLED=t fi } @@ -477,8 +469,8 @@ test_skip () { of_prereq=" of $test_prereq" fi - say_color skip >&3 "${statusprefix}skipping test: $@" - say_color skip "${statusprefix}ok $test_count # skip $1 (missing $missing_prereq${of_prereq})" + say_color skip >&3 "skipping test: $@" + say_color skip "ok $test_count # skip $1 (missing $missing_prereq${of_prereq})" : true ;; *) @@ -495,8 +487,6 @@ test_at_end_hook_ () { test_done () { GIT_EXIT_OK=t - # Note: t0000 relies on $HARNESS_ACTIVE disabling the .counts - # output file if test -z "$HARNESS_ACTIVE" then test_results_dir="$TEST_OUTPUT_DIRECTORY/test-results" @@ -516,11 +506,11 @@ test_done () { if test "$test_fixed" != 0 then - say_color error "${statusprefix}# $test_fixed known breakage(s) vanished; please update test(s)" + say_color error "# $test_fixed known breakage(s) vanished; please update test(s)" fi if test "$test_broken" != 0 then - say_color warn "${statusprefix}# still have $test_broken known breakage(s)" + say_color warn "# still have $test_broken known breakage(s)" fi if test "$test_broken" != 0 || test "$test_fixed" != 0 then @@ -543,9 +533,9 @@ test_done () { then if test $test_remaining -gt 0 then - say_color pass "${statusprefix}# passed all $msg" + say_color pass "# passed all $msg" fi - say "${statusprefix}1..$test_count$skip_all" + say "1..$test_count$skip_all" fi test -d "$remove_trash" && @@ -559,8 +549,8 @@ test_done () { *) if test $test_external_has_tap -eq 0 then - say_color error "${statusprefix}# failed $test_failure among $msg" - say "${statusprefix}1..$test_count" + say_color error "# failed $test_failure among $msg" + say "1..$test_count" fi exit 1 ;; @@ -568,9 +558,6 @@ test_done () { esac } - -# Set up a directory that we can put in PATH which redirects all git -# calls to 'valgrind git ...'. if test -n "$valgrind" then make_symlink () { @@ -594,11 +581,9 @@ then make_valgrind_symlink () { # handle only executables, unless they are shell libraries that - # need to be in the exec-path. We will just use "#!" as a - # guess for a shell-script, since we have no idea what the user - # may have configured as the shell path. + # need to be in the exec-path. test -x "$1" || - test "#!" = "$(head -c 2 <"$1")" || + test "# " = "$(head -c 2 <"$1")" || return; base=$(basename "$1") @@ -618,42 +603,33 @@ then make_symlink "$symlink_target" "$GIT_VALGRIND/bin/$base" || exit } - # In the case of --valgrind-parallel, we only need to do the - # wrapping once, in the main script. The worker children all - # have $valgrind_only_stride set, so we can skip based on that. - if test -z "$valgrind_only_stride" - then - # override all git executables in TEST_DIRECTORY/.. - GIT_VALGRIND=$TEST_DIRECTORY/valgrind - mkdir -p "$GIT_VALGRIND"/bin - for file in $GIT_BUILD_DIR/git* $GIT_BUILD_DIR/test-* - do - make_valgrind_symlink $file - done - # special-case the mergetools loadables - make_symlink "$GIT_BUILD_DIR"/mergetools "$GIT_VALGRIND/bin/mergetools" - OLDIFS=$IFS - IFS=: - for path in $PATH + # override all git executables in TEST_DIRECTORY/.. + GIT_VALGRIND=$TEST_DIRECTORY/valgrind + mkdir -p "$GIT_VALGRIND"/bin + for file in $GIT_BUILD_DIR/git* $GIT_BUILD_DIR/test-* + do + make_valgrind_symlink $file + done + # special-case the mergetools loadables + make_symlink "$GIT_BUILD_DIR"/mergetools "$GIT_VALGRIND/bin/mergetools" + OLDIFS=$IFS + IFS=: + for path in $PATH + do + ls "$path"/git-* 2> /dev/null | + while read file do - ls "$path"/git-* 2> /dev/null | - while read file - do - make_valgrind_symlink "$file" - done + make_valgrind_symlink "$file" done - IFS=$OLDIFS - fi + done + IFS=$OLDIFS PATH=$GIT_VALGRIND/bin:$PATH GIT_EXEC_PATH=$GIT_VALGRIND/bin export GIT_VALGRIND GIT_VALGRIND_MODE="$valgrind" export GIT_VALGRIND_MODE GIT_VALGRIND_ENABLED=t - if test -n "$valgrind_only" || test -n "$valgrind_only_stride" - then - GIT_VALGRIND_ENABLED= - fi + test -n "$valgrind_only" && GIT_VALGRIND_ENABLED= export GIT_VALGRIND_ENABLED elif test -n "$GIT_TEST_INSTALLED" then @@ -700,15 +676,6 @@ test -d "$GIT_BUILD_DIR"/templates/blt || { error "You haven't built things yet, have you?" } -if test -z "$GIT_TEST_INSTALLED" && test -z "$NO_PYTHON" -then - GITPYTHONLIB="$GIT_BUILD_DIR/git_remote_helpers/build/lib" - export GITPYTHONLIB - test -d "$GIT_BUILD_DIR"/git_remote_helpers/build || { - error "You haven't built git_remote_helpers yet, have you?" - } -fi - if ! test -x "$GIT_BUILD_DIR"/test-chmtime then echo >&2 'You need to build test-chmtime:' @@ -739,41 +706,6 @@ then else mkdir -p "$TRASH_DIRECTORY" fi - -# Gross hack to spawn N sub-instances of the tests in parallel, and -# summarize the results. Note that if this is enabled, the script -# terminates at the end of this 'if' block. -if test -n "$valgrind_parallel" -then - for i in $(test_seq 1 $valgrind_parallel) - do - root="$TRASH_DIRECTORY/vgparallel-$i" - mkdir "$root" - TEST_OUTPUT_DIRECTORY="$root" \ - ${SHELL_PATH} "$0" \ - --root="$root" --statusprefix="[$i] " \ - --valgrind="$valgrind" \ - --valgrind-only-stride="$valgrind_parallel" \ - --valgrind-only-offset="$i" & - pids="$pids $!" - done - trap "kill $pids" INT TERM HUP - wait $pids - trap - INT TERM HUP - for i in $(test_seq 1 $valgrind_parallel) - do - root="$TRASH_DIRECTORY/vgparallel-$i" - eval "$(cat "$root/test-results/$(basename "$0" .sh)"-*.counts | - sed 's/^\([a-z][a-z]*\) \([0-9][0-9]*\)/inner_\1=\2/')" - test_count=$(expr $test_count + $inner_total) - test_success=$(expr $test_success + $inner_success) - test_fixed=$(expr $test_fixed + $inner_fixed) - test_broken=$(expr $test_broken + $inner_broken) - test_failure=$(expr $test_failure + $inner_failed) - done - test_done -fi - # Use -P to resolve symlinks in our working directory so that the cwd # in subprocesses like git equals our $PWD (for pathname comparisons). cd -P "$TRASH_DIRECTORY" || exit 1 @@ -826,6 +758,7 @@ case $(uname -s) in test_set_prereq NOT_CYGWIN test_set_prereq SED_STRIPS_CR test_set_prereq GREP_STRIPS_CR + GIT_TEST_CMP=mingw_test_cmp ;; *CYGWIN*) test_set_prereq POSIXPERM @@ -903,6 +836,10 @@ test_lazy_prereq SYMLINKS ' ln -s x y && test -h y ' +test_lazy_prereq FILEMODE ' + test "$(git config --bool core.filemode)" = true +' + test_lazy_prereq CASE_INSENSITIVE_FS ' echo good >CamelCase && echo bad >camelcase && |