diff options
Diffstat (limited to 't')
317 files changed, 12094 insertions, 1867 deletions
diff --git a/t/Makefile b/t/Makefile index c7baefb7ea..47cbeb6e68 100644 --- a/t/Makefile +++ b/t/Makefile @@ -11,16 +11,25 @@ SHELL_PATH ?= $(SHELL) PERL_PATH ?= /usr/bin/perl TAR ?= $(TAR) RM ?= rm -f +PROVE ?= prove +DEFAULT_TEST_TARGET ?= test # Shell quote; SHELL_PATH_SQ = $(subst ','\'',$(SHELL_PATH)) T = $(wildcard t[0-9][0-9][0-9][0-9]-*.sh) TSVN = $(wildcard t91[0-9][0-9]-*.sh) +TGITWEB = $(wildcard t95[0-9][0-9]-*.sh) -all: pre-clean +all: $(DEFAULT_TEST_TARGET) + +test: pre-clean $(TEST_LINT) $(MAKE) aggregate-results-and-cleanup +prove: pre-clean $(TEST_LINT) + @echo "*** prove ***"; GIT_CONFIG=.git/config $(PROVE) --exec '$(SHELL_PATH_SQ)' $(GIT_PROVE_OPTS) $(T) :: $(GIT_TEST_OPTS) + $(MAKE) clean + $(T): @echo "*** $@ ***"; GIT_CONFIG=.git/config '$(SHELL_PATH_SQ)' $@ $(GIT_TEST_OPTS) @@ -32,6 +41,18 @@ clean: $(RM) -r valgrind/bin $(RM) .prove +test-lint: test-lint-duplicates test-lint-executable + +test-lint-duplicates: + @dups=`echo $(T) | tr ' ' '\n' | sed 's/-.*//' | sort | uniq -d` && \ + test -z "$$dups" || { \ + echo >&2 "duplicate test numbers:" $$dups; exit 1; } + +test-lint-executable: + @bad=`for i in $(T); do test -x "$$i" || echo $$i; done` && \ + test -z "$$bad" || { \ + echo >&2 "non-executable tests:" $$bad; exit 1; } + aggregate-results-and-cleanup: $(T) $(MAKE) aggregate-results $(MAKE) clean @@ -46,6 +67,9 @@ full-svn-test: $(MAKE) $(TSVN) GIT_SVN_NO_OPTIMIZE_COMMITS=1 LC_ALL=C $(MAKE) $(TSVN) GIT_SVN_NO_OPTIMIZE_COMMITS=0 LC_ALL=en_US.UTF-8 +gitweb-test: + $(MAKE) $(TGITWEB) + valgrind: GIT_TEST_OPTS=--valgrind $(MAKE) @@ -50,6 +50,12 @@ prove and other harnesses come with a lot of useful options. The # Repeat until no more failures $ prove -j 15 --state=failed,save ./t[0-9]*.sh +You can give DEFAULT_TEST_TARGET=prove on the make command (or define it +in config.mak) to cause "make test" to run tests under prove. +GIT_PROVE_OPTS can be used to pass additional options, e.g. + + $ make DEFAULT_TEST_TARGET=prove GIT_PROVE_OPTS='--timer --jobs 16' test + You can also run each test individually from command line, like this: $ sh ./t3010-ls-files-killed-modified.sh @@ -73,6 +79,10 @@ appropriately before running "make". --debug:: This may help the person who is developing a new test. It causes the command defined with test_debug to run. + The "trash" directory (used to store all temporary data + during testing) is not deleted even if there are no + failed tests so that you can inspect its contents after + the test finished. --immediate:: This causes the test to immediately exit upon the first @@ -92,6 +102,13 @@ appropriately before running "make". not see any output, this option implies --verbose. For convenience, it also implies --tee. + Note that valgrind is run with the option --leak-check=no, + as the git process is short-lived and some errors are not + interesting. In order to run a single command under the same + conditions manually, you should set GIT_VALGRIND to point to + the 't/valgrind/' directory and use the commands under + 't/valgrind/bin/'. + --tee:: In addition to printing the test output to the terminal, write it to files named 't/test-results/$TEST_NAME.out'. @@ -184,7 +201,7 @@ we are testing. If you create files under t/ directory (i.e. here) that is not the top-level test script, never name the file to match the above pattern. The Makefile here considers all such files as the -top-level test script and tries to run all of them. A care is +top-level test script and tries to run all of them. Care is especially needed if you are creating a common test library file, similar to test-lib.sh, because such a library file may not be suitable for standalone execution. @@ -259,27 +276,29 @@ Do: test ... That way all of the commands in your tests will succeed or fail. If - you must ignore the return value of something (e.g., the return - after unsetting a variable that was already unset is unportable) it's - best to indicate so explicitly with a semicolon: - - unset HLAGH; - git merge hla && - git push gh && - test ... + you must ignore the return value of something, consider using a + helper function (e.g. use sane_unset instead of unset, in order + to avoid unportable return value for unsetting a variable that was + already unset), or prepending the command with test_might_fail or + test_must_fail. - Check the test coverage for your tests. See the "Test coverage" below. - Don't blindly follow test coverage metrics, they're a good way to - spot if you've missed something. If a new function you added - doesn't have any coverage you're probably doing something wrong, + Don't blindly follow test coverage metrics; if a new function you added + doesn't have any coverage, then you're probably doing something wrong, but having 100% coverage doesn't necessarily mean that you tested everything. Tests that are likely to smoke out future regressions are better than tests that just inflate the coverage metrics. + - When a test checks for an absolute path that a git command generated, + construct the expected value using $(pwd) rather than $PWD, + $TEST_DIRECTORY, or $TRASH_DIRECTORY. It makes a difference on + Windows, where the shell (MSYS bash) mangles absolute path names. + For details, see the commit message of 4114156ae9. + Don't: - exit() within a <script> part. @@ -319,7 +338,7 @@ Keep in mind: Skipping tests -------------- -If you need to skip tests you should do so be using the three-arg form +If you need to skip tests you should do so by using the three-arg form of the test_* functions (see the "Test harness library" section below), e.g.: @@ -395,13 +414,6 @@ library for your script to use. Like test_expect_success this function can optionally use a three argument invocation with a prerequisite as the first argument. - - test_expect_code [<prereq>] <code> <message> <script> - - Analogous to test_expect_success, but pass the test if it exits - with a given exit <code> - - test_expect_code 1 'Merge with d/f conflicts' 'git merge "merge msg" B master' - - test_debug <script> This takes a single argument, <script>, and evaluates it only @@ -418,7 +430,7 @@ library for your script to use. - test_tick Make commit and tag names consistent by setting the author and - committer times to defined stated. Subsequent calls will + committer times to defined state. Subsequent calls will advance the times by a fixed amount. - test_commit <message> [<filename> [<contents>]] @@ -482,6 +494,15 @@ library for your script to use. 'Perl API' \ "$PERL_PATH" "$TEST_DIRECTORY"/t9700/test.pl + - test_expect_code <exit-code> <command> + + Run a command and ensure that it exits with the given exit code. + For example: + + test_expect_success 'Merge with d/f conflicts' ' + test_expect_code 1 git merge "merge msg" B master + ' + - test_must_fail <git-command> Run a git command and ensure it fails in a controlled way. Use @@ -501,6 +522,10 @@ library for your script to use. <expected> file. This behaves like "cmp" but produces more helpful output when the test is run with "-v" option. + - test_line_count (= | -lt | -ge | ...) <length> <file> + + Check whether a file has the length it is expected to. + - test_path_is_file <file> [<diagnosis>] test_path_is_dir <dir> [<diagnosis>] test_path_is_missing <path> [<diagnosis>] diff --git a/t/annotate-tests.sh b/t/annotate-tests.sh index 396b9653a3..d34208cc27 100644 --- a/t/annotate-tests.sh +++ b/t/annotate-tests.sh @@ -8,27 +8,27 @@ check_count () { $PROG file $head >.result || return 1 cat .result | perl -e ' my %expect = (@ARGV); - my %count = (); + my %count = map { $_ => 0 } keys %expect; while (<STDIN>) { if (/^[0-9a-f]+\t\(([^\t]+)\t/) { my $author = $1; for ($author) { s/^\s*//; s/\s*$//; } - if (exists $expect{$author}) { - $count{$author}++; - } + $count{$author}++; } } my $bad = 0; while (my ($author, $count) = each %count) { my $ok; - if ($expect{$author} != $count) { + my $value = 0; + $value = $expect{$author} if defined $expect{$author}; + if ($value != $count) { $bad = 1; $ok = "bad"; } else { $ok = "good"; } - print STDERR "Author $author (expected $expect{$author}, attributed $count) $ok\n"; + print STDERR "Author $author (expected $value, attributed $count) $ok\n"; } exit($bad); ' "$@" @@ -38,8 +38,8 @@ test_expect_success \ 'prepare reference tree' \ 'echo "1A quick brown fox jumps over the" >file && echo "lazy dog" >>file && - git add file - GIT_AUTHOR_NAME="A" git commit -a -m "Initial."' + git add file && + GIT_AUTHOR_NAME="A" GIT_AUTHOR_EMAIL="A@test.git" git commit -a -m "Initial."' test_expect_success \ 'check all lines blamed on A' \ @@ -49,7 +49,7 @@ test_expect_success \ 'Setup new lines blamed on B' \ 'echo "2A quick brown fox jumps over the" >>file && echo "lazy dog" >> file && - GIT_AUTHOR_NAME="B" git commit -a -m "Second."' + GIT_AUTHOR_NAME="B" GIT_AUTHOR_EMAIL="B@test.git" git commit -a -m "Second."' test_expect_success \ 'Two lines blamed on A, two on B' \ @@ -60,7 +60,7 @@ test_expect_success \ 'git checkout -b branch1 master && echo "3A slow green fox jumps into the" >> file && echo "well." >> file && - GIT_AUTHOR_NAME="B1" git commit -a -m "Branch1-1"' + GIT_AUTHOR_NAME="B1" GIT_AUTHOR_EMAIL="B1@test.git" git commit -a -m "Branch1-1"' test_expect_success \ 'Two lines blamed on A, two on B, two on B1' \ @@ -71,7 +71,7 @@ test_expect_success \ 'git checkout -b branch2 master && sed -e "s/2A quick brown/4A quick brown lazy dog/" < file > file.new && mv file.new file && - GIT_AUTHOR_NAME="B2" git commit -a -m "Branch2-1"' + GIT_AUTHOR_NAME="B2" GIT_AUTHOR_EMAIL="B2@test.git" git commit -a -m "Branch2-1"' test_expect_success \ 'Two lines blamed on A, one on B, one on B2' \ @@ -105,7 +105,7 @@ test_expect_success \ test_expect_success \ 'an incomplete line added' \ 'echo "incomplete" | tr -d "\\012" >>file && - GIT_AUTHOR_NAME="C" git commit -a -m "Incomplete"' + GIT_AUTHOR_NAME="C" GIT_AUTHOR_EMAIL="C@test.git" git commit -a -m "Incomplete"' test_expect_success \ 'With incomplete lines.' \ @@ -119,7 +119,7 @@ test_expect_success \ echo } | sed -e "s/^3A/99/" -e "/^1A/d" -e "/^incomplete/d" > file && echo "incomplete" | tr -d "\\012" >>file && - GIT_AUTHOR_NAME="D" git commit -a -m "edit"' + GIT_AUTHOR_NAME="D" GIT_AUTHOR_EMAIL="D@test.git" git commit -a -m "edit"' test_expect_success \ 'some edit' \ diff --git a/t/gitweb-lib.sh b/t/gitweb-lib.sh index 81ef2a0969..143eb1f240 100644 --- a/t/gitweb-lib.sh +++ b/t/gitweb-lib.sh @@ -19,9 +19,9 @@ our \$site_name = '[localhost]'; our \$site_header = ''; our \$site_footer = ''; our \$home_text = 'indextext.html'; -our @stylesheets = ('file:///$TEST_DIRECTORY/../gitweb/static/gitweb.css'); -our \$logo = 'file:///$TEST_DIRECTORY/../gitweb/static/git-logo.png'; -our \$favicon = 'file:///$TEST_DIRECTORY/../gitweb/static/git-favicon.png'; +our @stylesheets = ('file:///$GIT_BUILD_DIR/gitweb/static/gitweb.css'); +our \$logo = 'file:///$GIT_BUILD_DIR/gitweb/static/git-logo.png'; +our \$favicon = 'file:///$GIT_BUILD_DIR/gitweb/static/git-favicon.png'; our \$projects_list = ''; our \$export_ok = ''; our \$strict_export = ''; @@ -32,17 +32,34 @@ EOF cat >.git/description <<EOF $0 test repository EOF + + # You can set the GITWEB_TEST_INSTALLED environment variable to + # the gitwebdir (the directory where gitweb is installed / deployed to) + # of an existing gitweb instalation to test that installation, + # or simply to pathname of installed gitweb script. + if test -n "$GITWEB_TEST_INSTALLED" ; then + if test -d $GITWEB_TEST_INSTALLED; then + SCRIPT_NAME="$GITWEB_TEST_INSTALLED/gitweb.cgi" + else + SCRIPT_NAME="$GITWEB_TEST_INSTALLED" + fi + test -f "$SCRIPT_NAME" || + error "Cannot find gitweb at $GITWEB_TEST_INSTALLED." + say "# Testing $SCRIPT_NAME" + else # normal case, use source version of gitweb + SCRIPT_NAME="$GIT_BUILD_DIR/gitweb/gitweb.perl" + fi + export SCRIPT_NAME } gitweb_run () { GATEWAY_INTERFACE='CGI/1.1' HTTP_ACCEPT='*/*' REQUEST_METHOD='GET' - SCRIPT_NAME="$TEST_DIRECTORY/../gitweb/gitweb.perl" QUERY_STRING=""$1"" PATH_INFO=""$2"" export GATEWAY_INTERFACE HTTP_ACCEPT REQUEST_METHOD \ - SCRIPT_NAME QUERY_STRING PATH_INFO + QUERY_STRING PATH_INFO GITWEB_CONFIG=$(pwd)/gitweb_config.perl export GITWEB_CONFIG @@ -65,7 +82,12 @@ gitweb_run () { } close O; ' gitweb.output && - if grep '^[[]' gitweb.log >/dev/null 2>&1; then false; else true; fi + if grep '^[[]' gitweb.log >/dev/null 2>&1; then + test_debug 'cat gitweb.log >&2' && + false + else + true + fi # gitweb.log is left for debugging # gitweb.output is used to parse HTTP output @@ -80,9 +102,9 @@ if ! test_have_prereq PERL; then test_done fi -perl -MEncode -e 'decode_utf8("", Encode::FB_CROAK)' >/dev/null 2>&1 || { - skip_all='skipping gitweb tests, perl version is too old' - test_done +perl -MEncode -e '$e="";decode_utf8($e, Encode::FB_CROAK)' >/dev/null 2>&1 || { + skip_all='skipping gitweb tests, perl version is too old' + test_done } gitweb_init diff --git a/t/lib-git-svn.sh b/t/lib-git-svn.sh index 92d6d31942..199f22c231 100644 --- a/t/lib-git-svn.sh +++ b/t/lib-git-svn.sh @@ -68,41 +68,46 @@ svn_cmd () { svn "$orig_svncmd" --config-dir "$svnconf" "$@" } -for d in \ - "$SVN_HTTPD_PATH" \ - /usr/sbin/apache2 \ - /usr/sbin/httpd \ -; do - if test -f "$d" +prepare_httpd () { + for d in \ + "$SVN_HTTPD_PATH" \ + /usr/sbin/apache2 \ + /usr/sbin/httpd \ + ; do + if test -f "$d" + then + SVN_HTTPD_PATH="$d" + break + fi + done + if test -z "$SVN_HTTPD_PATH" then - SVN_HTTPD_PATH="$d" - break + echo >&2 '*** error: Apache not found' + return 1 fi -done -for d in \ - "$SVN_HTTPD_MODULE_PATH" \ - /usr/lib/apache2/modules \ - /usr/libexec/apache2 \ -; do - if test -d "$d" + for d in \ + "$SVN_HTTPD_MODULE_PATH" \ + /usr/lib/apache2/modules \ + /usr/libexec/apache2 \ + ; do + if test -d "$d" + then + SVN_HTTPD_MODULE_PATH="$d" + break + fi + done + if test -z "$SVN_HTTPD_MODULE_PATH" then - SVN_HTTPD_MODULE_PATH="$d" - break + echo >&2 '*** error: Apache module dir not found' + return 1 fi -done - -start_httpd () { - repo_base_path="$1" - if test -z "$SVN_HTTPD_PORT" + if test ! -f "$SVN_HTTPD_MODULE_PATH/mod_dav_svn.so" then - echo >&2 'SVN_HTTPD_PORT is not defined!' - return - fi - if test -z "$repo_base_path" - then - repo_base_path=svn + echo >&2 '*** error: Apache module "mod_dav_svn" not found' + return 1 fi + repo_base_path="${1-svn}" mkdir "$GIT_DIR"/logs cat > "$GIT_DIR/httpd.conf" <<EOF @@ -119,12 +124,24 @@ LoadModule dav_svn_module $SVN_HTTPD_MODULE_PATH/mod_dav_svn.so SVNPath "$rawsvnrepo" </Location> EOF +} + +start_httpd () { + if test -z "$SVN_HTTPD_PORT" + then + echo >&2 'SVN_HTTPD_PORT is not defined!' + return + fi + + prepare_httpd "$1" || return 1 + "$SVN_HTTPD_PATH" -f "$GIT_DIR"/httpd.conf -k start svnrepo="http://127.0.0.1:$SVN_HTTPD_PORT/$repo_base_path" } stop_httpd () { test -z "$SVN_HTTPD_PORT" && return + test ! -f "$GIT_DIR/httpd.conf" && return "$SVN_HTTPD_PATH" -f "$GIT_DIR"/httpd.conf -k stop } diff --git a/t/lib-httpd.sh b/t/lib-httpd.sh index e733f6516f..d3829b8d0a 100644 --- a/t/lib-httpd.sh +++ b/t/lib-httpd.sh @@ -75,12 +75,14 @@ fi prepare_httpd() { mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH" + cp "$TEST_PATH"/passwd "$HTTPD_ROOT_PATH" ln -s "$LIB_HTTPD_MODULE_PATH" "$HTTPD_ROOT_PATH/modules" if test -n "$LIB_HTTPD_SSL" then HTTPD_URL=https://127.0.0.1:$LIB_HTTPD_PORT + AUTH_HTTPD_URL=https://user%40host:user%40host@127.0.0.1:$LIB_HTTPD_PORT RANDFILE_PATH="$HTTPD_ROOT_PATH"/.rnd openssl req \ -config "$TEST_PATH/ssl.cnf" \ @@ -92,6 +94,7 @@ prepare_httpd() { HTTPD_PARA="$HTTPD_PARA -DSSL" else HTTPD_URL=http://127.0.0.1:$LIB_HTTPD_PORT + AUTH_HTTPD_URL=http://user%40host:user%40host@127.0.0.1:$LIB_HTTPD_PORT fi if test -n "$LIB_HTTPD_DAV" -o -n "$LIB_HTTPD_SVN" @@ -154,7 +157,7 @@ test_http_push_nonff() { grep "^ ! \[rejected\][ ]*$BRANCH -> $BRANCH (non-fast-forward)$" output ' - test_expect_success 'non-fast-forward push shows help message' ' + test_expect_success C_LOCALE_OUTPUT 'non-fast-forward push shows help message' ' grep "To prevent you from losing history, non-fast-forward updates were rejected" \ output ' diff --git a/t/lib-httpd/apache.conf b/t/lib-httpd/apache.conf index 4961505d1d..0a4cdfa93e 100644 --- a/t/lib-httpd/apache.conf +++ b/t/lib-httpd/apache.conf @@ -17,8 +17,33 @@ ErrorLog error.log <IfModule !mod_env.c> LoadModule env_module modules/mod_env.so </IfModule> +<IfModule !mod_rewrite.c> + LoadModule rewrite_module modules/mod_rewrite.so +</IFModule> +<IfModule !mod_version.c> + LoadModule version_module modules/mod_version.so +</IfModule> + +<IfVersion < 2.1> +<IfModule !mod_auth.c> + LoadModule auth_module modules/mod_auth.so +</IfModule> +</IfVersion> + +<IfVersion >= 2.1> +<IfModule !mod_auth_basic.c> + LoadModule auth_basic_module modules/mod_auth_basic.so +</IfModule> +<IfModule !mod_authn_file.c> + LoadModule authn_file_module modules/mod_authn_file.so +</IfModule> +<IfModule !mod_authz_user.c> + LoadModule authz_user_module modules/mod_authz_user.so +</IfModule> +</IfVersion> Alias /dumb/ www/ +Alias /auth/ www/auth/ <Location /smart/> SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH} @@ -36,6 +61,10 @@ ScriptAlias /smart_noexport/ ${GIT_EXEC_PATH}/git-http-backend/ Options ExecCGI </Files> +RewriteEngine on +RewriteRule ^/smart-redir-perm/(.*)$ /smart/$1 [R=301] +RewriteRule ^/smart-redir-temp/(.*)$ /smart/$1 [R=302] + <IfDefine SSL> LoadModule ssl_module modules/mod_ssl.so @@ -48,6 +77,13 @@ SSLMutex file:ssl_mutex SSLEngine On </IfDefine> +<Location /auth/> + AuthType Basic + AuthName "git-auth" + AuthUserFile passwd + Require valid-user +</Location> + <IfDefine DAV> LoadModule dav_module modules/mod_dav.so LoadModule dav_fs_module modules/mod_dav_fs.so diff --git a/t/lib-httpd/passwd b/t/lib-httpd/passwd new file mode 100644 index 0000000000..f2fbcad33e --- /dev/null +++ b/t/lib-httpd/passwd @@ -0,0 +1 @@ +user@host:nKpa8pZUHx/ic diff --git a/t/lib-terminal.sh b/t/lib-terminal.sh new file mode 100644 index 0000000000..58d911d21b --- /dev/null +++ b/t/lib-terminal.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +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. + # + # Reproduction recipe: run + # + # i=0 + # while ./test-terminal.perl echo hi $i + # do + # : $((i = $i + 1)) + # done + # + # 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 +' diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index f688bd3ef5..f4e8f43bae 100755 --- a/t/t0000-basic.sh +++ b/t/t0000-basic.sh @@ -80,11 +80,11 @@ EOF chmod +x passing-todo.sh && ./passing-todo.sh >out 2>err && ! test -s err && -cat >expect <<EOF && -ok 1 - pretend we have fixed a known breakage # TODO known breakage -# fixed 1 known breakage(s) -# passed all 1 test(s) -1..1 +sed -e 's/^> //' >expect <<EOF && +> ok 1 - pretend we have fixed a known breakage # TODO known breakage +> # fixed 1 known breakage(s) +> # passed all 1 test(s) +> 1..1 EOF test_cmp expect out) " @@ -130,22 +130,57 @@ test_expect_success 'tests clean up after themselves' ' test_when_finished clean=yes ' -cleaner=no -test_expect_code 1 'tests clean up even after a failure' ' - test_when_finished cleaner=yes && - (exit 1) -' - -if test $clean$cleaner != yesyes +if test $clean != yes then - say "bug in test framework: cleanup commands do not work reliably" + say "bug in test framework: basic cleanup command does not work reliably" exit 1 fi -test_expect_code 2 'failure to clean up causes the test to fail' ' - test_when_finished "(exit 2)" +test_expect_success 'tests clean up even on failures' " + mkdir failing-cleanup && + (cd failing-cleanup && + cat >failing-cleanup.sh <<EOF && +#!$SHELL_PATH + +test_description='Failing tests with cleanup commands' + +# Point to the t/test-lib.sh, which isn't in ../ as usual +TEST_DIRECTORY=\"$TEST_DIRECTORY\" +. \"\$TEST_DIRECTORY\"/test-lib.sh + +test_expect_success 'tests clean up even after a failure' ' + touch clean-after-failure && + test_when_finished rm clean-after-failure && + (exit 1) +' + +test_expect_success 'failure to clean up causes the test to fail' ' + test_when_finished \"(exit 2)\" ' +test_done +EOF + chmod +x failing-cleanup.sh && + test_must_fail ./failing-cleanup.sh >out 2>err && + ! test -s err && + ! test -f \"trash directory.failing-cleanup/clean-after-failure\" && +sed -e 's/Z$//' -e 's/^> //' >expect <<\EOF && +> not ok - 1 tests clean up even after a failure +> # Z +> # touch clean-after-failure && +> # test_when_finished rm clean-after-failure && +> # (exit 1) +> # Z +> not ok - 2 failure to clean up causes the test to fail +> # Z +> # test_when_finished \"(exit 2)\" +> # Z +> # failed 2 among 2 test(s) +> 1..2 +EOF + test_cmp expect out) +" + ################################################################ # Basics of the basics @@ -400,7 +435,7 @@ test_expect_success 'update-index D/F conflict' ' test $numpath0 = 1 ' -test_expect_success SYMLINKS 'absolute path works as expected' ' +test_expect_success SYMLINKS 'real path works as expected' ' mkdir first && ln -s ../.git first/.git && mkdir second && @@ -408,14 +443,14 @@ test_expect_success SYMLINKS 'absolute path works as expected' ' mkdir third && dir="$(cd .git; pwd -P)" && dir2=third/../second/other/.git && - test "$dir" = "$(test-path-utils make_absolute_path $dir2)" && + test "$dir" = "$(test-path-utils real_path $dir2)" && file="$dir"/index && - test "$file" = "$(test-path-utils make_absolute_path $dir2/index)" && + test "$file" = "$(test-path-utils real_path $dir2/index)" && basename=blub && - test "$dir/$basename" = "$(cd .git && test-path-utils make_absolute_path "$basename")" && + test "$dir/$basename" = "$(cd .git && test-path-utils real_path "$basename")" && ln -s ../first/file .git/syml && sym="$(cd first; pwd -P)"/file && - test "$sym" = "$(test-path-utils make_absolute_path "$dir2/syml")" + test "$sym" = "$(test-path-utils real_path "$dir2/syml")" ' test_expect_success 'very long name in the index handled sanely' ' diff --git a/t/t0001-init.sh b/t/t0001-init.sh index 7fe8883ae0..54520f6fa6 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -25,7 +25,7 @@ check_config () { test_expect_success 'plain' ' ( - unset GIT_DIR GIT_WORK_TREE + sane_unset GIT_DIR GIT_WORK_TREE && mkdir plain && cd plain && git init @@ -33,9 +33,65 @@ test_expect_success 'plain' ' check_config plain/.git false unset ' +test_expect_success 'plain nested in bare' ' + ( + sane_unset GIT_DIR GIT_WORK_TREE && + git init --bare bare-ancestor.git && + cd bare-ancestor.git && + mkdir plain-nested && + cd plain-nested && + git init + ) && + check_config bare-ancestor.git/plain-nested/.git false unset +' + +test_expect_success 'plain through aliased command, outside any git repo' ' + ( + sane_unset GIT_DIR GIT_WORK_TREE && + HOME=$(pwd)/alias-config && + export HOME && + mkdir alias-config && + echo "[alias] aliasedinit = init" >alias-config/.gitconfig && + + GIT_CEILING_DIRECTORIES=$(pwd) && + export GIT_CEILING_DIRECTORIES && + + mkdir plain-aliased && + cd plain-aliased && + git aliasedinit + ) && + check_config plain-aliased/.git false unset +' + +test_expect_failure 'plain nested through aliased command' ' + ( + sane_unset GIT_DIR GIT_WORK_TREE && + git init plain-ancestor-aliased && + cd plain-ancestor-aliased && + echo "[alias] aliasedinit = init" >>.git/config && + mkdir plain-nested && + cd plain-nested && + git aliasedinit + ) && + check_config plain-ancestor-aliased/plain-nested/.git false unset +' + +test_expect_failure 'plain nested in bare through aliased command' ' + ( + sane_unset GIT_DIR GIT_WORK_TREE && + git init --bare bare-ancestor-aliased.git && + cd bare-ancestor-aliased.git && + echo "[alias] aliasedinit = init" >>config && + mkdir plain-nested && + cd plain-nested && + git aliasedinit + ) && + check_config bare-ancestor-aliased.git/plain-nested/.git false unset +' + test_expect_success 'plain with GIT_WORK_TREE' ' if ( - unset GIT_DIR + sane_unset GIT_DIR && mkdir plain-wt && cd plain-wt && GIT_WORK_TREE=$(pwd) git init @@ -48,7 +104,7 @@ test_expect_success 'plain with GIT_WORK_TREE' ' test_expect_success 'plain bare' ' ( - unset GIT_DIR GIT_WORK_TREE GIT_CONFIG + sane_unset GIT_DIR GIT_WORK_TREE GIT_CONFIG && mkdir plain-bare-1 && cd plain-bare-1 && git --bare init @@ -58,7 +114,7 @@ test_expect_success 'plain bare' ' test_expect_success 'plain bare with GIT_WORK_TREE' ' if ( - unset GIT_DIR GIT_CONFIG + sane_unset GIT_DIR GIT_CONFIG && mkdir plain-bare-2 && cd plain-bare-2 && GIT_WORK_TREE=$(pwd) git --bare init @@ -72,7 +128,7 @@ test_expect_success 'plain bare with GIT_WORK_TREE' ' test_expect_success 'GIT_DIR bare' ' ( - unset GIT_CONFIG + sane_unset GIT_CONFIG && mkdir git-dir-bare.git && GIT_DIR=git-dir-bare.git git init ) && @@ -82,7 +138,7 @@ test_expect_success 'GIT_DIR bare' ' test_expect_success 'init --bare' ' ( - unset GIT_DIR GIT_WORK_TREE GIT_CONFIG + sane_unset GIT_DIR GIT_WORK_TREE GIT_CONFIG && mkdir init-bare.git && cd init-bare.git && git init --bare @@ -93,7 +149,7 @@ test_expect_success 'init --bare' ' test_expect_success 'GIT_DIR non-bare' ' ( - unset GIT_CONFIG + sane_unset GIT_CONFIG && mkdir non-bare && cd non-bare && GIT_DIR=.git git init @@ -104,7 +160,7 @@ test_expect_success 'GIT_DIR non-bare' ' test_expect_success 'GIT_DIR & GIT_WORK_TREE (1)' ' ( - unset GIT_CONFIG + sane_unset GIT_CONFIG && mkdir git-dir-wt-1.git && GIT_WORK_TREE=$(pwd) GIT_DIR=git-dir-wt-1.git git init ) && @@ -114,7 +170,7 @@ test_expect_success 'GIT_DIR & GIT_WORK_TREE (1)' ' test_expect_success 'GIT_DIR & GIT_WORK_TREE (2)' ' if ( - unset GIT_CONFIG + sane_unset GIT_CONFIG && mkdir git-dir-wt-2.git && GIT_WORK_TREE=$(pwd) GIT_DIR=git-dir-wt-2.git git --bare init ) @@ -124,10 +180,10 @@ test_expect_success 'GIT_DIR & GIT_WORK_TREE (2)' ' fi ' -test_expect_success 'reinit' ' +test_expect_success C_LOCALE_OUTPUT 'reinit' ' ( - unset GIT_CONFIG GIT_WORK_TREE GIT_CONFIG + sane_unset GIT_CONFIG GIT_WORK_TREE GIT_CONFIG && mkdir again && cd again && @@ -175,8 +231,7 @@ test_expect_success 'init with init.templatedir set' ' git config -f "$test_config" init.templatedir "${HOME}/templatedir-source" && mkdir templatedir-set && cd templatedir-set && - unset GIT_CONFIG_NOGLOBAL && - unset GIT_TEMPLATE_DIR && + sane_unset GIT_TEMPLATE_DIR && NO_SET_GIT_TEMPLATE_DIR=t && export NO_SET_GIT_TEMPLATE_DIR && git init @@ -187,7 +242,6 @@ test_expect_success 'init with init.templatedir set' ' test_expect_success 'init --bare/--shared overrides system/global config' ' ( test_config="$HOME"/.gitconfig && - unset GIT_CONFIG_NOGLOBAL && git config -f "$test_config" core.bare false && git config -f "$test_config" core.sharedRepository 0640 && mkdir init-bare-shared-override && @@ -202,7 +256,6 @@ test_expect_success 'init --bare/--shared overrides system/global config' ' test_expect_success 'init honors global core.sharedRepository' ' ( test_config="$HOME"/.gitconfig && - unset GIT_CONFIG_NOGLOBAL && git config -f "$test_config" core.sharedRepository 0666 && mkdir shared-honor-global && cd shared-honor-global && @@ -318,4 +371,50 @@ test_expect_success 'init prefers command line to GIT_DIR' ' ! test -d otherdir/refs ' +test_expect_success 'init with separate gitdir' ' + rm -rf newdir && + git init --separate-git-dir realgitdir newdir && + echo "gitdir: `pwd`/realgitdir" >expected && + test_cmp expected newdir/.git && + test -d realgitdir/refs +' + +test_expect_success 're-init to update git link' ' + ( + cd newdir && + git init --separate-git-dir ../surrealgitdir + ) && + echo "gitdir: `pwd`/surrealgitdir" >expected && + test_cmp expected newdir/.git && + test -d surrealgitdir/refs && + ! test -d realgitdir/refs +' + +test_expect_success 're-init to move gitdir' ' + rm -rf newdir realgitdir surrealgitdir && + git init newdir && + ( + cd newdir && + git init --separate-git-dir ../realgitdir + ) && + echo "gitdir: `pwd`/realgitdir" >expected && + test_cmp expected newdir/.git && + test -d realgitdir/refs +' + +test_expect_success SYMLINKS 're-init to move gitdir symlink' ' + rm -rf newdir realgitdir && + git init newdir && + ( + cd newdir && + mv .git here && + ln -s here .git && + git init -L ../realgitdir + ) && + echo "gitdir: `pwd`/realgitdir" >expected && + test_cmp expected newdir/.git && + test -d realgitdir/refs && + ! test -d newdir/here +' + test_done diff --git a/t/t0003-attributes.sh b/t/t0003-attributes.sh index de38c7f7aa..ebbc7554a7 100755 --- a/t/t0003-attributes.sh +++ b/t/t0003-attributes.sh @@ -36,6 +36,9 @@ test_expect_success 'setup' ' echo "d/* test=a/b/d/*" echo "d/yes notest" ) >a/b/.gitattributes + ( + echo "global test=global" + ) >"$HOME"/global-gitattributes ' @@ -57,9 +60,19 @@ test_expect_success 'attribute test' ' ' +test_expect_success 'core.attributesfile' ' + attr_check global unspecified && + git config core.attributesfile "$HOME/global-gitattributes" && + attr_check global global && + git config core.attributesfile "~/global-gitattributes" && + attr_check global global && + echo "global test=precedence" >> .gitattributes && + attr_check global precedence +' + test_expect_success 'attribute test: read paths from stdin' ' - cat <<EOF > expect + cat <<EOF > expect && f: test: f a/f: test: f a/c/f: test: f diff --git a/t/t0004-unwritable.sh b/t/t0004-unwritable.sh index 385b1265de..e3137d638e 100755 --- a/t/t0004-unwritable.sh +++ b/t/t0004-unwritable.sh @@ -16,53 +16,29 @@ test_expect_success setup ' ' test_expect_success POSIXPERM,SANITY 'write-tree should notice unwritable repository' ' - - ( - chmod a-w .git/objects .git/objects/?? && - test_must_fail git write-tree - ) - status=$? - chmod 775 .git/objects .git/objects/?? - (exit $status) - + test_when_finished "chmod 775 .git/objects .git/objects/??" && + chmod a-w .git/objects .git/objects/?? && + test_must_fail git write-tree ' test_expect_success POSIXPERM,SANITY 'commit should notice unwritable repository' ' - - ( - chmod a-w .git/objects .git/objects/?? && - test_must_fail git commit -m second - ) - status=$? - chmod 775 .git/objects .git/objects/?? - (exit $status) - + test_when_finished "chmod 775 .git/objects .git/objects/??" && + chmod a-w .git/objects .git/objects/?? && + test_must_fail git commit -m second ' test_expect_success POSIXPERM,SANITY 'update-index should notice unwritable repository' ' - - ( - echo 6O >file && - chmod a-w .git/objects .git/objects/?? && - test_must_fail git update-index file - ) - status=$? - chmod 775 .git/objects .git/objects/?? - (exit $status) - + test_when_finished "chmod 775 .git/objects .git/objects/??" && + echo 6O >file && + chmod a-w .git/objects .git/objects/?? && + test_must_fail git update-index file ' test_expect_success POSIXPERM,SANITY 'add should notice unwritable repository' ' - - ( - echo b >file && - chmod a-w .git/objects .git/objects/?? && - test_must_fail git add file - ) - status=$? - chmod 775 .git/objects .git/objects/?? - (exit $status) - + test_when_finished "chmod 775 .git/objects .git/objects/??" && + echo b >file && + chmod a-w .git/objects .git/objects/?? && + test_must_fail git add file ' test_done diff --git a/t/t0006-date.sh b/t/t0006-date.sh index 1d4d0a5c7d..f87abb5a06 100755 --- a/t/t0006-date.sh +++ b/t/t0006-date.sh @@ -25,6 +25,7 @@ check_show 37500000 '1 year, 2 months ago' check_show 55188000 '1 year, 9 months ago' check_show 630000000 '20 years ago' check_show 31449600 '12 months ago' +check_show 62985600 '2 years ago' check_parse() { echo "$1 -> $2" >expect diff --git a/t/t0020-crlf.sh b/t/t0020-crlf.sh index 234a94f3e6..1a8f44c44c 100755 --- a/t/t0020-crlf.sh +++ b/t/t0020-crlf.sh @@ -439,7 +439,7 @@ test_expect_success 'checkout when deleting .gitattributes' ' git rm .gitattributes && echo "contentsQ" | q_to_cr > .file2 && git add .file2 && - git commit -m third + git commit -m third && git checkout master~1 && git checkout master && diff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh index 828e35baf7..9078b84ae6 100755 --- a/t/t0021-conversion.sh +++ b/t/t0021-conversion.sh @@ -93,4 +93,47 @@ test_expect_success expanded_in_repo ' cmp expanded-keywords expected-output ' +# The use of %f in a filter definition is expanded to the path to +# the filename being smudged or cleaned. It must be shell escaped. +# First, set up some interesting file names and pet them in +# .gitattributes. +test_expect_success 'filter shell-escaped filenames' ' + cat >argc.sh <<-EOF && + #!$SHELL_PATH + cat >/dev/null + echo argc: \$# "\$@" + EOF + normal=name-no-magic && + special="name with '\''sq'\'' and \$x" && + echo some test text >"$normal" && + echo some test text >"$special" && + git add "$normal" "$special" && + git commit -q -m "add files" && + echo "name* filter=argc" >.gitattributes && + + # delete the files and check them out again, using a smudge filter + # that will count the args and echo the command-line back to us + git config filter.argc.smudge "sh ./argc.sh %f" && + rm "$normal" "$special" && + git checkout -- "$normal" "$special" && + + # make sure argc.sh counted the right number of args + echo "argc: 1 $normal" >expect && + test_cmp expect "$normal" && + echo "argc: 1 $special" >expect && + test_cmp expect "$special" && + + # do the same thing, but with more args in the filter expression + git config filter.argc.smudge "sh ./argc.sh %f --my-extra-arg" && + rm "$normal" "$special" && + git checkout -- "$normal" "$special" && + + # make sure argc.sh counted the right number of args + echo "argc: 2 $normal --my-extra-arg" >expect && + test_cmp expect "$normal" && + echo "argc: 2 $special --my-extra-arg" >expect && + test_cmp expect "$special" && + : +' + test_done diff --git a/t/t0024-crlf-archive.sh b/t/t0024-crlf-archive.sh index c7d0324374..ec6c1b3f8a 100755 --- a/t/t0024-crlf-archive.sh +++ b/t/t0024-crlf-archive.sh @@ -7,7 +7,7 @@ UNZIP=${UNZIP:-unzip} test_expect_success setup ' - git config core.autocrlf true + git config core.autocrlf true && printf "CRLF line ending\r\nAnd another\r\n" > sample && git add sample && @@ -20,7 +20,7 @@ test_expect_success setup ' test_expect_success 'tar archive' ' git archive --format=tar HEAD | - ( mkdir untarred && cd untarred && "$TAR" -xf - ) + ( mkdir untarred && cd untarred && "$TAR" -xf - ) && test_cmp sample untarred/sample diff --git a/t/t0026-eol-config.sh b/t/t0026-eol-config.sh index f37ac8fa0b..fe0164be62 100755 --- a/t/t0026-eol-config.sh +++ b/t/t0026-eol-config.sh @@ -12,7 +12,7 @@ test_expect_success setup ' git config core.autocrlf false && - echo "one text" > .gitattributes + echo "one text" > .gitattributes && for w in Hello world how are you; do echo $w; done >one && for w in I am very very fine thank you; do echo $w; done >two && diff --git a/t/t0040-parse-options.sh b/t/t0040-parse-options.sh index 20924506af..ae266147b6 100755 --- a/t/t0040-parse-options.sh +++ b/t/t0040-parse-options.sh @@ -19,7 +19,7 @@ usage: test-parse-options <options> --set23 set integer to 23 -t <time> get timestamp of <time> -L, --length <str> get length of <str> - -F, --file <FILE> set file to <FILE> + -F, --file <file> set file to <file> String options -s, --string <string> diff --git a/t/t0050-filesystem.sh b/t/t0050-filesystem.sh index 41df6bcf27..1542cf6a13 100755 --- a/t/t0050-filesystem.sh +++ b/t/t0050-filesystem.sh @@ -4,22 +4,22 @@ test_description='Various filesystem issues' . ./test-lib.sh -auml=`printf '\xc3\xa4'` -aumlcdiar=`printf '\x61\xcc\x88'` +auml=$(printf '\303\244') +aumlcdiar=$(printf '\141\314\210') case_insensitive= unibad= no_symlinks= test_expect_success 'see what we expect' ' - test_case=test_expect_success - test_unicode=test_expect_success + test_case=test_expect_success && + test_unicode=test_expect_success && mkdir junk && echo good >junk/CamelCase && echo bad >junk/camelcase && if test "$(cat junk/CamelCase)" != good then - test_case=test_expect_failure + test_case=test_expect_failure && case_insensitive=t fi && rm -fr junk && @@ -27,7 +27,7 @@ test_expect_success 'see what we expect' ' >junk/"$auml" && case "$(cd junk && echo *)" in "$aumlcdiar") - test_unicode=test_expect_failure + test_unicode=test_expect_failure && unibad=t ;; *) ;; @@ -36,7 +36,7 @@ test_expect_success 'see what we expect' ' { ln -s x y 2> /dev/null && test -h y 2> /dev/null || - no_symlinks=1 + no_symlinks=1 && rm -f y } ' @@ -128,7 +128,7 @@ test_expect_success "setup unicode normalization tests" ' cd unicode && touch "$aumlcdiar" && git add "$aumlcdiar" && - git commit -m initial + git commit -m initial && git tag initial && git checkout -b topic && git mv $aumlcdiar tmp && diff --git a/t/t0070-fundamental.sh b/t/t0070-fundamental.sh index 680d7d6861..9bee8bfd2e 100755 --- a/t/t0070-fundamental.sh +++ b/t/t0070-fundamental.sh @@ -12,4 +12,17 @@ test_expect_success 'character classes (isspace, isalpha etc.)' ' test-ctype ' +test_expect_success 'mktemp to nonexistent directory prints filename' ' + test_must_fail test-mktemp doesnotexist/testXXXXXX 2>err && + grep "doesnotexist/test" err +' + +test_expect_success POSIXPERM 'mktemp to unwritable directory prints filename' ' + mkdir cannotwrite && + chmod -w cannotwrite && + test_when_finished "chmod +w cannotwrite" && + test_must_fail test-mktemp cannotwrite/testXXXXXX 2>err && + grep "cannotwrite/test" err +' + test_done diff --git a/t/t0080-vcs-svn.sh b/t/t0080-vcs-svn.sh index d3225ada68..99a314b080 100755 --- a/t/t0080-vcs-svn.sh +++ b/t/t0080-vcs-svn.sh @@ -76,60 +76,6 @@ test_expect_success 'obj pool: high-water mark' ' test_cmp expected actual ' -test_expect_success 'line buffer' ' - echo HELLO >expected1 && - printf "%s\n" "" HELLO >expected2 && - echo >expected3 && - printf "%s\n" "" Q | q_to_nul >expected4 && - printf "%s\n" foo "" >expected5 && - printf "%s\n" "" foo >expected6 && - - test-line-buffer <<-\EOF >actual1 && - 5 - HELLO - EOF - - test-line-buffer <<-\EOF >actual2 && - 0 - - 5 - HELLO - EOF - - q_to_nul <<-\EOF | - 1 - Q - EOF - test-line-buffer >actual3 && - - q_to_nul <<-\EOF | - 0 - - 1 - Q - EOF - test-line-buffer >actual4 && - - test-line-buffer <<-\EOF >actual5 && - 5 - foo - EOF - - test-line-buffer <<-\EOF >actual6 && - 0 - - 5 - foo - EOF - - test_cmp expected1 actual1 && - test_cmp expected2 actual2 && - test_cmp expected3 actual3 && - test_cmp expected4 actual4 && - test_cmp expected5 actual5 && - test_cmp expected6 actual6 -' - test_expect_success 'string pool' ' echo a does not equal b >expected.differ && echo a equals a >expected.match && diff --git a/t/t0081-line-buffer.sh b/t/t0081-line-buffer.sh new file mode 100755 index 0000000000..5067d1e15b --- /dev/null +++ b/t/t0081-line-buffer.sh @@ -0,0 +1,192 @@ +#!/bin/sh + +test_description="Test the svn importer's input handling routines. + +These tests exercise the line_buffer library, but their real purpose +is to check the assumptions that library makes of the platform's input +routines. Processes engaged in bi-directional communication would +hang if fread or fgets is too greedy. + +While at it, check that input of newlines and null bytes are handled +correctly. +" +. ./test-lib.sh + +test -n "$GIT_REMOTE_SVN_TEST_BIG_FILES" && test_set_prereq EXPENSIVE + +generate_tens_of_lines () { + tens=$1 && + line=$2 && + + i=0 && + while test $i -lt "$tens" + do + for j in a b c d e f g h i j + do + echo "$line" + done && + : $((i = $i + 1)) || + return + done +} + +long_read_test () { + : each line is 10 bytes, including newline && + line=abcdefghi && + echo "$line" >expect && + + if ! test_declared_prereq PIPE + then + echo >&4 "long_read_test: need to declare PIPE prerequisite" + return 127 + fi && + tens_of_lines=$(($1 / 100 + 1)) && + lines=$(($tens_of_lines * 10)) && + readsize=$((($lines - 1) * 10 + 3)) && + copysize=7 && + rm -f input && + mkfifo input && + { + ( + generate_tens_of_lines $tens_of_lines "$line" && + exec sleep 100 + ) >input & + } && + test-line-buffer input <<-EOF >output && + binary $readsize + copy $copysize + EOF + kill $! && + test_line_count = $lines output && + tail -n 1 <output >actual && + test_cmp expect actual +} + +test_expect_success 'setup: have pipes?' ' + rm -f frob && + if mkfifo frob + then + test_set_prereq PIPE + fi +' + +test_expect_success 'hello world' ' + echo ">HELLO" >expect && + test-line-buffer <<-\EOF >actual && + binary 6 + HELLO + EOF + test_cmp expect actual +' + +test_expect_success PIPE '0-length read, no input available' ' + printf ">" >expect && + rm -f input && + mkfifo input && + { + sleep 100 >input & + } && + test-line-buffer input <<-\EOF >actual && + binary 0 + copy 0 + EOF + kill $! && + test_cmp expect actual +' + +test_expect_success '0-length read, send along greeting' ' + echo ">HELLO" >expect && + test-line-buffer <<-\EOF >actual && + binary 0 + copy 6 + HELLO + EOF + test_cmp expect actual +' + +test_expect_success PIPE '1-byte read, no input available' ' + printf ">%s" ab >expect && + rm -f input && + mkfifo input && + { + ( + printf "%s" a && + printf "%s" b && + exec sleep 100 + ) >input & + } && + test-line-buffer input <<-\EOF >actual && + binary 1 + copy 1 + EOF + kill $! && + test_cmp expect actual +' + +test_expect_success PIPE 'long read (around 8192 bytes)' ' + long_read_test 8192 +' + +test_expect_success PIPE,EXPENSIVE 'longer read (around 65536 bytes)' ' + long_read_test 65536 +' + +test_expect_success 'read from file descriptor' ' + rm -f input && + echo hello >expect && + echo hello >input && + echo copy 6 | + test-line-buffer "&4" 4<input >actual && + test_cmp expect actual +' + +test_expect_success 'skip, copy null byte' ' + echo Q | q_to_nul >expect && + q_to_nul <<-\EOF | test-line-buffer >actual && + skip 2 + Q + copy 2 + Q + EOF + test_cmp expect actual +' + +test_expect_success 'read null byte' ' + echo ">QhelloQ" | q_to_nul >expect && + q_to_nul <<-\EOF | test-line-buffer >actual && + binary 8 + QhelloQ + EOF + test_cmp expect actual +' + +test_expect_success 'long reads are truncated' ' + echo ">foo" >expect && + test-line-buffer <<-\EOF >actual && + binary 5 + foo + EOF + test_cmp expect actual +' + +test_expect_success 'long copies are truncated' ' + printf "%s\n" ">" foo >expect && + test-line-buffer <<-\EOF >actual && + binary 1 + + copy 5 + foo + EOF + test_cmp expect actual +' + +test_expect_success 'long binary reads are truncated' ' + echo ">foo" >expect && + test-line-buffer <<-\EOF >actual && + binary 5 + foo + EOF + test_cmp expect actual +' + +test_done diff --git a/t/t1000-read-tree-m-3way.sh b/t/t1000-read-tree-m-3way.sh index 4f171722d9..ca8a4098fa 100755 --- a/t/t1000-read-tree-m-3way.sh +++ b/t/t1000-read-tree-m-3way.sh @@ -309,7 +309,7 @@ test_expect_success \ test_expect_success \ '6 - must not exist in O && !A && !B case' " rm -f .git/index DD && - echo DD >DD + echo DD >DD && git update-index --add DD && test_must_fail git read-tree -m $tree_O $tree_A $tree_B " diff --git a/t/t1001-read-tree-m-2way.sh b/t/t1001-read-tree-m-2way.sh index 93ca84f9e6..680d992f22 100755 --- a/t/t1001-read-tree-m-2way.sh +++ b/t/t1001-read-tree-m-2way.sh @@ -98,8 +98,8 @@ test_expect_success \ git checkout-index -u -f -q -a && git update-index --add yomin && read_tree_twoway $treeH $treeM && - git ls-files --stage >4.out || return 1 - git diff --no-index M.out 4.out >4diff.out + git ls-files --stage >4.out && + test_must_fail git diff --no-index M.out 4.out >4diff.out && compare_change 4diff.out expected && check_cache_at yomin clean' @@ -112,8 +112,8 @@ test_expect_success \ git update-index --add yomin && echo yomin yomin >yomin && read_tree_twoway $treeH $treeM && - git ls-files --stage >5.out || return 1 - git diff --no-index M.out 5.out >5diff.out + git ls-files --stage >5.out && + test_must_fail git diff --no-index M.out 5.out >5diff.out && compare_change 5diff.out expected && check_cache_at yomin dirty' @@ -213,8 +213,8 @@ test_expect_success \ echo nitfol nitfol >nitfol && git update-index --add nitfol && read_tree_twoway $treeH $treeM && - git ls-files --stage >14.out || return 1 - git diff --no-index M.out 14.out >14diff.out + git ls-files --stage >14.out && + test_must_fail git diff --no-index M.out 14.out >14diff.out && compare_change 14diff.out expected && check_cache_at nitfol clean' @@ -227,8 +227,8 @@ test_expect_success \ git update-index --add nitfol && echo nitfol nitfol nitfol >nitfol && read_tree_twoway $treeH $treeM && - git ls-files --stage >15.out || return 1 - git diff --no-index M.out 15.out >15diff.out + git ls-files --stage >15.out && + test_must_fail git diff --no-index M.out 15.out >15diff.out && compare_change 15diff.out expected && check_cache_at nitfol dirty' @@ -377,7 +377,7 @@ test_expect_success \ git ls-files --stage >treeM.out && rm -f a && - mkdir a + mkdir a && : >a/b && git update-index --add --remove a a/b && treeH=`git write-tree` && @@ -394,7 +394,7 @@ test_expect_success '-m references the correct modified tree' ' echo >file-a && echo >file-b && git add file-a file-b && - git commit -a -m "test for correct modified tree" + git commit -a -m "test for correct modified tree" && git branch initial-mod && echo b >file-b && git commit -a -m "B" && diff --git a/t/t1002-read-tree-m-u-2way.sh b/t/t1002-read-tree-m-u-2way.sh index 0241329a08..a4a17e0017 100755 --- a/t/t1002-read-tree-m-u-2way.sh +++ b/t/t1002-read-tree-m-u-2way.sh @@ -205,8 +205,8 @@ test_expect_success \ echo nitfol nitfol >nitfol && git update-index --add nitfol && git read-tree -m -u $treeH $treeM && - git ls-files --stage >14.out || return 1 - git diff -U0 --no-index M.out 14.out >14diff.out + git ls-files --stage >14.out && + test_must_fail git diff -U0 --no-index M.out 14.out >14diff.out && compare_change 14diff.out expected && sum bozbar frotz >actual14.sum && grep -v nitfol M.sum > expected14.sum && @@ -226,8 +226,8 @@ test_expect_success \ git update-index --add nitfol && echo nitfol nitfol nitfol >nitfol && git read-tree -m -u $treeH $treeM && - git ls-files --stage >15.out || return 1 - git diff -U0 --no-index M.out 15.out >15diff.out + git ls-files --stage >15.out && + test_must_fail git diff -U0 --no-index M.out 15.out >15diff.out && compare_change 15diff.out expected && check_cache_at nitfol dirty && sum bozbar frotz >actual15.sum && @@ -314,7 +314,7 @@ test_expect_success \ # Also make sure we did not break DF vs DF/DF case. test_expect_success \ 'DF vs DF/DF case setup.' \ - 'rm -f .git/index + 'rm -f .git/index && echo DF >DF && git update-index --add DF && treeDF=`git write-tree` && diff --git a/t/t1007-hash-object.sh b/t/t1007-hash-object.sh index dd32432d62..6d52b824b1 100755 --- a/t/t1007-hash-object.sh +++ b/t/t1007-hash-object.sh @@ -188,4 +188,17 @@ for args in "-w --stdin-paths" "--stdin-paths -w"; do pop_repo done +test_expect_success 'corrupt tree' ' + echo abc >malformed-tree + test_must_fail git hash-object -t tree malformed-tree +' + +test_expect_success 'corrupt commit' ' + test_must_fail git hash-object -t commit --stdin </dev/null +' + +test_expect_success 'corrupt tag' ' + test_must_fail git hash-object -t tag --stdin </dev/null +' + test_done diff --git a/t/t1011-read-tree-sparse-checkout.sh b/t/t1011-read-tree-sparse-checkout.sh index 9a07de1a5b..de84e35c43 100755 --- a/t/t1011-read-tree-sparse-checkout.sh +++ b/t/t1011-read-tree-sparse-checkout.sh @@ -17,17 +17,19 @@ test_expect_success 'setup' ' cat >expected <<-\EOF && 100644 77f0ba1734ed79d12881f81b36ee134de6a3327b 0 init.t 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 sub/added + 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 subsub/added EOF cat >expected.swt <<-\EOF && H init.t H sub/added + H subsub/added EOF test_commit init && echo modified >>init.t && - mkdir sub && - touch sub/added && - git add init.t sub/added && + mkdir sub subsub && + touch sub/added subsub/added && + git add init.t sub/added subsub/added && git commit -m "modified and added" && git tag top && git rm sub/added && @@ -47,7 +49,7 @@ test_expect_success 'read-tree without .git/info/sparse-checkout' ' ' test_expect_success 'read-tree with .git/info/sparse-checkout but disabled' ' - echo >.git/info/sparse-checkout + echo >.git/info/sparse-checkout && git read-tree -m -u HEAD && git ls-files -t >result && test_cmp expected.swt result && @@ -81,6 +83,7 @@ test_expect_success 'match directories with trailing slash' ' cat >expected.swt-noinit <<-\EOF && S init.t H sub/added + S subsub/added EOF echo sub/ > .git/info/sparse-checkout && @@ -91,12 +94,20 @@ test_expect_success 'match directories with trailing slash' ' test -f sub/added ' -test_expect_failure 'match directories without trailing slash' ' - echo init.t >.git/info/sparse-checkout && +test_expect_success 'match directories without trailing slash' ' echo sub >>.git/info/sparse-checkout && git read-tree -m -u HEAD && git ls-files -t >result && - test_cmp expected.swt result && + test_cmp expected.swt-noinit result && + test ! -f init.t && + test -f sub/added +' + +test_expect_success 'match directory pattern' ' + echo "s?b" >>.git/info/sparse-checkout && + git read-tree -m -u HEAD && + git ls-files -t >result && + test_cmp expected.swt-noinit result && test ! -f init.t && test -f sub/added ' @@ -105,6 +116,7 @@ test_expect_success 'checkout area changes' ' cat >expected.swt-nosub <<-\EOF && H init.t S sub/added + S subsub/added EOF echo init.t >.git/info/sparse-checkout && diff --git a/t/t1020-subdirectory.sh b/t/t1020-subdirectory.sh index a3ac33801a..1fd187c5eb 100755 --- a/t/t1020-subdirectory.sh +++ b/t/t1020-subdirectory.sh @@ -110,6 +110,14 @@ test_expect_success 'read-tree' ' ) ' +test_expect_success 'alias expansion' ' + ( + git config alias.ss status && + cd dir && + git status && + git ss + ) +' test_expect_success 'no file/rev ambiguity check inside .git' ' git commit -a -m 1 && ( diff --git a/t/t1021-rerere-in-workdir.sh b/t/t1021-rerere-in-workdir.sh new file mode 100755 index 0000000000..301e071ff7 --- /dev/null +++ b/t/t1021-rerere-in-workdir.sh @@ -0,0 +1,55 @@ +#!/bin/sh + +test_description='rerere run in a workdir' +. ./test-lib.sh + +test_expect_success SYMLINKS setup ' + git config rerere.enabled true && + >world && + git add world && + test_tick && + git commit -m initial && + + echo hello >world && + test_tick && + git commit -a -m hello && + + git checkout -b side HEAD^ && + echo goodbye >world && + test_tick && + git commit -a -m goodbye && + + git checkout master +' + +test_expect_success SYMLINKS 'rerere in workdir' ' + rm -rf .git/rr-cache && + "$SHELL_PATH" "$TEST_DIRECTORY/../contrib/workdir/git-new-workdir" . work && + ( + cd work && + test_must_fail git merge side && + git rerere status >actual && + echo world >expect && + test_cmp expect actual + ) +' + +# This fails because we don't resolve relative symlink in mkdir_in_gitdir() +# For the purpose of helping contrib/workdir/git-new-workdir users, we do not +# have to support relative symlinks, but it might be nicer to make this work +# with a relative symbolic link someday. +test_expect_failure SYMLINKS 'rerere in workdir (relative)' ' + rm -rf .git/rr-cache && + "$SHELL_PATH" "$TEST_DIRECTORY/../contrib/workdir/git-new-workdir" . krow && + ( + cd krow && + rm -f .git/rr-cache && + ln -s ../.git/rr-cache .git/rr-cache && + test_must_fail git merge side && + git rerere status >actual && + echo world >expect && + test_cmp expect actual + ) +' + +test_done diff --git a/t/t1200-tutorial.sh b/t/t1200-tutorial.sh index ab55eda158..3264fefbad 100755 --- a/t/t1200-tutorial.sh +++ b/t/t1200-tutorial.sh @@ -42,7 +42,7 @@ test_expect_success 'git diff' ' ' test_expect_success 'tree' ' - tree=$(git write-tree 2>/dev/null) + tree=$(git write-tree 2>/dev/null) && test 8988da15d077d4829fc51d8544c097def6644dbb = $tree ' @@ -163,7 +163,10 @@ test_expect_success 'git resolve' ' git checkout mybranch && git merge -m "Merge upstream changes." master | sed -e "1s/[0-9a-f]\{7\}/VARIABLE/g" \ - -e "s/^Fast[- ]forward /FASTFORWARD /" >resolve.output && + -e "s/^Fast[- ]forward /FASTFORWARD /" >resolve.output +' + +test_expect_success C_LOCALE_OUTPUT 'git resolve output' ' test_cmp resolve.expect resolve.output ' diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh index 074f2f2e3e..53fb8228cf 100755 --- a/t/t1300-repo-config.sh +++ b/t/t1300-repo-config.sh @@ -289,6 +289,14 @@ test_expect_success 'working --list' \ 'git config --list > output && cmp output expect' cat > expect << EOF +EOF + +test_expect_success '--list without repo produces empty output' ' + git --git-dir=nonexistent config --list >output && + test_cmp expect output +' + +cat > expect << EOF beta.noindent sillyValue nextsection.nonewline wow2 for me EOF @@ -701,13 +709,13 @@ cat >expect <<\EOF trailingtilde = foo~ EOF -test_expect_success 'set --path' ' +test_expect_success NOT_MINGW 'set --path' ' git config --path path.home "~/" && git config --path path.normal "/dev/null" && git config --path path.trailingtilde "foo~" && test_cmp expect .git/config' -if test "${HOME+set}" +if test_have_prereq NOT_MINGW && test "${HOME+set}" then test_set_prereq HOMEVAR fi @@ -730,7 +738,7 @@ cat >expect <<\EOF foo~ EOF -test_expect_success 'get --path copes with unset $HOME' ' +test_expect_success NOT_MINGW 'get --path copes with unset $HOME' ' ( unset HOME; test_must_fail git config --get --path path.home \ @@ -836,6 +844,27 @@ 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_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_expect_success 'check split_cmdline return' " git config alias.split-cmdline-fix 'echo \"' && test_must_fail git split-cmdline-fix && @@ -847,11 +876,25 @@ test_expect_success 'check split_cmdline return' " " test_expect_success 'git -c "key=value" support' ' - test "z$(git -c name=value config name)" = zvalue && test "z$(git -c core.name=value config core.name)" = zvalue && - test "z$(git -c CamelCase=value config camelcase)" = zvalue && - test "z$(git -c flag config --bool flag)" = ztrue && - test_must_fail git -c core.name=value config name + test "z$(git -c foo.CamelCase=value config foo.camelcase)" = zvalue && + test "z$(git -c foo.flag config --bool foo.flag)" = ztrue && + test_must_fail git -c name=value config core.name +' + +test_expect_success 'key sanity-checking' ' + test_must_fail git config foo=bar && + test_must_fail git config foo=.bar && + test_must_fail git config foo.ba=r && + test_must_fail git config foo.1bar && + test_must_fail git config foo."ba + z".bar && + test_must_fail git config . false && + test_must_fail git config .foo false && + test_must_fail git config foo. false && + test_must_fail git config .foo. false && + git config foo.bar true && + git config foo."ba =z".bar false ' test_done diff --git a/t/t1302-repo-version.sh b/t/t1302-repo-version.sh index a6bf1bf4d6..0e47662406 100755 --- a/t/t1302-repo-version.sh +++ b/t/t1302-repo-version.sh @@ -39,7 +39,7 @@ test_expect_success 'gitdir selection on unsupported repo' ' ( cd test2 && git config core.repositoryformatversion >../actual - ) + ) && test_cmp expect actual ' diff --git a/t/t1303-wacky-config.sh b/t/t1303-wacky-config.sh index 080117c6bc..46103a1591 100755 --- a/t/t1303-wacky-config.sh +++ b/t/t1303-wacky-config.sh @@ -44,7 +44,7 @@ LONG_VALUE=$(printf "x%01021dx a" 7) test_expect_success 'do not crash on special long config line' ' setup && git config section.key "$LONG_VALUE" && - check section.key "fatal: bad config file line 2 in .git/config" + check section.key "$LONG_VALUE" ' test_done diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index 54ba3df95f..ff747f8229 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -52,9 +52,8 @@ rm -f .git/$m test_expect_success \ "fail to create $n" \ - "touch .git/$n_dir - git update-ref $n $A >out 2>err"' - test $? != 0' + "touch .git/$n_dir && + test_must_fail git update-ref $n $A >out 2>err" rm -f .git/$n_dir out err test_expect_success \ @@ -185,55 +184,55 @@ gd="Thu, 26 May 2005 18:33:00 -0500" ld="Thu, 26 May 2005 18:43:00 -0500" test_expect_success \ 'Query "master@{May 25 2005}" (before history)' \ - 'rm -f o e + 'rm -f o e && git rev-parse --verify "master@{May 25 2005}" >o 2>e && test '"$C"' = $(cat o) && test "warning: Log for '\'master\'' only goes back to $ed." = "$(cat e)"' test_expect_success \ "Query master@{2005-05-25} (before history)" \ - 'rm -f o e + 'rm -f o e && git rev-parse --verify master@{2005-05-25} >o 2>e && test '"$C"' = $(cat o) && echo test "warning: Log for '\'master\'' only goes back to $ed." = "$(cat e)"' test_expect_success \ 'Query "master@{May 26 2005 23:31:59}" (1 second before history)' \ - 'rm -f o e + 'rm -f o e && git rev-parse --verify "master@{May 26 2005 23:31:59}" >o 2>e && test '"$C"' = $(cat o) && test "warning: Log for '\''master'\'' only goes back to $ed." = "$(cat e)"' test_expect_success \ 'Query "master@{May 26 2005 23:32:00}" (exactly history start)' \ - 'rm -f o e + 'rm -f o e && git rev-parse --verify "master@{May 26 2005 23:32:00}" >o 2>e && test '"$C"' = $(cat o) && test "" = "$(cat e)"' test_expect_success \ 'Query "master@{May 26 2005 23:32:30}" (first non-creation change)' \ - 'rm -f o e + 'rm -f o e && git rev-parse --verify "master@{May 26 2005 23:32:30}" >o 2>e && test '"$A"' = $(cat o) && test "" = "$(cat e)"' test_expect_success \ 'Query "master@{2005-05-26 23:33:01}" (middle of history with gap)' \ - 'rm -f o e + 'rm -f o e && git rev-parse --verify "master@{2005-05-26 23:33:01}" >o 2>e && test '"$B"' = $(cat o) && test "warning: Log .git/logs/'"$m has gap after $gd"'." = "$(cat e)"' test_expect_success \ 'Query "master@{2005-05-26 23:38:00}" (middle of history)' \ - 'rm -f o e + 'rm -f o e && git rev-parse --verify "master@{2005-05-26 23:38:00}" >o 2>e && test '"$Z"' = $(cat o) && test "" = "$(cat e)"' test_expect_success \ 'Query "master@{2005-05-26 23:43:00}" (exact end of history)' \ - 'rm -f o e + 'rm -f o e && git rev-parse --verify "master@{2005-05-26 23:43:00}" >o 2>e && test '"$E"' = $(cat o) && test "" = "$(cat e)"' test_expect_success \ 'Query "master@{2005-05-28}" (past end of history)' \ - 'rm -f o e + 'rm -f o e && git rev-parse --verify "master@{2005-05-28}" >o 2>e && test '"$D"' = $(cat o) && test "warning: Log .git/logs/'"$m unexpectedly ended on $ld"'." = "$(cat e)"' @@ -247,7 +246,7 @@ test_expect_success \ git add F && GIT_AUTHOR_DATE="2005-05-26 23:30" \ GIT_COMMITTER_DATE="2005-05-26 23:30" git commit -m add -a && - h_TEST=$(git rev-parse --verify HEAD) + h_TEST=$(git rev-parse --verify HEAD) && echo The other day this did not work. >M && echo And then Bob told me how to fix it. >>M && echo OTHER >F && diff --git a/t/t1401-symbolic-ref.sh b/t/t1401-symbolic-ref.sh index 7fa5f5b22a..2c96551ed0 100755 --- a/t/t1401-symbolic-ref.sh +++ b/t/t1401-symbolic-ref.sh @@ -28,7 +28,7 @@ test_expect_success 'symbolic-ref refuses non-ref for HEAD' ' reset_to_sane test_expect_success 'symbolic-ref refuses bare sha1' ' - echo content >file && git add file && git commit -m one + echo content >file && git add file && git commit -m one && test_must_fail git symbolic-ref HEAD `git rev-parse HEAD` ' reset_to_sane diff --git a/t/t1402-check-ref-format.sh b/t/t1402-check-ref-format.sh index 782e75d000..1b0f82fa4c 100755 --- a/t/t1402-check-ref-format.sh +++ b/t/t1402-check-ref-format.sh @@ -32,7 +32,7 @@ test_expect_success "check-ref-format --branch @{-1}" ' T=$(git write-tree) && sha1=$(echo A | git commit-tree $T) && git update-ref refs/heads/master $sha1 && - git update-ref refs/remotes/origin/master $sha1 + git update-ref refs/remotes/origin/master $sha1 && git checkout master && git checkout origin/master && git checkout master && @@ -47,7 +47,7 @@ test_expect_success 'check-ref-format --branch from subdir' ' T=$(git write-tree) && sha1=$(echo A | git commit-tree $T) && git update-ref refs/heads/master $sha1 && - git update-ref refs/remotes/origin/master $sha1 + git update-ref refs/remotes/origin/master $sha1 && git checkout master && git checkout origin/master && git checkout master && diff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh index 25046c4208..252fc82837 100755 --- a/t/t1410-reflog.sh +++ b/t/t1410-reflog.sh @@ -186,8 +186,8 @@ test_expect_success 'delete' ' test_tick && git commit -m tiger C && - HEAD_entry_count=$(git reflog | wc -l) - master_entry_count=$(git reflog show master | wc -l) + HEAD_entry_count=$(git reflog | wc -l) && + master_entry_count=$(git reflog show master | wc -l) && test $HEAD_entry_count = 5 && test $master_entry_count = 5 && @@ -199,13 +199,13 @@ test_expect_success 'delete' ' test $HEAD_entry_count = $(git reflog | wc -l) && ! grep ox < output && - master_entry_count=$(wc -l < output) + master_entry_count=$(wc -l < output) && git reflog delete HEAD@{1} && test $(($HEAD_entry_count -1)) = $(git reflog | wc -l) && test $master_entry_count = $(git reflog show master | wc -l) && - HEAD_entry_count=$(git reflog | wc -l) + HEAD_entry_count=$(git reflog | wc -l) && git reflog delete master@{07.04.2005.15:15:00.-0700} && git reflog show master > output && diff --git a/t/t1411-reflog-show.sh b/t/t1411-reflog-show.sh index ba25ff354d..caa687b5b4 100755 --- a/t/t1411-reflog-show.sh +++ b/t/t1411-reflog-show.sh @@ -28,6 +28,24 @@ test_expect_success 'oneline reflog format' ' test_cmp expect actual ' +test_expect_success 'reflog default format' ' + git reflog -1 >actual && + test_cmp expect actual +' + +cat >expect <<'EOF' +commit e46513e +Reflog: HEAD@{0} (C O Mitter <committer@example.com>) +Reflog message: commit (initial): one +Author: A U Thor <author@example.com> + + one +EOF +test_expect_success 'override reflog default format' ' + git reflog --format=short -1 >actual && + test_cmp expect actual +' + cat >expect <<'EOF' Reflog: HEAD@{Thu Apr 7 15:13:13 2005 -0700} (C O Mitter <committer@example.com>) Reflog message: commit (initial): one diff --git a/t/t1412-reflog-loop.sh b/t/t1412-reflog-loop.sh new file mode 100755 index 0000000000..7f519e5ebe --- /dev/null +++ b/t/t1412-reflog-loop.sh @@ -0,0 +1,34 @@ +#!/bin/sh + +test_description='reflog walk shows repeated commits again' +. ./test-lib.sh + +test_expect_success 'setup commits' ' + test_tick && + echo content >file && git add file && git commit -m one && + git tag one && + echo content >>file && git add file && git commit -m two && + git tag two +' + +test_expect_success 'setup reflog with alternating commits' ' + git checkout -b topic && + git reset one && + git reset two && + git reset one && + git reset two +' + +test_expect_success 'reflog shows all entries' ' + cat >expect <<-\EOF + topic@{0} two: updating HEAD + topic@{1} one: updating HEAD + topic@{2} two: updating HEAD + topic@{3} one: updating HEAD + topic@{4} branch: Created from HEAD + EOF + git log -g --format="%gd %gs" topic >actual && + test_cmp expect actual +' + +test_done diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index 1be415e334..bb01d5ab8f 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -61,7 +61,7 @@ test_expect_success 'object with bad sha1' ' sha=$(echo blob | git hash-object -w --stdin) && old=$(echo $sha | sed "s+^..+&/+") && new=$(dirname $old)/ffffffffffffffffffffffffffffffffffffff && - sha="$(dirname $new)$(basename $new)" + sha="$(dirname $new)$(basename $new)" && mv .git/objects/$old .git/objects/$new && test_when_finished "remove_object $sha" && git update-index --add --cacheinfo 100644 $sha foo && @@ -111,7 +111,7 @@ test_expect_success 'email with embedded > is not okay' ' ' test_expect_success 'tag pointing to nonexistent' ' - cat >invalid-tag <<-\EOF + cat >invalid-tag <<-\EOF && object ffffffffffffffffffffffffffffffffffffffff type commit tag invalid diff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh index 2c8f01f668..da6252b117 100755 --- a/t/t1501-worktree.sh +++ b/t/t1501-worktree.sh @@ -340,4 +340,11 @@ test_expect_success 'make_relative_path handles double slashes in GIT_DIR' ' git --git-dir="$(pwd)//repo.git" --work-tree="$(pwd)" add dummy_file ' +test_expect_success 'relative $GIT_WORK_TREE and git subprocesses' ' + GIT_DIR=repo.git GIT_WORK_TREE=repo.git/work \ + test-subprocess --setup-work-tree rev-parse --show-toplevel >actual && + echo "$(pwd)/repo.git/work" >expected && + test_cmp expected actual +' + test_done diff --git a/t/t1502-rev-parse-parseopt.sh b/t/t1502-rev-parse-parseopt.sh index b3195c4707..1efd7f76dd 100755 --- a/t/t1502-rev-parse-parseopt.sh +++ b/t/t1502-rev-parse-parseopt.sh @@ -40,7 +40,7 @@ extra1 line above used to cause a segfault but no longer does EOF test_expect_success 'test --parseopt help output' ' - git rev-parse --parseopt -- -h > output < optionspec + test_expect_code 129 git rev-parse --parseopt -- -h > output < optionspec && test_cmp expect output ' diff --git a/t/t1503-rev-parse-verify.sh b/t/t1503-rev-parse-verify.sh index 100f857b16..813cc1b3e2 100755 --- a/t/t1503-rev-parse-verify.sh +++ b/t/t1503-rev-parse-verify.sh @@ -106,8 +106,8 @@ test_expect_success 'use --default' ' test_expect_success 'master@{n} for various n' ' N=$(git reflog | wc -l) && - Nm1=$((N-1)) && - Np1=$((N+1)) && + Nm1=$(($N-1)) && + Np1=$(($N+1)) && git rev-parse --verify master@{0} && git rev-parse --verify master@{1} && git rev-parse --verify master@{$Nm1} && diff --git a/t/t1504-ceiling-dirs.sh b/t/t1504-ceiling-dirs.sh index df5ad8c686..cce87a5ab5 100755 --- a/t/t1504-ceiling-dirs.sh +++ b/t/t1504-ceiling-dirs.sh @@ -9,8 +9,9 @@ test_prefix() { } test_fail() { - test_expect_code 128 "$1: prefix" \ - "git rev-parse --show-prefix" + test_expect_success "$1: prefix" ' + test_expect_code 128 git rev-parse --show-prefix + ' } TRASH_ROOT="$PWD" diff --git a/t/t1506-rev-parse-diagnosis.sh b/t/t1506-rev-parse-diagnosis.sh index 0eeeb0e450..4a6396f9e3 100755 --- a/t/t1506-rev-parse-diagnosis.sh +++ b/t/t1506-rev-parse-diagnosis.sh @@ -6,6 +6,13 @@ exec </dev/null . ./test-lib.sh +test_did_you_mean () +{ + printf "fatal: Path '$2$3' $4, but not ${5:-'$3'}.\n" >expected && + printf "Did you mean '$1:$2$3'${2:+ aka '$1:./$3'}?\n" >>expected && + test_cmp expected error +} + HASH_file= test_expect_success 'set up basic repo' ' @@ -31,6 +38,67 @@ test_expect_success 'correct file objects' ' test $HASH_file = $(git rev-parse :0:file.txt) ) ' +test_expect_success 'correct relative file objects (0)' ' + git rev-parse :file.txt >expected && + git rev-parse :./file.txt >result && + test_cmp expected result && + git rev-parse :0:./file.txt >result && + test_cmp expected result +' + +test_expect_success 'correct relative file objects (1)' ' + git rev-parse HEAD:file.txt >expected && + git rev-parse HEAD:./file.txt >result && + test_cmp expected result +' + +test_expect_success 'correct relative file objects (2)' ' + ( + cd subdir && + git rev-parse HEAD:../file.txt >result && + test_cmp ../expected result + ) +' + +test_expect_success 'correct relative file objects (3)' ' + ( + cd subdir && + git rev-parse HEAD:../subdir/../file.txt >result && + test_cmp ../expected result + ) +' + +test_expect_success 'correct relative file objects (4)' ' + git rev-parse HEAD:subdir/file.txt >expected && + ( + cd subdir && + git rev-parse HEAD:./file.txt >result && + test_cmp ../expected result + ) +' + +test_expect_success 'correct relative file objects (5)' ' + git rev-parse :subdir/file.txt >expected && + ( + cd subdir && + git rev-parse :./file.txt >result && + test_cmp ../expected result && + git rev-parse :0:./file.txt >result && + test_cmp ../expected result + ) +' + +test_expect_success 'correct relative file objects (6)' ' + git rev-parse :file.txt >expected && + ( + cd subdir && + git rev-parse :../file.txt >result && + test_cmp ../expected result && + git rev-parse :0:../file.txt >result && + test_cmp ../expected result + ) +' + test_expect_success 'incorrect revision id' ' test_must_fail git rev-parse foobar:file.txt 2>error && grep "Invalid object name '"'"'foobar'"'"'." error && @@ -45,7 +113,7 @@ test_expect_success 'incorrect file in sha1:path' ' grep "fatal: Path '"'"'index-only.txt'"'"' exists on disk, but not in '"'"'HEAD'"'"'." error && (cd subdir && test_must_fail git rev-parse HEAD:file2.txt 2> error && - grep "Did you mean '"'"'HEAD:subdir/file2.txt'"'"'?" error ) + test_did_you_mean HEAD subdir/ file2.txt exists ) ' test_expect_success 'incorrect file in :path and :N:path' ' @@ -54,14 +122,14 @@ test_expect_success 'incorrect file in :path and :N:path' ' test_must_fail git rev-parse :1:nothing.txt 2> error && grep "Path '"'"'nothing.txt'"'"' does not exist (neither on disk nor in the index)." error && test_must_fail git rev-parse :1:file.txt 2> error && - grep "Did you mean '"'"':0:file.txt'"'"'?" error && + test_did_you_mean ":0" "" file.txt "is in the index" "at stage 1" && (cd subdir && test_must_fail git rev-parse :1:file.txt 2> error && - grep "Did you mean '"'"':0:file.txt'"'"'?" error && + test_did_you_mean ":0" "" file.txt "is in the index" "at stage 1" && test_must_fail git rev-parse :file2.txt 2> error && - grep "Did you mean '"'"':0:subdir/file2.txt'"'"'?" error && + test_did_you_mean ":0" subdir/ file2.txt "is in the index" && test_must_fail git rev-parse :2:file2.txt 2> error && - grep "Did you mean '"'"':0:subdir/file2.txt'"'"'?" error) && + test_did_you_mean :0 subdir/ file2.txt "is in the index") && test_must_fail git rev-parse :disk-only.txt 2> error && grep "fatal: Path '"'"'disk-only.txt'"'"' exists on disk, but not in the index." error ' @@ -75,4 +143,29 @@ test_expect_success 'invalid @{n} reference' ' grep "fatal: Log for [^ ]* only has [0-9][0-9]* entries." error ' +test_expect_success 'relative path not found' ' + ( + cd subdir && + test_must_fail git rev-parse HEAD:./nonexistent.txt 2>error && + grep subdir/nonexistent.txt error + ) +' + +test_expect_success 'relative path outside worktree' ' + test_must_fail git rev-parse HEAD:../file.txt >output 2>error && + test -z "$(cat output)" && + grep "outside repository" error +' + +test_expect_success 'relative path when cwd is outside worktree' ' + test_must_fail git --git-dir=.git --work-tree=subdir rev-parse HEAD:./file.txt >output 2>error && + test -z "$(cat output)" && + grep "relative path syntax can.t be used outside working tree." error +' + +test_expect_success 'relative path when startup_info is NULL' ' + test_must_fail test-match-trees HEAD:./file.txt HEAD:./file.txt 2>error && + grep "BUG: startup_info struct is not initialized." error +' + test_done diff --git a/t/t1507-rev-parse-upstream.sh b/t/t1507-rev-parse-upstream.sh index 8c8dfdaf9f..a4555510c3 100755 --- a/t/t1507-rev-parse-upstream.sh +++ b/t/t1507-rev-parse-upstream.sh @@ -85,7 +85,7 @@ test_expect_success 'merge my-side@{u} records the correct name' ' git branch -t new my-side@{u} && git merge -s ours new@{u} && git show -s --pretty=format:%s >actual && - echo "Merge remote branch ${sq}origin/side${sq}" >expect && + echo "Merge remote-tracking branch ${sq}origin/side${sq}" >expect && test_cmp expect actual ) ' diff --git a/t/t1509-root-worktree.sh b/t/t1509-root-worktree.sh index 7f60fd0b2e..335420fd87 100755 --- a/t/t1509-root-worktree.sh +++ b/t/t1509-root-worktree.sh @@ -134,8 +134,8 @@ cat >ls.expected <<EOF 100644 $ONE_SHA1 0 me EOF -export GIT_DIR="$TRASH_DIRECTORY/.git" -export GIT_WORK_TREE=/ +GIT_DIR="$TRASH_DIRECTORY/.git" && export GIT_DIR +GIT_WORK_TREE=/ && export GIT_WORK_TREE test_vars 'abs gitdir, root' "$GIT_DIR" "/" "" test_foobar_root @@ -154,24 +154,24 @@ say "GIT_DIR relative, GIT_WORK_TREE set" test_expect_success 'go to /' 'cd /' -export GIT_DIR="$(echo $TRASH_DIRECTORY|sed 's,^/,,')/.git" -export GIT_WORK_TREE=/ +GIT_DIR="$(echo $TRASH_DIRECTORY|sed 's,^/,,')/.git" && export GIT_DIR +GIT_WORK_TREE=/ && export GIT_WORK_TREE test_vars 'rel gitdir, root' "$GIT_DIR" "/" "" test_foobar_root test_expect_success 'go to /foo' 'cd /foo' -export GIT_DIR="../$TRASH_DIRECTORY/.git" -export GIT_WORK_TREE=/ +GIT_DIR="../$TRASH_DIRECTORY/.git" && export GIT_DIR +GIT_WORK_TREE=/ && export GIT_WORK_TREE test_vars 'rel gitdir, foo' "$TRASH_DIRECTORY/.git" "/" "foo/" test_foobar_foo test_expect_success 'go to /foo/bar' 'cd /foo/bar' -export GIT_DIR="../../$TRASH_DIRECTORY/.git" -export GIT_WORK_TREE=/ +GIT_DIR="../../$TRASH_DIRECTORY/.git" && export GIT_DIR +GIT_WORK_TREE=/ && export GIT_WORK_TREE test_vars 'rel gitdir, foo/bar' "$TRASH_DIRECTORY/.git" "/" "foo/bar/" test_foobar_foobar @@ -180,24 +180,24 @@ say "GIT_DIR relative, GIT_WORK_TREE relative" test_expect_success 'go to /' 'cd /' -export GIT_DIR="$(echo $TRASH_DIRECTORY|sed 's,^/,,')/.git" -export GIT_WORK_TREE=. +GIT_DIR="$(echo $TRASH_DIRECTORY|sed 's,^/,,')/.git" && export GIT_DIR +GIT_WORK_TREE=. && export GIT_WORK_TREE test_vars 'rel gitdir, root' "$GIT_DIR" "/" "" test_foobar_root test_expect_success 'go to /' 'cd /foo' -export GIT_DIR="../$TRASH_DIRECTORY/.git" -export GIT_WORK_TREE=.. +GIT_DIR="../$TRASH_DIRECTORY/.git" && export GIT_DIR +GIT_WORK_TREE=.. && export GIT_WORK_TREE test_vars 'rel gitdir, foo' "$TRASH_DIRECTORY/.git" "/" "foo/" test_foobar_foo test_expect_success 'go to /foo/bar' 'cd /foo/bar' -export GIT_DIR="../../$TRASH_DIRECTORY/.git" -export GIT_WORK_TREE=../.. +GIT_DIR="../../$TRASH_DIRECTORY/.git" && export GIT_DIR +GIT_WORK_TREE=../.. && export GIT_WORK_TREE test_vars 'rel gitdir, foo/bar' "$TRASH_DIRECTORY/.git" "/" "foo/bar/" test_foobar_foobar diff --git a/t/t1510-repo-setup.sh b/t/t1510-repo-setup.sh new file mode 100755 index 0000000000..ec50a9ad70 --- /dev/null +++ b/t/t1510-repo-setup.sh @@ -0,0 +1,776 @@ +#!/bin/sh + +test_description="Tests of cwd/prefix/worktree/gitdir setup in all cases + +A few rules for repo setup: + +1. GIT_DIR is relative to user's cwd. --git-dir is equivalent to + GIT_DIR. + +2. .git file is relative to parent directory. .git file is basically + symlink in disguise. The directory where .git file points to will + become new git_dir. + +3. core.worktree is relative to git_dir. + +4. GIT_WORK_TREE is relative to user's cwd. --work-tree is + equivalent to GIT_WORK_TREE. + +5. GIT_WORK_TREE/core.worktree was originally meant to work only if + GIT_DIR is set, but earlier git didn't enforce it, and some scripts + depend on the implementation that happened to first discover .git by + going up from the users $cwd and then using the specified working tree + that may or may not have any relation to where .git was found in. This + historical behaviour must be kept. + +6. Effective GIT_WORK_TREE overrides core.worktree and core.bare + +7. Effective core.worktree conflicts with core.bare + +8. If GIT_DIR is set but neither worktree nor bare setting is given, + original cwd becomes worktree. + +9. If .git discovery is done inside a repo, the repo becomes a bare + repo. .git discovery is performed if GIT_DIR is not set. + +10. If no worktree is available, cwd remains unchanged, prefix is + NULL. + +11. When user's cwd is outside worktree, cwd remains unchanged, + prefix is NULL. +" +. ./test-lib.sh + +here=$(pwd) + +test_repo () { + ( + cd "$1" && + if test -n "$2" + then + GIT_DIR="$2" && + export GIT_DIR + fi && + if test -n "$3" + then + GIT_WORK_TREE="$3" && + export GIT_WORK_TREE + fi && + rm -f trace && + GIT_TRACE_SETUP="$(pwd)/trace" git symbolic-ref HEAD >/dev/null && + grep '^setup: ' trace >result && + test_cmp expected result + ) +} + +maybe_config () { + file=$1 var=$2 value=$3 && + if test "$value" != unset + then + git config --file="$file" "$var" "$value" + fi +} + +setup_repo () { + name=$1 worktreecfg=$2 gitfile=$3 barecfg=$4 && + sane_unset GIT_DIR GIT_WORK_TREE && + + git init "$name" && + maybe_config "$name/.git/config" core.worktree "$worktreecfg" && + maybe_config "$name/.git/config" core.bare "$barecfg" && + mkdir -p "$name/sub/sub" && + + if test "${gitfile:+set}" + then + mv "$name/.git" "$name.git" && + echo "gitdir: ../$name.git" >"$name/.git" + fi +} + +maybe_set () { + var=$1 value=$2 && + if test "$value" != unset + then + eval "$var=\$value" && + export $var + fi +} + +setup_env () { + worktreenv=$1 gitdirenv=$2 && + sane_unset GIT_DIR GIT_WORK_TREE && + maybe_set GIT_DIR "$gitdirenv" && + maybe_set GIT_WORK_TREE "$worktreeenv" +} + +expect () { + cat >"$1/expected" <<-EOF + setup: git_dir: $2 + setup: worktree: $3 + setup: cwd: $4 + setup: prefix: $5 + EOF +} + +try_case () { + name=$1 worktreeenv=$2 gitdirenv=$3 && + setup_env "$worktreeenv" "$gitdirenv" && + expect "$name" "$4" "$5" "$6" "$7" && + test_repo "$name" +} + +run_wt_tests () { + N=$1 gitfile=$2 + + absgit="$here/$N/.git" + dotgit=.git + dotdotgit=../../.git + + if test "$gitfile" + then + absgit="$here/$N.git" + dotgit=$absgit dotdotgit=$absgit + fi + + test_expect_success "#$N: explicit GIT_WORK_TREE and GIT_DIR at toplevel" ' + try_case $N "$here/$N" .git \ + "$dotgit" "$here/$N" "$here/$N" "(null)" && + try_case $N . .git \ + "$dotgit" "$here/$N" "$here/$N" "(null)" && + try_case $N "$here/$N" "$here/$N/.git" \ + "$absgit" "$here/$N" "$here/$N" "(null)" && + try_case $N . "$here/$N/.git" \ + "$absgit" "$here/$N" "$here/$N" "(null)" + ' + + test_expect_success "#$N: explicit GIT_WORK_TREE and GIT_DIR in subdir" ' + try_case $N/sub/sub "$here/$N" ../../.git \ + "$absgit" "$here/$N" "$here/$N" sub/sub/ && + try_case $N/sub/sub ../.. ../../.git \ + "$absgit" "$here/$N" "$here/$N" sub/sub/ && + try_case $N/sub/sub "$here/$N" "$here/$N/.git" \ + "$absgit" "$here/$N" "$here/$N" sub/sub/ && + try_case $N/sub/sub ../.. "$here/$N/.git" \ + "$absgit" "$here/$N" "$here/$N" sub/sub/ + ' + + test_expect_success "#$N: explicit GIT_WORK_TREE from parent of worktree" ' + try_case $N "$here/$N/wt" .git \ + "$dotgit" "$here/$N/wt" "$here/$N" "(null)" && + try_case $N wt .git \ + "$dotgit" "$here/$N/wt" "$here/$N" "(null)" && + try_case $N wt "$here/$N/.git" \ + "$absgit" "$here/$N/wt" "$here/$N" "(null)" && + try_case $N "$here/$N/wt" "$here/$N/.git" \ + "$absgit" "$here/$N/wt" "$here/$N" "(null)" + ' + + test_expect_success "#$N: explicit GIT_WORK_TREE from nephew of worktree" ' + try_case $N/sub/sub "$here/$N/wt" ../../.git \ + "$dotdotgit" "$here/$N/wt" "$here/$N/sub/sub" "(null)" && + try_case $N/sub/sub ../../wt ../../.git \ + "$dotdotgit" "$here/$N/wt" "$here/$N/sub/sub" "(null)" && + try_case $N/sub/sub ../../wt "$here/$N/.git" \ + "$absgit" "$here/$N/wt" "$here/$N/sub/sub" "(null)" && + try_case $N/sub/sub "$here/$N/wt" "$here/$N/.git" \ + "$absgit" "$here/$N/wt" "$here/$N/sub/sub" "(null)" + ' + + test_expect_success "#$N: chdir_to_toplevel uses worktree, not git dir" ' + try_case $N "$here" .git \ + "$absgit" "$here" "$here" $N/ && + try_case $N .. .git \ + "$absgit" "$here" "$here" $N/ && + try_case $N .. "$here/$N/.git" \ + "$absgit" "$here" "$here" $N/ && + try_case $N "$here" "$here/$N/.git" \ + "$absgit" "$here" "$here" $N/ + ' + + test_expect_success "#$N: chdir_to_toplevel uses worktree (from subdir)" ' + try_case $N/sub/sub "$here" ../../.git \ + "$absgit" "$here" "$here" $N/sub/sub/ && + try_case $N/sub/sub ../../.. ../../.git \ + "$absgit" "$here" "$here" $N/sub/sub/ && + try_case $N/sub/sub ../../../ "$here/$N/.git" \ + "$absgit" "$here" "$here" $N/sub/sub/ && + try_case $N/sub/sub "$here" "$here/$N/.git" \ + "$absgit" "$here" "$here" $N/sub/sub/ + ' +} + +# try_repo #c GIT_WORK_TREE GIT_DIR core.worktree .gitfile? core.bare \ +# (git dir) (work tree) (cwd) (prefix) \ <-- at toplevel +# (git dir) (work tree) (cwd) (prefix) <-- from subdir +try_repo () { + name=$1 worktreeenv=$2 gitdirenv=$3 && + setup_repo "$name" "$4" "$5" "$6" && + shift 6 && + try_case "$name" "$worktreeenv" "$gitdirenv" \ + "$1" "$2" "$3" "$4" && + shift 4 && + case "$gitdirenv" in + /* | ?:/* | unset) ;; + *) + gitdirenv=../$gitdirenv ;; + esac && + try_case "$name/sub" "$worktreeenv" "$gitdirenv" \ + "$1" "$2" "$3" "$4" +} + +# Bit 0 = GIT_WORK_TREE +# Bit 1 = GIT_DIR +# Bit 2 = core.worktree +# Bit 3 = .git is a file +# Bit 4 = bare repo +# Case# = encoding of the above 5 bits + +test_expect_success '#0: nonbare repo, no explicit configuration' ' + try_repo 0 unset unset unset "" unset \ + .git "$here/0" "$here/0" "(null)" \ + .git "$here/0" "$here/0" sub/ 2>message && + ! test -s message +' + +test_expect_success '#1: GIT_WORK_TREE without explicit GIT_DIR is accepted' ' + mkdir -p wt && + try_repo 1 "$here" unset unset "" unset \ + "$here/1/.git" "$here" "$here" 1/ \ + "$here/1/.git" "$here" "$here" 1/sub/ 2>message && + ! test -s message +' + +test_expect_success '#2: worktree defaults to cwd with explicit GIT_DIR' ' + try_repo 2 unset "$here/2/.git" unset "" unset \ + "$here/2/.git" "$here/2" "$here/2" "(null)" \ + "$here/2/.git" "$here/2/sub" "$here/2/sub" "(null)" +' + +test_expect_success '#2b: relative GIT_DIR' ' + try_repo 2b unset ".git" unset "" unset \ + ".git" "$here/2b" "$here/2b" "(null)" \ + "../.git" "$here/2b/sub" "$here/2b/sub" "(null)" +' + +test_expect_success '#3: setup' ' + setup_repo 3 unset "" unset && + mkdir -p 3/sub/sub 3/wt/sub +' +run_wt_tests 3 + +test_expect_success '#4: core.worktree without GIT_DIR set is accepted' ' + setup_repo 4 ../sub "" unset && + mkdir -p 4/sub sub && + try_case 4 unset unset \ + .git "$here/4/sub" "$here/4" "(null)" \ + "$here/4/.git" "$here/4/sub" "$here/4/sub" "(null)" 2>message && + ! test -s message +' + +test_expect_success '#5: core.worktree + GIT_WORK_TREE is accepted' ' + # or: you cannot intimidate away the lack of GIT_DIR setting + try_repo 5 "$here" unset "$here/5" "" unset \ + "$here/5/.git" "$here" "$here" 5/ \ + "$here/5/.git" "$here" "$here" 5/sub/ 2>message && + try_repo 5a .. unset "$here/5a" "" unset \ + "$here/5a/.git" "$here" "$here" 5a/ \ + "$here/5a/.git" "$here/5a" "$here/5a" sub/ && + ! test -s message +' + +test_expect_success '#6: setting GIT_DIR brings core.worktree to life' ' + setup_repo 6 "$here/6" "" unset && + try_case 6 unset .git \ + .git "$here/6" "$here/6" "(null)" && + try_case 6 unset "$here/6/.git" \ + "$here/6/.git" "$here/6" "$here/6" "(null)" && + try_case 6/sub/sub unset ../../.git \ + "$here/6/.git" "$here/6" "$here/6" sub/sub/ && + try_case 6/sub/sub unset "$here/6/.git" \ + "$here/6/.git" "$here/6" "$here/6" sub/sub/ +' + +test_expect_success '#6b: GIT_DIR set, core.worktree relative' ' + setup_repo 6b .. "" unset && + try_case 6b unset .git \ + .git "$here/6b" "$here/6b" "(null)" && + try_case 6b unset "$here/6b/.git" \ + "$here/6b/.git" "$here/6b" "$here/6b" "(null)" && + try_case 6b/sub/sub unset ../../.git \ + "$here/6b/.git" "$here/6b" "$here/6b" sub/sub/ && + try_case 6b/sub/sub unset "$here/6b/.git" \ + "$here/6b/.git" "$here/6b" "$here/6b" sub/sub/ +' + +test_expect_success '#6c: GIT_DIR set, core.worktree=../wt (absolute)' ' + setup_repo 6c "$here/6c/wt" "" unset && + mkdir -p 6c/wt/sub && + + try_case 6c unset .git \ + .git "$here/6c/wt" "$here/6c" "(null)" && + try_case 6c unset "$here/6c/.git" \ + "$here/6c/.git" "$here/6c/wt" "$here/6c" "(null)" && + try_case 6c/sub/sub unset ../../.git \ + ../../.git "$here/6c/wt" "$here/6c/sub/sub" "(null)" && + try_case 6c/sub/sub unset "$here/6c/.git" \ + "$here/6c/.git" "$here/6c/wt" "$here/6c/sub/sub" "(null)" +' + +test_expect_success '#6d: GIT_DIR set, core.worktree=../wt (relative)' ' + setup_repo 6d "$here/6d/wt" "" unset && + mkdir -p 6d/wt/sub && + + try_case 6d unset .git \ + .git "$here/6d/wt" "$here/6d" "(null)" && + try_case 6d unset "$here/6d/.git" \ + "$here/6d/.git" "$here/6d/wt" "$here/6d" "(null)" && + try_case 6d/sub/sub unset ../../.git \ + ../../.git "$here/6d/wt" "$here/6d/sub/sub" "(null)" && + try_case 6d/sub/sub unset "$here/6d/.git" \ + "$here/6d/.git" "$here/6d/wt" "$here/6d/sub/sub" "(null)" +' + +test_expect_success '#6e: GIT_DIR set, core.worktree=../.. (absolute)' ' + setup_repo 6e "$here" "" unset && + try_case 6e unset .git \ + "$here/6e/.git" "$here" "$here" 6e/ && + try_case 6e unset "$here/6e/.git" \ + "$here/6e/.git" "$here" "$here" 6e/ && + try_case 6e/sub/sub unset ../../.git \ + "$here/6e/.git" "$here" "$here" 6e/sub/sub/ && + try_case 6e/sub/sub unset "$here/6e/.git" \ + "$here/6e/.git" "$here" "$here" 6e/sub/sub/ +' + +test_expect_success '#6f: GIT_DIR set, core.worktree=../.. (relative)' ' + setup_repo 6f ../../ "" unset && + try_case 6f unset .git \ + "$here/6f/.git" "$here" "$here" 6f/ && + try_case 6f unset "$here/6f/.git" \ + "$here/6f/.git" "$here" "$here" 6f/ && + try_case 6f/sub/sub unset ../../.git \ + "$here/6f/.git" "$here" "$here" 6f/sub/sub/ && + try_case 6f/sub/sub unset "$here/6f/.git" \ + "$here/6f/.git" "$here" "$here" 6f/sub/sub/ +' + +# case #7: GIT_WORK_TREE overrides core.worktree. +test_expect_success '#7: setup' ' + setup_repo 7 non-existent "" unset && + mkdir -p 7/sub/sub 7/wt/sub +' +run_wt_tests 7 + +test_expect_success '#8: gitfile, easy case' ' + try_repo 8 unset unset unset gitfile unset \ + "$here/8.git" "$here/8" "$here/8" "(null)" \ + "$here/8.git" "$here/8" "$here/8" sub/ +' + +test_expect_success '#9: GIT_WORK_TREE accepted with gitfile' ' + mkdir -p 9/wt && + try_repo 9 wt unset unset gitfile unset \ + "$here/9.git" "$here/9/wt" "$here/9" "(null)" \ + "$here/9.git" "$here/9/sub/wt" "$here/9/sub" "(null)" 2>message && + ! test -s message +' + +test_expect_success '#10: GIT_DIR can point to gitfile' ' + try_repo 10 unset "$here/10/.git" unset gitfile unset \ + "$here/10.git" "$here/10" "$here/10" "(null)" \ + "$here/10.git" "$here/10/sub" "$here/10/sub" "(null)" +' + +test_expect_success '#10b: relative GIT_DIR can point to gitfile' ' + try_repo 10b unset .git unset gitfile unset \ + "$here/10b.git" "$here/10b" "$here/10b" "(null)" \ + "$here/10b.git" "$here/10b/sub" "$here/10b/sub" "(null)" +' + +# case #11: GIT_WORK_TREE works, gitfile case. +test_expect_success '#11: setup' ' + setup_repo 11 unset gitfile unset && + mkdir -p 11/sub/sub 11/wt/sub +' +run_wt_tests 11 gitfile + +test_expect_success '#12: core.worktree with gitfile is accepted' ' + try_repo 12 unset unset "$here/12" gitfile unset \ + "$here/12.git" "$here/12" "$here/12" "(null)" \ + "$here/12.git" "$here/12" "$here/12" sub/ 2>message && + ! test -s message +' + +test_expect_success '#13: core.worktree+GIT_WORK_TREE accepted (with gitfile)' ' + # or: you cannot intimidate away the lack of GIT_DIR setting + try_repo 13 non-existent-too unset non-existent gitfile unset \ + "$here/13.git" "$here/13/non-existent-too" "$here/13" "(null)" \ + "$here/13.git" "$here/13/sub/non-existent-too" "$here/13/sub" "(null)" 2>message && + ! test -s message +' + +# case #14. +# If this were more table-driven, it could share code with case #6. + +test_expect_success '#14: core.worktree with GIT_DIR pointing to gitfile' ' + setup_repo 14 "$here/14" gitfile unset && + try_case 14 unset .git \ + "$here/14.git" "$here/14" "$here/14" "(null)" && + try_case 14 unset "$here/14/.git" \ + "$here/14.git" "$here/14" "$here/14" "(null)" && + try_case 14/sub/sub unset ../../.git \ + "$here/14.git" "$here/14" "$here/14" sub/sub/ && + try_case 14/sub/sub unset "$here/14/.git" \ + "$here/14.git" "$here/14" "$here/14" sub/sub/ && + + setup_repo 14c "$here/14c/wt" gitfile unset && + mkdir -p 14c/wt/sub && + + try_case 14c unset .git \ + "$here/14c.git" "$here/14c/wt" "$here/14c" "(null)" && + try_case 14c unset "$here/14c/.git" \ + "$here/14c.git" "$here/14c/wt" "$here/14c" "(null)" && + try_case 14c/sub/sub unset ../../.git \ + "$here/14c.git" "$here/14c/wt" "$here/14c/sub/sub" "(null)" && + try_case 14c/sub/sub unset "$here/14c/.git" \ + "$here/14c.git" "$here/14c/wt" "$here/14c/sub/sub" "(null)" && + + setup_repo 14d "$here/14d/wt" gitfile unset && + mkdir -p 14d/wt/sub && + + try_case 14d unset .git \ + "$here/14d.git" "$here/14d/wt" "$here/14d" "(null)" && + try_case 14d unset "$here/14d/.git" \ + "$here/14d.git" "$here/14d/wt" "$here/14d" "(null)" && + try_case 14d/sub/sub unset ../../.git \ + "$here/14d.git" "$here/14d/wt" "$here/14d/sub/sub" "(null)" && + try_case 14d/sub/sub unset "$here/14d/.git" \ + "$here/14d.git" "$here/14d/wt" "$here/14d/sub/sub" "(null)" && + + setup_repo 14e "$here" gitfile unset && + try_case 14e unset .git \ + "$here/14e.git" "$here" "$here" 14e/ && + try_case 14e unset "$here/14e/.git" \ + "$here/14e.git" "$here" "$here" 14e/ && + try_case 14e/sub/sub unset ../../.git \ + "$here/14e.git" "$here" "$here" 14e/sub/sub/ && + try_case 14e/sub/sub unset "$here/14e/.git" \ + "$here/14e.git" "$here" "$here" 14e/sub/sub/ +' + +test_expect_success '#14b: core.worktree is relative to actual git dir' ' + setup_repo 14b ../14b gitfile unset && + try_case 14b unset .git \ + "$here/14b.git" "$here/14b" "$here/14b" "(null)" && + try_case 14b unset "$here/14b/.git" \ + "$here/14b.git" "$here/14b" "$here/14b" "(null)" && + try_case 14b/sub/sub unset ../../.git \ + "$here/14b.git" "$here/14b" "$here/14b" sub/sub/ && + try_case 14b/sub/sub unset "$here/14b/.git" \ + "$here/14b.git" "$here/14b" "$here/14b" sub/sub/ && + + setup_repo 14f ../ gitfile unset && + try_case 14f unset .git \ + "$here/14f.git" "$here" "$here" 14f/ && + try_case 14f unset "$here/14f/.git" \ + "$here/14f.git" "$here" "$here" 14f/ && + try_case 14f/sub/sub unset ../../.git \ + "$here/14f.git" "$here" "$here" 14f/sub/sub/ && + try_case 14f/sub/sub unset "$here/14f/.git" \ + "$here/14f.git" "$here" "$here" 14f/sub/sub/ +' + +# case #15: GIT_WORK_TREE overrides core.worktree (gitfile case). +test_expect_success '#15: setup' ' + setup_repo 15 non-existent gitfile unset && + mkdir -p 15/sub/sub 15/wt/sub +' +run_wt_tests 15 gitfile + +test_expect_success '#16a: implicitly bare repo (cwd inside .git dir)' ' + setup_repo 16a unset "" unset && + mkdir -p 16a/.git/wt/sub && + + try_case 16a/.git unset unset \ + . "(null)" "$here/16a/.git" "(null)" && + try_case 16a/.git/wt unset unset \ + "$here/16a/.git" "(null)" "$here/16a/.git/wt" "(null)" && + try_case 16a/.git/wt/sub unset unset \ + "$here/16a/.git" "(null)" "$here/16a/.git/wt/sub" "(null)" +' + +test_expect_success '#16b: bare .git (cwd inside .git dir)' ' + setup_repo 16b unset "" true && + mkdir -p 16b/.git/wt/sub && + + try_case 16b/.git unset unset \ + . "(null)" "$here/16b/.git" "(null)" && + try_case 16b/.git/wt unset unset \ + "$here/16b/.git" "(null)" "$here/16b/.git/wt" "(null)" && + try_case 16b/.git/wt/sub unset unset \ + "$here/16b/.git" "(null)" "$here/16b/.git/wt/sub" "(null)" +' + +test_expect_success '#16c: bare .git has no worktree' ' + try_repo 16c unset unset unset "" true \ + .git "(null)" "$here/16c" "(null)" \ + "$here/16c/.git" "(null)" "$here/16c/sub" "(null)" +' + +test_expect_success '#17: GIT_WORK_TREE without explicit GIT_DIR is accepted (bare case)' ' + # Just like #16. + setup_repo 17a unset "" true && + setup_repo 17b unset "" true && + mkdir -p 17a/.git/wt/sub && + mkdir -p 17b/.git/wt/sub && + + try_case 17a/.git "$here/17a" unset \ + "$here/17a/.git" "$here/17a" "$here/17a" .git/ \ + 2>message && + try_case 17a/.git/wt "$here/17a" unset \ + "$here/17a/.git" "$here/17a" "$here/17a" .git/wt/ && + try_case 17a/.git/wt/sub "$here/17a" unset \ + "$here/17a/.git" "$here/17a" "$here/17a" .git/wt/sub/ && + + try_case 17b/.git "$here/17b" unset \ + "$here/17b/.git" "$here/17b" "$here/17b" .git/ && + try_case 17b/.git/wt "$here/17b" unset \ + "$here/17b/.git" "$here/17b" "$here/17b" .git/wt/ && + try_case 17b/.git/wt/sub "$here/17b" unset \ + "$here/17b/.git" "$here/17b" "$here/17b" .git/wt/sub/ && + + try_repo 17c "$here/17c" unset unset "" true \ + .git "$here/17c" "$here/17c" "(null)" \ + "$here/17c/.git" "$here/17c" "$here/17c" sub/ 2>message && + ! test -s message +' + +test_expect_success '#18: bare .git named by GIT_DIR has no worktree' ' + try_repo 18 unset .git unset "" true \ + .git "(null)" "$here/18" "(null)" \ + ../.git "(null)" "$here/18/sub" "(null)" && + try_repo 18b unset "$here/18b/.git" unset "" true \ + "$here/18b/.git" "(null)" "$here/18b" "(null)" \ + "$here/18b/.git" "(null)" "$here/18b/sub" "(null)" +' + +# Case #19: GIT_DIR + GIT_WORK_TREE suppresses bareness. +test_expect_success '#19: setup' ' + setup_repo 19 unset "" true && + mkdir -p 19/sub/sub 19/wt/sub +' +run_wt_tests 19 + +test_expect_success '#20a: core.worktree without GIT_DIR accepted (inside .git)' ' + # Unlike case #16a. + setup_repo 20a "$here/20a" "" unset && + mkdir -p 20a/.git/wt/sub && + try_case 20a/.git unset unset \ + "$here/20a/.git" "$here/20a" "$here/20a" .git/ 2>message && + try_case 20a/.git/wt unset unset \ + "$here/20a/.git" "$here/20a" "$here/20a" .git/wt/ && + try_case 20a/.git/wt/sub unset unset \ + "$here/20a/.git" "$here/20a" "$here/20a" .git/wt/sub/ && + ! test -s message +' + +test_expect_success '#20b/c: core.worktree and core.bare conflict' ' + setup_repo 20b non-existent "" true && + mkdir -p 20b/.git/wt/sub && + ( + cd 20b/.git && + test_must_fail git symbolic-ref HEAD >/dev/null + ) 2>message && + grep "core.bare and core.worktree" message +' + +# Case #21: core.worktree/GIT_WORK_TREE overrides core.bare' ' +test_expect_success '#21: setup, core.worktree warns before overriding core.bare' ' + setup_repo 21 non-existent "" unset && + mkdir -p 21/.git/wt/sub && + ( + cd 21/.git && + GIT_WORK_TREE="$here/21" && + export GIT_WORK_TREE && + git symbolic-ref HEAD >/dev/null + ) 2>message && + ! test -s message + +' +run_wt_tests 21 + +test_expect_success '#22a: core.worktree = GIT_DIR = .git dir' ' + # like case #6. + + setup_repo 22a "$here/22a/.git" "" unset && + setup_repo 22ab . "" unset + mkdir -p 22a/.git/sub 22a/sub && + mkdir -p 22ab/.git/sub 22ab/sub && + try_case 22a/.git unset . \ + . "$here/22a/.git" "$here/22a/.git" "(null)" && + try_case 22a/.git unset "$here/22a/.git" \ + "$here/22a/.git" "$here/22a/.git" "$here/22a/.git" "(null)" && + try_case 22a/.git/sub unset .. \ + "$here/22a/.git" "$here/22a/.git" "$here/22a/.git" sub/ && + try_case 22a/.git/sub unset "$here/22a/.git" \ + "$here/22a/.git" "$here/22a/.git" "$here/22a/.git" sub/ && + + try_case 22ab/.git unset . \ + . "$here/22ab/.git" "$here/22ab/.git" "(null)" && + try_case 22ab/.git unset "$here/22ab/.git" \ + "$here/22ab/.git" "$here/22ab/.git" "$here/22ab/.git" "(null)" && + try_case 22ab/.git/sub unset .. \ + "$here/22ab/.git" "$here/22ab/.git" "$here/22ab/.git" sub/ && + try_case 22ab/.git unset "$here/22ab/.git" \ + "$here/22ab/.git" "$here/22ab/.git" "$here/22ab/.git" "(null)" +' + +test_expect_success '#22b: core.worktree child of .git, GIT_DIR=.git' ' + setup_repo 22b "$here/22b/.git/wt" "" unset && + setup_repo 22bb wt "" unset && + mkdir -p 22b/.git/sub 22b/sub 22b/.git/wt/sub 22b/wt/sub && + mkdir -p 22bb/.git/sub 22bb/sub 22bb/.git/wt 22bb/wt && + + try_case 22b/.git unset . \ + . "$here/22b/.git/wt" "$here/22b/.git" "(null)" && + try_case 22b/.git unset "$here/22b/.git" \ + "$here/22b/.git" "$here/22b/.git/wt" "$here/22b/.git" "(null)" && + try_case 22b/.git/sub unset .. \ + .. "$here/22b/.git/wt" "$here/22b/.git/sub" "(null)" && + try_case 22b/.git/sub unset "$here/22b/.git" \ + "$here/22b/.git" "$here/22b/.git/wt" "$here/22b/.git/sub" "(null)" && + + try_case 22bb/.git unset . \ + . "$here/22bb/.git/wt" "$here/22bb/.git" "(null)" && + try_case 22bb/.git unset "$here/22bb/.git" \ + "$here/22bb/.git" "$here/22bb/.git/wt" "$here/22bb/.git" "(null)" && + try_case 22bb/.git/sub unset .. \ + .. "$here/22bb/.git/wt" "$here/22bb/.git/sub" "(null)" && + try_case 22bb/.git/sub unset "$here/22bb/.git" \ + "$here/22bb/.git" "$here/22bb/.git/wt" "$here/22bb/.git/sub" "(null)" +' + +test_expect_success '#22c: core.worktree = .git/.., GIT_DIR=.git' ' + setup_repo 22c "$here/22c" "" unset && + setup_repo 22cb .. "" unset && + mkdir -p 22c/.git/sub 22c/sub && + mkdir -p 22cb/.git/sub 22cb/sub && + + try_case 22c/.git unset . \ + "$here/22c/.git" "$here/22c" "$here/22c" .git/ && + try_case 22c/.git unset "$here/22c/.git" \ + "$here/22c/.git" "$here/22c" "$here/22c" .git/ && + try_case 22c/.git/sub unset .. \ + "$here/22c/.git" "$here/22c" "$here/22c" .git/sub/ && + try_case 22c/.git/sub unset "$here/22c/.git" \ + "$here/22c/.git" "$here/22c" "$here/22c" .git/sub/ && + + try_case 22cb/.git unset . \ + "$here/22cb/.git" "$here/22cb" "$here/22cb" .git/ && + try_case 22cb/.git unset "$here/22cb/.git" \ + "$here/22cb/.git" "$here/22cb" "$here/22cb" .git/ && + try_case 22cb/.git/sub unset .. \ + "$here/22cb/.git" "$here/22cb" "$here/22cb" .git/sub/ && + try_case 22cb/.git/sub unset "$here/22cb/.git" \ + "$here/22cb/.git" "$here/22cb" "$here/22cb" .git/sub/ +' + +test_expect_success '#22.2: core.worktree and core.bare conflict' ' + setup_repo 22 "$here/22" "" true && + ( + cd 22/.git && + GIT_DIR=. && + export GIT_DIR && + test_must_fail git symbolic-ref HEAD 2>result + ) && + ( + cd 22 && + GIT_DIR=.git && + export GIT_DIR && + test_must_fail git symbolic-ref HEAD 2>result + ) && + grep "core.bare and core.worktree" 22/.git/result && + grep "core.bare and core.worktree" 22/result +' + +# Case #23: GIT_DIR + GIT_WORK_TREE(+core.worktree) suppresses bareness. +test_expect_success '#23: setup' ' + setup_repo 23 non-existent "" true && + mkdir -p 23/sub/sub 23/wt/sub +' +run_wt_tests 23 + +test_expect_success '#24: bare repo has no worktree (gitfile case)' ' + try_repo 24 unset unset unset gitfile true \ + "$here/24.git" "(null)" "$here/24" "(null)" \ + "$here/24.git" "(null)" "$here/24/sub" "(null)" +' + +test_expect_success '#25: GIT_WORK_TREE accepted if GIT_DIR unset (bare gitfile case)' ' + try_repo 25 "$here/25" unset unset gitfile true \ + "$here/25.git" "$here/25" "$here/25" "(null)" \ + "$here/25.git" "$here/25" "$here/25" "sub/" 2>message && + ! test -s message +' + +test_expect_success '#26: bare repo has no worktree (GIT_DIR -> gitfile case)' ' + try_repo 26 unset "$here/26/.git" unset gitfile true \ + "$here/26.git" "(null)" "$here/26" "(null)" \ + "$here/26.git" "(null)" "$here/26/sub" "(null)" && + try_repo 26b unset .git unset gitfile true \ + "$here/26b.git" "(null)" "$here/26b" "(null)" \ + "$here/26b.git" "(null)" "$here/26b/sub" "(null)" +' + +# Case #27: GIT_DIR + GIT_WORK_TREE suppresses bareness (with gitfile). +test_expect_success '#27: setup' ' + setup_repo 27 unset gitfile true && + mkdir -p 27/sub/sub 27/wt/sub +' +run_wt_tests 27 gitfile + +test_expect_success '#28: core.worktree and core.bare conflict (gitfile case)' ' + setup_repo 28 "$here/28" gitfile true && + ( + cd 28 && + test_must_fail git symbolic-ref HEAD + ) 2>message && + ! grep "^warning:" message && + grep "core.bare and core.worktree" message +' + +# Case #29: GIT_WORK_TREE(+core.worktree) overrides core.bare (gitfile case). +test_expect_success '#29: setup' ' + setup_repo 29 non-existent gitfile true && + mkdir -p 29/sub/sub 29/wt/sub + ( + cd 29 && + GIT_WORK_TREE="$here/29" && + export GIT_WORK_TREE && + git symbolic-ref HEAD >/dev/null + ) 2>message && + ! test -s message +' +run_wt_tests 29 gitfile + +test_expect_success '#30: core.worktree and core.bare conflict (gitfile version)' ' + # Just like case #22. + setup_repo 30 "$here/30" gitfile true && + ( + cd 30 && + GIT_DIR=.git && + export GIT_DIR && + test_must_fail git symbolic-ref HEAD 2>result + ) && + grep "core.bare and core.worktree" 30/result +' + +# Case #31: GIT_DIR + GIT_WORK_TREE(+core.worktree) suppresses +# bareness (gitfile version). +test_expect_success '#31: setup' ' + setup_repo 31 non-existent gitfile true && + mkdir -p 31/sub/sub 31/wt/sub +' +run_wt_tests 31 gitfile + +test_done diff --git a/t/t1511-rev-parse-caret.sh b/t/t1511-rev-parse-caret.sh new file mode 100755 index 0000000000..e043cb7c64 --- /dev/null +++ b/t/t1511-rev-parse-caret.sh @@ -0,0 +1,73 @@ +#!/bin/sh + +test_description='tests for ref^{stuff}' + +. ./test-lib.sh + +test_expect_success 'setup' ' + echo blob >a-blob && + git tag -a -m blob blob-tag `git hash-object -w a-blob` + mkdir a-tree && + echo moreblobs >a-tree/another-blob && + git add . && + TREE_SHA1=`git write-tree` && + git tag -a -m tree tree-tag "$TREE_SHA1" && + git commit -m Initial && + git tag -a -m commit commit-tag && + git branch ref && + git checkout master && + echo modified >>a-blob && + git add -u && + git commit -m Modified +' + +test_expect_success 'ref^{non-existent}' ' + test_must_fail git rev-parse ref^{non-existent} +' + +test_expect_success 'ref^{}' ' + git rev-parse ref >expected && + git rev-parse ref^{} >actual && + test_cmp expected actual && + git rev-parse commit-tag^{} >actual && + test_cmp expected actual +' + +test_expect_success 'ref^{commit}' ' + git rev-parse ref >expected && + git rev-parse ref^{commit} >actual && + test_cmp expected actual && + git rev-parse commit-tag^{commit} >actual && + test_cmp expected actual && + test_must_fail git rev-parse tree-tag^{commit} && + test_must_fail git rev-parse blob-tag^{commit} +' + +test_expect_success 'ref^{tree}' ' + echo $TREE_SHA1 >expected && + git rev-parse ref^{tree} >actual && + test_cmp expected actual && + git rev-parse commit-tag^{tree} >actual && + test_cmp expected actual && + git rev-parse tree-tag^{tree} >actual && + test_cmp expected actual && + test_must_fail git rev-parse blob-tag^{tree} +' + +test_expect_success 'ref^{/.}' ' + git rev-parse master >expected && + git rev-parse master^{/.} >actual && + test_cmp expected actual +' + +test_expect_success 'ref^{/non-existent}' ' + test_must_fail git rev-parse master^{/non-existent} +' + +test_expect_success 'ref^{/Initial}' ' + git rev-parse ref >expected && + git rev-parse master^{/Initial} >actual && + test_cmp expected actual +' + +test_done diff --git a/t/t2006-checkout-index-basic.sh b/t/t2006-checkout-index-basic.sh new file mode 100755 index 0000000000..b8559838b1 --- /dev/null +++ b/t/t2006-checkout-index-basic.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +test_description='basic checkout-index tests +' + +. ./test-lib.sh + +test_expect_success 'checkout-index --gobbledegook' ' + test_expect_code 129 git checkout-index --gobbledegook 2>err && + grep "[Uu]sage" err +' + +test_expect_success 'checkout-index -h in broken repository' ' + mkdir broken && + ( + cd broken && + git init && + >.git/index && + test_expect_code 129 git checkout-index -h >usage 2>&1 + ) && + grep "[Uu]sage" broken/usage +' + +test_done diff --git a/t/t2007-checkout-symlink.sh b/t/t2007-checkout-symlink.sh index a74ee227b8..e6f59f1914 100755 --- a/t/t2007-checkout-symlink.sh +++ b/t/t2007-checkout-symlink.sh @@ -17,7 +17,7 @@ test_expect_success SYMLINKS setup ' git branch side && echo goodbye >nitfol && - git add nitfol + git add nitfol && test_tick && git commit -m "master adds file nitfol" && diff --git a/t/t2016-checkout-patch.sh b/t/t2016-checkout-patch.sh index a463b13b27..9cd0ac4ba3 100755 --- a/t/t2016-checkout-patch.sh +++ b/t/t2016-checkout-patch.sh @@ -32,7 +32,7 @@ test_expect_success PERL 'git checkout -p' ' ' test_expect_success PERL 'git checkout -p with staged changes' ' - set_state dir/foo work index + set_state dir/foo work index && (echo n; echo y) | git checkout -p && verify_saved_state bar && verify_state dir/foo index index diff --git a/t/t2017-checkout-orphan.sh b/t/t2017-checkout-orphan.sh index 2d2f63f22e..0e3b8582f2 100755 --- a/t/t2017-checkout-orphan.sh +++ b/t/t2017-checkout-orphan.sh @@ -14,7 +14,7 @@ TEST_FILE=foo test_expect_success 'Setup' ' echo "Initial" >"$TEST_FILE" && git add "$TEST_FILE" && - git commit -m "First Commit" + git commit -m "First Commit" && test_tick && echo "State 1" >>"$TEST_FILE" && git add "$TEST_FILE" && diff --git a/t/t2019-checkout-ambiguous-ref.sh b/t/t2019-checkout-ambiguous-ref.sh new file mode 100755 index 0000000000..cc34e5535b --- /dev/null +++ b/t/t2019-checkout-ambiguous-ref.sh @@ -0,0 +1,59 @@ +#!/bin/sh + +test_description='checkout handling of ambiguous (branch/tag) refs' +. ./test-lib.sh + +test_expect_success 'setup ambiguous refs' ' + test_commit branch file && + git branch ambiguity && + git branch vagueness && + test_commit tag file && + git tag ambiguity && + git tag vagueness HEAD:file && + test_commit other file +' + +test_expect_success 'checkout ambiguous ref succeeds' ' + git checkout ambiguity >stdout 2>stderr +' + +test_expect_success 'checkout produces ambiguity warning' ' + grep "warning.*ambiguous" stderr +' + +test_expect_success 'checkout chooses branch over tag' ' + echo refs/heads/ambiguity >expect && + git symbolic-ref HEAD >actual && + test_cmp expect actual && + echo branch >expect && + test_cmp expect file +' + +test_expect_success C_LOCALE_OUTPUT 'checkout reports switch to branch' ' + grep "Switched to branch" stderr && + ! grep "^HEAD is now at" stderr +' + +test_expect_success 'checkout vague ref succeeds' ' + git checkout vagueness >stdout 2>stderr && + test_set_prereq VAGUENESS_SUCCESS +' + +test_expect_success VAGUENESS_SUCCESS 'checkout produces ambiguity warning' ' + grep "warning.*ambiguous" stderr +' + +test_expect_success VAGUENESS_SUCCESS 'checkout chooses branch over tag' ' + echo refs/heads/vagueness >expect && + git symbolic-ref HEAD >actual && + test_cmp expect actual && + echo branch >expect && + test_cmp expect file +' + +test_expect_success VAGUENESS_SUCCESS,C_LOCALE_OUTPUT 'checkout reports switch to branch' ' + grep "Switched to branch" stderr && + ! grep "^HEAD is now at" stderr +' + +test_done diff --git a/t/t2020-checkout-detach.sh b/t/t2020-checkout-detach.sh new file mode 100755 index 0000000000..569b27fe8d --- /dev/null +++ b/t/t2020-checkout-detach.sh @@ -0,0 +1,142 @@ +#!/bin/sh + +test_description='checkout into detached HEAD state' +. ./test-lib.sh + +check_detached () { + test_must_fail git symbolic-ref -q HEAD >/dev/null +} + +check_not_detached () { + git symbolic-ref -q HEAD >/dev/null +} + +ORPHAN_WARNING='you are leaving .* commit.*behind' +check_orphan_warning() { + grep "$ORPHAN_WARNING" "$1" +} +check_no_orphan_warning() { + ! grep "$ORPHAN_WARNING" "$1" +} + +reset () { + git checkout master && + check_not_detached +} + +test_expect_success 'setup' ' + test_commit one && + test_commit two && + test_commit three && git tag -d three && + test_commit four && git tag -d four && + git branch branch && + git tag tag +' + +test_expect_success 'checkout branch does not detach' ' + reset && + git checkout branch && + check_not_detached +' + +test_expect_success 'checkout tag detaches' ' + reset && + git checkout tag && + check_detached +' + +test_expect_success 'checkout branch by full name detaches' ' + reset && + git checkout refs/heads/branch && + check_detached +' + +test_expect_success 'checkout non-ref detaches' ' + reset && + git checkout branch^ && + check_detached +' + +test_expect_success 'checkout ref^0 detaches' ' + reset && + git checkout branch^0 && + check_detached +' + +test_expect_success 'checkout --detach detaches' ' + reset && + git checkout --detach branch && + check_detached +' + +test_expect_success 'checkout --detach without branch name' ' + reset && + git checkout --detach && + check_detached +' + +test_expect_success 'checkout --detach errors out for non-commit' ' + reset && + test_must_fail git checkout --detach one^{tree} && + check_not_detached +' + +test_expect_success 'checkout --detach errors out for extra argument' ' + reset && + git checkout master && + test_must_fail git checkout --detach tag one.t && + check_not_detached +' + +test_expect_success 'checkout --detached and -b are incompatible' ' + reset && + test_must_fail git checkout --detach -b newbranch tag && + check_not_detached +' + +test_expect_success 'checkout --detach moves HEAD' ' + reset && + git checkout one && + git checkout --detach two && + git diff --exit-code HEAD && + git diff --exit-code two +' + +test_expect_success 'checkout warns on orphan commits' ' + reset && + git checkout --detach two && + echo content >orphan && + git add orphan && + git commit -a -m orphan && + git checkout master 2>stderr && + check_orphan_warning stderr +' + +test_expect_success 'checkout does not warn leaving ref tip' ' + reset && + git checkout --detach two && + git checkout master 2>stderr && + check_no_orphan_warning stderr +' + +test_expect_success 'checkout does not warn leaving reachable commit' ' + reset && + git checkout --detach HEAD^ && + git checkout master 2>stderr && + check_no_orphan_warning stderr +' + +cat >expect <<'EOF' +Your branch is behind 'master' by 1 commit, and can be fast-forwarded. +EOF +test_expect_success 'tracking count is accurate after orphan check' ' + reset && + git branch child master^ && + git config branch.child.remote . && + git config branch.child.merge refs/heads/master && + git checkout child^ && + git checkout child >stdout && + test_cmp expect stdout +' + +test_done diff --git a/t/t2021-checkout-overwrite.sh b/t/t2021-checkout-overwrite.sh new file mode 100755 index 0000000000..5da63e9fa2 --- /dev/null +++ b/t/t2021-checkout-overwrite.sh @@ -0,0 +1,50 @@ +#!/bin/sh + +test_description='checkout must not overwrite an untracked objects' +. ./test-lib.sh + +test_expect_success 'setup' ' + + mkdir -p a/b/c && + >a/b/c/d && + git add -A && + git commit -m base && + git tag start +' + +test_expect_success 'create a commit where dir a/b changed to file' ' + + git checkout -b file && + rm -rf a/b && + >a/b && + git add -A && + git commit -m "dir to file" +' + +test_expect_success 'checkout commit with dir must not remove untracked a/b' ' + + git rm --cached a/b && + git commit -m "un-track the file" && + test_must_fail git checkout start && + test -f a/b +' + +test_expect_success SYMLINKS 'create a commit where dir a/b changed to symlink' ' + + rm -rf a/b && # cleanup if previous test failed + git checkout -f -b symlink start && + rm -rf a/b && + ln -s foo a/b && + git add -A && + git commit -m "dir to symlink" +' + +test_expect_success SYMLINKS 'checkout commit with dir must not remove untracked a/b' ' + + git rm --cached a/b && + git commit -m "un-track the symlink" && + test_must_fail git checkout start && + test -h a/b +' + +test_done diff --git a/t/t2050-git-dir-relative.sh b/t/t2050-git-dir-relative.sh index b7131d8c08..21f4659a9d 100755 --- a/t/t2050-git-dir-relative.sh +++ b/t/t2050-git-dir-relative.sh @@ -26,7 +26,7 @@ chmod +x .git/hooks/post-commit' test_expect_success 'post-commit hook used ordinarily' ' echo initial >top && -git add top +git add top && git commit -m initial && test -r "${COMMIT_FILE}" ' @@ -45,7 +45,7 @@ test -r "${COMMIT_FILE}" rm -rf "${COMMIT_FILE}" test_expect_success 'post-commit-hook from sub dir' ' -echo changed again >top +echo changed again >top && cd subdir && git --git-dir .git --work-tree .. add ../top && git --git-dir .git --work-tree .. commit -m subcommit && diff --git a/t/t2101-update-index-reupdate.sh b/t/t2101-update-index-reupdate.sh index 76ad7c344c..c8bce8c2e4 100755 --- a/t/t2101-update-index-reupdate.sh +++ b/t/t2101-update-index-reupdate.sh @@ -51,7 +51,7 @@ test_expect_success 'update-index again' \ echo hello world >dir1/file3 && echo goodbye people >file2 && git update-index --add file2 dir1/file3 && - echo hello everybody >file2 + echo hello everybody >file2 && echo happy >dir1/file3 && git update-index --again && git ls-files -s >current && diff --git a/t/t2107-update-index-basic.sh b/t/t2107-update-index-basic.sh new file mode 100755 index 0000000000..809fafe208 --- /dev/null +++ b/t/t2107-update-index-basic.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +test_description='basic update-index tests + +Tests for command-line parsing and basic operation. +' + +. ./test-lib.sh + +test_expect_success 'update-index --nonsense fails' ' + test_must_fail git update-index --nonsense 2>msg && + cat msg && + test -s msg +' + +test_expect_success 'update-index --nonsense dumps usage' ' + test_expect_code 129 git update-index --nonsense 2>err && + grep "[Uu]sage: git update-index" err +' + +test_expect_success 'update-index -h with corrupt index' ' + mkdir broken && + ( + cd broken && + git init && + >.git/index && + test_expect_code 129 git update-index -h >usage 2>&1 + ) && + grep "[Uu]sage: git update-index" broken/usage +' + +test_done diff --git a/t/t2200-add-update.sh b/t/t2200-add-update.sh index 2ad2819a34..856e7da1f2 100755 --- a/t/t2200-add-update.sh +++ b/t/t2200-add-update.sh @@ -25,7 +25,7 @@ test_expect_success setup ' echo initial >dir1/sub2 && echo initial >dir2/sub3 && git add check dir1 dir2 top foo && - test_tick + test_tick && git commit -m initial && echo changed >check && @@ -111,7 +111,7 @@ test_expect_success 'touch and then add explicitly' ' ' -test_expect_success 'add -n -u should not add but just report' ' +test_expect_success C_LOCALE_OUTPUT 'add -n -u should not add but just report' ' ( echo "add '\''check'\''" && diff --git a/t/t2204-add-ignored.sh b/t/t2204-add-ignored.sh index 24afdabab7..49753362f0 100755 --- a/t/t2204-add-ignored.sh +++ b/t/t2204-add-ignored.sh @@ -31,18 +31,21 @@ do rm -f .git/index && test_must_fail git add "$i" 2>err && git ls-files "$i" >out && - ! test -s out && - grep -e "Use -f if" err && - cat err + ! test -s out + ' + + test_expect_success C_LOCALE_OUTPUT "complaints for ignored $i output" ' + grep -e "Use -f if" err ' test_expect_success "complaints for ignored $i with unignored file" ' rm -f .git/index && test_must_fail git add "$i" file 2>err && git ls-files "$i" >out && - ! test -s out && - grep -e "Use -f if" err && - cat err + ! test -s out + ' + test_expect_success C_LOCALE_OUTPUT "complaints for ignored $i with unignored file output" ' + grep -e "Use -f if" err ' done @@ -54,9 +57,14 @@ do cd dir && test_must_fail git add "$i" 2>err && git ls-files "$i" >out && - ! test -s out && - grep -e "Use -f if" err && - cat err + ! test -s out + ) + ' + + test_expect_success C_LOCALE_OUTPUT "complaints for ignored $i in dir output" ' + ( + cd dir && + grep -e "Use -f if" err ) ' done @@ -69,9 +77,14 @@ do cd sub && test_must_fail git add "$i" 2>err && git ls-files "$i" >out && - ! test -s out && - grep -e "Use -f if" err && - cat err + ! test -s out + ) + ' + + test_expect_success C_LOCALE_OUTPUT "complaints for ignored $i in sub output" ' + ( + cd sub && + grep -e "Use -f if" err ) ' done diff --git a/t/t3001-ls-files-others-exclude.sh b/t/t3001-ls-files-others-exclude.sh index 6d2f2b67ee..c8fe978267 100755 --- a/t/t3001-ls-files-others-exclude.sh +++ b/t/t3001-ls-files-others-exclude.sh @@ -156,7 +156,7 @@ test_expect_success 'trailing slash in exclude allows directory match (2)' ' test_expect_success 'trailing slash in exclude forces directory match (1)' ' - >two + >two && git ls-files --others --exclude=two/ >output && grep "^two" output diff --git a/t/t3004-ls-files-basic.sh b/t/t3004-ls-files-basic.sh new file mode 100755 index 0000000000..490e052875 --- /dev/null +++ b/t/t3004-ls-files-basic.sh @@ -0,0 +1,39 @@ +#!/bin/sh + +test_description='basic ls-files tests + +This test runs git ls-files with various unusual or malformed +command-line arguments. +' + +. ./test-lib.sh + +>empty + +test_expect_success 'ls-files in empty repository' ' + git ls-files >actual && + test_cmp empty actual +' + +test_expect_success 'ls-files with nonexistent path' ' + git ls-files doesnotexist >actual && + test_cmp empty actual +' + +test_expect_success 'ls-files with nonsense option' ' + test_expect_code 129 git ls-files --nonsense 2>actual && + grep "[Uu]sage: git ls-files" actual +' + +test_expect_success 'ls-files -h in corrupt repository' ' + mkdir broken && + ( + cd broken && + git init && + >.git/index && + test_expect_code 129 git ls-files -h >usage 2>&1 + ) && + grep "[Uu]sage: git ls-files " broken/usage +' + +test_done diff --git a/t/t3020-ls-files-error-unmatch.sh b/t/t3020-ls-files-error-unmatch.sh index a7d8187169..ca01053bcc 100755 --- a/t/t3020-ls-files-error-unmatch.sh +++ b/t/t3020-ls-files-error-unmatch.sh @@ -26,4 +26,3 @@ test_expect_success \ 'git ls-files --error-unmatch foo bar' test_done -1 diff --git a/t/t3030-merge-recursive.sh b/t/t3030-merge-recursive.sh index 3935c4b1c4..806fdccce1 100755 --- a/t/t3030-merge-recursive.sh +++ b/t/t3030-merge-recursive.sh @@ -312,7 +312,7 @@ test_expect_success 'merge-recursive result' ' ' -test_expect_success 'fail if the index has unresolved entries' ' +test_expect_success C_LOCALE_OUTPUT 'fail if the index has unresolved entries' ' rm -fr [abcd] && git checkout -f "$c1" && @@ -557,7 +557,7 @@ test_expect_success 'reset and bind merge' ' echo "100644 $o0 0 c" echo "100644 $o1 0 d/e" ) >expected && - test_cmp expected actual + test_cmp expected actual && git read-tree --prefix=z/ master && git ls-files -s >actual && diff --git a/t/t3032-merge-recursive-options.sh b/t/t3032-merge-recursive-options.sh new file mode 100755 index 0000000000..2b17311cb0 --- /dev/null +++ b/t/t3032-merge-recursive-options.sh @@ -0,0 +1,203 @@ +#!/bin/sh + +test_description='merge-recursive options + +* [master] Clarify + ! [remote] Remove cruft +-- + + [remote] Remove cruft +* [master] Clarify +*+ [remote^] Initial revision +* ok 1: setup +' + +. ./test-lib.sh + +test_have_prereq SED_STRIPS_CR && SED_OPTIONS=-b +test_have_prereq MINGW && export GREP_OPTIONS=-U + +test_expect_success 'setup' ' + conflict_hunks () { + sed $SED_OPTIONS -n -e " + /^<<<</ b conflict + b + : conflict + p + /^>>>>/ b + n + b conflict + " "$@" + } && + + cat <<-\EOF >text.txt && + Hope, he says, cherishes the soul of him who lives in + justice and holiness and is the nurse of his age and the + companion of his journey;--hope which is mightiest to sway + the restless soul of man. + + How admirable are his words! And the great blessing of riches, I do + not say to every man, but to a good man, is, that he has had no + occasion to deceive or to defraud others, either intentionally or + unintentionally; and when he departs to the world below he is not in + any apprehension about offerings due to the gods or debts which he owes + to men. Now to this peace of mind the possession of wealth greatly + contributes; and therefore I say, that, setting one thing against + another, of the many advantages which wealth has to give, to a man of + sense this is in my opinion the greatest. + + Well said, Cephalus, I replied; but as concerning justice, what is + it?--to speak the truth and to pay your debts--no more than this? And + even to this are there not exceptions? Suppose that a friend when in + his right mind has deposited arms with me and he asks for them when he + is not in his right mind, ought I to give them back to him? No one + would say that I ought or that I should be right in doing so, any more + than they would say that I ought always to speak the truth to one who + is in his condition. + + You are quite right, he replied. + + But then, I said, speaking the truth and paying your debts is not a + correct definition of justice. + + CEPHALUS - SOCRATES - POLEMARCHUS + + Quite correct, Socrates, if Simonides is to be believed, said + Polemarchus interposing. + + I fear, said Cephalus, that I must go now, for I have to look after the + sacrifices, and I hand over the argument to Polemarchus and the company. + EOF + git add text.txt && + test_tick && + git commit -m "Initial revision" && + + git checkout -b remote && + sed -e " + s/\. /\. /g + s/[?] /? /g + s/ / /g + s/--/---/g + s/but as concerning/but as con cerning/ + /CEPHALUS - SOCRATES - POLEMARCHUS/ d + " text.txt >text.txt+ && + mv text.txt+ text.txt && + git commit -a -m "Remove cruft" && + + git checkout master && + sed -e " + s/\(not in his right mind\),\(.*\)/\1;\2Q/ + s/Quite correct\(.*\)/It is too correct\1Q/ + s/unintentionally/un intentionally/ + /un intentionally/ s/$/Q/ + s/Polemarchus interposing./Polemarchus, interposing.Q/ + /justice and holiness/ s/$/Q/ + /pay your debts/ s/$/Q/ + " text.txt | q_to_cr >text.txt+ && + mv text.txt+ text.txt && + git commit -a -m "Clarify" && + git show-branch --all +' + +test_expect_success 'naive merge fails' ' + git read-tree --reset -u HEAD && + test_must_fail git merge-recursive HEAD^ -- HEAD remote && + test_must_fail git update-index --refresh && + grep "<<<<<<" text.txt +' + +test_expect_success '--ignore-space-change makes merge succeed' ' + git read-tree --reset -u HEAD && + git merge-recursive --ignore-space-change HEAD^ -- HEAD remote +' + +test_expect_success 'naive cherry-pick fails' ' + git read-tree --reset -u HEAD && + test_must_fail git cherry-pick --no-commit remote && + git read-tree --reset -u HEAD && + test_must_fail git cherry-pick remote && + test_must_fail git update-index --refresh && + grep "<<<<<<" text.txt +' + +test_expect_success '-Xignore-space-change makes cherry-pick succeed' ' + git read-tree --reset -u HEAD && + git cherry-pick --no-commit -Xignore-space-change remote +' + +test_expect_success '--ignore-space-change: our w/s-only change wins' ' + q_to_cr <<-\EOF >expected && + justice and holiness and is the nurse of his age and theQ + EOF + + git read-tree --reset -u HEAD && + git merge-recursive --ignore-space-change HEAD^ -- HEAD remote && + grep "justice and holiness" text.txt >actual && + test_cmp expected actual +' + +test_expect_success '--ignore-space-change: their real change wins over w/s' ' + cat <<-\EOF >expected && + it?---to speak the truth and to pay your debts---no more than this? And + EOF + + git read-tree --reset -u HEAD && + git merge-recursive --ignore-space-change HEAD^ -- HEAD remote && + grep "pay your debts" text.txt >actual && + test_cmp expected actual +' + +test_expect_success '--ignore-space-change: does not ignore new spaces' ' + cat <<-\EOF >expected1 && + Well said, Cephalus, I replied; but as con cerning justice, what is + EOF + q_to_cr <<-\EOF >expected2 && + un intentionally; and when he departs to the world below he is not inQ + EOF + + git read-tree --reset -u HEAD && + git merge-recursive --ignore-space-change HEAD^ -- HEAD remote && + grep "Well said" text.txt >actual1 && + grep "when he departs" text.txt >actual2 && + test_cmp expected1 actual1 && + test_cmp expected2 actual2 +' + +test_expect_success '--ignore-all-space drops their new spaces' ' + cat <<-\EOF >expected && + Well said, Cephalus, I replied; but as concerning justice, what is + EOF + + git read-tree --reset -u HEAD && + git merge-recursive --ignore-all-space HEAD^ -- HEAD remote && + grep "Well said" text.txt >actual && + test_cmp expected actual +' + +test_expect_success '--ignore-all-space keeps our new spaces' ' + q_to_cr <<-\EOF >expected && + un intentionally; and when he departs to the world below he is not inQ + EOF + + git read-tree --reset -u HEAD && + git merge-recursive --ignore-all-space HEAD^ -- HEAD remote && + grep "when he departs" text.txt >actual && + test_cmp expected actual +' + +test_expect_success '--ignore-space-at-eol' ' + q_to_cr <<-\EOF >expected && + <<<<<<< HEAD + is not in his right mind; ought I to give them back to him? No oneQ + ======= + is not in his right mind, ought I to give them back to him? No one + >>>>>>> remote + EOF + + git read-tree --reset -u HEAD && + test_must_fail git merge-recursive --ignore-space-at-eol \ + HEAD^ -- HEAD remote && + conflict_hunks text.txt >actual && + test_cmp expected actual +' + +test_done diff --git a/t/t3050-subprojects-fetch.sh b/t/t3050-subprojects-fetch.sh index 4261e9641e..2f5f41a012 100755 --- a/t/t3050-subprojects-fetch.sh +++ b/t/t3050-subprojects-fetch.sh @@ -10,10 +10,10 @@ test_expect_success setup ' cd sub && git init && >subfile && - git add subfile + git add subfile && git commit -m "subproject commit #1" ) && - >mainfile + >mainfile && git add sub mainfile && test_tick && git commit -m "superproject commit #1" diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh index f54a533456..286a2a6869 100755 --- a/t/t3200-branch.sh +++ b/t/t3200-branch.sh @@ -26,6 +26,17 @@ test_expect_success \ ! test -f .git/refs/heads/--help ' +test_expect_success 'branch -h in broken repository' ' + mkdir broken && + ( + cd broken && + git init && + >.git/refs/heads/master && + test_expect_code 129 git branch -h >usage 2>&1 + ) && + grep "[Uu]sage" broken/usage +' + test_expect_success \ 'git branch abc should create a branch' \ 'git branch abc && test -f .git/refs/heads/abc' @@ -192,7 +203,7 @@ test_expect_success 'test deleting branch deletes branch config' \ test -z "$(git config branch.my7.remote)" && test -z "$(git config branch.my7.merge)"' -test_expect_success 'test deleting branch without config' \ +test_expect_success C_LOCALE_OUTPUT 'test deleting branch without config' \ 'git branch my7 s && sha1=$(git rev-parse my7 | cut -c 1-7) && test "$(git branch -d my7 2>&1)" = "Deleted branch my7 (was $sha1)."' @@ -212,6 +223,11 @@ test_expect_success \ 'branch from non-branch HEAD w/--track causes failure' \ 'test_must_fail git branch --track my10 HEAD^' +test_expect_success \ + 'branch from tag w/--track causes failure' \ + 'git tag foobar && + test_must_fail git branch --track my11 foobar' + # Keep this test last, as it changes the current branch cat >expect <<EOF 0000000000000000000000000000000000000000 $HEAD $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1117150200 +0000 branch: Created from master @@ -477,6 +493,15 @@ test_expect_success 'autosetuprebase always on an untracked remote branch' ' test "z$(git config branch.myr20.rebase)" = z ' +test_expect_success 'autosetuprebase always on detached HEAD' ' + git config branch.autosetupmerge always && + test_when_finished git checkout master && + git checkout HEAD^0 && + git branch my11 && + test -z "$(git config branch.my11.remote)" && + test -z "$(git config branch.my11.merge)" +' + test_expect_success 'detect misconfigured autosetuprebase (bad value)' ' git config branch.autosetuprebase garbage && test_must_fail git branch diff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh index 809d1c4ed4..4ef7d09115 100755 --- a/t/t3203-branch-output.sh +++ b/t/t3203-branch-output.sh @@ -12,13 +12,13 @@ test_expect_success 'make commits' ' ' test_expect_success 'make branches' ' - git branch branch-one + git branch branch-one && git branch branch-two HEAD^ ' test_expect_success 'make remote branches' ' - git update-ref refs/remotes/origin/branch-one branch-one - git update-ref refs/remotes/origin/branch-two branch-two + git update-ref refs/remotes/origin/branch-one branch-one && + git update-ref refs/remotes/origin/branch-two branch-two && git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/branch-one ' @@ -72,7 +72,7 @@ cat >expect <<'EOF' branch-two master EOF -test_expect_success 'git branch shows detached HEAD properly' ' +test_expect_success C_LOCALE_OUTPUT 'git branch shows detached HEAD properly' ' git checkout HEAD^0 && git branch >actual && test_cmp expect actual diff --git a/t/t3300-funny-names.sh b/t/t3300-funny-names.sh index f39a261d80..5e29a05259 100755 --- a/t/t3300-funny-names.sh +++ b/t/t3300-funny-names.sh @@ -43,8 +43,8 @@ test_expect_success TABS_IN_FILENAMES 'git ls-files no-funny' \ test_cmp expected current' test_expect_success TABS_IN_FILENAMES 'setup expect' ' -t0=`git write-tree` -echo "$t0" >t0 +t0=`git write-tree` && +echo "$t0" >t0 && cat > expected <<\EOF just space @@ -69,8 +69,8 @@ test_expect_success TABS_IN_FILENAMES 'git ls-files -z with-funny' \ test_cmp expected current' test_expect_success TABS_IN_FILENAMES 'setup expect' ' -t1=`git write-tree` -echo "$t1" >t1 +t1=`git write-tree` && +echo "$t1" >t1 && cat > expected <<\EOF just space diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh index a2b79a0430..1921ca3a73 100755 --- a/t/t3301-notes.sh +++ b/t/t3301-notes.sh @@ -52,7 +52,7 @@ test_expect_success 'refusing to edit notes in refs/remotes/' ' # 1 indicates caught gracefully by die, 128 means git-show barked test_expect_success 'handle empty notes gracefully' ' - git notes show ; test 1 = $? + test_expect_code 1 git notes show ' test_expect_success 'show non-existent notes entry with %N' ' @@ -627,16 +627,16 @@ test_expect_success '--show-notes=ref accumulates' ' test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' ' git config core.notesRef refs/notes/other && - echo "Note on a tree" > expect + echo "Note on a tree" > expect && git notes add -m "Note on a tree" HEAD: && git notes show HEAD: > actual && test_cmp expect actual && - echo "Note on a blob" > expect + echo "Note on a blob" > expect && filename=$(git ls-tree --name-only HEAD | head -n1) && git notes add -m "Note on a blob" HEAD:$filename && git notes show HEAD:$filename > actual && test_cmp expect actual && - echo "Note on a tag" > expect + echo "Note on a tag" > expect && git tag -a -m "This is an annotated tag" foobar HEAD^ && git notes add -m "Note on a tag" foobar && git notes show foobar > actual && @@ -962,6 +962,7 @@ Date: Thu Apr 7 15:27:13 2005 -0700 Notes (other): a fresh note +$whitespace another fresh note EOF @@ -983,8 +984,11 @@ Date: Thu Apr 7 15:27:13 2005 -0700 Notes (other): a fresh note +$whitespace another fresh note +$whitespace append 1 +$whitespace append 2 EOF @@ -1061,4 +1065,23 @@ test_expect_success 'git notes copy diagnoses too many or too few parameters' ' test_must_fail git notes copy one two three ' +test_expect_success 'git notes get-ref (no overrides)' ' + git config --unset core.notesRef && + sane_unset GIT_NOTES_REF && + test "$(git notes get-ref)" = "refs/notes/commits" +' + +test_expect_success 'git notes get-ref (core.notesRef)' ' + git config core.notesRef refs/notes/foo && + test "$(git notes get-ref)" = "refs/notes/foo" +' + +test_expect_success 'git notes get-ref (GIT_NOTES_REF)' ' + test "$(GIT_NOTES_REF=refs/notes/bar git notes get-ref)" = "refs/notes/bar" +' + +test_expect_success 'git notes get-ref (--ref)' ' + test "$(GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref)" = "refs/notes/baz" +' + test_done diff --git a/t/t3303-notes-subtrees.sh b/t/t3303-notes-subtrees.sh index 75ec18778e..704aee81ef 100755 --- a/t/t3303-notes-subtrees.sh +++ b/t/t3303-notes-subtrees.sh @@ -168,15 +168,16 @@ INPUT_END } verify_concatenated_notes () { - git log | grep "^ " > output && - i=$number_of_commits && - while [ $i -gt 0 ]; do - echo " commit #$i" && - echo " first note for commit #$i" && - echo " second note for commit #$i" && - i=$(($i-1)); - done > expect && - test_cmp expect output + git log | grep "^ " > output && + i=$number_of_commits && + while [ $i -gt 0 ]; do + echo " commit #$i" && + echo " first note for commit #$i" && + echo " " && + echo " second note for commit #$i" && + i=$(($i-1)); + done > expect && + test_cmp expect output } test_expect_success 'test notes in no fanout concatenated with 2/38-fanout' 'test_concatenated_notes "s|^..|&/|" ""' diff --git a/t/t3306-notes-prune.sh b/t/t3306-notes-prune.sh index c4282179b3..86bf909ee3 100755 --- a/t/t3306-notes-prune.sh +++ b/t/t3306-notes-prune.sh @@ -20,6 +20,9 @@ test_expect_success 'setup: create a few commits with notes' ' git add file3 && test_tick && git commit -m 3rd && + COMMIT_FILE=.git/objects/5e/e1c35e83ea47cd3cc4f8cbee0568915fbbbd29 && + test -f $COMMIT_FILE && + test-chmtime =+0 $COMMIT_FILE && git notes add -m "Note #3" ' diff --git a/t/t3307-notes-man.sh b/t/t3307-notes-man.sh index 3269f2eebd..2ea3be6546 100755 --- a/t/t3307-notes-man.sh +++ b/t/t3307-notes-man.sh @@ -26,7 +26,7 @@ test_expect_success 'example 1: notes to add an Acked-by line' ' ' test_expect_success 'example 2: binary notes' ' - cp "$TEST_DIRECTORY"/test4012.png . + cp "$TEST_DIRECTORY"/test4012.png . && git checkout B && blob=$(git hash-object -w test4012.png) && git notes --ref=logo add -C "$blob" && diff --git a/t/t3308-notes-merge.sh b/t/t3308-notes-merge.sh new file mode 100755 index 0000000000..24d82b49bb --- /dev/null +++ b/t/t3308-notes-merge.sh @@ -0,0 +1,368 @@ +#!/bin/sh +# +# Copyright (c) 2010 Johan Herland +# + +test_description='Test merging of notes trees' + +. ./test-lib.sh + +test_expect_success setup ' + test_commit 1st && + test_commit 2nd && + test_commit 3rd && + test_commit 4th && + test_commit 5th && + # Create notes on 4 first commits + git config core.notesRef refs/notes/x && + git notes add -m "Notes on 1st commit" 1st && + git notes add -m "Notes on 2nd commit" 2nd && + git notes add -m "Notes on 3rd commit" 3rd && + git notes add -m "Notes on 4th commit" 4th +' + +commit_sha1=$(git rev-parse 1st^{commit}) +commit_sha2=$(git rev-parse 2nd^{commit}) +commit_sha3=$(git rev-parse 3rd^{commit}) +commit_sha4=$(git rev-parse 4th^{commit}) +commit_sha5=$(git rev-parse 5th^{commit}) + +verify_notes () { + notes_ref="$1" + git -c core.notesRef="refs/notes/$notes_ref" notes | + sort >"output_notes_$notes_ref" && + test_cmp "expect_notes_$notes_ref" "output_notes_$notes_ref" && + git -c core.notesRef="refs/notes/$notes_ref" log --format="%H %s%n%N" \ + >"output_log_$notes_ref" && + test_cmp "expect_log_$notes_ref" "output_log_$notes_ref" +} + +cat <<EOF | sort >expect_notes_x +5e93d24084d32e1cb61f7070505b9d2530cca987 $commit_sha4 +8366731eeee53787d2bdf8fc1eff7d94757e8da0 $commit_sha3 +eede89064cd42441590d6afec6c37b321ada3389 $commit_sha2 +daa55ffad6cb99bf64226532147ffcaf5ce8bdd1 $commit_sha1 +EOF + +cat >expect_log_x <<EOF +$commit_sha5 5th + +$commit_sha4 4th +Notes on 4th commit + +$commit_sha3 3rd +Notes on 3rd commit + +$commit_sha2 2nd +Notes on 2nd commit + +$commit_sha1 1st +Notes on 1st commit + +EOF + +test_expect_success 'verify initial notes (x)' ' + verify_notes x +' + +cp expect_notes_x expect_notes_y +cp expect_log_x expect_log_y + +test_expect_success 'fail to merge empty notes ref into empty notes ref (z => y)' ' + test_must_fail git -c "core.notesRef=refs/notes/y" notes merge z +' + +test_expect_success 'fail to merge into various non-notes refs' ' + test_must_fail git -c "core.notesRef=refs/notes" notes merge x && + test_must_fail git -c "core.notesRef=refs/notes/" notes merge x && + mkdir -p .git/refs/notes/dir && + test_must_fail git -c "core.notesRef=refs/notes/dir" notes merge x && + test_must_fail git -c "core.notesRef=refs/notes/dir/" notes merge x && + test_must_fail git -c "core.notesRef=refs/heads/master" notes merge x && + test_must_fail git -c "core.notesRef=refs/notes/y:" notes merge x && + test_must_fail git -c "core.notesRef=refs/notes/y:foo" notes merge x && + test_must_fail git -c "core.notesRef=refs/notes/foo^{bar" notes merge x +' + +test_expect_success 'fail to merge various non-note-trees' ' + git config core.notesRef refs/notes/y && + test_must_fail git notes merge refs/notes && + test_must_fail git notes merge refs/notes/ && + test_must_fail git notes merge refs/notes/dir && + test_must_fail git notes merge refs/notes/dir/ && + test_must_fail git notes merge refs/heads/master && + test_must_fail git notes merge x: && + test_must_fail git notes merge x:foo && + test_must_fail git notes merge foo^{bar +' + +test_expect_success 'merge notes into empty notes ref (x => y)' ' + git config core.notesRef refs/notes/y && + git notes merge x && + verify_notes y && + # x and y should point to the same notes commit + test "$(git rev-parse refs/notes/x)" = "$(git rev-parse refs/notes/y)" +' + +test_expect_success 'merge empty notes ref (z => y)' ' + git notes merge z && + # y should not change (still == x) + test "$(git rev-parse refs/notes/x)" = "$(git rev-parse refs/notes/y)" +' + +test_expect_success 'change notes on other notes ref (y)' ' + # Not touching notes to 1st commit + git notes remove 2nd && + git notes append -m "More notes on 3rd commit" 3rd && + git notes add -f -m "New notes on 4th commit" 4th && + git notes add -m "Notes on 5th commit" 5th +' + +test_expect_success 'merge previous notes commit (y^ => y) => No-op' ' + pre_state="$(git rev-parse refs/notes/y)" && + git notes merge y^ && + # y should not move + test "$pre_state" = "$(git rev-parse refs/notes/y)" +' + +cat <<EOF | sort >expect_notes_y +0f2efbd00262f2fd41dfae33df8765618eeacd99 $commit_sha5 +dec2502dac3ea161543f71930044deff93fa945c $commit_sha4 +4069cdb399fd45463ec6eef8e051a16a03592d91 $commit_sha3 +daa55ffad6cb99bf64226532147ffcaf5ce8bdd1 $commit_sha1 +EOF + +cat >expect_log_y <<EOF +$commit_sha5 5th +Notes on 5th commit + +$commit_sha4 4th +New notes on 4th commit + +$commit_sha3 3rd +Notes on 3rd commit + +More notes on 3rd commit + +$commit_sha2 2nd + +$commit_sha1 1st +Notes on 1st commit + +EOF + +test_expect_success 'verify changed notes on other notes ref (y)' ' + verify_notes y +' + +test_expect_success 'verify unchanged notes on original notes ref (x)' ' + verify_notes x +' + +test_expect_success 'merge original notes (x) into changed notes (y) => No-op' ' + git notes merge -vvv x && + verify_notes y && + verify_notes x +' + +cp expect_notes_y expect_notes_x +cp expect_log_y expect_log_x + +test_expect_success 'merge changed (y) into original (x) => Fast-forward' ' + git config core.notesRef refs/notes/x && + git notes merge y && + verify_notes x && + verify_notes y && + # x and y should point to same the notes commit + test "$(git rev-parse refs/notes/x)" = "$(git rev-parse refs/notes/y)" +' + +test_expect_success 'merge empty notes ref (z => y)' ' + # Prepare empty (but valid) notes ref (z) + git config core.notesRef refs/notes/z && + git notes add -m "foo" && + git notes remove && + git notes >output_notes_z && + test_cmp /dev/null output_notes_z && + # Do the merge (z => y) + git config core.notesRef refs/notes/y && + git notes merge z && + verify_notes y && + # y should no longer point to the same notes commit as x + test "$(git rev-parse refs/notes/x)" != "$(git rev-parse refs/notes/y)" +' + +cat <<EOF | sort >expect_notes_y +0f2efbd00262f2fd41dfae33df8765618eeacd99 $commit_sha5 +dec2502dac3ea161543f71930044deff93fa945c $commit_sha4 +4069cdb399fd45463ec6eef8e051a16a03592d91 $commit_sha3 +d000d30e6ddcfce3a8122c403226a2ce2fd04d9d $commit_sha2 +43add6bd0c8c0bc871ac7991e0f5573cfba27804 $commit_sha1 +EOF + +cat >expect_log_y <<EOF +$commit_sha5 5th +Notes on 5th commit + +$commit_sha4 4th +New notes on 4th commit + +$commit_sha3 3rd +Notes on 3rd commit + +More notes on 3rd commit + +$commit_sha2 2nd +New notes on 2nd commit + +$commit_sha1 1st +Notes on 1st commit + +More notes on 1st commit + +EOF + +test_expect_success 'change notes on other notes ref (y)' ' + # Append to 1st commit notes + git notes append -m "More notes on 1st commit" 1st && + # Add new notes to 2nd commit + git notes add -m "New notes on 2nd commit" 2nd && + verify_notes y +' + +cat <<EOF | sort >expect_notes_x +0f2efbd00262f2fd41dfae33df8765618eeacd99 $commit_sha5 +1f257a3a90328557c452f0817d6cc50c89d315d4 $commit_sha4 +daa55ffad6cb99bf64226532147ffcaf5ce8bdd1 $commit_sha1 +EOF + +cat >expect_log_x <<EOF +$commit_sha5 5th +Notes on 5th commit + +$commit_sha4 4th +New notes on 4th commit + +More notes on 4th commit + +$commit_sha3 3rd + +$commit_sha2 2nd + +$commit_sha1 1st +Notes on 1st commit + +EOF + +test_expect_success 'change notes on notes ref (x)' ' + git config core.notesRef refs/notes/x && + git notes remove 3rd && + git notes append -m "More notes on 4th commit" 4th && + verify_notes x +' + +cat <<EOF | sort >expect_notes_x +0f2efbd00262f2fd41dfae33df8765618eeacd99 $commit_sha5 +1f257a3a90328557c452f0817d6cc50c89d315d4 $commit_sha4 +d000d30e6ddcfce3a8122c403226a2ce2fd04d9d $commit_sha2 +43add6bd0c8c0bc871ac7991e0f5573cfba27804 $commit_sha1 +EOF + +cat >expect_log_x <<EOF +$commit_sha5 5th +Notes on 5th commit + +$commit_sha4 4th +New notes on 4th commit + +More notes on 4th commit + +$commit_sha3 3rd + +$commit_sha2 2nd +New notes on 2nd commit + +$commit_sha1 1st +Notes on 1st commit + +More notes on 1st commit + +EOF + +test_expect_success 'merge y into x => Non-conflicting 3-way merge' ' + git notes merge y && + verify_notes x && + verify_notes y +' + +cat <<EOF | sort >expect_notes_w +05a4927951bcef347f51486575b878b2b60137f2 $commit_sha3 +d000d30e6ddcfce3a8122c403226a2ce2fd04d9d $commit_sha2 +EOF + +cat >expect_log_w <<EOF +$commit_sha5 5th + +$commit_sha4 4th + +$commit_sha3 3rd +New notes on 3rd commit + +$commit_sha2 2nd +New notes on 2nd commit + +$commit_sha1 1st + +EOF + +test_expect_success 'create notes on new, separate notes ref (w)' ' + git config core.notesRef refs/notes/w && + # Add same note as refs/notes/y on 2nd commit + git notes add -m "New notes on 2nd commit" 2nd && + # Add new note on 3rd commit (non-conflicting) + git notes add -m "New notes on 3rd commit" 3rd && + # Verify state of notes on new, separate notes ref (w) + verify_notes w +' + +cat <<EOF | sort >expect_notes_x +0f2efbd00262f2fd41dfae33df8765618eeacd99 $commit_sha5 +1f257a3a90328557c452f0817d6cc50c89d315d4 $commit_sha4 +05a4927951bcef347f51486575b878b2b60137f2 $commit_sha3 +d000d30e6ddcfce3a8122c403226a2ce2fd04d9d $commit_sha2 +43add6bd0c8c0bc871ac7991e0f5573cfba27804 $commit_sha1 +EOF + +cat >expect_log_x <<EOF +$commit_sha5 5th +Notes on 5th commit + +$commit_sha4 4th +New notes on 4th commit + +More notes on 4th commit + +$commit_sha3 3rd +New notes on 3rd commit + +$commit_sha2 2nd +New notes on 2nd commit + +$commit_sha1 1st +Notes on 1st commit + +More notes on 1st commit + +EOF + +test_expect_success 'merge w into x => Non-conflicting history-less merge' ' + git config core.notesRef refs/notes/x && + git notes merge w && + # Verify new state of notes on other notes ref (x) + verify_notes x && + # Also verify that nothing changed on other notes refs (y and w) + verify_notes y && + verify_notes w +' + +test_done diff --git a/t/t3309-notes-merge-auto-resolve.sh b/t/t3309-notes-merge-auto-resolve.sh new file mode 100755 index 0000000000..461fd84755 --- /dev/null +++ b/t/t3309-notes-merge-auto-resolve.sh @@ -0,0 +1,647 @@ +#!/bin/sh +# +# Copyright (c) 2010 Johan Herland +# + +test_description='Test notes merging with auto-resolving strategies' + +. ./test-lib.sh + +# Set up a notes merge scenario with all kinds of potential conflicts +test_expect_success 'setup commits' ' + test_commit 1st && + test_commit 2nd && + test_commit 3rd && + test_commit 4th && + test_commit 5th && + test_commit 6th && + test_commit 7th && + test_commit 8th && + test_commit 9th && + test_commit 10th && + test_commit 11th && + test_commit 12th && + test_commit 13th && + test_commit 14th && + test_commit 15th +' + +commit_sha1=$(git rev-parse 1st^{commit}) +commit_sha2=$(git rev-parse 2nd^{commit}) +commit_sha3=$(git rev-parse 3rd^{commit}) +commit_sha4=$(git rev-parse 4th^{commit}) +commit_sha5=$(git rev-parse 5th^{commit}) +commit_sha6=$(git rev-parse 6th^{commit}) +commit_sha7=$(git rev-parse 7th^{commit}) +commit_sha8=$(git rev-parse 8th^{commit}) +commit_sha9=$(git rev-parse 9th^{commit}) +commit_sha10=$(git rev-parse 10th^{commit}) +commit_sha11=$(git rev-parse 11th^{commit}) +commit_sha12=$(git rev-parse 12th^{commit}) +commit_sha13=$(git rev-parse 13th^{commit}) +commit_sha14=$(git rev-parse 14th^{commit}) +commit_sha15=$(git rev-parse 15th^{commit}) + +verify_notes () { + notes_ref="$1" + suffix="$2" + git -c core.notesRef="refs/notes/$notes_ref" notes | + sort >"output_notes_$suffix" && + test_cmp "expect_notes_$suffix" "output_notes_$suffix" && + git -c core.notesRef="refs/notes/$notes_ref" log --format="%H %s%n%N" \ + >"output_log_$suffix" && + test_cmp "expect_log_$suffix" "output_log_$suffix" +} + +test_expect_success 'setup merge base (x)' ' + git config core.notesRef refs/notes/x && + git notes add -m "x notes on 6th commit" 6th && + git notes add -m "x notes on 7th commit" 7th && + git notes add -m "x notes on 8th commit" 8th && + git notes add -m "x notes on 9th commit" 9th && + git notes add -m "x notes on 10th commit" 10th && + git notes add -m "x notes on 11th commit" 11th && + git notes add -m "x notes on 12th commit" 12th && + git notes add -m "x notes on 13th commit" 13th && + git notes add -m "x notes on 14th commit" 14th && + git notes add -m "x notes on 15th commit" 15th +' + +cat <<EOF | sort >expect_notes_x +457a85d6c814ea208550f15fcc48f804ac8dc023 $commit_sha15 +b0c95b954301d69da2bc3723f4cb1680d355937c $commit_sha14 +5d30216a129eeffa97d9694ffe8c74317a560315 $commit_sha13 +dd161bc149470fd890dd4ab52a4cbd79bbd18c36 $commit_sha12 +7abbc45126d680336fb24294f013a7cdfa3ed545 $commit_sha11 +b8d03e173f67f6505a76f6e00cf93440200dd9be $commit_sha10 +20c613c835011c48a5abe29170a2402ca6354910 $commit_sha9 +a3daf8a1e4e5dc3409a303ad8481d57bfea7f5d6 $commit_sha8 +897003322b53bc6ca098e9324ee508362347e734 $commit_sha7 +11d97fdebfa5ceee540a3da07bce6fa0222bc082 $commit_sha6 +EOF + +cat >expect_log_x <<EOF +$commit_sha15 15th +x notes on 15th commit + +$commit_sha14 14th +x notes on 14th commit + +$commit_sha13 13th +x notes on 13th commit + +$commit_sha12 12th +x notes on 12th commit + +$commit_sha11 11th +x notes on 11th commit + +$commit_sha10 10th +x notes on 10th commit + +$commit_sha9 9th +x notes on 9th commit + +$commit_sha8 8th +x notes on 8th commit + +$commit_sha7 7th +x notes on 7th commit + +$commit_sha6 6th +x notes on 6th commit + +$commit_sha5 5th + +$commit_sha4 4th + +$commit_sha3 3rd + +$commit_sha2 2nd + +$commit_sha1 1st + +EOF + +test_expect_success 'verify state of merge base (x)' 'verify_notes x x' + +test_expect_success 'setup local branch (y)' ' + git update-ref refs/notes/y refs/notes/x && + git config core.notesRef refs/notes/y && + git notes add -f -m "y notes on 3rd commit" 3rd && + git notes add -f -m "y notes on 4th commit" 4th && + git notes add -f -m "y notes on 5th commit" 5th && + git notes remove 6th && + git notes remove 7th && + git notes remove 8th && + git notes add -f -m "y notes on 12th commit" 12th && + git notes add -f -m "y notes on 13th commit" 13th && + git notes add -f -m "y notes on 14th commit" 14th && + git notes add -f -m "y notes on 15th commit" 15th +' + +cat <<EOF | sort >expect_notes_y +68b8630d25516028bed862719855b3d6768d7833 $commit_sha15 +5de7ea7ad4f47e7ff91989fb82234634730f75df $commit_sha14 +3a631fdb6f41b05b55d8f4baf20728ba8f6fccbc $commit_sha13 +a66055fa82f7a03fe0c02a6aba3287a85abf7c62 $commit_sha12 +7abbc45126d680336fb24294f013a7cdfa3ed545 $commit_sha11 +b8d03e173f67f6505a76f6e00cf93440200dd9be $commit_sha10 +20c613c835011c48a5abe29170a2402ca6354910 $commit_sha9 +154508c7a0bcad82b6fe4b472bc4c26b3bf0825b $commit_sha5 +e2bfd06a37dd2031684a59a6e2b033e212239c78 $commit_sha4 +5772f42408c0dd6f097a7ca2d24de0e78d1c46b1 $commit_sha3 +EOF + +cat >expect_log_y <<EOF +$commit_sha15 15th +y notes on 15th commit + +$commit_sha14 14th +y notes on 14th commit + +$commit_sha13 13th +y notes on 13th commit + +$commit_sha12 12th +y notes on 12th commit + +$commit_sha11 11th +x notes on 11th commit + +$commit_sha10 10th +x notes on 10th commit + +$commit_sha9 9th +x notes on 9th commit + +$commit_sha8 8th + +$commit_sha7 7th + +$commit_sha6 6th + +$commit_sha5 5th +y notes on 5th commit + +$commit_sha4 4th +y notes on 4th commit + +$commit_sha3 3rd +y notes on 3rd commit + +$commit_sha2 2nd + +$commit_sha1 1st + +EOF + +test_expect_success 'verify state of local branch (y)' 'verify_notes y y' + +test_expect_success 'setup remote branch (z)' ' + git update-ref refs/notes/z refs/notes/x && + git config core.notesRef refs/notes/z && + git notes add -f -m "z notes on 2nd commit" 2nd && + git notes add -f -m "y notes on 4th commit" 4th && + git notes add -f -m "z notes on 5th commit" 5th && + git notes remove 6th && + git notes add -f -m "z notes on 8th commit" 8th && + git notes remove 9th && + git notes add -f -m "z notes on 11th commit" 11th && + git notes remove 12th && + git notes add -f -m "y notes on 14th commit" 14th && + git notes add -f -m "z notes on 15th commit" 15th +' + +cat <<EOF | sort >expect_notes_z +9b4b2c61f0615412da3c10f98ff85b57c04ec765 $commit_sha15 +5de7ea7ad4f47e7ff91989fb82234634730f75df $commit_sha14 +5d30216a129eeffa97d9694ffe8c74317a560315 $commit_sha13 +7e3c53503a3db8dd996cb62e37c66e070b44b54d $commit_sha11 +b8d03e173f67f6505a76f6e00cf93440200dd9be $commit_sha10 +851e1638784a884c7dd26c5d41f3340f6387413a $commit_sha8 +897003322b53bc6ca098e9324ee508362347e734 $commit_sha7 +99fc34adfc400b95c67b013115e37e31aa9a6d23 $commit_sha5 +e2bfd06a37dd2031684a59a6e2b033e212239c78 $commit_sha4 +283b48219aee9a4105f6cab337e789065c82c2b9 $commit_sha2 +EOF + +cat >expect_log_z <<EOF +$commit_sha15 15th +z notes on 15th commit + +$commit_sha14 14th +y notes on 14th commit + +$commit_sha13 13th +x notes on 13th commit + +$commit_sha12 12th + +$commit_sha11 11th +z notes on 11th commit + +$commit_sha10 10th +x notes on 10th commit + +$commit_sha9 9th + +$commit_sha8 8th +z notes on 8th commit + +$commit_sha7 7th +x notes on 7th commit + +$commit_sha6 6th + +$commit_sha5 5th +z notes on 5th commit + +$commit_sha4 4th +y notes on 4th commit + +$commit_sha3 3rd + +$commit_sha2 2nd +z notes on 2nd commit + +$commit_sha1 1st + +EOF + +test_expect_success 'verify state of remote branch (z)' 'verify_notes z z' + +# At this point, before merging z into y, we have the following status: +# +# commit | base/x | local/y | remote/z | diff from x to y/z | result +# -------|---------|---------|----------|----------------------------|------- +# 1st | [none] | [none] | [none] | unchanged / unchanged | [none] +# 2nd | [none] | [none] | 283b482 | unchanged / added | 283b482 +# 3rd | [none] | 5772f42 | [none] | added / unchanged | 5772f42 +# 4th | [none] | e2bfd06 | e2bfd06 | added / added (same) | e2bfd06 +# 5th | [none] | 154508c | 99fc34a | added / added (diff) | ??? +# 6th | 11d97fd | [none] | [none] | removed / removed | [none] +# 7th | 8970033 | [none] | 8970033 | removed / unchanged | [none] +# 8th | a3daf8a | [none] | 851e163 | removed / changed | ??? +# 9th | 20c613c | 20c613c | [none] | unchanged / removed | [none] +# 10th | b8d03e1 | b8d03e1 | b8d03e1 | unchanged / unchanged | b8d03e1 +# 11th | 7abbc45 | 7abbc45 | 7e3c535 | unchanged / changed | 7e3c535 +# 12th | dd161bc | a66055f | [none] | changed / removed | ??? +# 13th | 5d30216 | 3a631fd | 5d30216 | changed / unchanged | 3a631fd +# 14th | b0c95b9 | 5de7ea7 | 5de7ea7 | changed / changed (same) | 5de7ea7 +# 15th | 457a85d | 68b8630 | 9b4b2c6 | changed / changed (diff) | ??? + +test_expect_success 'merge z into y with invalid strategy => Fail/No changes' ' + git config core.notesRef refs/notes/y && + test_must_fail git notes merge --strategy=foo z && + # Verify no changes (y) + verify_notes y y +' + +cat <<EOF | sort >expect_notes_ours +68b8630d25516028bed862719855b3d6768d7833 $commit_sha15 +5de7ea7ad4f47e7ff91989fb82234634730f75df $commit_sha14 +3a631fdb6f41b05b55d8f4baf20728ba8f6fccbc $commit_sha13 +a66055fa82f7a03fe0c02a6aba3287a85abf7c62 $commit_sha12 +7e3c53503a3db8dd996cb62e37c66e070b44b54d $commit_sha11 +b8d03e173f67f6505a76f6e00cf93440200dd9be $commit_sha10 +154508c7a0bcad82b6fe4b472bc4c26b3bf0825b $commit_sha5 +e2bfd06a37dd2031684a59a6e2b033e212239c78 $commit_sha4 +5772f42408c0dd6f097a7ca2d24de0e78d1c46b1 $commit_sha3 +283b48219aee9a4105f6cab337e789065c82c2b9 $commit_sha2 +EOF + +cat >expect_log_ours <<EOF +$commit_sha15 15th +y notes on 15th commit + +$commit_sha14 14th +y notes on 14th commit + +$commit_sha13 13th +y notes on 13th commit + +$commit_sha12 12th +y notes on 12th commit + +$commit_sha11 11th +z notes on 11th commit + +$commit_sha10 10th +x notes on 10th commit + +$commit_sha9 9th + +$commit_sha8 8th + +$commit_sha7 7th + +$commit_sha6 6th + +$commit_sha5 5th +y notes on 5th commit + +$commit_sha4 4th +y notes on 4th commit + +$commit_sha3 3rd +y notes on 3rd commit + +$commit_sha2 2nd +z notes on 2nd commit + +$commit_sha1 1st + +EOF + +test_expect_success 'merge z into y with "ours" strategy => Non-conflicting 3-way merge' ' + git notes merge --strategy=ours z && + verify_notes y ours +' + +test_expect_success 'reset to pre-merge state (y)' ' + git update-ref refs/notes/y refs/notes/y^1 && + # Verify pre-merge state + verify_notes y y +' + +cat <<EOF | sort >expect_notes_theirs +9b4b2c61f0615412da3c10f98ff85b57c04ec765 $commit_sha15 +5de7ea7ad4f47e7ff91989fb82234634730f75df $commit_sha14 +3a631fdb6f41b05b55d8f4baf20728ba8f6fccbc $commit_sha13 +7e3c53503a3db8dd996cb62e37c66e070b44b54d $commit_sha11 +b8d03e173f67f6505a76f6e00cf93440200dd9be $commit_sha10 +851e1638784a884c7dd26c5d41f3340f6387413a $commit_sha8 +99fc34adfc400b95c67b013115e37e31aa9a6d23 $commit_sha5 +e2bfd06a37dd2031684a59a6e2b033e212239c78 $commit_sha4 +5772f42408c0dd6f097a7ca2d24de0e78d1c46b1 $commit_sha3 +283b48219aee9a4105f6cab337e789065c82c2b9 $commit_sha2 +EOF + +cat >expect_log_theirs <<EOF +$commit_sha15 15th +z notes on 15th commit + +$commit_sha14 14th +y notes on 14th commit + +$commit_sha13 13th +y notes on 13th commit + +$commit_sha12 12th + +$commit_sha11 11th +z notes on 11th commit + +$commit_sha10 10th +x notes on 10th commit + +$commit_sha9 9th + +$commit_sha8 8th +z notes on 8th commit + +$commit_sha7 7th + +$commit_sha6 6th + +$commit_sha5 5th +z notes on 5th commit + +$commit_sha4 4th +y notes on 4th commit + +$commit_sha3 3rd +y notes on 3rd commit + +$commit_sha2 2nd +z notes on 2nd commit + +$commit_sha1 1st + +EOF + +test_expect_success 'merge z into y with "theirs" strategy => Non-conflicting 3-way merge' ' + git notes merge --strategy=theirs z && + verify_notes y theirs +' + +test_expect_success 'reset to pre-merge state (y)' ' + git update-ref refs/notes/y refs/notes/y^1 && + # Verify pre-merge state + verify_notes y y +' + +cat <<EOF | sort >expect_notes_union +7c4e546efd0fe939f876beb262ece02797880b54 $commit_sha15 +5de7ea7ad4f47e7ff91989fb82234634730f75df $commit_sha14 +3a631fdb6f41b05b55d8f4baf20728ba8f6fccbc $commit_sha13 +a66055fa82f7a03fe0c02a6aba3287a85abf7c62 $commit_sha12 +7e3c53503a3db8dd996cb62e37c66e070b44b54d $commit_sha11 +b8d03e173f67f6505a76f6e00cf93440200dd9be $commit_sha10 +851e1638784a884c7dd26c5d41f3340f6387413a $commit_sha8 +6c841cc36ea496027290967ca96bd2bef54dbb47 $commit_sha5 +e2bfd06a37dd2031684a59a6e2b033e212239c78 $commit_sha4 +5772f42408c0dd6f097a7ca2d24de0e78d1c46b1 $commit_sha3 +283b48219aee9a4105f6cab337e789065c82c2b9 $commit_sha2 +EOF + +cat >expect_log_union <<EOF +$commit_sha15 15th +y notes on 15th commit + +z notes on 15th commit + +$commit_sha14 14th +y notes on 14th commit + +$commit_sha13 13th +y notes on 13th commit + +$commit_sha12 12th +y notes on 12th commit + +$commit_sha11 11th +z notes on 11th commit + +$commit_sha10 10th +x notes on 10th commit + +$commit_sha9 9th + +$commit_sha8 8th +z notes on 8th commit + +$commit_sha7 7th + +$commit_sha6 6th + +$commit_sha5 5th +y notes on 5th commit + +z notes on 5th commit + +$commit_sha4 4th +y notes on 4th commit + +$commit_sha3 3rd +y notes on 3rd commit + +$commit_sha2 2nd +z notes on 2nd commit + +$commit_sha1 1st + +EOF + +test_expect_success 'merge z into y with "union" strategy => Non-conflicting 3-way merge' ' + git notes merge --strategy=union z && + verify_notes y union +' + +test_expect_success 'reset to pre-merge state (y)' ' + git update-ref refs/notes/y refs/notes/y^1 && + # Verify pre-merge state + verify_notes y y +' + +cat <<EOF | sort >expect_notes_union2 +d682107b8bf7a7aea1e537a8d5cb6a12b60135f1 $commit_sha15 +5de7ea7ad4f47e7ff91989fb82234634730f75df $commit_sha14 +3a631fdb6f41b05b55d8f4baf20728ba8f6fccbc $commit_sha13 +a66055fa82f7a03fe0c02a6aba3287a85abf7c62 $commit_sha12 +7e3c53503a3db8dd996cb62e37c66e070b44b54d $commit_sha11 +b8d03e173f67f6505a76f6e00cf93440200dd9be $commit_sha10 +851e1638784a884c7dd26c5d41f3340f6387413a $commit_sha8 +357b6ca14c7afd59b7f8b8aaaa6b8b723771135b $commit_sha5 +e2bfd06a37dd2031684a59a6e2b033e212239c78 $commit_sha4 +5772f42408c0dd6f097a7ca2d24de0e78d1c46b1 $commit_sha3 +283b48219aee9a4105f6cab337e789065c82c2b9 $commit_sha2 +EOF + +cat >expect_log_union2 <<EOF +$commit_sha15 15th +z notes on 15th commit + +y notes on 15th commit + +$commit_sha14 14th +y notes on 14th commit + +$commit_sha13 13th +y notes on 13th commit + +$commit_sha12 12th +y notes on 12th commit + +$commit_sha11 11th +z notes on 11th commit + +$commit_sha10 10th +x notes on 10th commit + +$commit_sha9 9th + +$commit_sha8 8th +z notes on 8th commit + +$commit_sha7 7th + +$commit_sha6 6th + +$commit_sha5 5th +z notes on 5th commit + +y notes on 5th commit + +$commit_sha4 4th +y notes on 4th commit + +$commit_sha3 3rd +y notes on 3rd commit + +$commit_sha2 2nd +z notes on 2nd commit + +$commit_sha1 1st + +EOF + +test_expect_success 'merge y into z with "union" strategy => Non-conflicting 3-way merge' ' + git config core.notesRef refs/notes/z && + git notes merge --strategy=union y && + verify_notes z union2 +' + +test_expect_success 'reset to pre-merge state (z)' ' + git update-ref refs/notes/z refs/notes/z^1 && + # Verify pre-merge state + verify_notes z z +' + +cat <<EOF | sort >expect_notes_cat_sort_uniq +6be90240b5f54594203e25d9f2f64b7567175aee $commit_sha15 +5de7ea7ad4f47e7ff91989fb82234634730f75df $commit_sha14 +3a631fdb6f41b05b55d8f4baf20728ba8f6fccbc $commit_sha13 +a66055fa82f7a03fe0c02a6aba3287a85abf7c62 $commit_sha12 +7e3c53503a3db8dd996cb62e37c66e070b44b54d $commit_sha11 +b8d03e173f67f6505a76f6e00cf93440200dd9be $commit_sha10 +851e1638784a884c7dd26c5d41f3340f6387413a $commit_sha8 +660311d7f78dc53db12ac373a43fca7465381a7e $commit_sha5 +e2bfd06a37dd2031684a59a6e2b033e212239c78 $commit_sha4 +5772f42408c0dd6f097a7ca2d24de0e78d1c46b1 $commit_sha3 +283b48219aee9a4105f6cab337e789065c82c2b9 $commit_sha2 +EOF + +cat >expect_log_cat_sort_uniq <<EOF +$commit_sha15 15th +y notes on 15th commit +z notes on 15th commit + +$commit_sha14 14th +y notes on 14th commit + +$commit_sha13 13th +y notes on 13th commit + +$commit_sha12 12th +y notes on 12th commit + +$commit_sha11 11th +z notes on 11th commit + +$commit_sha10 10th +x notes on 10th commit + +$commit_sha9 9th + +$commit_sha8 8th +z notes on 8th commit + +$commit_sha7 7th + +$commit_sha6 6th + +$commit_sha5 5th +y notes on 5th commit +z notes on 5th commit + +$commit_sha4 4th +y notes on 4th commit + +$commit_sha3 3rd +y notes on 3rd commit + +$commit_sha2 2nd +z notes on 2nd commit + +$commit_sha1 1st + +EOF + +test_expect_success 'merge y into z with "cat_sort_uniq" strategy => Non-conflicting 3-way merge' ' + git notes merge --strategy=cat_sort_uniq y && + verify_notes z cat_sort_uniq +' + +test_done diff --git a/t/t3310-notes-merge-manual-resolve.sh b/t/t3310-notes-merge-manual-resolve.sh new file mode 100755 index 0000000000..4ec4d11450 --- /dev/null +++ b/t/t3310-notes-merge-manual-resolve.sh @@ -0,0 +1,556 @@ +#!/bin/sh +# +# Copyright (c) 2010 Johan Herland +# + +test_description='Test notes merging with manual conflict resolution' + +. ./test-lib.sh + +# Set up a notes merge scenario with different kinds of conflicts +test_expect_success 'setup commits' ' + test_commit 1st && + test_commit 2nd && + test_commit 3rd && + test_commit 4th && + test_commit 5th +' + +commit_sha1=$(git rev-parse 1st^{commit}) +commit_sha2=$(git rev-parse 2nd^{commit}) +commit_sha3=$(git rev-parse 3rd^{commit}) +commit_sha4=$(git rev-parse 4th^{commit}) +commit_sha5=$(git rev-parse 5th^{commit}) + +verify_notes () { + notes_ref="$1" + git -c core.notesRef="refs/notes/$notes_ref" notes | + sort >"output_notes_$notes_ref" && + test_cmp "expect_notes_$notes_ref" "output_notes_$notes_ref" && + git -c core.notesRef="refs/notes/$notes_ref" log --format="%H %s%n%N" \ + >"output_log_$notes_ref" && + test_cmp "expect_log_$notes_ref" "output_log_$notes_ref" +} + +cat <<EOF | sort >expect_notes_x +6e8e3febca3c2bb896704335cc4d0c34cb2f8715 $commit_sha4 +e5388c10860456ee60673025345fe2e153eb8cf8 $commit_sha3 +ceefa674873670e7ecd131814d909723cce2b669 $commit_sha2 +EOF + +cat >expect_log_x <<EOF +$commit_sha5 5th + +$commit_sha4 4th +x notes on 4th commit + +$commit_sha3 3rd +x notes on 3rd commit + +$commit_sha2 2nd +x notes on 2nd commit + +$commit_sha1 1st + +EOF + +test_expect_success 'setup merge base (x)' ' + git config core.notesRef refs/notes/x && + git notes add -m "x notes on 2nd commit" 2nd && + git notes add -m "x notes on 3rd commit" 3rd && + git notes add -m "x notes on 4th commit" 4th && + verify_notes x +' + +cat <<EOF | sort >expect_notes_y +e2bfd06a37dd2031684a59a6e2b033e212239c78 $commit_sha4 +5772f42408c0dd6f097a7ca2d24de0e78d1c46b1 $commit_sha3 +b0a6021ec006d07e80e9b20ec9b444cbd9d560d3 $commit_sha1 +EOF + +cat >expect_log_y <<EOF +$commit_sha5 5th + +$commit_sha4 4th +y notes on 4th commit + +$commit_sha3 3rd +y notes on 3rd commit + +$commit_sha2 2nd + +$commit_sha1 1st +y notes on 1st commit + +EOF + +test_expect_success 'setup local branch (y)' ' + git update-ref refs/notes/y refs/notes/x && + git config core.notesRef refs/notes/y && + git notes add -f -m "y notes on 1st commit" 1st && + git notes remove 2nd && + git notes add -f -m "y notes on 3rd commit" 3rd && + git notes add -f -m "y notes on 4th commit" 4th && + verify_notes y +' + +cat <<EOF | sort >expect_notes_z +cff59c793c20bb49a4e01bc06fb06bad642e0d54 $commit_sha4 +283b48219aee9a4105f6cab337e789065c82c2b9 $commit_sha2 +0a81da8956346e19bcb27a906f04af327e03e31b $commit_sha1 +EOF + +cat >expect_log_z <<EOF +$commit_sha5 5th + +$commit_sha4 4th +z notes on 4th commit + +$commit_sha3 3rd + +$commit_sha2 2nd +z notes on 2nd commit + +$commit_sha1 1st +z notes on 1st commit + +EOF + +test_expect_success 'setup remote branch (z)' ' + git update-ref refs/notes/z refs/notes/x && + git config core.notesRef refs/notes/z && + git notes add -f -m "z notes on 1st commit" 1st && + git notes add -f -m "z notes on 2nd commit" 2nd && + git notes remove 3rd && + git notes add -f -m "z notes on 4th commit" 4th && + verify_notes z +' + +# At this point, before merging z into y, we have the following status: +# +# commit | base/x | local/y | remote/z | diff from x to y/z +# -------|---------|---------|----------|--------------------------- +# 1st | [none] | b0a6021 | 0a81da8 | added / added (diff) +# 2nd | ceefa67 | [none] | 283b482 | removed / changed +# 3rd | e5388c1 | 5772f42 | [none] | changed / removed +# 4th | 6e8e3fe | e2bfd06 | cff59c7 | changed / changed (diff) +# 5th | [none] | [none] | [none] | [none] + +cat <<EOF | sort >expect_conflicts +$commit_sha1 +$commit_sha2 +$commit_sha3 +$commit_sha4 +EOF + +cat >expect_conflict_$commit_sha1 <<EOF +<<<<<<< refs/notes/m +y notes on 1st commit +======= +z notes on 1st commit +>>>>>>> refs/notes/z +EOF + +cat >expect_conflict_$commit_sha2 <<EOF +z notes on 2nd commit +EOF + +cat >expect_conflict_$commit_sha3 <<EOF +y notes on 3rd commit +EOF + +cat >expect_conflict_$commit_sha4 <<EOF +<<<<<<< refs/notes/m +y notes on 4th commit +======= +z notes on 4th commit +>>>>>>> refs/notes/z +EOF + +cp expect_notes_y expect_notes_m +cp expect_log_y expect_log_m + +git rev-parse refs/notes/y > pre_merge_y +git rev-parse refs/notes/z > pre_merge_z + +test_expect_success 'merge z into m (== y) with default ("manual") resolver => Conflicting 3-way merge' ' + git update-ref refs/notes/m refs/notes/y && + git config core.notesRef refs/notes/m && + test_must_fail git notes merge z >output && + # Output should point to where to resolve conflicts + grep -q "\\.git/NOTES_MERGE_WORKTREE" output && + # Inspect merge conflicts + ls .git/NOTES_MERGE_WORKTREE >output_conflicts && + test_cmp expect_conflicts output_conflicts && + ( for f in $(cat expect_conflicts); do + test_cmp "expect_conflict_$f" ".git/NOTES_MERGE_WORKTREE/$f" || + exit 1 + done ) && + # Verify that current notes tree (pre-merge) has not changed (m == y) + verify_notes y && + verify_notes m && + test "$(git rev-parse refs/notes/m)" = "$(cat pre_merge_y)" +' + +cat <<EOF | sort >expect_notes_z +00494adecf2d9635a02fa431308d67993f853968 $commit_sha4 +283b48219aee9a4105f6cab337e789065c82c2b9 $commit_sha2 +0a81da8956346e19bcb27a906f04af327e03e31b $commit_sha1 +EOF + +cat >expect_log_z <<EOF +$commit_sha5 5th + +$commit_sha4 4th +z notes on 4th commit + +More z notes on 4th commit + +$commit_sha3 3rd + +$commit_sha2 2nd +z notes on 2nd commit + +$commit_sha1 1st +z notes on 1st commit + +EOF + +test_expect_success 'change notes in z' ' + git notes --ref z append -m "More z notes on 4th commit" 4th && + verify_notes z +' + +test_expect_success 'cannot do merge w/conflicts when previous merge is unfinished' ' + test -d .git/NOTES_MERGE_WORKTREE && + test_must_fail git notes merge z >output 2>&1 && + # Output should indicate what is wrong + grep -q "\\.git/NOTES_MERGE_\\* exists" output +' + +# Setup non-conflicting merge between x and new notes ref w + +cat <<EOF | sort >expect_notes_w +ceefa674873670e7ecd131814d909723cce2b669 $commit_sha2 +f75d1df88cbfe4258d49852f26cfc83f2ad4494b $commit_sha1 +EOF + +cat >expect_log_w <<EOF +$commit_sha5 5th + +$commit_sha4 4th + +$commit_sha3 3rd + +$commit_sha2 2nd +x notes on 2nd commit + +$commit_sha1 1st +w notes on 1st commit + +EOF + +test_expect_success 'setup unrelated notes ref (w)' ' + git config core.notesRef refs/notes/w && + git notes add -m "w notes on 1st commit" 1st && + git notes add -m "x notes on 2nd commit" 2nd && + verify_notes w +' + +cat <<EOF | sort >expect_notes_w +6e8e3febca3c2bb896704335cc4d0c34cb2f8715 $commit_sha4 +e5388c10860456ee60673025345fe2e153eb8cf8 $commit_sha3 +ceefa674873670e7ecd131814d909723cce2b669 $commit_sha2 +f75d1df88cbfe4258d49852f26cfc83f2ad4494b $commit_sha1 +EOF + +cat >expect_log_w <<EOF +$commit_sha5 5th + +$commit_sha4 4th +x notes on 4th commit + +$commit_sha3 3rd +x notes on 3rd commit + +$commit_sha2 2nd +x notes on 2nd commit + +$commit_sha1 1st +w notes on 1st commit + +EOF + +test_expect_success 'can do merge without conflicts even if previous merge is unfinished (x => w)' ' + test -d .git/NOTES_MERGE_WORKTREE && + git notes merge x && + verify_notes w && + # Verify that other notes refs has not changed (x and y) + verify_notes x && + verify_notes y +' + +cat <<EOF | sort >expect_notes_m +021faa20e931fb48986ffc6282b4bb05553ac946 $commit_sha4 +5772f42408c0dd6f097a7ca2d24de0e78d1c46b1 $commit_sha3 +283b48219aee9a4105f6cab337e789065c82c2b9 $commit_sha2 +0a59e787e6d688aa6309e56e8c1b89431a0fc1c1 $commit_sha1 +EOF + +cat >expect_log_m <<EOF +$commit_sha5 5th + +$commit_sha4 4th +y and z notes on 4th commit + +$commit_sha3 3rd +y notes on 3rd commit + +$commit_sha2 2nd +z notes on 2nd commit + +$commit_sha1 1st +y and z notes on 1st commit + +EOF + +test_expect_success 'finalize conflicting merge (z => m)' ' + # Resolve conflicts and finalize merge + cat >.git/NOTES_MERGE_WORKTREE/$commit_sha1 <<EOF && +y and z notes on 1st commit +EOF + cat >.git/NOTES_MERGE_WORKTREE/$commit_sha4 <<EOF && +y and z notes on 4th commit +EOF + git notes merge --commit && + # No .git/NOTES_MERGE_* files left + test_must_fail ls .git/NOTES_MERGE_* >output 2>/dev/null && + test_cmp /dev/null output && + # Merge commit has pre-merge y and pre-merge z as parents + test "$(git rev-parse refs/notes/m^1)" = "$(cat pre_merge_y)" && + test "$(git rev-parse refs/notes/m^2)" = "$(cat pre_merge_z)" && + # Merge commit mentions the notes refs merged + git log -1 --format=%B refs/notes/m > merge_commit_msg && + grep -q refs/notes/m merge_commit_msg && + grep -q refs/notes/z merge_commit_msg && + # Merge commit mentions conflicting notes + grep -q "Conflicts" merge_commit_msg && + ( for sha1 in $(cat expect_conflicts); do + grep -q "$sha1" merge_commit_msg || + exit 1 + done ) && + # Verify contents of merge result + verify_notes m && + # Verify that other notes refs has not changed (w, x, y and z) + verify_notes w && + verify_notes x && + verify_notes y && + verify_notes z +' + +cat >expect_conflict_$commit_sha4 <<EOF +<<<<<<< refs/notes/m +y notes on 4th commit +======= +z notes on 4th commit + +More z notes on 4th commit +>>>>>>> refs/notes/z +EOF + +cp expect_notes_y expect_notes_m +cp expect_log_y expect_log_m + +git rev-parse refs/notes/y > pre_merge_y +git rev-parse refs/notes/z > pre_merge_z + +test_expect_success 'redo merge of z into m (== y) with default ("manual") resolver => Conflicting 3-way merge' ' + git update-ref refs/notes/m refs/notes/y && + git config core.notesRef refs/notes/m && + test_must_fail git notes merge z >output && + # Output should point to where to resolve conflicts + grep -q "\\.git/NOTES_MERGE_WORKTREE" output && + # Inspect merge conflicts + ls .git/NOTES_MERGE_WORKTREE >output_conflicts && + test_cmp expect_conflicts output_conflicts && + ( for f in $(cat expect_conflicts); do + test_cmp "expect_conflict_$f" ".git/NOTES_MERGE_WORKTREE/$f" || + exit 1 + done ) && + # Verify that current notes tree (pre-merge) has not changed (m == y) + verify_notes y && + verify_notes m && + test "$(git rev-parse refs/notes/m)" = "$(cat pre_merge_y)" +' + +test_expect_success 'abort notes merge' ' + git notes merge --abort && + # No .git/NOTES_MERGE_* files left + test_must_fail ls .git/NOTES_MERGE_* >output 2>/dev/null && + test_cmp /dev/null output && + # m has not moved (still == y) + test "$(git rev-parse refs/notes/m)" = "$(cat pre_merge_y)" + # Verify that other notes refs has not changed (w, x, y and z) + verify_notes w && + verify_notes x && + verify_notes y && + verify_notes z +' + +git rev-parse refs/notes/y > pre_merge_y +git rev-parse refs/notes/z > pre_merge_z + +test_expect_success 'redo merge of z into m (== y) with default ("manual") resolver => Conflicting 3-way merge' ' + test_must_fail git notes merge z >output && + # Output should point to where to resolve conflicts + grep -q "\\.git/NOTES_MERGE_WORKTREE" output && + # Inspect merge conflicts + ls .git/NOTES_MERGE_WORKTREE >output_conflicts && + test_cmp expect_conflicts output_conflicts && + ( for f in $(cat expect_conflicts); do + test_cmp "expect_conflict_$f" ".git/NOTES_MERGE_WORKTREE/$f" || + exit 1 + done ) && + # Verify that current notes tree (pre-merge) has not changed (m == y) + verify_notes y && + verify_notes m && + test "$(git rev-parse refs/notes/m)" = "$(cat pre_merge_y)" +' + +cat <<EOF | sort >expect_notes_m +304dfb4325cf243025b9957486eb605a9b51c199 $commit_sha5 +283b48219aee9a4105f6cab337e789065c82c2b9 $commit_sha2 +0a59e787e6d688aa6309e56e8c1b89431a0fc1c1 $commit_sha1 +EOF + +cat >expect_log_m <<EOF +$commit_sha5 5th +new note on 5th commit + +$commit_sha4 4th + +$commit_sha3 3rd + +$commit_sha2 2nd +z notes on 2nd commit + +$commit_sha1 1st +y and z notes on 1st commit + +EOF + +test_expect_success 'add + remove notes in finalized merge (z => m)' ' + # Resolve one conflict + cat >.git/NOTES_MERGE_WORKTREE/$commit_sha1 <<EOF && +y and z notes on 1st commit +EOF + # Remove another conflict + rm .git/NOTES_MERGE_WORKTREE/$commit_sha4 && + # Remove a D/F conflict + rm .git/NOTES_MERGE_WORKTREE/$commit_sha3 && + # Add a new note + echo "new note on 5th commit" > .git/NOTES_MERGE_WORKTREE/$commit_sha5 && + # Finalize merge + git notes merge --commit && + # No .git/NOTES_MERGE_* files left + test_must_fail ls .git/NOTES_MERGE_* >output 2>/dev/null && + test_cmp /dev/null output && + # Merge commit has pre-merge y and pre-merge z as parents + test "$(git rev-parse refs/notes/m^1)" = "$(cat pre_merge_y)" && + test "$(git rev-parse refs/notes/m^2)" = "$(cat pre_merge_z)" && + # Merge commit mentions the notes refs merged + git log -1 --format=%B refs/notes/m > merge_commit_msg && + grep -q refs/notes/m merge_commit_msg && + grep -q refs/notes/z merge_commit_msg && + # Merge commit mentions conflicting notes + grep -q "Conflicts" merge_commit_msg && + ( for sha1 in $(cat expect_conflicts); do + grep -q "$sha1" merge_commit_msg || + exit 1 + done ) && + # Verify contents of merge result + verify_notes m && + # Verify that other notes refs has not changed (w, x, y and z) + verify_notes w && + verify_notes x && + verify_notes y && + verify_notes z +' + +cp expect_notes_y expect_notes_m +cp expect_log_y expect_log_m + +test_expect_success 'redo merge of z into m (== y) with default ("manual") resolver => Conflicting 3-way merge' ' + git update-ref refs/notes/m refs/notes/y && + test_must_fail git notes merge z >output && + # Output should point to where to resolve conflicts + grep -q "\\.git/NOTES_MERGE_WORKTREE" output && + # Inspect merge conflicts + ls .git/NOTES_MERGE_WORKTREE >output_conflicts && + test_cmp expect_conflicts output_conflicts && + ( for f in $(cat expect_conflicts); do + test_cmp "expect_conflict_$f" ".git/NOTES_MERGE_WORKTREE/$f" || + exit 1 + done ) && + # Verify that current notes tree (pre-merge) has not changed (m == y) + verify_notes y && + verify_notes m && + test "$(git rev-parse refs/notes/m)" = "$(cat pre_merge_y)" +' + +cp expect_notes_w expect_notes_m +cp expect_log_w expect_log_m + +test_expect_success 'reset notes ref m to somewhere else (w)' ' + git update-ref refs/notes/m refs/notes/w && + verify_notes m && + test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/w)" +' + +test_expect_success 'fail to finalize conflicting merge if underlying ref has moved in the meantime (m != NOTES_MERGE_PARTIAL^1)' ' + # Resolve conflicts + cat >.git/NOTES_MERGE_WORKTREE/$commit_sha1 <<EOF && +y and z notes on 1st commit +EOF + cat >.git/NOTES_MERGE_WORKTREE/$commit_sha4 <<EOF && +y and z notes on 4th commit +EOF + # Fail to finalize merge + test_must_fail git notes merge --commit >output 2>&1 && + # .git/NOTES_MERGE_* must remain + test -f .git/NOTES_MERGE_PARTIAL && + test -f .git/NOTES_MERGE_REF && + test -f .git/NOTES_MERGE_WORKTREE/$commit_sha1 && + test -f .git/NOTES_MERGE_WORKTREE/$commit_sha2 && + test -f .git/NOTES_MERGE_WORKTREE/$commit_sha3 && + test -f .git/NOTES_MERGE_WORKTREE/$commit_sha4 && + # Refs are unchanged + test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/w)" + test "$(git rev-parse refs/notes/y)" = "$(git rev-parse NOTES_MERGE_PARTIAL^1)" + test "$(git rev-parse refs/notes/m)" != "$(git rev-parse NOTES_MERGE_PARTIAL^1)" + # Mention refs/notes/m, and its current and expected value in output + grep -q "refs/notes/m" output && + grep -q "$(git rev-parse refs/notes/m)" output && + grep -q "$(git rev-parse NOTES_MERGE_PARTIAL^1)" output && + # Verify that other notes refs has not changed (w, x, y and z) + verify_notes w && + verify_notes x && + verify_notes y && + verify_notes z +' + +test_expect_success 'resolve situation by aborting the notes merge' ' + git notes merge --abort && + # No .git/NOTES_MERGE_* files left + test_must_fail ls .git/NOTES_MERGE_* >output 2>/dev/null && + test_cmp /dev/null output && + # m has not moved (still == w) + test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/w)" + # Verify that other notes refs has not changed (w, x, y and z) + verify_notes w && + verify_notes x && + verify_notes y && + verify_notes z +' + +test_done diff --git a/t/t3311-notes-merge-fanout.sh b/t/t3311-notes-merge-fanout.sh new file mode 100755 index 0000000000..93516ef67c --- /dev/null +++ b/t/t3311-notes-merge-fanout.sh @@ -0,0 +1,436 @@ +#!/bin/sh +# +# Copyright (c) 2010 Johan Herland +# + +test_description='Test notes merging at various fanout levels' + +. ./test-lib.sh + +verify_notes () { + notes_ref="$1" + commit="$2" + if test -f "expect_notes_$notes_ref" + then + git -c core.notesRef="refs/notes/$notes_ref" notes | + sort >"output_notes_$notes_ref" && + test_cmp "expect_notes_$notes_ref" "output_notes_$notes_ref" || + return 1 + fi && + git -c core.notesRef="refs/notes/$notes_ref" log --format="%H %s%n%N" \ + "$commit" >"output_log_$notes_ref" && + test_cmp "expect_log_$notes_ref" "output_log_$notes_ref" +} + +verify_fanout () { + notes_ref="$1" + # Expect entire notes tree to have a fanout == 1 + git rev-parse --quiet --verify "refs/notes/$notes_ref" >/dev/null && + git ls-tree -r --name-only "refs/notes/$notes_ref" | + while read path + do + case "$path" in + ??/??????????????????????????????????????) + : true + ;; + *) + echo "Invalid path \"$path\"" && + return 1 + ;; + esac + done +} + +verify_no_fanout () { + notes_ref="$1" + # Expect entire notes tree to have a fanout == 0 + git rev-parse --quiet --verify "refs/notes/$notes_ref" >/dev/null && + git ls-tree -r --name-only "refs/notes/$notes_ref" | + while read path + do + case "$path" in + ????????????????????????????????????????) + : true + ;; + *) + echo "Invalid path \"$path\"" && + return 1 + ;; + esac + done +} + +# Set up a notes merge scenario with different kinds of conflicts +test_expect_success 'setup a few initial commits with notes (notes ref: x)' ' + git config core.notesRef refs/notes/x && + for i in 1 2 3 4 5 + do + test_commit "commit$i" >/dev/null && + git notes add -m "notes for commit$i" || return 1 + done +' + +commit_sha1=$(git rev-parse commit1^{commit}) +commit_sha2=$(git rev-parse commit2^{commit}) +commit_sha3=$(git rev-parse commit3^{commit}) +commit_sha4=$(git rev-parse commit4^{commit}) +commit_sha5=$(git rev-parse commit5^{commit}) + +cat <<EOF | sort >expect_notes_x +aed91155c7a72c2188e781fdf40e0f3761b299db $commit_sha5 +99fab268f9d7ee7b011e091a436c78def8eeee69 $commit_sha4 +953c20ae26c7aa0b428c20693fe38bc687f9d1a9 $commit_sha3 +6358796131b8916eaa2dde6902642942a1cb37e1 $commit_sha2 +b02d459c32f0e68f2fe0981033bb34f38776ba47 $commit_sha1 +EOF + +cat >expect_log_x <<EOF +$commit_sha5 commit5 +notes for commit5 + +$commit_sha4 commit4 +notes for commit4 + +$commit_sha3 commit3 +notes for commit3 + +$commit_sha2 commit2 +notes for commit2 + +$commit_sha1 commit1 +notes for commit1 + +EOF + +test_expect_success 'sanity check (x)' ' + verify_notes x commit5 && + verify_no_fanout x +' + +num=300 + +cp expect_log_x expect_log_y + +test_expect_success 'Add a few hundred commits w/notes to trigger fanout (x -> y)' ' + git update-ref refs/notes/y refs/notes/x && + git config core.notesRef refs/notes/y && + i=5 && + while test $i -lt $num + do + i=$(($i + 1)) && + test_commit "commit$i" >/dev/null && + git notes add -m "notes for commit$i" || return 1 + done && + test "$(git rev-parse refs/notes/y)" != "$(git rev-parse refs/notes/x)" && + # Expected number of commits and notes + test $(git rev-list HEAD | wc -l) = $num && + test $(git notes list | wc -l) = $num && + # 5 first notes unchanged + verify_notes y commit5 +' + +test_expect_success 'notes tree has fanout (y)' 'verify_fanout y' + +test_expect_success 'No-op merge (already included) (x => y)' ' + git update-ref refs/notes/m refs/notes/y && + git config core.notesRef refs/notes/m && + git notes merge x && + test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/y)" +' + +test_expect_success 'Fast-forward merge (y => x)' ' + git update-ref refs/notes/m refs/notes/x && + git notes merge y && + test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/y)" +' + +cat <<EOF | sort >expect_notes_z +9f506ee70e20379d7f78204c77b334f43d77410d $commit_sha3 +23a47d6ea7d589895faf800752054818e1e7627b $commit_sha2 +b02d459c32f0e68f2fe0981033bb34f38776ba47 $commit_sha1 +EOF + +cat >expect_log_z <<EOF +$commit_sha5 commit5 + +$commit_sha4 commit4 + +$commit_sha3 commit3 +notes for commit3 + +appended notes for commit3 + +$commit_sha2 commit2 +new notes for commit2 + +$commit_sha1 commit1 +notes for commit1 + +EOF + +test_expect_success 'change some of the initial 5 notes (x -> z)' ' + git update-ref refs/notes/z refs/notes/x && + git config core.notesRef refs/notes/z && + git notes add -f -m "new notes for commit2" commit2 && + git notes append -m "appended notes for commit3" commit3 && + git notes remove commit4 && + git notes remove commit5 && + verify_notes z commit5 +' + +test_expect_success 'notes tree has no fanout (z)' 'verify_no_fanout z' + +cp expect_log_z expect_log_m + +test_expect_success 'successful merge without conflicts (y => z)' ' + git update-ref refs/notes/m refs/notes/z && + git config core.notesRef refs/notes/m && + git notes merge y && + verify_notes m commit5 && + # x/y/z unchanged + verify_notes x commit5 && + verify_notes y commit5 && + verify_notes z commit5 +' + +test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m' + +cat >expect_log_w <<EOF +$commit_sha5 commit5 + +$commit_sha4 commit4 +other notes for commit4 + +$commit_sha3 commit3 +other notes for commit3 + +$commit_sha2 commit2 +notes for commit2 + +$commit_sha1 commit1 +other notes for commit1 + +EOF + +test_expect_success 'introduce conflicting changes (y -> w)' ' + git update-ref refs/notes/w refs/notes/y && + git config core.notesRef refs/notes/w && + git notes add -f -m "other notes for commit1" commit1 && + git notes add -f -m "other notes for commit3" commit3 && + git notes add -f -m "other notes for commit4" commit4 && + git notes remove commit5 && + verify_notes w commit5 +' + +cat >expect_log_m <<EOF +$commit_sha5 commit5 + +$commit_sha4 commit4 +other notes for commit4 + +$commit_sha3 commit3 +other notes for commit3 + +$commit_sha2 commit2 +new notes for commit2 + +$commit_sha1 commit1 +other notes for commit1 + +EOF + +test_expect_success 'successful merge using "ours" strategy (z => w)' ' + git update-ref refs/notes/m refs/notes/w && + git config core.notesRef refs/notes/m && + git notes merge -s ours z && + verify_notes m commit5 && + # w/x/y/z unchanged + verify_notes w commit5 && + verify_notes x commit5 && + verify_notes y commit5 && + verify_notes z commit5 +' + +test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m' + +cat >expect_log_m <<EOF +$commit_sha5 commit5 + +$commit_sha4 commit4 + +$commit_sha3 commit3 +notes for commit3 + +appended notes for commit3 + +$commit_sha2 commit2 +new notes for commit2 + +$commit_sha1 commit1 +other notes for commit1 + +EOF + +test_expect_success 'successful merge using "theirs" strategy (z => w)' ' + git update-ref refs/notes/m refs/notes/w && + git notes merge -s theirs z && + verify_notes m commit5 && + # w/x/y/z unchanged + verify_notes w commit5 && + verify_notes x commit5 && + verify_notes y commit5 && + verify_notes z commit5 +' + +test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m' + +cat >expect_log_m <<EOF +$commit_sha5 commit5 + +$commit_sha4 commit4 +other notes for commit4 + +$commit_sha3 commit3 +other notes for commit3 + +notes for commit3 + +appended notes for commit3 + +$commit_sha2 commit2 +new notes for commit2 + +$commit_sha1 commit1 +other notes for commit1 + +EOF + +test_expect_success 'successful merge using "union" strategy (z => w)' ' + git update-ref refs/notes/m refs/notes/w && + git notes merge -s union z && + verify_notes m commit5 && + # w/x/y/z unchanged + verify_notes w commit5 && + verify_notes x commit5 && + verify_notes y commit5 && + verify_notes z commit5 +' + +test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m' + +cat >expect_log_m <<EOF +$commit_sha5 commit5 + +$commit_sha4 commit4 +other notes for commit4 + +$commit_sha3 commit3 +appended notes for commit3 +notes for commit3 +other notes for commit3 + +$commit_sha2 commit2 +new notes for commit2 + +$commit_sha1 commit1 +other notes for commit1 + +EOF + +test_expect_success 'successful merge using "cat_sort_uniq" strategy (z => w)' ' + git update-ref refs/notes/m refs/notes/w && + git notes merge -s cat_sort_uniq z && + verify_notes m commit5 && + # w/x/y/z unchanged + verify_notes w commit5 && + verify_notes x commit5 && + verify_notes y commit5 && + verify_notes z commit5 +' + +test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m' + +# We're merging z into w. Here are the conflicts we expect: +# +# commit | x -> w | x -> z | conflict? +# -------|-----------|-----------|---------- +# 1 | changed | unchanged | no, use w +# 2 | unchanged | changed | no, use z +# 3 | changed | changed | yes (w, then z in conflict markers) +# 4 | changed | deleted | yes (w) +# 5 | deleted | deleted | no, deleted + +test_expect_success 'fails to merge using "manual" strategy (z => w)' ' + git update-ref refs/notes/m refs/notes/w && + test_must_fail git notes merge z +' + +test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m' + +cat <<EOF | sort >expect_conflicts +$commit_sha3 +$commit_sha4 +EOF + +cat >expect_conflict_$commit_sha3 <<EOF +<<<<<<< refs/notes/m +other notes for commit3 +======= +notes for commit3 + +appended notes for commit3 +>>>>>>> refs/notes/z +EOF + +cat >expect_conflict_$commit_sha4 <<EOF +other notes for commit4 +EOF + +test_expect_success 'verify conflict entries (with no fanout)' ' + ls .git/NOTES_MERGE_WORKTREE >output_conflicts && + test_cmp expect_conflicts output_conflicts && + ( for f in $(cat expect_conflicts); do + test_cmp "expect_conflict_$f" ".git/NOTES_MERGE_WORKTREE/$f" || + exit 1 + done ) && + # Verify that current notes tree (pre-merge) has not changed (m == w) + test "$(git rev-parse refs/notes/m)" = "$(git rev-parse refs/notes/w)" +' + +cat >expect_log_m <<EOF +$commit_sha5 commit5 + +$commit_sha4 commit4 +other notes for commit4 + +$commit_sha3 commit3 +other notes for commit3 + +appended notes for commit3 + +$commit_sha2 commit2 +new notes for commit2 + +$commit_sha1 commit1 +other notes for commit1 + +EOF + +test_expect_success 'resolve and finalize merge (z => w)' ' + cat >.git/NOTES_MERGE_WORKTREE/$commit_sha3 <<EOF && +other notes for commit3 + +appended notes for commit3 +EOF + git notes merge --commit && + verify_notes m commit5 && + # w/x/y/z unchanged + verify_notes w commit5 && + verify_notes x commit5 && + verify_notes y commit5 && + verify_notes z commit5 +' + +test_expect_success 'notes tree still has fanout after merge (m)' 'verify_fanout m' + +test_done diff --git a/t/t3402-rebase-merge.sh b/t/t3402-rebase-merge.sh index 2bea65634a..be8c1d5ef9 100755 --- a/t/t3402-rebase-merge.sh +++ b/t/t3402-rebase-merge.sh @@ -117,4 +117,25 @@ test_expect_success 'picking rebase' ' esac ' +test_expect_success 'rebase -s funny -Xopt' ' + test_when_finished "rm -fr test-bin funny.was.run" && + mkdir test-bin && + cat >test-bin/git-merge-funny <<-EOF && + #!$SHELL_PATH + case "\$1" in --opt) ;; *) exit 2 ;; esac + shift && + >funny.was.run && + exec git merge-recursive "\$@" + EOF + chmod +x test-bin/git-merge-funny && + git reset --hard && + git checkout -b test-funny master^ && + test_commit funny && + ( + PATH=./test-bin:$PATH + git rebase -s funny -Xopt master + ) && + test -f funny.was.run +' + test_done diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index 7d20a74c5c..7d8147bb93 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -7,34 +7,39 @@ test_description='git rebase interactive This test runs git rebase "interactively", by faking an edit, and verifies that the result still makes sense. + +Initial setup: + + one - two - three - four (conflict-branch) + / + A - B - C - D - E (master) + | \ + | F - G - H (branch1) + | \ + |\ I (branch2) + | \ + | J - K - L - M (no-conflict-branch) + \ + N - O - P (no-ff-branch) + + where A, B, D and G all touch file1, and one, two, three, four all + touch file "conflict". ' . ./test-lib.sh . "$TEST_DIRECTORY"/lib-rebase.sh +test_cmp_rev () { + git rev-parse --verify "$1" >expect.rev && + git rev-parse --verify "$2" >actual.rev && + test_cmp expect.rev actual.rev +} + set_fake_editor -# Set up the repository like this: -# -# one - two - three - four (conflict-branch) -# / -# A - B - C - D - E (master) -# | \ -# | F - G - H (branch1) -# | \ -# |\ I (branch2) -# | \ -# | J - K - L - M (no-conflict-branch) -# \ -# N - O - P (no-ff-branch) -# -# where A, B, D and G all touch file1, and one, two, three, four all -# touch file "conflict". -# # WARNING: Modifications to the initial repository can change the SHA ID used # in the expect2 file for the 'stop on conflicting pick' test. - test_expect_success 'setup' ' test_commit A file1 && test_commit B file1 && @@ -46,29 +51,29 @@ test_expect_success 'setup' ' test_commit G file1 && test_commit H file5 && git checkout -b branch2 F && - test_commit I file6 + test_commit I file6 && git checkout -b conflict-branch A && - for n in one two three four - do - test_commit $n conflict - done && + test_commit one conflict && + test_commit two conflict && + test_commit three conflict && + test_commit four conflict && git checkout -b no-conflict-branch A && - for n in J K L M - do - test_commit $n file$n - done && + test_commit J fileJ && + test_commit K fileK && + test_commit L fileL && + test_commit M fileM && git checkout -b no-ff-branch A && - for n in N O P - do - test_commit $n file$n - done + test_commit N fileN && + test_commit O fileO && + test_commit P fileP ' # "exec" commands are ran with the user shell by default, but this may # be non-POSIX. For example, if SHELL=zsh then ">file" doesn't work # to create a file. Unseting SHELL avoids such non-portable behavior -# in tests. +# in tests. It must be exported for it to take effect where needed. SHELL= +export SHELL test_expect_success 'rebase -i with the exec command' ' git checkout master && @@ -82,20 +87,12 @@ test_expect_success 'rebase -i with the exec command' ' test_path_is_file touch-one && test_path_is_file touch-two && test_path_is_missing touch-three " (should have stopped before)" && - test $(git rev-parse C) = $(git rev-parse HEAD) || { - echo "Stopped at wrong revision:" - echo "($(git describe --tags HEAD) instead of C)" - false - } && + test_cmp_rev C HEAD && git rebase --continue && test_path_is_file touch-three && test_path_is_file "touch-file name with spaces" && test_path_is_file touch-after-semicolon && - test $(git rev-parse master) = $(git rev-parse HEAD) || { - echo "Stopped at wrong revision:" - echo "($(git describe --tags HEAD) instead of master)" - false - } && + test_cmp_rev master HEAD && rm -f touch-* ' @@ -116,11 +113,7 @@ test_expect_success 'rebase -i with the exec command checks tree cleanness' ' export FAKE_LINES && test_must_fail git rebase -i HEAD^ ) && - test $(git rev-parse master^) = $(git rev-parse HEAD) || { - echo "Stopped at wrong revision:" - echo "($(git describe --tags HEAD) instead of master^)" - false - } && + test_cmp_rev master^ HEAD && git reset --hard && git rebase --continue ' @@ -584,7 +577,7 @@ test_expect_success 'do "noop" when there is nothing to cherry-pick' ' git checkout -b branch4 HEAD && GIT_EDITOR=: git commit --amend \ - --author="Somebody else <somebody@else.com>" + --author="Somebody else <somebody@else.com>" && test $(git rev-parse branch3) != $(git rev-parse branch4) && git rebase -i branch3 && test $(git rev-parse branch3) = $(git rev-parse branch4) @@ -599,7 +592,7 @@ test_expect_success 'submodule rebase setup' ' git add elif && git commit -m "submodule initial" ) && echo 1 >file1 && - git add file1 sub + git add file1 sub && test_tick && git commit -m "One" && echo 2 >file1 && @@ -655,6 +648,7 @@ test_expect_success 'rebase -i can copy notes' ' cat >expect <<EOF an earlier note + a note EOF diff --git a/t/t3406-rebase-message.sh b/t/t3406-rebase-message.sh index 85fc7c4af8..fe5f936988 100755 --- a/t/t3406-rebase-message.sh +++ b/t/t3406-rebase-message.sh @@ -43,20 +43,20 @@ test_expect_success 'rebase -m' ' ' test_expect_success 'rebase --stat' ' - git reset --hard start + git reset --hard start && git rebase --stat master >diffstat.txt && grep "^ fileX | *1 +$" diffstat.txt ' test_expect_success 'rebase w/config rebase.stat' ' - git reset --hard start + git reset --hard start && git config rebase.stat true && git rebase master >diffstat.txt && grep "^ fileX | *1 +$" diffstat.txt ' test_expect_success 'rebase -n overrides config rebase.stat config' ' - git reset --hard start + git reset --hard start && git config rebase.stat true && git rebase -n master >diffstat.txt && ! grep "^ fileX | *1 +$" diffstat.txt diff --git a/t/t3407-rebase-abort.sh b/t/t3407-rebase-abort.sh index fbb3f2e0df..e573dc845b 100755 --- a/t/t3407-rebase-abort.sh +++ b/t/t3407-rebase-abort.sh @@ -72,6 +72,18 @@ testrebase() { test $(git rev-parse to-rebase) = $(git rev-parse pre-rebase) && test ! -d "$dotest" ' + + test_expect_success "rebase$type --abort does not update reflog" ' + cd "$work_dir" && + # Clean up the state from the previous one + git reset --hard pre-rebase && + git reflog show to-rebase > reflog_before && + test_must_fail git rebase$type master && + git rebase --abort && + git reflog show to-rebase > reflog_after && + test_cmp reflog_before reflog_after && + rm reflog_before reflog_after + ' } testrebase "" .git/rebase-apply diff --git a/t/t3408-rebase-multi-line.sh b/t/t3408-rebase-multi-line.sh index 2062b858bb..6b84e6042a 100755 --- a/t/t3408-rebase-multi-line.sh +++ b/t/t3408-rebase-multi-line.sh @@ -16,7 +16,7 @@ test_expect_success setup ' git commit -a -m "A sample commit log message that has a long summary that spills over multiple lines. -But otherwise with a sane description." +But otherwise with a sane description." && git branch side && diff --git a/t/t3409-rebase-preserve-merges.sh b/t/t3409-rebase-preserve-merges.sh index 74161a42ec..19341e5ca1 100755 --- a/t/t3409-rebase-preserve-merges.sh +++ b/t/t3409-rebase-preserve-merges.sh @@ -72,7 +72,7 @@ test_expect_success 'rebase -p fakes interactive rebase' ' git fetch && git rebase -p origin/topic && test 1 = $(git rev-list --all --pretty=oneline | grep "Modify A" | wc -l) && - test 1 = $(git rev-list --all --pretty=oneline | grep "Merge remote branch " | wc -l) + test 1 = $(git rev-list --all --pretty=oneline | grep "Merge remote-tracking branch " | wc -l) ) ' diff --git a/t/t3412-rebase-root.sh b/t/t3412-rebase-root.sh index 5869061c5b..086c91c7b4 100755 --- a/t/t3412-rebase-root.sh +++ b/t/t3412-rebase-root.sh @@ -173,14 +173,14 @@ EOF test_expect_success 'pre-rebase hook stops rebase' ' git checkout -b stops1 other && test_must_fail git rebase --root --onto master && - test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops1 + test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops1 && test 0 = $(git rev-list other...stops1 | wc -l) ' test_expect_success 'pre-rebase hook stops rebase -i' ' git checkout -b stops2 other && test_must_fail git rebase --root --onto master && - test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops2 + test "z$(git symbolic-ref HEAD)" = zrefs/heads/stops2 && test 0 = $(git rev-list other...stops2 | wc -l) ' diff --git a/t/t3415-rebase-autosquash.sh b/t/t3415-rebase-autosquash.sh index 37cb89ab53..b38be8e937 100755 --- a/t/t3415-rebase-autosquash.sh +++ b/t/t3415-rebase-autosquash.sh @@ -14,6 +14,7 @@ test_expect_success setup ' git add . && test_tick && git commit -m "first commit" && + git tag first-commit && echo 3 >file3 && git add . && test_tick && @@ -21,12 +22,12 @@ test_expect_success setup ' git tag base ' -test_auto_fixup() { +test_auto_fixup () { git reset --hard base && echo 1 >file1 && git add -u && test_tick && - git commit -m "fixup! first" + git commit -m "fixup! first" && git tag $1 && test_tick && @@ -50,12 +51,12 @@ test_expect_success 'auto fixup (config)' ' test_must_fail test_auto_fixup final-fixup-config-false ' -test_auto_squash() { +test_auto_squash () { git reset --hard base && echo 1 >file1 && git add -u && test_tick && - git commit -m "squash! first" + git commit -m "squash! first" && git tag $1 && test_tick && @@ -84,7 +85,7 @@ test_expect_success 'misspelled auto squash' ' echo 1 >file1 && git add -u && test_tick && - git commit -m "squash! forst" + git commit -m "squash! forst" && git tag final-missquash && test_tick && git rebase --autosquash -i HEAD^^^ && @@ -94,4 +95,102 @@ test_expect_success 'misspelled auto squash' ' test 0 = $(git rev-list final-missquash...HEAD | wc -l) ' +test_expect_success 'auto squash that matches 2 commits' ' + git reset --hard base && + echo 4 >file4 && + git add file4 && + test_tick && + git commit -m "first new commit" && + echo 1 >file1 && + git add -u && + test_tick && + git commit -m "squash! first" && + git tag final-multisquash && + test_tick && + git rebase --autosquash -i HEAD~4 && + git log --oneline >actual && + test 4 = $(wc -l <actual) && + git diff --exit-code final-multisquash && + test 1 = "$(git cat-file blob HEAD^^:file1)" && + test 2 = $(git cat-file commit HEAD^^ | grep first | wc -l) && + test 1 = $(git cat-file commit HEAD | grep first | wc -l) +' + +test_expect_success 'auto squash that matches a commit after the squash' ' + git reset --hard base && + echo 1 >file1 && + git add -u && + test_tick && + git commit -m "squash! third" && + echo 4 >file4 && + git add file4 && + test_tick && + git commit -m "third commit" && + git tag final-presquash && + test_tick && + git rebase --autosquash -i HEAD~4 && + git log --oneline >actual && + test 5 = $(wc -l <actual) && + git diff --exit-code final-presquash && + test 0 = "$(git cat-file blob HEAD^^:file1)" && + test 1 = "$(git cat-file blob HEAD^:file1)" && + test 1 = $(git cat-file commit HEAD | grep third | wc -l) && + test 1 = $(git cat-file commit HEAD^ | grep third | wc -l) +' +test_expect_success 'auto squash that matches a sha1' ' + git reset --hard base && + echo 1 >file1 && + git add -u && + test_tick && + git commit -m "squash! $(git rev-parse --short HEAD^)" && + git tag final-shasquash && + test_tick && + git rebase --autosquash -i HEAD^^^ && + git log --oneline >actual && + test 3 = $(wc -l <actual) && + git diff --exit-code final-shasquash && + test 1 = "$(git cat-file blob HEAD^:file1)" && + test 1 = $(git cat-file commit HEAD^ | grep squash | wc -l) +' + +test_expect_success 'auto squash that matches longer sha1' ' + git reset --hard base && + echo 1 >file1 && + git add -u && + test_tick && + git commit -m "squash! $(git rev-parse --short=11 HEAD^)" && + git tag final-longshasquash && + test_tick && + git rebase --autosquash -i HEAD^^^ && + git log --oneline >actual && + test 3 = $(wc -l <actual) && + git diff --exit-code final-longshasquash && + test 1 = "$(git cat-file blob HEAD^:file1)" && + test 1 = $(git cat-file commit HEAD^ | grep squash | wc -l) +' + +test_auto_commit_flags () { + git reset --hard base && + echo 1 >file1 && + git add -u && + test_tick && + git commit --$1 first-commit && + git tag final-commit-$1 && + test_tick && + git rebase --autosquash -i HEAD^^^ && + git log --oneline >actual && + test 3 = $(wc -l <actual) && + git diff --exit-code final-commit-$1 && + test 1 = "$(git cat-file blob HEAD^:file1)" && + test $2 = $(git cat-file commit HEAD^ | grep first | wc -l) +} + +test_expect_success 'use commit --fixup' ' + test_auto_commit_flags fixup 1 +' + +test_expect_success 'use commit --squash' ' + test_auto_commit_flags squash 2 +' + test_done diff --git a/t/t3417-rebase-whitespace-fix.sh b/t/t3417-rebase-whitespace-fix.sh index 220a740ee8..1fb3e499b4 100755 --- a/t/t3417-rebase-whitespace-fix.sh +++ b/t/t3417-rebase-whitespace-fix.sh @@ -89,7 +89,7 @@ test_expect_success 'same, but do not remove trailing spaces' ' git config core.whitespace "-blank-at-eol" && git reset --hard HEAD^ && cp third file && git add file && git commit -m third && - git rebase --whitespace=fix HEAD^^ + git rebase --whitespace=fix HEAD^^ && git diff --exit-code HEAD^:file expect-second && test_cmp file third ' diff --git a/t/t3419-rebase-patch-id.sh b/t/t3419-rebase-patch-id.sh new file mode 100755 index 0000000000..bd8efaf005 --- /dev/null +++ b/t/t3419-rebase-patch-id.sh @@ -0,0 +1,109 @@ +#!/bin/sh + +test_description='git rebase - test patch id computation' + +. ./test-lib.sh + +test_set_prereq NOT_EXPENSIVE +test -n "$GIT_PATCHID_TIMING_TESTS" && test_set_prereq EXPENSIVE +test -x /usr/bin/time && test_set_prereq USR_BIN_TIME + +count() +{ + i=0 + while test $i -lt $1 + do + echo "$i" + i=$(($i+1)) + done +} + +scramble() +{ + i=0 + while read x + do + if test $i -ne 0 + then + echo "$x" + fi + i=$((($i+1) % 10)) + done < "$1" > "$1.new" + mv -f "$1.new" "$1" +} + +run() +{ + echo \$ "$@" + /usr/bin/time "$@" >/dev/null +} + +test_expect_success 'setup' ' + git commit --allow-empty -m initial + git tag root +' + +do_tests() +{ + pr=$1 + nlines=$2 + + test_expect_success $pr "setup: $nlines lines" " + rm -f .gitattributes && + git checkout -q -f master && + git reset --hard root && + count $nlines >file && + git add file && + git commit -q -m initial && + git branch -f other && + + scramble file && + git add file && + git commit -q -m 'change big file' && + + git checkout -q other && + : >newfile && + git add newfile && + git commit -q -m 'add small file' && + + git cherry-pick master >/dev/null 2>&1 + " + + test_debug " + run git diff master^\! + " + + test_expect_success $pr 'setup attributes' " + echo 'file binary' >.gitattributes + " + + test_debug " + run git format-patch --stdout master && + run git format-patch --stdout --ignore-if-in-upstream master + " + + test_expect_success $pr 'detect upstream patch' " + git checkout -q master && + scramble file && + git add file && + git commit -q -m 'change big file again' && + git checkout -q other^{} && + git rebase master && + test_must_fail test -n \"\$(git rev-list master...HEAD~)\" + " + + test_expect_success $pr 'do not drop patch' " + git branch -f squashed master && + git checkout -q -f squashed && + git reset -q --soft HEAD~2 && + git commit -q -m squashed && + git checkout -q other^{} && + test_must_fail git rebase squashed && + rm -rf .git/rebase-apply + " +} + +do_tests NOT_EXPENSIVE 500 +do_tests EXPENSIVE 50000 + +test_done diff --git a/t/t3501-revert-cherry-pick.sh b/t/t3501-revert-cherry-pick.sh index bc7aedd048..753a6c972c 100755 --- a/t/t3501-revert-cherry-pick.sh +++ b/t/t3501-revert-cherry-pick.sh @@ -81,7 +81,17 @@ test_expect_success 'revert after renaming branch' ' ' -test_expect_success 'revert forbidden on dirty working tree' ' +test_expect_success 'cherry-pick on stat-dirty working tree' ' + git clone . copy && + ( + cd copy && + git checkout initial && + test-chmtime +40 oops && + git cherry-pick added + ) +' + +test_expect_success C_LOCALE_OUTPUT 'revert forbidden on dirty working tree' ' echo content >extra_file && git add extra_file && diff --git a/t/t3504-cherry-pick-rerere.sh b/t/t3504-cherry-pick-rerere.sh index f7b3518a32..e6a64816ef 100755 --- a/t/t3504-cherry-pick-rerere.sh +++ b/t/t3504-cherry-pick-rerere.sh @@ -23,7 +23,7 @@ test_expect_success 'conflicting merge' ' test_expect_success 'fixup' ' echo foo-dev >foo && git add foo && test_tick && git commit -q -m 4 && - git reset --hard HEAD^ + git reset --hard HEAD^ && echo foo-dev >expect ' @@ -33,7 +33,7 @@ test_expect_success 'cherry-pick conflict' ' ' test_expect_success 'reconfigure' ' - git config rerere.enabled false + git config rerere.enabled false && git reset --hard ' diff --git a/t/t3506-cherry-pick-ff.sh b/t/t3506-cherry-pick-ff.sh index e17ae712b1..51ca391e47 100755 --- a/t/t3506-cherry-pick-ff.sh +++ b/t/t3506-cherry-pick-ff.sh @@ -95,4 +95,14 @@ test_expect_success 'cherry pick a merge relative to nonexistent parent with --f test_must_fail git cherry-pick --ff -m 3 C ' +test_expect_success 'cherry pick a root commit with --ff' ' + git reset --hard first -- && + git rm file1 && + echo first >file2 && + git add file2 && + git commit --amend -m "file2" && + git cherry-pick --ff first && + test "$(git rev-parse --verify HEAD)" = "1df192cd8bc58a2b275d842cede4d221ad9000d1" +' + test_done diff --git a/t/t3507-cherry-pick-conflict.sh b/t/t3507-cherry-pick-conflict.sh index 607bf25d8f..c0c8330c20 100755 --- a/t/t3507-cherry-pick-conflict.sh +++ b/t/t3507-cherry-pick-conflict.sh @@ -11,6 +11,18 @@ test_description='test cherry-pick and revert with conflicts . ./test-lib.sh +test_cmp_rev () { + git rev-parse --verify "$1" >expect.rev && + git rev-parse --verify "$2" >actual.rev && + test_cmp expect.rev actual.rev +} + +pristine_detach () { + git checkout -f "$1^0" && + git read-tree -u --reset HEAD && + git clean -d -f -f -q -x +} + test_expect_success setup ' echo unrelated >unrelated && @@ -23,13 +35,7 @@ test_expect_success setup ' ' test_expect_success 'failed cherry-pick does not advance HEAD' ' - - git checkout -f initial^0 && - git read-tree -u --reset HEAD && - git clean -d -f -f -q -x && - - git update-index --refresh && - git diff-index --exit-code HEAD && + pristine_detach initial && head=$(git rev-parse HEAD) && test_must_fail git cherry-pick picked && @@ -38,34 +44,97 @@ test_expect_success 'failed cherry-pick does not advance HEAD' ' test "$head" = "$newhead" ' -test_expect_success 'advice from failed cherry-pick' " - git checkout -f initial^0 && - git read-tree -u --reset HEAD && - git clean -d -f -f -q -x && - - git update-index --refresh && - git diff-index --exit-code HEAD && +test_expect_success C_LOCALE_OUTPUT 'advice from failed cherry-pick' " + pristine_detach initial && picked=\$(git rev-parse --short picked) && cat <<-EOF >expected && error: could not apply \$picked... picked hint: after resolving the conflicts, mark the corrected paths hint: with 'git add <paths>' or 'git rm <paths>' - hint: and commit the result with 'git commit -c \$picked' + hint: and commit the result with 'git commit' EOF test_must_fail git cherry-pick picked 2>actual && test_cmp expected actual " -test_expect_success 'failed cherry-pick produces dirty index' ' +test_expect_success 'failed cherry-pick sets CHERRY_PICK_HEAD' ' + pristine_detach initial && + test_must_fail git cherry-pick picked && + test_cmp_rev picked CHERRY_PICK_HEAD +' - git checkout -f initial^0 && - git read-tree -u --reset HEAD && - git clean -d -f -f -q -x && +test_expect_success 'successful cherry-pick does not set CHERRY_PICK_HEAD' ' + pristine_detach initial && + git cherry-pick base && + test_must_fail git rev-parse --verify CHERRY_PICK_HEAD +' + +test_expect_success 'cherry-pick --no-commit does not set CHERRY_PICK_HEAD' ' + pristine_detach initial && + git cherry-pick --no-commit base && + test_must_fail git rev-parse --verify CHERRY_PICK_HEAD +' + +test_expect_success 'GIT_CHERRY_PICK_HELP suppresses CHERRY_PICK_HEAD' ' + pristine_detach initial && + ( + GIT_CHERRY_PICK_HELP="and then do something else" && + export GIT_CHERRY_PICK_HELP && + test_must_fail git cherry-pick picked + ) && + test_must_fail git rev-parse --verify CHERRY_PICK_HEAD +' + +test_expect_success 'git reset clears CHERRY_PICK_HEAD' ' + pristine_detach initial && + + test_must_fail git cherry-pick picked && + git reset && + + test_must_fail git rev-parse --verify CHERRY_PICK_HEAD +' + +test_expect_success 'failed commit does not clear CHERRY_PICK_HEAD' ' + pristine_detach initial && + + test_must_fail git cherry-pick picked && + test_must_fail git commit && + + test_cmp_rev picked CHERRY_PICK_HEAD +' + +test_expect_success 'cancelled commit does not clear CHERRY_PICK_HEAD' ' + pristine_detach initial && - git update-index --refresh && - git diff-index --exit-code HEAD && + test_must_fail git cherry-pick picked && + echo resolved >foo && + git add foo && + git update-index --refresh -q && + test_must_fail git diff-index --exit-code HEAD && + ( + GIT_EDITOR=false && + export GIT_EDITOR && + test_must_fail git commit + ) && + + test_cmp_rev picked CHERRY_PICK_HEAD +' + +test_expect_success 'successful commit clears CHERRY_PICK_HEAD' ' + pristine_detach initial && + + test_must_fail git cherry-pick picked && + echo resolved >foo && + git add foo && + git commit && + + test_must_fail git rev-parse --verify CHERRY_PICK_HEAD +' + +test_expect_success 'failed cherry-pick produces dirty index' ' + pristine_detach initial && test_must_fail git cherry-pick picked && @@ -74,9 +143,7 @@ test_expect_success 'failed cherry-pick produces dirty index' ' ' test_expect_success 'failed cherry-pick registers participants in index' ' - - git read-tree -u --reset HEAD && - git clean -d -f -f -q -x && + pristine_detach initial && { git checkout base -- foo && git ls-files --stage foo && @@ -90,10 +157,7 @@ test_expect_success 'failed cherry-pick registers participants in index' ' 2 s/ 0 / 2 / 3 s/ 0 / 3 / " < stages > expected && - git checkout -f initial^0 && - - git update-index --refresh && - git diff-index --exit-code HEAD && + git read-tree -u --reset HEAD && test_must_fail git cherry-pick picked && git ls-files --stage --unmerged > actual && @@ -102,10 +166,7 @@ test_expect_success 'failed cherry-pick registers participants in index' ' ' test_expect_success 'failed cherry-pick describes conflict in work tree' ' - - git checkout -f initial^0 && - git read-tree -u --reset HEAD && - git clean -d -f -f -q -x && + pristine_detach initial && cat <<-EOF > expected && <<<<<<< HEAD a @@ -114,9 +175,6 @@ test_expect_success 'failed cherry-pick describes conflict in work tree' ' >>>>>>> objid picked EOF - git update-index --refresh && - git diff-index --exit-code HEAD && - test_must_fail git cherry-pick picked && sed "s/[a-f0-9]*\.\.\./objid/" foo > actual && @@ -124,11 +182,8 @@ test_expect_success 'failed cherry-pick describes conflict in work tree' ' ' test_expect_success 'diff3 -m style' ' - + pristine_detach initial && git config merge.conflictstyle diff3 && - git checkout -f initial^0 && - git read-tree -u --reset HEAD && - git clean -d -f -f -q -x && cat <<-EOF > expected && <<<<<<< HEAD a @@ -139,9 +194,6 @@ test_expect_success 'diff3 -m style' ' >>>>>>> objid picked EOF - git update-index --refresh && - git diff-index --exit-code HEAD && - test_must_fail git cherry-pick picked && sed "s/[a-f0-9]*\.\.\./objid/" foo > actual && @@ -149,10 +201,8 @@ test_expect_success 'diff3 -m style' ' ' test_expect_success 'revert also handles conflicts sanely' ' - git config --unset merge.conflictstyle && - git read-tree -u --reset HEAD && - git clean -d -f -f -q -x && + pristine_detach initial && cat <<-EOF > expected && <<<<<<< HEAD a @@ -173,10 +223,7 @@ test_expect_success 'revert also handles conflicts sanely' ' 2 s/ 0 / 2 / 3 s/ 0 / 3 / " < stages > expected-stages && - git checkout -f initial^0 && - - git update-index --refresh && - git diff-index --exit-code HEAD && + git read-tree -u --reset HEAD && head=$(git rev-parse HEAD) && test_must_fail git revert picked && @@ -192,10 +239,8 @@ test_expect_success 'revert also handles conflicts sanely' ' ' test_expect_success 'revert conflict, diff3 -m style' ' + pristine_detach initial && git config merge.conflictstyle diff3 && - git checkout -f initial^0 && - git read-tree -u --reset HEAD && - git clean -d -f -f -q -x && cat <<-EOF > expected && <<<<<<< HEAD a @@ -206,9 +251,6 @@ test_expect_success 'revert conflict, diff3 -m style' ' >>>>>>> parent of objid picked EOF - git update-index --refresh && - git diff-index --exit-code HEAD && - test_must_fail git revert picked && sed "s/[a-f0-9]*\.\.\./objid/" foo > actual && diff --git a/t/t3509-cherry-pick-merge-df.sh b/t/t3509-cherry-pick-merge-df.sh index 948ca1bce6..df921d1f33 100755 --- a/t/t3509-cherry-pick-merge-df.sh +++ b/t/t3509-cherry-pick-merge-df.sh @@ -3,12 +3,14 @@ test_description='Test cherry-pick with directory/file conflicts' . ./test-lib.sh -test_expect_success SYMLINKS 'Setup rename across paths each below D/F conflicts' ' +test_expect_success 'Initialize repository' ' mkdir a && >a/f && git add a && - git commit -m a && + git commit -m a +' +test_expect_success SYMLINKS 'Setup rename across paths each below D/F conflicts' ' mkdir b && ln -s ../a b/a && git add b && diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh index b26cabd571..cd093bd347 100755 --- a/t/t3600-rm.sh +++ b/t/t3600-rm.sh @@ -96,7 +96,7 @@ test_expect_success FUNNYNAMES \ "git rm -f 'space embedded' 'tab embedded' 'newline embedded'" -test_expect_success RO_DIR 'Test that "git rm -f" fails if its rm fails' ' +test_expect_success SANITY 'Test that "git rm -f" fails if its rm fails' ' chmod a-w . && test_must_fail git rm -f baz && chmod 775 . diff --git a/t/t3700-add.sh b/t/t3700-add.sh index ec7108358e..7de42faf48 100755 --- a/t/t3700-add.sh +++ b/t/t3700-add.sh @@ -268,8 +268,12 @@ test_expect_success 'git add --dry-run of existing changed file' " test_expect_success 'git add --dry-run of non-existing file' " echo ignored-file >>.gitignore && - test_must_fail git add --dry-run track-this ignored-file >actual 2>&1 && - echo \"fatal: pathspec 'ignored-file' did not match any files\" | test_cmp - actual + test_must_fail git add --dry-run track-this ignored-file >actual 2>&1 +" + +test_expect_success C_LOCALE_OUTPUT 'git add --dry-run of an existing file output' " + echo \"fatal: pathspec 'ignored-file' did not match any files\" >expect && + test_cmp expect actual " cat >expect.err <<\EOF @@ -283,7 +287,10 @@ add 'track-this' EOF test_expect_success 'git add --dry-run --ignore-missing of non-existing file' ' - test_must_fail git add --dry-run --ignore-missing track-this ignored-file >actual.out 2>actual.err && + test_must_fail git add --dry-run --ignore-missing track-this ignored-file >actual.out 2>actual.err +' + +test_expect_success C_LOCALE_OUTPUT 'git add --dry-run --ignore-missing of non-existing file output' ' test_cmp expect.out actual.out && test_cmp expect.err actual.err ' diff --git a/t/t3900-i18n-commit.sh b/t/t3900-i18n-commit.sh index 256c4c9701..c06a5ee766 100755 --- a/t/t3900-i18n-commit.sh +++ b/t/t3900-i18n-commit.sh @@ -133,4 +133,33 @@ do ' done +test_commit_autosquash_flags () { + H=$1 + flag=$2 + test_expect_success "commit --$flag with $H encoding" ' + git config i18n.commitencoding $H && + git checkout -b $H-$flag C0 && + echo $H >>F && + git commit -a -F "$TEST_DIRECTORY"/t3900/$H.txt && + test_tick && + echo intermediate stuff >>G && + git add G && + git commit -a -m "intermediate commit" && + test_tick && + echo $H $flag >>F && + git commit -a --$flag HEAD~1 $3 && + E=$(git cat-file commit '$H-$flag' | + sed -ne "s/^encoding //p") && + test "z$E" = "z$H" && + git config --unset-all i18n.commitencoding && + git rebase --autosquash -i HEAD^^^ && + git log --oneline >actual && + test 3 = $(wc -l <actual) + ' +} + +test_commit_autosquash_flags eucJP fixup + +test_commit_autosquash_flags ISO-2022-JP squash '-m "squash message"' + test_done diff --git a/t/t3902-quoted.sh b/t/t3902-quoted.sh index 7d49469841..da82b655b3 100755 --- a/t/t3902-quoted.sh +++ b/t/t3902-quoted.sh @@ -36,19 +36,19 @@ for_each_name () { test_expect_success TABS_IN_FILENAMES 'setup' ' mkdir "$FN" && - for_each_name "echo initial >\"\$name\"" + for_each_name "echo initial >\"\$name\"" && git add . && git commit -q -m Initial && for_each_name "echo second >\"\$name\"" && - git commit -a -m Second + git commit -a -m Second && for_each_name "echo modified >\"\$name\"" ' test_expect_success TABS_IN_FILENAMES 'setup expected files' ' -cat >expect.quoted <<\EOF +cat >expect.quoted <<\EOF && Name "Name and a\nLF" "Name and an\tHT" diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh index a283dca25f..5c72540642 100755 --- a/t/t3903-stash.sh +++ b/t/t3903-stash.sh @@ -37,14 +37,32 @@ test_expect_success 'parents of stash' ' test_cmp output expect ' -test_expect_success 'apply needs clean working directory' ' - echo 4 > other-file && +test_expect_success 'applying bogus stash does nothing' ' + test_must_fail git stash apply stash@{1} && + echo 1 >expect && + test_cmp expect file +' + +test_expect_success 'apply does not need clean working directory' ' + echo 4 >other-file && git add other-file && - echo 5 > other-file && - test_must_fail git stash apply + echo 5 >other-file && + git stash apply && + echo 3 >expect && + test_cmp expect file +' + +test_expect_success 'apply does not clobber working directory changes' ' + git reset --hard && + echo 4 >file && + test_must_fail git stash apply && + echo 4 >expect && + test_cmp expect file ' test_expect_success 'apply stashed changes' ' + git reset --hard && + echo 5 >other-file && git add other-file && test_tick && git commit -m other-file && @@ -157,7 +175,7 @@ EOF test_expect_success 'stash branch' ' echo foo > file && - git commit file -m first + git commit file -m first && echo bar > file && echo bar2 > file2 && git add file2 && @@ -218,6 +236,14 @@ test_expect_success 'stash -k' ' test bar,bar4 = $(cat file),$(cat file2) ' +test_expect_success 'stash --no-keep-index' ' + echo bar33 > file && + echo bar44 > file2 && + git add file2 && + git stash --no-keep-index && + test bar,bar2 = $(cat file),$(cat file2) +' + test_expect_success 'stash --invalid-option' ' echo bar5 > file && echo bar6 > file2 && @@ -255,7 +281,7 @@ test_expect_success 'stash rm and ignore' ' echo file >.gitignore && git stash save "rm and ignore" && test bar = "$(cat file)" && - test file = "$(cat .gitignore)" + test file = "$(cat .gitignore)" && git stash apply && ! test -r file && test file = "$(cat .gitignore)" @@ -268,7 +294,7 @@ test_expect_success 'stash rm and ignore (stage .gitignore)' ' git add .gitignore && git stash save "rm and ignore (stage .gitignore)" && test bar = "$(cat file)" && - ! test -r .gitignore + ! test -r .gitignore && git stash apply && ! test -r file && test file = "$(cat .gitignore)" @@ -416,8 +442,37 @@ test_expect_success 'stash show - stashes on stack, stash-like argument' ' echo bar >> file && STASH_ID=$(git stash create) && git reset --hard && - git stash show ${STASH_ID} + cat >expected <<-EOF && + file | 1 + + 1 files changed, 1 insertions(+), 0 deletions(-) + EOF + git stash show ${STASH_ID} >actual && + test_cmp expected actual ' + +test_expect_success 'stash show -p - stashes on stack, stash-like argument' ' + git stash clear && + test_when_finished "git reset --hard HEAD" && + git reset --hard && + echo foo >> file && + git stash && + test_when_finished "git stash drop" && + echo bar >> file && + STASH_ID=$(git stash create) && + git reset --hard && + cat >expected <<-EOF && + diff --git a/file b/file + index 7601807..935fbd3 100644 + --- a/file + +++ b/file + @@ -1 +1,2 @@ + baz + +bar + EOF + git stash show -p ${STASH_ID} >actual && + test_cmp expected actual +' + test_expect_success 'stash show - no stashes on stack, stash-like argument' ' git stash clear && test_when_finished "git reset --hard HEAD" && @@ -425,7 +480,32 @@ test_expect_success 'stash show - no stashes on stack, stash-like argument' ' echo foo >> file && STASH_ID=$(git stash create) && git reset --hard && - git stash show ${STASH_ID} + cat >expected <<-EOF && + file | 1 + + 1 files changed, 1 insertions(+), 0 deletions(-) + EOF + git stash show ${STASH_ID} >actual && + test_cmp expected actual +' + +test_expect_success 'stash show -p - no stashes on stack, stash-like argument' ' + git stash clear && + test_when_finished "git reset --hard HEAD" && + git reset --hard && + echo foo >> file && + STASH_ID=$(git stash create) && + git reset --hard && + cat >expected <<-EOF && + diff --git a/file b/file + index 7601807..71b52c4 100644 + --- a/file + +++ b/file + @@ -1 +1,2 @@ + baz + +foo + EOF + git stash show -p ${STASH_ID} >actual && + test_cmp expected actual ' test_expect_success 'stash drop - fail early if specified stash is not a stash reference' ' @@ -483,12 +563,42 @@ test_expect_success 'invalid ref of the form stash@{n}, n >= N' ' echo bar6 > file2 && git add file2 && git stash && - test_must_fail git drop stash@{1} && - test_must_fail git pop stash@{1} && - test_must_fail git apply stash@{1} && - test_must_fail git show stash@{1} && - test_must_fail git branch tmp stash@{1} && + test_must_fail git stash drop stash@{1} && + test_must_fail git stash pop stash@{1} && + test_must_fail git stash apply stash@{1} && + test_must_fail git stash show stash@{1} && + test_must_fail git stash branch tmp stash@{1} && git stash drop ' +test_expect_success 'stash branch should not drop the stash if the branch exists' ' + git stash clear && + echo foo >file && + git add file && + git commit -m initial && + echo bar >file && + git stash && + test_must_fail git stash branch master stash@{0} && + git rev-parse stash@{0} -- +' + +test_expect_success 'stash apply shows status same as git status (relative to current directory)' ' + git stash clear && + echo 1 >subdir/subfile1 && + echo 2 >subdir/subfile2 && + git add subdir/subfile1 && + git commit -m subdir && + ( + cd subdir && + echo x >subfile1 && + echo x >../file && + git status >../expect && + git stash && + sane_unset GIT_MERGE_VERBOSITY && + git stash apply + ) | + sed -e 1,2d >actual && # drop "Saved..." and "HEAD is now..." + test_cmp expect actual +' + test_done diff --git a/t/t3904-stash-patch.sh b/t/t3904-stash-patch.sh index d1819ca23a..781fd71681 100755 --- a/t/t3904-stash-patch.sh +++ b/t/t3904-stash-patch.sh @@ -20,7 +20,7 @@ test_expect_success PERL 'setup' ' # note: bar sorts before dir, so the first 'n' is always to skip 'bar' test_expect_success PERL 'saying "n" does nothing' ' - set_state dir/foo work index + set_state dir/foo work index && (echo n; echo n) | test_must_fail git stash save -p && verify_state dir/foo work index && verify_saved_state bar @@ -48,6 +48,18 @@ test_expect_success PERL 'git stash -p --no-keep-index' ' verify_state bar dummy bar_index ' +test_expect_success PERL 'git stash --no-keep-index -p' ' + set_state dir/foo work index && + set_state bar bar_work bar_index && + (echo n; echo y) | git stash save --no-keep-index -p && + verify_state dir/foo head head && + verify_state bar bar_work dummy && + git reset --hard && + git stash apply --index && + verify_state dir/foo work index && + verify_state bar dummy bar_index +' + test_expect_success PERL 'none of this moved HEAD' ' verify_saved_head ' diff --git a/t/t4001-diff-rename.sh b/t/t4001-diff-rename.sh index 71bac83dd5..cad85450b7 100755 --- a/t/t4001-diff-rename.sh +++ b/t/t4001-diff-rename.sh @@ -64,7 +64,7 @@ test_expect_success \ 'validate the output.' \ 'compare_diff_patch current expected' -test_expect_success 'favour same basenames over different ones' ' +test_expect_success C_LOCALE_OUTPUT 'favour same basenames over different ones' ' cp path1 another-path && git add another-path && git commit -m 1 && @@ -73,7 +73,7 @@ test_expect_success 'favour same basenames over different ones' ' git mv another-path subdir/path1 && git status | grep "renamed: .*path1 -> subdir/path1"' -test_expect_success 'favour same basenames even with minor differences' ' +test_expect_success C_LOCALE_OUTPUT 'favour same basenames even with minor differences' ' git show HEAD:path1 | sed "s/15/16/" > subdir/path1 && git status | grep "renamed: .*path1 -> subdir/path1"' diff --git a/t/t4002-diff-basic.sh b/t/t4002-diff-basic.sh index 73441a5165..9fb8ca06a8 100755 --- a/t/t4002-diff-basic.sh +++ b/t/t4002-diff-basic.sh @@ -205,8 +205,8 @@ test_expect_success \ 'rm -fr Z [A-Z][A-Z] && git read-tree $tree_A && git checkout-index -f -a && - git read-tree --reset $tree_O || return 1 - git update-index --refresh >/dev/null ;# this can exit non-zero + git read-tree --reset $tree_O && + test_must_fail git update-index --refresh -q && git diff-files >.test-a && cmp_diff_files_output .test-a .test-recursive-OA' @@ -215,8 +215,8 @@ test_expect_success \ 'rm -fr Z [A-Z][A-Z] && git read-tree $tree_B && git checkout-index -f -a && - git read-tree --reset $tree_O || return 1 - git update-index --refresh >/dev/null ;# this can exit non-zero + git read-tree --reset $tree_O && + test_must_fail git update-index --refresh -q && git diff-files >.test-a && cmp_diff_files_output .test-a .test-recursive-OB' @@ -225,8 +225,8 @@ test_expect_success \ 'rm -fr Z [A-Z][A-Z] && git read-tree $tree_B && git checkout-index -f -a && - git read-tree --reset $tree_A || return 1 - git update-index --refresh >/dev/null ;# this can exit non-zero + git read-tree --reset $tree_A && + test_must_fail git update-index --refresh -q && git diff-files >.test-a && cmp_diff_files_output .test-a .test-recursive-AB' diff --git a/t/t4003-diff-rename-1.sh b/t/t4003-diff-rename-1.sh index c6130c4019..bfa8835638 100755 --- a/t/t4003-diff-rename-1.sh +++ b/t/t4003-diff-rename-1.sh @@ -29,7 +29,7 @@ test_expect_success \ # copy-and-edit one, and rename-and-edit the other. We do not say # anything about rezrov. -GIT_DIFF_OPTS=--unified=0 git diff-index -M -p $tree >current +GIT_DIFF_OPTS=--unified=0 git diff-index -C -p $tree >current cat >expected <<\EOF diff --git a/COPYING b/COPYING.1 copy from COPYING diff --git a/t/t4004-diff-rename-symlink.sh b/t/t4004-diff-rename-symlink.sh index 92a65f4852..6e562c80d1 100755 --- a/t/t4004-diff-rename-symlink.sh +++ b/t/t4004-diff-rename-symlink.sh @@ -35,7 +35,7 @@ test_expect_success SYMLINKS \ # a new creation. test_expect_success SYMLINKS 'setup diff output' " - GIT_DIFF_OPTS=--unified=0 git diff-index -M -p $tree >current && + GIT_DIFF_OPTS=--unified=0 git diff-index -C -p $tree >current && cat >expected <<\EOF diff --git a/bozbar b/bozbar new file mode 120000 diff --git a/t/t4005-diff-rename-2.sh b/t/t4005-diff-rename-2.sh index 1ba359d478..77d7f4946f 100755 --- a/t/t4005-diff-rename-2.sh +++ b/t/t4005-diff-rename-2.sh @@ -29,7 +29,7 @@ test_expect_success \ # and COPYING.2 are based on COPYING, and do not say anything about # rezrov. -git diff-index -M $tree >current +git diff-index -C $tree >current cat >expected <<\EOF :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 0603b3238a076dc6c8022aedc6648fa523a17178 C1234 COPYING COPYING.1 diff --git a/t/t4008-diff-break-rewrite.sh b/t/t4008-diff-break-rewrite.sh index e19ca65885..73b4a24f5e 100755 --- a/t/t4008-diff-break-rewrite.sh +++ b/t/t4008-diff-break-rewrite.sh @@ -155,7 +155,7 @@ test_expect_success \ git checkout-index -f -u -a && sed -e "s/git/GIT/" file0 >file1 && sed -e "s/git/GET/" file0 >file2 && - rm -f file0 + rm -f file0 && git update-index --add --remove file0 file1 file2' test_expect_success \ @@ -173,8 +173,8 @@ test_expect_success \ 'compare_diff_raw expected current' test_expect_success \ - 'run diff with -B -M' \ - 'git diff-index -B -M "$tree" >current' + 'run diff with -B -C' \ + 'git diff-index -B -C "$tree" >current' cat >expected <<\EOF :100644 100644 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 08bb2fb671deff4c03a4d4a0a1315dff98d5732c C095 file0 file1 diff --git a/t/t4009-diff-rename-4.sh b/t/t4009-diff-rename-4.sh index de3f17478e..f22c8e3dba 100755 --- a/t/t4009-diff-rename-4.sh +++ b/t/t4009-diff-rename-4.sh @@ -29,7 +29,7 @@ test_expect_success \ # and COPYING.2 are based on COPYING, and do not say anything about # rezrov. -git diff-index -z -M $tree >current +git diff-index -z -C $tree >current cat >expected <<\EOF :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 0603b3238a076dc6c8022aedc6648fa523a17178 C1234 diff --git a/t/t4010-diff-pathspec.sh b/t/t4010-diff-pathspec.sh index 94df7ae53a..fbc8cd8f05 100755 --- a/t/t4010-diff-pathspec.sh +++ b/t/t4010-diff-pathspec.sh @@ -70,4 +70,36 @@ test_expect_success 'diff-tree pathspec' ' test_cmp expected current ' +EMPTY_TREE=4b825dc642cb6eb9a060e54bf8d69288fbee4904 + +test_expect_success 'diff-tree with wildcard shows dir also matches' ' + git diff-tree --name-only $EMPTY_TREE $tree -- "f*" >result && + echo file0 >expected && + test_cmp expected result +' + +test_expect_success 'diff-tree -r with wildcard' ' + git diff-tree -r --name-only $EMPTY_TREE $tree -- "*file1" >result && + echo path1/file1 >expected && + test_cmp expected result +' + +test_expect_success 'diff-tree with wildcard shows dir also matches' ' + git diff-tree --name-only $tree $tree2 -- "path1/f*" >result && + echo path1 >expected && + test_cmp expected result +' + +test_expect_success 'diff-tree -r with wildcard from beginning' ' + git diff-tree -r --name-only $tree $tree2 -- "path1/*file1" >result && + echo path1/file1 >expected && + test_cmp expected result +' + +test_expect_success 'diff-tree -r with wildcard' ' + git diff-tree -r --name-only $tree $tree2 -- "path1/f*" >result && + echo path1/file1 >expected && + test_cmp expected result +' + test_done diff --git a/t/t4011-diff-symlink.sh b/t/t4011-diff-symlink.sh index 6f6948925f..408a19c4c2 100755 --- a/t/t4011-diff-symlink.sh +++ b/t/t4011-diff-symlink.sh @@ -88,4 +88,30 @@ test_expect_success SYMLINKS \ test_must_fail git diff --no-index pinky brain > output 2> output.err && grep narf output && ! grep error output.err' + +test_expect_success SYMLINKS 'setup symlinks with attributes' ' + echo "*.bin diff=bin" >>.gitattributes && + echo content >file.bin && + ln -s file.bin link.bin && + git add -N file.bin link.bin +' + +cat >expect <<'EOF' +diff --git a/file.bin b/file.bin +index e69de29..d95f3ad 100644 +Binary files a/file.bin and b/file.bin differ +diff --git a/link.bin b/link.bin +index e69de29..dce41ec 120000 +--- a/link.bin ++++ b/link.bin +@@ -0,0 +1 @@ ++file.bin +\ No newline at end of file +EOF +test_expect_success SYMLINKS 'symlinks do not respect userdiff config by path' ' + git config diff.bin.binary true && + git diff file.bin link.bin >actual && + test_cmp expect actual +' + test_done diff --git a/t/t4012-diff-binary.sh b/t/t4012-diff-binary.sh index bc46563afc..05ec062832 100755 --- a/t/t4012-diff-binary.sh +++ b/t/t4012-diff-binary.sh @@ -77,10 +77,6 @@ test_expect_success 'apply binary patch' \ tree1=`git write-tree` && test "$tree1" = "$tree0"' -nul_to_q() { - perl -pe 'y/\000/Q/' -} - test_expect_success 'diff --no-index with binary creation' ' echo Q | q_to_nul >binary && (: hide error code from diff, which just indicates differences diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh index 19857f4326..93a6f20871 100755 --- a/t/t4013-diff-various.sh +++ b/t/t4013-diff-various.sh @@ -80,18 +80,31 @@ test_expect_success setup ' git config log.showroot false && git commit --amend && + + GIT_AUTHOR_DATE="2006-06-26 00:06:00 +0000" && + GIT_COMMITTER_DATE="2006-06-26 00:06:00 +0000" && + export GIT_AUTHOR_DATE GIT_COMMITTER_DATE && + git checkout -b rearrange initial && + for i in B A; do echo $i; done >dir/sub && + git add dir/sub && + git commit -m "Rearranged lines in dir/sub" && + git checkout master && + git show-branch ' : <<\EOF ! [initial] Initial * [master] Merge branch 'side' - ! [side] Side ---- - - [master] Merge branch 'side' - *+ [side] Side - * [master^] Second -+*+ [initial] Initial + ! [rearrange] Rearranged lines in dir/sub + ! [side] Side +---- + + [rearrange] Rearranged lines in dir/sub + - [master] Merge branch 'side' + * + [side] Side + * [master^] Third + * [master~2] Second ++*++ [initial] Initial EOF V=`git version | sed -e 's/^git version //' -e 's/\./\\./g'` @@ -210,6 +223,12 @@ log -m -p master log -SF master log -S F master log -SF -p master +log -SF master --max-count=0 +log -SF master --max-count=1 +log -SF master --max-count=2 +log -GF master +log -GF -p master +log -GF -p --pickaxe-all master log --decorate --all log --decorate=full --all @@ -281,10 +300,23 @@ diff --no-index --name-status -- dir2 dir diff --no-index dir dir3 diff master master^ side diff --dirstat master~1 master~2 +diff --dirstat initial rearrange +diff --dirstat-by-file initial rearrange EOF test_expect_success 'log -S requires an argument' ' test_must_fail git log -S ' +test_expect_success 'diff --cached on unborn branch' ' + echo ref: refs/heads/unborn >.git/HEAD && + git diff --cached >result && + test_cmp "$TEST_DIRECTORY/t4013/diff.diff_--cached" result +' + +test_expect_success 'diff --cached -- file on unborn branch' ' + git diff --cached -- file0 >result && + test_cmp "$TEST_DIRECTORY/t4013/diff.diff_--cached_--_file0" result +' + test_done diff --git a/t/t4013/diff.diff_--cached b/t/t4013/diff.diff_--cached new file mode 100644 index 0000000000..ff16e83e7c --- /dev/null +++ b/t/t4013/diff.diff_--cached @@ -0,0 +1,38 @@ +diff --git a/dir/sub b/dir/sub +new file mode 100644 +index 0000000..992913c +--- /dev/null ++++ b/dir/sub +@@ -0,0 +1,8 @@ ++A ++B ++C ++D ++E ++F ++1 ++2 +diff --git a/file0 b/file0 +new file mode 100644 +index 0000000..10a8a9f +--- /dev/null ++++ b/file0 +@@ -0,0 +1,9 @@ ++1 ++2 ++3 ++4 ++5 ++6 ++A ++B ++C +diff --git a/file1 b/file1 +new file mode 100644 +index 0000000..b1e6722 +--- /dev/null ++++ b/file1 +@@ -0,0 +1,3 @@ ++A ++B ++C diff --git a/t/t4013/diff.diff_--cached_--_file0 b/t/t4013/diff.diff_--cached_--_file0 new file mode 100644 index 0000000000..b9bb858a03 --- /dev/null +++ b/t/t4013/diff.diff_--cached_--_file0 @@ -0,0 +1,15 @@ +diff --git a/file0 b/file0 +new file mode 100644 +index 0000000..10a8a9f +--- /dev/null ++++ b/file0 +@@ -0,0 +1,9 @@ ++1 ++2 ++3 ++4 ++5 ++6 ++A ++B ++C diff --git a/t/t4013/diff.diff_--dirstat-by-file_initial_rearrange b/t/t4013/diff.diff_--dirstat-by-file_initial_rearrange new file mode 100644 index 0000000000..e48e33f678 --- /dev/null +++ b/t/t4013/diff.diff_--dirstat-by-file_initial_rearrange @@ -0,0 +1,3 @@ +$ git diff --dirstat-by-file initial rearrange + 100.0% dir/ +$ diff --git a/t/t4013/diff.diff_--dirstat_initial_rearrange b/t/t4013/diff.diff_--dirstat_initial_rearrange new file mode 100644 index 0000000000..5fb02c13bc --- /dev/null +++ b/t/t4013/diff.diff_--dirstat_initial_rearrange @@ -0,0 +1,3 @@ +$ git diff --dirstat initial rearrange + 100.0% dir/ +$ diff --git a/t/t4013/diff.format-patch_--stdout_--cover-letter_-n_initial..master^ b/t/t4013/diff.format-patch_--stdout_--cover-letter_-n_initial..master^ index 1f0f9ad44b..3b4e113012 100644 --- a/t/t4013/diff.format-patch_--stdout_--cover-letter_-n_initial..master^ +++ b/t/t4013/diff.format-patch_--stdout_--cover-letter_-n_initial..master^ @@ -1,7 +1,7 @@ $ git format-patch --stdout --cover-letter -n initial..master^ From 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 Mon Sep 17 00:00:00 2001 From: C O Mitter <committer@example.com> -Date: Mon, 26 Jun 2006 00:05:00 +0000 +Date: Mon, 26 Jun 2006 00:06:00 +0000 Subject: [DIFFERENT_PREFIX 0/2] *** SUBJECT HERE *** *** BLURB HERE *** diff --git a/t/t4013/diff.log_--decorate=full_--all b/t/t4013/diff.log_--decorate=full_--all index d155e0bab2..44d45257da 100644 --- a/t/t4013/diff.log_--decorate=full_--all +++ b/t/t4013/diff.log_--decorate=full_--all @@ -1,4 +1,10 @@ $ git log --decorate=full --all +commit cd4e72fd96faed3f0ba949dc42967430374e2290 (refs/heads/rearrange) +Author: A U Thor <author@example.com> +Date: Mon Jun 26 00:06:00 2006 +0000 + + Rearranged lines in dir/sub + commit 59d314ad6f356dd08601a4cd5e530381da3e3c64 (HEAD, refs/heads/master) Merge: 9a6d494 c7a2ab9 Author: A U Thor <author@example.com> diff --git a/t/t4013/diff.log_--decorate_--all b/t/t4013/diff.log_--decorate_--all index fd7c3e6439..27d3eabc26 100644 --- a/t/t4013/diff.log_--decorate_--all +++ b/t/t4013/diff.log_--decorate_--all @@ -1,4 +1,10 @@ $ git log --decorate --all +commit cd4e72fd96faed3f0ba949dc42967430374e2290 (rearrange) +Author: A U Thor <author@example.com> +Date: Mon Jun 26 00:06:00 2006 +0000 + + Rearranged lines in dir/sub + commit 59d314ad6f356dd08601a4cd5e530381da3e3c64 (HEAD, master) Merge: 9a6d494 c7a2ab9 Author: A U Thor <author@example.com> diff --git a/t/t4013/diff.log_-GF_-p_--pickaxe-all_master b/t/t4013/diff.log_-GF_-p_--pickaxe-all_master new file mode 100644 index 0000000000..d36f88098b --- /dev/null +++ b/t/t4013/diff.log_-GF_-p_--pickaxe-all_master @@ -0,0 +1,27 @@ +$ git log -GF -p --pickaxe-all master +commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 +Author: A U Thor <author@example.com> +Date: Mon Jun 26 00:02:00 2006 +0000 + + Third + +diff --git a/dir/sub b/dir/sub +index 8422d40..cead32e 100644 +--- a/dir/sub ++++ b/dir/sub +@@ -2,3 +2,5 @@ A + B + C + D ++E ++F +diff --git a/file1 b/file1 +new file mode 100644 +index 0000000..b1e6722 +--- /dev/null ++++ b/file1 +@@ -0,0 +1,3 @@ ++A ++B ++C +$ diff --git a/t/t4013/diff.log_-GF_-p_master b/t/t4013/diff.log_-GF_-p_master new file mode 100644 index 0000000000..9d93f2c23a --- /dev/null +++ b/t/t4013/diff.log_-GF_-p_master @@ -0,0 +1,18 @@ +$ git log -GF -p master +commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 +Author: A U Thor <author@example.com> +Date: Mon Jun 26 00:02:00 2006 +0000 + + Third + +diff --git a/dir/sub b/dir/sub +index 8422d40..cead32e 100644 +--- a/dir/sub ++++ b/dir/sub +@@ -2,3 +2,5 @@ A + B + C + D ++E ++F +$ diff --git a/t/t4013/diff.log_-GF_master b/t/t4013/diff.log_-GF_master new file mode 100644 index 0000000000..4c6708d2d0 --- /dev/null +++ b/t/t4013/diff.log_-GF_master @@ -0,0 +1,7 @@ +$ git log -GF master +commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 +Author: A U Thor <author@example.com> +Date: Mon Jun 26 00:02:00 2006 +0000 + + Third +$ diff --git a/t/t4013/diff.log_-SF_master_--max-count=0 b/t/t4013/diff.log_-SF_master_--max-count=0 new file mode 100644 index 0000000000..c1fc6c8731 --- /dev/null +++ b/t/t4013/diff.log_-SF_master_--max-count=0 @@ -0,0 +1,2 @@ +$ git log -SF master --max-count=0 +$ diff --git a/t/t4013/diff.log_-SF_master_--max-count=1 b/t/t4013/diff.log_-SF_master_--max-count=1 new file mode 100644 index 0000000000..c981a03814 --- /dev/null +++ b/t/t4013/diff.log_-SF_master_--max-count=1 @@ -0,0 +1,7 @@ +$ git log -SF master --max-count=1 +commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 +Author: A U Thor <author@example.com> +Date: Mon Jun 26 00:02:00 2006 +0000 + + Third +$ diff --git a/t/t4013/diff.log_-SF_master_--max-count=2 b/t/t4013/diff.log_-SF_master_--max-count=2 new file mode 100644 index 0000000000..a6c55fd482 --- /dev/null +++ b/t/t4013/diff.log_-SF_master_--max-count=2 @@ -0,0 +1,7 @@ +$ git log -SF master --max-count=2 +commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 +Author: A U Thor <author@example.com> +Date: Mon Jun 26 00:02:00 2006 +0000 + + Third +$ diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index f87434b9f8..c3cdb52053 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -6,30 +6,36 @@ test_description='various format-patch tests' . ./test-lib.sh +. "$TEST_DIRECTORY"/lib-terminal.sh test_expect_success setup ' for i in 1 2 3 4 5 6 7 8 9 10; do echo "$i"; done >file && cat file >elif && git add file elif && + test_tick && git commit -m Initial && git checkout -b side && for i in 1 2 5 6 A B C 7 8 9 10; do echo "$i"; done >file && test_chmod +x elif && + test_tick && git commit -m "Side changes #1" && for i in D E F; do echo "$i"; done >>file && git update-index file && + test_tick && git commit -m "Side changes #2" && git tag C2 && for i in 5 6 1 2 3 A 4 B C 7 8 9 10 D E F; do echo "$i"; done >file && git update-index file && + test_tick && git commit -m "Side changes #3 with \\n backslash-n in it." && git checkout master && git diff-tree -p C2 | git apply --index && + test_tick && git commit -m "Master accepts moral equivalent of #2" ' @@ -51,6 +57,22 @@ test_expect_success "format-patch --ignore-if-in-upstream" ' ' +test_expect_success "format-patch doesn't consider merge commits" ' + + git checkout -b slave master && + echo "Another line" >>file && + test_tick && + git commit -am "Slave change #1" && + echo "Yet another line" >>file && + test_tick && + git commit -am "Slave change #2" && + git checkout -b merger master && + test_tick && + git merge --no-ff slave && + cnt=`git format-patch -3 --stdout | grep "^From " | wc -l` && + test $cnt = 3 +' + test_expect_success "format-patch result applies" ' git checkout -b rebuild-0 master && @@ -592,7 +614,7 @@ echo "fatal: --name-only does not make sense" > expect.name-only echo "fatal: --name-status does not make sense" > expect.name-status echo "fatal: --check does not make sense" > expect.check -test_expect_success 'options no longer allowed for format-patch' ' +test_expect_success C_LOCALE_OUTPUT 'options no longer allowed for format-patch' ' test_must_fail git format-patch --name-only 2> output && test_cmp expect.name-only output && test_must_fail git format-patch --name-status 2> output && @@ -665,4 +687,110 @@ test_expect_success 'format-patch --signature="" supresses signatures' ' ! grep "^-- \$" output ' +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_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_path_is_missing pager_used && + test_path_is_missing .git/pager_used +' + +test_expect_success 'format-patch handles multi-line subjects' ' + rm -rf patches/ && + echo content >>file && + for i in one two three; do echo $i; done >msg && + git add file && + git commit -F msg && + git format-patch -o patches -1 && + grep ^Subject: patches/0001-one.patch >actual && + echo "Subject: [PATCH] one two three" >expect && + test_cmp expect actual +' + +test_expect_success 'format-patch handles multi-line encoded subjects' ' + rm -rf patches/ && + echo content >>file && + for i in en två tre; do echo $i; done >msg && + git add file && + git commit -F msg && + git format-patch -o patches -1 && + grep ^Subject: patches/0001-en.patch >actual && + echo "Subject: [PATCH] =?UTF-8?q?en=20tv=C3=A5=20tre?=" >expect && + test_cmp expect actual +' + +M8="foo bar " +M64=$M8$M8$M8$M8$M8$M8$M8$M8 +M512=$M64$M64$M64$M64$M64$M64$M64$M64 +cat >expect <<'EOF' +Subject: [PATCH] foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo + bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar + foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo + bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar + foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo + bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar + foo bar foo bar foo bar foo bar foo bar foo bar foo bar foo + bar foo bar foo bar foo bar foo bar foo bar foo bar foo bar + foo bar foo bar foo bar foo bar +EOF +test_expect_success 'format-patch wraps extremely long headers (ascii)' ' + echo content >>file && + git add file && + git commit -m "$M512" && + git format-patch --stdout -1 >patch && + sed -n "/^Subject/p; /^ /p; /^$/q" <patch >subject && + test_cmp expect subject +' + +M8="föö bar " +M64=$M8$M8$M8$M8$M8$M8$M8$M8 +M512=$M64$M64$M64$M64$M64$M64$M64$M64 +cat >expect <<'EOF' +Subject: [PATCH] =?UTF-8?q?f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6?= + =?UTF-8?q?=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6?= + =?UTF-8?q?=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6?= + =?UTF-8?q?=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6?= + =?UTF-8?q?=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6?= + =?UTF-8?q?=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6?= + =?UTF-8?q?=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6?= + =?UTF-8?q?=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6?= + =?UTF-8?q?=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6?= + =?UTF-8?q?=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6?= + =?UTF-8?q?=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6?= + =?UTF-8?q?=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6?= + =?UTF-8?q?=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6?= + =?UTF-8?q?=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6?= + =?UTF-8?q?=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6?= + =?UTF-8?q?=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6?= + =?UTF-8?q?=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6?= + =?UTF-8?q?=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6?= + =?UTF-8?q?=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6?= + =?UTF-8?q?=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6?= + =?UTF-8?q?=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6=C3=B6=20bar=20f=C3=B6?= + =?UTF-8?q?=C3=B6=20bar=20f=C3=B6=C3=B6=20bar?= +EOF +test_expect_success 'format-patch wraps extremely long headers (rfc2047)' ' + rm -rf patches/ && + echo content >>file && + git add file && + git commit -m "$M512" && + git format-patch --stdout -1 >patch && + sed -n "/^Subject/p; /^ /p; /^$/q" <patch >subject && + test_cmp expect subject +' + test_done diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh index 935d101fe8..9059bcd69e 100755 --- a/t/t4015-diff-whitespace.sh +++ b/t/t4015-diff-whitespace.sh @@ -330,7 +330,7 @@ test_expect_success 'check space before tab in indent (space-before-tab: on)' ' test_expect_success 'check spaces as indentation (indent-with-non-tab: off)' ' - git config core.whitespace "-indent-with-non-tab" + git config core.whitespace "-indent-with-non-tab" && echo " foo ();" > x && git diff --check @@ -344,6 +344,13 @@ test_expect_success 'check spaces as indentation (indent-with-non-tab: on)' ' ' +test_expect_success 'ditto, but tabwidth=9' ' + + git config core.whitespace "indent-with-non-tab,tabwidth=9" && + git diff --check + +' + test_expect_success 'check tabs and spaces as indentation (indent-with-non-tab: on)' ' git config core.whitespace "indent-with-non-tab" && @@ -352,6 +359,20 @@ test_expect_success 'check tabs and spaces as indentation (indent-with-non-tab: ' +test_expect_success 'ditto, but tabwidth=10' ' + + git config core.whitespace "indent-with-non-tab,tabwidth=10" && + test_must_fail git diff --check + +' + +test_expect_success 'ditto, but tabwidth=20' ' + + git config core.whitespace "indent-with-non-tab,tabwidth=20" && + git diff --check + +' + test_expect_success 'check tabs as indentation (tab-in-indent: off)' ' git config core.whitespace "-tab-in-indent" && @@ -376,6 +397,13 @@ test_expect_success 'check tabs and spaces as indentation (tab-in-indent: on)' ' ' +test_expect_success 'ditto, but tabwidth=1 (must be irrelevant)' ' + + git config core.whitespace "tab-in-indent,tabwidth=1" && + test_must_fail git diff --check + +' + test_expect_success 'check tab-in-indent and indent-with-non-tab conflict' ' git config core.whitespace "tab-in-indent,indent-with-non-tab" && @@ -491,4 +519,41 @@ test_expect_success 'combined diff with autocrlf conversion' ' ' +# Start testing the colored format for whitespace checks + +test_expect_success 'setup diff colors' ' + git config color.diff always && + git config color.diff.plain normal && + git config color.diff.meta bold && + git config color.diff.frag cyan && + git config color.diff.func normal && + git config color.diff.old red && + git config color.diff.new green && + git config color.diff.commit yellow && + git config color.diff.whitespace "normal red" && + + git config core.autocrlf false +' +cat >expected <<\EOF +<BOLD>diff --git a/x b/x<RESET> +<BOLD>index 9daeafb..2874b91 100644<RESET> +<BOLD>--- a/x<RESET> +<BOLD>+++ b/x<RESET> +<CYAN>@@ -1 +1,4 @@<RESET> + test<RESET> +<GREEN>+<RESET><GREEN>{<RESET> +<GREEN>+<RESET><BRED> <RESET> +<GREEN>+<RESET><GREEN>}<RESET> +EOF + +test_expect_success 'diff that introduces a line with only tabs' ' + git config core.whitespace blank-at-eol && + git reset --hard && + echo "test" > x && + git commit -m "initial" x && + echo "{NTN}" | tr "NT" "\n\t" >> x && + git -c color.diff=always diff | test_decode_color >current && + test_cmp expected current +' + test_done diff --git a/t/t4017-diff-retval.sh b/t/t4017-diff-retval.sh index 61589853df..95a7ca7070 100755 --- a/t/t4017-diff-retval.sh +++ b/t/t4017-diff-retval.sh @@ -29,66 +29,49 @@ test_expect_success 'git diff --quiet -w HEAD^ HEAD' ' ' test_expect_success 'git diff-tree HEAD^ HEAD' ' - git diff-tree --exit-code HEAD^ HEAD - test $? = 1 + test_expect_code 1 git diff-tree --exit-code HEAD^ HEAD ' test_expect_success 'git diff-tree HEAD^ HEAD -- a' ' git diff-tree --exit-code HEAD^ HEAD -- a - test $? = 0 ' test_expect_success 'git diff-tree HEAD^ HEAD -- b' ' - git diff-tree --exit-code HEAD^ HEAD -- b - test $? = 1 + test_expect_code 1 git diff-tree --exit-code HEAD^ HEAD -- b ' test_expect_success 'echo HEAD | git diff-tree --stdin' ' - echo $(git rev-parse HEAD) | git diff-tree --exit-code --stdin - test $? = 1 + echo $(git rev-parse HEAD) | test_expect_code 1 git diff-tree --exit-code --stdin ' test_expect_success 'git diff-tree HEAD HEAD' ' git diff-tree --exit-code HEAD HEAD - test $? = 0 ' test_expect_success 'git diff-files' ' git diff-files --exit-code - test $? = 0 ' test_expect_success 'git diff-index --cached HEAD' ' git diff-index --exit-code --cached HEAD - test $? = 0 ' test_expect_success 'git diff-index --cached HEAD^' ' - git diff-index --exit-code --cached HEAD^ - test $? = 1 + test_expect_code 1 git diff-index --exit-code --cached HEAD^ ' test_expect_success 'git diff-index --cached HEAD^' ' echo text >>b && echo 3 >c && - git add . && { - git diff-index --exit-code --cached HEAD^ - test $? = 1 - } + git add . && + test_expect_code 1 git diff-index --exit-code --cached HEAD^ ' test_expect_success 'git diff-tree -Stext HEAD^ HEAD -- b' ' - git commit -m "text in b" && { - git diff-tree -p --exit-code -Stext HEAD^ HEAD -- b - test $? = 1 - } + git commit -m "text in b" && + test_expect_code 1 git diff-tree -p --exit-code -Stext HEAD^ HEAD -- b ' test_expect_success 'git diff-tree -Snot-found HEAD^ HEAD -- b' ' git diff-tree -p --exit-code -Snot-found HEAD^ HEAD -- b - test $? = 0 ' test_expect_success 'git diff-files' ' - echo 3 >>c && { - git diff-files --exit-code - test $? = 1 - } + echo 3 >>c && + test_expect_code 1 git diff-files --exit-code ' test_expect_success 'git diff-index --cached HEAD' ' - git update-index c && { - git diff-index --exit-code --cached HEAD - test $? = 1 - } + git update-index c && + test_expect_code 1 git diff-index --exit-code --cached HEAD ' test_expect_success '--check --exit-code returns 0 for no difference' ' @@ -100,30 +83,26 @@ test_expect_success '--check --exit-code returns 0 for no difference' ' test_expect_success '--check --exit-code returns 1 for a clean difference' ' echo "good" > a && - git diff --check --exit-code - test $? = 1 + test_expect_code 1 git diff --check --exit-code ' test_expect_success '--check --exit-code returns 3 for a dirty difference' ' echo "bad " >> a && - git diff --check --exit-code - test $? = 3 + test_expect_code 3 git diff --check --exit-code ' test_expect_success '--check with --no-pager returns 2 for dirty difference' ' - git --no-pager diff --check - test $? = 2 + test_expect_code 2 git --no-pager diff --check ' test_expect_success 'check should test not just the last line' ' echo "" >>a && - git --no-pager diff --check - test $? = 2 + test_expect_code 2 git --no-pager diff --check ' @@ -133,10 +112,8 @@ test_expect_success 'check detects leftover conflict markers' ' echo binary >>b && git commit -m "side" b && test_must_fail git merge master && - git add b && ( - git --no-pager diff --cached --check >test.out - test $? = 2 - ) && + git add b && + test_expect_code 2 git --no-pager diff --cached --check >test.out && test 3 = $(grep "conflict marker" test.out | wc -l) && git reset --hard ' @@ -146,19 +123,13 @@ test_expect_success 'check honors conflict marker length' ' echo ">>>>>>> boo" >>b && echo "======" >>a && git diff --check a && - ( - git diff --check b - test $? = 2 - ) && + test_expect_code 2 git diff --check b && git reset --hard && echo ">>>>>>>> boo" >>b && echo "========" >>a && git diff --check && echo "b conflict-marker-size=8" >.gitattributes && - ( - git diff --check b - test $? = 2 - ) && + test_expect_code 2 git diff --check b && git diff --check a && git reset --hard ' diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh index c8e19372b0..3646930623 100755 --- a/t/t4018-diff-funcname.sh +++ b/t/t4018-diff-funcname.sh @@ -32,7 +32,7 @@ EOF sed 's/beer\\/beer,\\/' < Beer.java > Beer-correct.java -builtin_patterns="bibtex cpp csharp html java objc pascal php python ruby tex" +builtin_patterns="bibtex cpp csharp fortran html java objc pascal perl php python ruby tex" for p in $builtin_patterns do test_expect_success "builtin $p pattern compiles" ' diff --git a/t/t4019-diff-wserror.sh b/t/t4019-diff-wserror.sh index f6d1f1ebab..a5019759bc 100755 --- a/t/t4019-diff-wserror.sh +++ b/t/t4019-diff-wserror.sh @@ -36,11 +36,12 @@ prepare_output () { git diff --color >output $grep_a "$blue_grep" output >error $grep_a -v "$blue_grep" output >normal + return 0 } test_expect_success default ' - prepare_output + prepare_output && grep Eight normal >/dev/null && grep HT error >/dev/null && @@ -50,10 +51,67 @@ test_expect_success default ' ' +test_expect_success 'default (attribute)' ' + + test_might_fail git config --unset core.whitespace && + echo "F whitespace" >.gitattributes && + prepare_output && + + grep Eight error >/dev/null && + grep HT error >/dev/null && + grep With error >/dev/null && + grep Return error >/dev/null && + grep No normal >/dev/null + +' + +test_expect_success 'default, tabwidth=10 (attribute)' ' + + git config core.whitespace "tabwidth=10" && + echo "F whitespace" >.gitattributes && + prepare_output && + + grep Eight normal >/dev/null && + grep HT error >/dev/null && + grep With error >/dev/null && + grep Return error >/dev/null && + grep No normal >/dev/null + +' + +test_expect_success 'no check (attribute)' ' + + test_might_fail git config --unset core.whitespace && + echo "F -whitespace" >.gitattributes && + prepare_output && + + grep Eight normal >/dev/null && + grep HT normal >/dev/null && + grep With normal >/dev/null && + grep Return normal >/dev/null && + grep No normal >/dev/null + +' + +test_expect_success 'no check, tabwidth=10 (attribute), must be irrelevant' ' + + git config core.whitespace "tabwidth=10" && + echo "F -whitespace" >.gitattributes && + prepare_output && + + grep Eight normal >/dev/null && + grep HT normal >/dev/null && + grep With normal >/dev/null && + grep Return normal >/dev/null && + grep No normal >/dev/null + +' + test_expect_success 'without -trail' ' - git config core.whitespace -trail - prepare_output + rm -f .gitattributes && + git config core.whitespace -trail && + prepare_output && grep Eight normal >/dev/null && grep HT error >/dev/null && @@ -65,9 +123,9 @@ test_expect_success 'without -trail' ' test_expect_success 'without -trail (attribute)' ' - git config --unset core.whitespace - echo "F whitespace=-trail" >.gitattributes - prepare_output + test_might_fail git config --unset core.whitespace && + echo "F whitespace=-trail" >.gitattributes && + prepare_output && grep Eight normal >/dev/null && grep HT error >/dev/null && @@ -79,9 +137,9 @@ test_expect_success 'without -trail (attribute)' ' test_expect_success 'without -space' ' - rm -f .gitattributes - git config core.whitespace -space - prepare_output + rm -f .gitattributes && + git config core.whitespace -space && + prepare_output && grep Eight normal >/dev/null && grep HT normal >/dev/null && @@ -93,9 +151,9 @@ test_expect_success 'without -space' ' test_expect_success 'without -space (attribute)' ' - git config --unset core.whitespace - echo "F whitespace=-space" >.gitattributes - prepare_output + test_might_fail git config --unset core.whitespace && + echo "F whitespace=-space" >.gitattributes && + prepare_output && grep Eight normal >/dev/null && grep HT normal >/dev/null && @@ -107,9 +165,9 @@ test_expect_success 'without -space (attribute)' ' test_expect_success 'with indent-non-tab only' ' - rm -f .gitattributes - git config core.whitespace indent,-trailing,-space - prepare_output + rm -f .gitattributes && + git config core.whitespace indent,-trailing,-space && + prepare_output && grep Eight error >/dev/null && grep HT normal >/dev/null && @@ -121,9 +179,9 @@ test_expect_success 'with indent-non-tab only' ' test_expect_success 'with indent-non-tab only (attribute)' ' - git config --unset core.whitespace - echo "F whitespace=indent,-trailing,-space" >.gitattributes - prepare_output + test_might_fail git config --unset core.whitespace && + echo "F whitespace=indent,-trailing,-space" >.gitattributes && + prepare_output && grep Eight error >/dev/null && grep HT normal >/dev/null && @@ -133,11 +191,39 @@ test_expect_success 'with indent-non-tab only (attribute)' ' ' +test_expect_success 'with indent-non-tab only, tabwidth=10' ' + + rm -f .gitattributes && + git config core.whitespace indent,tabwidth=10,-trailing,-space && + prepare_output && + + grep Eight normal >/dev/null && + grep HT normal >/dev/null && + grep With normal >/dev/null && + grep Return normal >/dev/null && + grep No normal >/dev/null + +' + +test_expect_success 'with indent-non-tab only, tabwidth=10 (attribute)' ' + + test_might_fail git config --unset core.whitespace && + echo "F whitespace=indent,-trailing,-space,tabwidth=10" >.gitattributes && + prepare_output && + + grep Eight normal >/dev/null && + grep HT normal >/dev/null && + grep With normal >/dev/null && + grep Return normal >/dev/null && + grep No normal >/dev/null + +' + test_expect_success 'with cr-at-eol' ' - rm -f .gitattributes - git config core.whitespace cr-at-eol - prepare_output + rm -f .gitattributes && + git config core.whitespace cr-at-eol && + prepare_output && grep Eight normal >/dev/null && grep HT error >/dev/null && @@ -149,9 +235,9 @@ test_expect_success 'with cr-at-eol' ' test_expect_success 'with cr-at-eol (attribute)' ' - git config --unset core.whitespace - echo "F whitespace=trailing,cr-at-eol" >.gitattributes - prepare_output + test_might_fail git config --unset core.whitespace && + echo "F whitespace=trailing,cr-at-eol" >.gitattributes && + prepare_output && grep Eight normal >/dev/null && grep HT error >/dev/null && @@ -178,12 +264,21 @@ test_expect_success 'trailing empty lines (2)' ' ' +test_expect_success 'checkdiff shows correct line number for trailing blank lines' ' + + printf "a\nb\n" > G && + git add G && + printf "x\nx\nx\na\nb\nc\n\n" > G && + [ "$(git diff --check -- G)" = "G:7: new blank line at EOF." ] + +' + test_expect_success 'do not color trailing cr in context' ' - git config --unset core.whitespace + test_might_fail git config --unset core.whitespace && rm -f .gitattributes && echo AAAQ | tr Q "\015" >G && git add G && - echo BBBQ | tr Q "\015" >>G + echo BBBQ | tr Q "\015" >>G && git diff --color G | tr "\015" Q >output && grep "BBB.*${blue_grep}Q" output && grep "AAA.*\[mQ" output diff --git a/t/t4021-format-patch-numbered.sh b/t/t4021-format-patch-numbered.sh index 709b3231ca..886494b58f 100755 --- a/t/t4021-format-patch-numbered.sh +++ b/t/t4021-format-patch-numbered.sh @@ -95,7 +95,7 @@ test_expect_success 'format.numbered && --keep-subject' ' test_expect_success 'format.numbered = auto' ' - git config format.numbered auto + git config format.numbered auto && git format-patch --stdout HEAD~2 > patch5 && test_numbered patch5 diff --git a/t/t4026-color.sh b/t/t4026-color.sh index d5ccdd0cf8..3726a0e201 100755 --- a/t/t4026-color.sh +++ b/t/t4026-color.sh @@ -74,7 +74,6 @@ test_expect_success 'extra character after attribute' ' ' test_expect_success 'unknown color slots are ignored (diff)' ' - git config --unset diff.color.new git config color.diff.nosuchslotwilleverbedefined white && git diff --color ' diff --git a/t/t4027-diff-submodule.sh b/t/t4027-diff-submodule.sh index d99814ac64..241a74d2a2 100755 --- a/t/t4027-diff-submodule.sh +++ b/t/t4027-diff-submodule.sh @@ -316,11 +316,11 @@ test_expect_success 'git diff (empty submodule dir)' ' test_expect_success 'conflicted submodule setup' ' # 39 efs - c=fffffffffffffffffffffffffffffffffffffff + c=fffffffffffffffffffffffffffffffffffffff && ( - echo "000000 $_z40 0 sub" - echo "160000 1$c 1 sub" - echo "160000 2$c 2 sub" + echo "000000 $_z40 0 sub" && + echo "160000 1$c 1 sub" && + echo "160000 2$c 2 sub" && echo "160000 3$c 3 sub" ) | git update-index --index-info && echo >expect.nosub '\''diff --cc sub diff --git a/t/t4031-diff-rewrite-binary.sh b/t/t4031-diff-rewrite-binary.sh index 7e7b307a24..7d7470f21b 100755 --- a/t/t4031-diff-rewrite-binary.sh +++ b/t/t4031-diff-rewrite-binary.sh @@ -44,6 +44,13 @@ test_expect_success 'rewrite diff can show binary patch' ' grep "GIT binary patch" diff ' +test_expect_success 'rewrite diff --stat shows binary changes' ' + git diff -B --stat --summary >diff && + grep "Bin" diff && + grep "0 insertions.*0 deletions" diff && + grep " rewrite file" diff +' + { echo "#!$SHELL_PATH" cat <<'EOF' diff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh index 6f7548c3a1..37aeab0d5c 100755 --- a/t/t4034-diff-words.sh +++ b/t/t4034-diff-words.sh @@ -4,331 +4,307 @@ test_description='word diff colors' . ./test-lib.sh -test_expect_success setup ' - - git config diff.color.old red - git config diff.color.new green - git config diff.color.func magenta +cat >pre.simple <<-\EOF + h(4) -' + a = b + c +EOF +cat >post.simple <<-\EOF + h(4),hh[44] -word_diff () { - test_must_fail git diff --no-index "$@" pre post > output && - test_decode_color <output >output.decrypted && - test_cmp expect output.decrypted -} + a = b + c -cat > pre <<\EOF -h(4) + aa = a -a = b + c + aeff = aeff * ( aaa ) EOF +cat >expect.letter-runs-are-words <<-\EOF + <BOLD>diff --git a/pre b/post<RESET> + <BOLD>index 330b04f..5ed8eff 100644<RESET> + <BOLD>--- a/pre<RESET> + <BOLD>+++ b/post<RESET> + <CYAN>@@ -1,3 +1,7 @@<RESET> + h(4),<GREEN>hh<RESET>[44] -cat > post <<\EOF -h(4),hh[44] + a = b + c<RESET> -a = b + c + <GREEN>aa = a<RESET> -aa = a - -aeff = aeff * ( aaa ) + <GREEN>aeff = aeff * ( aaa<RESET> ) EOF +cat >expect.non-whitespace-is-word <<-\EOF + <BOLD>diff --git a/pre b/post<RESET> + <BOLD>index 330b04f..5ed8eff 100644<RESET> + <BOLD>--- a/pre<RESET> + <BOLD>+++ b/post<RESET> + <CYAN>@@ -1,3 +1,7 @@<RESET> + h(4)<GREEN>,hh[44]<RESET> -cat > expect <<\EOF -<WHITE>diff --git a/pre b/post<RESET> -<WHITE>index 330b04f..5ed8eff 100644<RESET> -<WHITE>--- a/pre<RESET> -<WHITE>+++ b/post<RESET> -<CYAN>@@ -1,3 +1,7 @@<RESET> -<RED>h(4)<RESET><GREEN>h(4),hh[44]<RESET> - -a = b + c<RESET> + a = b + c<RESET> -<GREEN>aa = a<RESET> + <GREEN>aa = a<RESET> -<GREEN>aeff = aeff * ( aaa )<RESET> + <GREEN>aeff = aeff * ( aaa )<RESET> EOF -test_expect_success 'word diff with runs of whitespace' ' +word_diff () { + test_must_fail git diff --no-index "$@" pre post >output && + test_decode_color <output >output.decrypted && + test_cmp expect output.decrypted +} - word_diff --color-words +test_language_driver () { + lang=$1 + test_expect_success "diff driver '$lang'" ' + cp "$TEST_DIRECTORY/t4034/'"$lang"'/pre" \ + "$TEST_DIRECTORY/t4034/'"$lang"'/post" \ + "$TEST_DIRECTORY/t4034/'"$lang"'/expect" . && + echo "* diff='"$lang"'" >.gitattributes && + word_diff --color-words + ' +} +test_expect_success setup ' + git config diff.color.old red && + git config diff.color.new green && + git config diff.color.func magenta ' -test_expect_success '--word-diff=color' ' - - word_diff --word-diff=color - +test_expect_success 'set up pre and post with runs of whitespace' ' + cp pre.simple pre && + cp post.simple post ' -test_expect_success '--color --word-diff=color' ' - +test_expect_success 'word diff with runs of whitespace' ' + cat >expect <<-\EOF && + <BOLD>diff --git a/pre b/post<RESET> + <BOLD>index 330b04f..5ed8eff 100644<RESET> + <BOLD>--- a/pre<RESET> + <BOLD>+++ b/post<RESET> + <CYAN>@@ -1,3 +1,7 @@<RESET> + <RED>h(4)<RESET><GREEN>h(4),hh[44]<RESET> + + a = b + c<RESET> + + <GREEN>aa = a<RESET> + + <GREEN>aeff = aeff * ( aaa )<RESET> + EOF + word_diff --color-words && + word_diff --word-diff=color && word_diff --color --word-diff=color - ' -sed 's/#.*$//' > expect <<EOF -diff --git a/pre b/post -index 330b04f..5ed8eff 100644 ---- a/pre -+++ b/post -@@ -1,3 +1,7 @@ --h(4) -+h(4),hh[44] -~ - # significant space -~ - a = b + c -~ -~ -+aa = a -~ -~ -+aeff = aeff * ( aaa ) -~ -EOF - test_expect_success '--word-diff=porcelain' ' - + sed 's/#.*$//' >expect <<-\EOF && + diff --git a/pre b/post + index 330b04f..5ed8eff 100644 + --- a/pre + +++ b/post + @@ -1,3 +1,7 @@ + -h(4) + +h(4),hh[44] + ~ + # significant space + ~ + a = b + c + ~ + ~ + +aa = a + ~ + ~ + +aeff = aeff * ( aaa ) + ~ + EOF word_diff --word-diff=porcelain - ' -cat > expect <<EOF -diff --git a/pre b/post -index 330b04f..5ed8eff 100644 ---- a/pre -+++ b/post -@@ -1,3 +1,7 @@ -[-h(4)-]{+h(4),hh[44]+} - -a = b + c - -{+aa = a+} - -{+aeff = aeff * ( aaa )+} -EOF - test_expect_success '--word-diff=plain' ' + cat >expect <<-\EOF && + diff --git a/pre b/post + index 330b04f..5ed8eff 100644 + --- a/pre + +++ b/post + @@ -1,3 +1,7 @@ + [-h(4)-]{+h(4),hh[44]+} - word_diff --word-diff=plain + a = b + c -' - -test_expect_success '--word-diff=plain --no-color' ' + {+aa = a+} + {+aeff = aeff * ( aaa )+} + EOF + word_diff --word-diff=plain && word_diff --word-diff=plain --no-color - ' -cat > expect <<EOF -<WHITE>diff --git a/pre b/post<RESET> -<WHITE>index 330b04f..5ed8eff 100644<RESET> -<WHITE>--- a/pre<RESET> -<WHITE>+++ b/post<RESET> -<CYAN>@@ -1,3 +1,7 @@<RESET> -<RED>[-h(4)-]<RESET><GREEN>{+h(4),hh[44]+}<RESET> - -a = b + c<RESET> +test_expect_success '--word-diff=plain --color' ' + cat >expect <<-\EOF && + <BOLD>diff --git a/pre b/post<RESET> + <BOLD>index 330b04f..5ed8eff 100644<RESET> + <BOLD>--- a/pre<RESET> + <BOLD>+++ b/post<RESET> + <CYAN>@@ -1,3 +1,7 @@<RESET> + <RED>[-h(4)-]<RESET><GREEN>{+h(4),hh[44]+}<RESET> -<GREEN>{+aa = a+}<RESET> + a = b + c<RESET> -<GREEN>{+aeff = aeff * ( aaa )+}<RESET> -EOF - -test_expect_success '--word-diff=plain --color' ' + <GREEN>{+aa = a+}<RESET> + <GREEN>{+aeff = aeff * ( aaa )+}<RESET> + EOF word_diff --word-diff=plain --color - ' -cat > expect <<\EOF -<WHITE>diff --git a/pre b/post<RESET> -<WHITE>index 330b04f..5ed8eff 100644<RESET> -<WHITE>--- a/pre<RESET> -<WHITE>+++ b/post<RESET> -<CYAN>@@ -1 +1 @@<RESET> -<RED>h(4)<RESET><GREEN>h(4),hh[44]<RESET> -<CYAN>@@ -3,0 +4,4 @@<RESET> <RESET><MAGENTA>a = b + c<RESET> - -<GREEN>aa = a<RESET> - -<GREEN>aeff = aeff * ( aaa )<RESET> -EOF - test_expect_success 'word diff without context' ' - + cat >expect <<-\EOF && + <BOLD>diff --git a/pre b/post<RESET> + <BOLD>index 330b04f..5ed8eff 100644<RESET> + <BOLD>--- a/pre<RESET> + <BOLD>+++ b/post<RESET> + <CYAN>@@ -1 +1 @@<RESET> + <RED>h(4)<RESET><GREEN>h(4),hh[44]<RESET> + <CYAN>@@ -3,0 +4,4 @@<RESET> <RESET><MAGENTA>a = b + c<RESET> + + <GREEN>aa = a<RESET> + + <GREEN>aeff = aeff * ( aaa )<RESET> + EOF word_diff --color-words --unified=0 - ' -cat > expect <<\EOF -<WHITE>diff --git a/pre b/post<RESET> -<WHITE>index 330b04f..5ed8eff 100644<RESET> -<WHITE>--- a/pre<RESET> -<WHITE>+++ b/post<RESET> -<CYAN>@@ -1,3 +1,7 @@<RESET> -h(4),<GREEN>hh<RESET>[44] - -a = b + c<RESET> - -<GREEN>aa = a<RESET> - -<GREEN>aeff = aeff * ( aaa<RESET> ) -EOF -cp expect expect.letter-runs-are-words - test_expect_success 'word diff with a regular expression' ' - + cp expect.letter-runs-are-words expect && word_diff --color-words="[a-z]+" - ' -test_expect_success 'set a diff driver' ' +test_expect_success 'set up a diff driver' ' git config diff.testdriver.wordRegex "[^[:space:]]" && - cat <<EOF > .gitattributes -pre diff=testdriver -post diff=testdriver -EOF + cat <<-\EOF >.gitattributes + pre diff=testdriver + post diff=testdriver + EOF ' test_expect_success 'option overrides .gitattributes' ' - + cp expect.letter-runs-are-words expect && word_diff --color-words="[a-z]+" - ' -cat > expect <<\EOF -<WHITE>diff --git a/pre b/post<RESET> -<WHITE>index 330b04f..5ed8eff 100644<RESET> -<WHITE>--- a/pre<RESET> -<WHITE>+++ b/post<RESET> -<CYAN>@@ -1,3 +1,7 @@<RESET> -h(4)<GREEN>,hh[44]<RESET> - -a = b + c<RESET> - -<GREEN>aa = a<RESET> - -<GREEN>aeff = aeff * ( aaa )<RESET> -EOF -cp expect expect.non-whitespace-is-word - test_expect_success 'use regex supplied by driver' ' - + cp expect.non-whitespace-is-word expect && word_diff --color-words - ' -test_expect_success 'set diff.wordRegex option' ' +test_expect_success 'set up diff.wordRegex option' ' git config diff.wordRegex "[[:alnum:]]+" ' -cp expect.letter-runs-are-words expect - test_expect_success 'command-line overrides config' ' + cp expect.letter-runs-are-words expect && word_diff --color-words="[a-z]+" ' -cat > expect <<\EOF -<WHITE>diff --git a/pre b/post<RESET> -<WHITE>index 330b04f..5ed8eff 100644<RESET> -<WHITE>--- a/pre<RESET> -<WHITE>+++ b/post<RESET> -<CYAN>@@ -1,3 +1,7 @@<RESET> -h(4),<GREEN>{+hh+}<RESET>[44] - -a = b + c<RESET> +test_expect_success 'command-line overrides config: --word-diff-regex' ' + cat >expect <<-\EOF && + <BOLD>diff --git a/pre b/post<RESET> + <BOLD>index 330b04f..5ed8eff 100644<RESET> + <BOLD>--- a/pre<RESET> + <BOLD>+++ b/post<RESET> + <CYAN>@@ -1,3 +1,7 @@<RESET> + h(4),<GREEN>{+hh+}<RESET>[44] -<GREEN>{+aa = a+}<RESET> + a = b + c<RESET> -<GREEN>{+aeff = aeff * ( aaa+}<RESET> ) -EOF + <GREEN>{+aa = a+}<RESET> -test_expect_success 'command-line overrides config: --word-diff-regex' ' + <GREEN>{+aeff = aeff * ( aaa+}<RESET> ) + EOF word_diff --color --word-diff-regex="[a-z]+" ' -cp expect.non-whitespace-is-word expect - test_expect_success '.gitattributes override config' ' + cp expect.non-whitespace-is-word expect && word_diff --color-words ' -test_expect_success 'remove diff driver regex' ' - git config --unset diff.testdriver.wordRegex +test_expect_success 'setup: remove diff driver regex' ' + test_might_fail git config --unset diff.testdriver.wordRegex ' -cat > expect <<\EOF -<WHITE>diff --git a/pre b/post<RESET> -<WHITE>index 330b04f..5ed8eff 100644<RESET> -<WHITE>--- a/pre<RESET> -<WHITE>+++ b/post<RESET> -<CYAN>@@ -1,3 +1,7 @@<RESET> -h(4),<GREEN>hh[44<RESET>] - -a = b + c<RESET> +test_expect_success 'use configured regex' ' + cat >expect <<-\EOF && + <BOLD>diff --git a/pre b/post<RESET> + <BOLD>index 330b04f..5ed8eff 100644<RESET> + <BOLD>--- a/pre<RESET> + <BOLD>+++ b/post<RESET> + <CYAN>@@ -1,3 +1,7 @@<RESET> + h(4),<GREEN>hh[44<RESET>] -<GREEN>aa = a<RESET> + a = b + c<RESET> -<GREEN>aeff = aeff * ( aaa<RESET> ) -EOF + <GREEN>aa = a<RESET> -test_expect_success 'use configured regex' ' + <GREEN>aeff = aeff * ( aaa<RESET> ) + EOF word_diff --color-words ' -echo 'aaa (aaa)' > pre -echo 'aaa (aaa) aaa' > post - -cat > expect <<\EOF -<WHITE>diff --git a/pre b/post<RESET> -<WHITE>index c29453b..be22f37 100644<RESET> -<WHITE>--- a/pre<RESET> -<WHITE>+++ b/post<RESET> -<CYAN>@@ -1 +1 @@<RESET> -aaa (aaa) <GREEN>aaa<RESET> -EOF - test_expect_success 'test parsing words for newline' ' - + echo "aaa (aaa)" >pre && + echo "aaa (aaa) aaa" >post && + cat >expect <<-\EOF && + <BOLD>diff --git a/pre b/post<RESET> + <BOLD>index c29453b..be22f37 100644<RESET> + <BOLD>--- a/pre<RESET> + <BOLD>+++ b/post<RESET> + <CYAN>@@ -1 +1 @@<RESET> + aaa (aaa) <GREEN>aaa<RESET> + EOF word_diff --color-words="a+" - - ' -echo '(:' > pre -echo '(' > post - -cat > expect <<\EOF -<WHITE>diff --git a/pre b/post<RESET> -<WHITE>index 289cb9d..2d06f37 100644<RESET> -<WHITE>--- a/pre<RESET> -<WHITE>+++ b/post<RESET> -<CYAN>@@ -1 +1 @@<RESET> -(<RED>:<RESET> -EOF - test_expect_success 'test when words are only removed at the end' ' - + echo "(:" >pre && + echo "(" >post && + cat >expect <<-\EOF && + <BOLD>diff --git a/pre b/post<RESET> + <BOLD>index 289cb9d..2d06f37 100644<RESET> + <BOLD>--- a/pre<RESET> + <BOLD>+++ b/post<RESET> + <CYAN>@@ -1 +1 @@<RESET> + (<RED>:<RESET> + EOF word_diff --color-words=. - ' -cat > expect <<\EOF -diff --git a/pre b/post -index 289cb9d..2d06f37 100644 ---- a/pre -+++ b/post -@@ -1 +1 @@ --(: -+( -EOF - test_expect_success '--word-diff=none' ' - + echo "(:" >pre && + echo "(" >post && + cat >expect <<-\EOF && + diff --git a/pre b/post + index 289cb9d..2d06f37 100644 + --- a/pre + +++ b/post + @@ -1 +1 @@ + -(: + +( + EOF word_diff --word-diff=plain --word-diff=none - ' +test_language_driver bibtex +test_language_driver cpp +test_language_driver csharp +test_language_driver fortran +test_language_driver html +test_language_driver java +test_language_driver objc +test_language_driver pascal +test_language_driver perl +test_language_driver php +test_language_driver python +test_language_driver ruby +test_language_driver tex + test_done diff --git a/t/t4034/bibtex/expect b/t/t4034/bibtex/expect new file mode 100644 index 0000000000..a157774f9d --- /dev/null +++ b/t/t4034/bibtex/expect @@ -0,0 +1,15 @@ +<BOLD>diff --git a/pre b/post<RESET> +<BOLD>index 95cd55b..ddcba9b 100644<RESET> +<BOLD>--- a/pre<RESET> +<BOLD>+++ b/post<RESET> +<CYAN>@@ -1,9 +1,10 @@<RESET> +@article{aldous1987uie,<RESET> + title={{Ultimate instability of exponential back-off protocol for acknowledgment-based transmission control of random access communication channels}},<RESET> + author={Aldous, <RED>D.<RESET><GREEN>David<RESET>}, + journal={Information Theory, IEEE Transactions on},<RESET> + volume={<RED>33<RESET><GREEN>Bogus.<RESET>}, + number={<RED>2<RESET><GREEN>4<RESET>}, + pages={219--223},<RESET> + year=<GREEN>1987,<RESET> +<GREEN> note={This is in fact a rather funny read since ethernet works well in practice. The<RESET> {<RED>1987<RESET><GREEN>\em pre} reference is the right one, however.<RESET>}<RED>,<RESET> +}<RESET> diff --git a/t/t4034/bibtex/post b/t/t4034/bibtex/post new file mode 100644 index 0000000000..ddcba9b2fc --- /dev/null +++ b/t/t4034/bibtex/post @@ -0,0 +1,10 @@ +@article{aldous1987uie, + title={{Ultimate instability of exponential back-off protocol for acknowledgment-based transmission control of random access communication channels}}, + author={Aldous, David}, + journal={Information Theory, IEEE Transactions on}, + volume={Bogus.}, + number={4}, + pages={219--223}, + year=1987, + note={This is in fact a rather funny read since ethernet works well in practice. The {\em pre} reference is the right one, however.} +} diff --git a/t/t4034/bibtex/pre b/t/t4034/bibtex/pre new file mode 100644 index 0000000000..95cd55bd7b --- /dev/null +++ b/t/t4034/bibtex/pre @@ -0,0 +1,9 @@ +@article{aldous1987uie, + title={{Ultimate instability of exponential back-off protocol for acknowledgment-based transmission control of random access communication channels}}, + author={Aldous, D.}, + journal={Information Theory, IEEE Transactions on}, + volume={33}, + number={2}, + pages={219--223}, + year={1987}, +} diff --git a/t/t4034/cpp/expect b/t/t4034/cpp/expect new file mode 100644 index 0000000000..37d1ea2587 --- /dev/null +++ b/t/t4034/cpp/expect @@ -0,0 +1,36 @@ +<BOLD>diff --git a/pre b/post<RESET> +<BOLD>index 23d5c8a..7e8c026 100644<RESET> +<BOLD>--- a/pre<RESET> +<BOLD>+++ b/post<RESET> +<CYAN>@@ -1,19 +1,19 @@<RESET> +Foo() : x(0<RED>&&1<RESET><GREEN>&42<RESET>) { <GREEN>bar(x);<RESET> } +cout<<"Hello World<RED>!<RESET><GREEN>?<RESET>\n"<<endl; +<GREEN>(<RESET>1<GREEN>) (<RESET>-1e10<GREEN>) (<RESET>0xabcdef<GREEN>)<RESET> '<RED>x<RESET><GREEN>y<RESET>' +[<RED>a<RESET><GREEN>x<RESET>] <RED>a<RESET><GREEN>x<RESET>-><RED>b a<RESET><GREEN>y x<RESET>.<RED>b<RESET><GREEN>y<RESET> +!<RED>a<RESET><GREEN>x<RESET> ~<RED>a a<RESET><GREEN>x x<RESET>++ <RED>a<RESET><GREEN>x<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 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> +<RED>a<RESET><GREEN>y<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 a<RESET><GREEN>y 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> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>&<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>^<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>|<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>&&<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>||<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>?<RED>b<RESET><GREEN>y<RESET>:z +<RED>a<RESET><GREEN>x<RESET>=<RED>b a<RESET><GREEN>y x<RESET>+=<RED>b a<RESET><GREEN>y x<RESET>-=<RED>b a<RESET><GREEN>y x<RESET>*=<RED>b a<RESET><GREEN>y x<RESET>/=<RED>b a<RESET><GREEN>y x<RESET>%=<RED>b a<RESET><GREEN>y x<RESET><<=<RED>b a<RESET><GREEN>y x<RESET>>>=<RED>b a<RESET><GREEN>y x<RESET>&=<RED>b a<RESET><GREEN>y x<RESET>^=<RED>b a<RESET><GREEN>y x<RESET>|=<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>,y +<RED>a<RESET><GREEN>x<RESET>::<RED>b<RESET><GREEN>y<RESET> diff --git a/t/t4034/cpp/post b/t/t4034/cpp/post new file mode 100644 index 0000000000..7e8c026cef --- /dev/null +++ b/t/t4034/cpp/post @@ -0,0 +1,19 @@ +Foo() : x(0&42) { bar(x); } +cout<<"Hello World?\n"<<endl; +(1) (-1e10) (0xabcdef) 'y' +[x] x->y x.y +!x ~x x++ x-- x*y x&y +x*y x/y x%y +x+y x-y +x<<y x>>y +x<y x<=y x>y x>=y +x==y x!=y +x&y +x^y +x|y +x&&y +x||y +x?y:z +x=y x+=y x-=y x*=y x/=y x%=y x<<=y x>>=y x&=y x^=y x|=y +x,y +x::y diff --git a/t/t4034/cpp/pre b/t/t4034/cpp/pre new file mode 100644 index 0000000000..23d5c8adf5 --- /dev/null +++ b/t/t4034/cpp/pre @@ -0,0 +1,19 @@ +Foo():x(0&&1){} +cout<<"Hello World!\n"<<endl; +1 -1e10 0xabcdef 'x' +[a] a->b a.b +!a ~a a++ a-- a*b a&b +a*b a/b a%b +a+b a-b +a<<b a>>b +a<b a<=b a>b a>=b +a==b a!=b +a&b +a^b +a|b +a&&b +a||b +a?b:z +a=b a+=b a-=b a*=b a/=b a%=b a<<=b a>>=b a&=b a^=b a|=b +a,y +a::b diff --git a/t/t4034/csharp/expect b/t/t4034/csharp/expect new file mode 100644 index 0000000000..e5d1dd2b3d --- /dev/null +++ b/t/t4034/csharp/expect @@ -0,0 +1,35 @@ +<BOLD>diff --git a/pre b/post<RESET> +<BOLD>index 9106d63..dd5f421 100644<RESET> +<BOLD>--- a/pre<RESET> +<BOLD>+++ b/post<RESET> +<CYAN>@@ -1,18 +1,18 @@<RESET> +Foo() : x(0<RED>&&1<RESET><GREEN>&42<RESET>) { <GREEN>bar(x);<RESET> } +cout<<"Hello World<RED>!<RESET><GREEN>?<RESET>\n"<<endl; +<GREEN>(<RESET>1<GREEN>) (<RESET>-1e10<GREEN>) (<RESET>0xabcdef<GREEN>)<RESET> '<RED>x<RESET><GREEN>y<RESET>' +[<RED>a<RESET><GREEN>x<RESET>] <RED>a<RESET><GREEN>x<RESET>-><RED>b a<RESET><GREEN>y x<RESET>.<RED>b<RESET><GREEN>y<RESET> +!<RED>a<RESET><GREEN>x<RESET> ~<RED>a a<RESET><GREEN>x x<RESET>++ <RED>a<RESET><GREEN>x<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 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> +<RED>a<RESET><GREEN>y<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 a<RESET><GREEN>y 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> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>&<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>^<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>|<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>&&<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>||<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>?<RED>b<RESET><GREEN>y<RESET>:z +<RED>a<RESET><GREEN>x<RESET>=<RED>b a<RESET><GREEN>y x<RESET>+=<RED>b a<RESET><GREEN>y x<RESET>-=<RED>b a<RESET><GREEN>y x<RESET>*=<RED>b a<RESET><GREEN>y x<RESET>/=<RED>b a<RESET><GREEN>y x<RESET>%=<RED>b a<RESET><GREEN>y x<RESET><<=<RED>b a<RESET><GREEN>y x<RESET>>>=<RED>b a<RESET><GREEN>y x<RESET>&=<RED>b a<RESET><GREEN>y x<RESET>^=<RED>b a<RESET><GREEN>y x<RESET>|=<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>,y diff --git a/t/t4034/csharp/post b/t/t4034/csharp/post new file mode 100644 index 0000000000..dd5f4218a6 --- /dev/null +++ b/t/t4034/csharp/post @@ -0,0 +1,18 @@ +Foo() : x(0&42) { bar(x); } +cout<<"Hello World?\n"<<endl; +(1) (-1e10) (0xabcdef) 'y' +[x] x->y x.y +!x ~x x++ x-- x*y x&y +x*y x/y x%y +x+y x-y +x<<y x>>y +x<y x<=y x>y x>=y +x==y x!=y +x&y +x^y +x|y +x&&y +x||y +x?y:z +x=y x+=y x-=y x*=y x/=y x%=y x<<=y x>>=y x&=y x^=y x|=y +x,y diff --git a/t/t4034/csharp/pre b/t/t4034/csharp/pre new file mode 100644 index 0000000000..9106d63e87 --- /dev/null +++ b/t/t4034/csharp/pre @@ -0,0 +1,18 @@ +Foo():x(0&&1){} +cout<<"Hello World!\n"<<endl; +1 -1e10 0xabcdef 'x' +[a] a->b a.b +!a ~a a++ a-- a*b a&b +a*b a/b a%b +a+b a-b +a<<b a>>b +a<b a<=b a>b a>=b +a==b a!=b +a&b +a^b +a|b +a&&b +a||b +a?b:z +a=b a+=b a-=b a*=b a/=b a%=b a<<=b a>>=b a&=b a^=b a|=b +a,y diff --git a/t/t4034/fortran/expect b/t/t4034/fortran/expect new file mode 100644 index 0000000000..b233dbd621 --- /dev/null +++ b/t/t4034/fortran/expect @@ -0,0 +1,10 @@ +<BOLD>diff --git a/pre b/post<RESET> +<BOLD>index 87f0d0b..d308da2 100644<RESET> +<BOLD>--- a/pre<RESET> +<BOLD>+++ b/post<RESET> +<CYAN>@@ -1,5 +1,5 @@<RESET> +print *, "Hello World<RED>!<RESET><GREEN>?<RESET>" + +DO10I = 1,10<RESET> +<RED>DO10I<RESET><GREEN>DO 10 I<RESET> = 1,10 +<RED>DO10I<RESET><GREEN>DO 1 0 I<RESET> = 1,10 diff --git a/t/t4034/fortran/post b/t/t4034/fortran/post new file mode 100644 index 0000000000..d308da2ad2 --- /dev/null +++ b/t/t4034/fortran/post @@ -0,0 +1,5 @@ +print *, "Hello World?" + +DO10I = 1,10 +DO 10 I = 1,10 +DO 1 0 I = 1,10 diff --git a/t/t4034/fortran/pre b/t/t4034/fortran/pre new file mode 100644 index 0000000000..87f0d0b031 --- /dev/null +++ b/t/t4034/fortran/pre @@ -0,0 +1,5 @@ +print *, "Hello World!" + +DO10I = 1,10 +DO10I = 1,10 +DO10I = 1,10 diff --git a/t/t4034/html/expect b/t/t4034/html/expect new file mode 100644 index 0000000000..447b49ab6d --- /dev/null +++ b/t/t4034/html/expect @@ -0,0 +1,8 @@ +<BOLD>diff --git a/pre b/post<RESET> +<BOLD>index 8ca4aea..46921e5 100644<RESET> +<BOLD>--- a/pre<RESET> +<BOLD>+++ b/post<RESET> +<CYAN>@@ -1,3 +1,3 @@<RESET> +<tag <GREEN>newattr="newvalue"<RESET>><GREEN>added<RESET> content</tag> +<tag attr=<RED>"value"<RESET><GREEN>"newvalue"<RESET>><RED>content<RESET><GREEN>changed<RESET></tag> +<<RED>tag<RESET><GREEN>newtag<RESET>>content <RED>&entity;<RESET><GREEN>&newentity;<RESET><<RED>/tag<RESET><GREEN>/newtag<RESET>> diff --git a/t/t4034/html/post b/t/t4034/html/post new file mode 100644 index 0000000000..46921e586c --- /dev/null +++ b/t/t4034/html/post @@ -0,0 +1,3 @@ +<tag newattr="newvalue">added content</tag> +<tag attr="newvalue">changed</tag> +<newtag>content &newentity;</newtag> diff --git a/t/t4034/html/pre b/t/t4034/html/pre new file mode 100644 index 0000000000..8ca4aeae83 --- /dev/null +++ b/t/t4034/html/pre @@ -0,0 +1,3 @@ +<tag>content</tag> +<tag attr="value">content</tag> +<tag>content &entity;</tag> diff --git a/t/t4034/java/expect b/t/t4034/java/expect new file mode 100644 index 0000000000..37d1ea2587 --- /dev/null +++ b/t/t4034/java/expect @@ -0,0 +1,36 @@ +<BOLD>diff --git a/pre b/post<RESET> +<BOLD>index 23d5c8a..7e8c026 100644<RESET> +<BOLD>--- a/pre<RESET> +<BOLD>+++ b/post<RESET> +<CYAN>@@ -1,19 +1,19 @@<RESET> +Foo() : x(0<RED>&&1<RESET><GREEN>&42<RESET>) { <GREEN>bar(x);<RESET> } +cout<<"Hello World<RED>!<RESET><GREEN>?<RESET>\n"<<endl; +<GREEN>(<RESET>1<GREEN>) (<RESET>-1e10<GREEN>) (<RESET>0xabcdef<GREEN>)<RESET> '<RED>x<RESET><GREEN>y<RESET>' +[<RED>a<RESET><GREEN>x<RESET>] <RED>a<RESET><GREEN>x<RESET>-><RED>b a<RESET><GREEN>y x<RESET>.<RED>b<RESET><GREEN>y<RESET> +!<RED>a<RESET><GREEN>x<RESET> ~<RED>a a<RESET><GREEN>x x<RESET>++ <RED>a<RESET><GREEN>x<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 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> +<RED>a<RESET><GREEN>y<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 a<RESET><GREEN>y 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> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>&<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>^<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>|<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>&&<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>||<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>?<RED>b<RESET><GREEN>y<RESET>:z +<RED>a<RESET><GREEN>x<RESET>=<RED>b a<RESET><GREEN>y x<RESET>+=<RED>b a<RESET><GREEN>y x<RESET>-=<RED>b a<RESET><GREEN>y x<RESET>*=<RED>b a<RESET><GREEN>y x<RESET>/=<RED>b a<RESET><GREEN>y x<RESET>%=<RED>b a<RESET><GREEN>y x<RESET><<=<RED>b a<RESET><GREEN>y x<RESET>>>=<RED>b a<RESET><GREEN>y x<RESET>&=<RED>b a<RESET><GREEN>y x<RESET>^=<RED>b a<RESET><GREEN>y x<RESET>|=<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>,y +<RED>a<RESET><GREEN>x<RESET>::<RED>b<RESET><GREEN>y<RESET> diff --git a/t/t4034/java/post b/t/t4034/java/post new file mode 100644 index 0000000000..7e8c026cef --- /dev/null +++ b/t/t4034/java/post @@ -0,0 +1,19 @@ +Foo() : x(0&42) { bar(x); } +cout<<"Hello World?\n"<<endl; +(1) (-1e10) (0xabcdef) 'y' +[x] x->y x.y +!x ~x x++ x-- x*y x&y +x*y x/y x%y +x+y x-y +x<<y x>>y +x<y x<=y x>y x>=y +x==y x!=y +x&y +x^y +x|y +x&&y +x||y +x?y:z +x=y x+=y x-=y x*=y x/=y x%=y x<<=y x>>=y x&=y x^=y x|=y +x,y +x::y diff --git a/t/t4034/java/pre b/t/t4034/java/pre new file mode 100644 index 0000000000..23d5c8adf5 --- /dev/null +++ b/t/t4034/java/pre @@ -0,0 +1,19 @@ +Foo():x(0&&1){} +cout<<"Hello World!\n"<<endl; +1 -1e10 0xabcdef 'x' +[a] a->b a.b +!a ~a a++ a-- a*b a&b +a*b a/b a%b +a+b a-b +a<<b a>>b +a<b a<=b a>b a>=b +a==b a!=b +a&b +a^b +a|b +a&&b +a||b +a?b:z +a=b a+=b a-=b a*=b a/=b a%=b a<<=b a>>=b a&=b a^=b a|=b +a,y +a::b diff --git a/t/t4034/objc/expect b/t/t4034/objc/expect new file mode 100644 index 0000000000..e5d1dd2b3d --- /dev/null +++ b/t/t4034/objc/expect @@ -0,0 +1,35 @@ +<BOLD>diff --git a/pre b/post<RESET> +<BOLD>index 9106d63..dd5f421 100644<RESET> +<BOLD>--- a/pre<RESET> +<BOLD>+++ b/post<RESET> +<CYAN>@@ -1,18 +1,18 @@<RESET> +Foo() : x(0<RED>&&1<RESET><GREEN>&42<RESET>) { <GREEN>bar(x);<RESET> } +cout<<"Hello World<RED>!<RESET><GREEN>?<RESET>\n"<<endl; +<GREEN>(<RESET>1<GREEN>) (<RESET>-1e10<GREEN>) (<RESET>0xabcdef<GREEN>)<RESET> '<RED>x<RESET><GREEN>y<RESET>' +[<RED>a<RESET><GREEN>x<RESET>] <RED>a<RESET><GREEN>x<RESET>-><RED>b a<RESET><GREEN>y x<RESET>.<RED>b<RESET><GREEN>y<RESET> +!<RED>a<RESET><GREEN>x<RESET> ~<RED>a a<RESET><GREEN>x x<RESET>++ <RED>a<RESET><GREEN>x<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 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> +<RED>a<RESET><GREEN>y<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 a<RESET><GREEN>y 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> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>&<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>^<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>|<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>&&<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>||<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>?<RED>b<RESET><GREEN>y<RESET>:z +<RED>a<RESET><GREEN>x<RESET>=<RED>b a<RESET><GREEN>y x<RESET>+=<RED>b a<RESET><GREEN>y x<RESET>-=<RED>b a<RESET><GREEN>y x<RESET>*=<RED>b a<RESET><GREEN>y x<RESET>/=<RED>b a<RESET><GREEN>y x<RESET>%=<RED>b a<RESET><GREEN>y x<RESET><<=<RED>b a<RESET><GREEN>y x<RESET>>>=<RED>b a<RESET><GREEN>y x<RESET>&=<RED>b a<RESET><GREEN>y x<RESET>^=<RED>b a<RESET><GREEN>y x<RESET>|=<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>,y diff --git a/t/t4034/objc/post b/t/t4034/objc/post new file mode 100644 index 0000000000..dd5f4218a6 --- /dev/null +++ b/t/t4034/objc/post @@ -0,0 +1,18 @@ +Foo() : x(0&42) { bar(x); } +cout<<"Hello World?\n"<<endl; +(1) (-1e10) (0xabcdef) 'y' +[x] x->y x.y +!x ~x x++ x-- x*y x&y +x*y x/y x%y +x+y x-y +x<<y x>>y +x<y x<=y x>y x>=y +x==y x!=y +x&y +x^y +x|y +x&&y +x||y +x?y:z +x=y x+=y x-=y x*=y x/=y x%=y x<<=y x>>=y x&=y x^=y x|=y +x,y diff --git a/t/t4034/objc/pre b/t/t4034/objc/pre new file mode 100644 index 0000000000..9106d63e87 --- /dev/null +++ b/t/t4034/objc/pre @@ -0,0 +1,18 @@ +Foo():x(0&&1){} +cout<<"Hello World!\n"<<endl; +1 -1e10 0xabcdef 'x' +[a] a->b a.b +!a ~a a++ a-- a*b a&b +a*b a/b a%b +a+b a-b +a<<b a>>b +a<b a<=b a>b a>=b +a==b a!=b +a&b +a^b +a|b +a&&b +a||b +a?b:z +a=b a+=b a-=b a*=b a/=b a%=b a<<=b a>>=b a&=b a^=b a|=b +a,y diff --git a/t/t4034/pascal/expect b/t/t4034/pascal/expect new file mode 100644 index 0000000000..2ce4230954 --- /dev/null +++ b/t/t4034/pascal/expect @@ -0,0 +1,35 @@ +<BOLD>diff --git a/pre b/post<RESET> +<BOLD>index 077046c..8865e6b 100644<RESET> +<BOLD>--- a/pre<RESET> +<BOLD>+++ b/post<RESET> +<CYAN>@@ -1,18 +1,18 @@<RESET> +writeln("Hello World<RED>!<RESET><GREEN>?<RESET>"); +<GREEN>(<RESET>1<GREEN>) (<RESET>-1e10<GREEN>) (<RESET>0xabcdef<GREEN>)<RESET> '<RED>x<RESET><GREEN>y<RESET>' +[<RED>a<RESET><GREEN>x<RESET>] <RED>a<RESET><GREEN>x<RESET>-><RED>b a<RESET><GREEN>y x<RESET>.<RED>b<RESET><GREEN>y<RESET> +!<RED>a<RESET><GREEN>x<RESET> ~<RED>a a<RESET><GREEN>x x<RESET>++ <RED>a<RESET><GREEN>x<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 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> +<RED>a<RESET><GREEN>y<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 a<RESET><GREEN>y 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> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>&<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>^<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>|<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>&&<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>||<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>?<RED>b<RESET><GREEN>y<RESET>:z +<RED>a<RESET><GREEN>x<RESET>=<RED>b a<RESET><GREEN>y x<RESET>+=<RED>b a<RESET><GREEN>y x<RESET>-=<RED>b a<RESET><GREEN>y x<RESET>*=<RED>b a<RESET><GREEN>y x<RESET>/=<RED>b a<RESET><GREEN>y x<RESET>%=<RED>b a<RESET><GREEN>y x<RESET><<=<RED>b a<RESET><GREEN>y x<RESET>>>=<RED>b a<RESET><GREEN>y x<RESET>&=<RED>b a<RESET><GREEN>y x<RESET>^=<RED>b a<RESET><GREEN>y x<RESET>|=<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>,y +<RED>a<RESET><GREEN>x<RESET>::<RED>b<RESET><GREEN>y<RESET> diff --git a/t/t4034/pascal/post b/t/t4034/pascal/post new file mode 100644 index 0000000000..8865e6bddd --- /dev/null +++ b/t/t4034/pascal/post @@ -0,0 +1,18 @@ +writeln("Hello World?"); +(1) (-1e10) (0xabcdef) 'y' +[x] x->y x.y +!x ~x x++ x-- x*y x&y +x*y x/y x%y +x+y x-y +x<<y x>>y +x<y x<=y x>y x>=y +x==y x!=y +x&y +x^y +x|y +x&&y +x||y +x?y:z +x=y x+=y x-=y x*=y x/=y x%=y x<<=y x>>=y x&=y x^=y x|=y +x,y +x::y diff --git a/t/t4034/pascal/pre b/t/t4034/pascal/pre new file mode 100644 index 0000000000..077046c832 --- /dev/null +++ b/t/t4034/pascal/pre @@ -0,0 +1,18 @@ +writeln("Hello World!"); +1 -1e10 0xabcdef 'x' +[a] a->b a.b +!a ~a a++ a-- a*b a&b +a*b a/b a%b +a+b a-b +a<<b a>>b +a<b a<=b a>b a>=b +a==b a!=b +a&b +a^b +a|b +a&&b +a||b +a?b:z +a=b a+=b a-=b a*=b a/=b a%=b a<<=b a>>=b a&=b a^=b a|=b +a,y +a::b diff --git a/t/t4034/perl/expect b/t/t4034/perl/expect new file mode 100644 index 0000000000..a1deb6b6ad --- /dev/null +++ b/t/t4034/perl/expect @@ -0,0 +1,13 @@ +<BOLD>diff --git a/pre b/post<RESET> +<BOLD>index f6610d3..e8b72ef 100644<RESET> +<BOLD>--- a/pre<RESET> +<BOLD>+++ b/post<RESET> +<CYAN>@@ -4,8 +4,8 @@<RESET> + +package Frotz;<RESET> +sub new {<RESET> + my <GREEN>(<RESET>$class<GREEN>, %opts)<RESET> = <RED>shift<RESET><GREEN>@_<RESET>; + return bless { <GREEN>xyzzy => "nitfol", %opts<RESET> }, $class; +}<RESET> + +__END__<RESET> diff --git a/t/t4034/perl/post b/t/t4034/perl/post new file mode 100644 index 0000000000..e8b72ef5dc --- /dev/null +++ b/t/t4034/perl/post @@ -0,0 +1,22 @@ +#!/usr/bin/perl + +use strict; + +package Frotz; +sub new { + my ($class, %opts) = @_; + return bless { xyzzy => "nitfol", %opts }, $class; +} + +__END__ +=head1 NAME + +frotz - Frotz + +=head1 SYNOPSIS + + use frotz; + + $nitfol = new Frotz(); + +=cut diff --git a/t/t4034/perl/pre b/t/t4034/perl/pre new file mode 100644 index 0000000000..f6610d37b8 --- /dev/null +++ b/t/t4034/perl/pre @@ -0,0 +1,22 @@ +#!/usr/bin/perl + +use strict; + +package Frotz; +sub new { + my $class = shift; + return bless {}, $class; +} + +__END__ +=head1 NAME + +frotz - Frotz + +=head1 SYNOPSIS + + use frotz; + + $nitfol = new Frotz(); + +=cut diff --git a/t/t4034/php/expect b/t/t4034/php/expect new file mode 100644 index 0000000000..040440860a --- /dev/null +++ b/t/t4034/php/expect @@ -0,0 +1,35 @@ +<BOLD>diff --git a/pre b/post<RESET> +<BOLD>index cf6e06b..4420a49 100644<RESET> +<BOLD>--- a/pre<RESET> +<BOLD>+++ b/post<RESET> +<CYAN>@@ -1,18 +1,18 @@<RESET> +<GREEN>(<RESET>$var<GREEN>)<RESET> $ var +<?="Hello World<RED>!<RESET><GREEN>?<RESET>"?> +<GREEN>(<RESET>1<GREEN>) (<RESET>-1e10<GREEN>) (<RESET>0xabcdef<GREEN>)<RESET> '<RED>x<RESET><GREEN>y<RESET>' +[<RED>a<RESET><GREEN>x<RESET>] <RED>a<RESET><GREEN>x<RESET>-><RED>b a<RESET><GREEN>y x<RESET>.<RED>b<RESET><GREEN>y<RESET> +!<RED>a<RESET><GREEN>x<RESET> ~<RED>a a<RESET><GREEN>x x<RESET>++ <RED>a<RESET><GREEN>x<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 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> +<RED>a<RESET><GREEN>y<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 a<RESET><GREEN>y 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> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>&<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>^<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>|<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>&&<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>||<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>?<RED>b<RESET><GREEN>y<RESET>:z +<RED>a<RESET><GREEN>x<RESET>=<RED>b a<RESET><GREEN>y x<RESET>+=<RED>b a<RESET><GREEN>y x<RESET>-=<RED>b a<RESET><GREEN>y x<RESET>*=<RED>b a<RESET><GREEN>y x<RESET>/=<RED>b a<RESET><GREEN>y x<RESET>%=<RED>b a<RESET><GREEN>y x<RESET><<=<RED>b a<RESET><GREEN>y x<RESET>>>=<RED>b a<RESET><GREEN>y x<RESET>&=<RED>b a<RESET><GREEN>y x<RESET>^=<RED>b a<RESET><GREEN>y x<RESET>|=<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>,y diff --git a/t/t4034/php/post b/t/t4034/php/post new file mode 100644 index 0000000000..4420a49192 --- /dev/null +++ b/t/t4034/php/post @@ -0,0 +1,18 @@ +($var) $ var +<?="Hello World?"?> +(1) (-1e10) (0xabcdef) 'y' +[x] x->y x.y +!x ~x x++ x-- x*y x&y +x*y x/y x%y +x+y x-y +x<<y x>>y +x<y x<=y x>y x>=y +x==y x!=y +x&y +x^y +x|y +x&&y +x||y +x?y:z +x=y x+=y x-=y x*=y x/=y x%=y x<<=y x>>=y x&=y x^=y x|=y +x,y diff --git a/t/t4034/php/pre b/t/t4034/php/pre new file mode 100644 index 0000000000..cf6e06bc22 --- /dev/null +++ b/t/t4034/php/pre @@ -0,0 +1,18 @@ +$var $var +<?= "Hello World!" ?> +1 -1e10 0xabcdef 'x' +[a] a->b a.b +!a ~a a++ a-- a*b a&b +a*b a/b a%b +a+b a-b +a<<b a>>b +a<b a<=b a>b a>=b +a==b a!=b +a&b +a^b +a|b +a&&b +a||b +a?b:z +a=b a+=b a-=b a*=b a/=b a%=b a<<=b a>>=b a&=b a^=b a|=b +a,y diff --git a/t/t4034/python/expect b/t/t4034/python/expect new file mode 100644 index 0000000000..8abb8a48b4 --- /dev/null +++ b/t/t4034/python/expect @@ -0,0 +1,34 @@ +<BOLD>diff --git a/pre b/post<RESET> +<BOLD>index 438f776..68baf34 100644<RESET> +<BOLD>--- a/pre<RESET> +<BOLD>+++ b/post<RESET> +<CYAN>@@ -1,17 +1,17 @@<RESET> +print<RED>u<RESET> "Hello World<RED>!<RESET><GREEN>?<RESET>\n"<GREEN>; print<RESET> +<GREEN>(<RESET>1<GREEN>) (<RESET>-1e10<GREEN>) (<RESET>0xabcdef<GREEN>) u<RESET>'<RED>x<RESET><GREEN>y<RESET>' +[<RED>a<RESET><GREEN>x<RESET>] <RED>a<RESET><GREEN>x<RESET>-><RED>b a<RESET><GREEN>y x<RESET>.<RED>b<RESET><GREEN>y<RESET> +!<RED>a<RESET><GREEN>x<RESET> ~<RED>a a<RESET><GREEN>x x<RESET>++ <RED>a<RESET><GREEN>x<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 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> +<RED>a<RESET><GREEN>y<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 a<RESET><GREEN>y 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> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>&<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>^<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>|<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>&&<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>||<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>?<RED>b<RESET><GREEN>y<RESET>:z +<RED>a<RESET><GREEN>x<RESET>=<RED>b a<RESET><GREEN>y x<RESET>+=<RED>b a<RESET><GREEN>y x<RESET>-=<RED>b a<RESET><GREEN>y x<RESET>*=<RED>b a<RESET><GREEN>y x<RESET>/=<RED>b a<RESET><GREEN>y x<RESET>%=<RED>b a<RESET><GREEN>y x<RESET><<=<RED>b a<RESET><GREEN>y x<RESET>>>=<RED>b a<RESET><GREEN>y x<RESET>&=<RED>b a<RESET><GREEN>y x<RESET>^=<RED>b a<RESET><GREEN>y x<RESET>|=<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>,y diff --git a/t/t4034/python/post b/t/t4034/python/post new file mode 100644 index 0000000000..68baf34f0e --- /dev/null +++ b/t/t4034/python/post @@ -0,0 +1,17 @@ +print "Hello World?\n"; print +(1) (-1e10) (0xabcdef) u'y' +[x] x->y x.y +!x ~x x++ x-- x*y x&y +x*y x/y x%y +x+y x-y +x<<y x>>y +x<y x<=y x>y x>=y +x==y x!=y +x&y +x^y +x|y +x&&y +x||y +x?y:z +x=y x+=y x-=y x*=y x/=y x%=y x<<=y x>>=y x&=y x^=y x|=y +x,y diff --git a/t/t4034/python/pre b/t/t4034/python/pre new file mode 100644 index 0000000000..438f776875 --- /dev/null +++ b/t/t4034/python/pre @@ -0,0 +1,17 @@ +print u"Hello World!\n" +1 -1e10 0xabcdef 'x' +[a] a->b a.b +!a ~a a++ a-- a*b a&b +a*b a/b a%b +a+b a-b +a<<b a>>b +a<b a<=b a>b a>=b +a==b a!=b +a&b +a^b +a|b +a&&b +a||b +a?b:z +a=b a+=b a-=b a*=b a/=b a%=b a<<=b a>>=b a&=b a^=b a|=b +a,y diff --git a/t/t4034/ruby/expect b/t/t4034/ruby/expect new file mode 100644 index 0000000000..16e1dd5674 --- /dev/null +++ b/t/t4034/ruby/expect @@ -0,0 +1,34 @@ +<BOLD>diff --git a/pre b/post<RESET> +<BOLD>index 30ed9a1..7678f14 100644<RESET> +<BOLD>--- a/pre<RESET> +<BOLD>+++ b/post<RESET> +<CYAN>@@ -1,17 +1,17 @@<RESET> +10.downto(1) {|<RED>x<RESET><GREEN>y<RESET>| puts <RED>x<RESET><GREEN>y<RESET>} +<GREEN>(<RESET>1<GREEN>) (<RESET>-1e10<GREEN>) (<RESET>0xabcdef<GREEN>)<RESET> '<RED>x<RESET><GREEN>y<RESET>' +[<RED>a<RESET><GREEN>x<RESET>] <RED>a<RESET><GREEN>x<RESET>-><RED>b a<RESET><GREEN>y x<RESET>.<RED>b<RESET><GREEN>y<RESET> +!<RED>a<RESET><GREEN>x<RESET> ~<RED>a a<RESET><GREEN>x x<RESET>++ <RED>a<RESET><GREEN>x<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 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> +<RED>a<RESET><GREEN>y<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 a<RESET><GREEN>y 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> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>&<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>^<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>|<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>&&<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>||<RED>b<RESET> +<RED>a?b<RESET><GREEN>y<RESET> +<GREEN>x?y<RESET>:z +<RED>a<RESET><GREEN>x<RESET>=<RED>b a<RESET><GREEN>y x<RESET>+=<RED>b a<RESET><GREEN>y x<RESET>-=<RED>b a<RESET><GREEN>y x<RESET>*=<RED>b a<RESET><GREEN>y x<RESET>/=<RED>b a<RESET><GREEN>y x<RESET>%=<RED>b a<RESET><GREEN>y x<RESET><<=<RED>b a<RESET><GREEN>y x<RESET>>>=<RED>b a<RESET><GREEN>y x<RESET>&=<RED>b a<RESET><GREEN>y x<RESET>^=<RED>b a<RESET><GREEN>y x<RESET>|=<RED>b<RESET> +<RED>a<RESET><GREEN>y<RESET> +<GREEN>x<RESET>,y diff --git a/t/t4034/ruby/post b/t/t4034/ruby/post new file mode 100644 index 0000000000..7678f14e14 --- /dev/null +++ b/t/t4034/ruby/post @@ -0,0 +1,17 @@ +10.downto(1) {|y| puts y} +(1) (-1e10) (0xabcdef) 'y' +[x] x->y x.y +!x ~x x++ x-- x*y x&y +x*y x/y x%y +x+y x-y +x<<y x>>y +x<y x<=y x>y x>=y +x==y x!=y +x&y +x^y +x|y +x&&y +x||y +x?y:z +x=y x+=y x-=y x*=y x/=y x%=y x<<=y x>>=y x&=y x^=y x|=y +x,y diff --git a/t/t4034/ruby/pre b/t/t4034/ruby/pre new file mode 100644 index 0000000000..30ed9a1595 --- /dev/null +++ b/t/t4034/ruby/pre @@ -0,0 +1,17 @@ +10.downto(1) {|x| puts x} +1 -1e10 0xabcdef 'x' +[a] a->b a.b +!a ~a a++ a-- a*b a&b +a*b a/b a%b +a+b a-b +a<<b a>>b +a<b a<=b a>b a>=b +a==b a!=b +a&b +a^b +a|b +a&&b +a||b +a?b:z +a=b a+=b a-=b a*=b a/=b a%=b a<<=b a>>=b a&=b a^=b a|=b +a,y diff --git a/t/t4034/tex/expect b/t/t4034/tex/expect new file mode 100644 index 0000000000..604969bcde --- /dev/null +++ b/t/t4034/tex/expect @@ -0,0 +1,9 @@ +<BOLD>diff --git a/pre b/post<RESET> +<BOLD>index 2b2dfcb..65cab61 100644<RESET> +<BOLD>--- a/pre<RESET> +<BOLD>+++ b/post<RESET> +<CYAN>@@ -1,4 +1,4 @@<RESET> +\section{Something <GREEN>new<RESET>} +<RED>\emph<RESET><GREEN>\textbf<RESET>{Macro style} +{<RED>\em<RESET><GREEN>\bfseries<RESET> State toggle style} +\\[<RED>1em<RESET><GREEN>1cm<RESET>] diff --git a/t/t4034/tex/post b/t/t4034/tex/post new file mode 100644 index 0000000000..65cab61a10 --- /dev/null +++ b/t/t4034/tex/post @@ -0,0 +1,4 @@ +\section{Something new} +\textbf{Macro style} +{\bfseries State toggle style} +\\[1cm] diff --git a/t/t4034/tex/pre b/t/t4034/tex/pre new file mode 100644 index 0000000000..2b2dfcb65c --- /dev/null +++ b/t/t4034/tex/pre @@ -0,0 +1,4 @@ +\section{Something} +\emph{Macro style} +{\em State toggle style} +\\[1em] diff --git a/t/t4040-whitespace-status.sh b/t/t4040-whitespace-status.sh index a30b03bcf2..abc49348b1 100755 --- a/t/t4040-whitespace-status.sh +++ b/t/t4040-whitespace-status.sh @@ -60,4 +60,11 @@ test_expect_success 'diff-files -b -p --exit-code' ' git diff-files -b -p --exit-code ' +test_expect_success 'diff-files --diff-filter --quiet' ' + git reset --hard && + rm a/d && + echo x >>b/e && + test_must_fail git diff-files --diff-filter=M --quiet +' + test_done diff --git a/t/t4041-diff-submodule-option.sh b/t/t4041-diff-submodule-option.sh index 995bdfafec..bf9a7526bd 100755 --- a/t/t4041-diff-submodule-option.sh +++ b/t/t4041-diff-submodule-option.sh @@ -37,9 +37,10 @@ head1=$(add_file sm1 foo1 foo2) test_expect_success 'added submodule' " git add sm1 && git diff-index -p --submodule=log HEAD >actual && - diff actual - <<-EOF + cat >expected <<-EOF && Submodule sm1 0000000...$head1 (new submodule) EOF + test_cmp expected actual " commit_file sm1 && @@ -47,33 +48,36 @@ head2=$(add_file sm1 foo3) test_expect_success 'modified submodule(forward)' " git diff-index -p --submodule=log HEAD >actual && - diff actual - <<-EOF + cat >expected <<-EOF && Submodule sm1 $head1..$head2: > Add foo3 EOF + test_cmp expected actual " test_expect_success 'modified submodule(forward)' " git diff --submodule=log >actual && - diff actual - <<-EOF + cat >expected <<-EOF && Submodule sm1 $head1..$head2: > Add foo3 EOF + test_cmp expected actual " test_expect_success 'modified submodule(forward) --submodule' " git diff --submodule >actual && - diff actual - <<-EOF + cat >expected <<-EOF && Submodule sm1 $head1..$head2: > Add foo3 EOF + test_cmp expected actual " fullhead1=$(cd sm1; git rev-list --max-count=1 $head1) fullhead2=$(cd sm1; git rev-list --max-count=1 $head2) test_expect_success 'modified submodule(forward) --submodule=short' " git diff --submodule=short >actual && - diff actual - <<-EOF + cat >expected <<-EOF && diff --git a/sm1 b/sm1 index $head1..$head2 160000 --- a/sm1 @@ -82,6 +86,7 @@ index $head1..$head2 160000 -Subproject commit $fullhead1 +Subproject commit $fullhead2 EOF + test_cmp expected actual " commit_file sm1 && @@ -93,24 +98,26 @@ head3=$( test_expect_success 'modified submodule(backward)' " git diff-index -p --submodule=log HEAD >actual && - diff actual - <<-EOF + cat >expected <<-EOF && Submodule sm1 $head2..$head3 (rewind): < Add foo3 < Add foo2 EOF + test_cmp expected actual " head4=$(add_file sm1 foo4 foo5) && head4_full=$(GIT_DIR=sm1/.git git rev-parse --verify HEAD) test_expect_success 'modified submodule(backward and forward)' " git diff-index -p --submodule=log HEAD >actual && - diff actual - <<-EOF + cat >expected <<-EOF && Submodule sm1 $head2...$head4: > Add foo5 > Add foo4 < Add foo3 < Add foo2 EOF + test_cmp expected actual " commit_file sm1 && @@ -123,7 +130,7 @@ mv sm1-bak sm1 test_expect_success 'typechanged submodule(submodule->blob), --cached' " git diff --submodule=log --cached >actual && - diff actual - <<-EOF + cat >expected <<-EOF && Submodule sm1 41fbea9...0000000 (submodule deleted) diff --git a/sm1 b/sm1 new file mode 100644 @@ -133,11 +140,12 @@ index 0000000..9da5fb8 @@ -0,0 +1 @@ +sm1 EOF + test_cmp expected actual " test_expect_success 'typechanged submodule(submodule->blob)' " git diff --submodule=log >actual && - diff actual - <<-EOF + cat >expected <<-EOF && diff --git a/sm1 b/sm1 deleted file mode 100644 index 9da5fb8..0000000 @@ -147,13 +155,14 @@ index 9da5fb8..0000000 -sm1 Submodule sm1 0000000...$head4 (new submodule) EOF + test_cmp expected actual " rm -rf sm1 && git checkout-index sm1 test_expect_success 'typechanged submodule(submodule->blob)' " git diff-index -p --submodule=log HEAD >actual && - diff actual - <<-EOF + cat >expected <<-EOF && Submodule sm1 $head4...0000000 (submodule deleted) diff --git a/sm1 b/sm1 new file mode 100644 @@ -163,6 +172,7 @@ index 0000000..$head5 @@ -0,0 +1 @@ +sm1 EOF + test_cmp expected actual " rm -f sm1 && @@ -171,15 +181,16 @@ head6=$(add_file sm1 foo6 foo7) fullhead6=$(cd sm1; git rev-list --max-count=1 $head6) test_expect_success 'nonexistent commit' " git diff-index -p --submodule=log HEAD >actual && - diff actual - <<-EOF + cat >expected <<-EOF && Submodule sm1 $head4...$head6 (commits not present) EOF + test_cmp expected actual " commit_file test_expect_success 'typechanged submodule(blob->submodule)' " git diff-index -p --submodule=log HEAD >actual && - diff actual - <<-EOF + cat >expected <<-EOF && diff --git a/sm1 b/sm1 deleted file mode 100644 index $head5..0000000 @@ -189,21 +200,24 @@ index $head5..0000000 -sm1 Submodule sm1 0000000...$head6 (new submodule) EOF + test_cmp expected actual " commit_file sm1 && test_expect_success 'submodule is up to date' " git diff-index -p --submodule=log HEAD >actual && - diff actual - <<-EOF + cat >expected <<-EOF && EOF + test_cmp expected actual " test_expect_success 'submodule contains untracked content' " echo new > sm1/new-file && git diff-index -p --submodule=log HEAD >actual && - diff actual - <<-EOF + cat >expected <<-EOF && Submodule sm1 contains untracked content EOF + test_cmp expected actual " test_expect_success 'submodule contains untracked content (untracked ignored)' " @@ -224,18 +238,20 @@ test_expect_success 'submodule contains untracked content (all ignored)' " test_expect_success 'submodule contains untracked and modifed content' " echo new > sm1/foo6 && git diff-index -p --submodule=log HEAD >actual && - diff actual - <<-EOF + cat >expected <<-EOF && Submodule sm1 contains untracked content Submodule sm1 contains modified content EOF + test_cmp expected actual " test_expect_success 'submodule contains untracked and modifed content (untracked ignored)' " echo new > sm1/foo6 && git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual && - diff actual - <<-EOF + cat >expected <<-EOF && Submodule sm1 contains modified content EOF + test_cmp expected actual " test_expect_success 'submodule contains untracked and modifed content (dirty ignored)' " @@ -253,45 +269,50 @@ test_expect_success 'submodule contains untracked and modifed content (all ignor test_expect_success 'submodule contains modifed content' " rm -f sm1/new-file && git diff-index -p --submodule=log HEAD >actual && - diff actual - <<-EOF + cat >expected <<-EOF && Submodule sm1 contains modified content EOF + test_cmp expected actual " (cd sm1; git commit -mchange foo6 >/dev/null) && head8=$(cd sm1; git rev-parse --verify HEAD | cut -c1-7) && test_expect_success 'submodule is modified' " git diff-index -p --submodule=log HEAD >actual && - diff actual - <<-EOF + cat >expected <<-EOF && Submodule sm1 $head6..$head8: > change EOF + test_cmp expected actual " test_expect_success 'modified submodule contains untracked content' " echo new > sm1/new-file && git diff-index -p --submodule=log HEAD >actual && - diff actual - <<-EOF + cat >expected <<-EOF && Submodule sm1 contains untracked content Submodule sm1 $head6..$head8: > change EOF + test_cmp expected actual " test_expect_success 'modified submodule contains untracked content (untracked ignored)' " git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual && - diff actual - <<-EOF + cat >expected <<-EOF && Submodule sm1 $head6..$head8: > change EOF + test_cmp expected actual " test_expect_success 'modified submodule contains untracked content (dirty ignored)' " git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual && - diff actual - <<-EOF + cat >expected <<-EOF && Submodule sm1 $head6..$head8: > change EOF + test_cmp expected actual " test_expect_success 'modified submodule contains untracked content (all ignored)' " @@ -302,31 +323,34 @@ test_expect_success 'modified submodule contains untracked content (all ignored) test_expect_success 'modified submodule contains untracked and modifed content' " echo modification >> sm1/foo6 && git diff-index -p --submodule=log HEAD >actual && - diff actual - <<-EOF + cat >expected <<-EOF && Submodule sm1 contains untracked content Submodule sm1 contains modified content Submodule sm1 $head6..$head8: > change EOF + test_cmp expected actual " test_expect_success 'modified submodule contains untracked and modifed content (untracked ignored)' " echo modification >> sm1/foo6 && git diff-index -p --ignore-submodules=untracked --submodule=log HEAD >actual && - diff actual - <<-EOF + cat >expected <<-EOF && Submodule sm1 contains modified content Submodule sm1 $head6..$head8: > change EOF + test_cmp expected actual " test_expect_success 'modified submodule contains untracked and modifed content (dirty ignored)' " echo modification >> sm1/foo6 && git diff-index -p --ignore-submodules=dirty --submodule=log HEAD >actual && - diff actual - <<-EOF + cat >expected <<-EOF && Submodule sm1 $head6..$head8: > change EOF + test_cmp expected actual " test_expect_success 'modified submodule contains untracked and modifed content (all ignored)' " @@ -338,19 +362,21 @@ test_expect_success 'modified submodule contains untracked and modifed content ( test_expect_success 'modified submodule contains modifed content' " rm -f sm1/new-file && git diff-index -p --submodule=log HEAD >actual && - diff actual - <<-EOF + cat >expected <<-EOF && Submodule sm1 contains modified content Submodule sm1 $head6..$head8: > change EOF + test_cmp expected actual " rm -rf sm1 test_expect_success 'deleted submodule' " git diff-index -p --submodule=log HEAD >actual && - diff actual - <<-EOF + cat >expected <<-EOF && Submodule sm1 $head6...0000000 (submodule deleted) EOF + test_cmp expected actual " test_create_repo sm2 && @@ -359,41 +385,45 @@ git add sm2 test_expect_success 'multiple submodules' " git diff-index -p --submodule=log HEAD >actual && - diff actual - <<-EOF + cat >expected <<-EOF && Submodule sm1 $head6...0000000 (submodule deleted) Submodule sm2 0000000...$head7 (new submodule) EOF + test_cmp expected actual " test_expect_success 'path filter' " git diff-index -p --submodule=log HEAD sm2 >actual && - diff actual - <<-EOF + cat >expected <<-EOF && Submodule sm2 0000000...$head7 (new submodule) EOF + test_cmp expected actual " commit_file sm2 test_expect_success 'given commit' " git diff-index -p --submodule=log HEAD^ >actual && - diff actual - <<-EOF + cat >expected <<-EOF && Submodule sm1 $head6...0000000 (submodule deleted) Submodule sm2 0000000...$head7 (new submodule) EOF + test_cmp expected actual " test_expect_success 'given commit --submodule' " git diff-index -p --submodule HEAD^ >actual && - diff actual - <<-EOF + cat >expected <<-EOF && Submodule sm1 $head6...0000000 (submodule deleted) Submodule sm2 0000000...$head7 (new submodule) EOF + test_cmp expected actual " fullhead7=$(cd sm2; git rev-list --max-count=1 $head7) test_expect_success 'given commit --submodule=short' " git diff-index -p --submodule=short HEAD^ >actual && - diff actual - <<-EOF + cat >expected <<-EOF && diff --git a/sm1 b/sm1 deleted file mode 160000 index $head6..0000000 @@ -409,6 +439,7 @@ index 0000000..$head7 @@ -0,0 +1 @@ +Subproject commit $fullhead7 EOF + test_cmp expected actual " test_expect_success 'setup .git file for sm2' ' @@ -420,10 +451,11 @@ test_expect_success 'setup .git file for sm2' ' test_expect_success 'diff --submodule with .git file' ' git diff --submodule HEAD^ >actual && - diff actual - <<-EOF + cat >expected <<-EOF && Submodule sm1 $head6...0000000 (submodule deleted) Submodule sm2 0000000...$head7 (new submodule) EOF + test_cmp expected actual ' test_done diff --git a/t/t4103-apply-binary.sh b/t/t4103-apply-binary.sh index 9692f16f35..dbbf56cba9 100755 --- a/t/t4103-apply-binary.sh +++ b/t/t4103-apply-binary.sh @@ -37,15 +37,24 @@ test_expect_success 'setup' " git diff-tree -p -C master binary >C.diff && git diff-tree -p --binary master binary >BF.diff && - git diff-tree -p --binary -C master binary >CF.diff + git diff-tree -p --binary -C master binary >CF.diff && + + git diff-tree -p --full-index master binary >B-index.diff && + git diff-tree -p -C --full-index master binary >C-index.diff && + + git init other-repo && + (cd other-repo && + git fetch .. master && + git reset --hard FETCH_HEAD + ) " test_expect_success 'stat binary diff -- should not fail.' \ - 'git checkout master + 'git checkout master && git apply --stat --summary B.diff' test_expect_success 'stat binary diff (copy) -- should not fail.' \ - 'git checkout master + 'git checkout master && git apply --stat --summary C.diff' test_expect_success 'check binary diff -- should fail.' \ @@ -69,11 +78,11 @@ test_expect_success \ ' test_expect_success 'check binary diff with replacement.' \ - 'git checkout master + 'git checkout master && git apply --check --allow-binary-replacement BF.diff' test_expect_success 'check binary diff with replacement (copy).' \ - 'git checkout master + 'git checkout master && git apply --check --allow-binary-replacement CF.diff' # Now we start applying them. @@ -100,6 +109,22 @@ test_expect_success 'apply binary diff (copy) -- should fail.' \ 'do_reset && test_must_fail git apply --index C.diff' +test_expect_success 'apply binary diff with full-index' ' + do_reset && + git apply B-index.diff +' + +test_expect_success 'apply binary diff with full-index (copy)' ' + do_reset && + git apply C-index.diff +' + +test_expect_success 'apply full-index binary diff in new repo' ' + (cd other-repo && + do_reset && + test_must_fail git apply ../B-index.diff) +' + test_expect_success 'apply binary diff without replacement.' \ 'do_reset && git apply BF.diff' diff --git a/t/t4111-apply-subdir.sh b/t/t4111-apply-subdir.sh index a52d94ae21..7c398432ba 100755 --- a/t/t4111-apply-subdir.sh +++ b/t/t4111-apply-subdir.sh @@ -89,7 +89,7 @@ test_expect_success 'apply --index from subdir of toplevel' ' test_expect_success 'apply from .git dir' ' cp postimage expected && cp preimage .git/file && - cp preimage .git/objects/file + cp preimage .git/objects/file && ( cd .git && git apply "$patch" @@ -100,7 +100,7 @@ test_expect_success 'apply from .git dir' ' test_expect_success 'apply from subdir of .git dir' ' cp postimage expected && cp preimage .git/file && - cp preimage .git/objects/file + cp preimage .git/objects/file && ( cd .git/objects && git apply "$patch" diff --git a/t/t4119-apply-config.sh b/t/t4119-apply-config.sh index 3c73a783a7..3d0384daa8 100755 --- a/t/t4119-apply-config.sh +++ b/t/t4119-apply-config.sh @@ -73,7 +73,7 @@ D=`pwd` test_expect_success 'apply --whitespace=strip in subdir' ' cd "$D" && - git config --unset-all apply.whitespace + git config --unset-all apply.whitespace && rm -f sub/file1 && cp saved sub/file1 && git update-index --refresh && diff --git a/t/t4120-apply-popt.sh b/t/t4120-apply-popt.sh index 2b2d00b334..a33d510bf6 100755 --- a/t/t4120-apply-popt.sh +++ b/t/t4120-apply-popt.sh @@ -6,6 +6,7 @@ test_description='git apply -p handling.' . ./test-lib.sh +. "$TEST_DIRECTORY"/lib-prereq-FILEMODE.sh test_expect_success setup ' mkdir sub && @@ -56,4 +57,34 @@ test_expect_success 'apply with too large -p and fancy filename' ' grep "removing 3 leading" err ' +test_expect_success 'apply (-p2) diff, mode change only' ' + cat >patch.chmod <<-\EOF && + diff --git a/sub/file1 b/sub/file1 + old mode 100644 + new mode 100755 + EOF + test_chmod -x file1 && + git apply --index -p2 patch.chmod && + case $(git ls-files -s file1) in 100755*) : good;; *) false;; esac +' + +test_expect_success FILEMODE 'file mode was changed' ' + test -x file1 +' + +test_expect_success 'apply (-p2) diff, rename' ' + cat >patch.rename <<-\EOF && + diff --git a/sub/file1 b/sub/file2 + similarity index 100% + rename from sub/file1 + rename to sub/file2 + EOF + echo A >expected && + + cp file1.saved file1 && + rm -f file2 && + git apply -p2 patch.rename && + test_cmp expected file2 +' + test_done diff --git a/t/t4124-apply-ws-rule.sh b/t/t4124-apply-ws-rule.sh index 8a676a5dcd..6f6ee88b28 100755 --- a/t/t4124-apply-ws-rule.sh +++ b/t/t4124-apply-ws-rule.sh @@ -10,7 +10,8 @@ prepare_test_file () { # X RULE # ! trailing-space # @ space-before-tab - # # indent-with-non-tab + # # indent-with-non-tab (default tab width 8) + # = indent-with-non-tab,tabwidth=16 # % tab-in-indent sed -e "s/_/ /g" -e "s/>/ /" <<-\EOF An_SP in an ordinary line>and a HT. @@ -25,8 +26,8 @@ prepare_test_file () { ________>_Eight SP, a HT and a SP (@#%). _______________Fifteen SP (#). _______________>Fifteen SP and a HT (@#%). - ________________Sixteen SP (#). - ________________>Sixteen SP and a HT (@#%). + ________________Sixteen SP (#=). + ________________>Sixteen SP and a HT (@#%=). _____a__Five SP, a non WS, two SP. A line with a (!) trailing SP_ A line with a (!) trailing HT> @@ -121,6 +122,34 @@ test_expect_success 'whitespace=error-all, no rule (attribute)' ' ' +test_expect_success 'spaces inserted by tab-in-indent' ' + + git config core.whitespace -trailing,-space,-indent,tab && + rm -f .gitattributes && + test_fix % && + sed -e "s/_/ /g" -e "s/>/ /" <<-\EOF >expect && + An_SP in an ordinary line>and a HT. + ________A HT (%). + ________A SP and a HT (@%). + _________A SP, a HT and a SP (@%). + _______Seven SP. + ________Eight SP (#). + ________Seven SP and a HT (@%). + ________________Eight SP and a HT (@#%). + _________Seven SP, a HT and a SP (@%). + _________________Eight SP, a HT and a SP (@#%). + _______________Fifteen SP (#). + ________________Fifteen SP and a HT (@#%). + ________________Sixteen SP (#=). + ________________________Sixteen SP and a HT (@#%=). + _____a__Five SP, a non WS, two SP. + A line with a (!) trailing SP_ + A line with a (!) trailing HT> + EOF + test_cmp expect target + +' + for t in - '' do case "$t" in '') tt='!' ;; *) tt= ;; esac @@ -129,7 +158,7 @@ do case "$s" in '') ts='@' ;; *) ts= ;; esac for i in - '' do - case "$i" in '') ti='#' ;; *) ti= ;; esac + case "$i" in '') ti='#' ti16='=';; *) ti= ti16= ;; esac for h in - '' do [ -z "$h$i" ] && continue @@ -142,12 +171,22 @@ do test_fix "$tt$ts$ti$th" ' + test_expect_success "rule=$rule,tabwidth=16" ' + git config core.whitespace "$rule,tabwidth=16" && + test_fix "$tt$ts$ti16$th" + ' + test_expect_success "rule=$rule (attributes)" ' git config --unset core.whitespace && echo "target whitespace=$rule" >.gitattributes && test_fix "$tt$ts$ti$th" ' + test_expect_success "rule=$rule,tabwidth=16 (attributes)" ' + echo "target whitespace=$rule,tabwidth=16" >.gitattributes && + test_fix "$tt$ts$ti16$th" + ' + done done done @@ -176,9 +215,8 @@ test_expect_success 'trailing whitespace & no newline at the end of file' ' ' test_expect_success 'blank at EOF with --whitespace=fix (1)' ' - : these can fail depending on what we did before - git config --unset core.whitespace - rm -f .gitattributes + test_might_fail git config --unset core.whitespace && + rm -f .gitattributes && { echo a; echo b; echo c; } >one && git add one && @@ -368,7 +406,7 @@ test_expect_success 'missing blanks at EOF must only match blank lines' ' git diff -- one >patch && echo a >one && - test_must_fail git apply patch + test_must_fail git apply patch && test_must_fail git apply --whitespace=fix patch && test_must_fail git apply --ignore-space-change --whitespace=fix patch ' @@ -419,7 +457,7 @@ test_expect_success 'same, but with CR-LF line endings && cr-at-eol set' ' printf "b\r\n" >>one && printf "c\r\n" >>one && cp one save-one && - printf " \r\n" >>one + printf " \r\n" >>one && git add one && printf "d\r\n" >>one && cp one expect && @@ -436,7 +474,7 @@ test_expect_success 'same, but with CR-LF line endings && cr-at-eol unset' ' printf "b\r\n" >>one && printf "c\r\n" >>one && cp one save-one && - printf " \r\n" >>one + printf " \r\n" >>one && git add one && cp one expect && printf "d\r\n" >>one && diff --git a/t/t4127-apply-same-fn.sh b/t/t4127-apply-same-fn.sh index 77200c0b2d..972946c174 100755 --- a/t/t4127-apply-same-fn.sh +++ b/t/t4127-apply-same-fn.sh @@ -31,7 +31,7 @@ test_expect_success 'apply same filename with independent changes' ' ' test_expect_success 'apply same filename with overlapping changes' ' - git reset --hard + git reset --hard && modify "s/^d/z/" same_fn && git diff > patch0 && git add same_fn && @@ -44,8 +44,8 @@ test_expect_success 'apply same filename with overlapping changes' ' ' test_expect_success 'apply same new filename after rename' ' - git reset --hard - git mv same_fn new_fn + git reset --hard && + git mv same_fn new_fn && modify "s/^d/z/" new_fn && git add new_fn && git diff -M --cached > patch1 && @@ -58,12 +58,12 @@ test_expect_success 'apply same new filename after rename' ' ' test_expect_success 'apply same old filename after rename -- should fail.' ' - git reset --hard - git mv same_fn new_fn + git reset --hard && + git mv same_fn new_fn && modify "s/^d/z/" new_fn && git add new_fn && git diff -M --cached > patch1 && - git mv new_fn same_fn + git mv new_fn same_fn && modify "s/^e/y/" same_fn && git diff >> patch1 && git reset --hard && @@ -71,13 +71,13 @@ test_expect_success 'apply same old filename after rename -- should fail.' ' ' test_expect_success 'apply A->B (rename), C->A (rename), A->A -- should pass.' ' - git reset --hard - git mv same_fn new_fn + git reset --hard && + git mv same_fn new_fn && modify "s/^d/z/" new_fn && git add new_fn && git diff -M --cached > patch1 && git commit -m "a rename" && - git mv other_fn same_fn + git mv other_fn same_fn && modify "s/^e/y/" same_fn && git add same_fn && git diff -M --cached >> patch1 && diff --git a/t/t4130-apply-criss-cross-rename.sh b/t/t4130-apply-criss-cross-rename.sh index 7cfa2d6287..d173acde0f 100755 --- a/t/t4130-apply-criss-cross-rename.sh +++ b/t/t4130-apply-criss-cross-rename.sh @@ -44,7 +44,7 @@ test_expect_success 'criss-cross rename' ' git reset --hard && mv file1 tmp && mv file2 file1 && - mv file3 file2 + mv file3 file2 && mv tmp file3 && cp file1 file1-swapped && cp file2 file2-swapped && diff --git a/t/t4132-apply-removal.sh b/t/t4132-apply-removal.sh index bb1ffe3b6c..a2bc1cd37d 100755 --- a/t/t4132-apply-removal.sh +++ b/t/t4132-apply-removal.sh @@ -30,6 +30,7 @@ test_expect_success setup ' epocWest="1969-12-31 16:00:00.000000000 -0800" && epocGMT="1970-01-01 00:00:00.000000000 +0000" && epocEast="1970-01-01 09:00:00.000000000 +0900" && + epocWest2="1969-12-31 16:00:00 -08:00" && sed -e "s/TS0/$epocWest/" -e "s/TS1/$timeWest/" <c >createWest.patch && sed -e "s/TS0/$epocEast/" -e "s/TS1/$timeEast/" <c >createEast.patch && @@ -46,6 +47,7 @@ test_expect_success setup ' sed -e "s/TS0/$timeWest/" -e "s/TS1/$epocWest/" <d >removeWest.patch && sed -e "s/TS0/$timeEast/" -e "s/TS1/$epocEast/" <d >removeEast.patch && sed -e "s/TS0/$timeGMT/" -e "s/TS1/$epocGMT/" <d >removeGMT.patch && + sed -e "s/TS0/$timeWest/" -e "s/TS1/$epocWest2/" <d >removeWest2.patch && echo something >something && >empty diff --git a/t/t4133-apply-filenames.sh b/t/t4133-apply-filenames.sh index 34218071b6..94da99075c 100755 --- a/t/t4133-apply-filenames.sh +++ b/t/t4133-apply-filenames.sh @@ -8,7 +8,7 @@ test_description='git apply filename consistency check' . ./test-lib.sh test_expect_success setup ' - cat > bad1.patch <<EOF + cat > bad1.patch <<EOF && diff --git a/f b/f new file mode 100644 index 0000000..d00491f @@ -29,9 +29,9 @@ EOF ' test_expect_success 'apply diff with inconsistent filenames in headers' ' - test_must_fail git apply bad1.patch 2>err - grep "inconsistent new filename" err - test_must_fail git apply bad2.patch 2>err + test_must_fail git apply bad1.patch 2>err && + grep "inconsistent new filename" err && + test_must_fail git apply bad2.patch 2>err && grep "inconsistent old filename" err ' diff --git a/t/t4134-apply-submodule.sh b/t/t4134-apply-submodule.sh index 1b82f93cff..0043930ca6 100755 --- a/t/t4134-apply-submodule.sh +++ b/t/t4134-apply-submodule.sh @@ -8,7 +8,7 @@ test_description='git apply submodule tests' . ./test-lib.sh test_expect_success setup ' - cat > create-sm.patch <<EOF + cat > create-sm.patch <<EOF && diff --git a/dir/sm b/dir/sm new file mode 160000 index 0000000..0123456 diff --git a/t/t4135-apply-weird-filenames.sh b/t/t4135-apply-weird-filenames.sh index 1e5aad57ab..bf5dc57286 100755 --- a/t/t4135-apply-weird-filenames.sh +++ b/t/t4135-apply-weird-filenames.sh @@ -72,4 +72,20 @@ test_expect_success 'whitespace-damaged traditional patch' ' test_cmp expected postimage.txt ' +test_expect_success 'traditional patch with colon in timezone' ' + echo postimage >expected && + reset_preimage && + rm -f "post image.txt" && + git apply "$vector/funny-tz.diff" && + test_cmp expected "post image.txt" +' + +test_expect_success 'traditional, whitespace-damaged, colon in timezone' ' + echo postimage >expected && + reset_preimage && + rm -f "post image.txt" && + git apply "$vector/damaged-tz.diff" && + test_cmp expected "post image.txt" +' + test_done diff --git a/t/t4135/damaged-tz.diff b/t/t4135/damaged-tz.diff new file mode 100644 index 0000000000..07aaf08370 --- /dev/null +++ b/t/t4135/damaged-tz.diff @@ -0,0 +1,5 @@ +diff -urN -X /usr/people/jes/exclude-linux linux-2.6.12-rc2-mm3-vanilla/post image.txt linux-2.6.12-rc2-mm3/post image.txt +--- linux-2.6.12-rc2-mm3-vanilla/post image.txt 1969-12-31 16:00:00 -08:00 ++++ linux-2.6.12-rc2-mm3/post image.txt 2005-04-12 02:14:06 -07:00 +@@ -0,0 +1 @@ ++postimage diff --git a/t/t4135/funny-tz.diff b/t/t4135/funny-tz.diff new file mode 100644 index 0000000000..998e3a867e --- /dev/null +++ b/t/t4135/funny-tz.diff @@ -0,0 +1,5 @@ +diff -urN -X /usr/people/jes/exclude-linux linux-2.6.12-rc2-mm3-vanilla/post image.txt linux-2.6.12-rc2-mm3/post image.txt +--- linux-2.6.12-rc2-mm3-vanilla/post image.txt 1969-12-31 16:00:00 -08:00 ++++ linux-2.6.12-rc2-mm3/post image.txt 2005-04-12 02:14:06 -07:00 +@@ -0,0 +1 @@ ++postimage diff --git a/t/t4150-am.sh b/t/t4150-am.sh index 1c3d8ed548..850fc96d1f 100755 --- a/t/t4150-am.sh +++ b/t/t4150-am.sh @@ -219,7 +219,7 @@ test_expect_success 'am stays in branch' ' test_expect_success 'am --signoff does not add Signed-off-by: line if already there' ' git format-patch --stdout HEAD^ >patch3 && - sed -e "/^Subject/ s,\[PATCH,Re: Re: Re: & 1/5 v2," patch3 >patch4 + sed -e "/^Subject/ s,\[PATCH,Re: Re: Re: & 1/5 v2," patch3 >patch4 && rm -fr .git/rebase-apply && git reset --hard && git checkout HEAD^ && diff --git a/t/t4151-am-abort.sh b/t/t4151-am-abort.sh index b55c411788..c95c4ccc39 100755 --- a/t/t4151-am-abort.sh +++ b/t/t4151-am-abort.sh @@ -62,4 +62,13 @@ do done +test_expect_success 'am --abort will keep the local commits intact' ' + test_must_fail git am 0004-*.patch && + test_commit unrelated && + git rev-parse HEAD >expect && + git am --abort && + git rev-parse HEAD >actual && + test_cmp expect actual +' + test_done diff --git a/t/t4201-shortlog.sh b/t/t4201-shortlog.sh index cdb70b4b33..6872ba1a42 100755 --- a/t/t4201-shortlog.sh +++ b/t/t4201-shortlog.sh @@ -35,7 +35,7 @@ test_expect_success 'setup' ' tr 1234 "\370\235\204\236")" a1 && echo 5 >a1 && - git commit --quiet -m "a 12 34 56 78" a1 + git commit --quiet -m "a 12 34 56 78" a1 && echo 6 >a1 && git commit --quiet -m "Commit by someone else" \ diff --git a/t/t4202-log.sh b/t/t4202-log.sh index 2e51356947..2fcc31a6f3 100755 --- a/t/t4202-log.sh +++ b/t/t4202-log.sh @@ -191,7 +191,7 @@ test_expect_success 'git show <commits> leaves list of commits as given' ' test_expect_success 'setup case sensitivity tests' ' echo case >one && test_tick && - git add one + git add one && git commit -a -m Second ' @@ -341,7 +341,7 @@ test_expect_success 'set up more tangled history' ' test_commit octopus-b && git checkout master && test_commit seventh && - git merge octopus-a octopus-b + git merge octopus-a octopus-b && git merge reach ' @@ -393,7 +393,7 @@ test_expect_success 'log --graph with merge' ' ' test_expect_success 'log.decorate configuration' ' - git config --unset-all log.decorate || : + test_might_fail git config --unset-all log.decorate && git log --oneline >expect.none && git log --oneline --decorate >expect.short && @@ -422,6 +422,15 @@ test_expect_success 'log.decorate configuration' ' test_cmp expect.full actual && git config --unset-all log.decorate && + git config log.decorate 1 && + git log --oneline >actual && + test_cmp expect.short actual && + git log --oneline --decorate=full >actual && + test_cmp expect.full actual && + git log --oneline --decorate=no >actual && + test_cmp expect.none actual && + + git config --unset-all log.decorate && git config log.decorate short && git log --oneline >actual && test_cmp expect.short actual && diff --git a/t/t4203-mailmap.sh b/t/t4203-mailmap.sh index 9a7d1b4466..e818de6ddd 100755 --- a/t/t4203-mailmap.sh +++ b/t/t4203-mailmap.sh @@ -4,6 +4,14 @@ test_description='.mailmap configurations' . ./test-lib.sh +fuzz_blame () { + sed " + s/$_x05[0-9a-f][0-9a-f][0-9a-f]/OBJID/g + s/$_x05[0-9a-f][0-9a-f]/OBJI/g + s/[-0-9]\{10\} [:0-9]\{8\} [-+][0-9]\{4\}/DATE/g + " "$@" +} + test_expect_success setup ' echo one >one && git add one && @@ -11,6 +19,7 @@ test_expect_success setup ' git commit -m initial && echo two >>one && git add one && + test_tick && git commit --author "nick1 <bugs@company.xx>" -m second ' @@ -54,7 +63,7 @@ Repo Guy (1): EOF test_expect_success 'mailmap.file set' ' - mkdir internal_mailmap && + mkdir -p internal_mailmap && echo "Internal Guy <bugs@company.xx>" > internal_mailmap/.mailmap && git config mailmap.file internal_mailmap/.mailmap && git shortlog HEAD >actual && @@ -93,6 +102,40 @@ test_expect_success 'mailmap.file non-existant' ' ' cat >expect <<\EOF +Internal Guy (1): + second + +Repo Guy (1): + initial + +EOF + +test_expect_success 'name entry after email entry' ' + mkdir -p internal_mailmap && + echo "<bugs@company.xy> <bugs@company.xx>" >internal_mailmap/.mailmap && + echo "Internal Guy <bugs@company.xx>" >>internal_mailmap/.mailmap && + git shortlog HEAD >actual && + test_cmp expect actual +' + +cat >expect <<\EOF +Internal Guy (1): + second + +Repo Guy (1): + initial + +EOF + +test_expect_success 'name entry after email entry, case-insensitive' ' + mkdir -p internal_mailmap && + echo "<bugs@company.xy> <bugs@company.xx>" >internal_mailmap/.mailmap && + echo "Internal Guy <BUGS@Company.xx>" >>internal_mailmap/.mailmap && + git shortlog HEAD >actual && + test_cmp expect actual +' + +cat >expect <<\EOF A U Thor (1): initial @@ -101,7 +144,7 @@ nick1 (1): EOF test_expect_success 'No mailmap files, but configured' ' - rm .mailmap && + rm -f .mailmap internal_mailmap/.mailmap && git shortlog HEAD >actual && test_cmp expect actual ' @@ -153,7 +196,7 @@ test_expect_success 'Shortlog output (complex mapping)' ' test_tick && git commit --author "CTO <cto@coompany.xx>" -m seventh && - mkdir internal_mailmap && + mkdir -p internal_mailmap && echo "Committed <committer@example.com>" > internal_mailmap/.mailmap && echo "<cto@company.xx> <cto@coompany.xx>" >> internal_mailmap/.mailmap && echo "Some Dude <some@dude.xx> nick1 <bugs@company.xx>" >> internal_mailmap/.mailmap && @@ -198,18 +241,18 @@ test_expect_success 'Log output (complex mapping)' ' # git blame cat >expect <<\EOF -^3a2fdcb (A U Thor 2005-04-07 15:13:13 -0700 1) one -7de6f99b (Some Dude 2005-04-07 15:13:13 -0700 2) two -5815879d (Other Author 2005-04-07 15:14:13 -0700 3) three -ff859d96 (Other Author 2005-04-07 15:15:13 -0700 4) four -5ab6d4fa (Santa Claus 2005-04-07 15:16:13 -0700 5) five -38a42d8b (Santa Claus 2005-04-07 15:17:13 -0700 6) six -8ddc0386 (CTO 2005-04-07 15:18:13 -0700 7) seven +^OBJI (A U Thor DATE 1) one +OBJID (Some Dude DATE 2) two +OBJID (Other Author DATE 3) three +OBJID (Other Author DATE 4) four +OBJID (Santa Claus DATE 5) five +OBJID (Santa Claus DATE 6) six +OBJID (CTO DATE 7) seven EOF - test_expect_success 'Blame output (complex mapping)' ' git blame one >actual && - test_cmp expect actual + fuzz_blame actual >actual.fuzz && + test_cmp expect actual.fuzz ' test_done diff --git a/t/t4204-patch-id.sh b/t/t4204-patch-id.sh index 68e2652814..d2c930de87 100755 --- a/t/t4204-patch-id.sh +++ b/t/t4204-patch-id.sh @@ -63,4 +63,40 @@ test_expect_success 'patch-id supports git-format-patch MIME output' ' test_cmp patch-id_master patch-id_same ' +cat >nonl <<\EOF +diff --git i/a w/a +index e69de29..2e65efe 100644 +--- i/a ++++ w/a +@@ -0,0 +1 @@ ++a +\ No newline at end of file +diff --git i/b w/b +index e69de29..6178079 100644 +--- i/b ++++ w/b +@@ -0,0 +1 @@ ++b +EOF + +cat >withnl <<\EOF +diff --git i/a w/a +index e69de29..7898192 100644 +--- i/a ++++ w/a +@@ -0,0 +1 @@ ++a +diff --git i/b w/b +index e69de29..6178079 100644 +--- i/b ++++ w/b +@@ -0,0 +1 @@ ++b +EOF + +test_expect_success 'patch-id handles no-nl-at-eof markers' ' + cat nonl | calc_patch_id nonl && + cat withnl | calc_patch_id withnl && + test_cmp patch-id_nonl patch-id_withnl +' test_done diff --git a/t/t4252-am-options.sh b/t/t4252-am-options.sh index f603c1b133..e758e634a3 100755 --- a/t/t4252-am-options.sh +++ b/t/t4252-am-options.sh @@ -59,7 +59,7 @@ test_expect_success 'interrupted am --directory="frotz nitfol"' ' ' test_expect_success 'apply to a funny path' ' - with_sq="with'\''sq" + with_sq="with'\''sq" && rm -fr .git/rebase-apply && git reset --hard initial && git am --directory="$with_sq" "$tm"/am-test-5-2 && diff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh index 27bfba55bd..cff1b3e050 100755 --- a/t/t5000-tar-tree.sh +++ b/t/t5000-tar-tree.sh @@ -94,7 +94,7 @@ test_expect_success 'git archive with --output' \ 'git archive --output=b4.tar HEAD && test_cmp b.tar b4.tar' -test_expect_success 'git archive --remote' \ +test_expect_success NOT_MINGW 'git archive --remote' \ 'git archive --remote=. HEAD >b5.tar && test_cmp b.tar b5.tar' diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh index bbb9c1251d..602806d09c 100755 --- a/t/t5300-pack-object.sh +++ b/t/t5300-pack-object.sh @@ -12,7 +12,7 @@ TRASH=`pwd` test_expect_success \ 'setup' \ - 'rm -f .git/index* + 'rm -f .git/index* && perl -e "print \"a\" x 4096;" > a && perl -e "print \"b\" x 4096;" > b && perl -e "print \"c\" x 4096;" > c && diff --git a/t/t5301-sliding-window.sh b/t/t5301-sliding-window.sh index 0a24e61ff9..2fc5af6007 100755 --- a/t/t5301-sliding-window.sh +++ b/t/t5301-sliding-window.sh @@ -8,7 +8,7 @@ test_description='mmap sliding window tests' test_expect_success \ 'setup' \ - 'rm -f .git/index* + 'rm -f .git/index* && for i in a b c do echo $i >$i && @@ -48,7 +48,7 @@ test_expect_success \ git repack -a -d && test "`git count-objects`" = "0 objects, 0 kilobytes" && pack2=`ls .git/objects/pack/*.pack` && - test -f "$pack2" + test -f "$pack2" && test "$pack1" \!= "$pack2"' test_expect_success \ diff --git a/t/t5302-pack-index.sh b/t/t5302-pack-index.sh index fb3a270822..b34ea93a80 100755 --- a/t/t5302-pack-index.sh +++ b/t/t5302-pack-index.sh @@ -8,7 +8,7 @@ test_description='pack index with 64-bit offsets and object CRC' test_expect_success \ 'setup' \ - 'rm -rf .git + 'rm -rf .git && git init && git config pack.threads 1 && i=1 && diff --git a/t/t5304-prune.sh b/t/t5304-prune.sh index e2ed13dba2..d645328609 100755 --- a/t/t5304-prune.sh +++ b/t/t5304-prune.sh @@ -14,7 +14,8 @@ add_blob() { BLOB=$(echo aleph_0 | git hash-object -w --stdin) && BLOB_FILE=.git/objects/$(echo $BLOB | sed "s/^../&\//") && test $((1 + $before)) = $(git count-objects | sed "s/ .*//") && - test -f $BLOB_FILE + test -f $BLOB_FILE && + test-chmtime =+0 $BLOB_FILE } test_expect_success setup ' diff --git a/t/t5400-send-pack.sh b/t/t5400-send-pack.sh index 5bcf0b867a..b0b2684a1f 100755 --- a/t/t5400-send-pack.sh +++ b/t/t5400-send-pack.sh @@ -129,7 +129,7 @@ test_expect_success 'denyNonFastforwards trumps --force' ' test "$victim_orig" = "$victim_head" ' -test_expect_success 'push --all excludes remote tracking hierarchy' ' +test_expect_success 'push --all excludes remote-tracking hierarchy' ' mkdir parent && ( cd parent && diff --git a/t/t5407-post-rewrite-hook.sh b/t/t5407-post-rewrite-hook.sh index 552da65a61..baa670cea5 100755 --- a/t/t5407-post-rewrite-hook.sh +++ b/t/t5407-post-rewrite-hook.sh @@ -10,7 +10,11 @@ test_expect_success 'setup' ' test_commit A foo A && test_commit B foo B && test_commit C foo C && - test_commit D foo D + test_commit D foo D && + git checkout A^0 && + test_commit E bar E && + test_commit F foo F && + git checkout master ' mkdir .git/hooks @@ -79,6 +83,18 @@ EOF verify_hook_input ' +test_expect_success 'git rebase --skip the last one' ' + git reset --hard F && + clear_hook_input && + test_must_fail git rebase --onto D A && + git rebase --skip && + echo rebase >expected.args && + cat >expected.data <<EOF && +$(git rev-parse E) $(git rev-parse HEAD) +EOF + verify_hook_input +' + test_expect_success 'git rebase -m' ' git reset --hard D && clear_hook_input && diff --git a/t/t5500-fetch-pack.sh b/t/t5500-fetch-pack.sh index 18376d6608..bafcca765e 100755 --- a/t/t5500-fetch-pack.sh +++ b/t/t5500-fetch-pack.sh @@ -91,7 +91,7 @@ test_expect_success 'setup' ' prev=$cur && cur=$(($cur+1)) done && - add B1 $A1 + add B1 $A1 && echo $ATIP > .git/refs/heads/A && echo $BTIP > .git/refs/heads/B && git symbolic-ref HEAD refs/heads/B diff --git a/t/t5501-fetch-push-alternates.sh b/t/t5501-fetch-push-alternates.sh new file mode 100755 index 0000000000..b5ced8483a --- /dev/null +++ b/t/t5501-fetch-push-alternates.sh @@ -0,0 +1,66 @@ +#!/bin/sh + +test_description='fetch/push involving alternates' +. ./test-lib.sh + +count_objects () { + loose=0 inpack=0 + eval "$( + git count-objects -v | + sed -n -e 's/^count: \(.*\)/loose=\1/p' \ + -e 's/^in-pack: \(.*\)/inpack=\1/p' + )" && + echo $(( $loose + $inpack )) +} + + +test_expect_success setup ' + ( + git init original && + cd original && + i=0 && + while test $i -le 100 + do + echo "$i" >count && + git add count && + git commit -m "$i" || exit + i=$(($i + 1)) + done + ) && + ( + git clone --reference=original "file:///$(pwd)/original" one && + cd one && + echo Z >count && + git add count && + git commit -m Z && + count_objects >../one.count + ) && + A=$(pwd)/original/.git/objects && + git init receiver && + echo "$A" >receiver/.git/objects/info/alternates && + git init fetcher && + echo "$A" >fetcher/.git/objects/info/alternates +' + +test_expect_success 'pushing into a repository with the same alternate' ' + ( + cd one && + git push ../receiver master:refs/heads/it + ) && + ( + cd receiver && + count_objects >../receiver.count + ) && + test_cmp one.count receiver.count +' + +test_expect_success 'fetching from a repository with the same alternate' ' + ( + cd fetcher && + git fetch ../one master:refs/heads/it && + count_objects >../fetcher.count + ) && + test_cmp one.count fetcher.count +' + +test_done diff --git a/t/t5502-quickfetch.sh b/t/t5502-quickfetch.sh index 1037a723fe..7a46cbdbe6 100755 --- a/t/t5502-quickfetch.sh +++ b/t/t5502-quickfetch.sh @@ -57,7 +57,7 @@ test_expect_success 'copy commit and tree but not blob by hand' ' cd cloned && git count-objects | sed -e "s/ *objects,.*//" ) ) && - test $cnt -eq 6 + test $cnt -eq 6 && blob=$(git rev-parse HEAD:file | sed -e "s|..|&/|") && test -f "cloned/.git/objects/$blob" && diff --git a/t/t5503-tagfollow.sh b/t/t5503-tagfollow.sh index 8a298a655f..60de2d6ede 100755 --- a/t/t5503-tagfollow.sh +++ b/t/t5503-tagfollow.sh @@ -4,14 +4,9 @@ test_description='test automatic tag following' . ./test-lib.sh -case $(uname -s) in -*MINGW*) +if ! test_have_prereq NOT_MINGW; then say "GIT_DEBUG_SEND_PACK not supported - skipping tests" - ;; -*) - test_set_prereq NOT_MINGW - ;; -esac +fi # End state of the repository: # @@ -54,7 +49,7 @@ EOF ' test_expect_success NOT_MINGW 'fetch A (new commit : 1 connection)' ' - rm -f $U + rm -f $U && ( cd cloned && GIT_DEBUG_SEND_PACK=3 git fetch 3>../$U && @@ -87,7 +82,7 @@ EOF ' test_expect_success NOT_MINGW 'fetch C, T (new branch, tag : 1 connection)' ' - rm -f $U + rm -f $U && ( cd cloned && GIT_DEBUG_SEND_PACK=3 git fetch 3>../$U && @@ -126,7 +121,7 @@ EOF ' test_expect_success NOT_MINGW 'fetch B, S (commit and tag : 1 connection)' ' - rm -f $U + rm -f $U && ( cd cloned && GIT_DEBUG_SEND_PACK=3 git fetch 3>../$U && diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index 5d1c66ea71..4e69c907d8 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -107,16 +107,18 @@ test_expect_success 'remove remote' ' ) ' -test_expect_success 'remove remote protects non-remote branches' ' +test_expect_success 'remove remote protects local branches' ' ( cd test && { cat >expect1 <<EOF -Note: A non-remote branch was not removed; to delete it, use: +Note: A branch outside the refs/remotes/ hierarchy was not removed; +to delete it, use: git branch -d master EOF } && { cat >expect2 <<EOF -Note: Non-remote branches were not removed; to delete them, use: +Note: Some branches outside the refs/remotes/ hierarchy were not removed; +to delete them, use: git branch -d foobranch git branch -d master EOF @@ -302,6 +304,84 @@ test_expect_success 'add --mirror && prune' ' git rev-parse --verify refs/heads/side) ' +test_expect_success 'add --mirror=fetch' ' + mkdir mirror-fetch && + git init mirror-fetch/parent && + (cd mirror-fetch/parent && + test_commit one) && + git init --bare mirror-fetch/child && + (cd mirror-fetch/child && + git remote add --mirror=fetch -f parent ../parent) +' + +test_expect_success 'fetch mirrors act as mirrors during fetch' ' + (cd mirror-fetch/parent && + git branch new && + git branch -m master renamed + ) && + (cd mirror-fetch/child && + git fetch parent && + git rev-parse --verify refs/heads/new && + git rev-parse --verify refs/heads/renamed + ) +' + +test_expect_success 'fetch mirrors can prune' ' + (cd mirror-fetch/child && + git remote prune parent && + test_must_fail git rev-parse --verify refs/heads/master + ) +' + +test_expect_success 'fetch mirrors do not act as mirrors during push' ' + (cd mirror-fetch/parent && + git checkout HEAD^0 + ) && + (cd mirror-fetch/child && + git branch -m renamed renamed2 && + git push parent + ) && + (cd mirror-fetch/parent && + git rev-parse --verify renamed && + test_must_fail git rev-parse --verify refs/heads/renamed2 + ) +' + +test_expect_success 'add --mirror=push' ' + mkdir mirror-push && + git init --bare mirror-push/public && + git init mirror-push/private && + (cd mirror-push/private && + test_commit one && + git remote add --mirror=push public ../public + ) +' + +test_expect_success 'push mirrors act as mirrors during push' ' + (cd mirror-push/private && + git branch new && + git branch -m master renamed && + git push public + ) && + (cd mirror-push/private && + git rev-parse --verify refs/heads/new && + git rev-parse --verify refs/heads/renamed && + test_must_fail git rev-parse --verify refs/heads/master + ) +' + +test_expect_success 'push mirrors do not act as mirrors during fetch' ' + (cd mirror-push/public && + git branch -m renamed renamed2 && + git symbolic-ref HEAD refs/heads/renamed2 + ) && + (cd mirror-push/private && + git fetch public && + git rev-parse --verify refs/heads/renamed && + test_must_fail git rev-parse --verify refs/heads/renamed2 + ) +' + test_expect_success 'add alt && prune' ' (mkdir alttst && cd alttst && diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh index 9a884751ec..7e433b179f 100755 --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@ -119,7 +119,7 @@ test_expect_success 'fetch must not resolve short tag name' ' test_expect_success 'fetch must not resolve short remote name' ' cd "$D" && - git update-ref refs/remotes/six/HEAD HEAD + git update-ref refs/remotes/six/HEAD HEAD && mkdir six && cd six && diff --git a/t/t5513-fetch-track.sh b/t/t5513-fetch-track.sh index 9e7486274b..65d1e05bd6 100755 --- a/t/t5513-fetch-track.sh +++ b/t/t5513-fetch-track.sh @@ -1,6 +1,6 @@ #!/bin/sh -test_description='fetch follows remote tracking branches correctly' +test_description='fetch follows remote-tracking branches correctly' . ./test-lib.sh diff --git a/t/t5514-fetch-multiple.sh b/t/t5514-fetch-multiple.sh index b73733219d..227dd56137 100755 --- a/t/t5514-fetch-multiple.sh +++ b/t/t5514-fetch-multiple.sh @@ -27,7 +27,7 @@ test_expect_success setup ' ( cd two && git branch another ) && - git clone --mirror two three + git clone --mirror two three && git clone one test ' diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index b11da79c9c..d73731e644 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -586,7 +586,7 @@ test_expect_success 'push --delete refuses src:dest refspecs' ' ' test_expect_success 'warn on push to HEAD of non-bare repository' ' - mk_test heads/master + mk_test heads/master && ( cd testrepo && git checkout master && @@ -597,7 +597,7 @@ test_expect_success 'warn on push to HEAD of non-bare repository' ' ' test_expect_success 'deny push to HEAD of non-bare repository' ' - mk_test heads/master + mk_test heads/master && ( cd testrepo && git checkout master && @@ -607,7 +607,7 @@ test_expect_success 'deny push to HEAD of non-bare repository' ' ' test_expect_success 'allow push to HEAD of bare repository (bare)' ' - mk_test heads/master + mk_test heads/master && ( cd testrepo && git checkout master && @@ -619,7 +619,7 @@ test_expect_success 'allow push to HEAD of bare repository (bare)' ' ' test_expect_success 'allow push to HEAD of non-bare repository (config)' ' - mk_test heads/master + mk_test heads/master && ( cd testrepo && git checkout master && diff --git a/t/t5519-push-alternates.sh b/t/t5519-push-alternates.sh index 96be5236a2..c00c9b071d 100755 --- a/t/t5519-push-alternates.sh +++ b/t/t5519-push-alternates.sh @@ -123,7 +123,7 @@ test_expect_success 'bob works and pushes again' ' ( cd alice-pub && git cat-file commit master >../bob-work/commit - ) + ) && ( # This time Bob does not pull from Alice, and # the master branch at her public repository points diff --git a/t/t5520-pull.sh b/t/t5520-pull.sh index 0b489f5b12..0e5eb678ce 100755 --- a/t/t5520-pull.sh +++ b/t/t5520-pull.sh @@ -46,6 +46,17 @@ test_expect_success 'pulling into void using master:master' ' test_cmp file cloned-uho/file ' +test_expect_success 'pulling into void does not overwrite untracked files' ' + git init cloned-untracked && + ( + cd cloned-untracked && + echo untracked >file && + test_must_fail git pull .. master && + echo untracked >expect && + test_cmp expect file + ) +' + test_expect_success 'test . as a remote' ' git branch copy master && @@ -222,4 +233,11 @@ test_expect_success 'git pull --rebase does not reapply old patches' ' ) ' +test_expect_success 'git pull --rebase against local branch' ' + git checkout -b copy2 to-rebase-orig && + git pull --rebase . to-rebase && + test "conflicting modification" = "$(cat file)" && + test file = "$(cat file2)" +' + test_done diff --git a/t/t5523-push-upstream.sh b/t/t5523-push-upstream.sh index 00da70763b..c229fe68f1 100755 --- a/t/t5523-push-upstream.sh +++ b/t/t5523-push-upstream.sh @@ -2,9 +2,14 @@ test_description='push with --set-upstream' . ./test-lib.sh +. "$TEST_DIRECTORY"/lib-terminal.sh + +ensure_fresh_upstream() { + rm -rf parent && git init --bare parent +} test_expect_success 'setup bare parent' ' - git init --bare parent && + ensure_fresh_upstream && git remote add upstream parent ' @@ -66,4 +71,41 @@ test_expect_success 'push -u HEAD' ' check_config headbranch upstream refs/heads/headbranch ' +test_expect_success TTY 'progress messages go to tty' ' + ensure_fresh_upstream && + + test_terminal git push -u upstream master >out 2>err && + grep "Writing objects" err +' + +test_expect_success 'progress messages do not go to non-tty' ' + ensure_fresh_upstream && + + # skip progress messages, since stderr is non-tty + git push -u upstream master >out 2>err && + ! grep "Writing objects" err +' + +test_expect_success 'progress messages go to non-tty (forced)' ' + ensure_fresh_upstream && + + # force progress messages to stderr, even though it is non-tty + git push -u --progress upstream master >out 2>err && + grep "Writing objects" err +' + +test_expect_success TTY 'push -q suppresses progress' ' + ensure_fresh_upstream && + + test_terminal git push -u -q upstream master >out 2>err && + ! grep "Writing objects" err +' + +test_expect_failure TTY 'push --no-progress suppresses progress' ' + ensure_fresh_upstream && + + test_terminal git push -u --no-progress upstream master >out 2>err && + ! grep "Writing objects" err +' + test_done diff --git a/t/t5526-fetch-submodules.sh b/t/t5526-fetch-submodules.sh new file mode 100755 index 0000000000..af78e21ba9 --- /dev/null +++ b/t/t5526-fetch-submodules.sh @@ -0,0 +1,474 @@ +#!/bin/sh +# Copyright (c) 2010, Jens Lehmann + +test_description='Recursive "git fetch" for submodules' + +. ./test-lib.sh + +pwd=$(pwd) + +add_upstream_commit() { + ( + cd submodule && + head1=$(git rev-parse --short HEAD) && + echo new >> subfile && + test_tick && + git add subfile && + git commit -m new subfile && + head2=$(git rev-parse --short HEAD) && + echo "From $pwd/submodule" > ../expect.err && + echo " $head1..$head2 master -> origin/master" >> ../expect.err + ) && + ( + cd deepsubmodule && + head1=$(git rev-parse --short HEAD) && + echo new >> deepsubfile && + test_tick && + git add deepsubfile && + git commit -m new deepsubfile && + head2=$(git rev-parse --short HEAD) && + echo "From $pwd/deepsubmodule" >> ../expect.err && + echo " $head1..$head2 master -> origin/master" >> ../expect.err + ) +} + +test_expect_success setup ' + mkdir deepsubmodule && + ( + cd deepsubmodule && + git init && + echo deepsubcontent > deepsubfile && + git add deepsubfile && + git commit -m new deepsubfile + ) && + mkdir submodule && + ( + cd submodule && + git init && + echo subcontent > subfile && + git add subfile && + git submodule add "$pwd/deepsubmodule" deepsubmodule && + git commit -a -m new + ) && + git submodule add "$pwd/submodule" submodule && + git commit -am initial && + git clone . downstream && + ( + cd downstream && + git submodule update --init --recursive + ) && + echo "Fetching submodule submodule" > expect.out && + echo "Fetching submodule submodule/deepsubmodule" >> expect.out +' + +test_expect_success "fetch --recurse-submodules recurses into submodules" ' + add_upstream_commit && + ( + cd downstream && + git fetch --recurse-submodules >../actual.out 2>../actual.err + ) +' + +test_expect_success C_LOCALE_OUTPUT "fetch --recurse-submodules recurses into submodules: output" ' + test_cmp expect.out actual.out && + test_cmp expect.err actual.err +' + +test_expect_success "fetch alone only fetches superproject" ' + add_upstream_commit && + ( + cd downstream && + git fetch >../actual.out 2>../actual.err + ) && + ! test -s actual.out && + ! test -s actual.err +' + +test_expect_success "fetch --no-recurse-submodules only fetches superproject" ' + ( + cd downstream && + git fetch --no-recurse-submodules >../actual.out 2>../actual.err + ) && + ! test -s actual.out && + ! test -s actual.err +' + +test_expect_success "using fetchRecurseSubmodules=true in .gitmodules recurses into submodules" ' + ( + cd downstream && + git config -f .gitmodules submodule.submodule.fetchRecurseSubmodules true && + git fetch >../actual.out 2>../actual.err + ) +' + +test_expect_success C_LOCALE_OUTPUT "using fetchRecurseSubmodules=true in .gitmodules recurses into submodules" ' + test_cmp expect.out actual.out && + test_cmp expect.err actual.err +' + +test_expect_success "--no-recurse-submodules overrides .gitmodules config" ' + add_upstream_commit && + ( + cd downstream && + git fetch --no-recurse-submodules >../actual.out 2>../actual.err + ) && + ! test -s actual.out && + ! test -s actual.err +' + +test_expect_success "using fetchRecurseSubmodules=false in .git/config overrides setting in .gitmodules" ' + ( + cd downstream && + git config submodule.submodule.fetchRecurseSubmodules false && + git fetch >../actual.out 2>../actual.err + ) && + ! test -s actual.out && + ! test -s actual.err +' + +test_expect_success "--recurse-submodules overrides fetchRecurseSubmodules setting from .git/config" ' + ( + cd downstream && + git fetch --recurse-submodules >../actual.out 2>../actual.err && + git config --unset -f .gitmodules submodule.submodule.fetchRecurseSubmodules && + git config --unset submodule.submodule.fetchRecurseSubmodules + ) +' + +test_expect_success C_LOCALE_OUTPUT "--recurse-submodules overrides fetchRecurseSubmodules setting from .git/config: output" ' + test_cmp expect.out actual.out && + test_cmp expect.err actual.err +' + +test_expect_success "--quiet propagates to submodules" ' + ( + cd downstream && + git fetch --recurse-submodules --quiet >../actual.out 2>../actual.err + ) && + ! test -s actual.out && + ! test -s actual.err +' + +test_expect_success "--dry-run propagates to submodules" ' + add_upstream_commit && + ( + cd downstream && + git fetch --recurse-submodules --dry-run >../actual.out 2>../actual.err + ) +' + +test_expect_success C_LOCALE_OUTPUT "--dry-run propagates to submodules: output" ' + test_cmp expect.out actual.out && + test_cmp expect.err actual.err +' + +test_expect_success "Without --dry-run propagates to submodules" ' + ( + cd downstream && + git fetch --recurse-submodules >../actual.out 2>../actual.err + ) +' + +test_expect_success C_LOCALE_OUTPUT "Without --dry-run propagates to submodules: output" ' + test_cmp expect.out actual.out && + test_cmp expect.err actual.err +' + +test_expect_success "recurseSubmodules=true propagates into submodules" ' + add_upstream_commit && + ( + cd downstream && + git config fetch.recurseSubmodules true + git fetch >../actual.out 2>../actual.err + ) +' + +test_expect_success C_LOCALE_OUTPUT "recurseSubmodules=true propagates into submodules: output" ' + test_cmp expect.out actual.out && + test_cmp expect.err actual.err +' + +test_expect_success "--recurse-submodules overrides config in submodule" ' + add_upstream_commit && + ( + cd downstream && + ( + cd submodule && + git config fetch.recurseSubmodules false + ) && + git fetch --recurse-submodules >../actual.out 2>../actual.err + ) +' + +test_expect_success C_LOCALE_OUTPUT "--recurse-submodules overrides config in submodule: output" ' + test_cmp expect.out actual.out && + test_cmp expect.err actual.err +' + +test_expect_success "--no-recurse-submodules overrides config setting" ' + add_upstream_commit && + ( + cd downstream && + git config fetch.recurseSubmodules true + git fetch --no-recurse-submodules >../actual.out 2>../actual.err + ) && + ! test -s actual.out && + ! test -s actual.err +' + +test_expect_success "Recursion doesn't happen when no new commits are fetched in the superproject" ' + ( + cd downstream && + ( + cd submodule && + git config --unset fetch.recurseSubmodules + ) && + git config --unset fetch.recurseSubmodules + git fetch >../actual.out 2>../actual.err + ) && + ! test -s actual.out && + ! test -s actual.err +' + +test_expect_success "Recursion stops when no new submodule commits are fetched" ' + head1=$(git rev-parse --short HEAD) && + git add submodule && + git commit -m "new submodule" && + head2=$(git rev-parse --short HEAD) && + echo "Fetching submodule submodule" > expect.out.sub && + echo "From $pwd/." > expect.err.sub && + echo " $head1..$head2 master -> origin/master" >> expect.err.sub + head -2 expect.err >> expect.err.sub && + ( + cd downstream && + git fetch >../actual.out 2>../actual.err + ) && + test_cmp expect.err.sub actual.err && + test_cmp expect.out.sub actual.out +' + +test_expect_success "Recursion doesn't happen when new superproject commits don't change any submodules" ' + add_upstream_commit && + head1=$(git rev-parse --short HEAD) && + echo a > file && + git add file && + git commit -m "new file" && + head2=$(git rev-parse --short HEAD) && + echo "From $pwd/." > expect.err.file && + echo " $head1..$head2 master -> origin/master" >> expect.err.file && + ( + cd downstream && + git fetch >../actual.out 2>../actual.err + ) && + ! test -s actual.out && + test_cmp expect.err.file actual.err +' + +test_expect_success "Recursion picks up config in submodule" ' + ( + cd downstream && + git fetch --recurse-submodules && + ( + cd submodule && + git config fetch.recurseSubmodules true + ) + ) && + add_upstream_commit && + head1=$(git rev-parse --short HEAD) && + git add submodule && + git commit -m "new submodule" && + head2=$(git rev-parse --short HEAD) && + echo "From $pwd/." > expect.err.sub && + echo " $head1..$head2 master -> origin/master" >> expect.err.sub && + cat expect.err >> expect.err.sub && + ( + cd downstream && + git fetch >../actual.out 2>../actual.err && + ( + cd submodule && + git config --unset fetch.recurseSubmodules + ) + ) && + test_cmp expect.err.sub actual.err && + test_cmp expect.out actual.out +' + +test_expect_success "Recursion picks up all submodules when necessary" ' + add_upstream_commit && + ( + cd submodule && + ( + cd deepsubmodule && + git fetch && + git checkout -q FETCH_HEAD + ) && + head1=$(git rev-parse --short HEAD^) && + git add deepsubmodule && + git commit -m "new deepsubmodule" + head2=$(git rev-parse --short HEAD) && + echo "From $pwd/submodule" > ../expect.err.sub && + echo " $head1..$head2 master -> origin/master" >> ../expect.err.sub + ) && + head1=$(git rev-parse --short HEAD) && + git add submodule && + git commit -m "new submodule" && + head2=$(git rev-parse --short HEAD) && + echo "From $pwd/." > expect.err.2 && + echo " $head1..$head2 master -> origin/master" >> expect.err.2 && + cat expect.err.sub >> expect.err.2 && + tail -2 expect.err >> expect.err.2 && + ( + cd downstream && + git fetch >../actual.out 2>../actual.err + ) && + test_cmp expect.err.2 actual.err && + test_cmp expect.out actual.out +' + +test_expect_success "'--recurse-submodules=on-demand' doesn't recurse when no new commits are fetched in the superproject (and ignores config)" ' + add_upstream_commit && + ( + cd submodule && + ( + cd deepsubmodule && + git fetch && + git checkout -q FETCH_HEAD + ) && + head1=$(git rev-parse --short HEAD^) && + git add deepsubmodule && + git commit -m "new deepsubmodule" + head2=$(git rev-parse --short HEAD) && + echo "From $pwd/submodule" > ../expect.err.sub && + echo " $head1..$head2 master -> origin/master" >> ../expect.err.sub + ) && + ( + cd downstream && + git config fetch.recurseSubmodules true && + git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err && + git config --unset fetch.recurseSubmodules + ) && + ! test -s actual.out && + ! test -s actual.err +' + +test_expect_success "'--recurse-submodules=on-demand' recurses as deep as necessary (and ignores config)" ' + head1=$(git rev-parse --short HEAD) && + git add submodule && + git commit -m "new submodule" && + head2=$(git rev-parse --short HEAD) && + tail -2 expect.err > expect.err.deepsub && + echo "From $pwd/." > expect.err && + echo " $head1..$head2 master -> origin/master" >> expect.err + cat expect.err.sub >> expect.err && + cat expect.err.deepsub >> expect.err && + ( + cd downstream && + git config fetch.recurseSubmodules false && + ( + cd submodule && + git config -f .gitmodules submodule.deepsubmodule.fetchRecursive false + ) && + git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err && + git config --unset fetch.recurseSubmodules + ( + cd submodule && + git config --unset -f .gitmodules submodule.deepsubmodule.fetchRecursive + ) + ) && + test_cmp expect.out actual.out && + test_cmp expect.err actual.err +' + +test_expect_success "'--recurse-submodules=on-demand' stops when no new submodule commits are found in the superproject (and ignores config)" ' + add_upstream_commit && + head1=$(git rev-parse --short HEAD) && + echo a >> file && + git add file && + git commit -m "new file" && + head2=$(git rev-parse --short HEAD) && + echo "From $pwd/." > expect.err.file && + echo " $head1..$head2 master -> origin/master" >> expect.err.file && + ( + cd downstream && + git fetch --recurse-submodules=on-demand >../actual.out 2>../actual.err + ) && + ! test -s actual.out && + test_cmp expect.err.file actual.err +' + +test_expect_success "'fetch.recurseSubmodules=on-demand' overrides global config" ' + ( + cd downstream && + git fetch --recurse-submodules + ) && + add_upstream_commit && + git config --global fetch.recurseSubmodules false && + head1=$(git rev-parse --short HEAD) && + git add submodule && + git commit -m "new submodule" && + head2=$(git rev-parse --short HEAD) && + echo "From $pwd/." > expect.err.2 && + echo " $head1..$head2 master -> origin/master" >> expect.err.2 + head -2 expect.err >> expect.err.2 && + ( + cd downstream && + git config fetch.recurseSubmodules on-demand && + git fetch >../actual.out 2>../actual.err + ) && + git config --global --unset fetch.recurseSubmodules && + ( + cd downstream && + git config --unset fetch.recurseSubmodules + ) && + test_cmp expect.out.sub actual.out && + test_cmp expect.err.2 actual.err +' + +test_expect_success "'submodule.<sub>.fetchRecurseSubmodules=on-demand' overrides fetch.recurseSubmodules" ' + ( + cd downstream && + git fetch --recurse-submodules + ) && + add_upstream_commit && + git config fetch.recurseSubmodules false && + head1=$(git rev-parse --short HEAD) && + git add submodule && + git commit -m "new submodule" && + head2=$(git rev-parse --short HEAD) && + echo "From $pwd/." > expect.err.2 && + echo " $head1..$head2 master -> origin/master" >> expect.err.2 + head -2 expect.err >> expect.err.2 && + ( + cd downstream && + git config submodule.submodule.fetchRecurseSubmodules on-demand && + git fetch >../actual.out 2>../actual.err + ) && + git config --unset fetch.recurseSubmodules && + ( + cd downstream && + git config --unset submodule.submodule.fetchRecurseSubmodules + ) && + test_cmp expect.out.sub actual.out && + test_cmp expect.err.2 actual.err +' + +test_expect_success "don't fetch submodule when newly recorded commits are already present" ' + ( + cd submodule && + git checkout -q HEAD^^ + ) && + head1=$(git rev-parse --short HEAD) && + git add submodule && + git commit -m "submodule rewound" && + head2=$(git rev-parse --short HEAD) && + echo "From $pwd/." > expect.err && + echo " $head1..$head2 master -> origin/master" >> expect.err && + ( + cd downstream && + git fetch >../actual.out 2>../actual.err + ) && + ! test -s actual.out && + test_cmp expect.err actual.err +' + +test_done diff --git a/t/t5531-deep-submodule-push.sh b/t/t5531-deep-submodule-push.sh index 65d8d474bc..faa2e96337 100755 --- a/t/t5531-deep-submodule-push.sh +++ b/t/t5531-deep-submodule-push.sh @@ -6,7 +6,7 @@ test_description='unpack-objects' test_expect_success setup ' mkdir pub.git && - GIT_DIR=pub.git git init --bare + GIT_DIR=pub.git git init --bare && GIT_DIR=pub.git git config receive.fsckobjects true && mkdir work && ( diff --git a/t/t5541-http-push.sh b/t/t5541-http-push.sh index b0c2a2c3ae..0492877d51 100755 --- a/t/t5541-http-push.sh +++ b/t/t5541-http-push.sh @@ -128,11 +128,14 @@ test_expect_success 'push fails for non-fast-forward refs unmatched by remote he # push master too; this ensures there is at least one '"'push'"' command to # the remote helper and triggers interaction with the helper. - test_must_fail git push -v origin +master master:retsam >output 2>&1 && + test_must_fail git push -v origin +master master:retsam >output 2>&1' +test_expect_success 'push fails for non-fast-forward refs unmatched by remote helper: remote output' ' grep "^ + [a-f0-9]*\.\.\.[a-f0-9]* *master -> master (forced update)$" output && - grep "^ ! \[rejected\] *master -> retsam (non-fast-forward)$" output && + grep "^ ! \[rejected\] *master -> retsam (non-fast-forward)$" output +' +test_expect_success C_LOCALE_OUTPUT 'push fails for non-fast-forward refs unmatched by remote helper: our output' ' grep "To prevent you from losing history, non-fast-forward updates were rejected" \ output ' diff --git a/t/t5550-http-fetch.sh b/t/t5550-http-fetch.sh index 2fb48d09ed..a1883ca6b6 100755 --- a/t/t5550-http-fetch.sh +++ b/t/t5550-http-fetch.sh @@ -30,18 +30,37 @@ test_expect_success 'create http-accessible bare repository' ' ' test_expect_success 'clone http repository' ' - git clone $HTTPD_URL/dumb/repo.git clone && + git clone $HTTPD_URL/dumb/repo.git clone-tmpl && + cp -R clone-tmpl clone && test_cmp file clone/file ' +test_expect_success 'clone http repository with authentication' ' + mkdir "$HTTPD_DOCUMENT_ROOT_PATH/auth/" && + cp -Rf "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" "$HTTPD_DOCUMENT_ROOT_PATH/auth/repo.git" && + git clone $AUTH_HTTPD_URL/auth/repo.git clone-auth && + test_cmp file clone-auth/file +' + test_expect_success 'fetch changes via http' ' echo content >>file && git commit -a -m two && - git push public + git push public && (cd clone && git pull) && test_cmp file clone/file ' +test_expect_success 'fetch changes via manual http-fetch' ' + cp -R clone-tmpl clone2 && + + HEAD=$(git rev-parse --verify HEAD) && + (cd clone2 && + git http-fetch -a -w heads/master-new $HEAD $(git config remote.origin.url) && + git checkout master-new && + test $HEAD = $(git rev-parse --verify HEAD)) && + test_cmp file clone2/file +' + test_expect_success 'http remote detects correct HEAD' ' git push public master:other && (cd clone && diff --git a/t/t5551-http-fetch.sh b/t/t5551-http-fetch.sh index fd19121372..26d355725f 100755 --- a/t/t5551-http-fetch.sh +++ b/t/t5551-http-fetch.sh @@ -101,5 +101,13 @@ test_expect_success 'used upload-pack service' ' test_cmp exp act ' +test_expect_success 'follow redirects (301)' ' + git clone $HTTPD_URL/smart-redir-perm/repo.git --quiet repo-p +' + +test_expect_success 'follow redirects (302)' ' + git clone $HTTPD_URL/smart-redir-temp/repo.git --quiet repo-t +' + stop_httpd test_done diff --git a/t/t5560-http-backend-noserver.sh b/t/t5560-http-backend-noserver.sh index 44885b850c..0ad7ce07c4 100755 --- a/t/t5560-http-backend-noserver.sh +++ b/t/t5560-http-backend-noserver.sh @@ -5,16 +5,17 @@ test_description='test git-http-backend-noserver' HTTPD_DOCUMENT_ROOT_PATH="$TRASH_DIRECTORY" +test_have_prereq MINGW && export GREP_OPTIONS=-U + run_backend() { echo "$2" | QUERY_STRING="${1#*\?}" \ - GIT_PROJECT_ROOT="$HTTPD_DOCUMENT_ROOT_PATH" \ - PATH_INFO="${1%%\?*}" \ + PATH_TRANSLATED="$HTTPD_DOCUMENT_ROOT_PATH/${1%%\?*}" \ git http-backend >act.out 2>act.err } GET() { - export REQUEST_METHOD="GET" && + REQUEST_METHOD="GET" && export REQUEST_METHOD && run_backend "/repo.git/$1" && unset REQUEST_METHOD && if ! grep "Status" act.out >act @@ -26,8 +27,8 @@ GET() { } POST() { - export REQUEST_METHOD="POST" && - export CONTENT_TYPE="application/x-$1-request" && + REQUEST_METHOD="POST" && export REQUEST_METHOD && + CONTENT_TYPE="application/x-$1-request" && export CONTENT_TYPE && run_backend "/repo.git/$1" "$2" && unset REQUEST_METHOD && unset CONTENT_TYPE && @@ -46,7 +47,7 @@ log_div() { . "$TEST_DIRECTORY"/t556x_common expect_aliased() { - export REQUEST_METHOD="GET" && + REQUEST_METHOD="GET" && export REQUEST_METHOD && if test $1 = 0; then run_backend "$2" else diff --git a/t/t556x_common b/t/t556x_common index be024e551c..82926cfdb7 100755 --- a/t/t556x_common +++ b/t/t556x_common @@ -50,72 +50,72 @@ get_static_files() { } SMART=smart -export GIT_HTTP_EXPORT_ALL=1 +GIT_HTTP_EXPORT_ALL=1 && export GIT_HTTP_EXPORT_ALL test_expect_success 'direct refs/heads/master not found' ' - log_div "refs/heads/master" + log_div "refs/heads/master" && GET refs/heads/master "404 Not Found" ' test_expect_success 'static file is ok' ' - log_div "getanyfile default" + log_div "getanyfile default" && get_static_files "200 OK" ' SMART=smart_noexport unset GIT_HTTP_EXPORT_ALL test_expect_success 'no export by default' ' - log_div "no git-daemon-export-ok" + log_div "no git-daemon-export-ok" && get_static_files "404 Not Found" ' test_expect_success 'export if git-daemon-export-ok' ' - log_div "git-daemon-export-ok" + log_div "git-daemon-export-ok" && (cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && touch git-daemon-export-ok ) && get_static_files "200 OK" ' SMART=smart -export GIT_HTTP_EXPORT_ALL=1 +GIT_HTTP_EXPORT_ALL=1 && export GIT_HTTP_EXPORT_ALL test_expect_success 'static file if http.getanyfile true is ok' ' - log_div "getanyfile true" + log_div "getanyfile true" && config http.getanyfile true && get_static_files "200 OK" ' test_expect_success 'static file if http.getanyfile false fails' ' - log_div "getanyfile false" + log_div "getanyfile false" && config http.getanyfile false && get_static_files "403 Forbidden" ' test_expect_success 'http.uploadpack default enabled' ' - log_div "uploadpack default" + log_div "uploadpack default" && GET info/refs?service=git-upload-pack "200 OK" && POST git-upload-pack 0000 "200 OK" ' test_expect_success 'http.uploadpack true' ' - log_div "uploadpack true" + log_div "uploadpack true" && config http.uploadpack true && GET info/refs?service=git-upload-pack "200 OK" && POST git-upload-pack 0000 "200 OK" ' test_expect_success 'http.uploadpack false' ' - log_div "uploadpack false" + log_div "uploadpack false" && config http.uploadpack false && GET info/refs?service=git-upload-pack "403 Forbidden" && POST git-upload-pack 0000 "403 Forbidden" ' test_expect_success 'http.receivepack default disabled' ' - log_div "receivepack default" + log_div "receivepack default" && GET info/refs?service=git-receive-pack "403 Forbidden" && POST git-receive-pack 0000 "403 Forbidden" ' test_expect_success 'http.receivepack true' ' - log_div "receivepack true" + log_div "receivepack true" && config http.receivepack true && GET info/refs?service=git-receive-pack "200 OK" && POST git-receive-pack 0000 "200 OK" ' test_expect_success 'http.receivepack false' ' - log_div "receivepack false" + log_div "receivepack false" && config http.receivepack false && GET info/refs?service=git-receive-pack "403 Forbidden" && POST git-receive-pack 0000 "403 Forbidden" diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh index 987e0c8463..5a068b21e4 100755 --- a/t/t5601-clone.sh +++ b/t/t5601-clone.sh @@ -31,7 +31,7 @@ test_expect_success 'clone with excess parameters (2)' ' ' -test_expect_success 'output from clone' ' +test_expect_success C_LOCALE_OUTPUT 'output from clone' ' rm -fr dst && git clone -n "file://$(pwd)/src" dst >output && test $(grep Clon output | wc -l) = 1 @@ -164,7 +164,6 @@ test_expect_success 'clone a void' ' test_expect_success 'clone respects global branch.autosetuprebase' ' ( test_config="$HOME/.gitconfig" && - unset GIT_CONFIG_NOGLOBAL && git config -f "$test_config" branch.autosetuprebase remote && rm -fr dst && git clone src dst && @@ -192,4 +191,17 @@ test_expect_success 'do not respect url-encoding of non-url path' ' git clone x+y xy-regular ' +test_expect_success 'clone separate gitdir' ' + rm -rf dst && + git clone --separate-git-dir realgitdir src dst && + echo "gitdir: `pwd`/realgitdir" >expected && + test_cmp expected dst/.git && + test -d realgitdir/refs +' + +test_expect_success 'clone separate gitdir where target already exists' ' + rm -rf dst && + test_must_fail git clone --separate-git-dir realgitdir src dst +' + test_done diff --git a/t/t5602-clone-remote-exec.sh b/t/t5602-clone-remote-exec.sh index deffdaee49..3f353d99e8 100755 --- a/t/t5602-clone-remote-exec.sh +++ b/t/t5602-clone-remote-exec.sh @@ -5,21 +5,29 @@ test_description=clone . ./test-lib.sh test_expect_success setup ' - echo "#!/bin/sh" > not_ssh - echo "echo \"\$*\" > not_ssh_output" >> not_ssh - echo "exit 1" >> not_ssh + echo "#!/bin/sh" > not_ssh && + echo "echo \"\$*\" > not_ssh_output" >> not_ssh && + echo "exit 1" >> not_ssh && chmod +x not_ssh ' test_expect_success 'clone calls git upload-pack unqualified with no -u option' ' - GIT_SSH=./not_ssh git clone localhost:/path/to/repo junk - echo "localhost git-upload-pack '\''/path/to/repo'\''" >expected + ( + GIT_SSH=./not_ssh && + export GIT_SSH && + test_must_fail 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 git clone -u ./something/bin/git-upload-pack localhost:/path/to/repo junk - echo "localhost ./something/bin/git-upload-pack '\''/path/to/repo'\''" >expected + ( + GIT_SSH=./not_ssh && + export GIT_SSH && + test_must_fail 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 8b4c356cd2..6972258b27 100755 --- a/t/t5701-clone-local.sh +++ b/t/t5701-clone-local.sh @@ -10,11 +10,11 @@ test_expect_success 'preparing origin repository' ' git clone --bare . a.git && git clone --bare . x && test "$(GIT_CONFIG=a.git/config git config --bool core.bare)" = true && - test "$(GIT_CONFIG=x/config git config --bool core.bare)" = true + test "$(GIT_CONFIG=x/config git config --bool core.bare)" = true && git bundle create b1.bundle --all && git bundle create b2.bundle master && mkdir dir && - cp b1.bundle dir/b3 + cp b1.bundle dir/b3 && cp b1.bundle b4 ' @@ -112,7 +112,7 @@ test_expect_success 'bundle clone with nonexistent HEAD' ' cd "$D" && git clone b2.bundle b2 && cd b2 && - git fetch + git fetch && test ! -e .git/refs/heads/master ' @@ -144,4 +144,17 @@ test_expect_success 'clone empty repository, and then push should not segfault.' test_must_fail git push) ' +test_expect_success 'cloning non-existent directory fails' ' + cd "$D" && + rm -rf does-not-exist && + test_must_fail git clone does-not-exist +' + +test_expect_success 'cloning non-git directory fails' ' + cd "$D" && + rm -rf not-a-git-repo not-a-git-repo-clone && + mkdir not-a-git-repo && + test_must_fail git clone not-a-git-repo not-a-git-repo-clone +' + test_done diff --git a/t/t6000-rev-list-misc.sh b/t/t6000-rev-list-misc.sh new file mode 100755 index 0000000000..b10685af4e --- /dev/null +++ b/t/t6000-rev-list-misc.sh @@ -0,0 +1,51 @@ +#!/bin/sh + +test_description='miscellaneous rev-list tests' + +. ./test-lib.sh + +test_expect_success setup ' + echo content1 >wanted_file && + echo content2 >unwanted_file && + git add wanted_file unwanted_file && + git commit -m one +' + +test_expect_success 'rev-list --objects heeds pathspecs' ' + git rev-list --objects HEAD -- wanted_file >output && + grep wanted_file output && + ! grep unwanted_file output +' + +test_expect_success 'rev-list --objects with pathspecs and deeper paths' ' + mkdir foo && + >foo/file && + git add foo/file && + git commit -m two && + + git rev-list --objects HEAD -- foo >output && + grep foo/file output && + + git rev-list --objects HEAD -- foo/file >output && + grep foo/file output && + ! grep unwanted_file output +' + +test_expect_success 'rev-list --objects with pathspecs and copied files' ' + git checkout --orphan junio-testcase && + git rm -rf . && + + mkdir two && + echo frotz >one && + cp one two/three && + git add one two/three && + test_tick && + git commit -m that && + + ONE=$(git rev-parse HEAD:one) + git rev-list --objects HEAD two >output && + grep "$ONE two/three" output && + ! grep one output +' + +test_done diff --git a/t/t6001-rev-list-graft.sh b/t/t6001-rev-list-graft.sh index fc57e7d3fd..8efcd13079 100755 --- a/t/t6001-rev-list-graft.sh +++ b/t/t6001-rev-list-graft.sh @@ -90,22 +90,22 @@ check () { for type in basic parents parents-raw do test_expect_success 'without grafts' " - rm -f .git/info/grafts + rm -f .git/info/grafts && check $type $B2 -- $B2 $B1 $B0 " test_expect_success 'with grafts' " - echo '$B0 $A2' >.git/info/grafts + echo '$B0 $A2' >.git/info/grafts && check $type $B2 -- $B2 $B1 $B0 $A2 $A1 $A0 " test_expect_success 'without grafts, with pathlimit' " - rm -f .git/info/grafts + rm -f .git/info/grafts && check $type $B2 subdir -- $B2 $B0 " test_expect_success 'with grafts, with pathlimit' " - echo '$B0 $A2' >.git/info/grafts + echo '$B0 $A2' >.git/info/grafts && check $type $B2 subdir -- $B2 $B0 $A2 $A0 " diff --git a/t/t6004-rev-list-path-optim.sh b/t/t6004-rev-list-path-optim.sh index 5dabf1c5e3..3e8c42ee0b 100755 --- a/t/t6004-rev-list-path-optim.sh +++ b/t/t6004-rev-list-path-optim.sh @@ -1,51 +1,96 @@ #!/bin/sh -test_description='git rev-list trivial path optimization test' +test_description='git rev-list trivial path optimization test + + d/z1 + b0 b1 + o------------------------*----o master + / / + o---------o----o----o----o side + a0 c0 c1 a1 c2 + d/f0 d/f1 + d/z0 + +' . ./test-lib.sh test_expect_success setup ' -echo Hello > a && -git add a && -git commit -m "Initial commit" a && -initial=$(git rev-parse --verify HEAD) + echo Hello >a && + mkdir d && + echo World >d/f && + echo World >d/z && + git add a d && + test_tick && + git commit -m "Initial commit" && + git rev-parse --verify HEAD && + git tag initial ' test_expect_success path-optimization ' - commit=$(echo "Unchanged tree" | git commit-tree "HEAD^{tree}" -p HEAD) && - test $(git rev-list $commit | wc -l) = 2 && - test $(git rev-list $commit -- . | wc -l) = 1 + test_tick && + commit=$(echo "Unchanged tree" | git commit-tree "HEAD^{tree}" -p HEAD) && + test $(git rev-list $commit | wc -l) = 2 && + test $(git rev-list $commit -- . | wc -l) = 1 ' test_expect_success 'further setup' ' git checkout -b side && echo Irrelevant >c && - git add c && + echo Irrelevant >d/f && + git add c d/f && + test_tick && git commit -m "Side makes an irrelevant commit" && + git tag side_c0 && echo "More Irrelevancy" >c && git add c && + test_tick && git commit -m "Side makes another irrelevant commit" && echo Bye >a && git add a && + test_tick && git commit -m "Side touches a" && - side=$(git rev-parse --verify HEAD) && + git tag side_a1 && echo "Yet more Irrelevancy" >c && git add c && + test_tick && git commit -m "Side makes yet another irrelevant commit" && git checkout master && echo Another >b && - git add b && + echo Munged >d/z && + git add b d/z && + test_tick && git commit -m "Master touches b" && + git tag master_b0 && git merge side && echo Touched >b && git add b && + test_tick && git commit -m "Master touches b again" ' test_expect_success 'path optimization 2' ' - ( echo "$side"; echo "$initial" ) >expected && + git rev-parse side_a1 initial >expected && git rev-list HEAD -- a >actual && test_cmp expected actual ' +test_expect_success 'pathspec with leading path' ' + git rev-parse master^ master_b0 side_c0 initial >expected && + git rev-list HEAD -- d >actual && + test_cmp expected actual +' + +test_expect_success 'pathspec with glob (1)' ' + git rev-parse master^ master_b0 side_c0 initial >expected && + git rev-list HEAD -- "d/*" >actual && + test_cmp expected actual +' + +test_expect_success 'pathspec with glob (2)' ' + git rev-parse side_c0 initial >expected && + git rev-list HEAD -- "d/[a-m]*" >actual && + test_cmp expected actual +' + test_done diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh index cccacd4add..d918cc02d0 100755 --- a/t/t6006-rev-list-format.sh +++ b/t/t6006-rev-list-format.sh @@ -162,6 +162,14 @@ commit 131a310eb913d107dd3c09a65d1651175898735d commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 EOF +test_expect_success '%x00 shows NUL' ' + echo >expect commit f58db70b055c5718631e5c61528b28b12090cdea && + echo >>expect fooQbar && + git rev-list -1 --format=foo%x00bar HEAD >actual.nul && + nul_to_q <actual.nul >actual && + test_cmp expect actual +' + test_expect_success '%ad respects --date=' ' echo 2005-04-07 >expect.ad-short && git log -1 --date=short --pretty=tformat:%ad >output.ad-short master && diff --git a/t/t6007-rev-list-cherry-pick-file.sh b/t/t6007-rev-list-cherry-pick-file.sh index b565638e92..cacf3de6c9 100755 --- a/t/t6007-rev-list-cherry-pick-file.sh +++ b/t/t6007-rev-list-cherry-pick-file.sh @@ -4,13 +4,14 @@ test_description='test git rev-list --cherry-pick -- file' . ./test-lib.sh -# A---B +# A---B---D---F # \ # \ -# C +# C---E # # B changes a file foo.c, adding a line of text. C changes foo.c as # well as bar.c, but the change in foo.c was identical to change B. +# D and C change bar in the same way, E and F differently. test_expect_success setup ' echo Hallo > foo && @@ -25,11 +26,26 @@ test_expect_success setup ' test_tick && git commit -m "C" && git tag C && + echo Dello > bar && + git add bar && + test_tick && + git commit -m "E" && + git tag E && git checkout master && git checkout branch foo && test_tick && git commit -m "B" && - git tag B + git tag B && + echo Cello > bar && + git add bar && + test_tick && + git commit -m "D" && + git tag D && + echo Nello > bar && + git add bar && + test_tick && + git commit -m "F" && + git tag F ' cat >expect <<EOF @@ -53,8 +69,92 @@ test_expect_success '--cherry-pick foo comes up empty' ' test -z "$(git rev-list --left-right --cherry-pick B...C -- foo)" ' +cat >expect <<EOF +>tags/C +EOF + test_expect_success '--cherry-pick bar does not come up empty' ' - ! test -z "$(git rev-list --left-right --cherry-pick B...C -- bar)" + git rev-list --left-right --cherry-pick B...C -- bar > actual && + git name-rev --stdin --name-only --refs="*tags/*" \ + < actual > actual.named && + test_cmp actual.named expect +' + +test_expect_success 'bar does not come up empty' ' + git rev-list --left-right B...C -- bar > actual && + git name-rev --stdin --name-only --refs="*tags/*" \ + < actual > actual.named && + test_cmp actual.named expect +' + +cat >expect <<EOF +<tags/F +>tags/E +EOF + +test_expect_success '--cherry-pick bar does not come up empty (II)' ' + git rev-list --left-right --cherry-pick F...E -- bar > actual && + git name-rev --stdin --name-only --refs="*tags/*" \ + < actual > actual.named && + test_cmp actual.named expect +' + +cat >expect <<EOF ++tags/F +=tags/D ++tags/E +=tags/C +EOF + +test_expect_success '--cherry-mark' ' + git rev-list --cherry-mark F...E -- bar > actual && + git name-rev --stdin --name-only --refs="*tags/*" \ + < actual > actual.named && + test_cmp actual.named expect +' + +cat >expect <<EOF +<tags/F +=tags/D +>tags/E +=tags/C +EOF + +test_expect_success '--cherry-mark --left-right' ' + git rev-list --cherry-mark --left-right F...E -- bar > actual && + git name-rev --stdin --name-only --refs="*tags/*" \ + < actual > actual.named && + test_cmp actual.named expect +' + +cat >expect <<EOF +tags/E +EOF + +test_expect_success '--cherry-pick --right-only' ' + git rev-list --cherry-pick --right-only F...E -- bar > actual && + git name-rev --stdin --name-only --refs="*tags/*" \ + < actual > actual.named && + test_cmp actual.named expect +' + +test_expect_success '--cherry-pick --left-only' ' + git rev-list --cherry-pick --left-only E...F -- bar > actual && + git name-rev --stdin --name-only --refs="*tags/*" \ + < actual > actual.named && + test_cmp actual.named expect +' + +cat >expect <<EOF ++tags/E +=tags/C +EOF + +test_expect_success '--cherry' ' + git rev-list --cherry F...E -- bar > actual && + git name-rev --stdin --name-only --refs="*tags/*" \ + < actual > actual.named && + test_cmp actual.named expect ' test_expect_success '--cherry-pick with independent, but identical branches' ' @@ -75,11 +175,8 @@ cat >expect <<EOF 1 2 EOF -# Insert an extra commit to break the symmetry test_expect_success '--count --left-right' ' - git checkout branch && - test_commit D && - git rev-list --count --left-right B...D > actual && + git rev-list --count --left-right C...D > actual && test_cmp expect actual ' diff --git a/t/t6009-rev-list-parent.sh b/t/t6009-rev-list-parent.sh index c8a96a9a99..30507407ff 100755 --- a/t/t6009-rev-list-parent.sh +++ b/t/t6009-rev-list-parent.sh @@ -1,14 +1,15 @@ #!/bin/sh -test_description='properly cull all ancestors' +test_description='ancestor culling and limiting by parent number' . ./test-lib.sh -commit () { - test_tick && - echo $1 >file && - git commit -a -m $1 && - git tag $1 +check_revlist () { + rev_list_args="$1" && + shift && + git rev-parse "$@" >expect && + git rev-list $rev_list_args --all >actual && + test_cmp expect actual } test_expect_success setup ' @@ -16,13 +17,13 @@ test_expect_success setup ' touch file && git add file && - commit one && + test_commit one && - test_tick=$(($test_tick - 2400)) + test_tick=$(($test_tick - 2400)) && - commit two && - commit three && - commit four && + test_commit two && + test_commit three && + test_commit four && git log --pretty=oneline --abbrev-commit ' @@ -35,4 +36,101 @@ test_expect_success 'one is ancestor of others and should not be shown' ' ' +test_expect_success 'setup roots, merges and octopuses' ' + + git checkout --orphan newroot && + test_commit five && + git checkout -b sidebranch two && + test_commit six && + git checkout -b anotherbranch three && + test_commit seven && + git checkout -b yetanotherbranch four && + test_commit eight && + git checkout master && + test_merge normalmerge newroot && + test_tick && + git merge -m tripus sidebranch anotherbranch && + git tag tripus && + git checkout -b tetrabranch normalmerge && + test_tick && + git merge -m tetrapus sidebranch anotherbranch yetanotherbranch && + git tag tetrapus && + git checkout master +' + +test_expect_success 'rev-list roots' ' + + check_revlist "--max-parents=0" one five +' + +test_expect_success 'rev-list no merges' ' + + check_revlist "--max-parents=1" one eight seven six five four three two && + check_revlist "--no-merges" one eight seven six five four three two +' + +test_expect_success 'rev-list no octopuses' ' + + check_revlist "--max-parents=2" one normalmerge eight seven six five four three two +' + +test_expect_success 'rev-list no roots' ' + + check_revlist "--min-parents=1" tetrapus tripus normalmerge eight seven six four three two +' + +test_expect_success 'rev-list merges' ' + + check_revlist "--min-parents=2" tetrapus tripus normalmerge && + check_revlist "--merges" tetrapus tripus normalmerge +' + +test_expect_success 'rev-list octopus' ' + + check_revlist "--min-parents=3" tetrapus tripus +' + +test_expect_success 'rev-list ordinary commits' ' + + check_revlist "--min-parents=1 --max-parents=1" eight seven six four three two +' + +test_expect_success 'rev-list --merges --no-merges yields empty set' ' + + check_revlist "--min-parents=2 --no-merges" && + check_revlist "--merges --no-merges" && + check_revlist "--no-merges --merges" +' + +test_expect_success 'rev-list override and infinities' ' + + check_revlist "--min-parents=2 --max-parents=1 --max-parents=3" tripus normalmerge && + check_revlist "--min-parents=1 --min-parents=2 --max-parents=7" tetrapus tripus normalmerge && + check_revlist "--min-parents=2 --max-parents=8" tetrapus tripus normalmerge && + check_revlist "--min-parents=2 --max-parents=-1" tetrapus tripus normalmerge && + check_revlist "--min-parents=2 --no-max-parents" tetrapus tripus normalmerge && + check_revlist "--max-parents=0 --min-parents=1 --no-min-parents" one five +' + +test_expect_success 'dodecapus' ' + + roots= && + for i in 1 2 3 4 5 6 7 8 9 10 11 + do + git checkout -b root$i five && + test_commit $i && + roots="$roots root$i" || + return + done && + git checkout master && + test_tick && + git merge -m dodecapus $roots && + git tag dodecapus && + + check_revlist "--min-parents=4" dodecapus tetrapus && + check_revlist "--min-parents=8" dodecapus && + check_revlist "--min-parents=12" dodecapus && + check_revlist "--min-parents=13" && + check_revlist "--min-parents=4 --max-parents=11" tetrapus +' test_done diff --git a/t/t6010-merge-base.sh b/t/t6010-merge-base.sh index 62197a3d35..082032edc3 100755 --- a/t/t6010-merge-base.sh +++ b/t/t6010-merge-base.sh @@ -131,7 +131,7 @@ test_expect_success 'unsynchronized clocks' ' R2=$(doit 3 R2 $R1) && PL=$(doit 4 PL $L2 $C2) && - PR=$(doit 4 PR $C2 $R2) + PR=$(doit 4 PR $C2 $R2) && git name-rev $C2 >expected && diff --git a/t/t6016-rev-list-graph-simplify-history.sh b/t/t6016-rev-list-graph-simplify-history.sh index 27fd52b7be..f7181d1d6a 100755 --- a/t/t6016-rev-list-graph-simplify-history.sh +++ b/t/t6016-rev-list-graph-simplify-history.sh @@ -29,7 +29,7 @@ test_expect_success 'set up rev-list --graph test' ' # Octopus merge B and C into branch A git checkout A && git merge B C && - git tag A4 + git tag A4 && test_commit A5 bar.txt && @@ -39,7 +39,7 @@ test_expect_success 'set up rev-list --graph test' ' test_commit C4 bar.txt && git checkout A && git merge -s ours C && - git tag A6 + git tag A6 && test_commit A7 bar.txt && @@ -90,7 +90,7 @@ test_expect_success '--graph --all' ' # that undecorated merges are interesting, even with --simplify-by-decoration test_expect_success '--graph --simplify-by-decoration' ' rm -f expected && - git tag -d A4 + git tag -d A4 && echo "* $A7" >> expected && echo "* $A6" >> expected && echo "|\\ " >> expected && @@ -116,12 +116,15 @@ test_expect_success '--graph --simplify-by-decoration' ' test_cmp expected actual ' -# Get rid of all decorations on branch B, and graph with it simplified away +test_expect_success 'setup: get rid of decorations on B' ' + git tag -d B2 && + git tag -d B1 && + git branch -d B +' + +# Graph with branch B simplified away test_expect_success '--graph --simplify-by-decoration prune branch B' ' rm -f expected && - git tag -d B2 - git tag -d B1 - git branch -d B echo "* $A7" >> expected && echo "* $A6" >> expected && echo "|\\ " >> expected && @@ -143,9 +146,6 @@ test_expect_success '--graph --simplify-by-decoration prune branch B' ' test_expect_success '--graph --full-history -- bar.txt' ' rm -f expected && - git tag -d B2 - git tag -d B1 - git branch -d B echo "* $A7" >> expected && echo "* $A6" >> expected && echo "|\\ " >> expected && @@ -163,9 +163,6 @@ test_expect_success '--graph --full-history -- bar.txt' ' test_expect_success '--graph --full-history --simplify-merges -- bar.txt' ' rm -f expected && - git tag -d B2 - git tag -d B1 - git branch -d B echo "* $A7" >> expected && echo "* $A6" >> expected && echo "|\\ " >> expected && @@ -181,9 +178,6 @@ test_expect_success '--graph --full-history --simplify-merges -- bar.txt' ' test_expect_success '--graph -- bar.txt' ' rm -f expected && - git tag -d B2 - git tag -d B1 - git branch -d B echo "* $A7" >> expected && echo "* $A5" >> expected && echo "* $A3" >> expected && @@ -196,9 +190,6 @@ test_expect_success '--graph -- bar.txt' ' test_expect_success '--graph --sparse -- bar.txt' ' rm -f expected && - git tag -d B2 - git tag -d B1 - git branch -d B echo "* $A7" >> expected && echo "* $A6" >> expected && echo "* $A5" >> expected && diff --git a/t/t6020-merge-df.sh b/t/t6020-merge-df.sh index b129f1dbd5..eec8f4e3ed 100755 --- a/t/t6020-merge-df.sh +++ b/t/t6020-merge-df.sh @@ -24,7 +24,7 @@ test_expect_success 'prepare repository' ' ' test_expect_success 'Merge with d/f conflicts' ' - test_must_fail git merge master + test_expect_code 1 git merge "merge msg" B master ' test_expect_success 'F/D conflict' ' diff --git a/t/t6022-merge-rename.sh b/t/t6022-merge-rename.sh index 7d955c1e12..5f3b604fd9 100755 --- a/t/t6022-merge-rename.sh +++ b/t/t6022-merge-rename.sh @@ -99,245 +99,147 @@ git checkout master' test_expect_success 'pull renaming branch into unrenaming one' \ ' - git show-branch - git pull . white && { - echo "BAD: should have conflicted" - return 1 - } - git ls-files -s - test "$(git ls-files -u B | wc -l)" -eq 3 || { - echo "BAD: should have left stages for B" - return 1 - } - test "$(git ls-files -s N | wc -l)" -eq 1 || { - echo "BAD: should have merged N" - return 1 - } + git show-branch && + test_expect_code 1 git pull . white && + git ls-files -s && + git ls-files -u B >b.stages && + test_line_count = 3 b.stages && + git ls-files -s N >n.stages && + test_line_count = 1 n.stages && sed -ne "/^g/{ p q - }" B | grep master || { - echo "BAD: should have listed our change first" - return 1 - } - test "$(git diff white N | wc -l)" -eq 0 || { - echo "BAD: should have taken colored branch" - return 1 - } + }" B | grep master && + git diff --exit-code white N ' test_expect_success 'pull renaming branch into another renaming one' \ ' - rm -f B - git reset --hard - git checkout red - git pull . white && { - echo "BAD: should have conflicted" - return 1 - } - test "$(git ls-files -u B | wc -l)" -eq 3 || { - echo "BAD: should have left stages" - return 1 - } - test "$(git ls-files -s N | wc -l)" -eq 1 || { - echo "BAD: should have merged N" - return 1 - } + rm -f B && + git reset --hard && + git checkout red && + test_expect_code 1 git pull . white && + git ls-files -u B >b.stages && + test_line_count = 3 b.stages && + git ls-files -s N >n.stages && + test_line_count = 1 n.stages && sed -ne "/^g/{ p q - }" B | grep red || { - echo "BAD: should have listed our change first" - return 1 - } - test "$(git diff white N | wc -l)" -eq 0 || { - echo "BAD: should have taken colored branch" - return 1 - } + }" B | grep red && + git diff --exit-code white N ' test_expect_success 'pull unrenaming branch into renaming one' \ ' - git reset --hard - git show-branch - git pull . master && { - echo "BAD: should have conflicted" - return 1 - } - test "$(git ls-files -u B | wc -l)" -eq 3 || { - echo "BAD: should have left stages" - return 1 - } - test "$(git ls-files -s N | wc -l)" -eq 1 || { - echo "BAD: should have merged N" - return 1 - } + git reset --hard && + git show-branch && + test_expect_code 1 git pull . master && + git ls-files -u B >b.stages && + test_line_count = 3 b.stages && + git ls-files -s N >n.stages && + test_line_count = 1 n.stages && sed -ne "/^g/{ p q - }" B | grep red || { - echo "BAD: should have listed our change first" - return 1 - } - test "$(git diff white N | wc -l)" -eq 0 || { - echo "BAD: should have taken colored branch" - return 1 - } + }" B | grep red && + git diff --exit-code white N ' test_expect_success 'pull conflicting renames' \ ' - git reset --hard - git show-branch - git pull . blue && { - echo "BAD: should have conflicted" - return 1 - } - test "$(git ls-files -u A | wc -l)" -eq 1 || { - echo "BAD: should have left a stage" - return 1 - } - test "$(git ls-files -u B | wc -l)" -eq 1 || { - echo "BAD: should have left a stage" - return 1 - } - test "$(git ls-files -u C | wc -l)" -eq 1 || { - echo "BAD: should have left a stage" - return 1 - } - test "$(git ls-files -s N | wc -l)" -eq 1 || { - echo "BAD: should have merged N" - return 1 - } + git reset --hard && + git show-branch && + test_expect_code 1 git pull . blue && + git ls-files -u A >a.stages && + test_line_count = 1 a.stages && + git ls-files -u B >b.stages && + test_line_count = 1 b.stages && + git ls-files -u C >c.stages && + test_line_count = 1 c.stages && + git ls-files -s N >n.stages && + test_line_count = 1 n.stages && sed -ne "/^g/{ p q - }" B | grep red || { - echo "BAD: should have listed our change first" - return 1 - } - test "$(git diff white N | wc -l)" -eq 0 || { - echo "BAD: should have taken colored branch" - return 1 - } + }" B | grep red && + git diff --exit-code white N ' test_expect_success 'interference with untracked working tree file' ' - - git reset --hard - git show-branch - echo >A this file should not matter - git pull . white && { - echo "BAD: should have conflicted" - return 1 - } - test -f A || { - echo "BAD: should have left A intact" - return 1 - } + git reset --hard && + git show-branch && + echo >A this file should not matter && + test_expect_code 1 git pull . white && + test_path_is_file A ' test_expect_success 'interference with untracked working tree file' ' - - git reset --hard - git checkout white - git show-branch - rm -f A - echo >A this file should not matter - git pull . red && { - echo "BAD: should have conflicted" - return 1 - } - test -f A || { - echo "BAD: should have left A intact" - return 1 - } + git reset --hard && + git checkout white && + git show-branch && + rm -f A && + echo >A this file should not matter && + test_expect_code 1 git pull . red && + test_path_is_file A ' test_expect_success 'interference with untracked working tree file' ' - - git reset --hard - rm -f A M - git checkout -f master - git tag -f anchor - git show-branch - git pull . yellow || { - echo "BAD: should have cleanly merged" - return 1 - } - test -f M && { - echo "BAD: should have removed M" - return 1 - } + git reset --hard && + rm -f A M && + git checkout -f master && + git tag -f anchor && + git show-branch && + git pull . yellow && + test_path_is_missing M && git reset --hard anchor ' test_expect_success 'updated working tree file should prevent the merge' ' - - git reset --hard - rm -f A M - git checkout -f master - git tag -f anchor - git show-branch - echo >>M one line addition - cat M >M.saved - git pull . yellow && { - echo "BAD: should have complained" - return 1 - } - test_cmp M M.saved || { - echo "BAD: should have left M intact" - return 1 - } + git reset --hard && + rm -f A M && + git checkout -f master && + git tag -f anchor && + git show-branch && + echo >>M one line addition && + cat M >M.saved && + test_expect_code 128 git pull . yellow && + test_cmp M M.saved && rm -f M.saved ' test_expect_success 'updated working tree file should prevent the merge' ' - - git reset --hard - rm -f A M - git checkout -f master - git tag -f anchor - git show-branch - echo >>M one line addition - cat M >M.saved - git update-index M - git pull . yellow && { - echo "BAD: should have complained" - return 1 - } - test_cmp M M.saved || { - echo "BAD: should have left M intact" - return 1 - } + git reset --hard && + rm -f A M && + git checkout -f master && + git tag -f anchor && + git show-branch && + echo >>M one line addition && + cat M >M.saved && + git update-index M && + test_expect_code 128 git pull . yellow && + test_cmp M M.saved && rm -f M.saved ' test_expect_success 'interference with untracked working tree file' ' - - git reset --hard - rm -f A M - git checkout -f yellow - git tag -f anchor - git show-branch - echo >M this file should not matter - git pull . master || { - echo "BAD: should have cleanly merged" - return 1 - } - test -f M || { - echo "BAD: should have left M intact" - return 1 - } - git ls-files -s | grep M && { - echo "BAD: M must be untracked in the result" - return 1 - } + git reset --hard && + rm -f A M && + git checkout -f yellow && + git tag -f anchor && + git show-branch && + echo >M this file should not matter && + git pull . master && + test_path_is_file M && + ! { + git ls-files -s | + grep M + } && git reset --hard anchor ' test_expect_success 'merge of identical changes in a renamed file' ' - rm -f A M N + rm -f A M N && git reset --hard && git checkout change+rename && GIT_MERGE_VERBOSITY=3 git merge change | grep "^Skipped B" && diff --git a/t/t6023-merge-file.sh b/t/t6023-merge-file.sh index d486d73994..d9f343942c 100755 --- a/t/t6023-merge-file.sh +++ b/t/t6023-merge-file.sh @@ -64,6 +64,14 @@ cp new1.txt test.txt test_expect_success "merge without conflict" \ "git merge-file test.txt orig.txt new2.txt" +test_expect_success 'works in subdirectory' ' + mkdir dir && + cp new1.txt dir/a.txt && + cp orig.txt dir/o.txt && + cp new2.txt dir/b.txt && + ( cd dir && git merge-file a.txt o.txt b.txt ) +' + cp new1.txt test.txt test_expect_success "merge without conflict (--quiet)" \ "git merge-file --quiet test.txt orig.txt new2.txt" diff --git a/t/t6024-recursive-merge.sh b/t/t6024-recursive-merge.sh index b3fbf659c0..755d30ce2a 100755 --- a/t/t6024-recursive-merge.sh +++ b/t/t6024-recursive-merge.sh @@ -104,7 +104,7 @@ test_expect_success 'mark rename/delete as unmerged' ' test_tick && git commit -m delete && git checkout -b rename HEAD^ && - git mv a1 a2 + git mv a1 a2 && test_tick && git commit -m rename && test_must_fail git merge delete && diff --git a/t/t6029-merge-subtree.sh b/t/t6029-merge-subtree.sh index 3900d9f61f..73fc240e85 100755 --- a/t/t6029-merge-subtree.sh +++ b/t/t6029-merge-subtree.sh @@ -6,7 +6,7 @@ test_description='subtree merge strategy' test_expect_success setup ' - s="1 2 3 4 5 6 7 8" + s="1 2 3 4 5 6 7 8" && for i in $s; do echo $i; done >hello && git add hello && git commit -m initial && diff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh index 3b042aacd6..b5063b6fe6 100755 --- a/t/t6030-bisect-porcelain.sh +++ b/t/t6030-bisect-porcelain.sh @@ -517,13 +517,13 @@ test_expect_success '"parallel" side branch creation' ' add_line_into_file "2(para): line 2 on parallel branch" dir2/file2 && PARA_HASH2=$(git rev-parse --verify HEAD) && add_line_into_file "3(para): line 3 on parallel branch" dir2/file3 && - PARA_HASH3=$(git rev-parse --verify HEAD) + PARA_HASH3=$(git rev-parse --verify HEAD) && git merge -m "merge HASH4 and PARA_HASH3" "$HASH4" && - PARA_HASH4=$(git rev-parse --verify HEAD) + PARA_HASH4=$(git rev-parse --verify HEAD) && add_line_into_file "5(para): add line on parallel branch" dir1/file1 && - PARA_HASH5=$(git rev-parse --verify HEAD) + PARA_HASH5=$(git rev-parse --verify HEAD) && add_line_into_file "6(para): add line on parallel branch" dir2/file2 && - PARA_HASH6=$(git rev-parse --verify HEAD) + PARA_HASH6=$(git rev-parse --verify HEAD) && git merge -m "merge HASH7 and PARA_HASH6" "$HASH7" && PARA_HASH7=$(git rev-parse --verify HEAD) ' diff --git a/t/t6035-merge-dir-to-symlink.sh b/t/t6035-merge-dir-to-symlink.sh index 92e02d5d77..2599ae50eb 100755 --- a/t/t6035-merge-dir-to-symlink.sh +++ b/t/t6035-merge-dir-to-symlink.sh @@ -17,13 +17,21 @@ test_expect_success SYMLINKS 'create a commit where dir a/b changed to symlink' git commit -m "dir to symlink" ' -test_expect_success SYMLINKS 'keep a/b-2/c/d across checkout' ' +test_expect_success SYMLINKS 'checkout does not clobber untracked symlink' ' git checkout HEAD^0 && git reset --hard master && git rm --cached a/b && git commit -m "untracked symlink remains" && - git checkout start^0 && - test -f a/b-2/c/d + test_must_fail git checkout start^0 +' + +test_expect_success SYMLINKS 'a/b-2/c/d is kept when clobbering symlink b' ' + git checkout HEAD^0 && + git reset --hard master && + git rm --cached a/b && + git commit -m "untracked symlink remains" && + git checkout -f start^0 && + test -f a/b-2/c/d ' test_expect_success SYMLINKS 'checkout should not have deleted a/b-2/c/d' ' diff --git a/t/t6036-recursive-corner-cases.sh b/t/t6036-recursive-corner-cases.sh index a2e5c5c08f..871577d90c 100755 --- a/t/t6036-recursive-corner-cases.sh +++ b/t/t6036-recursive-corner-cases.sh @@ -15,7 +15,7 @@ test_description='recursive merge corner cases' # test_expect_success 'setup basic criss-cross + rename with no modifications' ' - ten="0 1 2 3 4 5 6 7 8 9" + ten="0 1 2 3 4 5 6 7 8 9" && for i in $ten do echo line $i in a sample file diff --git a/t/t6038-merge-text-auto.sh b/t/t6038-merge-text-auto.sh index 52d0dc4bb8..d9c2d386dd 100755 --- a/t/t6038-merge-text-auto.sh +++ b/t/t6038-merge-text-auto.sh @@ -14,6 +14,8 @@ test_description='CRLF merge conflict across text=auto change . ./test-lib.sh +test_have_prereq SED_STRIPS_CR && SED_OPTIONS=-b + test_expect_success setup ' git config core.autocrlf false && @@ -60,7 +62,7 @@ test_expect_success setup ' test_expect_success 'set up fuzz_conflict() helper' ' fuzz_conflict() { - sed -e "s/^\([<>=]......\) .*/\1/" "$@" + sed $SED_OPTIONS -e "s/^\([<>=]......\) .*/\1/" "$@" } ' diff --git a/t/t6040-tracking-info.sh b/t/t6040-tracking-info.sh index 1785e178a4..6c3719141a 100755 --- a/t/t6040-tracking-info.sh +++ b/t/t6040-tracking-info.sh @@ -42,7 +42,7 @@ b3 behind 1 b4 ahead 2 EOF -test_expect_success 'branch -v' ' +test_expect_success C_LOCALE_OUTPUT 'branch -v' ' ( cd test && git branch -v @@ -60,7 +60,7 @@ test_expect_success 'checkout' ' test_expect_success 'checkout with local tracked branch' ' git checkout master && - git checkout follower >actual + git checkout follower >actual && grep "is ahead of" actual ' @@ -74,20 +74,20 @@ test_expect_success 'status' ' grep "have 1 and 1 different" actual ' -test_expect_success 'status when tracking lightweight tags' ' +test_expect_success 'fail to track lightweight tags' ' git checkout master && git tag light && - git branch --track lighttrack light >actual && - grep "set up to track" actual && - git checkout lighttrack + test_must_fail git branch --track lighttrack light >actual && + test_must_fail grep "set up to track" actual && + test_must_fail git checkout lighttrack ' -test_expect_success 'status when tracking annotated tags' ' +test_expect_success 'fail to track annotated tags' ' git checkout master && git tag -m heavy heavy && - git branch --track heavytrack heavy >actual && - grep "set up to track" actual && - git checkout heavytrack + test_must_fail git branch --track heavytrack heavy >actual && + test_must_fail grep "set up to track" actual && + test_must_fail git checkout heavytrack ' test_expect_success 'setup tracking with branch --set-upstream on existing branch' ' diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh index c907523e7e..ae2194e07d 100755 --- a/t/t6050-replace.sh +++ b/t/t6050-replace.sh @@ -53,7 +53,7 @@ test_expect_success 'set up buggy branch' ' echo "line 12" >> hello && echo "line 13" >> hello && add_and_commit_file hello "2 more lines" && - HASH6=$(git rev-parse --verify HEAD) + HASH6=$(git rev-parse --verify HEAD) && echo "line 14" >> hello && echo "line 15" >> hello && echo "line 16" >> hello && @@ -205,9 +205,16 @@ test_expect_success 'fetch branch with replacement' ' git branch tofetch $HASH6 && ( cd clone_dir && - git fetch origin refs/heads/tofetch:refs/heads/parallel3 - git log --pretty=oneline parallel3 | grep $PARA3 - git show $PARA3 | grep "A U Thor" + git fetch origin refs/heads/tofetch:refs/heads/parallel3 && + git log --pretty=oneline parallel3 > output.txt && + ! grep $PARA3 output.txt && + git show $PARA3 > para3.txt && + grep "A U Thor" para3.txt && + git fetch origin "refs/replace/*:refs/replace/*" && + git log --pretty=oneline parallel3 > output.txt && + grep $PARA3 output.txt && + git show $PARA3 > para3.txt && + grep "O Thor" para3.txt ) ' diff --git a/t/t6110-rev-list-sparse.sh b/t/t6110-rev-list-sparse.sh new file mode 100755 index 0000000000..656ac7fe9d --- /dev/null +++ b/t/t6110-rev-list-sparse.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +test_description='operations that cull histories in unusual ways' +. ./test-lib.sh + +test_expect_success setup ' + test_commit A && + test_commit B && + test_commit C && + git checkout -b side HEAD^ && + test_commit D && + test_commit E && + git merge master +' + +test_expect_success 'rev-list --first-parent --boundary' ' + git rev-list --first-parent --boundary HEAD^.. +' + +test_done diff --git a/t/t6120-describe.sh b/t/t6120-describe.sh index 876d1ab743..1826996245 100755 --- a/t/t6120-describe.sh +++ b/t/t6120-describe.sh @@ -123,7 +123,7 @@ cat - >err.expect <<EOF warning: tag 'A' is really 'Q' here EOF check_describe A-* HEAD -test_expect_success 'warning was displayed for Q' ' +test_expect_success C_LOCALE_OUTPUT 'warning was displayed for Q' ' test_cmp err.expect err.actual ' test_expect_success 'rename tag Q back to A' ' diff --git a/t/t6200-fmt-merge-msg.sh b/t/t6200-fmt-merge-msg.sh index 71f6cad3c2..9a16806921 100755 --- a/t/t6200-fmt-merge-msg.sh +++ b/t/t6200-fmt-merge-msg.sh @@ -129,6 +129,97 @@ test_expect_success '[merge] summary/log configuration' ' test_cmp expected actual2 ' +test_expect_success 'setup: clear [merge] configuration' ' + test_might_fail git config --unset-all merge.log && + test_might_fail git config --unset-all merge.summary +' + +test_expect_success 'setup FETCH_HEAD' ' + git checkout master && + test_tick && + git fetch . left +' + +test_expect_success 'merge.log=3 limits shortlog length' ' + cat >expected <<-EOF && + Merge branch ${apos}left${apos} + + * left: (5 commits) + Left #5 + Left #4 + Left #3 + ... + EOF + + git -c merge.log=3 fmt-merge-msg <.git/FETCH_HEAD >actual && + test_cmp expected actual +' + +test_expect_success 'merge.log=5 shows all 5 commits' ' + cat >expected <<-EOF && + Merge branch ${apos}left${apos} + + * left: + Left #5 + Left #4 + Left #3 + Common #2 + Common #1 + EOF + + git -c merge.log=5 fmt-merge-msg <.git/FETCH_HEAD >actual && + test_cmp expected actual +' + +test_expect_success 'merge.log=0 disables shortlog' ' + echo "Merge branch ${apos}left${apos}" >expected + git -c merge.log=0 fmt-merge-msg <.git/FETCH_HEAD >actual && + test_cmp expected actual +' + +test_expect_success '--log=3 limits shortlog length' ' + cat >expected <<-EOF && + Merge branch ${apos}left${apos} + + * left: (5 commits) + Left #5 + Left #4 + Left #3 + ... + EOF + + git fmt-merge-msg --log=3 <.git/FETCH_HEAD >actual && + test_cmp expected actual +' + +test_expect_success '--log=5 shows all 5 commits' ' + cat >expected <<-EOF && + Merge branch ${apos}left${apos} + + * left: + Left #5 + Left #4 + Left #3 + Common #2 + Common #1 + EOF + + git fmt-merge-msg --log=5 <.git/FETCH_HEAD >actual && + test_cmp expected actual +' + +test_expect_success '--no-log disables shortlog' ' + echo "Merge branch ${apos}left${apos}" >expected && + git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual && + test_cmp expected actual +' + +test_expect_success '--log=0 disables shortlog' ' + echo "Merge branch ${apos}left${apos}" >expected && + git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual && + test_cmp expected actual +' + test_expect_success 'fmt-merge-msg -m' ' echo "Sync with left" >expected && cat >expected.log <<-EOF && diff --git a/t/t6500-gc.sh b/t/t6500-gc.sh new file mode 100755 index 0000000000..82f3639937 --- /dev/null +++ b/t/t6500-gc.sh @@ -0,0 +1,28 @@ +#!/bin/sh + +test_description='basic git gc tests +' + +. ./test-lib.sh + +test_expect_success 'gc empty repository' ' + git gc +' + +test_expect_success 'gc --gobbledegook' ' + test_expect_code 129 git gc --nonsense 2>err && + grep "[Uu]sage: git gc" err +' + +test_expect_success 'gc -h with invalid configuration' ' + mkdir broken && + ( + cd broken && + git init && + echo "[gc] pruneexpire = CORRUPT" >>.git/config && + test_expect_code 129 git gc -h >usage 2>&1 + ) && + grep "[Uu]sage" broken/usage +' + +test_done diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index 65a35d94a0..a845b154e4 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -61,7 +61,7 @@ test_expect_success \ test_expect_success \ 'checking -f on untracked file with existing target' \ 'touch path0/untracked1 && - git mv -f untracked1 path0 + test_must_fail git mv -f untracked1 path0 && test ! -f .git/index.lock && test -f untracked1 && test -f path0/untracked1' @@ -207,7 +207,7 @@ test_expect_success 'git mv should not change sha1 of moved cache entry' ' git init && echo 1 >dirty && git add dirty && - entry="$(git ls-files --stage dirty | cut -f 1)" + entry="$(git ls-files --stage dirty | cut -f 1)" && git mv dirty dirty2 && [ "$entry" = "$(git ls-files --stage dirty2 | cut -f 1)" ] && echo 2 >dirty2 && diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh index ac943f5eee..1dedfd0c83 100755 --- a/t/t7004-tag.sh +++ b/t/t7004-tag.sh @@ -1030,6 +1030,72 @@ test_expect_success GPG \ test_cmp expect actual ' +# usage with rfc1991 signatures +echo "rfc1991" > gpghome/gpg.conf +get_tag_header rfc1991-signed-tag $commit commit $time >expect +echo "RFC1991 signed tag" >>expect +echo '-----BEGIN PGP MESSAGE-----' >>expect +test_expect_success GPG \ + 'creating a signed tag with rfc1991' ' + git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag $commit && + get_tag_msg rfc1991-signed-tag >actual && + test_cmp expect actual +' + +cat >fakeeditor <<'EOF' +#!/bin/sh +cp "$1" actual +EOF +chmod +x fakeeditor + +test_expect_success GPG \ + 'reediting a signed tag body omits signature' ' + echo "RFC1991 signed tag" >expect && + GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit && + test_cmp expect actual +' + +test_expect_success GPG \ + 'verifying rfc1991 signature' ' + git tag -v rfc1991-signed-tag +' + +test_expect_success GPG \ + 'list tag with rfc1991 signature' ' + echo "rfc1991-signed-tag RFC1991 signed tag" >expect && + git tag -l -n1 rfc1991-signed-tag >actual && + test_cmp expect actual && + git tag -l -n2 rfc1991-signed-tag >actual && + test_cmp expect actual && + git tag -l -n999 rfc1991-signed-tag >actual && + test_cmp expect actual +' + +rm -f gpghome/gpg.conf + +test_expect_success GPG \ + 'verifying rfc1991 signature without --rfc1991' ' + git tag -v rfc1991-signed-tag +' + +test_expect_success GPG \ + 'list tag with rfc1991 signature without --rfc1991' ' + echo "rfc1991-signed-tag RFC1991 signed tag" >expect && + git tag -l -n1 rfc1991-signed-tag >actual && + test_cmp expect actual && + git tag -l -n2 rfc1991-signed-tag >actual && + test_cmp expect actual && + git tag -l -n999 rfc1991-signed-tag >actual && + test_cmp expect actual +' + +test_expect_success GPG \ + 'reediting a signed tag body omits signature' ' + echo "RFC1991 signed tag" >expect && + GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit && + test_cmp expect actual +' + # try to sign with bad user.signingkey git config user.signingkey BobTheMouse test_expect_success GPG \ @@ -1051,13 +1117,24 @@ test_expect_success \ test_expect_success \ 'message in editor has initial comment' ' - GIT_EDITOR=cat git tag -a initial-comment > actual + ! (GIT_EDITOR=cat git tag -a initial-comment > actual) +' + +test_expect_success \ + C_LOCALE_OUTPUT \ + 'message in editor has initial comment: first line' ' # check the first line --- should be empty - first=$(sed -e 1q <actual) && - test -z "$first" && + echo >first.expect && + sed -e 1q <actual >first.actual && + test_cmp first.expect first.actual +' + +test_expect_success \ + 'message in editor has initial comment: remainder' ' # remove commented lines from the remainder -- should be empty - rest=$(sed -e 1d -e '/^#/d' <actual) && - test -z "$rest" + >rest.expect + sed -e 1d -e '/^#/d' <actual >rest.actual && + test_cmp rest.expect rest.actual ' get_tag_header reuse $commit commit $time >expect @@ -1097,7 +1174,7 @@ hash1=$(git rev-parse HEAD) test_expect_success 'creating second commit and tag' ' echo foo-2.0 >foo && git add foo && - git commit -m second + git commit -m second && git tag v2.0 ' @@ -1122,18 +1199,18 @@ v2.0 EOF test_expect_success 'checking that first commit is in all tags (hash)' " - git tag -l --contains $hash1 v* >actual + git tag -l --contains $hash1 v* >actual && test_cmp expected actual " # other ways of specifying the commit test_expect_success 'checking that first commit is in all tags (tag)' " - git tag -l --contains v1.0 v* >actual + git tag -l --contains v1.0 v* >actual && test_cmp expected actual " test_expect_success 'checking that first commit is in all tags (relative)' " - git tag -l --contains HEAD~2 v* >actual + git tag -l --contains HEAD~2 v* >actual && test_cmp expected actual " @@ -1142,7 +1219,7 @@ v2.0 EOF test_expect_success 'checking that second commit only has one tag' " - git tag -l --contains $hash2 v* >actual + git tag -l --contains $hash2 v* >actual && test_cmp expected actual " @@ -1151,7 +1228,7 @@ cat > expected <<EOF EOF test_expect_success 'checking that third commit has no tags' " - git tag -l --contains $hash3 v* >actual + git tag -l --contains $hash3 v* >actual && test_cmp expected actual " @@ -1161,7 +1238,7 @@ test_expect_success 'creating simple branch' ' git branch stable v2.0 && git checkout stable && echo foo-3.0 > foo && - git commit foo -m fourth + git commit foo -m fourth && git tag v3.0 ' @@ -1172,7 +1249,7 @@ v3.0 EOF test_expect_success 'checking that branch head only has one tag' " - git tag -l --contains $hash4 v* >actual + git tag -l --contains $hash4 v* >actual && test_cmp expected actual " @@ -1186,7 +1263,7 @@ v4.0 EOF test_expect_success 'checking that original branch head has one tag now' " - git tag -l --contains $hash3 v* >actual + git tag -l --contains $hash3 v* >actual && test_cmp expected actual " @@ -1201,18 +1278,18 @@ v4.0 EOF test_expect_success 'checking that initial commit is in all tags' " - git tag -l --contains $hash1 v* >actual + git tag -l --contains $hash1 v* >actual && test_cmp expected actual " # mixing modes and options: test_expect_success 'mixing incompatibles modes and options is forbidden' ' - test_must_fail git tag -a - test_must_fail git tag -l -v - test_must_fail git tag -n 100 - test_must_fail git tag -l -m msg - test_must_fail git tag -l -F some file + test_must_fail git tag -a && + test_must_fail git tag -l -v && + test_must_fail git tag -n 100 && + test_must_fail git tag -l -m msg && + test_must_fail git tag -l -F some file && test_must_fail git tag -v -s ' diff --git a/t/t7006-pager.sh b/t/t7006-pager.sh index fb744e3c4a..ed7575d0fd 100755 --- a/t/t7006-pager.sh +++ b/t/t7006-pager.sh @@ -4,44 +4,15 @@ test_description='Test automatic use of a pager.' . ./test-lib.sh . "$TEST_DIRECTORY"/lib-pager.sh +. "$TEST_DIRECTORY"/lib-terminal.sh cleanup_fail() { echo >&2 cleanup failed (exit 1) } -test_expect_success 'set up terminal for tests' ' - rm -f stdout_is_tty || - cleanup_fail && - - if test -t 1 - then - >stdout_is_tty - elif - test_have_prereq PERL && - "$PERL_PATH" "$TEST_DIRECTORY"/t7006/test-terminal.perl \ - sh -c "test -t 1" - then - >test_terminal_works - fi -' - -if test -e stdout_is_tty -then - test_terminal() { "$@"; } - test_set_prereq TTY -elif test -e test_terminal_works -then - test_terminal() { - "$PERL_PATH" "$TEST_DIRECTORY"/t7006/test-terminal.perl "$@" - } - test_set_prereq TTY -else - say "# no usable terminal, so skipping some tests" -fi - test_expect_success 'setup' ' - unset GIT_PAGER GIT_PAGER_IN_USE; + sane_unset GIT_PAGER GIT_PAGER_IN_USE && test_might_fail git config --unset core.pager && PAGER="cat >paginated.out" && @@ -213,11 +184,6 @@ test_expect_success 'color when writing to a file intended for a pager' ' colorful colorful.log ' -if test_have_prereq SIMPLEPAGER && test_have_prereq TTY -then - test_set_prereq SIMPLEPAGERTTY -fi - # Use this helper to make it easy for the caller of your # terminal-using function to specify whether it should fail. # If you write @@ -253,8 +219,8 @@ parse_args() { test_default_pager() { parse_args "$@" - $test_expectation SIMPLEPAGERTTY "$cmd - default pager is used by default" " - unset PAGER GIT_PAGER; + $test_expectation SIMPLEPAGER,TTY "$cmd - default pager is used by default" " + sane_unset PAGER GIT_PAGER && test_might_fail git config --unset core.pager && rm -f default_pager_used || cleanup_fail && @@ -277,7 +243,7 @@ test_PAGER_overrides() { parse_args "$@" $test_expectation TTY "$cmd - PAGER overrides default pager" " - unset GIT_PAGER; + sane_unset GIT_PAGER && test_might_fail git config --unset core.pager && rm -f PAGER_used || cleanup_fail && @@ -305,7 +271,7 @@ test_core_pager() { parse_args "$@" $test_expectation TTY "$cmd - repository-local core.pager setting $used_if_wanted" " - unset GIT_PAGER; + sane_unset GIT_PAGER && rm -f core.pager_used || cleanup_fail && @@ -333,7 +299,7 @@ test_pager_subdir_helper() { parse_args "$@" $test_expectation TTY "$cmd - core.pager $used_if_wanted from subdirectory" " - unset GIT_PAGER; + sane_unset GIT_PAGER && rm -f core.pager_used && rm -fr sub || cleanup_fail && @@ -435,4 +401,33 @@ test_core_pager_subdir expect_success 'git -p shortlog' test_core_pager_subdir expect_success test_must_fail \ 'git -p apply </dev/null' +test_expect_success TTY 'command-specific pager' ' + unset PAGER GIT_PAGER; + echo "foo:initial" >expect && + >actual && + git config --unset core.pager && + git config pager.log "sed s/^/foo:/ >actual" && + test_terminal git log --format=%s -1 && + test_cmp expect actual +' + +test_expect_success TTY 'command-specific pager overrides core.pager' ' + unset PAGER GIT_PAGER; + echo "foo:initial" >expect && + >actual && + git config core.pager "exit 1" + git config pager.log "sed s/^/foo:/ >actual" && + test_terminal git log --format=%s -1 && + test_cmp expect actual +' + +test_expect_success TTY 'command-specific pager overridden by environment' ' + GIT_PAGER="sed s/^/foo:/ >actual" && export GIT_PAGER && + >actual && + echo "foo:initial" >expect && + git config pager.log "exit 1" && + test_terminal git log --format=%s -1 && + test_cmp expect actual +' + test_done diff --git a/t/t7012-skip-worktree-writing.sh b/t/t7012-skip-worktree-writing.sh index 582d0b54f1..14fcb1c7f5 100755 --- a/t/t7012-skip-worktree-writing.sh +++ b/t/t7012-skip-worktree-writing.sh @@ -124,13 +124,13 @@ cat >expected <<EOF Would remove expected Would remove result EOF -test_expect_success 'git-clean, absent case' ' +test_expect_success C_LOCALE_OUTPUT 'git-clean, absent case' ' setup_absent && git clean -n > result && test_cmp expected result ' -test_expect_success 'git-clean, dirty case' ' +test_expect_success C_LOCALE_OUTPUT 'git-clean, dirty case' ' setup_dirty && git clean -n > result && test_cmp expected result diff --git a/t/t7060-wtstatus.sh b/t/t7060-wtstatus.sh index fcac472598..b4fcc86a10 100755 --- a/t/t7060-wtstatus.sh +++ b/t/t7060-wtstatus.sh @@ -38,7 +38,7 @@ cat >expect <<EOF no changes added to commit (use "git add" and/or "git commit -a") EOF -test_expect_success 'M/D conflict does not segfault' ' +test_expect_success C_LOCALE_OUTPUT 'M/D conflict does not segfault' ' mkdir mdconflict && ( cd mdconflict && diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh index b8cf2603a1..7be2ff38fc 100755 --- a/t/t7102-reset.sh +++ b/t/t7102-reset.sh @@ -423,7 +423,7 @@ Unstaged changes after reset: M file2 EOF -test_expect_success '--mixed refreshes the index' ' +test_expect_success C_LOCALE_OUTPUT '--mixed refreshes the index' ' echo 123 >> file2 && git reset --mixed HEAD > output && test_cmp expect output diff --git a/t/t7105-reset-patch.sh b/t/t7105-reset-patch.sh index 9891e2c1f5..95fab20361 100755 --- a/t/t7105-reset-patch.sh +++ b/t/t7105-reset-patch.sh @@ -18,7 +18,7 @@ test_expect_success PERL 'setup' ' # note: bar sorts before foo, so the first 'n' is always to skip 'bar' test_expect_success PERL 'saying "n" does nothing' ' - set_and_save_state dir/foo work work + set_and_save_state dir/foo work work && (echo n; echo n) | git reset -p && verify_saved_state dir/foo && verify_saved_state bar @@ -42,14 +42,14 @@ test_expect_success PERL 'git reset -p HEAD^' ' # the failure case (and thus get out of the loop). test_expect_success PERL 'git reset -p dir' ' - set_state dir/foo work work + set_state dir/foo work work && (echo y; echo n) | git reset -p dir && verify_state dir/foo work head && verify_saved_state bar ' test_expect_success PERL 'git reset -p -- foo (inside dir)' ' - set_state dir/foo work work + set_state dir/foo work work && (echo y; echo n) | (cd dir && git reset -p -- foo) && verify_state dir/foo work head && verify_saved_state bar diff --git a/t/t7110-reset-merge.sh b/t/t7110-reset-merge.sh index 70cdd8e618..b42820ad69 100755 --- a/t/t7110-reset-merge.sh +++ b/t/t7110-reset-merge.sh @@ -233,7 +233,7 @@ test_expect_success '"reset --merge HEAD^" is ok with pending merge' ' # working index HEAD target working index HEAD # ---------------------------------------------------- # file1: X U B C --keep (disallowed) -test_expect_success '"reset --keep HEAD^" fails with pending merge' ' +test_expect_success C_LOCALE_OUTPUT '"reset --keep HEAD^" fails with pending merge' ' git reset --hard third && test_must_fail git merge branch1 && test_must_fail git reset --keep HEAD^ 2>err.log && @@ -259,7 +259,7 @@ test_expect_success '"reset --merge HEAD" is ok with pending merge' ' # working index HEAD target working index HEAD # ---------------------------------------------------- # file1: X U B B --keep (disallowed) -test_expect_success '"reset --keep HEAD" fails with pending merge' ' +test_expect_success C_LOCALE_OUTPUT '"reset --keep HEAD" fails with pending merge' ' git reset --hard third && test_must_fail git merge branch1 && test_must_fail git reset --keep HEAD 2>err.log && @@ -280,7 +280,7 @@ test_expect_success '--merge is ok with added/deleted merge' ' git diff --exit-code --cached ' -test_expect_success '--keep fails with added/deleted merge' ' +test_expect_success C_LOCALE_OUTPUT '--keep fails with added/deleted merge' ' git reset --hard third && rm -f file2 && test_must_fail git merge branch3 && diff --git a/t/t7201-co.sh b/t/t7201-co.sh index 1337fa5a22..37ed0931d9 100755 --- a/t/t7201-co.sh +++ b/t/t7201-co.sh @@ -223,7 +223,7 @@ test_expect_success 'checkout --merge --conflict=diff3 <branch>' ' test_cmp two expect ' -test_expect_success 'checkout to detach HEAD (with advice declined)' ' +test_expect_success C_LOCALE_OUTPUT 'checkout to detach HEAD (with advice declined)' ' git config advice.detachedHead false && git checkout -f renamer && git clean -f && @@ -242,7 +242,7 @@ test_expect_success 'checkout to detach HEAD (with advice declined)' ' fi ' -test_expect_success 'checkout to detach HEAD' ' +test_expect_success C_LOCALE_OUTPUT 'checkout to detach HEAD' ' git config advice.detachedHead true && git checkout -f renamer && git clean -f && git checkout renamer^ 2>messages && @@ -260,7 +260,7 @@ test_expect_success 'checkout to detach HEAD' ' fi ' -test_expect_success 'checkout to detach HEAD with branchname^' ' +test_expect_success C_LOCALE_OUTPUT 'checkout to detach HEAD with branchname^' ' git checkout -f master && git clean -f && git checkout renamer^ && @@ -276,7 +276,7 @@ test_expect_success 'checkout to detach HEAD with branchname^' ' fi ' -test_expect_success 'checkout to detach HEAD with :/message' ' +test_expect_success C_LOCALE_OUTPUT 'checkout to detach HEAD with :/message' ' git checkout -f master && git clean -f && git checkout ":/Initial" && @@ -292,7 +292,7 @@ test_expect_success 'checkout to detach HEAD with :/message' ' fi ' -test_expect_success 'checkout to detach HEAD with HEAD^0' ' +test_expect_success C_LOCALE_OUTPUT 'checkout to detach HEAD with HEAD^0' ' git checkout -f master && git clean -f && git checkout HEAD^0 && @@ -408,6 +408,15 @@ test_expect_success 'checkout w/--track from non-branch HEAD fails' ' test "z$(git rev-parse master^0)" = "z$(git rev-parse HEAD)" ' +test_expect_success 'checkout w/--track from tag fails' ' + git checkout master^0 && + test_must_fail git symbolic-ref HEAD && + test_must_fail git checkout --track -b track frotz && + test_must_fail git rev-parse --verify track && + test_must_fail git symbolic-ref HEAD && + test "z$(git rev-parse master^0)" = "z$(git rev-parse HEAD)" +' + test_expect_success 'detach a symbolic link HEAD' ' git checkout master && git config --bool core.prefersymlinkrefs yes && @@ -423,7 +432,6 @@ test_expect_success 'detach a symbolic link HEAD' ' test_expect_success \ 'checkout with --track fakes a sensible -b <name>' ' git update-ref refs/remotes/origin/koala/bear renamer && - git update-ref refs/new/koala/bear renamer && git checkout --track origin/koala/bear && test "refs/heads/koala/bear" = "$(git symbolic-ref HEAD)" && @@ -439,12 +447,6 @@ test_expect_success \ git checkout --track remotes/origin/koala/bear && test "refs/heads/koala/bear" = "$(git symbolic-ref HEAD)" && - test "$(git rev-parse HEAD)" = "$(git rev-parse renamer)" && - - git checkout master && git branch -D koala/bear && - - git checkout --track refs/new/koala/bear && - test "refs/heads/koala/bear" = "$(git symbolic-ref HEAD)" && test "$(git rev-parse HEAD)" = "$(git rev-parse renamer)" ' diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh index 6c776e9bec..800b5368a5 100755 --- a/t/t7300-clean.sh +++ b/t/t7300-clean.sh @@ -110,7 +110,7 @@ test_expect_success 'git clean with prefix' ' ' -test_expect_success 'git clean with relative prefix' ' +test_expect_success C_LOCALE_OUTPUT 'git clean with relative prefix' ' mkdir -p build docs && touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && @@ -125,7 +125,7 @@ test_expect_success 'git clean with relative prefix' ' } ' -test_expect_success 'git clean with absolute path' ' +test_expect_success C_LOCALE_OUTPUT 'git clean with absolute path' ' mkdir -p build docs && touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && @@ -179,11 +179,11 @@ test_expect_success 'git clean -d with prefix and path' ' ' -test_expect_success 'git clean symbolic link' ' +test_expect_success SYMLINKS 'git clean symbolic link' ' mkdir -p build docs && touch a.out src/part3.c docs/manual.txt obj.o build/lib.so && - ln -s docs/manual.txt src/part4.c + ln -s docs/manual.txt src/part4.c && git clean && test -f Makefile && test -f README && @@ -377,7 +377,7 @@ test_expect_success 'clean.requireForce and -f' ' ' -test_expect_success 'core.excludesfile' ' +test_expect_success C_LOCALE_OUTPUT 'core.excludesfile' ' echo excludes >excludes && echo included >included && @@ -453,4 +453,11 @@ test_expect_success 'git clean -e' ' ) ' +test_expect_success SANITY 'git clean -d with an unreadable empty directory' ' + mkdir foo && + chmod a= foo && + git clean -dfx foo && + ! test -d foo +' + test_done diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index 782b0a3ece..874279e32d 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -421,11 +421,67 @@ test_expect_success 'add submodules without specifying an explicit path' ' git commit -m "repo commit 1" ) && git clone --bare repo/ bare.git && - cd addtest && - git submodule add "$submodurl/repo" && - git config -f .gitmodules submodule.repo.path repo && - git submodule add "$submodurl/bare.git" && - git config -f .gitmodules submodule.bare.path bare + ( + cd addtest && + git submodule add "$submodurl/repo" && + git config -f .gitmodules submodule.repo.path repo && + git submodule add "$submodurl/bare.git" && + git config -f .gitmodules submodule.bare.path bare + ) +' + +test_expect_success 'add should fail when path is used by a file' ' + ( + cd addtest && + touch file && + test_must_fail git submodule add "$submodurl/repo" file + ) +' + +test_expect_success 'add should fail when path is used by an existing directory' ' + ( + cd addtest && + mkdir empty-dir && + test_must_fail git submodule add "$submodurl/repo" empty-dir + ) +' + +test_expect_success 'set up for relative path tests' ' + mkdir reltest && + ( + cd reltest && + git init && + mkdir sub && + ( + cd sub && + git init && + test_commit foo + ) && + git add sub && + git config -f .gitmodules submodule.sub.path sub && + git config -f .gitmodules submodule.sub.url ../subrepo && + cp .git/config pristine-.git-config + ) +' + +test_expect_success 'relative path works with URL' ' + ( + cd reltest && + cp pristine-.git-config .git/config && + git config remote.origin.url ssh://hostname/repo && + git submodule init && + test "$(git config submodule.sub.url)" = ssh://hostname/subrepo + ) +' + +test_expect_success 'relative path works with user@host:path' ' + ( + cd reltest && + cp pristine-.git-config .git/config && + git config remote.origin.url user@host:repo && + git submodule init && + test "$(git config submodule.sub.url)" = user@host:subrepo + ) ' test_done diff --git a/t/t7401-submodule-summary.sh b/t/t7401-submodule-summary.sh index 294584452b..7d7fde057b 100755 --- a/t/t7401-submodule-summary.sh +++ b/t/t7401-submodule-summary.sh @@ -37,11 +37,12 @@ head1=$(add_file sm1 foo1 foo2) test_expect_success 'added submodule' " git add sm1 && git submodule summary >actual && - diff actual - <<-EOF + cat >expected <<-EOF && * sm1 0000000...$head1 (2): > Add foo2 EOF + test_cmp expected actual " commit_file sm1 && @@ -49,20 +50,22 @@ head2=$(add_file sm1 foo3) test_expect_success 'modified submodule(forward)' " git submodule summary >actual && - diff actual - <<-EOF + cat >expected <<-EOF && * sm1 $head1...$head2 (1): > Add foo3 EOF + test_cmp expected actual " test_expect_success 'modified submodule(forward), --files' " git submodule summary --files >actual && - diff actual - <<-EOF + cat >expected <<-EOF && * sm1 $head1...$head2 (1): > Add foo3 EOF + test_cmp expected actual " commit_file sm1 && @@ -74,19 +77,20 @@ head3=$( test_expect_success 'modified submodule(backward)' " git submodule summary >actual && - diff actual - <<-EOF + cat >expected <<-EOF && * sm1 $head2...$head3 (2): < Add foo3 < Add foo2 EOF + test_cmp expected actual " head4=$(add_file sm1 foo4 foo5) && head4_full=$(GIT_DIR=sm1/.git git rev-parse --verify HEAD) test_expect_success 'modified submodule(backward and forward)' " git submodule summary >actual && - diff actual - <<-EOF + cat >expected <<-EOF && * sm1 $head2...$head4 (4): > Add foo5 > Add foo4 @@ -94,17 +98,19 @@ test_expect_success 'modified submodule(backward and forward)' " < Add foo2 EOF + test_cmp expected actual " test_expect_success '--summary-limit' " git submodule summary -n 3 >actual && - diff actual - <<-EOF + cat >expected <<-EOF && * sm1 $head2...$head4 (4): > Add foo5 > Add foo4 < Add foo3 EOF + test_cmp expected actual " commit_file sm1 && @@ -117,30 +123,33 @@ mv sm1-bak sm1 test_expect_success 'typechanged submodule(submodule->blob), --cached' " git submodule summary --cached >actual && - diff actual - <<-EOF + cat >expected <<-EOF && * sm1 $head4(submodule)->$head5(blob) (3): < Add foo5 EOF + test_cmp actual expected " test_expect_success 'typechanged submodule(submodule->blob), --files' " git submodule summary --files >actual && - diff actual - <<-EOF + cat >expected <<-EOF && * sm1 $head5(blob)->$head4(submodule) (3): > Add foo5 EOF + test_cmp actual expected " rm -rf sm1 && git checkout-index sm1 test_expect_success 'typechanged submodule(submodule->blob)' " git submodule summary >actual && - diff actual - <<-EOF + cat >expected <<-EOF && * sm1 $head4(submodule)->$head5(blob): EOF + test_cmp actual expected " rm -f sm1 && @@ -148,31 +157,34 @@ test_create_repo sm1 && head6=$(add_file sm1 foo6 foo7) test_expect_success 'nonexistent commit' " git submodule summary >actual && - diff actual - <<-EOF + cat >expected <<-EOF && * sm1 $head4...$head6: Warn: sm1 doesn't contain commit $head4_full EOF + test_cmp actual expected " commit_file test_expect_success 'typechanged submodule(blob->submodule)' " git submodule summary >actual && - diff actual - <<-EOF + cat >expected <<-EOF && * sm1 $head5(blob)->$head6(submodule) (2): > Add foo7 EOF + test_cmp expected actual " commit_file sm1 && rm -rf sm1 test_expect_success 'deleted submodule' " git submodule summary >actual && - diff actual - <<-EOF + cat >expected <<-EOF && * sm1 $head6...0000000: EOF + test_cmp expected actual " test_create_repo sm2 && @@ -181,34 +193,37 @@ git add sm2 test_expect_success 'multiple submodules' " git submodule summary >actual && - diff actual - <<-EOF + cat >expected <<-EOF && * sm1 $head6...0000000: * sm2 0000000...$head7 (2): > Add foo9 EOF + test_cmp expected actual " test_expect_success 'path filter' " git submodule summary sm2 >actual && - diff actual - <<-EOF + cat >expected <<-EOF && * sm2 0000000...$head7 (2): > Add foo9 EOF + test_cmp expected actual " commit_file sm2 test_expect_success 'given commit' " git submodule summary HEAD^ >actual && - diff actual - <<-EOF + cat >expected <<-EOF && * sm1 $head6...0000000: * sm2 0000000...$head7 (2): > Add foo9 EOF + test_cmp expected actual " test_expect_success '--for-status' " diff --git a/t/t7403-submodule-sync.sh b/t/t7403-submodule-sync.sh index 02522f9627..d600583cef 100755 --- a/t/t7403-submodule-sync.sh +++ b/t/t7403-submodule-sync.sh @@ -23,7 +23,9 @@ test_expect_success setup ' git commit -m "submodule" ) && git clone super super-clone && - (cd super-clone && git submodule update --init) + (cd super-clone && git submodule update --init) && + git clone super empty-clone && + (cd empty-clone && git submodule init) ' test_expect_success 'change submodule' ' @@ -50,7 +52,7 @@ test_expect_success 'change submodule url' ' test_expect_success '"git submodule sync" should update submodule URLs' ' (cd super-clone && - git pull && + git pull --no-recurse-submodules && git submodule sync ) && test -d "$(git config -f super-clone/submodule/.git/config \ @@ -64,4 +66,12 @@ test_expect_success '"git submodule sync" should update submodule URLs' ' ) ' +test_expect_success '"git submodule sync" should update submodule URLs if not yet cloned' ' + (cd empty-clone && + git pull && + git submodule sync && + test -d "$(git config submodule.submodule.url)" + ) +' + test_done diff --git a/t/t7405-submodule-merge.sh b/t/t7405-submodule-merge.sh index 7e2e258950..a8fb30b792 100755 --- a/t/t7405-submodule-merge.sh +++ b/t/t7405-submodule-merge.sh @@ -56,11 +56,11 @@ test_expect_success setup ' # History setup # -# b -# / \ -# a d -# \ / -# c +# b +# / \ +# init -- a d +# \ \ / +# g c # # a in the main repository records to sub-a in the submodule and # analogous b and c. d should be automatically found by merging c into @@ -76,6 +76,8 @@ test_expect_success 'setup for merge search' ' git add file-a && git commit -m "sub-a" && git branch sub-a) && + git commit --allow-empty -m init && + git branch init && git add sub && git commit -m "a" && git branch a && @@ -101,7 +103,13 @@ test_expect_success 'setup for merge search' ' git checkout -b sub-d sub-b && git merge sub-c) && git commit -a -m "d" && - git branch test b) + git branch test b && + + git checkout -b g init && + (cd sub && + git checkout -b sub-g sub-c) && + git add sub && + git commit -a -m "g") ' test_expect_success 'merge with one side as a fast-forward of the other' ' @@ -176,6 +184,44 @@ test_expect_success 'merging should fail for changes that are backwards' ' test_must_fail git merge f) ' + +# Check that the conflicting submodule is detected when it is +# in the common ancestor. status should be 'U00...00" +test_expect_success 'git submodule status should display the merge conflict properly with merge base' ' + (cd merge-search && + cat >.gitmodules <<EOF && +[submodule "sub"] + path = sub + url = $TRASH_DIRECTORY/sub +EOF + cat >expect <<EOF && +U0000000000000000000000000000000000000000 sub +EOF + git submodule status > actual && + test_cmp expect actual && + git reset --hard) +' + +# Check that the conflicting submodule is detected when it is +# not in the common ancestor. status should be 'U00...00" +test_expect_success 'git submodule status should display the merge conflict properly without merge-base' ' + (cd merge-search && + git checkout -b test-no-merge-base g && + test_must_fail git merge b && + cat >.gitmodules <<EOF && +[submodule "sub"] + path = sub + url = $TRASH_DIRECTORY/sub +EOF + cat >expect <<EOF && +U0000000000000000000000000000000000000000 sub +EOF + git submodule status > actual && + test_cmp expect actual && + git reset --hard) +' + + test_expect_success 'merging with a modify/modify conflict between merge bases' ' git reset --hard HEAD && git checkout -b test2 c && diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh index bfb4975e94..bf7c788735 100755 --- a/t/t7406-submodule-update.sh +++ b/t/t7406-submodule-update.sh @@ -74,6 +74,26 @@ test_expect_success 'submodule update detaching the HEAD ' ' ) ' +apos="'"; +test_expect_success 'submodule update does not fetch already present commits' ' + (cd submodule && + echo line3 >> file && + git add file && + test_tick && + git commit -m "upstream line3" + ) && + (cd super/submodule && + head=$(git rev-parse --verify HEAD) && + echo "Submodule path ${apos}submodule$apos: checked out $apos$head$apos" > ../../expected && + git reset --hard HEAD~1 + ) && + (cd super && + git submodule update > ../actual 2> ../actual.err + ) && + test_cmp expected actual && + ! test -s actual.err +' + test_expect_success 'submodule update --rebase staying on master' ' (cd super/submodule && git checkout master @@ -203,4 +223,56 @@ test_expect_success 'submodule init picks up merge' ' ) ' +test_expect_success 'submodule update --merge - ignores --merge for new submodules' ' + (cd super && + rm -rf submodule && + git submodule update submodule && + git status -s submodule >expect && + rm -rf submodule && + git submodule update --merge submodule && + git status -s submodule >actual && + test_cmp expect actual + ) +' + +test_expect_success 'submodule update --rebase - ignores --rebase for new submodules' ' + (cd super && + rm -rf submodule && + git submodule update submodule && + git status -s submodule >expect && + rm -rf submodule && + git submodule update --rebase submodule && + git status -s submodule >actual && + test_cmp expect actual + ) +' + +test_expect_success 'submodule update ignores update=merge config for new submodules' ' + (cd super && + rm -rf submodule && + git submodule update submodule && + git status -s submodule >expect && + rm -rf submodule && + git config submodule.submodule.update merge && + git submodule update submodule && + git status -s submodule >actual && + git config --unset submodule.submodule.update && + test_cmp expect actual + ) +' + +test_expect_success 'submodule update ignores update=rebase config for new submodules' ' + (cd super && + rm -rf submodule && + git submodule update submodule && + git status -s submodule >expect && + rm -rf submodule && + git config submodule.submodule.update rebase && + git submodule update submodule && + git status -s submodule >actual && + git config --unset submodule.submodule.update && + test_cmp expect actual + ) +' + test_done diff --git a/t/t7407-submodule-foreach.sh b/t/t7407-submodule-foreach.sh index 905a8baae9..e5be13c271 100755 --- a/t/t7407-submodule-foreach.sh +++ b/t/t7407-submodule-foreach.sh @@ -226,6 +226,25 @@ test_expect_success 'test "status --recursive"' ' test_cmp expect actual ' +sed -e "/nested1 /s/.*/+$nested1sha1 nested1 (file2~1)/;/sub[1-3]/d" < expect > expect2 +mv -f expect2 expect + +test_expect_success 'ensure "status --cached --recursive" preserves the --cached flag' ' + ( + cd clone3 && + ( + cd nested1 && + test_commit file2 + ) && + git submodule status --cached --recursive -- nested1 > ../actual + ) && + if test_have_prereq MINGW + then + dos2unix actual + fi && + test_cmp expect actual +' + test_expect_success 'use "git clone --recursive" to checkout all submodules' ' git clone --recursive super clone4 && test -d clone4/.git && @@ -238,4 +257,39 @@ test_expect_success 'use "git clone --recursive" to checkout all submodules' ' test -d clone4/nested1/nested2/nested3/submodule/.git ' +test_expect_success 'test "update --recursive" with a flag with spaces' ' + git clone super "common objects" && + git clone super clone5 && + ( + cd clone5 && + test ! -d nested1/.git && + git submodule update --init --recursive --reference="$(dirname "$PWD")/common objects" && + test -d nested1/.git && + test -d nested1/nested2/.git && + test -d nested1/nested2/nested3/.git && + test -f nested1/.git/objects/info/alternates && + test -f nested1/nested2/.git/objects/info/alternates && + test -f nested1/nested2/nested3/.git/objects/info/alternates + ) +' + +test_expect_success 'use "update --recursive nested1" to checkout all submodules rooted in nested1' ' + git clone super clone6 && + ( + cd clone6 && + test ! -d sub1/.git && + test ! -d sub2/.git && + test ! -d sub3/.git && + test ! -d nested1/.git && + git submodule update --init --recursive -- nested1 && + test ! -d sub1/.git && + test ! -d sub2/.git && + test ! -d sub3/.git && + test -d nested1/.git && + test -d nested1/nested2/.git && + test -d nested1/nested2/nested3/.git && + test -d nested1/nested2/nested3/submodule/.git + ) +' + test_done diff --git a/t/t7500-commit.sh b/t/t7500-commit.sh index aa9c577e9e..bcdf0847d0 100755 --- a/t/t7500-commit.sh +++ b/t/t7500-commit.sh @@ -10,7 +10,12 @@ Tests for selected commit options.' . ./test-lib.sh commit_msg_is () { - test "`git log --pretty=format:%s%b -1`" = "$1" + expect=commit_msg_is.expect + actual=commit_msg_is.actual + + printf "%s" "$(git log --pretty=format:%s%b -1)" >$expect && + printf "%s" "$1" >$actual && + test_cmp $expect $actual } # A sanity check to see if commit is working at all. @@ -23,13 +28,21 @@ test_expect_success 'a basic commit in an empty tree should succeed' ' test_expect_success 'nonexistent template file should return error' ' echo changes >> foo && git add foo && - test_must_fail git commit --template "$PWD"/notexist + ( + GIT_EDITOR="echo hello >\"\$1\"" && + export GIT_EDITOR && + test_must_fail git commit --template "$PWD"/notexist + ) ' test_expect_success 'nonexistent template file in config should return error' ' git config commit.template "$PWD"/notexist && - test_must_fail git commit && - git config --unset commit.template + test_when_finished "git config --unset commit.template" && + ( + GIT_EDITOR="echo hello >\"\$1\"" && + export GIT_EDITOR && + test_must_fail git commit + ) ' # From now on we'll use a template file that exists. @@ -59,7 +72,7 @@ test_expect_success 'adding comments to a template should not commit' ' ) ' -test_expect_success 'adding real content to a template should commit' ' +test_expect_success C_LOCALE_OUTPUT 'adding real content to a template should commit' ' ( test_set_editor "$TEST_DIRECTORY"/t7500/add-content && git commit --template "$TEMPLATE" @@ -67,7 +80,7 @@ test_expect_success 'adding real content to a template should commit' ' commit_msg_is "template linecommit message" ' -test_expect_success '-t option should be short for --template' ' +test_expect_success C_LOCALE_OUTPUT '-t option should be short for --template' ' echo "short template" > "$TEMPLATE" && echo "new content" >> foo && git add foo && @@ -78,7 +91,7 @@ test_expect_success '-t option should be short for --template' ' commit_msg_is "short templatecommit message" ' -test_expect_success 'config-specified template should commit' ' +test_expect_success C_LOCALE_OUTPUT 'config-specified template should commit' ' echo "new template" > "$TEMPLATE" && git config commit.template "$TEMPLATE" && echo "more content" >> foo && @@ -215,4 +228,84 @@ test_expect_success 'Commit a message with --allow-empty-message' ' commit_msg_is "hello there" ' +commit_for_rebase_autosquash_setup () { + echo "first content line" >>foo && + git add foo && + cat >log <<EOF && +target message subject line + +target message body line 1 +target message body line 2 +EOF + git commit -F log && + echo "second content line" >>foo && + git add foo && + git commit -m "intermediate commit" && + echo "third content line" >>foo && + git add foo +} + +test_expect_success 'commit --fixup provides correct one-line commit message' ' + commit_for_rebase_autosquash_setup && + git commit --fixup HEAD~1 && + commit_msg_is "fixup! target message subject line" +' + +test_expect_success 'commit --squash works with -F' ' + commit_for_rebase_autosquash_setup && + echo "log message from file" >msgfile && + git commit --squash HEAD~1 -F msgfile && + commit_msg_is "squash! target message subject linelog message from file" +' + +test_expect_success 'commit --squash works with -m' ' + commit_for_rebase_autosquash_setup && + git commit --squash HEAD~1 -m "foo bar\nbaz" && + commit_msg_is "squash! target message subject linefoo bar\nbaz" +' + +test_expect_success 'commit --squash works with -C' ' + commit_for_rebase_autosquash_setup && + git commit --squash HEAD~1 -C HEAD && + commit_msg_is "squash! target message subject lineintermediate commit" +' + +test_expect_success 'commit --squash works with -c' ' + commit_for_rebase_autosquash_setup && + test_set_editor "$TEST_DIRECTORY"/t7500/edit-content && + git commit --squash HEAD~1 -c HEAD && + commit_msg_is "squash! target message subject lineedited commit" +' + +test_expect_success 'commit --squash works with -C for same commit' ' + commit_for_rebase_autosquash_setup && + git commit --squash HEAD -C HEAD && + commit_msg_is "squash! intermediate commit" +' + +test_expect_success 'commit --squash works with -c for same commit' ' + commit_for_rebase_autosquash_setup && + test_set_editor "$TEST_DIRECTORY"/t7500/edit-content && + git commit --squash HEAD -c HEAD && + commit_msg_is "squash! edited commit" +' + +test_expect_success C_LOCALE_OUTPUT 'commit --squash works with editor' ' + commit_for_rebase_autosquash_setup && + test_set_editor "$TEST_DIRECTORY"/t7500/add-content && + git commit --squash HEAD~1 && + commit_msg_is "squash! target message subject linecommit message" +' + +test_expect_success 'invalid message options when using --fixup' ' + echo changes >>foo && + echo "message" >log && + git add foo && + test_must_fail git commit --fixup HEAD~1 --squash HEAD~2 && + test_must_fail git commit --fixup HEAD~1 -C HEAD~2 && + test_must_fail git commit --fixup HEAD~1 -c HEAD~2 && + test_must_fail git commit --fixup HEAD~1 -m "cmdline message" && + test_must_fail git commit --fixup HEAD~1 -F log +' + test_done diff --git a/t/t7500/edit-content b/t/t7500/edit-content new file mode 100755 index 0000000000..08db9fdd2e --- /dev/null +++ b/t/t7500/edit-content @@ -0,0 +1,4 @@ +#!/bin/sh +sed -e "s/intermediate/edited/g" <"$1" >"$1-" +mv "$1-" "$1" +exit 0 diff --git a/t/t7501-commit.sh b/t/t7501-commit.sh index 8297cb4f1e..a76c474195 100755 --- a/t/t7501-commit.sh +++ b/t/t7501-commit.sh @@ -14,8 +14,11 @@ test_tick test_expect_success \ "initial status" \ "echo 'bongo bongo' >file && - git add file && \ - git status | grep 'Initial commit'" + git add file" + +test_expect_success C_LOCALE_OUTPUT \ + "Constructing initial commit" \ + "git status | grep 'Initial commit'" test_expect_success \ "fail initial amend" \ @@ -230,6 +233,10 @@ test_expect_success 'amend commit to fix date' ' ' +test_expect_success 'commit complains about bogus date' ' + test_must_fail git commit --amend --date=10.11.2010 +' + test_expect_success 'sign off (1)' ' echo 1 >positive && diff --git a/t/t7502-commit.sh b/t/t7502-commit.sh index ac2e187a57..cfb569eaba 100755 --- a/t/t7502-commit.sh +++ b/t/t7502-commit.sh @@ -22,7 +22,10 @@ check_summary_oneline() { SUMMARY_POSTFIX="$(git log -1 --pretty='format:%h')" echo "[$SUMMARY_PREFIX $SUMMARY_POSTFIX] $2" >exp && - test_cmp exp act + if test_have_prereq C_LOCALE_OUTPUT + then + test_cmp exp act + fi } test_expect_success 'output summary format' ' @@ -32,7 +35,10 @@ test_expect_success 'output summary format' ' check_summary_oneline "root-commit" "initial" && echo change >>file1 && - git add file1 && + git add file1 +' + +test_expect_success 'output summary format: root-commit' ' check_summary_oneline "" "a change" ' @@ -215,30 +221,35 @@ test_expect_success 'cleanup commit messages (strip,-F)' ' ' -echo "sample - -# Please enter the commit message for your changes. Lines starting -# with '#' will be ignored, and an empty message aborts the commit." >expect - test_expect_success 'cleanup commit messages (strip,-F,-e)' ' echo >>negative && { echo;echo sample;echo; } >text && git commit -e -F text -a && - head -n 4 .git/COMMIT_EDITMSG >actual && - test_cmp expect actual + head -n 4 .git/COMMIT_EDITMSG >actual +' +echo "sample + +# Please enter the commit message for your changes. Lines starting +# with '#' will be ignored, and an empty message aborts the commit." >expect + +test_expect_success C_LOCALE_OUTPUT 'cleanup commit messages (strip,-F,-e): output' ' + test_cmp expect actual ' echo "# # Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> #" >> expect -test_expect_success 'author different from committer' ' +test_expect_success C_LOCALE_OUTPUT 'author different from committer' ' echo >>negative && git commit -e -m "sample" - head -n 7 .git/COMMIT_EDITMSG >actual && + head -n 7 .git/COMMIT_EDITMSG >actual +' + +test_expect_success C_LOCALE_OUTPUT 'author different from committer: output' ' test_cmp expect actual ' @@ -248,17 +259,20 @@ rm -f expect.tmp echo "# Committer: #" >> expect -test_expect_success 'committer is automatic' ' +test_expect_success C_LOCALE_OUTPUT 'committer is automatic' ' echo >>negative && ( - unset GIT_COMMITTER_EMAIL - unset GIT_COMMITTER_NAME + sane_unset GIT_COMMITTER_EMAIL && + sane_unset GIT_COMMITTER_NAME && # must fail because there is no change test_must_fail git commit -e -m "sample" ) && head -n 8 .git/COMMIT_EDITMSG | \ - sed "s/^# Committer: .*/# Committer:/" >actual && + sed "s/^# Committer: .*/# Committer:/" >actual +' + +test_expect_success C_LOCALE_OUTPUT 'committer is automatic: output' ' test_cmp expect actual ' @@ -370,66 +384,66 @@ try_commit () { try_commit_status_combo () { - test_expect_success 'commit' ' + test_expect_success C_LOCALE_OUTPUT 'commit' ' clear_config commit.status && try_commit "" && grep "^# Changes to be committed:" .git/COMMIT_EDITMSG ' - test_expect_success 'commit' ' + test_expect_success C_LOCALE_OUTPUT 'commit' ' clear_config commit.status && try_commit "" && grep "^# Changes to be committed:" .git/COMMIT_EDITMSG ' - test_expect_success 'commit --status' ' + test_expect_success C_LOCALE_OUTPUT 'commit --status' ' clear_config commit.status && try_commit --status && grep "^# Changes to be committed:" .git/COMMIT_EDITMSG ' - test_expect_success 'commit --no-status' ' + test_expect_success C_LOCALE_OUTPUT 'commit --no-status' ' clear_config commit.status && - try_commit --no-status + try_commit --no-status && ! grep "^# Changes to be committed:" .git/COMMIT_EDITMSG ' - test_expect_success 'commit with commit.status = yes' ' + test_expect_success C_LOCALE_OUTPUT 'commit with commit.status = yes' ' clear_config commit.status && git config commit.status yes && try_commit "" && grep "^# Changes to be committed:" .git/COMMIT_EDITMSG ' - test_expect_success 'commit with commit.status = no' ' + test_expect_success C_LOCALE_OUTPUT 'commit with commit.status = no' ' clear_config commit.status && git config commit.status no && try_commit "" && ! grep "^# Changes to be committed:" .git/COMMIT_EDITMSG ' - test_expect_success 'commit --status with commit.status = yes' ' + test_expect_success C_LOCALE_OUTPUT 'commit --status with commit.status = yes' ' clear_config commit.status && git config commit.status yes && try_commit --status && grep "^# Changes to be committed:" .git/COMMIT_EDITMSG ' - test_expect_success 'commit --no-status with commit.status = yes' ' + test_expect_success C_LOCALE_OUTPUT 'commit --no-status with commit.status = yes' ' clear_config commit.status && git config commit.status yes && try_commit --no-status && ! grep "^# Changes to be committed:" .git/COMMIT_EDITMSG ' - test_expect_success 'commit --status with commit.status = no' ' + test_expect_success C_LOCALE_OUTPUT 'commit --status with commit.status = no' ' clear_config commit.status && git config commit.status no && try_commit --status && grep "^# Changes to be committed:" .git/COMMIT_EDITMSG ' - test_expect_success 'commit --no-status with commit.status = no' ' + test_expect_success C_LOCALE_OUTPUT 'commit --no-status with commit.status = no' ' clear_config commit.status && git config commit.status no && try_commit --no-status && diff --git a/t/t7505-prepare-commit-msg-hook.sh b/t/t7505-prepare-commit-msg-hook.sh index ff189624d4..5b4b694f18 100755 --- a/t/t7505-prepare-commit-msg-hook.sh +++ b/t/t7505-prepare-commit-msg-hook.sh @@ -132,6 +132,18 @@ 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 && + git add file && + git commit -m other && + git checkout - && + git merge other && + test "`git log -1 --pretty=format:%s`" = merge +' + cat > "$HOOK" <<'EOF' #!/bin/sh exit 1 diff --git a/t/t7506-status-submodule.sh b/t/t7506-status-submodule.sh index 3d4f85d74f..c56733253f 100755 --- a/t/t7506-status-submodule.sh +++ b/t/t7506-status-submodule.sh @@ -20,17 +20,17 @@ test_expect_success 'setup' ' git commit -m "Add submodule sub" ' -test_expect_success 'status clean' ' +test_expect_success C_LOCALE_OUTPUT 'status clean' ' git status >output && grep "nothing to commit" output ' -test_expect_success 'commit --dry-run -a clean' ' +test_expect_success C_LOCALE_OUTPUT 'commit --dry-run -a clean' ' test_must_fail git commit --dry-run -a >output && grep "nothing to commit" output ' -test_expect_success 'status with modified file in submodule' ' +test_expect_success C_LOCALE_OUTPUT 'status with modified file in submodule' ' (cd sub && git reset --hard) && echo "changed" >sub/foo && git status >output && @@ -46,7 +46,7 @@ test_expect_success 'status with modified file in submodule (porcelain)' ' EOF ' -test_expect_success 'status with added file in submodule' ' +test_expect_success C_LOCALE_OUTPUT 'status with added file in submodule' ' (cd sub && git reset --hard && echo >foo && git add foo) && git status >output && grep "modified: sub (modified content)" output @@ -60,14 +60,14 @@ test_expect_success 'status with added file in submodule (porcelain)' ' EOF ' -test_expect_success 'status with untracked file in submodule' ' +test_expect_success C_LOCALE_OUTPUT 'status with untracked file in submodule' ' (cd sub && git reset --hard) && echo "content" >sub/new-file && git status >output && grep "modified: sub (untracked content)" output ' -test_expect_success 'status -uno with untracked file in submodule' ' +test_expect_success C_LOCALE_OUTPUT 'status -uno with untracked file in submodule' ' git status -uno >output && grep "^nothing to commit" output ' @@ -79,7 +79,7 @@ test_expect_success 'status with untracked file in submodule (porcelain)' ' EOF ' -test_expect_success 'status with added and untracked file in submodule' ' +test_expect_success C_LOCALE_OUTPUT 'status with added and untracked file in submodule' ' (cd sub && git reset --hard && echo >foo && git add foo) && echo "content" >sub/new-file && git status >output && @@ -95,7 +95,7 @@ test_expect_success 'status with added and untracked file in submodule (porcelai EOF ' -test_expect_success 'status with modified file in modified submodule' ' +test_expect_success C_LOCALE_OUTPUT 'status with modified file in modified submodule' ' (cd sub && git reset --hard) && rm sub/new-file && (cd sub && echo "next change" >foo && git commit -m "next change" foo) && @@ -113,7 +113,7 @@ test_expect_success 'status with modified file in modified submodule (porcelain) EOF ' -test_expect_success 'status with added file in modified submodule' ' +test_expect_success C_LOCALE_OUTPUT 'status with added file in modified submodule' ' (cd sub && git reset --hard && echo >foo && git add foo) && git status >output && grep "modified: sub (new commits, modified content)" output @@ -127,7 +127,7 @@ test_expect_success 'status with added file in modified submodule (porcelain)' ' EOF ' -test_expect_success 'status with untracked file in modified submodule' ' +test_expect_success C_LOCALE_OUTPUT 'status with untracked file in modified submodule' ' (cd sub && git reset --hard) && echo "content" >sub/new-file && git status >output && @@ -141,7 +141,7 @@ test_expect_success 'status with untracked file in modified submodule (porcelain EOF ' -test_expect_success 'status with added and untracked file in modified submodule' ' +test_expect_success C_LOCALE_OUTPUT 'status with added and untracked file in modified submodule' ' (cd sub && git reset --hard && echo >foo && git add foo) && echo "content" >sub/new-file && git status >output && @@ -167,7 +167,7 @@ test_expect_success 'setup .git file for sub' ' git commit -m "added .real to .gitignore" .gitignore ' -test_expect_success 'status with added file in modified submodule with .git file' ' +test_expect_success C_LOCALE_OUTPUT 'status with added file in modified submodule with .git file' ' (cd sub && git reset --hard && echo >foo && git add foo) && git status >output && grep "modified: sub (new commits, modified content)" output @@ -177,12 +177,12 @@ test_expect_success 'rm submodule contents' ' rm -rf sub/* sub/.git ' -test_expect_success 'status clean (empty submodule dir)' ' +test_expect_success C_LOCALE_OUTPUT 'status clean (empty submodule dir)' ' git status >output && grep "nothing to commit" output ' -test_expect_success 'status -a clean (empty submodule dir)' ' +test_expect_success C_LOCALE_OUTPUT 'status -a clean (empty submodule dir)' ' test_must_fail git commit --dry-run -a >output && grep "nothing to commit" output ' diff --git a/t/t7508-status.sh b/t/t7508-status.sh index c9300f3c8b..a93e70fac4 100755 --- a/t/t7508-status.sh +++ b/t/t7508-status.sh @@ -7,6 +7,30 @@ test_description='git status' . ./test-lib.sh +test_expect_success 'status -h in broken repository' ' + mkdir broken && + test_when_finished "rm -fr broken" && + ( + cd broken && + git init && + echo "[status] showuntrackedfiles = CORRUPT" >>.git/config && + test_expect_code 129 git status -h >usage 2>&1 + ) && + grep "[Uu]sage" broken/usage +' + +test_expect_success 'commit -h in broken repository' ' + mkdir broken && + test_when_finished "rm -fr broken" && + ( + cd broken && + git init && + echo "[status] showuntrackedfiles = CORRUPT" >>.git/config && + test_expect_code 129 git commit -h >usage 2>&1 + ) && + grep "[Uu]sage" broken/usage +' + test_expect_success 'setup' ' : >tracked && : >modified && @@ -31,7 +55,7 @@ test_expect_success 'setup' ' git add dir2/added ' -test_expect_success 'status (1)' ' +test_expect_success C_LOCALE_OUTPUT 'status (1)' ' grep "use \"git rm --cached <file>\.\.\.\" to unstage" output @@ -44,7 +68,7 @@ cat >expect <<\EOF # # new file: dir2/added # -# Changed but not updated: +# 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) # @@ -61,7 +85,7 @@ cat >expect <<\EOF # untracked EOF -test_expect_success 'status (2)' ' +test_expect_success C_LOCALE_OUTPUT 'status (2)' ' git status >output && test_cmp expect output @@ -73,7 +97,7 @@ cat >expect <<\EOF # Changes to be committed: # new file: dir2/added # -# Changed but not updated: +# Changes not staged for commit: # modified: dir1/modified # # Untracked files: @@ -87,7 +111,7 @@ EOF git config advice.statusHints false -test_expect_success 'status (advice.statusHints false)' ' +test_expect_success C_LOCALE_OUTPUT 'status (advice.statusHints false)' ' git status >output && test_cmp expect output @@ -133,6 +157,12 @@ test_expect_success 'status -s -b' ' ' +test_expect_success 'setup dir3' ' + mkdir dir3 && + : >dir3/untracked1 && + : >dir3/untracked2 +' + cat >expect <<EOF # On branch master # Changes to be committed: @@ -140,7 +170,7 @@ cat >expect <<EOF # # new file: dir2/added # -# Changed but not updated: +# 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) # @@ -148,16 +178,14 @@ cat >expect <<EOF # # Untracked files not listed (use -u option to show untracked files) EOF -test_expect_success 'status -uno' ' - mkdir dir3 && - : >dir3/untracked1 && - : >dir3/untracked2 && +test_expect_success C_LOCALE_OUTPUT 'status -uno' ' git status -uno >output && test_cmp expect output ' -test_expect_success 'status (status.showUntrackedFiles no)' ' +test_expect_success C_LOCALE_OUTPUT 'status (status.showUntrackedFiles no)' ' git config status.showuntrackedfiles no + test_when_finished "git config --unset status.showuntrackedfiles" && git status >output && test_cmp expect output ' @@ -167,13 +195,13 @@ cat >expect <<EOF # Changes to be committed: # new file: dir2/added # -# Changed but not updated: +# Changes not staged for commit: # modified: dir1/modified # # Untracked files not listed EOF git config advice.statusHints false -test_expect_success 'status -uno (advice.statusHints false)' ' +test_expect_success C_LOCALE_OUTPUT 'status -uno (advice.statusHints false)' ' git status -uno >output && test_cmp expect output ' @@ -184,7 +212,6 @@ cat >expect << EOF A dir2/added EOF test_expect_success 'status -s -uno' ' - git config --unset status.showuntrackedfiles git status -s -uno >output && test_cmp expect output ' @@ -202,7 +229,7 @@ cat >expect <<EOF # # new file: dir2/added # -# Changed but not updated: +# 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) # @@ -219,13 +246,14 @@ cat >expect <<EOF # output # untracked EOF -test_expect_success 'status -unormal' ' +test_expect_success C_LOCALE_OUTPUT 'status -unormal' ' git status -unormal >output && test_cmp expect output ' -test_expect_success 'status (status.showUntrackedFiles normal)' ' +test_expect_success C_LOCALE_OUTPUT 'status (status.showUntrackedFiles normal)' ' git config status.showuntrackedfiles normal + test_when_finished "git config --unset status.showuntrackedfiles" && git status >output && test_cmp expect output ' @@ -242,7 +270,6 @@ A dir2/added ?? untracked EOF test_expect_success 'status -s -unormal' ' - git config --unset status.showuntrackedfiles git status -s -unormal >output && test_cmp expect output ' @@ -260,7 +287,7 @@ cat >expect <<EOF # # new file: dir2/added # -# Changed but not updated: +# 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) # @@ -278,18 +305,21 @@ cat >expect <<EOF # output # untracked EOF -test_expect_success 'status -uall' ' +test_expect_success C_LOCALE_OUTPUT 'status -uall' ' git status -uall >output && test_cmp expect output ' -test_expect_success 'status (status.showUntrackedFiles all)' ' +test_expect_success C_LOCALE_OUTPUT 'status (status.showUntrackedFiles all)' ' git config status.showuntrackedfiles all + test_when_finished "git config --unset status.showuntrackedfiles" && git status >output && - rm -rf dir3 && - git config --unset status.showuntrackedfiles && test_cmp expect output ' +test_expect_success 'teardown dir3' ' + rm -rf dir3 +' + cat >expect <<EOF M dir1/modified A dir2/added @@ -320,7 +350,7 @@ cat >expect <<\EOF # # new file: ../dir2/added # -# Changed but not updated: +# 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) # @@ -337,7 +367,7 @@ cat >expect <<\EOF # ../untracked EOF -test_expect_success 'status with relative paths' ' +test_expect_success C_LOCALE_OUTPUT 'status with relative paths' ' (cd dir1 && git status) >output && test_cmp expect output @@ -381,18 +411,19 @@ test_expect_success 'status --porcelain ignores relative paths setting' ' test_expect_success 'setup unique colors' ' - git config status.color.untracked blue + git config status.color.untracked blue && + git config status.color.branch green ' cat >expect <<\EOF -# On branch master +# On branch <GREEN>master<RESET> # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # <GREEN>new file: dir2/added<RESET> # -# Changed but not updated: +# 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) # @@ -409,18 +440,19 @@ cat >expect <<\EOF # <BLUE>untracked<RESET> EOF -test_expect_success 'status with color.ui' ' +test_expect_success C_LOCALE_OUTPUT 'status with color.ui' ' git config color.ui always && + test_when_finished "git config --unset color.ui" && git status | test_decode_color >output && test_cmp expect output ' -test_expect_success 'status with color.status' ' +test_expect_success C_LOCALE_OUTPUT 'status with color.status' ' - git config --unset color.ui && git config color.status always && + test_when_finished "git config --unset color.status" && git status | test_decode_color >output && test_cmp expect output @@ -439,7 +471,6 @@ EOF test_expect_success 'status -s with color.ui' ' - git config --unset color.status && git config color.ui always && git status -s | test_decode_color >output && test_cmp expect output @@ -521,7 +552,7 @@ cat >expect <<\EOF # # new file: dir2/added # -# Changed but not updated: +# 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) # @@ -539,9 +570,10 @@ cat >expect <<\EOF EOF -test_expect_success 'status without relative paths' ' +test_expect_success C_LOCALE_OUTPUT 'status without relative paths' ' - git config status.relativePaths false + git config status.relativePaths false && + test_when_finished "git config --unset status.relativePaths" && (cd dir1 && git status) >output && test_cmp expect output @@ -560,6 +592,8 @@ EOF test_expect_success 'status -s without relative paths' ' + git config status.relativePaths false && + test_when_finished "git config --unset status.relativePaths" && (cd dir1 && git status -s) >output && test_cmp expect output @@ -582,7 +616,10 @@ cat <<EOF >expect # untracked EOF test_expect_success 'dry-run of partial commit excluding new file in index' ' - git commit --dry-run dir1/modified >output && + git commit --dry-run dir1/modified >output +' + +test_expect_success C_LOCALE_OUTPUT 'dry-run of partial commit excluding new file in index: output' ' test_cmp expect output ' @@ -614,7 +651,7 @@ cat >expect <<EOF # new file: dir2/added # new file: sm # -# Changed but not updated: +# 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) # @@ -630,13 +667,13 @@ cat >expect <<EOF # output # untracked EOF -test_expect_success 'status submodule summary is disabled by default' ' +test_expect_success C_LOCALE_OUTPUT 'status submodule summary is disabled by default' ' git status >output && test_cmp expect output ' # we expect the same as the previous test -test_expect_success 'status --untracked-files=all does not show submodule' ' +test_expect_success C_LOCALE_OUTPUT 'status --untracked-files=all does not show submodule' ' git status --untracked-files=all >output && test_cmp expect output ' @@ -673,7 +710,7 @@ cat >expect <<EOF # new file: dir2/added # new file: sm # -# Changed but not updated: +# 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) # @@ -694,7 +731,7 @@ cat >expect <<EOF # output # untracked EOF -test_expect_success 'status submodule summary' ' +test_expect_success C_LOCALE_OUTPUT 'status submodule summary' ' git config status.submodulesummary 10 && git status >output && test_cmp expect output @@ -718,7 +755,7 @@ test_expect_success 'status -s submodule summary' ' cat >expect <<EOF # On branch master -# Changed but not updated: +# 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) # @@ -735,8 +772,11 @@ cat >expect <<EOF # untracked no changes added to commit (use "git add" and/or "git commit -a") EOF -test_expect_success 'status submodule summary (clean submodule)' ' - git commit -m "commit submodule" && +test_expect_success 'status submodule summary (clean submodule): commit' ' + git commit -m "commit submodule" +' + +test_expect_success C_LOCALE_OUTPUT 'status submodule summary (clean submodule): output' ' git config status.submodulesummary 10 && test_must_fail git commit --dry-run >output && test_cmp expect output && @@ -766,7 +806,7 @@ cat >expect <<EOF # new file: dir2/added # new file: sm # -# Changed but not updated: +# 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) # @@ -787,7 +827,7 @@ cat >expect <<EOF # output # untracked EOF -test_expect_success 'commit --dry-run submodule summary (--amend)' ' +test_expect_success C_LOCALE_OUTPUT 'commit --dry-run submodule summary (--amend)' ' git config status.submodulesummary 10 && git commit --dry-run --amend >output && test_cmp expect output @@ -819,7 +859,7 @@ cat > expect << EOF # # modified: sm # -# Changed but not updated: +# 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) # @@ -842,13 +882,13 @@ cat > expect << EOF # untracked EOF -test_expect_success '--ignore-submodules=untracked suppresses submodules with untracked content' ' +test_expect_success C_LOCALE_OUTPUT '--ignore-submodules=untracked suppresses submodules with untracked content' ' echo modified > sm/untracked && git status --ignore-submodules=untracked > output && test_cmp expect output ' -test_expect_success '.gitmodules ignore=untracked suppresses submodules with untracked content' ' +test_expect_success C_LOCALE_OUTPUT '.gitmodules ignore=untracked suppresses submodules with untracked content' ' git config diff.ignoreSubmodules dirty && git status >output && test_cmp expect output && @@ -860,7 +900,7 @@ test_expect_success '.gitmodules ignore=untracked suppresses submodules with unt git config --unset diff.ignoreSubmodules ' -test_expect_success '.git/config ignore=untracked suppresses submodules with untracked content' ' +test_expect_success C_LOCALE_OUTPUT '.git/config ignore=untracked suppresses submodules with untracked content' ' git config --add -f .gitmodules submodule.subname.ignore none && git config --add -f .gitmodules submodule.subname.path sm && git config --add submodule.subname.ignore untracked && @@ -871,12 +911,12 @@ test_expect_success '.git/config ignore=untracked suppresses submodules with unt git config --remove-section -f .gitmodules submodule.subname ' -test_expect_success '--ignore-submodules=dirty suppresses submodules with untracked content' ' +test_expect_success C_LOCALE_OUTPUT '--ignore-submodules=dirty suppresses submodules with untracked content' ' git status --ignore-submodules=dirty > output && test_cmp expect output ' -test_expect_success '.gitmodules ignore=dirty suppresses submodules with untracked content' ' +test_expect_success C_LOCALE_OUTPUT '.gitmodules ignore=dirty suppresses submodules with untracked content' ' git config diff.ignoreSubmodules dirty && git status >output && ! test -s actual && @@ -888,7 +928,7 @@ test_expect_success '.gitmodules ignore=dirty suppresses submodules with untrack git config --unset diff.ignoreSubmodules ' -test_expect_success '.git/config ignore=dirty suppresses submodules with untracked content' ' +test_expect_success C_LOCALE_OUTPUT '.git/config ignore=dirty suppresses submodules with untracked content' ' git config --add -f .gitmodules submodule.subname.ignore none && git config --add -f .gitmodules submodule.subname.path sm && git config --add submodule.subname.ignore dirty && @@ -899,13 +939,13 @@ test_expect_success '.git/config ignore=dirty suppresses submodules with untrack git config -f .gitmodules --remove-section submodule.subname ' -test_expect_success '--ignore-submodules=dirty suppresses submodules with modified content' ' +test_expect_success C_LOCALE_OUTPUT '--ignore-submodules=dirty suppresses submodules with modified content' ' echo modified > sm/foo && git status --ignore-submodules=dirty > output && test_cmp expect output ' -test_expect_success '.gitmodules ignore=dirty suppresses submodules with modified content' ' +test_expect_success C_LOCALE_OUTPUT '.gitmodules ignore=dirty suppresses submodules with modified content' ' git config --add -f .gitmodules submodule.subname.ignore dirty && git config --add -f .gitmodules submodule.subname.path sm && git status > output && @@ -913,7 +953,7 @@ test_expect_success '.gitmodules ignore=dirty suppresses submodules with modifie git config -f .gitmodules --remove-section submodule.subname ' -test_expect_success '.git/config ignore=dirty suppresses submodules with modified content' ' +test_expect_success C_LOCALE_OUTPUT '.git/config ignore=dirty suppresses submodules with modified content' ' git config --add -f .gitmodules submodule.subname.ignore none && git config --add -f .gitmodules submodule.subname.path sm && git config --add submodule.subname.ignore dirty && @@ -931,7 +971,7 @@ cat > expect << EOF # # modified: sm # -# Changed but not updated: +# 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) @@ -956,12 +996,12 @@ cat > expect << EOF # untracked EOF -test_expect_success "--ignore-submodules=untracked doesn't suppress submodules with modified content" ' +test_expect_success C_LOCALE_OUTPUT "--ignore-submodules=untracked doesn't suppress submodules with modified content" ' git status --ignore-submodules=untracked > output && test_cmp expect output ' -test_expect_success ".gitmodules ignore=untracked doesn't suppress submodules with modified content" ' +test_expect_success C_LOCALE_OUTPUT ".gitmodules ignore=untracked doesn't suppress submodules with modified content" ' git config --add -f .gitmodules submodule.subname.ignore untracked && git config --add -f .gitmodules submodule.subname.path sm && git status > output && @@ -969,7 +1009,7 @@ test_expect_success ".gitmodules ignore=untracked doesn't suppress submodules wi git config -f .gitmodules --remove-section submodule.subname ' -test_expect_success ".git/config ignore=untracked doesn't suppress submodules with modified content" ' +test_expect_success C_LOCALE_OUTPUT ".git/config ignore=untracked doesn't suppress submodules with modified content" ' git config --add -f .gitmodules submodule.subname.ignore none && git config --add -f .gitmodules submodule.subname.path sm && git config --add submodule.subname.ignore untracked && @@ -989,7 +1029,7 @@ cat > expect << EOF # # modified: sm # -# Changed but not updated: +# 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) # @@ -1018,12 +1058,12 @@ cat > expect << EOF # untracked EOF -test_expect_success "--ignore-submodules=untracked doesn't suppress submodule summary" ' +test_expect_success C_LOCALE_OUTPUT "--ignore-submodules=untracked doesn't suppress submodule summary" ' git status --ignore-submodules=untracked > output && test_cmp expect output ' -test_expect_success ".gitmodules ignore=untracked doesn't suppress submodule summary" ' +test_expect_success C_LOCALE_OUTPUT ".gitmodules ignore=untracked doesn't suppress submodule summary" ' git config --add -f .gitmodules submodule.subname.ignore untracked && git config --add -f .gitmodules submodule.subname.path sm && git status > output && @@ -1031,7 +1071,7 @@ test_expect_success ".gitmodules ignore=untracked doesn't suppress submodule sum git config -f .gitmodules --remove-section submodule.subname ' -test_expect_success ".git/config ignore=untracked doesn't suppress submodule summary" ' +test_expect_success C_LOCALE_OUTPUT ".git/config ignore=untracked doesn't suppress 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 untracked && @@ -1042,11 +1082,11 @@ test_expect_success ".git/config ignore=untracked doesn't suppress submodule sum git config -f .gitmodules --remove-section submodule.subname ' -test_expect_success "--ignore-submodules=dirty doesn't suppress submodule summary" ' +test_expect_success C_LOCALE_OUTPUT "--ignore-submodules=dirty doesn't suppress submodule summary" ' git status --ignore-submodules=dirty > output && test_cmp expect output ' -test_expect_success ".gitmodules ignore=dirty doesn't suppress submodule summary" ' +test_expect_success C_LOCALE_OUTPUT ".gitmodules ignore=dirty doesn't suppress submodule summary" ' git config --add -f .gitmodules submodule.subname.ignore dirty && git config --add -f .gitmodules submodule.subname.path sm && git status > output && @@ -1054,7 +1094,7 @@ test_expect_success ".gitmodules ignore=dirty doesn't suppress submodule summary git config -f .gitmodules --remove-section submodule.subname ' -test_expect_success ".git/config ignore=dirty doesn't suppress submodule summary" ' +test_expect_success C_LOCALE_OUTPUT ".git/config ignore=dirty doesn't suppress 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 dirty && @@ -1067,7 +1107,7 @@ test_expect_success ".git/config ignore=dirty doesn't suppress submodule summary cat > expect << EOF # On branch master -# Changed but not updated: +# 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) # @@ -1086,7 +1126,7 @@ cat > expect << EOF no changes added to commit (use "git add" and/or "git commit -a") EOF -test_expect_success "--ignore-submodules=all suppresses submodule summary" ' +test_expect_success C_LOCALE_OUTPUT "--ignore-submodules=all suppresses submodule summary" ' git status --ignore-submodules=all > output && test_cmp expect output ' diff --git a/t/t7509-commit.sh b/t/t7509-commit.sh index 643ab03f99..b61fd3c3c4 100755 --- a/t/t7509-commit.sh +++ b/t/t7509-commit.sh @@ -40,7 +40,7 @@ test_expect_success '-C option copies only the message with --reset-author' ' test_tick && git commit -a -C Initial --reset-author && echo "author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect && - author_header HEAD >actual + author_header HEAD >actual && test_cmp expect actual && message_body Initial >expect && @@ -157,4 +157,33 @@ test_expect_success '--reset-author should be rejected without -c/-C/--amend' ' test_must_fail git commit -a --reset-author -m done ' +test_expect_success 'commit respects CHERRY_PICK_HEAD and MERGE_MSG' ' + echo "cherry-pick 1a" >>foo && + test_tick && + git commit -am "cherry-pick 1" --author="Cherry <cherry@pick.er>" && + git tag cherry-pick-head && + git rev-parse cherry-pick-head >.git/CHERRY_PICK_HEAD && + echo "This is a MERGE_MSG" >.git/MERGE_MSG && + echo "cherry-pick 1b" >>foo && + test_tick && + git commit -a && + author_header cherry-pick-head >expect && + author_header HEAD >actual && + test_cmp expect actual && + + echo "This is a MERGE_MSG" >expect && + message_body HEAD >actual && + test_cmp expect actual +' + +test_expect_success '--reset-author with CHERRY_PICK_HEAD' ' + git rev-parse cherry-pick-head >.git/CHERRY_PICK_HEAD && + echo "cherry-pick 2" >>foo && + test_tick && + git commit -am "cherry-pick 2" --reset-author && + echo "author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> $GIT_AUTHOR_DATE" >expect && + author_header HEAD >actual && + test_cmp expect actual +' + test_done diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh index b4f40e4c3a..87d5d788cb 100755 --- a/t/t7600-merge.sh +++ b/t/t7600-merge.sh @@ -144,6 +144,17 @@ test_expect_success 'test option parsing' ' test_must_fail git merge ' +test_expect_success 'merge -h with invalid index' ' + mkdir broken && + ( + cd broken && + git init && + >.git/index && + test_expect_code 129 git merge -h 2>usage + ) && + grep "[Uu]sage: git merge" broken/usage +' + test_expect_success 'reject non-strategy with a git-merge-foo name' ' test_must_fail git merge -s index c1 ' @@ -484,7 +495,7 @@ test_expect_success 'merge fast-forward in a dirty tree' ' test_debug 'git log --graph --decorate --oneline --all' -test_expect_success 'in-index merge' ' +test_expect_success C_LOCALE_OUTPUT 'in-index merge' ' git reset --hard c0 && git merge --no-ff -s resolve c1 >out && grep "Wonderful." out && diff --git a/t/t7601-merge-pull-config.sh b/t/t7601-merge-pull-config.sh index 7ba94ea99b..b44b293950 100755 --- a/t/t7601-merge-pull-config.sh +++ b/t/t7601-merge-pull-config.sh @@ -114,13 +114,13 @@ test_expect_success 'setup conflicted merge' ' test_expect_success 'merge picks up the best result' ' git config --unset-all pull.twohead && git reset --hard c5 && - git merge -s resolve c6 + test_must_fail git merge -s resolve c6 && resolve_count=$(conflict_count) && git reset --hard c5 && - git merge -s recursive c6 + test_must_fail git merge -s recursive c6 && recursive_count=$(conflict_count) && git reset --hard c5 && - git merge -s recursive -s resolve c6 + test_must_fail git merge -s recursive -s resolve c6 && auto_count=$(conflict_count) && test $auto_count = $recursive_count && test $auto_count != $resolve_count @@ -129,13 +129,13 @@ test_expect_success 'merge picks up the best result' ' test_expect_success 'merge picks up the best result (from config)' ' git config pull.twohead "recursive resolve" && git reset --hard c5 && - git merge -s resolve c6 + test_must_fail git merge -s resolve c6 && resolve_count=$(conflict_count) && git reset --hard c5 && - git merge -s recursive c6 + test_must_fail git merge -s recursive c6 && recursive_count=$(conflict_count) && git reset --hard c5 && - git merge c6 + test_must_fail git merge c6 && auto_count=$(conflict_count) && test $auto_count = $recursive_count && test $auto_count != $resolve_count diff --git a/t/t7602-merge-octopus-many.sh b/t/t7602-merge-octopus-many.sh index 2746169514..0a46795ae7 100755 --- a/t/t7602-merge-octopus-many.sh +++ b/t/t7602-merge-octopus-many.sh @@ -31,7 +31,7 @@ test_expect_success 'merge c1 with c2, c3, c4, ... c29' ' do refs="$refs c$i" i=`expr $i + 1` - done + done && git merge $refs && test "$(git rev-parse c1)" != "$(git rev-parse HEAD)" && i=1 && diff --git a/t/t7607-merge-overwrite.sh b/t/t7607-merge-overwrite.sh index d82349a6a8..ef84f04102 100755 --- a/t/t7607-merge-overwrite.sh +++ b/t/t7607-merge-overwrite.sh @@ -7,48 +7,54 @@ Do not overwrite changes.' . ./test-lib.sh test_expect_success 'setup' ' - echo c0 > c0.c && - git add c0.c && - git commit -m c0 && - git tag c0 && - echo c1 > c1.c && - git add c1.c && - git commit -m c1 && - git tag c1 && + test_commit c0 c0.c && + test_commit c1 c1.c && + test_commit c1a c1.c "c1 a" && git reset --hard c0 && - echo c2 > c2.c && - git add c2.c && - git commit -m c2 && - git tag c2 && - git reset --hard c1 && - echo "c1 a" > c1.c && - git add c1.c && - git commit -m "c1 a" && - git tag c1a && + test_commit c2 c2.c && + git reset --hard c0 && + mkdir sub && + echo "sub/f" > sub/f && + mkdir sub2 && + echo "sub2/f" > sub2/f && + git add sub/f sub2/f && + git commit -m sub && + git tag sub && echo "VERY IMPORTANT CHANGES" > important ' test_expect_success 'will not overwrite untracked file' ' git reset --hard c1 && - cat important > c2.c && + cp important c2.c && test_must_fail git merge c2 && + test_path_is_missing .git/MERGE_HEAD && test_cmp important c2.c ' +test_expect_success 'will overwrite tracked file' ' + git reset --hard c1 && + cp important c2.c && + git add c2.c && + git commit -m important && + git checkout c2 +' + test_expect_success 'will not overwrite new file' ' git reset --hard c1 && - cat important > c2.c && + cp important c2.c && git add c2.c && test_must_fail git merge c2 && + test_path_is_missing .git/MERGE_HEAD && test_cmp important c2.c ' test_expect_success 'will not overwrite staged changes' ' git reset --hard c1 && - cat important > c2.c && + cp important c2.c && git add c2.c && rm c2.c && test_must_fail git merge c2 && + test_path_is_missing .git/MERGE_HEAD && git checkout c2.c && test_cmp important c2.c ' @@ -57,7 +63,7 @@ test_expect_success 'will not overwrite removed file' ' git reset --hard c1 && git rm c1.c && git commit -m "rm c1.c" && - cat important > c1.c && + cp important c1.c && test_must_fail git merge c1a && test_cmp important c1.c ' @@ -66,9 +72,10 @@ test_expect_success 'will not overwrite re-added file' ' git reset --hard c1 && git rm c1.c && git commit -m "rm c1.c" && - cat important > c1.c && + cp important c1.c && git add c1.c && test_must_fail git merge c1a && + test_path_is_missing .git/MERGE_HEAD && test_cmp important c1.c ' @@ -76,12 +83,104 @@ test_expect_success 'will not overwrite removed file with staged changes' ' git reset --hard c1 && git rm c1.c && git commit -m "rm c1.c" && - cat important > c1.c && + cp important c1.c && git add c1.c && rm c1.c && test_must_fail git merge c1a && + test_path_is_missing .git/MERGE_HEAD && git checkout c1.c && test_cmp important c1.c ' +test_expect_success 'will not overwrite untracked subtree' ' + git reset --hard c0 && + rm -rf sub && + mkdir -p sub/f && + cp important sub/f/important && + test_must_fail git merge sub && + test_path_is_missing .git/MERGE_HEAD && + test_cmp important sub/f/important +' + +cat >expect <<\EOF +error: The following untracked working tree files would be overwritten by merge: + sub + sub2 +Please move or remove them before you can merge. +EOF + +test_expect_success 'will not overwrite untracked file in leading path' ' + git reset --hard c0 && + rm -rf sub && + cp important sub && + cp important sub2 && + test_must_fail git merge sub 2>out && + test_cmp out expect && + test_path_is_missing .git/MERGE_HEAD && + test_cmp important sub && + test_cmp important sub2 && + rm -f sub sub2 +' + +test_expect_success SYMLINKS 'will not overwrite untracked symlink in leading path' ' + git reset --hard c0 && + rm -rf sub && + mkdir sub2 && + ln -s sub2 sub && + test_must_fail git merge sub && + test_path_is_missing .git/MERGE_HEAD +' + +test_expect_success SYMLINKS 'will not be confused by symlink in leading path' ' + git reset --hard c0 && + rm -rf sub && + ln -s sub2 sub && + git add sub && + git commit -m ln && + git checkout sub +' + +cat >expect <<\EOF +error: Untracked working tree file 'c0.c' would be overwritten by merge. +fatal: read-tree failed +EOF + +test_expect_success 'will not overwrite untracked file on unborn branch' ' + git reset --hard c0 && + git rm -fr . && + git checkout --orphan new && + cp important c0.c && + test_must_fail git merge c0 2>out +' + +test_expect_success C_LOCALE_OUTPUT 'will not overwrite untracked file on unborn branch: output' ' + test_cmp out expect +' + +test_expect_success 'will not overwrite untracked file on unborn branch .git/MERGE_HEAD sanity etc.' ' + test_when_finished "rm c0.c" && + test_path_is_missing .git/MERGE_HEAD && + test_cmp important c0.c +' + +test_expect_success 'failed merge leaves unborn branch in the womb' ' + test_must_fail git rev-parse --verify HEAD +' + +test_expect_success 'set up unborn branch and content' ' + git symbolic-ref HEAD refs/heads/unborn && + rm -f .git/index && + echo foo > tracked-file && + git add tracked-file && + echo bar > untracked-file +' + +test_expect_success 'will not clobber WT/index when merging into unborn' ' + git merge master && + grep foo tracked-file && + git show :tracked-file >expect && + grep foo expect && + grep bar untracked-file +' + test_done diff --git a/t/t7608-merge-messages.sh b/t/t7608-merge-messages.sh index 28d56797b1..9225fa6f02 100755 --- a/t/t7608-merge-messages.sh +++ b/t/t7608-merge-messages.sh @@ -47,14 +47,14 @@ test_expect_success 'ambiguous tag' ' check_oneline "Merge commit QambiguousQ" ' -test_expect_success 'remote branch' ' +test_expect_success 'remote-tracking branch' ' git checkout -b remote master && test_commit remote-1 && git update-ref refs/remotes/origin/master remote && git checkout master && test_commit master-5 && git merge origin/master && - check_oneline "Merge remote branch Qorigin/masterQ" + check_oneline "Merge remote-tracking branch Qorigin/masterQ" ' test_done diff --git a/t/t7609-merge-co-error-msgs.sh b/t/t7609-merge-co-error-msgs.sh index 114d2bd785..c994836c53 100755 --- a/t/t7609-merge-co-error-msgs.sh +++ b/t/t7609-merge-co-error-msgs.sh @@ -27,10 +27,10 @@ test_expect_success 'setup' ' cat >expect <<\EOF error: The following untracked working tree files would be overwritten by merge: - two - three - four five + four + three + two Please move or remove them before you can merge. EOF @@ -49,9 +49,9 @@ test_expect_success 'untracked files overwritten by merge (fast and non-fast for cat >expect <<\EOF error: Your local changes to the following files would be overwritten by merge: - two - three four + three + two Please, commit your changes or stash them before you can merge. error: The following untracked working tree files would be overwritten by merge: five @@ -68,8 +68,8 @@ test_expect_success 'untracked files or local changes ovewritten by merge' ' cat >expect <<\EOF error: Your local changes to the following files would be overwritten by checkout: - rep/two rep/one + rep/two Please, commit your changes or stash them before you can switch branches. EOF @@ -89,8 +89,8 @@ test_expect_success 'cannot switch branches because of local changes' ' cat >expect <<\EOF error: Your local changes to the following files would be overwritten by checkout: - rep/two rep/one + rep/two Please, commit your changes or stash them before you can switch branches. EOF @@ -102,8 +102,8 @@ test_expect_success 'not uptodate file porcelain checkout error' ' cat >expect <<\EOF error: Updating the following directories would lose untracked files in it: - rep2 rep + rep2 EOF diff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh index 3bd74042ef..dc838c93bc 100755 --- a/t/t7610-mergetool.sh +++ b/t/t7610-mergetool.sh @@ -16,23 +16,33 @@ Testing basic merge tool invocation' test_expect_success 'setup' ' git config rerere.enabled true && echo master >file1 && + echo master file11 >file11 && + echo master file12 >file12 && + echo master file13 >file13 && + echo master file14 >file14 && mkdir subdir && echo master sub >subdir/file3 && - git add file1 subdir/file3 && - git commit -m "added file1" && + git add file1 file1[1-4] subdir/file3 && + git commit -m "add initial versions" && git checkout -b branch1 master && echo branch1 change >file1 && echo branch1 newfile >file2 && + echo branch1 change file11 >file11 && + echo branch1 change file13 >file13 && echo branch1 sub >subdir/file3 && - git add file1 file2 subdir/file3 && + git add file1 file11 file13 file2 subdir/file3 && + git rm file12 && git commit -m "branch1 changes" && git checkout master && echo master updated >file1 && echo master new >file2 && + echo master updated file12 >file12 && + echo master updated file14 >file14 && echo master new sub >subdir/file3 && - git add file1 file2 subdir/file3 && + git add file1 file12 file14 file2 subdir/file3 && + git rm file11 && git commit -m "master updates" && git config merge.tool mytool && @@ -46,6 +56,8 @@ test_expect_success 'custom mergetool' ' ( yes "" | git mergetool file1 >/dev/null 2>&1 ) && ( yes "" | git mergetool file2 >/dev/null 2>&1 ) && ( yes "" | git mergetool subdir/file3 >/dev/null 2>&1 ) && + ( yes "d" | git mergetool file11 >/dev/null 2>&1 ) && + ( yes "d" | git mergetool file12 >/dev/null 2>&1 ) && test "$(cat file1)" = "master updated" && test "$(cat file2)" = "master new" && test "$(cat subdir/file3)" = "master new sub" && @@ -54,11 +66,13 @@ test_expect_success 'custom mergetool' ' test_expect_success 'mergetool crlf' ' git config core.autocrlf true && - git checkout -b test2 branch1 + git checkout -b test2 branch1 && test_must_fail git merge master >/dev/null 2>&1 && ( yes "" | git mergetool file1 >/dev/null 2>&1 ) && ( yes "" | git mergetool file2 >/dev/null 2>&1 ) && ( yes "" | git mergetool subdir/file3 >/dev/null 2>&1 ) && + ( yes "d" | git mergetool file11 >/dev/null 2>&1 ) && + ( yes "d" | git mergetool file12 >/dev/null 2>&1 ) && test "$(printf x | cat file1 -)" = "$(printf "master updated\r\nx")" && test "$(printf x | cat file2 -)" = "$(printf "master new\r\nx")" && test "$(printf x | cat subdir/file3 -)" = "$(printf "master new sub\r\nx")" && @@ -82,6 +96,8 @@ test_expect_success 'mergetool on file in parent dir' ' cd subdir && ( yes "" | git mergetool ../file1 >/dev/null 2>&1 ) && ( yes "" | git mergetool ../file2 >/dev/null 2>&1 ) && + ( yes "d" | git mergetool ../file11 >/dev/null 2>&1 ) && + ( yes "d" | git mergetool ../file12 >/dev/null 2>&1 ) && test "$(cat ../file1)" = "master updated" && test "$(cat ../file2)" = "master new" && git commit -m "branch1 resolved with mergetool - subdir" @@ -92,6 +108,8 @@ test_expect_success 'mergetool skips autoresolved' ' git checkout -b test4 branch1 && test_must_fail git merge master && test -n "$(git ls-files -u)" && + ( yes "d" | git mergetool file11 >/dev/null 2>&1 ) && + ( yes "d" | git mergetool file12 >/dev/null 2>&1 ) && output="$(git mergetool --no-prompt)" && test "$output" = "No files need merging" && git reset --hard @@ -102,13 +120,23 @@ test_expect_success 'mergetool merges all from subdir' ' cd subdir && git config rerere.enabled false && test_must_fail git merge master && - git mergetool --no-prompt && + ( yes "d" "d" | git mergetool --no-prompt ) && test "$(cat ../file1)" = "master updated" && test "$(cat ../file2)" = "master new" && test "$(cat file3)" = "master new sub" && - git add ../file1 ../file2 file3 && git commit -m "branch2 resolved by mergetool from subdir" ) ' +test_expect_success 'mergetool skips resolved paths when rerere is active' ' + git config rerere.enabled true && + rm -rf .git/rr-cache && + git checkout -b test5 branch1 + test_must_fail git merge master >/dev/null 2>&1 && + ( yes "d" "d" | git mergetool --no-prompt >/dev/null 2>&1 ) && + output="$(yes "n" | git mergetool --no-prompt)" && + test "$output" = "No files need merging" && + git reset --hard +' + test_done diff --git a/t/t7611-merge-abort.sh b/t/t7611-merge-abort.sh new file mode 100755 index 0000000000..cdb3f444cd --- /dev/null +++ b/t/t7611-merge-abort.sh @@ -0,0 +1,325 @@ +#!/bin/sh + +test_description='test aborting in-progress merges + +Set up repo with conflicting and non-conflicting branches: + +There are three files foo/bar/baz, and the following graph illustrates the +content of these files in each commit: + +# foo/bar/baz --- foo/bar/bazz <-- master +# \ +# --- foo/barf/bazf <-- conflict_branch +# \ +# --- foo/bart/baz <-- clean_branch + +Next, test git merge --abort with the following variables: +- before/after successful merge (should fail when not in merge context) +- with/without conflicts +- clean/dirty index before merge +- clean/dirty worktree before merge +- dirty index before merge matches contents on remote branch +- changed/unchanged worktree after merge +- changed/unchanged index after merge +' +. ./test-lib.sh + +test_expect_success 'setup' ' + # Create the above repo + echo foo > foo && + echo bar > bar && + echo baz > baz && + git add foo bar baz && + git commit -m initial && + echo bazz > baz && + git commit -a -m "second" && + git checkout -b conflict_branch HEAD^ && + echo barf > bar && + echo bazf > baz && + git commit -a -m "conflict" && + git checkout -b clean_branch HEAD^ && + echo bart > bar && + git commit -a -m "clean" && + git checkout master +' + +pre_merge_head="$(git rev-parse HEAD)" + +test_expect_success 'fails without MERGE_HEAD (unstarted merge)' ' + test_must_fail git merge --abort 2>output +' + +test_expect_success C_LOCALE_OUTPUT 'fails without MERGE_HEAD (unstarted merge): fatal output' ' + grep -q MERGE_HEAD output +' + +test_expect_success 'fails without MERGE_HEAD (unstarted merge): .git/MERGE_HEAD sanity' ' + test ! -f .git/MERGE_HEAD && + test "$pre_merge_head" = "$(git rev-parse HEAD)" +' + +test_expect_success 'fails without MERGE_HEAD (completed merge)' ' + git merge clean_branch && + test ! -f .git/MERGE_HEAD && + # Merge successfully completed + post_merge_head="$(git rev-parse HEAD)" && + test_must_fail git merge --abort 2>output +' + +test_expect_success C_LOCALE_OUTPUT 'fails without MERGE_HEAD (completed merge): output' ' + grep -q MERGE_HEAD output +' + +test_expect_success 'fails without MERGE_HEAD (completed merge): .git/MERGE_HEAD sanity' ' + test ! -f .git/MERGE_HEAD && + test "$post_merge_head" = "$(git rev-parse HEAD)" +' + +test_expect_success 'Forget previous merge' ' + git reset --hard "$pre_merge_head" +' + +test_expect_success 'Abort after --no-commit' ' + # Redo merge, but stop before creating merge commit + git merge --no-commit clean_branch && + test -f .git/MERGE_HEAD && + # Abort non-conflicting merge + git merge --abort && + test ! -f .git/MERGE_HEAD && + test "$pre_merge_head" = "$(git rev-parse HEAD)" && + test -z "$(git diff)" && + test -z "$(git diff --staged)" +' + +test_expect_success 'Abort after conflicts' ' + # Create conflicting merge + test_must_fail git merge conflict_branch && + test -f .git/MERGE_HEAD && + # Abort conflicting merge + git merge --abort && + test ! -f .git/MERGE_HEAD && + test "$pre_merge_head" = "$(git rev-parse HEAD)" && + test -z "$(git diff)" && + test -z "$(git diff --staged)" +' + +test_expect_success 'Clean merge with dirty index fails' ' + echo xyzzy >> foo && + git add foo && + git diff --staged > expect && + test_must_fail git merge clean_branch && + test ! -f .git/MERGE_HEAD && + test "$pre_merge_head" = "$(git rev-parse HEAD)" && + test -z "$(git diff)" && + git diff --staged > actual && + test_cmp expect actual +' + +test_expect_success 'Conflicting merge with dirty index fails' ' + test_must_fail git merge conflict_branch && + test ! -f .git/MERGE_HEAD && + test "$pre_merge_head" = "$(git rev-parse HEAD)" && + test -z "$(git diff)" && + git diff --staged > actual && + test_cmp expect actual +' + +test_expect_success 'Reset index (but preserve worktree changes)' ' + git reset "$pre_merge_head" && + git diff > actual && + test_cmp expect actual +' + +test_expect_success 'Abort clean merge with non-conflicting dirty worktree' ' + git merge --no-commit clean_branch && + test -f .git/MERGE_HEAD && + # Abort merge + git merge --abort && + test ! -f .git/MERGE_HEAD && + test "$pre_merge_head" = "$(git rev-parse HEAD)" && + test -z "$(git diff --staged)" && + git diff > actual && + test_cmp expect actual +' + +test_expect_success 'Abort conflicting merge with non-conflicting dirty worktree' ' + test_must_fail git merge conflict_branch && + test -f .git/MERGE_HEAD && + # Abort merge + git merge --abort && + test ! -f .git/MERGE_HEAD && + test "$pre_merge_head" = "$(git rev-parse HEAD)" && + test -z "$(git diff --staged)" && + git diff > actual && + test_cmp expect actual +' + +test_expect_success 'Reset worktree changes' ' + git reset --hard "$pre_merge_head" +' + +test_expect_success 'Fail clean merge with conflicting dirty worktree' ' + echo xyzzy >> bar && + git diff > expect && + test_must_fail git merge --no-commit clean_branch && + test ! -f .git/MERGE_HEAD && + test "$pre_merge_head" = "$(git rev-parse HEAD)" && + test -z "$(git diff --staged)" && + git diff > actual && + test_cmp expect actual +' + +test_expect_success 'Fail conflicting merge with conflicting dirty worktree' ' + test_must_fail git merge conflict_branch && + test ! -f .git/MERGE_HEAD && + test "$pre_merge_head" = "$(git rev-parse HEAD)" && + test -z "$(git diff --staged)" && + git diff > actual && + test_cmp expect actual +' + +test_expect_success 'Reset worktree changes' ' + git reset --hard "$pre_merge_head" +' + +test_expect_success 'Fail clean merge with matching dirty worktree' ' + echo bart > bar && + git diff > expect && + test_must_fail git merge --no-commit clean_branch && + test ! -f .git/MERGE_HEAD && + test "$pre_merge_head" = "$(git rev-parse HEAD)" && + test -z "$(git diff --staged)" && + git diff > actual && + test_cmp expect actual +' + +test_expect_success 'Abort clean merge with matching dirty index' ' + git add bar && + git diff --staged > expect && + git merge --no-commit clean_branch && + test -f .git/MERGE_HEAD && + ### When aborting the merge, git will discard all staged changes, + ### including those that were staged pre-merge. In other words, + ### --abort will LOSE any staged changes (the staged changes that + ### are lost must match the merge result, or the merge would not + ### have been allowed to start). Change expectations accordingly: + rm expect && + touch expect && + # Abort merge + git merge --abort && + test ! -f .git/MERGE_HEAD && + test "$pre_merge_head" = "$(git rev-parse HEAD)" && + git diff --staged > actual && + test_cmp expect actual && + test -z "$(git diff)" +' + +test_expect_success 'Reset worktree changes' ' + git reset --hard "$pre_merge_head" +' + +test_expect_success 'Fail conflicting merge with matching dirty worktree' ' + echo barf > bar && + git diff > expect && + test_must_fail git merge conflict_branch && + test ! -f .git/MERGE_HEAD && + test "$pre_merge_head" = "$(git rev-parse HEAD)" && + test -z "$(git diff --staged)" && + git diff > actual && + test_cmp expect actual +' + +test_expect_success 'Abort conflicting merge with matching dirty index' ' + git add bar && + git diff --staged > expect && + test_must_fail git merge conflict_branch && + test -f .git/MERGE_HEAD && + ### When aborting the merge, git will discard all staged changes, + ### including those that were staged pre-merge. In other words, + ### --abort will LOSE any staged changes (the staged changes that + ### are lost must match the merge result, or the merge would not + ### have been allowed to start). Change expectations accordingly: + rm expect && + touch expect && + # Abort merge + git merge --abort && + test ! -f .git/MERGE_HEAD && + test "$pre_merge_head" = "$(git rev-parse HEAD)" && + git diff --staged > actual && + test_cmp expect actual && + test -z "$(git diff)" +' + +test_expect_success 'Reset worktree changes' ' + git reset --hard "$pre_merge_head" +' + +test_expect_success 'Abort merge with pre- and post-merge worktree changes' ' + # Pre-merge worktree changes + echo xyzzy > foo && + echo barf > bar && + git add bar && + git diff > expect && + git diff --staged > expect-staged && + # Perform merge + test_must_fail git merge conflict_branch && + test -f .git/MERGE_HEAD && + # Post-merge worktree changes + echo yzxxz > foo && + echo blech > baz && + ### When aborting the merge, git will discard staged changes (bar) + ### and unmerged changes (baz). Other changes that are neither + ### staged nor marked as unmerged (foo), will be preserved. For + ### these changed, git cannot tell pre-merge changes apart from + ### post-merge changes, so the post-merge changes will be + ### preserved. Change expectations accordingly: + git diff -- foo > expect && + rm expect-staged && + touch expect-staged && + # Abort merge + git merge --abort && + test ! -f .git/MERGE_HEAD && + test "$pre_merge_head" = "$(git rev-parse HEAD)" && + git diff > actual && + test_cmp expect actual && + git diff --staged > actual-staged && + test_cmp expect-staged actual-staged +' + +test_expect_success 'Reset worktree changes' ' + git reset --hard "$pre_merge_head" +' + +test_expect_success 'Abort merge with pre- and post-merge index changes' ' + # Pre-merge worktree changes + echo xyzzy > foo && + echo barf > bar && + git add bar && + git diff > expect && + git diff --staged > expect-staged && + # Perform merge + test_must_fail git merge conflict_branch && + test -f .git/MERGE_HEAD && + # Post-merge worktree changes + echo yzxxz > foo && + echo blech > baz && + git add foo bar && + ### When aborting the merge, git will discard all staged changes + ### (foo, bar and baz), and no changes will be preserved. Whether + ### the changes were staged pre- or post-merge does not matter + ### (except for not preventing starting the merge). + ### Change expectations accordingly: + rm expect expect-staged && + touch expect && + touch expect-staged && + # Abort merge + git merge --abort && + test ! -f .git/MERGE_HEAD && + test "$pre_merge_head" = "$(git rev-parse HEAD)" && + git diff > actual && + test_cmp expect actual && + git diff --staged > actual-staged && + test_cmp expect-staged actual-staged +' + +test_done diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index c2f66ff170..d954b846a1 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -56,7 +56,7 @@ test_expect_success 'loose objects in alternate ODB are not repacked' ' ' test_expect_success 'packed obs in alt ODB are repacked even when local repo is packless' ' - mkdir alt_objects/pack + mkdir alt_objects/pack && mv .git/objects/pack/* alt_objects/pack && git repack -a && myidx=$(ls -1 .git/objects/pack/*.idx) && @@ -95,14 +95,14 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' ' # swap the .keep so the commit object is in the pack with .keep for p in alt_objects/pack/*.pack do - base_name=$(basename $p .pack) + base_name=$(basename $p .pack) && if test -f alt_objects/pack/$base_name.keep then rm alt_objects/pack/$base_name.keep else touch alt_objects/pack/$base_name.keep fi - done + done && git repack -a -d && myidx=$(ls -1 .git/objects/pack/*.idx) && test -f "$myidx" && diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh index 58dc6f6452..4048d106d4 100755 --- a/t/t7800-difftool.sh +++ b/t/t7800-difftool.sh @@ -98,7 +98,7 @@ test_expect_success PERL 'difftool --gui works without configured diff.guitool' # Specify the diff tool using $GIT_DIFF_TOOL test_expect_success PERL 'GIT_DIFF_TOOL variable' ' - git config --unset diff.tool + test_might_fail git config --unset diff.tool && GIT_DIFF_TOOL=test-tool && export GIT_DIFF_TOOL && @@ -166,7 +166,7 @@ test_expect_success PERL 'difftool.prompt config variable is false' ' # Test that we don't have to pass --no-prompt when mergetool.prompt is false test_expect_success PERL 'difftool merge.prompt = false' ' - git config --unset difftool.prompt + test_might_fail git config --unset difftool.prompt && git config mergetool.prompt false && diff=$(git difftool branch) && @@ -211,7 +211,7 @@ test_expect_success PERL 'difftool last flag wins' ' # git-difftool falls back to git-mergetool config variables # so test that behavior here test_expect_success PERL 'difftool + mergetool config variables' ' - remove_config_vars + remove_config_vars && git config merge.tool test-tool && git config mergetool.test-tool.cmd "cat \$LOCAL" && @@ -254,17 +254,17 @@ test_expect_success PERL 'difftool -x cat' ' ' test_expect_success PERL 'difftool --extcmd echo arg1' ' - diff=$(git difftool --no-prompt --extcmd sh\ -c\ \"echo\ \$1\" branch) + diff=$(git difftool --no-prompt --extcmd sh\ -c\ \"echo\ \$1\" branch) && test "$diff" = file ' test_expect_success PERL 'difftool --extcmd cat arg1' ' - diff=$(git difftool --no-prompt --extcmd sh\ -c\ \"cat\ \$1\" branch) + diff=$(git difftool --no-prompt --extcmd sh\ -c\ \"cat\ \$1\" branch) && test "$diff" = master ' test_expect_success PERL 'difftool --extcmd cat arg2' ' - diff=$(git difftool --no-prompt --extcmd sh\ -c\ \"cat\ \$2\" branch) + diff=$(git difftool --no-prompt --extcmd sh\ -c\ \"cat\ \$2\" branch) && test "$diff" = branch ' diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh index 023f225a4b..8184c264cf 100755 --- a/t/t7810-grep.sh +++ b/t/t7810-grep.sh @@ -59,7 +59,29 @@ do echo ${HC}file:4:foo mmap bar_mmap echo ${HC}file:5:foo_mmap bar mmap baz } >expected && - git grep -n -w -e mmap $H >actual && + git -c grep.linenumber=false grep -n -w -e mmap $H >actual && + test_cmp expected actual + ' + + test_expect_success "grep -w $L" ' + { + echo ${HC}file:1:foo mmap bar + echo ${HC}file:3:foo_mmap bar mmap + echo ${HC}file:4:foo mmap bar_mmap + echo ${HC}file:5:foo_mmap bar mmap baz + } >expected && + git -c grep.linenumber=true grep -w -e mmap $H >actual && + test_cmp expected actual + ' + + test_expect_success "grep -w $L" ' + { + echo ${HC}file:foo mmap bar + echo ${HC}file:foo_mmap bar mmap + echo ${HC}file:foo mmap bar_mmap + echo ${HC}file:foo_mmap bar mmap baz + } >expected && + git -c grep.linenumber=true grep --no-line-number -w -e mmap $H >actual && test_cmp expected actual ' @@ -182,6 +204,24 @@ do test_cmp expected actual ' + test_expect_success "grep --max-depth 0 -- . t $L" ' + { + echo ${HC}t/v:1:vvv + echo ${HC}v:1:vvv + } >expected && + git grep --max-depth 0 -n -e vvv $H -- . t >actual && + test_cmp expected actual + ' + + test_expect_success "grep --max-depth 0 -- t . $L" ' + { + echo ${HC}t/v:1:vvv + echo ${HC}v:1:vvv + } >expected && + git grep --max-depth 0 -n -e vvv $H -- t . >actual && + test_cmp expected actual + ' + done cat >expected <<EOF @@ -285,6 +325,11 @@ test_expect_success 'grep -f, ignore empty lines' ' test_cmp expected actual ' +test_expect_success 'grep -f, ignore empty lines, read patterns from stdin' ' + git grep -f - <patterns >actual && + test_cmp expected actual +' + cat >expected <<EOF y:y yy -- @@ -324,8 +369,13 @@ test_expect_success 'log grep setup' ' echo a >>file && test_tick && - git commit -a -m "third" + git commit -a -m "third" && + echo a >>file && + test_tick && + GIT_AUTHOR_NAME="Night Fall" \ + GIT_AUTHOR_EMAIL="nitfol@frobozz.com" \ + git commit -a -m "fourth" ' test_expect_success 'log grep (1)' ' @@ -372,6 +422,28 @@ test_expect_success 'log --grep --author implicitly uses all-match' ' test_cmp expect actual ' +test_expect_success 'log with multiple --author uses union' ' + git log --author="Thor" --author="Aster" --format=%s >actual && + { + echo third && echo second && echo initial + } >expect && + test_cmp expect actual +' + +test_expect_success 'log with --grep and multiple --author uses all-match' ' + git log --author="Thor" --author="Night" --grep=i --format=%s >actual && + { + echo third && echo initial + } >expect && + test_cmp expect actual +' + +test_expect_success 'log with --grep and multiple --author uses all-match' ' + git log --author="Thor" --author="Night" --grep=q --format=%s >actual && + >expect && + test_cmp expect actual +' + test_expect_success 'grep with CE_VALID file' ' git update-index --assume-unchanged t/t && rm t/t && @@ -452,7 +524,7 @@ test_expect_success 'outside of git repository' ' echo file1:hello && echo sub/file2:world } >non/expect.full && - echo file2:world >non/expect.sub + echo file2:world >non/expect.sub && ( GIT_CEILING_DIRECTORIES="$(pwd)/non/git" && export GIT_CEILING_DIRECTORIES && @@ -478,7 +550,7 @@ test_expect_success 'inside git repository but with --no-index' ' echo sub/file2:world } >is/expect.full && : >is/expect.empty && - echo file2:world >is/expect.sub + echo file2:world >is/expect.sub && ( cd is/git && git init && diff --git a/t/t7811-grep-open.sh b/t/t7811-grep-open.sh index 568a6f2b69..aedf484fee 100755 --- a/t/t7811-grep-open.sh +++ b/t/t7811-grep-open.sh @@ -61,7 +61,7 @@ test_expect_success SIMPLEPAGER 'git grep -O' ' test_cmp empty out ' -test_expect_success 'git grep -O --cached' ' +test_expect_success C_LOCALE_OUTPUT 'git grep -O --cached' ' test_must_fail git grep --cached -O GREP_PATTERN >out 2>msg && grep open-files-in-pager msg ' diff --git a/t/t8001-annotate.sh b/t/t8001-annotate.sh index 45cb60ea4b..41962f04a7 100755 --- a/t/t8001-annotate.sh +++ b/t/t8001-annotate.sh @@ -6,10 +6,11 @@ test_description='git annotate' PROG='git annotate' . "$TEST_DIRECTORY"/annotate-tests.sh -test_expect_success \ - 'Annotating an old revision works' \ - '[ $(git annotate file master | awk "{print \$3}" | grep -c "^A$") -eq 2 ] && \ - [ $(git annotate file master | awk "{print \$3}" | grep -c "^B$") -eq 2 ]' - +test_expect_success 'Annotating an old revision works' ' + git annotate file master >result && + awk "{ print \$3; }" <result >authors && + test 2 = $(grep A <authors | wc -l) && + test 2 = $(grep B <authors | wc -l) +' test_done diff --git a/t/t8002-blame.sh b/t/t8002-blame.sh index 597cf0486f..d3a51e1269 100755 --- a/t/t8002-blame.sh +++ b/t/t8002-blame.sh @@ -6,4 +6,9 @@ test_description='git blame' PROG='git blame -c' . "$TEST_DIRECTORY"/annotate-tests.sh +PROG='git blame -c -e' +test_expect_success 'Blame --show-email works' ' + check_count "<A@test.git>" 1 "<B@test.git>" 1 "<B1@test.git>" 1 "<B2@test.git>" 1 "<author@example.com>" 1 "<C@test.git>" 1 "<D@test.git>" 1 +' + test_done diff --git a/t/t8003-blame.sh b/t/t8003-blame-corner-cases.sh index 230143cf31..230143cf31 100755 --- a/t/t8003-blame.sh +++ b/t/t8003-blame-corner-cases.sh diff --git a/t/t8004-blame.sh b/t/t8004-blame-with-conflicts.sh index ba19ac127e..ba19ac127e 100755 --- a/t/t8004-blame.sh +++ b/t/t8004-blame-with-conflicts.sh diff --git a/t/t8006-blame-textconv.sh b/t/t8006-blame-textconv.sh index 9ad96d4d32..32ec82ad67 100755 --- a/t/t8006-blame-textconv.sh +++ b/t/t8006-blame-textconv.sh @@ -9,22 +9,30 @@ find_blame() { cat >helper <<'EOF' #!/bin/sh -sed 's/^/converted: /' "$@" +grep -q '^bin: ' "$1" || { echo "E: $1 is not \"binary\" file" 1>&2; exit 1; } +sed 's/^bin: /converted: /' "$1" EOF chmod +x helper test_expect_success 'setup ' ' - echo test 1 >one.bin && - echo test number 2 >two.bin && + echo "bin: test 1" >one.bin && + echo "bin: test number 2" >two.bin && + if test_have_prereq SYMLINKS; then + ln -s one.bin symlink.bin + fi && git add . && GIT_AUTHOR_NAME=Number1 git commit -a -m First --date="2010-01-01 18:00:00" && - echo test 1 version 2 >one.bin && - echo test number 2 version 2 >>two.bin && + echo "bin: test 1 version 2" >one.bin && + echo "bin: test number 2 version 2" >>two.bin && + if test_have_prereq SYMLINKS; then + rm symlink.bin && + ln -s two.bin symlink.bin + fi && GIT_AUTHOR_NAME=Number2 git commit -a -m Second --date="2010-01-01 20:00:00" ' cat >expected <<EOF -(Number2 2010-01-01 20:00:00 +0000 1) test 1 version 2 +(Number2 2010-01-01 20:00:00 +0000 1) bin: test 1 version 2 EOF test_expect_success 'no filter specified' ' @@ -66,8 +74,29 @@ test_expect_success 'blame --textconv going through revisions' ' test_cmp expected result ' +test_expect_success 'setup +cachetextconv' ' + git config diff.test.cachetextconv true +' + +cat >expected_one <<EOF +(Number2 2010-01-01 20:00:00 +0000 1) converted: test 1 version 2 +EOF + +test_expect_success 'blame --textconv works with textconvcache' ' + git blame --textconv two.bin >blame && + find_blame <blame >result && + test_cmp expected result && + git blame --textconv one.bin >blame && + find_blame <blame >result && + test_cmp expected_one result +' + +test_expect_success 'setup -cachetextconv' ' + git config diff.test.cachetextconv false +' + test_expect_success 'make a new commit' ' - echo "test number 2 version 3" >>two.bin && + echo "bin: test number 2 version 3" >>two.bin && GIT_AUTHOR_NAME=Number3 git commit -a -m Third --date="2010-01-01 22:00:00" ' @@ -77,4 +106,45 @@ test_expect_success 'blame from previous revision' ' test_cmp expected result ' +cat >expected <<EOF +(Number2 2010-01-01 20:00:00 +0000 1) two.bin +EOF + +test_expect_success SYMLINKS 'blame with --no-textconv (on symlink)' ' + git blame --no-textconv symlink.bin >blame && + find_blame <blame >result && + test_cmp expected result +' + +test_expect_success SYMLINKS 'blame --textconv (on symlink)' ' + git blame --textconv symlink.bin >blame && + find_blame <blame >result && + test_cmp expected result +' + +# cp two.bin three.bin and make small tweak +# (this will direct blame -C -C three.bin to consider two.bin and symlink.bin) +test_expect_success SYMLINKS 'make another new commit' ' + cat >three.bin <<\EOF && +bin: test number 2 +bin: test number 2 version 2 +bin: test number 2 version 3 +bin: test number 3 +EOF + git add three.bin && + GIT_AUTHOR_NAME=Number4 git commit -a -m Fourth --date="2010-01-01 23:00:00" +' + +test_expect_success SYMLINKS 'blame on last commit (-C -C, symlink)' ' + git blame -C -C three.bin >blame && + find_blame <blame >result && + cat >expected <<\EOF && +(Number1 2010-01-01 18:00:00 +0000 1) converted: test number 2 +(Number2 2010-01-01 20:00:00 +0000 2) converted: test number 2 version 2 +(Number3 2010-01-01 22:00:00 +0000 3) converted: test number 2 version 3 +(Number4 2010-01-01 23:00:00 +0000 4) converted: test number 3 +EOF + test_cmp expected result +' + test_done diff --git a/t/t8007-cat-file-textconv.sh b/t/t8007-cat-file-textconv.sh index 38ac05e4a0..78a0085e64 100755 --- a/t/t8007-cat-file-textconv.sh +++ b/t/t8007-cat-file-textconv.sh @@ -5,15 +5,19 @@ test_description='git cat-file textconv support' cat >helper <<'EOF' #!/bin/sh -sed 's/^/converted: /' "$@" +grep -q '^bin: ' "$1" || { echo "E: $1 is not \"binary\" file" 1>&2; exit 1; } +sed 's/^bin: /converted: /' "$1" EOF chmod +x helper test_expect_success 'setup ' ' - echo test >one.bin && + echo "bin: test" >one.bin && + if test_have_prereq SYMLINKS; then + ln -s one.bin symlink.bin + fi && git add . && GIT_AUTHOR_NAME=Number1 git commit -a -m First --date="2010-01-01 18:00:00" && - echo test version 2 >one.bin && + echo "bin: test version 2" >one.bin && GIT_AUTHOR_NAME=Number2 git commit -a -m Second --date="2010-01-01 20:00:00" ' @@ -33,7 +37,7 @@ test_expect_success 'setup textconv filters' ' ' cat >expected <<EOF -test version 2 +bin: test version 2 EOF test_expect_success 'cat-file without --textconv' ' @@ -42,7 +46,7 @@ test_expect_success 'cat-file without --textconv' ' ' cat >expected <<EOF -test +bin: test EOF test_expect_success 'cat-file without --textconv on previous commit' ' @@ -67,4 +71,28 @@ test_expect_success 'cat-file --textconv on previous commit' ' git cat-file --textconv HEAD^:one.bin >result && test_cmp expected result ' + +test_expect_success SYMLINKS 'cat-file without --textconv (symlink)' ' + git cat-file blob :symlink.bin >result && + printf "%s" "one.bin" >expected + test_cmp expected result +' + + +test_expect_success SYMLINKS '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 + test_cmp expected result +' + +test_expect_success SYMLINKS '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 + test_cmp expected result +' + test_done diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index 71b3df9b55..579ddb7572 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -201,10 +201,28 @@ test_expect_success $PREREQ 'Prompting works' ' grep "^To: to@example.com\$" msgtxt1 ' +test_expect_success $PREREQ 'tocmd works' ' + clean_fake_sendmail && + cp $patches tocmd.patch && + echo tocmd--tocmd@example.com >>tocmd.patch && + { + echo "#!$SHELL_PATH" + echo sed -n -e s/^tocmd--//p \"\$1\" + } > tocmd-sed && + chmod +x tocmd-sed && + git send-email \ + --from="Example <nobody@example.com>" \ + --to-cmd=./tocmd-sed \ + --smtp-server="$(pwd)/fake.sendmail" \ + tocmd.patch \ + && + grep "^To: tocmd@example.com" msgtxt1 +' + test_expect_success $PREREQ 'cccmd works' ' clean_fake_sendmail && cp $patches cccmd.patch && - echo cccmd--cccmd@example.com >>cccmd.patch && + echo "cccmd-- cccmd@example.com" >>cccmd.patch && { echo "#!$SHELL_PATH" echo sed -n -e s/^cccmd--//p \"\$1\" @@ -247,7 +265,7 @@ test_expect_success $PREREQ 'Author From: in message body' ' --to=nobody@example.com \ --smtp-server="$(pwd)/fake.sendmail" \ $patches && - sed "1,/^\$/d" < msgtxt1 > msgbody1 + sed "1,/^\$/d" < msgtxt1 > msgbody1 && grep "From: A <author@example.com>" msgbody1 ' @@ -258,7 +276,7 @@ test_expect_success $PREREQ 'Author From: not in message body' ' --to=nobody@example.com \ --smtp-server="$(pwd)/fake.sendmail" \ $patches && - sed "1,/^\$/d" < msgtxt1 > msgbody1 + sed "1,/^\$/d" < msgtxt1 > msgbody1 && ! grep "From: A <author@example.com>" msgbody1 ' @@ -279,8 +297,8 @@ test_expect_success $PREREQ 'Invalid In-Reply-To' ' --to=nobody@example.com \ --in-reply-to=" " \ --smtp-server="$(pwd)/fake.sendmail" \ - $patches - 2>errors + $patches \ + 2>errors && ! grep "^In-Reply-To: < *>" msgtxt1 ' @@ -295,6 +313,49 @@ test_expect_success $PREREQ 'Valid In-Reply-To when prompting' ' ! grep "^In-Reply-To: < *>" msgtxt1 ' +test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' ' + clean_fake_sendmail && + echo "<unique-message-id@example.com>" >expect && + git send-email \ + --from="Example <nobody@example.com>" \ + --to=nobody@example.com \ + --nochain-reply-to \ + --in-reply-to="$(cat expect)" \ + --smtp-server="$(pwd)/fake.sendmail" \ + $patches $patches $patches \ + 2>errors && + # The first message is a reply to --in-reply-to + sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual && + test_cmp expect actual && + # Second and subsequent messages are replies to the first one + sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect && + sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual && + test_cmp expect actual && + sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual && + test_cmp expect actual +' + +test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' ' + clean_fake_sendmail && + echo "<unique-message-id@example.com>" >expect && + git send-email \ + --from="Example <nobody@example.com>" \ + --to=nobody@example.com \ + --chain-reply-to \ + --in-reply-to="$(cat expect)" \ + --smtp-server="$(pwd)/fake.sendmail" \ + $patches $patches $patches \ + 2>errors && + sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual && + test_cmp expect actual && + sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect && + sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual && + test_cmp expect actual && + sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt2 >expect && + sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual && + test_cmp expect actual +' + test_expect_success $PREREQ 'setup fake editor' ' (echo "#!$SHELL_PATH" && echo "echo fake edit >>\"\$1\"" @@ -556,7 +617,7 @@ EOF " test_expect_success $PREREQ '--suppress-cc=sob' ' - git config --unset sendemail.cccmd + test_might_fail git config --unset sendemail.cccmd && test_suppression sob ' @@ -947,6 +1008,45 @@ test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' ' ! grep "RCPT TO:<other@ex.com>" stdout ' +test_expect_success $PREREQ 'patches To headers are used by default' ' + patch=`git format-patch -1 --to="bodies@example.com"` && + test_when_finished "rm $patch" && + git send-email \ + --dry-run \ + --from="Example <nobody@example.com>" \ + --smtp-server relay.example.com \ + $patch >stdout && + grep "RCPT TO:<bodies@example.com>" stdout +' + +test_expect_success $PREREQ 'patches To headers are appended to' ' + patch=`git format-patch -1 --to="bodies@example.com"` && + test_when_finished "rm $patch" && + git send-email \ + --dry-run \ + --from="Example <nobody@example.com>" \ + --to=nobody@example.com \ + --smtp-server relay.example.com \ + $patch >stdout && + grep "RCPT TO:<bodies@example.com>" stdout && + grep "RCPT TO:<nobody@example.com>" stdout +' + +test_expect_success $PREREQ 'To headers from files reset each patch' ' + patch1=`git format-patch -1 --to="bodies@example.com"` && + patch2=`git format-patch -1 --to="other@example.com" HEAD~` && + test_when_finished "rm $patch1 && rm $patch2" && + git send-email \ + --dry-run \ + --from="Example <nobody@example.com>" \ + --to="nobody@example.com" \ + --smtp-server relay.example.com \ + $patch1 $patch2 >stdout && + test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 && + test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 && + test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1 +' + test_expect_success $PREREQ 'setup expect' ' cat >email-using-8bit <<EOF From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001 @@ -1032,4 +1132,40 @@ test_expect_success $PREREQ '--8bit-encoding also treats subject' ' test_cmp expected actual ' +# Note that the patches in this test are deliberately out of order; we +# want to make sure it works even if the cover-letter is not in the +# first mail. +test_expect_success $PREREQ 'refusing to send cover letter template' ' + clean_fake_sendmail && + rm -fr outdir && + git format-patch --cover-letter -2 -o outdir && + test_must_fail git send-email \ + --from="Example <nobody@example.com>" \ + --to=nobody@example.com \ + --smtp-server="$(pwd)/fake.sendmail" \ + outdir/0002-*.patch \ + outdir/0000-*.patch \ + outdir/0001-*.patch \ + 2>errors >out && + grep "SUBJECT HERE" errors && + test -z "$(ls msgtxt*)" +' + +test_expect_success $PREREQ '--force sends cover letter template anyway' ' + clean_fake_sendmail && + rm -fr outdir && + git format-patch --cover-letter -2 -o outdir && + git send-email \ + --force \ + --from="Example <nobody@example.com>" \ + --to=nobody@example.com \ + --smtp-server="$(pwd)/fake.sendmail" \ + outdir/0002-*.patch \ + outdir/0000-*.patch \ + outdir/0001-*.patch \ + 2>errors >out && + ! grep "SUBJECT HERE" errors && + test -n "$(ls msgtxt*)" +' + test_done diff --git a/t/t9010-svn-fe.sh b/t/t9010-svn-fe.sh index a713dfc50b..6f6175a8f7 100755 --- a/t/t9010-svn-fe.sh +++ b/t/t9010-svn-fe.sh @@ -2,31 +2,862 @@ test_description='check svn dumpfile importer' -. ./lib-git-svn.sh - -test_dump() { - label=$1 - dump=$2 - test_expect_success "$dump" ' - svnadmin create "$label-svn" && - svnadmin load "$label-svn" < "$TEST_DIRECTORY/$dump" && - svn_cmd export "file://$PWD/$label-svn" "$label-svnco" && - git init "$label-git" && - test-svn-fe "$TEST_DIRECTORY/$dump" >"$label.fe" && - ( - cd "$label-git" && - git fast-import < ../"$label.fe" - ) && - ( - cd "$label-svnco" && - git init && - git add . && - git fetch "../$label-git" master && - git diff --exit-code FETCH_HEAD - ) - ' +. ./test-lib.sh + +reinit_git () { + rm -fr .git && + git init +} + +properties () { + while test "$#" -ne 0 + do + property="$1" && + value="$2" && + printf "%s\n" "K ${#property}" && + printf "%s\n" "$property" && + printf "%s\n" "V ${#value}" && + printf "%s\n" "$value" && + shift 2 || + return 1 + done +} + +text_no_props () { + text="$1 +" && + printf "%s\n" "Prop-content-length: 10" && + printf "%s\n" "Text-content-length: ${#text}" && + printf "%s\n" "Content-length: $((${#text} + 10))" && + printf "%s\n" "" "PROPS-END" && + printf "%s\n" "$text" } -test_dump simple t9135/svn.dump +>empty + +test_expect_success 'empty dump' ' + reinit_git && + echo "SVN-fs-dump-format-version: 2" >input && + test-svn-fe input >stream && + git fast-import <stream +' + +test_expect_success 'v4 dumps not supported' ' + reinit_git && + echo "SVN-fs-dump-format-version: 4" >v4.dump && + test_must_fail test-svn-fe v4.dump >stream && + test_cmp empty stream +' + +test_expect_failure 'empty revision' ' + reinit_git && + printf "rev <nobody, nobody@local>: %s\n" "" "" >expect && + cat >emptyrev.dump <<-\EOF && + SVN-fs-dump-format-version: 3 + + Revision-number: 1 + Prop-content-length: 0 + Content-length: 0 + + Revision-number: 2 + Prop-content-length: 0 + Content-length: 0 + + EOF + test-svn-fe emptyrev.dump >stream && + git fast-import <stream && + git log -p --format="rev <%an, %ae>: %s" HEAD >actual && + test_cmp expect actual +' + +test_expect_success 'empty properties' ' + reinit_git && + printf "rev <nobody, nobody@local>: %s\n" "" "" >expect && + cat >emptyprop.dump <<-\EOF && + SVN-fs-dump-format-version: 3 + + Revision-number: 1 + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + + Revision-number: 2 + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + EOF + test-svn-fe emptyprop.dump >stream && + git fast-import <stream && + git log -p --format="rev <%an, %ae>: %s" HEAD >actual && + test_cmp expect actual +' + +test_expect_success 'author name and commit message' ' + reinit_git && + echo "<author@example.com, author@example.com@local>" >expect.author && + cat >message <<-\EOF && + A concise summary of the change + + A detailed description of the change, why it is needed, what + was broken and why applying this is the best course of action. + + * file.c + Details pertaining to an individual file. + EOF + { + properties \ + svn:author author@example.com \ + svn:log "$(cat message)" && + echo PROPS-END + } >props && + { + echo "SVN-fs-dump-format-version: 3" && + echo && + echo "Revision-number: 1" && + echo Prop-content-length: $(wc -c <props) && + echo Content-length: $(wc -c <props) && + echo && + cat props + } >log.dump && + test-svn-fe log.dump >stream && + git fast-import <stream && + git log -p --format="%B" HEAD >actual.log && + git log --format="<%an, %ae>" >actual.author && + test_cmp message actual.log && + test_cmp expect.author actual.author +' + +test_expect_success 'unsupported properties are ignored' ' + reinit_git && + echo author >expect && + cat >extraprop.dump <<-\EOF && + SVN-fs-dump-format-version: 3 + + Revision-number: 1 + Prop-content-length: 56 + Content-length: 56 + + K 8 + nonsense + V 1 + y + K 10 + svn:author + V 6 + author + PROPS-END + EOF + test-svn-fe extraprop.dump >stream && + git fast-import <stream && + git log -p --format=%an HEAD >actual && + test_cmp expect actual +' + +test_expect_failure 'timestamp and empty file' ' + echo author@example.com >expect.author && + echo 1999-01-01 >expect.date && + echo file >expect.files && + reinit_git && + { + properties \ + svn:author author@example.com \ + svn:date "1999-01-01T00:01:002.000000Z" \ + svn:log "add empty file" && + echo PROPS-END + } >props && + { + cat <<-EOF && + SVN-fs-dump-format-version: 3 + + Revision-number: 1 + EOF + echo Prop-content-length: $(wc -c <props) && + echo Content-length: $(wc -c <props) && + echo && + cat props && + cat <<-\EOF + + Node-path: empty-file + Node-kind: file + Node-action: add + Content-length: 0 + + EOF + } >emptyfile.dump && + test-svn-fe emptyfile.dump >stream && + git fast-import <stream && + git log --format=%an HEAD >actual.author && + git log --date=short --format=%ad HEAD >actual.date && + git ls-tree -r --name-only HEAD >actual.files && + test_cmp expect.author actual.author && + test_cmp expect.date actual.date && + test_cmp expect.files actual.files && + git checkout HEAD empty-file && + test_cmp empty file +' + +test_expect_success 'directory with files' ' + reinit_git && + printf "%s\n" directory/file1 directory/file2 >expect.files && + echo hi >hi && + echo hello >hello && + { + properties \ + svn:author author@example.com \ + svn:date "1999-02-01T00:01:002.000000Z" \ + svn:log "add directory with some files in it" && + echo PROPS-END + } >props && + { + cat <<-EOF && + SVN-fs-dump-format-version: 3 + + Revision-number: 1 + EOF + echo Prop-content-length: $(wc -c <props) && + echo Content-length: $(wc -c <props) && + echo && + cat props && + cat <<-\EOF && + + Node-path: directory + Node-kind: dir + Node-action: add + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + + Node-path: directory/file1 + Node-kind: file + Node-action: add + EOF + text_no_props hello && + cat <<-\EOF && + Node-path: directory/file2 + Node-kind: file + Node-action: add + EOF + text_no_props hi + } >directory.dump && + test-svn-fe directory.dump >stream && + git fast-import <stream && + + git ls-tree -r --name-only HEAD >actual.files && + git checkout HEAD directory && + test_cmp expect.files actual.files && + test_cmp hello directory/file1 && + test_cmp hi directory/file2 +' + +test_expect_success 'node without action' ' + cat >inaction.dump <<-\EOF && + SVN-fs-dump-format-version: 3 + + Revision-number: 1 + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + + Node-path: directory + Node-kind: dir + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + EOF + test_must_fail test-svn-fe inaction.dump +' + +test_expect_success 'action: add node without text' ' + cat >textless.dump <<-\EOF && + SVN-fs-dump-format-version: 3 + + Revision-number: 1 + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + + Node-path: textless + Node-kind: file + Node-action: add + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + EOF + test_must_fail test-svn-fe textless.dump +' + +test_expect_failure 'change file mode but keep old content' ' + reinit_git && + cat >expect <<-\EOF && + OBJID + :120000 100644 OBJID OBJID T greeting + OBJID + :100644 120000 OBJID OBJID T greeting + OBJID + :000000 100644 OBJID OBJID A greeting + EOF + echo "link hello" >expect.blob && + echo hello >hello && + cat >filemode.dump <<-\EOF && + SVN-fs-dump-format-version: 3 + + Revision-number: 1 + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + + Node-path: greeting + Node-kind: file + Node-action: add + Prop-content-length: 10 + Text-content-length: 11 + Content-length: 21 + + PROPS-END + link hello + + Revision-number: 2 + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + + Node-path: greeting + Node-kind: file + Node-action: change + Prop-content-length: 33 + Content-length: 33 + + K 11 + svn:special + V 1 + * + PROPS-END + + Revision-number: 3 + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + + Node-path: greeting + Node-kind: file + Node-action: change + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + EOF + test-svn-fe filemode.dump >stream && + git fast-import <stream && + { + git rev-list HEAD | + git diff-tree --root --stdin | + sed "s/$_x40/OBJID/g" + } >actual && + git show HEAD:greeting >actual.blob && + git show HEAD^:greeting >actual.target && + test_cmp expect actual && + test_cmp expect.blob actual.blob && + test_cmp hello actual.target +' + +test_expect_success 'NUL in property value' ' + reinit_git && + echo "commit message" >expect.message && + { + properties \ + unimportant "something with a NUL (Q)" \ + svn:log "commit message"&& + echo PROPS-END + } | + q_to_nul >props && + { + cat <<-\EOF && + SVN-fs-dump-format-version: 3 + + Revision-number: 1 + EOF + echo Prop-content-length: $(wc -c <props) && + echo Content-length: $(wc -c <props) && + echo && + cat props + } >nulprop.dump && + test-svn-fe nulprop.dump >stream && + git fast-import <stream && + git diff-tree --always -s --format=%s HEAD >actual.message && + test_cmp expect.message actual.message +' + +test_expect_success 'NUL in log message, file content, and property name' ' + # Caveat: svnadmin 1.6.16 (r1073529) truncates at \0 in the + # svn:specialQnotreally example. + reinit_git && + cat >expect <<-\EOF && + OBJID + :100644 100644 OBJID OBJID M greeting + OBJID + :000000 100644 OBJID OBJID A greeting + EOF + printf "\n%s\n" "something with an ASCII NUL (Q)" >expect.message && + printf "%s\n" "helQo" >expect.hello1 && + printf "%s\n" "link hello" >expect.hello2 && + { + properties svn:log "something with an ASCII NUL (Q)" && + echo PROPS-END + } | + q_to_nul >props && + { + q_to_nul <<-\EOF && + SVN-fs-dump-format-version: 3 + + Revision-number: 1 + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + + Node-path: greeting + Node-kind: file + Node-action: add + Prop-content-length: 10 + Text-content-length: 6 + Content-length: 16 + + PROPS-END + helQo + + Revision-number: 2 + EOF + echo Prop-content-length: $(wc -c <props) && + echo Content-length: $(wc -c <props) && + echo && + cat props && + q_to_nul <<-\EOF + + Node-path: greeting + Node-kind: file + Node-action: change + Prop-content-length: 43 + Text-content-length: 11 + Content-length: 54 + + K 21 + svn:specialQnotreally + V 1 + * + PROPS-END + link hello + EOF + } >8bitclean.dump && + test-svn-fe 8bitclean.dump >stream && + git fast-import <stream && + { + git rev-list HEAD | + git diff-tree --root --stdin | + sed "s/$_x40/OBJID/g" + } >actual && + { + git cat-file commit HEAD | nul_to_q && + echo + } | + sed -ne "/^\$/,\$ p" >actual.message && + git cat-file blob HEAD^:greeting | nul_to_q >actual.hello1 && + git cat-file blob HEAD:greeting | nul_to_q >actual.hello2 && + test_cmp expect actual && + test_cmp expect.message actual.message && + test_cmp expect.hello1 actual.hello1 && + test_cmp expect.hello2 actual.hello2 +' + +test_expect_success 'change file mode and reiterate content' ' + reinit_git && + cat >expect <<-\EOF && + OBJID + :120000 100644 OBJID OBJID T greeting + OBJID + :100644 120000 OBJID OBJID T greeting + OBJID + :000000 100644 OBJID OBJID A greeting + EOF + echo "link hello" >expect.blob && + echo hello >hello && + cat >filemode.dump <<-\EOF && + SVN-fs-dump-format-version: 3 + + Revision-number: 1 + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + + Node-path: greeting + Node-kind: file + Node-action: add + Prop-content-length: 10 + Text-content-length: 11 + Content-length: 21 + + PROPS-END + link hello + + Revision-number: 2 + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + + Node-path: greeting + Node-kind: file + Node-action: change + Prop-content-length: 33 + Text-content-length: 11 + Content-length: 44 + + K 11 + svn:special + V 1 + * + PROPS-END + link hello + + Revision-number: 3 + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + + Node-path: greeting + Node-kind: file + Node-action: change + Prop-content-length: 10 + Text-content-length: 11 + Content-length: 21 + + PROPS-END + link hello + EOF + test-svn-fe filemode.dump >stream && + git fast-import <stream && + { + git rev-list HEAD | + git diff-tree --root --stdin | + sed "s/$_x40/OBJID/g" + } >actual && + git show HEAD:greeting >actual.blob && + git show HEAD^:greeting >actual.target && + test_cmp expect actual && + test_cmp expect.blob actual.blob && + test_cmp hello actual.target +' + +test_expect_success 'deltas not supported' ' + { + # (old) h + (inline) ello + (old) \n + printf "SVNQ%b%b%s" "Q\003\006\005\004" "\001Q\0204\001\002" "ello" | + q_to_nul + } >delta && + { + properties \ + svn:author author@example.com \ + svn:date "1999-01-05T00:01:002.000000Z" \ + svn:log "add greeting" && + echo PROPS-END + } >props && + { + properties \ + svn:author author@example.com \ + svn:date "1999-01-06T00:01:002.000000Z" \ + svn:log "change it" && + echo PROPS-END + } >props2 && + { + echo SVN-fs-dump-format-version: 3 && + echo && + echo Revision-number: 1 && + echo Prop-content-length: $(wc -c <props) && + echo Content-length: $(wc -c <props) && + echo && + cat props && + cat <<-\EOF && + + Node-path: hello + Node-kind: file + Node-action: add + Prop-content-length: 10 + Text-content-length: 3 + Content-length: 13 + + PROPS-END + hi + + EOF + echo Revision-number: 2 && + echo Prop-content-length: $(wc -c <props2) && + echo Content-length: $(wc -c <props2) && + echo && + cat props2 && + cat <<-\EOF && + + Node-path: hello + Node-kind: file + Node-action: change + Text-delta: true + Prop-content-length: 10 + EOF + echo Text-content-length: $(wc -c <delta) && + echo Content-length: $((10 + $(wc -c <delta))) && + echo && + echo PROPS-END && + cat delta + } >delta.dump && + test_must_fail test-svn-fe delta.dump +' + +test_expect_success 'property deltas supported' ' + reinit_git && + cat >expect <<-\EOF && + OBJID + :100755 100644 OBJID OBJID M script.sh + EOF + { + properties \ + svn:author author@example.com \ + svn:date "1999-03-06T00:01:002.000000Z" \ + svn:log "make an executable, or chmod -x it" && + echo PROPS-END + } >revprops && + { + echo SVN-fs-dump-format-version: 3 && + echo && + echo Revision-number: 1 && + echo Prop-content-length: $(wc -c <revprops) && + echo Content-length: $(wc -c <revprops) && + echo && + cat revprops && + echo && + cat <<-\EOF && + Node-path: script.sh + Node-kind: file + Node-action: add + Text-content-length: 0 + Prop-content-length: 39 + Content-length: 39 + + K 14 + svn:executable + V 4 + true + PROPS-END + + EOF + echo Revision-number: 2 && + echo Prop-content-length: $(wc -c <revprops) && + echo Content-length: $(wc -c <revprops) && + echo && + cat revprops && + echo && + cat <<-\EOF + Node-path: script.sh + Node-kind: file + Node-action: change + Prop-delta: true + Prop-content-length: 30 + Content-length: 30 + + D 14 + svn:executable + PROPS-END + EOF + } >propdelta.dump && + test-svn-fe propdelta.dump >stream && + git fast-import <stream && + { + git rev-list HEAD | + git diff-tree --stdin | + sed "s/$_x40/OBJID/g" + } >actual && + test_cmp expect actual +' + +test_expect_success 'properties on /' ' + reinit_git && + cat <<-\EOF >expect && + OBJID + OBJID + :000000 100644 OBJID OBJID A greeting + EOF + sed -e "s/X$//" <<-\EOF >changeroot.dump && + SVN-fs-dump-format-version: 3 + + Revision-number: 1 + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + + Node-path: greeting + Node-kind: file + Node-action: add + Text-content-length: 0 + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + + Revision-number: 2 + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + + Node-path: X + Node-kind: dir + Node-action: change + Prop-delta: true + Prop-content-length: 43 + Content-length: 43 + + K 10 + svn:ignore + V 11 + build-area + + PROPS-END + EOF + test-svn-fe changeroot.dump >stream && + git fast-import <stream && + { + git rev-list HEAD | + git diff-tree --root --always --stdin | + sed "s/$_x40/OBJID/g" + } >actual && + test_cmp expect actual +' + +test_expect_success 'deltas for typechange' ' + reinit_git && + cat >expect <<-\EOF && + OBJID + :120000 100644 OBJID OBJID T test-file + OBJID + :100755 120000 OBJID OBJID T test-file + OBJID + :000000 100755 OBJID OBJID A test-file + EOF + cat >deleteprop.dump <<-\EOF && + SVN-fs-dump-format-version: 3 + + Revision-number: 1 + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + + Node-path: test-file + Node-kind: file + Node-action: add + Prop-delta: true + Prop-content-length: 35 + Text-content-length: 17 + Content-length: 52 + + K 14 + svn:executable + V 0 + + PROPS-END + link testing 123 + + Revision-number: 2 + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + + Node-path: test-file + Node-kind: file + Node-action: change + Prop-delta: true + Prop-content-length: 53 + Text-content-length: 17 + Content-length: 70 + + K 11 + svn:special + V 1 + * + D 14 + svn:executable + PROPS-END + link testing 231 + + Revision-number: 3 + Prop-content-length: 10 + Content-length: 10 + + PROPS-END + + Node-path: test-file + Node-kind: file + Node-action: change + Prop-delta: true + Prop-content-length: 27 + Text-content-length: 17 + Content-length: 44 + + D 11 + svn:special + PROPS-END + link testing 321 + EOF + test-svn-fe deleteprop.dump >stream && + git fast-import <stream && + { + git rev-list HEAD | + git diff-tree --root --stdin | + sed "s/$_x40/OBJID/g" + } >actual && + test_cmp expect actual +' + + +test_expect_success 'set up svn repo' ' + svnconf=$PWD/svnconf && + mkdir -p "$svnconf" && + + if + svnadmin -h >/dev/null 2>&1 && + svnadmin create simple-svn && + svnadmin load simple-svn <"$TEST_DIRECTORY/t9135/svn.dump" && + svn export --config-dir "$svnconf" "file://$PWD/simple-svn" simple-svnco + then + test_set_prereq SVNREPO + fi +' + +test_expect_success SVNREPO 't9135/svn.dump' ' + git init simple-git && + test-svn-fe "$TEST_DIRECTORY/t9135/svn.dump" >simple.fe && + ( + cd simple-git && + git fast-import <../simple.fe + ) && + ( + cd simple-svnco && + git init && + git add . && + git fetch ../simple-git master && + git diff --exit-code FETCH_HEAD + ) +' test_done diff --git a/t/t9100-git-svn-basic.sh b/t/t9100-git-svn-basic.sh index 2f458f7a99..b041516a1d 100755 --- a/t/t9100-git-svn-basic.sh +++ b/t/t9100-git-svn-basic.sh @@ -143,7 +143,7 @@ test_expect_success "$name" ' git svn set-tree --find-copies-harder --rmdir \ ${remotes_git_svn}..mybranch5 && svn_cmd up "$SVN_TREE" && - test -L "$SVN_TREE"/exec.sh' + test -h "$SVN_TREE"/exec.sh' name='new symlink is added to a file that was also just made executable' @@ -156,7 +156,7 @@ test_expect_success "$name" ' ${remotes_git_svn}..mybranch5 && svn_cmd up "$SVN_TREE" && test -x "$SVN_TREE"/bar/zzz && - test -L "$SVN_TREE"/exec-2.sh' + test -h "$SVN_TREE"/exec-2.sh' name='modify a symlink to become a file' test_expect_success "$name" ' @@ -169,7 +169,7 @@ test_expect_success "$name" ' ${remotes_git_svn}..mybranch5 && svn_cmd up "$SVN_TREE" && test -f "$SVN_TREE"/exec-2.sh && - test ! -L "$SVN_TREE"/exec-2.sh && + test ! -h "$SVN_TREE"/exec-2.sh && test_cmp help "$SVN_TREE"/exec-2.sh' name="commit with UTF-8 message: locale: $GIT_SVN_LC_ALL" diff --git a/t/t9104-git-svn-follow-parent.sh b/t/t9104-git-svn-follow-parent.sh index f7f3c5ab8e..13b179e721 100755 --- a/t/t9104-git-svn-follow-parent.sh +++ b/t/t9104-git-svn-follow-parent.sh @@ -190,7 +190,7 @@ test_expect_success "follow-parent is atomic" ' git svn init --minimize-url -i stunk "$svnrepo"/stunk && git svn fetch -i stunk && git svn init --minimize-url -i flunked "$svnrepo"/flunked && - git svn fetch -i flunked + git svn fetch -i flunked && test "`git rev-parse --verify refs/remotes/flunk@18`" \ = "`git rev-parse --verify refs/remotes/stunk`" && test "`git rev-parse --verify refs/remotes/flunk~1`" \ diff --git a/t/t9119-git-svn-info.sh b/t/t9119-git-svn-info.sh index f3f397cdda..ff19695e77 100755 --- a/t/t9119-git-svn-info.sh +++ b/t/t9119-git-svn-info.sh @@ -18,21 +18,14 @@ case $v in ;; esac -ptouch() { - perl -w -e ' - use strict; - use POSIX qw(mktime); - die "ptouch requires exactly 2 arguments" if @ARGV != 2; - my $text_last_updated = shift @ARGV; - my $git_file = shift @ARGV; - die "\"$git_file\" does not exist" if ! -e $git_file; - if ($text_last_updated - =~ /(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})/) { - my $mtime = mktime($6, $5, $4, $3, $2 - 1, $1 - 1900); - my $atime = $mtime; - utime $atime, $mtime, $git_file; - } - ' "`svn_cmd info $2 | grep '^Text Last Updated:'`" "$1" +# On the "Text Last Updated" line, "git svn info" does not return the +# same value as "svn info" (i.e. the commit timestamp that touched the +# path most recently); do not expect that field to match. +test_cmp_info () { + sed -e '/^Text Last Updated:/d' "$1" >tmp.expect + sed -e '/^Text Last Updated:/d' "$2" >tmp.actual + test_cmp tmp.expect tmp.actual && + rm -f tmp.expect tmp.actual } quoted_svnrepo="$(echo $svnrepo | sed 's/ /%20/')" @@ -62,17 +55,13 @@ test_expect_success 'setup repository and import' ' cd gitwc && git svn init "$svnrepo" && git svn fetch - ) && - ptouch gitwc/file svnwc/file && - ptouch gitwc/directory svnwc/directory && - ptouch gitwc/symlink-file svnwc/symlink-file && - ptouch gitwc/symlink-directory svnwc/symlink-directory + ) ' test_expect_success 'info' " (cd svnwc; svn info) > expected.info && (cd gitwc; git svn info) > actual.info && - test_cmp expected.info actual.info + test_cmp_info expected.info actual.info " test_expect_success 'info --url' ' @@ -82,7 +71,7 @@ test_expect_success 'info --url' ' test_expect_success 'info .' " (cd svnwc; svn info .) > expected.info-dot && (cd gitwc; git svn info .) > actual.info-dot && - test_cmp expected.info-dot actual.info-dot + test_cmp_info expected.info-dot actual.info-dot " test_expect_success 'info --url .' ' @@ -92,7 +81,7 @@ test_expect_success 'info --url .' ' test_expect_success 'info file' " (cd svnwc; svn info file) > expected.info-file && (cd gitwc; git svn info file) > actual.info-file && - test_cmp expected.info-file actual.info-file + test_cmp_info expected.info-file actual.info-file " test_expect_success 'info --url file' ' @@ -102,13 +91,13 @@ test_expect_success 'info --url file' ' test_expect_success 'info directory' " (cd svnwc; svn info directory) > expected.info-directory && (cd gitwc; git svn info directory) > actual.info-directory && - test_cmp expected.info-directory actual.info-directory + test_cmp_info expected.info-directory actual.info-directory " test_expect_success 'info inside directory' " (cd svnwc/directory; svn info) > expected.info-inside-directory && (cd gitwc/directory; git svn info) > actual.info-inside-directory && - test_cmp expected.info-inside-directory actual.info-inside-directory + test_cmp_info expected.info-inside-directory actual.info-inside-directory " test_expect_success 'info --url directory' ' @@ -118,7 +107,7 @@ test_expect_success 'info --url directory' ' test_expect_success 'info symlink-file' " (cd svnwc; svn info symlink-file) > expected.info-symlink-file && (cd gitwc; git svn info symlink-file) > actual.info-symlink-file && - test_cmp expected.info-symlink-file actual.info-symlink-file + test_cmp_info expected.info-symlink-file actual.info-symlink-file " test_expect_success 'info --url symlink-file' ' @@ -131,7 +120,7 @@ test_expect_success 'info symlink-directory' " > expected.info-symlink-directory && (cd gitwc; git svn info symlink-directory) \ > actual.info-symlink-directory && - test_cmp expected.info-symlink-directory actual.info-symlink-directory + test_cmp_info expected.info-symlink-directory actual.info-symlink-directory " test_expect_success 'info --url symlink-directory' ' @@ -146,14 +135,13 @@ test_expect_success 'info added-file' " git add added-file ) && cp gitwc/added-file svnwc/added-file && - ptouch gitwc/added-file svnwc/added-file && ( cd svnwc && svn_cmd add added-file > /dev/null ) && (cd svnwc; svn info added-file) > expected.info-added-file && (cd gitwc; git svn info added-file) > actual.info-added-file && - test_cmp expected.info-added-file actual.info-added-file + test_cmp_info expected.info-added-file actual.info-added-file " test_expect_success 'info --url added-file' ' @@ -163,7 +151,6 @@ test_expect_success 'info --url added-file' ' test_expect_success 'info added-directory' " mkdir gitwc/added-directory svnwc/added-directory && - ptouch gitwc/added-directory svnwc/added-directory && touch gitwc/added-directory/.placeholder && ( cd svnwc && @@ -177,7 +164,7 @@ test_expect_success 'info added-directory' " > expected.info-added-directory && (cd gitwc; git svn info added-directory) \ > actual.info-added-directory && - test_cmp expected.info-added-directory actual.info-added-directory + test_cmp_info expected.info-added-directory actual.info-added-directory " test_expect_success 'info --url added-directory' ' @@ -196,13 +183,12 @@ test_expect_success 'info added-symlink-file' " ln -s added-file added-symlink-file && svn_cmd add added-symlink-file > /dev/null ) && - ptouch gitwc/added-symlink-file svnwc/added-symlink-file && (cd svnwc; svn info added-symlink-file) \ > expected.info-added-symlink-file && (cd gitwc; git svn info added-symlink-file) \ > actual.info-added-symlink-file && - test_cmp expected.info-added-symlink-file \ - actual.info-added-symlink-file + test_cmp_info expected.info-added-symlink-file \ + actual.info-added-symlink-file " test_expect_success 'info --url added-symlink-file' ' @@ -221,13 +207,12 @@ test_expect_success 'info added-symlink-directory' " ln -s added-directory added-symlink-directory && svn_cmd add added-symlink-directory > /dev/null ) && - ptouch gitwc/added-symlink-directory svnwc/added-symlink-directory && (cd svnwc; svn info added-symlink-directory) \ > expected.info-added-symlink-directory && (cd gitwc; git svn info added-symlink-directory) \ > actual.info-added-symlink-directory && - test_cmp expected.info-added-symlink-directory \ - actual.info-added-symlink-directory + test_cmp_info expected.info-added-symlink-directory \ + actual.info-added-symlink-directory " test_expect_success 'info --url added-symlink-directory' ' @@ -235,11 +220,6 @@ test_expect_success 'info --url added-symlink-directory' ' = "$quoted_svnrepo/added-symlink-directory" ' -# The next few tests replace the "Text Last Updated" value with a -# placeholder since git doesn't have a way to know the date that a -# now-deleted file was last checked out locally. Internally it -# simply reuses the Last Changed Date. - test_expect_success 'info deleted-file' " ( cd gitwc && @@ -249,13 +229,9 @@ test_expect_success 'info deleted-file' " cd svnwc && svn_cmd rm --force file > /dev/null ) && - (cd svnwc; svn info file) | - sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \ - > expected.info-deleted-file && - (cd gitwc; git svn info file) | - sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \ - > actual.info-deleted-file && - test_cmp expected.info-deleted-file actual.info-deleted-file + (cd svnwc; svn info file) >expected.info-deleted-file && + (cd gitwc; git svn info file) >actual.info-deleted-file && + test_cmp_info expected.info-deleted-file actual.info-deleted-file " test_expect_success 'info --url file (deleted)' ' @@ -272,13 +248,9 @@ test_expect_success 'info deleted-directory' " cd svnwc && svn_cmd rm --force directory > /dev/null ) && - (cd svnwc; svn info directory) | - sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \ - > expected.info-deleted-directory && - (cd gitwc; git svn info directory) | - sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \ - > actual.info-deleted-directory && - test_cmp expected.info-deleted-directory actual.info-deleted-directory + (cd svnwc; svn info directory) >expected.info-deleted-directory && + (cd gitwc; git svn info directory) >actual.info-deleted-directory && + test_cmp_info expected.info-deleted-directory actual.info-deleted-directory " test_expect_success 'info --url directory (deleted)' ' @@ -295,14 +267,9 @@ test_expect_success 'info deleted-symlink-file' " cd svnwc && svn_cmd rm --force symlink-file > /dev/null ) && - (cd svnwc; svn info symlink-file) | - sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \ - > expected.info-deleted-symlink-file && - (cd gitwc; git svn info symlink-file) | - sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \ - > actual.info-deleted-symlink-file && - test_cmp expected.info-deleted-symlink-file \ - actual.info-deleted-symlink-file + (cd svnwc; svn info symlink-file) >expected.info-deleted-symlink-file && + (cd gitwc; git svn info symlink-file) >actual.info-deleted-symlink-file && + test_cmp_info expected.info-deleted-symlink-file actual.info-deleted-symlink-file " test_expect_success 'info --url symlink-file (deleted)' ' @@ -319,14 +286,9 @@ test_expect_success 'info deleted-symlink-directory' " cd svnwc && svn_cmd rm --force symlink-directory > /dev/null ) && - (cd svnwc; svn info symlink-directory) | - sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \ - > expected.info-deleted-symlink-directory && - (cd gitwc; git svn info symlink-directory) | - sed -e 's/^\(Text Last Updated:\).*/\1 TEXT-LAST-UPDATED-STRING/' \ - > actual.info-deleted-symlink-directory && - test_cmp expected.info-deleted-symlink-directory \ - actual.info-deleted-symlink-directory + (cd svnwc; svn info symlink-directory) >expected.info-deleted-symlink-directory && + (cd gitwc; git svn info symlink-directory) >actual.info-deleted-symlink-directory && + test_cmp_info expected.info-deleted-symlink-directory actual.info-deleted-symlink-directory " test_expect_success 'info --url symlink-directory (deleted)' ' diff --git a/t/t9123-git-svn-rebuild-with-rewriteroot.sh b/t/t9123-git-svn-rebuild-with-rewriteroot.sh index 0ed90d982d..fd8184787f 100755 --- a/t/t9123-git-svn-rebuild-with-rewriteroot.sh +++ b/t/t9123-git-svn-rebuild-with-rewriteroot.sh @@ -16,7 +16,7 @@ rm -rf import test_expect_success 'init, fetch and checkout repository' ' git svn init --rewrite-root=http://invalid.invalid/ "$svnrepo" && - git svn fetch + git svn fetch && git checkout -b mybranch ${remotes_git_svn} ' diff --git a/t/t9124-git-svn-dcommit-auto-props.sh b/t/t9124-git-svn-dcommit-auto-props.sh index d6b076f6b7..aa841e1299 100755 --- a/t/t9124-git-svn-dcommit-auto-props.sh +++ b/t/t9124-git-svn-dcommit-auto-props.sh @@ -24,7 +24,7 @@ test_expect_success 'initialize git svn' ' svn_cmd import -m "import for git svn" . "$svnrepo" ) && rm -rf import && - git svn init "$svnrepo" + git svn init "$svnrepo" && git svn fetch ' diff --git a/t/t9130-git-svn-authors-file.sh b/t/t9130-git-svn-authors-file.sh index ec0a106614..b324c491c5 100755 --- a/t/t9130-git-svn-authors-file.sh +++ b/t/t9130-git-svn-authors-file.sh @@ -96,7 +96,6 @@ test_expect_success 'fresh clone with svn.authors-file in config' ' rm -r "$GIT_DIR" && test x = x"$(git config svn.authorsfile)" && test_config="$HOME"/.gitconfig && - unset GIT_CONFIG_NOGLOBAL && unset GIT_DIR && unset GIT_CONFIG && git config --global \ diff --git a/t/t9131-git-svn-empty-symlink.sh b/t/t9131-git-svn-empty-symlink.sh index 9a24a65b64..f762038f0e 100755 --- a/t/t9131-git-svn-empty-symlink.sh +++ b/t/t9131-git-svn-empty-symlink.sh @@ -88,7 +88,7 @@ test_expect_success 'enable broken symlink workaround' \ test_expect_success '"bar" is an empty file' 'test -f x/bar && ! test -s x/bar' test_expect_success 'get "bar" => symlink fix from svn' \ '(cd x && git svn rebase)' -test_expect_success SYMLINKS '"bar" becomes a symlink' 'test -L x/bar' +test_expect_success SYMLINKS '"bar" becomes a symlink' 'test -h x/bar' test_expect_success 'clone using git svn' 'git svn clone -r1 "$svnrepo" y' diff --git a/t/t9142-git-svn-shallow-clone.sh b/t/t9142-git-svn-shallow-clone.sh index 1236accd99..e21ee5f663 100755 --- a/t/t9142-git-svn-shallow-clone.sh +++ b/t/t9142-git-svn-shallow-clone.sh @@ -17,11 +17,10 @@ test_expect_success 'setup test repository' ' > foo && svn_cmd add foo && svn_cmd commit -m "add foo" - ) + ) && + start_httpd ' -start_httpd - test_expect_success 'clone trunk with "-r HEAD"' ' git svn clone -r HEAD "$svnrepo/trunk" g && ( cd g && git rev-parse --symbolic --verify HEAD ) diff --git a/t/t9143-git-svn-gc.sh b/t/t9143-git-svn-gc.sh index 337ea59711..4594e1ae2f 100755 --- a/t/t9143-git-svn-gc.sh +++ b/t/t9143-git-svn-gc.sh @@ -37,13 +37,11 @@ test_expect_success 'git svn gc runs' 'git svn gc' test_expect_success 'git svn index removed' '! test -f .git/svn/refs/remotes/git-svn/index' -if perl -MCompress::Zlib -e 0 2>/dev/null +if test -r .git/svn/refs/remotes/git-svn/unhandled.log.gz then test_expect_success 'git svn gc produces a valid gzip file' ' gunzip .git/svn/refs/remotes/git-svn/unhandled.log.gz ' -else - say "# Perl Compress::Zlib unavailable, skipping gunzip test" fi test_expect_success 'git svn gc does not change unhandled.log files' ' diff --git a/t/t9146-git-svn-empty-dirs.sh b/t/t9146-git-svn-empty-dirs.sh index 565365cbd3..6d3130e618 100755 --- a/t/t9146-git-svn-empty-dirs.sh +++ b/t/t9146-git-svn-empty-dirs.sh @@ -28,12 +28,29 @@ test_expect_success 'empty directories exist' ' ) ' +test_expect_success 'option automkdirs set to false' ' + ( + git svn init "$svnrepo" cloned-no-mkdirs && + cd cloned-no-mkdirs && + git config svn-remote.svn.automkdirs false && + git svn fetch && + for i in a b c d d/e d/e/f "weird file name" + do + if test -d "$i" + then + echo >&2 "$i exists" + exit 1 + fi + done + ) +' + test_expect_success 'more emptiness' ' svn_cmd mkdir -m "bang bang" "$svnrepo"/"! !" ' test_expect_success 'git svn rebase creates empty directory' ' - ( cd cloned && git svn rebase ) + ( cd cloned && git svn rebase ) && test -d cloned/"! !" ' diff --git a/t/t9151-svn-mergeinfo.sh b/t/t9151-svn-mergeinfo.sh index 250c651eae..4f6c06ecb2 100755 --- a/t/t9151-svn-mergeinfo.sh +++ b/t/t9151-svn-mergeinfo.sh @@ -18,39 +18,39 @@ test_expect_success 'load svn dump' " test_expect_success 'all svn merges became git merge commits' ' unmarked=$(git rev-list --parents --all --grep=Merge | - grep -v " .* " | cut -f1 -d" ") + grep -v " .* " | cut -f1 -d" ") && [ -z "$unmarked" ] ' test_expect_success 'cherry picks did not become git merge commits' ' bad_cherries=$(git rev-list --parents --all --grep=Cherry | - grep " .* " | cut -f1 -d" ") + grep " .* " | cut -f1 -d" ") && [ -z "$bad_cherries" ] ' test_expect_success 'svn non-merge merge commits did not become git merge commits' ' bad_non_merges=$(git rev-list --parents --all --grep=non-merge | - grep " .* " | cut -f1 -d" ") + grep " .* " | cut -f1 -d" ") && [ -z "$bad_non_merges" ] ' test_expect_success 'commit made to merged branch is reachable from the merge' ' - before_commit=$(git rev-list --all --grep="trunk commit before merging trunk to b2") - merge_commit=$(git rev-list --all --grep="Merge trunk to b2") - not_reachable=$(git rev-list -1 $before_commit --not $merge_commit) + before_commit=$(git rev-list --all --grep="trunk commit before merging trunk to b2") && + merge_commit=$(git rev-list --all --grep="Merge trunk to b2") && + not_reachable=$(git rev-list -1 $before_commit --not $merge_commit) && [ -z "$not_reachable" ] ' test_expect_success 'merging two branches in one commit is detected correctly' ' - f1_commit=$(git rev-list --all --grep="make f1 branch from trunk") - f2_commit=$(git rev-list --all --grep="make f2 branch from trunk") - merge_commit=$(git rev-list --all --grep="Merge f1 and f2 to trunk") - not_reachable=$(git rev-list -1 $f1_commit $f2_commit --not $merge_commit) + f1_commit=$(git rev-list --all --grep="make f1 branch from trunk") && + f2_commit=$(git rev-list --all --grep="make f2 branch from trunk") && + merge_commit=$(git rev-list --all --grep="Merge f1 and f2 to trunk") && + not_reachable=$(git rev-list -1 $f1_commit $f2_commit --not $merge_commit) && [ -z "$not_reachable" ] ' test_expect_failure 'everything got merged in the end' ' - unmerged=$(git rev-list --all --not master) + unmerged=$(git rev-list --all --not master) && [ -z "$unmerged" ] ' diff --git a/t/t9157-git-svn-fetch-merge.sh b/t/t9157-git-svn-fetch-merge.sh new file mode 100755 index 0000000000..991d2aa1be --- /dev/null +++ b/t/t9157-git-svn-fetch-merge.sh @@ -0,0 +1,58 @@ +#!/bin/sh +# +# Copyright (c) 2010 Steven Walter +# + +test_description='git svn merge detection' +. ./lib-git-svn.sh + +svn_ver="$(svn --version --quiet)" +case $svn_ver in +0.* | 1.[0-4].*) + skip_all="skipping git-svn test - SVN too old ($svn_ver)" + test_done + ;; +esac + +test_expect_success 'initialize source svn repo' ' + svn_cmd mkdir -m x "$svnrepo"/trunk && + svn_cmd mkdir -m x "$svnrepo"/branches && + svn_cmd co "$svnrepo"/trunk "$SVN_TREE" && + ( + cd "$SVN_TREE" && + touch foo && + svn add foo && + svn commit -m "initial commit" && + svn cp -m branch "$svnrepo"/trunk "$svnrepo"/branches/branch1 && + touch bar && + svn add bar && + svn commit -m x && + svn cp -m branch "$svnrepo"/trunk "$svnrepo"/branches/branch2 && + svn switch "$svnrepo"/branches/branch1 && + touch baz && + svn add baz && + svn commit -m x && + svn switch "$svnrepo"/trunk && + svn merge "$svnrepo"/branches/branch1 && + svn commit -m "merge" && + svn switch "$svnrepo"/branches/branch1 && + svn commit -m x && + svn switch "$svnrepo"/branches/branch2 && + svn merge "$svnrepo"/branches/branch1 && + svn commit -m "merge branch1" && + svn switch "$svnrepo"/trunk && + svn merge "$svnrepo"/branches/branch2 && + svn resolved baz && + svn commit -m "merge branch2" + ) && + rm -rf "$SVN_TREE" +' + +test_expect_success 'clone svn repo' ' + git svn init -s "$svnrepo" && + git svn fetch +' + +test_expect_success 'verify merge commit' 'git rev-parse HEAD^2' + +test_done diff --git a/t/t9158-git-svn-mergeinfo.sh b/t/t9158-git-svn-mergeinfo.sh new file mode 100755 index 0000000000..3ab43902b3 --- /dev/null +++ b/t/t9158-git-svn-mergeinfo.sh @@ -0,0 +1,41 @@ +#!/bin/sh +# +# Copyright (c) 2010 Steven Walter +# + +test_description='git svn mergeinfo propagation' + +. ./lib-git-svn.sh + +say 'define NO_SVN_TESTS to skip git svn tests' + +test_expect_success 'initialize source svn repo' ' + svn_cmd mkdir -m x "$svnrepo"/trunk && + svn_cmd co "$svnrepo"/trunk "$SVN_TREE" && + ( + cd "$SVN_TREE" && + touch foo && + svn_cmd add foo && + svn_cmd commit -m "initial commit" + ) && + rm -rf "$SVN_TREE" +' + +test_expect_success 'clone svn repo' ' + git svn init "$svnrepo"/trunk && + git svn fetch +' + +test_expect_success 'change svn:mergeinfo' ' + touch bar && + git add bar && + git commit -m "bar" && + git svn dcommit --mergeinfo="/branches/foo:1-10" +' + +test_expect_success 'verify svn:mergeinfo' ' + mergeinfo=$(svn_cmd propget svn:mergeinfo "$svnrepo"/trunk) + test "$mergeinfo" = "/branches/foo:1-10" +' + +test_done diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh index 7c059204e9..6b1ba6c858 100755 --- a/t/t9300-fast-import.sh +++ b/t/t9300-fast-import.sh @@ -7,6 +7,23 @@ test_description='test git fast-import utility' . ./test-lib.sh . "$TEST_DIRECTORY"/diff-lib.sh ;# test-lib chdir's into trash +# Print $1 bytes from stdin to stdout. +# +# This could be written as "head -c $1", but IRIX "head" does not +# support the -c option. +head_c () { + perl -e ' + my $len = $ARGV[1]; + while ($len > 0) { + my $s; + my $nread = sysread(STDIN, $s, $len); + die "cannot read: $!" unless defined($nread); + print $s; + $len -= $nread; + } + ' - "$1" +} + file2_data='file2 second line of EOF' @@ -23,11 +40,26 @@ file5_data='an inline file. file6_data='#!/bin/sh echo "$@"' +>empty + +test_expect_success 'setup: have pipes?' ' + rm -f frob && + if mkfifo frob + then + test_set_prereq PIPE + fi +' + ### ### series A ### test_tick + +test_expect_success 'empty stream succeeds' ' + git fast-import </dev/null +' + cat >input <<INPUT_END blob mark :2 @@ -321,7 +353,7 @@ test_expect_success \ 'for p in .git/objects/pack/*.pack;do git verify-pack $p||exit;done' test_expect_success \ 'C: validate reuse existing blob' \ - 'test $newf = `git rev-parse --verify branch:file2/newf` + 'test $newf = `git rev-parse --verify branch:file2/newf` && test $oldf = `git rev-parse --verify branch:file2/oldf`' cat >expect <<EOF @@ -874,6 +906,140 @@ test_expect_success \ git diff-tree -C --find-copies-harder -r N4^ N4 >actual && compare_diff_raw expect actual' +test_expect_success PIPE 'N: read and copy directory' ' + cat >expect <<-\EOF + :100755 100755 f1fb5da718392694d0076d677d6d0e364c79b0bc f1fb5da718392694d0076d677d6d0e364c79b0bc C100 file2/newf file3/newf + :100644 100644 7123f7f44e39be127c5eb701e5968176ee9d78b1 7123f7f44e39be127c5eb701e5968176ee9d78b1 C100 file2/oldf file3/oldf + EOF + git update-ref -d refs/heads/N4 && + rm -f backflow && + mkfifo backflow && + ( + exec <backflow && + cat <<-EOF && + commit refs/heads/N4 + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + data <<COMMIT + copy by tree hash, part 2 + COMMIT + + from refs/heads/branch^0 + ls "file2" + EOF + read mode type tree filename && + echo "M 040000 $tree file3" + ) | + git fast-import --cat-blob-fd=3 3>backflow && + git diff-tree -C --find-copies-harder -r N4^ N4 >actual && + compare_diff_raw expect actual +' + +test_expect_success PIPE 'N: empty directory reads as missing' ' + cat <<-\EOF >expect && + OBJNAME + :000000 100644 OBJNAME OBJNAME A unrelated + EOF + echo "missing src" >expect.response && + git update-ref -d refs/heads/read-empty && + rm -f backflow && + mkfifo backflow && + ( + exec <backflow && + cat <<-EOF && + commit refs/heads/read-empty + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + data <<COMMIT + read "empty" (missing) directory + COMMIT + + M 100644 inline src/greeting + data <<BLOB + hello + BLOB + C src/greeting dst1/non-greeting + C src/greeting unrelated + # leave behind "empty" src directory + D src/greeting + ls "src" + EOF + read -r line && + printf "%s\n" "$line" >response && + cat <<-\EOF + D dst1 + D dst2 + EOF + ) | + git fast-import --cat-blob-fd=3 3>backflow && + test_cmp expect.response response && + git rev-list read-empty | + git diff-tree -r --root --stdin | + sed "s/$_x40/OBJNAME/g" >actual && + test_cmp expect actual +' + +test_expect_success \ + 'N: copy root directory by tree hash' \ + 'cat >expect <<-\EOF && + :100755 000000 f1fb5da718392694d0076d677d6d0e364c79b0bc 0000000000000000000000000000000000000000 D file3/newf + :100644 000000 7123f7f44e39be127c5eb701e5968176ee9d78b1 0000000000000000000000000000000000000000 D file3/oldf + EOF + root=$(git rev-parse refs/heads/branch^0^{tree}) && + cat >input <<-INPUT_END && + commit refs/heads/N6 + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + data <<COMMIT + copy root directory by tree hash + COMMIT + + from refs/heads/branch^0 + M 040000 $root "" + INPUT_END + git fast-import <input && + git diff-tree -C --find-copies-harder -r N4 N6 >actual && + compare_diff_raw expect actual' + +test_expect_success \ + 'N: delete directory by copying' \ + 'cat >expect <<-\EOF && + OBJID + :100644 000000 OBJID OBJID D foo/bar/qux + OBJID + :000000 100644 OBJID OBJID A foo/bar/baz + :000000 100644 OBJID OBJID A foo/bar/qux + EOF + empty_tree=$(git mktree </dev/null) && + cat >input <<-INPUT_END && + commit refs/heads/N-delete + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + data <<COMMIT + collect data to be deleted + COMMIT + + deleteall + M 100644 inline foo/bar/baz + data <<DATA_END + hello + DATA_END + C "foo/bar/baz" "foo/bar/qux" + C "foo/bar/baz" "foo/bar/quux/1" + C "foo/bar/baz" "foo/bar/quuux" + M 040000 $empty_tree foo/bar/quux + M 040000 $empty_tree foo/bar/quuux + + commit refs/heads/N-delete + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + data <<COMMIT + delete subdirectory + COMMIT + + M 040000 $empty_tree foo/bar/qux + INPUT_END + git fast-import <input && + git rev-list N-delete | + git diff-tree -r --stdin --root --always | + sed -e "s/$_x40/OBJID/g" >actual && + test_cmp expect actual' + test_expect_success \ 'N: modify copied tree' \ 'cat >expect <<-\EOF && @@ -907,6 +1073,114 @@ test_expect_success \ git diff-tree -C --find-copies-harder -r N5^^ N5 >actual && compare_diff_raw expect actual' +test_expect_success \ + 'N: reject foo/ syntax' \ + 'subdir=$(git rev-parse refs/heads/branch^0:file2) && + test_must_fail git fast-import <<-INPUT_END + commit refs/heads/N5B + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + data <<COMMIT + copy with invalid syntax + COMMIT + + from refs/heads/branch^0 + M 040000 $subdir file3/ + INPUT_END' + +test_expect_success \ + 'N: copy to root by id and modify' \ + 'echo "hello, world" >expect.foo && + echo hello >expect.bar && + git fast-import <<-SETUP_END && + commit refs/heads/N7 + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + data <<COMMIT + hello, tree + COMMIT + + deleteall + M 644 inline foo/bar + data <<EOF + hello + EOF + SETUP_END + + tree=$(git rev-parse --verify N7:) && + git fast-import <<-INPUT_END && + commit refs/heads/N8 + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + data <<COMMIT + copy to root by id and modify + COMMIT + + M 040000 $tree "" + M 644 inline foo/foo + data <<EOF + hello, world + EOF + INPUT_END + git show N8:foo/foo >actual.foo && + git show N8:foo/bar >actual.bar && + test_cmp expect.foo actual.foo && + test_cmp expect.bar actual.bar' + +test_expect_success \ + 'N: extract subtree' \ + 'branch=$(git rev-parse --verify refs/heads/branch^{tree}) && + cat >input <<-INPUT_END && + commit refs/heads/N9 + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + data <<COMMIT + extract subtree branch:newdir + COMMIT + + M 040000 $branch "" + C "newdir" "" + INPUT_END + git fast-import <input && + git diff --exit-code branch:newdir N9' + +test_expect_success \ + 'N: modify subtree, extract it, and modify again' \ + 'echo hello >expect.baz && + echo hello, world >expect.qux && + git fast-import <<-SETUP_END && + commit refs/heads/N10 + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + data <<COMMIT + hello, tree + COMMIT + + deleteall + M 644 inline foo/bar/baz + data <<EOF + hello + EOF + SETUP_END + + tree=$(git rev-parse --verify N10:) && + git fast-import <<-INPUT_END && + commit refs/heads/N11 + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + data <<COMMIT + copy to root by id and modify + COMMIT + + M 040000 $tree "" + M 100644 inline foo/bar/qux + data <<EOF + hello, world + EOF + R "foo" "" + C "bar/qux" "bar/quux" + INPUT_END + git show N11:bar/baz >actual.baz && + git show N11:bar/qux >actual.qux && + git show N11:bar/quux >actual.quux && + test_cmp expect.baz actual.baz && + test_cmp expect.qux actual.qux && + test_cmp expect.qux actual.quux' + ### ### series O ### @@ -1553,6 +1827,61 @@ test_expect_success \ 'cat input | git fast-import --export-marks=other.marks && grep :1 other.marks' +test_expect_success 'R: catch typo in marks file name' ' + test_must_fail git fast-import --import-marks=nonexistent.marks </dev/null && + echo "feature import-marks=nonexistent.marks" | + test_must_fail git fast-import +' + +test_expect_success 'R: import and output marks can be the same file' ' + rm -f io.marks && + blob=$(echo hi | git hash-object --stdin) && + cat >expect <<-EOF && + :1 $blob + :2 $blob + EOF + git fast-import --export-marks=io.marks <<-\EOF && + blob + mark :1 + data 3 + hi + + EOF + git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF && + blob + mark :2 + data 3 + hi + + EOF + test_cmp expect io.marks +' + +test_expect_success 'R: --import-marks=foo --output-marks=foo to create foo fails' ' + rm -f io.marks && + test_must_fail git fast-import --import-marks=io.marks --export-marks=io.marks <<-\EOF + blob + mark :1 + data 3 + hi + + EOF +' + +test_expect_success 'R: --import-marks-if-exists' ' + rm -f io.marks && + blob=$(echo hi | git hash-object --stdin) && + echo ":1 $blob" >expect && + git fast-import --import-marks-if-exists=io.marks --export-marks=io.marks <<-\EOF && + blob + mark :1 + data 3 + hi + + EOF + test_cmp expect io.marks +' + cat >input << EOF feature import-marks=marks.out feature export-marks=marks.new @@ -1611,6 +1940,250 @@ test_expect_success 'R: feature no-relative-marks should be honoured' ' test_cmp marks.new non-relative.out ' +test_expect_success 'R: feature ls supported' ' + echo "feature ls" | + git fast-import +' + +test_expect_success 'R: feature cat-blob supported' ' + echo "feature cat-blob" | + git fast-import +' + +test_expect_success 'R: cat-blob-fd must be a nonnegative integer' ' + test_must_fail git fast-import --cat-blob-fd=-1 </dev/null +' + +test_expect_success 'R: print old blob' ' + blob=$(echo "yes it can" | git hash-object -w --stdin) && + cat >expect <<-EOF && + ${blob} blob 11 + yes it can + + EOF + echo "cat-blob $blob" | + git fast-import --cat-blob-fd=6 6>actual && + test_cmp expect actual +' + +test_expect_success 'R: in-stream cat-blob-fd not respected' ' + echo hello >greeting && + blob=$(git hash-object -w greeting) && + cat >expect <<-EOF && + ${blob} blob 6 + hello + + EOF + git fast-import --cat-blob-fd=3 3>actual.3 >actual.1 <<-EOF && + cat-blob $blob + EOF + test_cmp expect actual.3 && + test_cmp empty actual.1 && + git fast-import 3>actual.3 >actual.1 <<-EOF && + option cat-blob-fd=3 + cat-blob $blob + EOF + test_cmp empty actual.3 && + test_cmp expect actual.1 +' + +test_expect_success 'R: print new blob' ' + blob=$(echo "yep yep yep" | git hash-object --stdin) && + cat >expect <<-EOF && + ${blob} blob 12 + yep yep yep + + EOF + git fast-import --cat-blob-fd=6 6>actual <<-\EOF && + blob + mark :1 + data <<BLOB_END + yep yep yep + BLOB_END + cat-blob :1 + EOF + test_cmp expect actual +' + +test_expect_success 'R: print new blob by sha1' ' + blob=$(echo "a new blob named by sha1" | git hash-object --stdin) && + cat >expect <<-EOF && + ${blob} blob 25 + a new blob named by sha1 + + EOF + git fast-import --cat-blob-fd=6 6>actual <<-EOF && + blob + data <<BLOB_END + a new blob named by sha1 + BLOB_END + cat-blob $blob + EOF + test_cmp expect actual +' + +test_expect_success 'setup: big file' ' + ( + echo "the quick brown fox jumps over the lazy dog" >big && + for i in 1 2 3 + do + cat big big big big >bigger && + cat bigger bigger bigger bigger >big || + exit + done + ) +' + +test_expect_success 'R: print two blobs to stdout' ' + blob1=$(git hash-object big) && + blob1_len=$(wc -c <big) && + blob2=$(echo hello | git hash-object --stdin) && + { + echo ${blob1} blob $blob1_len && + cat big && + cat <<-EOF + + ${blob2} blob 6 + hello + + EOF + } >expect && + { + cat <<-\END_PART1 && + blob + mark :1 + data <<data_end + END_PART1 + cat big && + cat <<-\EOF + data_end + blob + mark :2 + data <<data_end + hello + data_end + cat-blob :1 + cat-blob :2 + EOF + } | + git fast-import >actual && + test_cmp expect actual +' + +test_expect_success PIPE 'R: copy using cat-file' ' + expect_id=$(git hash-object big) && + expect_len=$(wc -c <big) && + echo $expect_id blob $expect_len >expect.response && + + rm -f blobs && + cat >frontend <<-\FRONTEND_END && + #!/bin/sh + FRONTEND_END + + mkfifo blobs && + ( + export GIT_COMMITTER_NAME GIT_COMMITTER_EMAIL GIT_COMMITTER_DATE && + cat <<-\EOF && + feature cat-blob + blob + mark :1 + data <<BLOB + EOF + cat big && + cat <<-\EOF && + BLOB + cat-blob :1 + EOF + + read blob_id type size <&3 && + echo "$blob_id $type $size" >response && + head_c $size >blob <&3 && + read newline <&3 && + + cat <<-EOF && + commit refs/heads/copied + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + data <<COMMIT + copy big file as file3 + COMMIT + M 644 inline file3 + data <<BLOB + EOF + cat blob && + echo BLOB + ) 3<blobs | + git fast-import --cat-blob-fd=3 3>blobs && + git show copied:file3 >actual && + test_cmp expect.response response && + test_cmp big actual +' + +test_expect_success PIPE 'R: print blob mid-commit' ' + rm -f blobs && + echo "A blob from _before_ the commit." >expect && + mkfifo blobs && + ( + exec 3<blobs && + cat <<-EOF && + feature cat-blob + blob + mark :1 + data <<BLOB + A blob from _before_ the commit. + BLOB + commit refs/heads/temporary + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + data <<COMMIT + Empty commit + COMMIT + cat-blob :1 + EOF + + read blob_id type size <&3 && + head_c $size >actual <&3 && + read newline <&3 && + + echo + ) | + git fast-import --cat-blob-fd=3 3>blobs && + test_cmp expect actual +' + +test_expect_success PIPE 'R: print staged blob within commit' ' + rm -f blobs && + echo "A blob from _within_ the commit." >expect && + mkfifo blobs && + ( + exec 3<blobs && + cat <<-EOF && + feature cat-blob + commit refs/heads/within + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + data <<COMMIT + Empty commit + COMMIT + M 644 inline within + data <<BLOB + A blob from _within_ the commit. + BLOB + EOF + + to_get=$( + echo "A blob from _within_ the commit." | + git hash-object --stdin + ) && + echo "cat-blob $to_get" && + + read blob_id type size <&3 && + head_c $size >actual <&3 && + read newline <&3 && + + echo deleteall + ) | + git fast-import --cat-blob-fd=3 3>blobs && + test_cmp expect actual +' + cat >input << EOF option git quiet blob @@ -1619,8 +2192,6 @@ hi EOF -touch empty - test_expect_success 'R: quiet option results in no stats being output' ' cat input | git fast-import 2> output && test_cmp empty output @@ -1638,6 +2209,14 @@ test_expect_success 'R: unknown commandline options are rejected' '\ test_must_fail git fast-import --non-existing-option < /dev/null ' +test_expect_success 'R: die on invalid option argument' ' + echo "option git active-branches=-5" | + test_must_fail git fast-import && + echo "option git depth=" | + test_must_fail git fast-import && + test_must_fail git fast-import --depth="5 elephants" </dev/null +' + cat >input <<EOF option non-existing-vcs non-existing-option EOF diff --git a/t/t9301-fast-import-notes.sh b/t/t9301-fast-import-notes.sh index a5c99d8507..463254c727 100755 --- a/t/t9301-fast-import-notes.sh +++ b/t/t9301-fast-import-notes.sh @@ -120,6 +120,7 @@ test_expect_success 'add notes with simple M command' ' test_tick cat >input <<INPUT_END +feature notes commit refs/notes/test committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <<COMMIT @@ -255,13 +256,18 @@ EOF INPUT_END +whitespace=" " + cat >expect <<EXPECT_END fourth commit pre-prefix of note for fourth commit +$whitespace prefix of note for fourth commit +$whitespace third note for fourth commit third commit prefix of note for third commit +$whitespace third note for third commit second commit third note for second commit diff --git a/t/t9350-fast-export.sh b/t/t9350-fast-export.sh index 8c8e679468..f823c05305 100755 --- a/t/t9350-fast-export.sh +++ b/t/t9350-fast-export.sh @@ -26,7 +26,7 @@ test_expect_success 'setup' ' test_tick && git tag rein && git checkout -b wer HEAD^ && - echo lange > file2 + echo lange > file2 && test_tick && git commit -m sitzt file2 && test_tick && diff --git a/t/t9400-git-cvsserver-server.sh b/t/t9400-git-cvsserver-server.sh index 36c457e7f2..9199550ef4 100755 --- a/t/t9400-git-cvsserver-server.sh +++ b/t/t9400-git-cvsserver-server.sh @@ -57,7 +57,7 @@ test_expect_success 'setup' ' # as argument to co -d test_expect_success 'basic checkout' \ 'GIT_CONFIG="$git_config" cvs -Q co -d cvswork master && - test "$(echo $(grep -v ^D cvswork/CVS/Entries|cut -d/ -f2,3,5 | head -n 1))" = "empty/1.1/" + test "$(echo $(grep -v ^D cvswork/CVS/Entries|cut -d/ -f2,3,5 | head -n 1))" = "empty/1.1/" && test "$(echo $(grep -v ^D cvswork/CVS/Entries|cut -d/ -f2,3,5 | sed -ne \$p))" = "secondrootfile/1.1/"' #------------------------ diff --git a/t/t9401-git-cvsserver-crlf.sh b/t/t9401-git-cvsserver-crlf.sh index 1bbfd824e5..ff6d6fb473 100755 --- a/t/t9401-git-cvsserver-crlf.sh +++ b/t/t9401-git-cvsserver-crlf.sh @@ -70,7 +70,7 @@ test_expect_success 'setup' ' mkdir subdir && echo "Another text file" > subdir/file.h && echo "Another binary: Q (this time CR)" | q_to_cr > subdir/withCr.bin && - echo "Mixed up NUL, but marked text: Q <- there" | q_to_nul > mixedUp.c + echo "Mixed up NUL, but marked text: Q <- there" | q_to_nul > mixedUp.c && echo "Unspecified" > subdir/unspecified.other && echo "/*.bin -crlf" > .gitattributes && echo "/*.c crlf" >> .gitattributes && diff --git a/t/t9500-gitweb-standalone-no-errors.sh b/t/t9500-gitweb-standalone-no-errors.sh index 4f2b9b062b..afac5b56a8 100755 --- a/t/t9500-gitweb-standalone-no-errors.sh +++ b/t/t9500-gitweb-standalone-no-errors.sh @@ -18,42 +18,34 @@ or warnings to log.' test_expect_success \ 'no commits: projects_list (implicit)' \ 'gitweb_run' -test_debug 'cat gitweb.log' test_expect_success \ 'no commits: projects_index' \ 'gitweb_run "a=project_index"' -test_debug 'cat gitweb.log' test_expect_success \ 'no commits: .git summary (implicit)' \ 'gitweb_run "p=.git"' -test_debug 'cat gitweb.log' test_expect_success \ 'no commits: .git commit (implicit HEAD)' \ 'gitweb_run "p=.git;a=commit"' -test_debug 'cat gitweb.log' test_expect_success \ 'no commits: .git commitdiff (implicit HEAD)' \ 'gitweb_run "p=.git;a=commitdiff"' -test_debug 'cat gitweb.log' test_expect_success \ 'no commits: .git tree (implicit HEAD)' \ 'gitweb_run "p=.git;a=tree"' -test_debug 'cat gitweb.log' test_expect_success \ 'no commits: .git heads' \ 'gitweb_run "p=.git;a=heads"' -test_debug 'cat gitweb.log' test_expect_success \ 'no commits: .git tags' \ 'gitweb_run "p=.git;a=tags"' -test_debug 'cat gitweb.log' # ---------------------------------------------------------------------- @@ -69,52 +61,42 @@ test_expect_success \ test_expect_success \ 'projects_list (implicit)' \ 'gitweb_run' -test_debug 'cat gitweb.log' test_expect_success \ 'projects_index' \ 'gitweb_run "a=project_index"' -test_debug 'cat gitweb.log' test_expect_success \ '.git summary (implicit)' \ 'gitweb_run "p=.git"' -test_debug 'cat gitweb.log' test_expect_success \ '.git commit (implicit HEAD)' \ 'gitweb_run "p=.git;a=commit"' -test_debug 'cat gitweb.log' test_expect_success \ '.git commitdiff (implicit HEAD, root commit)' \ 'gitweb_run "p=.git;a=commitdiff"' -test_debug 'cat gitweb.log' test_expect_success \ '.git commitdiff_plain (implicit HEAD, root commit)' \ 'gitweb_run "p=.git;a=commitdiff_plain"' -test_debug 'cat gitweb.log' test_expect_success \ '.git commit (HEAD)' \ 'gitweb_run "p=.git;a=commit;h=HEAD"' -test_debug 'cat gitweb.log' test_expect_success \ '.git tree (implicit HEAD)' \ 'gitweb_run "p=.git;a=tree"' -test_debug 'cat gitweb.log' test_expect_success \ '.git blob (file)' \ 'gitweb_run "p=.git;a=blob;f=file"' -test_debug 'cat gitweb.log' test_expect_success \ '.git blob_plain (file)' \ 'gitweb_run "p=.git;a=blob_plain;f=file"' -test_debug 'cat gitweb.log' # ---------------------------------------------------------------------- # nonexistent objects @@ -122,37 +104,30 @@ test_debug 'cat gitweb.log' test_expect_success \ '.git commit (non-existent)' \ 'gitweb_run "p=.git;a=commit;h=non-existent"' -test_debug 'cat gitweb.log' test_expect_success \ '.git commitdiff (non-existent)' \ 'gitweb_run "p=.git;a=commitdiff;h=non-existent"' -test_debug 'cat gitweb.log' test_expect_success \ '.git commitdiff (non-existent vs HEAD)' \ 'gitweb_run "p=.git;a=commitdiff;hp=non-existent;h=HEAD"' -test_debug 'cat gitweb.log' test_expect_success \ '.git tree (0000000000000000000000000000000000000000)' \ 'gitweb_run "p=.git;a=tree;h=0000000000000000000000000000000000000000"' -test_debug 'cat gitweb.log' test_expect_success \ '.git tag (0000000000000000000000000000000000000000)' \ 'gitweb_run "p=.git;a=tag;h=0000000000000000000000000000000000000000"' -test_debug 'cat gitweb.log' test_expect_success \ '.git blob (non-existent)' \ 'gitweb_run "p=.git;a=blob;f=non-existent"' -test_debug 'cat gitweb.log' test_expect_success \ '.git blob_plain (non-existent)' \ 'gitweb_run "p=.git;a=blob_plain;f=non-existent"' -test_debug 'cat gitweb.log' # ---------------------------------------------------------------------- @@ -161,7 +136,6 @@ test_debug 'cat gitweb.log' test_expect_success \ 'commitdiff(0): root' \ 'gitweb_run "p=.git;a=commitdiff"' -test_debug 'cat gitweb.log' test_expect_success \ 'commitdiff(0): file added' \ @@ -169,21 +143,18 @@ test_expect_success \ git add new_file && git commit -a -m "File added." && gitweb_run "p=.git;a=commitdiff"' -test_debug 'cat gitweb.log' test_expect_success \ 'commitdiff(0): mode change' \ 'test_chmod +x new_file && git commit -a -m "Mode changed." && gitweb_run "p=.git;a=commitdiff"' -test_debug 'cat gitweb.log' test_expect_success \ 'commitdiff(0): file renamed' \ 'git mv new_file renamed_file && git commit -a -m "File renamed." && gitweb_run "p=.git;a=commitdiff"' -test_debug 'cat gitweb.log' test_expect_success SYMLINKS \ 'commitdiff(0): file to symlink' \ @@ -191,7 +162,6 @@ test_expect_success SYMLINKS \ ln -s file renamed_file && git commit -a -m "File to symlink." && gitweb_run "p=.git;a=commitdiff"' -test_debug 'cat gitweb.log' test_expect_success \ 'commitdiff(0): file deleted' \ @@ -199,7 +169,6 @@ test_expect_success \ rm -f renamed_file && git commit -a -m "File removed." && gitweb_run "p=.git;a=commitdiff"' -test_debug 'cat gitweb.log' test_expect_success \ 'commitdiff(0): file copied / new file' \ @@ -207,7 +176,6 @@ test_expect_success \ git add file2 && git commit -a -m "File copied." && gitweb_run "p=.git;a=commitdiff"' -test_debug 'cat gitweb.log' test_expect_success \ 'commitdiff(0): mode change and modified' \ @@ -215,7 +183,6 @@ test_expect_success \ test_chmod +x file2 && git commit -a -m "Mode change and modification." && gitweb_run "p=.git;a=commitdiff"' -test_debug 'cat gitweb.log' test_expect_success \ 'commitdiff(0): renamed and modified' \ @@ -233,7 +200,6 @@ EOF echo "Propter nomen suum." >> file3 && git commit -a -m "File rename and modification." && gitweb_run "p=.git;a=commitdiff"' -test_debug 'cat gitweb.log' test_expect_success \ 'commitdiff(0): renamed, mode change and modified' \ @@ -242,7 +208,6 @@ test_expect_success \ test_chmod +x file2 && git commit -a -m "File rename, mode change and modification." && gitweb_run "p=.git;a=commitdiff"' -test_debug 'cat gitweb.log' # ---------------------------------------------------------------------- # commitdiff testing (taken from t4114-apply-typechange.sh) @@ -279,42 +244,34 @@ test_expect_success SYMLINKS 'setup typechange commits' ' test_expect_success \ 'commitdiff(2): file renamed from foo to foo/baz' \ 'gitweb_run "p=.git;a=commitdiff;hp=initial;h=foo-baz-renamed-from-foo"' -test_debug 'cat gitweb.log' test_expect_success \ 'commitdiff(2): file renamed from foo/baz to foo' \ 'gitweb_run "p=.git;a=commitdiff;hp=foo-baz-renamed-from-foo;h=initial"' -test_debug 'cat gitweb.log' test_expect_success \ 'commitdiff(2): directory becomes file' \ 'gitweb_run "p=.git;a=commitdiff;hp=foo-becomes-a-directory;h=initial"' -test_debug 'cat gitweb.log' test_expect_success \ 'commitdiff(2): file becomes directory' \ 'gitweb_run "p=.git;a=commitdiff;hp=initial;h=foo-becomes-a-directory"' -test_debug 'cat gitweb.log' test_expect_success \ 'commitdiff(2): file becomes symlink' \ 'gitweb_run "p=.git;a=commitdiff;hp=initial;h=foo-symlinked-to-bar"' -test_debug 'cat gitweb.log' test_expect_success \ 'commitdiff(2): symlink becomes file' \ 'gitweb_run "p=.git;a=commitdiff;hp=foo-symlinked-to-bar;h=foo-back-to-file"' -test_debug 'cat gitweb.log' test_expect_success \ 'commitdiff(2): symlink becomes directory' \ 'gitweb_run "p=.git;a=commitdiff;hp=foo-symlinked-to-bar;h=foo-becomes-a-directory"' -test_debug 'cat gitweb.log' test_expect_success \ 'commitdiff(2): directory becomes symlink' \ 'gitweb_run "p=.git;a=commitdiff;hp=foo-becomes-a-directory;h=foo-symlinked-to-bar"' -test_debug 'cat gitweb.log' # ---------------------------------------------------------------------- # commit, commitdiff: merge, large @@ -330,12 +287,10 @@ test_expect_success \ test_expect_success \ 'commit(0): merge commit' \ 'gitweb_run "p=.git;a=commit"' -test_debug 'cat gitweb.log' test_expect_success \ 'commitdiff(0): merge commit' \ 'gitweb_run "p=.git;a=commitdiff"' -test_debug 'cat gitweb.log' test_expect_success \ 'Prepare large commit' \ @@ -371,12 +326,10 @@ test_expect_success \ test_expect_success \ 'commit(1): large commit' \ 'gitweb_run "p=.git;a=commit;h=b"' -test_debug 'cat gitweb.log' test_expect_success \ 'commitdiff(1): large commit' \ 'gitweb_run "p=.git;a=commitdiff;h=b"' -test_debug 'cat gitweb.log' # ---------------------------------------------------------------------- # tags testing @@ -394,17 +347,14 @@ test_expect_success \ git tag lightweight/tag-tree HEAD^{tree} && git tag lightweight/tag-blob HEAD:file && gitweb_run "p=.git;a=tags"' -test_debug 'cat gitweb.log' test_expect_success \ 'tag: Tag to commit object' \ 'gitweb_run "p=.git;a=tag;h=tag-commit"' -test_debug 'cat gitweb.log' test_expect_success \ 'tag: on lightweight tag (invalid)' \ 'gitweb_run "p=.git;a=tag;h=lightweight/tag-commit"' -test_debug 'cat gitweb.log' # ---------------------------------------------------------------------- # logs @@ -412,22 +362,18 @@ test_debug 'cat gitweb.log' test_expect_success \ 'logs: log (implicit HEAD)' \ 'gitweb_run "p=.git;a=log"' -test_debug 'cat gitweb.log' test_expect_success \ 'logs: shortlog (implicit HEAD)' \ 'gitweb_run "p=.git;a=shortlog"' -test_debug 'cat gitweb.log' test_expect_success \ 'logs: history (implicit HEAD, file)' \ 'gitweb_run "p=.git;a=history;f=file"' -test_debug 'cat gitweb.log' test_expect_success \ 'logs: history (implicit HEAD, non-existent file)' \ 'gitweb_run "p=.git;a=history;f=non-existent"' -test_debug 'cat gitweb.log' test_expect_success \ 'logs: history (implicit HEAD, deleted file)' \ @@ -438,55 +384,45 @@ test_expect_success \ git rm deleted_file && git commit -m "Delete file" && gitweb_run "p=.git;a=history;f=deleted_file"' -test_debug 'cat gitweb.log' # ---------------------------------------------------------------------- # path_info links test_expect_success \ 'path_info: project' \ 'gitweb_run "" "/.git"' -test_debug 'cat gitweb.log' test_expect_success \ 'path_info: project/branch' \ 'gitweb_run "" "/.git/b"' -test_debug 'cat gitweb.log' test_expect_success \ 'path_info: project/branch:file' \ 'gitweb_run "" "/.git/master:file"' -test_debug 'cat gitweb.log' test_expect_success \ 'path_info: project/branch:dir/' \ 'gitweb_run "" "/.git/master:foo/"' -test_debug 'cat gitweb.log' test_expect_success \ 'path_info: project/branch:file (non-existent)' \ 'gitweb_run "" "/.git/master:non-existent"' -test_debug 'cat gitweb.log' test_expect_success \ 'path_info: project/branch:dir/ (non-existent)' \ 'gitweb_run "" "/.git/master:non-existent/"' -test_debug 'cat gitweb.log' test_expect_success \ 'path_info: project/branch:/file' \ 'gitweb_run "" "/.git/master:/file"' -test_debug 'cat gitweb.log' test_expect_success \ 'path_info: project/:/file (implicit HEAD)' \ 'gitweb_run "" "/.git/:/file"' -test_debug 'cat gitweb.log' test_expect_success \ 'path_info: project/:/ (implicit HEAD, top tree)' \ 'gitweb_run "" "/.git/:/"' -test_debug 'cat gitweb.log' # ---------------------------------------------------------------------- @@ -495,17 +431,14 @@ test_debug 'cat gitweb.log' test_expect_success \ 'feeds: OPML' \ 'gitweb_run "a=opml"' -test_debug 'cat gitweb.log' test_expect_success \ 'feed: RSS' \ 'gitweb_run "p=.git;a=rss"' -test_debug 'cat gitweb.log' test_expect_success \ 'feed: Atom' \ 'gitweb_run "p=.git;a=atom"' -test_debug 'cat gitweb.log' # ---------------------------------------------------------------------- # encoding/decoding @@ -513,27 +446,28 @@ test_debug 'cat gitweb.log' test_expect_success \ 'encode(commit): utf8' \ '. "$TEST_DIRECTORY"/t3901-utf8.txt && + test_when_finished "GIT_AUTHOR_NAME=\"A U Thor\"" && + test_when_finished "GIT_COMMITTER_NAME=\"C O Mitter\"" && echo "UTF-8" >> file && git add file && git commit -F "$TEST_DIRECTORY"/t3900/1-UTF-8.txt && gitweb_run "p=.git;a=commit"' -test_debug 'cat gitweb.log' test_expect_success \ 'encode(commit): iso-8859-1' \ '. "$TEST_DIRECTORY"/t3901-8859-1.txt && + test_when_finished "GIT_AUTHOR_NAME=\"A U Thor\"" && + test_when_finished "GIT_COMMITTER_NAME=\"C O Mitter\"" && echo "ISO-8859-1" >> file && git add file && git config i18n.commitencoding ISO-8859-1 && + test_when_finished "git config --unset i18n.commitencoding" && git commit -F "$TEST_DIRECTORY"/t3900/ISO8859-1.txt && - git config --unset i18n.commitencoding && gitweb_run "p=.git;a=commit"' -test_debug 'cat gitweb.log' test_expect_success \ 'encode(log): utf-8 and iso-8859-1' \ 'gitweb_run "p=.git;a=log"' -test_debug 'cat gitweb.log' # ---------------------------------------------------------------------- # extra options @@ -541,27 +475,22 @@ test_debug 'cat gitweb.log' test_expect_success \ 'opt: log --no-merges' \ 'gitweb_run "p=.git;a=log;opt=--no-merges"' -test_debug 'cat gitweb.log' test_expect_success \ 'opt: atom --no-merges' \ 'gitweb_run "p=.git;a=log;opt=--no-merges"' -test_debug 'cat gitweb.log' test_expect_success \ 'opt: "file" history --no-merges' \ 'gitweb_run "p=.git;a=history;f=file;opt=--no-merges"' -test_debug 'cat gitweb.log' test_expect_success \ 'opt: log --no-such-option (invalid option)' \ 'gitweb_run "p=.git;a=log;opt=--no-such-option"' -test_debug 'cat gitweb.log' test_expect_success \ 'opt: tree --no-merges (invalid option for action)' \ 'gitweb_run "p=.git;a=tree;opt=--no-merges"' -test_debug 'cat gitweb.log' # ---------------------------------------------------------------------- # testing config_to_multi / cloneurl @@ -569,14 +498,12 @@ test_debug 'cat gitweb.log' test_expect_success \ 'URL: no project URLs, no base URL' \ 'gitweb_run "p=.git;a=summary"' -test_debug 'cat gitweb.log' test_expect_success \ 'URL: project URLs via gitweb.url' \ 'git config --add gitweb.url git://example.com/git/trash.git && git config --add gitweb.url http://example.com/git/trash.git && gitweb_run "p=.git;a=summary"' -test_debug 'cat gitweb.log' cat >.git/cloneurl <<\EOF git://example.com/git/trash.git @@ -586,7 +513,6 @@ EOF test_expect_success \ 'URL: project URLs via cloneurl file' \ 'gitweb_run "p=.git;a=summary"' -test_debug 'cat gitweb.log' # ---------------------------------------------------------------------- # gitweb config and repo config @@ -604,12 +530,10 @@ EOF test_expect_success \ 'config override: projects list (implicit)' \ 'gitweb_run' -test_debug 'cat gitweb.log' test_expect_success \ 'config override: tree view, features not overridden in repo config' \ 'gitweb_run "p=.git;a=tree"' -test_debug 'cat gitweb.log' test_expect_success \ 'config override: tree view, features disabled in repo config' \ @@ -617,14 +541,12 @@ test_expect_success \ git config gitweb.snapshot none && git config gitweb.avatar gravatar && gitweb_run "p=.git;a=tree"' -test_debug 'cat gitweb.log' test_expect_success \ 'config override: tree view, features enabled in repo config (1)' \ 'git config gitweb.blame yes && git config gitweb.snapshot "zip,tgz, tbz2" && gitweb_run "p=.git;a=tree"' -test_debug 'cat gitweb.log' cat >.git/config <<\EOF # testing noval and alternate separator @@ -635,7 +557,6 @@ EOF test_expect_success \ 'config override: tree view, features enabled in repo config (2)' \ 'gitweb_run "p=.git;a=tree"' -test_debug 'cat gitweb.log' # ---------------------------------------------------------------------- # non-ASCII in README.html @@ -645,35 +566,33 @@ test_expect_success \ 'echo "<b>UTF-8 example:</b><br />" > .git/README.html && cat "$TEST_DIRECTORY"/t3900/1-UTF-8.txt >> .git/README.html && gitweb_run "p=.git;a=summary"' -test_debug 'cat gitweb.log' # ---------------------------------------------------------------------- # syntax highlighting -cat >>gitweb_config.perl <<\EOF -$feature{'highlight'}{'override'} = 1; -EOF highlight --version >/dev/null 2>&1 if [ $? -eq 127 ]; then say "Skipping syntax highlighting test, because 'highlight' was not found" else test_set_prereq HIGHLIGHT + cat >>gitweb_config.perl <<-\EOF + our $highlight_bin = "highlight"; + $feature{'highlight'}{'override'} = 1; + EOF fi test_expect_success HIGHLIGHT \ - 'syntax highlighting (no highlight)' \ + 'syntax highlighting (no highlight, unknown syntax)' \ 'git config gitweb.highlight yes && gitweb_run "p=.git;a=blob;f=file"' -test_debug 'cat gitweb.log' test_expect_success HIGHLIGHT \ - 'syntax highlighting (highlighted)' \ + 'syntax highlighting (highlighted, shell script)' \ 'git config gitweb.highlight yes && echo "#!/usr/bin/sh" > test.sh && git add test.sh && git commit -m "Add test.sh" && gitweb_run "p=.git;a=blob;f=test.sh"' -test_debug 'cat gitweb.log' test_done diff --git a/t/t9501-gitweb-standalone-http-status.sh b/t/t9501-gitweb-standalone-http-status.sh index 2487da1296..26102ee9b0 100755 --- a/t/t9501-gitweb-standalone-http-status.sh +++ b/t/t9501-gitweb-standalone-http-status.sh @@ -16,7 +16,7 @@ code and message.' # snapshot settings test_expect_success 'setup' " - test_commit 'SnapshotTests' 'i can has snapshot?' + test_commit 'SnapshotTests' 'i can has snapshot' " @@ -126,7 +126,6 @@ test_expect_success 'load checking: load too high (default action)' ' grep "Status: 503 Service Unavailable" gitweb.headers && grep "503 - The load average on the server is too high" gitweb.body ' -test_debug 'cat gitweb.log' # just in case test_debug 'cat gitweb.headers' # turn off load checking diff --git a/t/t9600-cvsimport.sh b/t/t9600-cvsimport.sh index 432b82e3d5..4c384ff023 100755 --- a/t/t9600-cvsimport.sh +++ b/t/t9600-cvsimport.sh @@ -89,7 +89,8 @@ EOF test_expect_success PERL 'update git module' ' (cd module-git && - git cvsimport -a -R -z 0 module && + git config cvsimport.trackRevisions true && + git cvsimport -a -z 0 module && git merge origin ) && test_cmp module-cvs/o_fortuna module-git/o_fortuna @@ -117,7 +118,8 @@ test_expect_success PERL 'cvsimport.module config works' ' (cd module-git && git config cvsimport.module module && - git cvsimport -a -R -z0 && + git config cvsimport.trackRevisions true && + git cvsimport -a -z0 && git merge origin ) && test_cmp module-cvs/tick module-git/tick @@ -137,6 +139,7 @@ test_expect_success PERL 'import from a CVS working tree' ' $CVS co -d import-from-wt module && (cd import-from-wt && + git config cvsimport.trackRevisions false && git cvsimport -a -z0 && echo 1 >expect && git log -1 --pretty=format:%s%n >actual && diff --git a/t/t9700/test.pl b/t/t9700/test.pl index 671f38db2b..13ba96e21a 100755 --- a/t/t9700/test.pl +++ b/t/t9700/test.pl @@ -1,7 +1,7 @@ #!/usr/bin/perl use lib (split(/:/, $ENV{GITPERLLIB})); -use 5.006002; +use 5.008; use warnings; use strict; @@ -113,6 +113,16 @@ like($last_commit, qr/^[0-9a-fA-F]{40}$/, 'rev-parse returned hash'); my $dir_commit = $r2->command_oneline('log', '-n1', '--pretty=format:%H', '.'); isnt($last_commit, $dir_commit, 'log . does not show last commit'); +# commands outside working tree +chdir($abs_repo_dir . '/..'); +my $r3 = Git->repository(Directory => $abs_repo_dir); +my $tmpfile3 = "$abs_repo_dir/file3.tmp"; +open TEMPFILE3, "+>$tmpfile3" or die "Can't open $tmpfile3: $!"; +is($r3->cat_blob($file1hash, \*TEMPFILE3), 15, "cat_blob(outside): size"); +close TEMPFILE3; +unlink $tmpfile3; +chdir($abs_repo_dir); + printf "1..%d\n", Test::More->builder->current_test; my $is_passing = eval { Test::More->is_passing }; diff --git a/t/t9800-git-p4.sh b/t/t9800-git-p4.sh new file mode 100755 index 0000000000..a523473954 --- /dev/null +++ b/t/t9800-git-p4.sh @@ -0,0 +1,139 @@ +#!/bin/sh + +test_description='git-p4 tests' + +. ./test-lib.sh + +( p4 -h && p4d -h ) >/dev/null 2>&1 || { + skip_all='skipping git-p4 tests; no p4 or p4d' + test_done +} + +GITP4=$GIT_BUILD_DIR/contrib/fast-import/git-p4 +P4DPORT=10669 + +db="$TRASH_DIRECTORY/db" +cli="$TRASH_DIRECTORY/cli" +git="$TRASH_DIRECTORY/git" + +test_debug 'echo p4d -q -d -r "$db" -p $P4DPORT' +test_expect_success setup ' + mkdir -p "$db" && + p4d -q -d -r "$db" -p $P4DPORT && + mkdir -p "$cli" && + mkdir -p "$git" && + export P4PORT=localhost:$P4DPORT +' + +test_expect_success 'add p4 files' ' + cd "$cli" && + p4 client -i <<-EOF && + Client: client + Description: client + Root: $cli + View: //depot/... //client/... + EOF + export P4CLIENT=client && + echo file1 >file1 && + p4 add file1 && + p4 submit -d "file1" && + echo file2 >file2 && + p4 add file2 && + p4 submit -d "file2" && + cd "$TRASH_DIRECTORY" +' + +test_expect_success 'basic git-p4 clone' ' + "$GITP4" clone --dest="$git" //depot && + cd "$git" && + git log --oneline >lines && + test_line_count = 1 lines && + cd .. && + rm -rf "$git" && mkdir "$git" +' + +test_expect_success 'git-p4 clone @all' ' + "$GITP4" clone --dest="$git" //depot@all && + cd "$git" && + git log --oneline >lines && + test_line_count = 2 lines && + cd .. && + rm -rf "$git" && mkdir "$git" +' + +test_expect_success 'git-p4 sync uninitialized repo' ' + test_create_repo "$git" && + cd "$git" && + test_must_fail "$GITP4" sync && + rm -rf "$git" && mkdir "$git" +' + +# +# Create a git repo by hand. Add a commit so that HEAD is valid. +# Test imports a new p4 repository into a new git branch. +# +test_expect_success 'git-p4 sync new branch' ' + test_create_repo "$git" && + cd "$git" && + test_commit head && + "$GITP4" sync --branch=refs/remotes/p4/depot //depot@all && + git log --oneline p4/depot >lines && + cat lines && + test_line_count = 2 lines && + cd .. && + rm -rf "$git" && mkdir "$git" +' + +test_expect_success 'exit when p4 fails to produce marshaled output' ' + badp4dir="$TRASH_DIRECTORY/badp4dir" && + mkdir -p "$badp4dir" && + cat >"$badp4dir"/p4 <<-EOF && + #!$SHELL_PATH + exit 1 + EOF + chmod 755 "$badp4dir"/p4 && + PATH="$badp4dir:$PATH" "$GITP4" clone --dest="$git" //depot >errs 2>&1 ; retval=$? && + test $retval -eq 1 && + test_must_fail grep -q Traceback errs +' + +test_expect_success 'add p4 files with wildcards in the names' ' + cd "$cli" && + echo file-wild-hash >file-wild#hash && + echo file-wild-star >file-wild\*star && + echo file-wild-at >file-wild@at && + echo file-wild-percent >file-wild%percent && + p4 add -f file-wild* && + p4 submit -d "file wildcards" && + cd "$TRASH_DIRECTORY" +' + +test_expect_success 'wildcard files git-p4 clone' ' + "$GITP4" clone --dest="$git" //depot && + cd "$git" && + test -f file-wild#hash && + test -f file-wild\*star && + test -f file-wild@at && + test -f file-wild%percent && + cd "$TRASH_DIRECTORY" && + rm -rf "$git" && mkdir "$git" +' + +test_expect_success 'clone bare' ' + "$GITP4" clone --dest="$git" --bare //depot && + cd "$git" && + test ! -d .git && + bare=`git config --get core.bare` && + test "$bare" = true && + cd "$TRASH_DIRECTORY" && + rm -rf "$git" && mkdir "$git" +' + +test_expect_success 'shutdown' ' + pid=`pgrep -f p4d` && + test -n "$pid" && + test_debug "ps wl `echo $pid`" && + kill $pid +' + +test_done diff --git a/t/test-lib.sh b/t/test-lib.sh index 830e5e7360..abc47f3abc 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -43,33 +43,25 @@ TERM=dumb export LANG LC_ALL PAGER TERM TZ EDITOR=: unset VISUAL -unset GIT_EDITOR -unset AUTHOR_DATE -unset AUTHOR_EMAIL -unset AUTHOR_NAME -unset COMMIT_AUTHOR_EMAIL -unset COMMIT_AUTHOR_NAME unset EMAIL -unset GIT_ALTERNATE_OBJECT_DIRECTORIES -unset GIT_AUTHOR_DATE +unset $(perl -e ' + my @env = keys %ENV; + my $ok = join("|", qw( + TRACE + DEBUG + USE_LOOKUP + TEST + .*_TEST + PROVE + VALGRIND + )); + my @vars = grep(/^GIT_/ && !/^GIT_($ok)/o, @env); + print join("\n", @vars); +') GIT_AUTHOR_EMAIL=author@example.com GIT_AUTHOR_NAME='A U Thor' -unset GIT_COMMITTER_DATE GIT_COMMITTER_EMAIL=committer@example.com GIT_COMMITTER_NAME='C O Mitter' -unset GIT_DIFF_OPTS -unset GIT_DIR -unset GIT_WORK_TREE -unset GIT_EXTERNAL_DIFF -unset GIT_INDEX_FILE -unset GIT_OBJECT_DIRECTORY -unset GIT_CEILING_DIRECTORIES -unset SHA1_FILE_DIRECTORIES -unset SHA1_FILE_DIRECTORY -unset GIT_NOTES_REF -unset GIT_NOTES_DISPLAY_REF -unset GIT_NOTES_REWRITE_REF -unset GIT_NOTES_REWRITE_MODE GIT_MERGE_VERBOSITY=5 export GIT_MERGE_VERBOSITY export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME @@ -238,14 +230,51 @@ test_set_editor () { } test_decode_color () { - sed -e 's/.\[1m/<WHITE>/g' \ - -e 's/.\[31m/<RED>/g' \ - -e 's/.\[32m/<GREEN>/g' \ - -e 's/.\[33m/<YELLOW>/g' \ - -e 's/.\[34m/<BLUE>/g' \ - -e 's/.\[35m/<MAGENTA>/g' \ - -e 's/.\[36m/<CYAN>/g' \ - -e 's/.\[m/<RESET>/g' + awk ' + function name(n) { + if (n == 0) return "RESET"; + if (n == 1) return "BOLD"; + if (n == 30) return "BLACK"; + if (n == 31) return "RED"; + if (n == 32) return "GREEN"; + if (n == 33) return "YELLOW"; + if (n == 34) return "BLUE"; + if (n == 35) return "MAGENTA"; + if (n == 36) return "CYAN"; + if (n == 37) return "WHITE"; + if (n == 40) return "BLACK"; + if (n == 41) return "BRED"; + if (n == 42) return "BGREEN"; + if (n == 43) return "BYELLOW"; + if (n == 44) return "BBLUE"; + if (n == 45) return "BMAGENTA"; + if (n == 46) return "BCYAN"; + if (n == 47) return "BWHITE"; + } + { + while (match($0, /\033\[[0-9;]*m/) != 0) { + printf "%s<", substr($0, 1, RSTART-1); + codes = substr($0, RSTART+2, RLENGTH-3); + if (length(codes) == 0) + printf "%s", name(0) + else { + n = split(codes, ary, ";"); + sep = ""; + for (i = 1; i <= n; i++) { + printf "%s%s", sep, name(ary[i]); + sep = ";" + } + } + printf ">"; + $0 = substr($0, RSTART + RLENGTH, length($0) - RSTART - RLENGTH + 1); + } + print + } + ' +} + +nul_to_q () { + perl -pe 'y/\000/Q/' } q_to_nul () { @@ -268,6 +297,17 @@ remove_cr () { tr '\015' Q | sed -e 's/Q$//' } +# In some bourne shell implementations, the "unset" builtin returns +# nonzero status when a variable to be unset was not set in the first +# place. +# +# Use sane_unset when that should not be considered an error. + +sane_unset () { + unset "$@" + return 0 +} + test_tick () { if test -z "${test_tick+set}" then @@ -362,6 +402,15 @@ test_have_prereq () { test $total_prereq = $ok_prereq } +test_declared_prereq () { + case ",$test_prereq," in + *,$1,*) + return 0 + ;; + esac + return 1 +} + # You are not expected to call test_ok_ and test_failure_ directly, use # the text_expect_* functions instead. @@ -414,17 +463,17 @@ test_skip () { break esac done - if test -z "$to_skip" && test -n "$prereq" && - ! test_have_prereq "$prereq" + if test -z "$to_skip" && test -n "$test_prereq" && + ! test_have_prereq "$test_prereq" then to_skip=t fi case "$to_skip" in t) of_prereq= - if test "$missing_prereq" != "$prereq" + if test "$missing_prereq" != "$test_prereq" then - of_prereq=" of $prereq" + of_prereq=" of $test_prereq" fi say_color skip >&3 "skipping test: $@" @@ -438,9 +487,10 @@ test_skip () { } test_expect_failure () { - test "$#" = 3 && { prereq=$1; shift; } || prereq= + test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq= test "$#" = 2 || error "bug in the test script: not 2 or 3 parameters to test-expect-failure" + export test_prereq if ! test_skip "$@" then say >&3 "checking known breakage: $2" @@ -456,9 +506,10 @@ test_expect_failure () { } test_expect_success () { - test "$#" = 3 && { prereq=$1; shift; } || prereq= + test "$#" = 3 && { test_prereq=$1; shift; } || test_prereq= test "$#" = 2 || error "bug in the test script: not 2 or 3 parameters to test-expect-success" + export test_prereq if ! test_skip "$@" then say >&3 "expecting success: $2" @@ -473,24 +524,6 @@ test_expect_success () { echo >&3 "" } -test_expect_code () { - test "$#" = 4 && { prereq=$1; shift; } || prereq= - test "$#" = 3 || - error "bug in the test script: not 3 or 4 parameters to test-expect-code" - if ! test_skip "$@" - then - say >&3 "expecting exit code $1: $3" - test_run_ "$3" - if [ "$?" = 0 -a "$eval_ret" = "$1" ] - then - test_ok_ "$2" - else - test_failure_ "$@" - fi - fi - echo >&3 "" -} - # test_external runs external test scripts that provide continuous # test output about their progress, and succeeds/fails on # zero/non-zero exit code. It outputs the test output on stdout even @@ -500,11 +533,12 @@ test_expect_code () { # Usage: test_external description command arguments... # Example: test_external 'Perl API' perl ../path/to/test.pl test_external () { - test "$#" = 4 && { prereq=$1; shift; } || prereq= + test "$#" = 4 && { test_prereq=$1; shift; } || test_prereq= test "$#" = 3 || error >&5 "bug in the test script: not 3 or 4 parameters to test_external" descr="$1" shift + export test_prereq if ! test_skip "$descr" "$@" then # Announce the script to reduce confusion about the @@ -605,6 +639,28 @@ test_path_is_missing () { fi } +# test_line_count checks that a file has the number of lines it +# ought to. For example: +# +# test_expect_success 'produce exactly one line of output' ' +# do something >output && +# test_line_count = 1 output +# ' +# +# is like "test $(wc -l <output) = 1" except that it passes the +# output through when the number of lines is wrong. + +test_line_count () { + if test $# != 3 + then + error "bug in the test script: not 3 parameters to test_line_count" + elif ! test $(wc -l <"$3") "$1" "$2" + then + echo "test_line_count: line count for $3 !$1 $2" + cat "$3" + return 1 + fi +} # This is not among top-level (test_expect_success | test_expect_failure) # but is a prefix that can be used in the test script, like: @@ -658,6 +714,28 @@ test_might_fail () { return 0 } +# Similar to test_must_fail and test_might_fail, but check that a +# given command exited with a given exit code. Meant to be used as: +# +# test_expect_success 'Merge with d/f conflicts' ' +# test_expect_code 1 git merge "merge msg" B master +# ' + +test_expect_code () { + want_code=$1 + shift + "$@" + exit_code=$? + if test $exit_code = $want_code + then + echo >&2 "test_expect_code: command exited with $exit_code: $*" + return 0 + else + echo >&2 "test_expect_code: command exited with $exit_code, we wanted $want_code $*" + return 1 + fi +} + # test_cmp is a helper function to compare actual and expected output. # You can use it like: # @@ -865,8 +943,8 @@ fi GIT_TEMPLATE_DIR="$GIT_BUILD_DIR"/templates/blt unset GIT_CONFIG GIT_CONFIG_NOSYSTEM=1 -GIT_CONFIG_NOGLOBAL=1 -export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_CONFIG_NOGLOBAL +GIT_ATTR_NOSYSTEM=1 +export PATH GIT_EXEC_PATH GIT_TEMPLATE_DIR GIT_CONFIG_NOSYSTEM GIT_ATTR_NOSYSTEM . "$GIT_BUILD_DIR"/GIT-BUILD-OPTIONS @@ -915,14 +993,14 @@ rm -fr "$test" || { exit 1 } +HOME="$TRASH_DIRECTORY" +export HOME + test_create_repo "$test" # 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 "$test" || exit 1 -HOME=$(pwd) -export HOME - this_test=${0##*/} this_test=${this_test%%-*} for skp in $GIT_SKIP_TESTS @@ -970,17 +1048,35 @@ case $(uname -s) in # no POSIX permissions # backslashes in pathspec are converted to '/' # exec does not inherit the PID + test_set_prereq MINGW + test_set_prereq SED_STRIPS_CR + ;; +*CYGWIN*) + test_set_prereq POSIXPERM + test_set_prereq EXECKEEPSPID + test_set_prereq NOT_MINGW + test_set_prereq SED_STRIPS_CR ;; *) test_set_prereq POSIXPERM test_set_prereq BSLASHPSPEC test_set_prereq EXECKEEPSPID + test_set_prereq NOT_MINGW ;; esac test -z "$NO_PERL" && test_set_prereq PERL test -z "$NO_PYTHON" && test_set_prereq PYTHON +# Can we rely on git's output in the C locale? +if test -n "$GETTEXT_POISON" +then + GIT_GETTEXT_POISON=YesPlease + export GIT_GETTEXT_POISON +else + test_set_prereq C_LOCALE_OUTPUT +fi + # test whether the filesystem supports symbolic links ln -s x y 2>/dev/null && test -h y 2>/dev/null && test_set_prereq SYMLINKS rm -f y diff --git a/t/t7006/test-terminal.perl b/t/test-terminal.perl index 73ff809371..ee01eb957e 100755 --- a/t/t7006/test-terminal.perl +++ b/t/test-terminal.perl @@ -1,17 +1,19 @@ #!/usr/bin/perl +use 5.008; use strict; use warnings; use IO::Pty; use File::Copy; -# Run @$argv in the background with stdout redirected to $out. +# Run @$argv in the background with stdio redirected to $out and $err. sub start_child { - my ($argv, $out) = @_; + my ($argv, $out, $err) = @_; my $pid = fork; if (not defined $pid) { die "fork failed: $!" } elsif ($pid == 0) { open STDOUT, ">&", $out; + open STDERR, ">&", $err; close $out; exec(@$argv) or die "cannot exec '$argv->[0]': $!" } @@ -47,12 +49,28 @@ sub xsendfile { copy($in, $out, 4096) or $!{EIO} or die "cannot copy from child: $!"; } +sub copy_stdio { + my ($out, $err) = @_; + my $pid = fork; + defined $pid or die "fork failed: $!"; + if (!$pid) { + close($out); + xsendfile(\*STDERR, $err); + exit 0; + } + close($err); + xsendfile(\*STDOUT, $out); + finish_child($pid) == 0 + or exit 1; +} + if ($#ARGV < 1) { die "usage: test-terminal program args"; } -my $master = new IO::Pty; -my $slave = $master->slave; -my $pid = start_child(\@ARGV, $slave); -close $slave; -xsendfile(\*STDOUT, $master); +my $master_out = new IO::Pty; +my $master_err = new IO::Pty; +my $pid = start_child(\@ARGV, $master_out->slave, $master_err->slave); +close $master_out->slave; +close $master_err->slave; +copy_stdio($master_out, $master_err); exit(finish_child($pid)); diff --git a/t/valgrind/default.supp b/t/valgrind/default.supp index 9e013fa3b2..0a6724fcc4 100644 --- a/t/valgrind/default.supp +++ b/t/valgrind/default.supp @@ -43,3 +43,9 @@ fun:write_buffer fun:write_loose_object } + +{ + ignore-sse-strlen-invalid-read-size + Memcheck:Addr4 + fun:copy_ref +} |