diff options
Diffstat (limited to 't')
155 files changed, 4407 insertions, 860 deletions
diff --git a/t/Makefile b/t/Makefile index 8fd1a72357..43b15e36ae 100644 --- a/t/Makefile +++ b/t/Makefile @@ -13,7 +13,7 @@ TAR ?= $(TAR) RM ?= rm -f PROVE ?= prove DEFAULT_TEST_TARGET ?= test -TEST_LINT ?= test-lint-duplicates test-lint-executable +TEST_LINT ?= test-lint ifdef TEST_OUTPUT_DIRECTORY TEST_RESULTS_DIRECTORY = $(TEST_OUTPUT_DIRECTORY)/test-results @@ -29,6 +29,7 @@ TEST_RESULTS_DIRECTORY_SQ = $(subst ','\'',$(TEST_RESULTS_DIRECTORY)) T = $(sort $(wildcard t[0-9][0-9][0-9][0-9]-*.sh)) TSVN = $(sort $(wildcard t91[0-9][0-9]-*.sh)) TGITWEB = $(sort $(wildcard t95[0-9][0-9]-*.sh)) +THELPERS = $(sort $(filter-out $(T),$(wildcard *.sh))) all: $(DEFAULT_TEST_TARGET) @@ -65,7 +66,7 @@ test-lint-executable: echo >&2 "non-executable tests:" $$bad; exit 1; } test-lint-shell-syntax: - @'$(PERL_PATH_SQ)' check-non-portable-shell.pl $(T) + @'$(PERL_PATH_SQ)' check-non-portable-shell.pl $(T) $(THELPERS) aggregate-results-and-cleanup: $(T) $(MAKE) aggregate-results @@ -71,6 +71,7 @@ You can pass --verbose (or -v), --debug (or -d), and --immediate (or -i) command line argument to the test, or by setting GIT_TEST_OPTS appropriately before running "make". +-v:: --verbose:: This makes the test more verbose. Specifically, the command being run and their output if any are also @@ -81,6 +82,7 @@ appropriately before running "make". numbers matching <pattern>. The number matched against is simply the running count of the test within the file. +-d:: --debug:: This may help the person who is developing a new test. It causes the command defined with test_debug to run. @@ -89,6 +91,7 @@ appropriately before running "make". failed tests so that you can inspect its contents after the test finished. +-i:: --immediate:: This causes the test to immediately exit upon the first failed test. Cleanup commands requested with @@ -96,10 +99,17 @@ appropriately before running "make". in order to keep the state for inspection by the tester to diagnose the bug. +-l:: --long-tests:: This causes additional long-running tests to be run (where available), for more exhaustive testing. +-r:: +--run=<test-selector>:: + Run only the subset of tests indicated by + <test-selector>. See section "Skipping Tests" below for + <test-selector> syntax. + --valgrind=<tool>:: Execute all Git binaries under valgrind tool <tool> and exit with status 126 on errors (just like regular tests, this will @@ -187,10 +197,77 @@ and either can match the "t[0-9]{4}" part to skip the whole test, or t[0-9]{4} followed by ".$number" to say which particular test to skip. -Note that some tests in the existing test suite rely on previous -test item, so you cannot arbitrarily disable one and expect the -remainder of test to check what the test originally was intended -to check. +For an individual test suite --run could be used to specify that +only some tests should be run or that some tests should be +excluded from a run. + +The argument for --run is a list of individual test numbers or +ranges with an optional negation prefix that define what tests in +a test suite to include in the run. A range is two numbers +separated with a dash and matches a range of tests with both ends +been included. You may omit the first or the second number to +mean "from the first test" or "up to the very last test" +respectively. + +Optional prefix of '!' means that the test or a range of tests +should be excluded from the run. + +If --run starts with an unprefixed number or range the initial +set of tests to run is empty. If the first item starts with '!' +all the tests are added to the initial set. After initial set is +determined every test number or range is added or excluded from +the set one by one, from left to right. + +Individual numbers or ranges could be separated either by a space +or a comma. + +For example, to run only tests up to a specific test (21), one +could do this: + + $ sh ./t9200-git-cvsexport-commit.sh --run='1-21' + +or this: + + $ sh ./t9200-git-cvsexport-commit.sh --run='-21' + +Common case is to run several setup tests (1, 2, 3) and then a +specific test (21) that relies on that setup: + + $ sh ./t9200-git-cvsexport-commit.sh --run='1 2 3 21' + +or: + + $ sh ./t9200-git-cvsexport-commit.sh --run=1,2,3,21 + +or: + + $ sh ./t9200-git-cvsexport-commit.sh --run='-3 21' + +As noted above, the test set is built going though items left to +right, so this: + + $ sh ./t9200-git-cvsexport-commit.sh --run='1-4 !3' + +will run tests 1, 2, and 4. Items that comes later have higher +precendence. It means that this: + + $ sh ./t9200-git-cvsexport-commit.sh --run='!3 1-4' + +would just run tests from 1 to 4, including 3. + +You may use negation with ranges. The following will run all +test in the test suite except from 7 up to 11: + + $ sh ./t9200-git-cvsexport-commit.sh --run='!7-11' + +Some tests in a test suite rely on the previous tests performing +certain actions, specifically some tests are designated as +"setup" test, so you cannot _arbitrarily_ disable one test and +expect the rest to function correctly. + +--run is mostly useful when you want to focus on a specific test +and know what setup is needed for it. Or when you want to run +everything up to a certain test. Naming Tests @@ -596,6 +673,27 @@ library for your script to use. ... ' + - test_write_lines <lines> + + Write <lines> on standard output, one line per argument. + Useful to prepare multi-line files in a compact form. + + Example: + + test_write_lines a b c d e f g >foo + + Is a more compact equivalent of: + cat >foo <<-EOF + a + b + c + d + e + f + g + EOF + + - test_pause This command is useful for writing and debugging tests and must be diff --git a/t/annotate-tests.sh b/t/annotate-tests.sh index 304c7b7d87..071e4d7d3e 100644 --- a/t/annotate-tests.sh +++ b/t/annotate-tests.sh @@ -1,6 +1,17 @@ # This file isn't used as a test script directly, instead it is # sourced from t8001-annotate.sh and t8002-blame.sh. +if test_have_prereq MINGW +then + sanitize_L () { + echo "$1" | sed 'sX\(^-L\|,\)\^\?/X&\\;*Xg' + } +else + sanitize_L () { + echo "$1" + } +fi + check_count () { head= && file='file' && @@ -10,6 +21,7 @@ check_count () { case "$1" in -h) head="$2"; shift; shift ;; -f) file="$2"; shift; shift ;; + -L*) options="$options $(sanitize_L "$1")"; shift ;; -*) options="$options $1"; shift ;; *) break ;; esac diff --git a/t/check-non-portable-shell.pl b/t/check-non-portable-shell.pl index 45971f43b7..b170cbc045 100755 --- a/t/check-non-portable-shell.pl +++ b/t/check-non-portable-shell.pl @@ -16,12 +16,12 @@ sub err { while (<>) { chomp; - /^\s*sed\s+-i/ and err 'sed -i is not portable'; - /^\s*echo\s+-n/ and err 'echo -n is not portable (please use printf)'; + /\bsed\s+-i/ and err 'sed -i is not portable'; + /\becho\s+-n/ and err 'echo -n is not portable (please use printf)'; /^\s*declare\s+/ and err 'arrays/declare not portable'; /^\s*[^#]\s*which\s/ and err 'which is not portable (please use type)'; - /test\s+[^=]*==/ and err '"test a == b" is not portable (please use =)'; - /^\s*export\s+[^=]*=/ and err '"export FOO=bar" is not portable (please use FOO=bar && export FOO)'; + /\btest\s+[^=]*==/ and err '"test a == b" is not portable (please use =)'; + /\bexport\s+[A-Za-z0-9_]*=/ and err '"export FOO=bar" is not portable (please use FOO=bar && export FOO)'; # this resets our $. for each file close ARGV if eof; } diff --git a/t/lib-credential.sh b/t/lib-credential.sh index 957ae936e8..9e7d7962b0 100755 --- a/t/lib-credential.sh +++ b/t/lib-credential.sh @@ -281,7 +281,7 @@ helper_test_timeout() { cat >askpass <<\EOF #!/bin/sh echo >&2 askpass: $* -what=`echo $1 | cut -d" " -f1 | tr A-Z a-z | tr -cd a-z` +what=$(echo $1 | cut -d" " -f1 | tr A-Z a-z | tr -cd a-z) echo "askpass-$what" EOF chmod +x askpass diff --git a/t/lib-cvs.sh b/t/lib-cvs.sh index 5076718916..9b2bcfb1b0 100644 --- a/t/lib-cvs.sh +++ b/t/lib-cvs.sh @@ -13,7 +13,7 @@ fi CVS="cvs -f" export CVS -cvsps_version=`cvsps -h 2>&1 | sed -ne 's/cvsps version //p'` +cvsps_version=$(cvsps -h 2>&1 | sed -ne 's/cvsps version //p') case "$cvsps_version" in 2.1 | 2.2*) ;; diff --git a/t/lib-gpg.sh b/t/lib-gpg.sh index 05824fa8e4..fd499e7c49 100755 --- a/t/lib-gpg.sh +++ b/t/lib-gpg.sh @@ -1,6 +1,6 @@ #!/bin/sh -gpg_version=`gpg --version 2>&1` +gpg_version=$(gpg --version 2>&1) if test $? = 127; then say "You do not seem to have gpg installed" else diff --git a/t/lib-httpd.sh b/t/lib-httpd.sh index 252cbf163b..fd53b57187 100644 --- a/t/lib-httpd.sh +++ b/t/lib-httpd.sh @@ -37,6 +37,11 @@ then test_done fi +if ! test_have_prereq SANITY; then + test_skip_or_die $GIT_TEST_HTTPD \ + "Cannot run httpd tests as root" +fi + HTTPD_PARA="" for DEFAULT_HTTPD_PATH in '/usr/sbin/httpd' '/usr/sbin/apache2' @@ -105,10 +110,15 @@ else "Could not identify web server at '$LIB_HTTPD_PATH'" fi +install_script () { + write_script "$HTTPD_ROOT_PATH/$1" <"$TEST_PATH/$1" +} + prepare_httpd() { mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH" cp "$TEST_PATH"/passwd "$HTTPD_ROOT_PATH" - cp "$TEST_PATH"/broken-smart-http.sh "$HTTPD_ROOT_PATH" + install_script broken-smart-http.sh + install_script error.sh ln -s "$LIB_HTTPD_MODULE_PATH" "$HTTPD_ROOT_PATH/modules" @@ -132,7 +142,7 @@ prepare_httpd() { HTTPD_URL_USER=$HTTPD_PROTO://user%40host@$HTTPD_DEST HTTPD_URL_USER_PASS=$HTTPD_PROTO://user%40host:pass%40host@$HTTPD_DEST - if test -n "$LIB_HTTPD_DAV" -o -n "$LIB_HTTPD_SVN" + if test -n "$LIB_HTTPD_DAV" || test -n "$LIB_HTTPD_SVN" then HTTPD_PARA="$HTTPD_PARA -DDAV" diff --git a/t/lib-httpd/apache.conf b/t/lib-httpd/apache.conf index 3a03e8263d..b384d79935 100644 --- a/t/lib-httpd/apache.conf +++ b/t/lib-httpd/apache.conf @@ -97,12 +97,16 @@ Alias /auth/dumb/ www/auth/dumb/ </LocationMatch> ScriptAliasMatch /smart_*[^/]*/(.*) ${GIT_EXEC_PATH}/git-http-backend/$1 ScriptAlias /broken_smart/ broken-smart-http.sh/ +ScriptAlias /error/ error.sh/ <Directory ${GIT_EXEC_PATH}> Options FollowSymlinks </Directory> <Files broken-smart-http.sh> Options ExecCGI </Files> +<Files error.sh> + Options ExecCGI +</Files> <Files ${GIT_EXEC_PATH}/git-http-backend> Options ExecCGI </Files> diff --git a/t/lib-httpd/broken-smart-http.sh b/t/lib-httpd/broken-smart-http.sh index f7ebfffa80..82cc610b0a 100755..100644 --- a/t/lib-httpd/broken-smart-http.sh +++ b/t/lib-httpd/broken-smart-http.sh @@ -1,4 +1,3 @@ -#!/bin/sh printf "Content-Type: text/%s\n" "html" echo printf "%s\n" "001e# service=git-upload-pack" diff --git a/t/lib-httpd/error.sh b/t/lib-httpd/error.sh new file mode 100755 index 0000000000..a77b8e5469 --- /dev/null +++ b/t/lib-httpd/error.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +printf "Status: 500 Intentional Breakage\n" + +printf "Content-Type: " +charset=iso-8859-1 +case "$PATH_INFO" in +*html*) + printf "text/html" + ;; +*text*) + printf "text/plain" + ;; +*charset*) + printf "text/plain; charset=utf-8" + charset=utf-8 + ;; +*utf16*) + printf "text/plain; charset=utf-16" + charset=utf-16 + ;; +*odd-spacing*) + printf "text/plain; foo=bar ;charset=utf-16; other=nonsense" + charset=utf-16 + ;; +esac +printf "\n" + +printf "\n" +printf "this is the error message\n" | +iconv -f us-ascii -t $charset diff --git a/t/lib-submodule-update.sh b/t/lib-submodule-update.sh new file mode 100755 index 0000000000..79cdd34a54 --- /dev/null +++ b/t/lib-submodule-update.sh @@ -0,0 +1,680 @@ +# Create a submodule layout used for all tests below. +# +# The following use cases are covered: +# - New submodule (no_submodule => add_sub1) +# - Removed submodule (add_sub1 => remove_sub1) +# - Updated submodule (add_sub1 => modify_sub1) +# - Submodule updated to invalid commit (add_sub1 => invalid_sub1) +# - Submodule updated from invalid commit (invalid_sub1 => valid_sub1) +# - Submodule replaced by tracked files in directory (add_sub1 => +# replace_sub1_with_directory) +# - Directory containing tracked files replaced by submodule +# (replace_sub1_with_directory => replace_directory_with_sub1) +# - Submodule replaced by tracked file with the same name (add_sub1 => +# replace_sub1_with_file) +# - Tracked file replaced by submodule (replace_sub1_with_file => +# replace_file_with_sub1) +# +# --O-----O +# / ^ replace_directory_with_sub1 +# / replace_sub1_with_directory +# /----O +# / ^ +# / modify_sub1 +# O------O-------O +# ^ ^\ ^ +# | | \ remove_sub1 +# | | -----O-----O +# | | \ ^ replace_file_with_sub1 +# | | \ replace_sub1_with_file +# | add_sub1 --O-----O +# no_submodule ^ valid_sub1 +# invalid_sub1 +# +create_lib_submodule_repo () { + git init submodule_update_repo && + ( + cd submodule_update_repo && + echo "expect" >>.gitignore && + echo "actual" >>.gitignore && + echo "x" >file1 && + echo "y" >file2 && + git add .gitignore file1 file2 && + git commit -m "Base" && + git branch "no_submodule" && + + git checkout -b "add_sub1" && + git submodule add ./. sub1 && + git config -f .gitmodules submodule.sub1.ignore all && + git config submodule.sub1.ignore all && + git add .gitmodules && + git commit -m "Add sub1" && + git checkout -b remove_sub1 && + git revert HEAD && + + git checkout -b "modify_sub1" "add_sub1" && + git submodule update && + ( + cd sub1 && + git fetch && + git checkout -b "modifications" && + echo "z" >file2 && + echo "x" >file3 && + git add file2 file3 && + git commit -m "modified file2 and added file3" && + git push origin modifications + ) && + git add sub1 && + git commit -m "Modify sub1" && + + git checkout -b "replace_sub1_with_directory" "add_sub1" && + git submodule update && + ( + cd sub1 && + git checkout modifications + ) && + git rm --cached sub1 && + rm sub1/.git* && + git config -f .gitmodules --remove-section "submodule.sub1" && + git add .gitmodules sub1/* && + git commit -m "Replace sub1 with directory" && + git checkout -b replace_directory_with_sub1 && + git revert HEAD && + + git checkout -b "replace_sub1_with_file" "add_sub1" && + git rm sub1 && + echo "content" >sub1 && + git add sub1 && + git commit -m "Replace sub1 with file" && + git checkout -b replace_file_with_sub1 && + git revert HEAD && + + git checkout -b "invalid_sub1" "add_sub1" && + git update-index --cacheinfo 160000 0123456789012345678901234567890123456789 sub1 && + git commit -m "Invalid sub1 commit" && + git checkout -b valid_sub1 && + git revert HEAD && + git checkout master + ) +} + +# Helper function to replace gitfile with .git directory +replace_gitfile_with_git_dir () { + ( + cd "$1" && + git_dir="$(git rev-parse --git-dir)" && + rm -f .git && + cp -R "$git_dir" .git && + GIT_WORK_TREE=. git config --unset core.worktree + ) +} + +# Test that the .git directory in the submodule is unchanged (except for the +# core.worktree setting, which appears only in $GIT_DIR/modules/$1/config). +# Call this function before test_submodule_content as the latter might +# write the index file leading to false positive index differences. +# +# Note that this only supports submodules at the root level of the +# superproject, with the default name, i.e. same as its path. +test_git_directory_is_unchanged () { + ( + cd ".git/modules/$1" && + # does core.worktree point at the right place? + test "$(git config core.worktree)" = "../../../$1" && + # remove it temporarily before comparing, as + # "$1/.git/config" lacks it... + git config --unset core.worktree + ) && + diff -r ".git/modules/$1" "$1/.git" && + ( + # ... and then restore. + cd ".git/modules/$1" && + git config core.worktree "../../../$1" + ) +} + +# Helper function to be executed at the start of every test below, it sets up +# the submodule repo if it doesn't exist and configures the most problematic +# settings for diff.ignoreSubmodules. +prolog () { + (test -d submodule_update_repo || create_lib_submodule_repo) && + test_config_global diff.ignoreSubmodules all && + test_config diff.ignoreSubmodules all +} + +# Helper function to bring work tree back into the state given by the +# commit. This includes trying to populate sub1 accordingly if it exists and +# should be updated to an existing commit. +reset_work_tree_to () { + rm -rf submodule_update && + git clone submodule_update_repo submodule_update && + ( + cd submodule_update && + rm -rf sub1 && + git checkout -f "$1" && + git status -u -s >actual && + test_must_be_empty actual && + sha1=$(git rev-parse --revs-only HEAD:sub1) && + if test -n "$sha1" && + test $(cd "sub1" && git rev-parse --verify "$sha1^{commit}") + then + git submodule update --init --recursive "sub1" + fi + ) +} + +# Test that the superproject contains the content according to commit "$1" +# (the work tree must match the index for everything but submodules but the +# index must exactly match the given commit including any submodule SHA-1s). +test_superproject_content () { + git diff-index --cached "$1" >actual && + test_must_be_empty actual && + git diff-files --ignore-submodules >actual && + test_must_be_empty actual +} + +# Test that the given submodule at path "$1" contains the content according +# to the submodule commit recorded in the superproject's commit "$2" +test_submodule_content () { + if test $# != 2 + then + echo "test_submodule_content needs two arguments" + return 1 + fi && + submodule="$1" && + commit="$2" && + test -d "$submodule"/ && + if ! test -f "$submodule"/.git && ! test -d "$submodule"/.git + then + echo "Submodule $submodule is not populated" + return 1 + fi && + sha1=$(git rev-parse --verify "$commit:$submodule") && + if test -z "$sha1" + then + echo "Couldn't retrieve SHA-1 of $submodule for $commit" + return 1 + fi && + ( + cd "$submodule" && + git status -u -s >actual && + test_must_be_empty actual && + git diff "$sha1" >actual && + test_must_be_empty actual + ) +} + +# Test that the following transitions are correctly handled: +# - Updated submodule +# - New submodule +# - Removed submodule +# - Directory containing tracked files replaced by submodule +# - Submodule replaced by tracked files in directory +# - Submodule replaced by tracked file with the same name +# - tracked file replaced by submodule +# +# The default is that submodule contents aren't changed until "git submodule +# update" is run. And even then that command doesn't delete the work tree of +# a removed submodule. +# +# Removing a submodule containing a .git directory must fail even when forced +# to protect the history! +# + +# Test that submodule contents are currently not updated when switching +# between commits that change a submodule. +test_submodule_switch () { + command="$1" + ######################### Appearing submodule ######################### + # Switching to a commit letting a submodule appear creates empty dir ... + if test "$KNOWN_FAILURE_STASH_DOES_IGNORE_SUBMODULE_CHANGES" = 1 + then + # Restoring stash fails to restore submodule index entry + RESULT="failure" + else + RESULT="success" + fi + test_expect_$RESULT "$command: added submodule creates empty directory" ' + prolog && + reset_work_tree_to no_submodule && + ( + cd submodule_update && + git branch -t add_sub1 origin/add_sub1 && + $command add_sub1 && + test_superproject_content origin/add_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... and doesn't care if it already exists ... + test_expect_$RESULT "$command: added submodule leaves existing empty directory alone" ' + prolog && + reset_work_tree_to no_submodule && + ( + cd submodule_update && + mkdir sub1 && + git branch -t add_sub1 origin/add_sub1 && + $command add_sub1 && + test_superproject_content origin/add_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... unless there is an untracked file in its place. + test_expect_success "$command: added submodule doesn't remove untracked unignored file with same name" ' + prolog && + reset_work_tree_to no_submodule && + ( + cd submodule_update && + git branch -t add_sub1 origin/add_sub1 && + >sub1 && + test_must_fail $command add_sub1 && + test_superproject_content origin/no_submodule && + test_must_be_empty sub1 + ) + ' + # Replacing a tracked file with a submodule produces an empty + # directory ... + test_expect_$RESULT "$command: replace tracked file with submodule creates empty directory" ' + prolog && + reset_work_tree_to replace_sub1_with_file && + ( + cd submodule_update && + git branch -t replace_file_with_sub1 origin/replace_file_with_sub1 && + $command replace_file_with_sub1 && + test_superproject_content origin/replace_file_with_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/replace_file_with_sub1 + ) + ' + # ... as does removing a directory with tracked files with a + # submodule. + if test "$KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR" = 1 + then + # Non fast-forward merges fail with "Directory sub1 doesn't + # exist. sub1" because the empty submodule directory is not + # created + RESULT="failure" + else + RESULT="success" + fi + test_expect_$RESULT "$command: replace directory with submodule" ' + prolog && + reset_work_tree_to replace_sub1_with_directory && + ( + cd submodule_update && + git branch -t replace_directory_with_sub1 origin/replace_directory_with_sub1 && + $command replace_directory_with_sub1 && + test_superproject_content origin/replace_directory_with_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/replace_directory_with_sub1 + ) + ' + + ######################## Disappearing submodule ####################### + # Removing a submodule doesn't remove its work tree ... + if test "$KNOWN_FAILURE_STASH_DOES_IGNORE_SUBMODULE_CHANGES" = 1 + then + RESULT="failure" + else + RESULT="success" + fi + test_expect_$RESULT "$command: removed submodule leaves submodule directory and its contents in place" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t remove_sub1 origin/remove_sub1 && + $command remove_sub1 && + test_superproject_content origin/remove_sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... especially when it contains a .git directory. + test_expect_$RESULT "$command: removed submodule leaves submodule containing a .git directory alone" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t remove_sub1 origin/remove_sub1 && + replace_gitfile_with_git_dir sub1 && + $command remove_sub1 && + test_superproject_content origin/remove_sub1 && + test_git_directory_is_unchanged sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # Replacing a submodule with files in a directory must fail as the + # submodule work tree isn't removed ... + if test "$KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES" = 1 + then + # Non fast-forward merges attempt to merge the former + # submodule files with the newly checked out ones in the + # directory of the same name while it shouldn't. + RESULT="failure" + else + RESULT="success" + fi + test_expect_$RESULT "$command: replace submodule with a directory must fail" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t replace_sub1_with_directory origin/replace_sub1_with_directory && + test_must_fail $command replace_sub1_with_directory && + test_superproject_content origin/add_sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... especially when it contains a .git directory. + test_expect_$RESULT "$command: replace submodule containing a .git directory with a directory must fail" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t replace_sub1_with_directory origin/replace_sub1_with_directory && + replace_gitfile_with_git_dir sub1 && + test_must_fail $command replace_sub1_with_directory && + test_superproject_content origin/add_sub1 && + test_git_directory_is_unchanged sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # Replacing it with a file must fail as it could throw away any local + # work tree changes ... + test_expect_failure "$command: replace submodule with a file must fail" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t replace_sub1_with_file origin/replace_sub1_with_file && + test_must_fail $command replace_sub1_with_file && + test_superproject_content origin/add_sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... or even destroy unpushed parts of submodule history if that + # still uses a .git directory. + test_expect_failure "$command: replace submodule containing a .git directory with a file must fail" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t replace_sub1_with_file origin/replace_sub1_with_file && + replace_gitfile_with_git_dir sub1 && + test_must_fail $command replace_sub1_with_file && + test_superproject_content origin/add_sub1 && + test_git_directory_is_unchanged sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + + ########################## Modified submodule ######################### + # Updating a submodule sha1 doesn't update the submodule's work tree + if test "$KNOWN_FAILURE_CHERRY_PICK_SEES_EMPTY_COMMIT" = 1 + then + # When cherry picking a SHA-1 update for an ignored submodule + # the commit incorrectly fails with "The previous cherry-pick + # is now empty, possibly due to conflict resolution." + RESULT="failure" + else + RESULT="success" + fi + test_expect_$RESULT "$command: modified submodule does not update submodule work tree" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t modify_sub1 origin/modify_sub1 && + $command modify_sub1 && + test_superproject_content origin/modify_sub1 && + test_submodule_content sub1 origin/add_sub1 && + git submodule update && + test_submodule_content sub1 origin/modify_sub1 + ) + ' + + # Updating a submodule to an invalid sha1 doesn't update the + # submodule's work tree, subsequent update will fail + test_expect_$RESULT "$command: modified submodule does not update submodule work tree to invalid commit" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t invalid_sub1 origin/invalid_sub1 && + $command invalid_sub1 && + test_superproject_content origin/invalid_sub1 && + test_submodule_content sub1 origin/add_sub1 && + test_must_fail git submodule update && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # Updating a submodule from an invalid sha1 doesn't update the + # submodule's work tree, subsequent update will succeed + test_expect_$RESULT "$command: modified submodule does not update submodule work tree from invalid commit" ' + prolog && + reset_work_tree_to invalid_sub1 && + ( + cd submodule_update && + git branch -t valid_sub1 origin/valid_sub1 && + $command valid_sub1 && + test_superproject_content origin/valid_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/valid_sub1 + ) + ' +} + +# Test that submodule contents are currently not updated when switching +# between commits that change a submodule, but throwing away local changes in +# the superproject is allowed. +test_submodule_forced_switch () { + command="$1" + ######################### Appearing submodule ######################### + # Switching to a commit letting a submodule appear creates empty dir ... + test_expect_success "$command: added submodule creates empty directory" ' + prolog && + reset_work_tree_to no_submodule && + ( + cd submodule_update && + git branch -t add_sub1 origin/add_sub1 && + $command add_sub1 && + test_superproject_content origin/add_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... and doesn't care if it already exists ... + test_expect_success "$command: added submodule leaves existing empty directory alone" ' + prolog && + reset_work_tree_to no_submodule && + ( + cd submodule_update && + git branch -t add_sub1 origin/add_sub1 && + mkdir sub1 && + $command add_sub1 && + test_superproject_content origin/add_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... unless there is an untracked file in its place. + test_expect_success "$command: added submodule does remove untracked unignored file with same name when forced" ' + prolog && + reset_work_tree_to no_submodule && + ( + cd submodule_update && + git branch -t add_sub1 origin/add_sub1 && + >sub1 && + $command add_sub1 && + test_superproject_content origin/add_sub1 && + test_dir_is_empty sub1 + ) + ' + # Replacing a tracked file with a submodule produces an empty + # directory ... + test_expect_success "$command: replace tracked file with submodule creates empty directory" ' + prolog && + reset_work_tree_to replace_sub1_with_file && + ( + cd submodule_update && + git branch -t replace_file_with_sub1 origin/replace_file_with_sub1 && + $command replace_file_with_sub1 && + test_superproject_content origin/replace_file_with_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/replace_file_with_sub1 + ) + ' + # ... as does removing a directory with tracked files with a + # submodule. + test_expect_success "$command: replace directory with submodule" ' + prolog && + reset_work_tree_to replace_sub1_with_directory && + ( + cd submodule_update && + git branch -t replace_directory_with_sub1 origin/replace_directory_with_sub1 && + $command replace_directory_with_sub1 && + test_superproject_content origin/replace_directory_with_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/replace_directory_with_sub1 + ) + ' + + ######################## Disappearing submodule ####################### + # Removing a submodule doesn't remove its work tree ... + test_expect_success "$command: removed submodule leaves submodule directory and its contents in place" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t remove_sub1 origin/remove_sub1 && + $command remove_sub1 && + test_superproject_content origin/remove_sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... especially when it contains a .git directory. + test_expect_success "$command: removed submodule leaves submodule containing a .git directory alone" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t remove_sub1 origin/remove_sub1 && + replace_gitfile_with_git_dir sub1 && + $command remove_sub1 && + test_superproject_content origin/remove_sub1 && + test_git_directory_is_unchanged sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # Replacing a submodule with files in a directory must fail as the + # submodule work tree isn't removed ... + test_expect_failure "$command: replace submodule with a directory must fail" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t replace_sub1_with_directory origin/replace_sub1_with_directory && + test_must_fail $command replace_sub1_with_directory && + test_superproject_content origin/add_sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... especially when it contains a .git directory. + test_expect_failure "$command: replace submodule containing a .git directory with a directory must fail" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t replace_sub1_with_directory origin/replace_sub1_with_directory && + replace_gitfile_with_git_dir sub1 && + test_must_fail $command replace_sub1_with_directory && + test_superproject_content origin/add_sub1 && + test_git_directory_is_unchanged sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # Replacing it with a file must fail as it could throw away any local + # work tree changes ... + test_expect_failure "$command: replace submodule with a file must fail" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t replace_sub1_with_file origin/replace_sub1_with_file && + test_must_fail $command replace_sub1_with_file && + test_superproject_content origin/add_sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... or even destroy unpushed parts of submodule history if that + # still uses a .git directory. + test_expect_failure "$command: replace submodule containing a .git directory with a file must fail" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t replace_sub1_with_file origin/replace_sub1_with_file && + replace_gitfile_with_git_dir sub1 && + test_must_fail $command replace_sub1_with_file && + test_superproject_content origin/add_sub1 && + test_git_directory_is_unchanged sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + + ########################## Modified submodule ######################### + # Updating a submodule sha1 doesn't update the submodule's work tree + test_expect_success "$command: modified submodule does not update submodule work tree" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t modify_sub1 origin/modify_sub1 && + $command modify_sub1 && + test_superproject_content origin/modify_sub1 && + test_submodule_content sub1 origin/add_sub1 && + git submodule update && + test_submodule_content sub1 origin/modify_sub1 + ) + ' + # Updating a submodule to an invalid sha1 doesn't update the + # submodule's work tree, subsequent update will fail + test_expect_success "$command: modified submodule does not update submodule work tree to invalid commit" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t invalid_sub1 origin/invalid_sub1 && + $command invalid_sub1 && + test_superproject_content origin/invalid_sub1 && + test_submodule_content sub1 origin/add_sub1 && + test_must_fail git submodule update && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # Updating a submodule from an invalid sha1 doesn't update the + # submodule's work tree, subsequent update will succeed + test_expect_success "$command: modified submodule does not update submodule work tree from invalid commit" ' + prolog && + reset_work_tree_to invalid_sub1 && + ( + cd submodule_update && + git branch -t valid_sub1 origin/valid_sub1 && + $command valid_sub1 && + test_superproject_content origin/valid_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/valid_sub1 + ) + ' +} diff --git a/t/perf/p5302-pack-index.sh b/t/perf/p5302-pack-index.sh index 6cb5b0d55b..5ee9211f98 100755 --- a/t/perf/p5302-pack-index.sh +++ b/t/perf/p5302-pack-index.sh @@ -8,7 +8,7 @@ test_perf_large_repo test_expect_success 'repack' ' git repack -ad && - PACK=`ls .git/objects/pack/*.pack | head -n1` && + PACK=$(ls .git/objects/pack/*.pack | head -n1) && test -f "$PACK" && export PACK ' diff --git a/t/perf/p5310-pack-bitmaps.sh b/t/perf/p5310-pack-bitmaps.sh index 685d46f8b7..f8ed8573b7 100755 --- a/t/perf/p5310-pack-bitmaps.sh +++ b/t/perf/p5310-pack-bitmaps.sh @@ -8,6 +8,9 @@ test_perf_large_repo # note that we do everything through config, # since we want to be able to compare bitmap-aware # git versus non-bitmap git +# +# We intentionally use the deprecated pack.writebitmaps +# config so that we can test against older versions of git. test_expect_success 'setup bitmap config' ' git config pack.writebitmaps true && git config pack.writebitmaphashcache true diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index a2bb63ce8e..f10ba4a01e 100755 --- a/t/t0000-basic.sh +++ b/t/t0000-basic.sh @@ -42,9 +42,9 @@ test_expect_success 'success is reported like this' ' : ' -run_sub_test_lib_test () { - name="$1" descr="$2" # stdin is the body of the test code - shift 2 +_run_sub_test_lib_test_common () { + neg="$1" name="$2" descr="$3" # stdin is the body of the test code + shift 3 mkdir "$name" && ( # Pretend we're not running under a test harness, whether we @@ -70,10 +70,23 @@ run_sub_test_lib_test () { export TEST_DIRECTORY && TEST_OUTPUT_DIRECTORY=$(pwd) && export TEST_OUTPUT_DIRECTORY && - ./"$name.sh" "$@" >out 2>err + if test -z "$neg" + then + ./"$name.sh" "$@" >out 2>err + else + ! ./"$name.sh" "$@" >out 2>err + fi ) } +run_sub_test_lib_test () { + _run_sub_test_lib_test_common '' "$@" +} + +run_sub_test_lib_test_err () { + _run_sub_test_lib_test_common '!' "$@" +} + check_sub_test_lib_test () { name="$1" # stdin is the expected output from the test ( @@ -84,6 +97,18 @@ check_sub_test_lib_test () { ) } +check_sub_test_lib_test_err () { + name="$1" # stdin is the expected output output from the test + # expected error output is in descriptior 3 + ( + cd "$name" && + sed -e 's/^> //' -e 's/Z$//' >expect.out && + test_cmp expect.out out && + sed -e 's/^> //' -e 's/Z$//' <&3 >expect.err && + test_cmp expect.err err + ) +} + test_expect_success 'pretend we have a fully passing test suite' " run_sub_test_lib_test full-pass '3 passing tests' <<-\\EOF && for i in 1 2 3 @@ -270,6 +295,398 @@ test_expect_success 'test --verbose-only' ' EOF ' +test_expect_success 'GIT_SKIP_TESTS' " + ( + GIT_SKIP_TESTS='git.2' && export GIT_SKIP_TESTS && + run_sub_test_lib_test git-skip-tests-basic \ + 'GIT_SKIP_TESTS' <<-\\EOF && + for i in 1 2 3 + do + test_expect_success \"passing test #\$i\" 'true' + done + test_done + EOF + check_sub_test_lib_test git-skip-tests-basic <<-\\EOF + > ok 1 - passing test #1 + > ok 2 # skip passing test #2 (GIT_SKIP_TESTS) + > ok 3 - passing test #3 + > # passed all 3 test(s) + > 1..3 + EOF + ) +" + +test_expect_success 'GIT_SKIP_TESTS several tests' " + ( + GIT_SKIP_TESTS='git.2 git.5' && export GIT_SKIP_TESTS && + run_sub_test_lib_test git-skip-tests-several \ + 'GIT_SKIP_TESTS several tests' <<-\\EOF && + for i in 1 2 3 4 5 6 + do + test_expect_success \"passing test #\$i\" 'true' + done + test_done + EOF + check_sub_test_lib_test git-skip-tests-several <<-\\EOF + > ok 1 - passing test #1 + > ok 2 # skip passing test #2 (GIT_SKIP_TESTS) + > ok 3 - passing test #3 + > ok 4 - passing test #4 + > ok 5 # skip passing test #5 (GIT_SKIP_TESTS) + > ok 6 - passing test #6 + > # passed all 6 test(s) + > 1..6 + EOF + ) +" + +test_expect_success 'GIT_SKIP_TESTS sh pattern' " + ( + GIT_SKIP_TESTS='git.[2-5]' && export GIT_SKIP_TESTS && + run_sub_test_lib_test git-skip-tests-sh-pattern \ + 'GIT_SKIP_TESTS sh pattern' <<-\\EOF && + for i in 1 2 3 4 5 6 + do + test_expect_success \"passing test #\$i\" 'true' + done + test_done + EOF + check_sub_test_lib_test git-skip-tests-sh-pattern <<-\\EOF + > ok 1 - passing test #1 + > ok 2 # skip passing test #2 (GIT_SKIP_TESTS) + > ok 3 # skip passing test #3 (GIT_SKIP_TESTS) + > ok 4 # skip passing test #4 (GIT_SKIP_TESTS) + > ok 5 # skip passing test #5 (GIT_SKIP_TESTS) + > ok 6 - passing test #6 + > # passed all 6 test(s) + > 1..6 + EOF + ) +" + +test_expect_success '--run basic' " + run_sub_test_lib_test run-basic \ + '--run basic' --run='1 3 5' <<-\\EOF && + for i in 1 2 3 4 5 6 + do + test_expect_success \"passing test #\$i\" 'true' + done + test_done + EOF + check_sub_test_lib_test run-basic <<-\\EOF + > ok 1 - passing test #1 + > ok 2 # skip passing test #2 (--run) + > ok 3 - passing test #3 + > ok 4 # skip passing test #4 (--run) + > ok 5 - passing test #5 + > ok 6 # skip passing test #6 (--run) + > # passed all 6 test(s) + > 1..6 + EOF +" + +test_expect_success '--run with a range' " + run_sub_test_lib_test run-range \ + '--run with a range' --run='1-3' <<-\\EOF && + for i in 1 2 3 4 5 6 + do + test_expect_success \"passing test #\$i\" 'true' + done + test_done + EOF + check_sub_test_lib_test run-range <<-\\EOF + > ok 1 - passing test #1 + > ok 2 - passing test #2 + > ok 3 - passing test #3 + > ok 4 # skip passing test #4 (--run) + > ok 5 # skip passing test #5 (--run) + > ok 6 # skip passing test #6 (--run) + > # passed all 6 test(s) + > 1..6 + EOF +" + +test_expect_success '--run with two ranges' " + run_sub_test_lib_test run-two-ranges \ + '--run with two ranges' --run='1-2 5-6' <<-\\EOF && + for i in 1 2 3 4 5 6 + do + test_expect_success \"passing test #\$i\" 'true' + done + test_done + EOF + check_sub_test_lib_test run-two-ranges <<-\\EOF + > ok 1 - passing test #1 + > ok 2 - passing test #2 + > ok 3 # skip passing test #3 (--run) + > ok 4 # skip passing test #4 (--run) + > ok 5 - passing test #5 + > ok 6 - passing test #6 + > # passed all 6 test(s) + > 1..6 + EOF +" + +test_expect_success '--run with a left open range' " + run_sub_test_lib_test run-left-open-range \ + '--run with a left open range' --run='-3' <<-\\EOF && + for i in 1 2 3 4 5 6 + do + test_expect_success \"passing test #\$i\" 'true' + done + test_done + EOF + check_sub_test_lib_test run-left-open-range <<-\\EOF + > ok 1 - passing test #1 + > ok 2 - passing test #2 + > ok 3 - passing test #3 + > ok 4 # skip passing test #4 (--run) + > ok 5 # skip passing test #5 (--run) + > ok 6 # skip passing test #6 (--run) + > # passed all 6 test(s) + > 1..6 + EOF +" + +test_expect_success '--run with a right open range' " + run_sub_test_lib_test run-right-open-range \ + '--run with a right open range' --run='4-' <<-\\EOF && + for i in 1 2 3 4 5 6 + do + test_expect_success \"passing test #\$i\" 'true' + done + test_done + EOF + check_sub_test_lib_test run-right-open-range <<-\\EOF + > ok 1 # skip passing test #1 (--run) + > ok 2 # skip passing test #2 (--run) + > ok 3 # skip passing test #3 (--run) + > ok 4 - passing test #4 + > ok 5 - passing test #5 + > ok 6 - passing test #6 + > # passed all 6 test(s) + > 1..6 + EOF +" + +test_expect_success '--run with basic negation' " + run_sub_test_lib_test run-basic-neg \ + '--run with basic negation' --run='"'!3'"' <<-\\EOF && + for i in 1 2 3 4 5 6 + do + test_expect_success \"passing test #\$i\" 'true' + done + test_done + EOF + check_sub_test_lib_test run-basic-neg <<-\\EOF + > ok 1 - passing test #1 + > ok 2 - passing test #2 + > ok 3 # skip passing test #3 (--run) + > ok 4 - passing test #4 + > ok 5 - passing test #5 + > ok 6 - passing test #6 + > # passed all 6 test(s) + > 1..6 + EOF +" + +test_expect_success '--run with two negations' " + run_sub_test_lib_test run-two-neg \ + '--run with two negations' --run='"'!3 !6'"' <<-\\EOF && + for i in 1 2 3 4 5 6 + do + test_expect_success \"passing test #\$i\" 'true' + done + test_done + EOF + check_sub_test_lib_test run-two-neg <<-\\EOF + > ok 1 - passing test #1 + > ok 2 - passing test #2 + > ok 3 # skip passing test #3 (--run) + > ok 4 - passing test #4 + > ok 5 - passing test #5 + > ok 6 # skip passing test #6 (--run) + > # passed all 6 test(s) + > 1..6 + EOF +" + +test_expect_success '--run a range and negation' " + run_sub_test_lib_test run-range-and-neg \ + '--run a range and negation' --run='"'-4 !2'"' <<-\\EOF && + for i in 1 2 3 4 5 6 + do + test_expect_success \"passing test #\$i\" 'true' + done + test_done + EOF + check_sub_test_lib_test run-range-and-neg <<-\\EOF + > ok 1 - passing test #1 + > ok 2 # skip passing test #2 (--run) + > ok 3 - passing test #3 + > ok 4 - passing test #4 + > ok 5 # skip passing test #5 (--run) + > ok 6 # skip passing test #6 (--run) + > # passed all 6 test(s) + > 1..6 + EOF +" + +test_expect_success '--run range negation' " + run_sub_test_lib_test run-range-neg \ + '--run range negation' --run='"'!1-3'"' <<-\\EOF && + for i in 1 2 3 4 5 6 + do + test_expect_success \"passing test #\$i\" 'true' + done + test_done + EOF + check_sub_test_lib_test run-range-neg <<-\\EOF + > ok 1 # skip passing test #1 (--run) + > ok 2 # skip passing test #2 (--run) + > ok 3 # skip passing test #3 (--run) + > ok 4 - passing test #4 + > ok 5 - passing test #5 + > ok 6 - passing test #6 + > # passed all 6 test(s) + > 1..6 + EOF +" + +test_expect_success '--run include, exclude and include' " + run_sub_test_lib_test run-inc-neg-inc \ + '--run include, exclude and include' \ + --run='"'1-5 !1-3 2'"' <<-\\EOF && + for i in 1 2 3 4 5 6 + do + test_expect_success \"passing test #\$i\" 'true' + done + test_done + EOF + check_sub_test_lib_test run-inc-neg-inc <<-\\EOF + > ok 1 # skip passing test #1 (--run) + > ok 2 - passing test #2 + > ok 3 # skip passing test #3 (--run) + > ok 4 - passing test #4 + > ok 5 - passing test #5 + > ok 6 # skip passing test #6 (--run) + > # passed all 6 test(s) + > 1..6 + EOF +" + +test_expect_success '--run include, exclude and include, comma separated' " + run_sub_test_lib_test run-inc-neg-inc-comma \ + '--run include, exclude and include, comma separated' \ + --run=1-5,\!1-3,2 <<-\\EOF && + for i in 1 2 3 4 5 6 + do + test_expect_success \"passing test #\$i\" 'true' + done + test_done + EOF + check_sub_test_lib_test run-inc-neg-inc-comma <<-\\EOF + > ok 1 # skip passing test #1 (--run) + > ok 2 - passing test #2 + > ok 3 # skip passing test #3 (--run) + > ok 4 - passing test #4 + > ok 5 - passing test #5 + > ok 6 # skip passing test #6 (--run) + > # passed all 6 test(s) + > 1..6 + EOF +" + +test_expect_success '--run exclude and include' " + run_sub_test_lib_test run-neg-inc \ + '--run exclude and include' \ + --run='"'!3- 5'"' <<-\\EOF && + for i in 1 2 3 4 5 6 + do + test_expect_success \"passing test #\$i\" 'true' + done + test_done + EOF + check_sub_test_lib_test run-neg-inc <<-\\EOF + > ok 1 - passing test #1 + > ok 2 - passing test #2 + > ok 3 # skip passing test #3 (--run) + > ok 4 # skip passing test #4 (--run) + > ok 5 - passing test #5 + > ok 6 # skip passing test #6 (--run) + > # passed all 6 test(s) + > 1..6 + EOF +" + +test_expect_success '--run empty selectors' " + run_sub_test_lib_test run-empty-sel \ + '--run empty selectors' \ + --run='1,,3,,,5' <<-\\EOF && + for i in 1 2 3 4 5 6 + do + test_expect_success \"passing test #\$i\" 'true' + done + test_done + EOF + check_sub_test_lib_test run-empty-sel <<-\\EOF + > ok 1 - passing test #1 + > ok 2 # skip passing test #2 (--run) + > ok 3 - passing test #3 + > ok 4 # skip passing test #4 (--run) + > ok 5 - passing test #5 + > ok 6 # skip passing test #6 (--run) + > # passed all 6 test(s) + > 1..6 + EOF +" + +test_expect_success '--run invalid range start' " + run_sub_test_lib_test_err run-inv-range-start \ + '--run invalid range start' \ + --run='a-5' <<-\\EOF && + test_expect_success \"passing test #1\" 'true' + test_done + EOF + check_sub_test_lib_test_err run-inv-range-start \ + <<-\\EOF_OUT 3<<-\\EOF_ERR + > FATAL: Unexpected exit with code 1 + EOF_OUT + > error: --run: invalid non-numeric in range start: 'a-5' + EOF_ERR +" + +test_expect_success '--run invalid range end' " + run_sub_test_lib_test_err run-inv-range-end \ + '--run invalid range end' \ + --run='1-z' <<-\\EOF && + test_expect_success \"passing test #1\" 'true' + test_done + EOF + check_sub_test_lib_test_err run-inv-range-end \ + <<-\\EOF_OUT 3<<-\\EOF_ERR + > FATAL: Unexpected exit with code 1 + EOF_OUT + > error: --run: invalid non-numeric in range end: '1-z' + EOF_ERR +" + +test_expect_success '--run invalid selector' " + run_sub_test_lib_test_err run-inv-selector \ + '--run invalid selector' \ + --run='1?' <<-\\EOF && + test_expect_success \"passing test #1\" 'true' + test_done + EOF + check_sub_test_lib_test_err run-inv-selector \ + <<-\\EOF_OUT 3<<-\\EOF_ERR + > FATAL: Unexpected exit with code 1 + EOF_OUT + > error: --run: invalid non-numeric in test selector: '1?' + EOF_ERR +" + + test_set_prereq HAVEIT haveit=no test_expect_success HAVEIT 'test runs if prerequisite is satisfied' ' diff --git a/t/t0001-init.sh b/t/t0001-init.sh index bbc9cb60dd..e62c0ffbc2 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -56,7 +56,7 @@ test_expect_success 'plain through aliased command, outside any git repo' ' check_config plain-aliased/.git false unset ' -test_expect_failure 'plain nested through aliased command' ' +test_expect_success 'plain nested through aliased command' ' ( git init plain-ancestor-aliased && cd plain-ancestor-aliased && @@ -68,7 +68,7 @@ test_expect_failure 'plain nested through aliased command' ' check_config plain-ancestor-aliased/plain-nested/.git false unset ' -test_expect_failure 'plain nested in bare through aliased command' ' +test_expect_success 'plain nested in bare through aliased command' ' ( git init --bare bare-ancestor-aliased.git && cd bare-ancestor-aliased.git && @@ -185,14 +185,14 @@ test_expect_success 'init --bare/--shared overrides system/global config' ' git init --bare --shared=0666 init-bare-shared-override && check_config init-bare-shared-override true unset && test x0666 = \ - x`git config -f init-bare-shared-override/config core.sharedRepository` + x$(git config -f init-bare-shared-override/config core.sharedRepository) ' test_expect_success 'init honors global core.sharedRepository' ' test_config_global core.sharedRepository 0666 && git init shared-honor-global && test x0666 = \ - x`git config -f shared-honor-global/.git/config core.sharedRepository` + x$(git config -f shared-honor-global/.git/config core.sharedRepository) ' test_expect_success 'init rejects insanely long --template' ' @@ -285,7 +285,7 @@ test_expect_success 'init prefers command line to GIT_DIR' ' test_expect_success 'init with separate gitdir' ' rm -rf newdir && git init --separate-git-dir realgitdir newdir && - echo "gitdir: `pwd`/realgitdir" >expected && + echo "gitdir: $(pwd)/realgitdir" >expected && test_cmp expected newdir/.git && test_path_is_dir realgitdir/refs ' @@ -299,7 +299,7 @@ test_expect_success 're-init to update git link' ' cd newdir && git init --separate-git-dir ../surrealgitdir ) && - echo "gitdir: `pwd`/surrealgitdir" >expected && + echo "gitdir: $(pwd)/surrealgitdir" >expected && test_cmp expected newdir/.git && test_path_is_dir surrealgitdir/refs && test_path_is_missing realgitdir/refs @@ -312,7 +312,7 @@ test_expect_success 're-init to move gitdir' ' cd newdir && git init --separate-git-dir ../realgitdir ) && - echo "gitdir: `pwd`/realgitdir" >expected && + echo "gitdir: $(pwd)/realgitdir" >expected && test_cmp expected newdir/.git && test_path_is_dir realgitdir/refs ' @@ -326,7 +326,7 @@ test_expect_success SYMLINKS 're-init to move gitdir symlink' ' ln -s here .git && git init --separate-git-dir ../realgitdir ) && - echo "gitdir: `pwd`/realgitdir" >expected && + echo "gitdir: $(pwd)/realgitdir" >expected && test_cmp expected newdir/.git && test_cmp expected newdir/here && test_path_is_dir realgitdir/refs diff --git a/t/t0008-ignores.sh b/t/t0008-ignores.sh index 63beb99828..39e55a13c8 100755 --- a/t/t0008-ignores.sh +++ b/t/t0008-ignores.sh @@ -806,4 +806,29 @@ test_expect_success !MINGW 'quoting allows trailing whitespace' ' test_cmp err.expect err ' +test_expect_success NOT_MINGW,NOT_CYGWIN 'correct handling of backslashes' ' + rm -rf whitespace && + mkdir whitespace && + >"whitespace/trailing 1 " && + >"whitespace/trailing 2 \\\\" && + >"whitespace/trailing 3 \\\\" && + >"whitespace/trailing 4 \\ " && + >"whitespace/trailing 5 \\ \\ " && + >"whitespace/trailing 6 \\a\\" && + >whitespace/untracked && + sed -e "s/Z$//" >ignore <<-\EOF && + whitespace/trailing 1 \ Z + whitespace/trailing 2 \\\\Z + whitespace/trailing 3 \\\\ Z + whitespace/trailing 4 \\\ Z + whitespace/trailing 5 \\ \\\ Z + whitespace/trailing 6 \\a\\Z + EOF + echo whitespace/untracked >expect && + >err.expect && + git ls-files -o -X ignore whitespace >actual 2>err && + test_cmp expect actual && + test_cmp err.expect err +' + test_done diff --git a/t/t0010-racy-git.sh b/t/t0010-racy-git.sh index e45a9e40e4..5657c5a87b 100755 --- a/t/t0010-racy-git.sh +++ b/t/t0010-racy-git.sh @@ -14,7 +14,7 @@ do git update-index --add infocom echo xyzzy >infocom - files=`git diff-files -p` + files=$(git diff-files -p) test_expect_success \ "Racy GIT trial #$trial part A" \ 'test "" != "$files"' @@ -23,7 +23,7 @@ do echo xyzzy >cornerstone git update-index --add cornerstone - files=`git diff-files -p` + files=$(git diff-files -p) test_expect_success \ "Racy GIT trial #$trial part B" \ 'test "" != "$files"' diff --git a/t/t0011-hashmap.sh b/t/t0011-hashmap.sh index 391e2b6492..f97c80556f 100755 --- a/t/t0011-hashmap.sh +++ b/t/t0011-hashmap.sh @@ -237,4 +237,17 @@ test_expect_success 'grow / shrink' ' ' +test_expect_success 'string interning' ' + +test_hashmap "intern value1 +intern Value1 +intern value2 +intern value2 +" "value1 +Value1 +value2 +value2" + +' + test_done diff --git a/t/t0020-crlf.sh b/t/t0020-crlf.sh index e526184a0b..d2e51a81bc 100755 --- a/t/t0020-crlf.sh +++ b/t/t0020-crlf.sh @@ -20,14 +20,14 @@ test_expect_success setup ' git commit -m initial && - one=`git rev-parse HEAD:one` && - dir=`git rev-parse HEAD:dir` && - two=`git rev-parse HEAD:dir/two` && - three=`git rev-parse HEAD:three` && + one=$(git rev-parse HEAD:one) && + dir=$(git rev-parse HEAD:dir) && + two=$(git rev-parse HEAD:dir/two) && + three=$(git rev-parse HEAD:three) && for w in Some extra lines here; do echo $w; done >>one && git diff >patch.file && - patched=`git hash-object --stdin <one` && + patched=$(git hash-object --stdin <one) && git read-tree --reset -u HEAD && echo happy. @@ -111,7 +111,7 @@ test_expect_success 'update with autocrlf=input' ' } done && - differs=`git diff-index --cached HEAD` && + differs=$(git diff-index --cached HEAD) && test -z "$differs" || { echo Oops "$differs" false @@ -135,7 +135,7 @@ test_expect_success 'update with autocrlf=true' ' } done && - differs=`git diff-index --cached HEAD` && + differs=$(git diff-index --cached HEAD) && test -z "$differs" || { echo Oops "$differs" false @@ -158,9 +158,9 @@ test_expect_success 'checkout with autocrlf=true' ' break } done && - test "$one" = `git hash-object --stdin <one` && - test "$two" = `git hash-object --stdin <dir/two` && - differs=`git diff-index --cached HEAD` && + test "$one" = $(git hash-object --stdin <one) && + test "$two" = $(git hash-object --stdin <dir/two) && + differs=$(git diff-index --cached HEAD) && test -z "$differs" || { echo Oops "$differs" false @@ -184,9 +184,9 @@ test_expect_success 'checkout with autocrlf=input' ' git update-index -- $f fi done && - test "$one" = `git hash-object --stdin <one` && - test "$two" = `git hash-object --stdin <dir/two` && - differs=`git diff-index --cached HEAD` && + test "$one" = $(git hash-object --stdin <one) && + test "$two" = $(git hash-object --stdin <dir/two) && + differs=$(git diff-index --cached HEAD) && test -z "$differs" || { echo Oops "$differs" false @@ -200,7 +200,7 @@ test_expect_success 'apply patch (autocrlf=input)' ' git read-tree --reset -u HEAD && git apply patch.file && - test "$patched" = "`git hash-object --stdin <one`" || { + test "$patched" = "$(git hash-object --stdin <one)" || { echo "Eh? apply without index" false } @@ -213,7 +213,7 @@ test_expect_success 'apply patch --cached (autocrlf=input)' ' git read-tree --reset -u HEAD && git apply --cached patch.file && - test "$patched" = `git rev-parse :one` || { + test "$patched" = $(git rev-parse :one) || { echo "Eh? apply with --cached" false } @@ -226,8 +226,8 @@ test_expect_success 'apply patch --index (autocrlf=input)' ' git read-tree --reset -u HEAD && git apply --index patch.file && - test "$patched" = `git rev-parse :one` && - test "$patched" = `git hash-object --stdin <one` || { + test "$patched" = $(git rev-parse :one) && + test "$patched" = $(git hash-object --stdin <one) || { echo "Eh? apply with --index" false } @@ -240,7 +240,7 @@ test_expect_success 'apply patch (autocrlf=true)' ' git read-tree --reset -u HEAD && git apply patch.file && - test "$patched" = "`remove_cr <one | git hash-object --stdin`" || { + test "$patched" = "$(remove_cr <one | git hash-object --stdin)" || { echo "Eh? apply without index" false } @@ -253,7 +253,7 @@ test_expect_success 'apply patch --cached (autocrlf=true)' ' git read-tree --reset -u HEAD && git apply --cached patch.file && - test "$patched" = `git rev-parse :one` || { + test "$patched" = $(git rev-parse :one) || { echo "Eh? apply without index" false } @@ -266,8 +266,8 @@ test_expect_success 'apply patch --index (autocrlf=true)' ' git read-tree --reset -u HEAD && git apply --index patch.file && - test "$patched" = `git rev-parse :one` && - test "$patched" = "`remove_cr <one | git hash-object --stdin`" || { + test "$patched" = $(git rev-parse :one) && + test "$patched" = "$(remove_cr <one | git hash-object --stdin)" || { echo "Eh? apply with --index" false } diff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh index b92e6cb046..f890c54d13 100755 --- a/t/t0021-conversion.sh +++ b/t/t0021-conversion.sh @@ -190,8 +190,6 @@ test_expect_success 'required filter clean failure' ' test_must_fail git add test.fc ' -test -n "$GIT_TEST_LONG" && test_set_prereq EXPENSIVE - test_expect_success EXPENSIVE 'filter large file' ' git config filter.largefile.smudge cat && git config filter.largefile.clean cat && diff --git a/t/t0025-crlf-auto.sh b/t/t0025-crlf-auto.sh index f5f67a6337..c164b4662a 100755 --- a/t/t0025-crlf-auto.sh +++ b/t/t0025-crlf-auto.sh @@ -12,144 +12,144 @@ test_expect_success setup ' git config core.autocrlf false && - 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}Q; done | q_to_cr >two && - for w in Oh here is a QNUL byte how alarming; do echo ${w}; done | q_to_nul >three && + for w in Hello world how are you; do echo $w; done >LFonly && + for w in I am very very fine thank you; do echo ${w}Q; done | q_to_cr >CRLFonly && + for w in Oh here is a QNUL byte how alarming; do echo ${w}; done | q_to_nul >LFwithNUL && git add . && git commit -m initial && - one=`git rev-parse HEAD:one` && - two=`git rev-parse HEAD:two` && - three=`git rev-parse HEAD:three` && + LFonly=$(git rev-parse HEAD:LFonly) && + CRLFonly=$(git rev-parse HEAD:CRLFonly) && + LFwithNUL=$(git rev-parse HEAD:LFwithNUL) && echo happy. ' test_expect_success 'default settings cause no changes' ' - rm -f .gitattributes tmp one two three && + rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL && git read-tree --reset -u HEAD && - ! has_cr one && - has_cr two && - onediff=`git diff one` && - twodiff=`git diff two` && - threediff=`git diff three` && - test -z "$onediff" -a -z "$twodiff" -a -z "$threediff" + ! has_cr LFonly && + has_cr CRLFonly && + LFonlydiff=$(git diff LFonly) && + CRLFonlydiff=$(git diff CRLFonly) && + LFwithNULdiff=$(git diff LFwithNUL) && + test -z "$LFonlydiff" -a -z "$CRLFonlydiff" -a -z "$LFwithNULdiff" ' test_expect_success 'crlf=true causes a CRLF file to be normalized' ' # Backwards compatibility check - rm -f .gitattributes tmp one two three && - echo "two crlf" > .gitattributes && + rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL && + echo "CRLFonly crlf" > .gitattributes && git read-tree --reset -u HEAD && # Note, "normalized" means that git will normalize it if added - has_cr two && - twodiff=`git diff two` && - test -n "$twodiff" + has_cr CRLFonly && + CRLFonlydiff=$(git diff CRLFonly) && + test -n "$CRLFonlydiff" ' test_expect_success 'text=true causes a CRLF file to be normalized' ' - rm -f .gitattributes tmp one two three && - echo "two text" > .gitattributes && + rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL && + echo "CRLFonly text" > .gitattributes && git read-tree --reset -u HEAD && # Note, "normalized" means that git will normalize it if added - has_cr two && - twodiff=`git diff two` && - test -n "$twodiff" + has_cr CRLFonly && + CRLFonlydiff=$(git diff CRLFonly) && + test -n "$CRLFonlydiff" ' test_expect_success 'eol=crlf gives a normalized file CRLFs with autocrlf=false' ' - rm -f .gitattributes tmp one two three && + rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL && git config core.autocrlf false && - echo "one eol=crlf" > .gitattributes && + echo "LFonly eol=crlf" > .gitattributes && git read-tree --reset -u HEAD && - has_cr one && - onediff=`git diff one` && - test -z "$onediff" + has_cr LFonly && + LFonlydiff=$(git diff LFonly) && + test -z "$LFonlydiff" ' test_expect_success 'eol=crlf gives a normalized file CRLFs with autocrlf=input' ' - rm -f .gitattributes tmp one two three && + rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL && git config core.autocrlf input && - echo "one eol=crlf" > .gitattributes && + echo "LFonly eol=crlf" > .gitattributes && git read-tree --reset -u HEAD && - has_cr one && - onediff=`git diff one` && - test -z "$onediff" + has_cr LFonly && + LFonlydiff=$(git diff LFonly) && + test -z "$LFonlydiff" ' test_expect_success 'eol=lf gives a normalized file LFs with autocrlf=true' ' - rm -f .gitattributes tmp one two three && + rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL && git config core.autocrlf true && - echo "one eol=lf" > .gitattributes && + echo "LFonly eol=lf" > .gitattributes && git read-tree --reset -u HEAD && - ! has_cr one && - onediff=`git diff one` && - test -z "$onediff" + ! has_cr LFonly && + LFonlydiff=$(git diff LFonly) && + test -z "$LFonlydiff" ' test_expect_success 'autocrlf=true does not normalize CRLF files' ' - rm -f .gitattributes tmp one two three && + rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL && git config core.autocrlf true && git read-tree --reset -u HEAD && - has_cr one && - has_cr two && - onediff=`git diff one` && - twodiff=`git diff two` && - threediff=`git diff three` && - test -z "$onediff" -a -z "$twodiff" -a -z "$threediff" + has_cr LFonly && + has_cr CRLFonly && + LFonlydiff=$(git diff LFonly) && + CRLFonlydiff=$(git diff CRLFonly) && + LFwithNULdiff=$(git diff LFwithNUL) && + test -z "$LFonlydiff" -a -z "$CRLFonlydiff" -a -z "$LFwithNULdiff" ' test_expect_success 'text=auto, autocrlf=true _does_ normalize CRLF files' ' - rm -f .gitattributes tmp one two three && + rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL && git config core.autocrlf true && echo "* text=auto" > .gitattributes && git read-tree --reset -u HEAD && - has_cr one && - has_cr two && - onediff=`git diff one` && - twodiff=`git diff two` && - threediff=`git diff three` && - test -z "$onediff" -a -n "$twodiff" -a -z "$threediff" + has_cr LFonly && + has_cr CRLFonly && + LFonlydiff=$(git diff LFonly) && + CRLFonlydiff=$(git diff CRLFonly) && + LFwithNULdiff=$(git diff LFwithNUL) && + test -z "$LFonlydiff" -a -n "$CRLFonlydiff" -a -z "$LFwithNULdiff" ' test_expect_success 'text=auto, autocrlf=true does not normalize binary files' ' - rm -f .gitattributes tmp one two three && + rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL && git config core.autocrlf true && echo "* text=auto" > .gitattributes && git read-tree --reset -u HEAD && - ! has_cr three && - threediff=`git diff three` && - test -z "$threediff" + ! has_cr LFwithNUL && + LFwithNULdiff=$(git diff LFwithNUL) && + test -z "$LFwithNULdiff" ' test_expect_success 'eol=crlf _does_ normalize binary files' ' - rm -f .gitattributes tmp one two three && - echo "three eol=crlf" > .gitattributes && + rm -f .gitattributes tmp LFonly CRLFonly LFwithNUL && + echo "LFwithNUL eol=crlf" > .gitattributes && git read-tree --reset -u HEAD && - has_cr three && - threediff=`git diff three` && - test -z "$threediff" + has_cr LFwithNUL && + LFwithNULdiff=$(git diff LFwithNUL) && + test -z "$LFwithNULdiff" ' test_done diff --git a/t/t0026-eol-config.sh b/t/t0026-eol-config.sh index fe0164be62..4807b0f015 100755 --- a/t/t0026-eol-config.sh +++ b/t/t0026-eol-config.sh @@ -20,8 +20,8 @@ test_expect_success setup ' git commit -m initial && - one=`git rev-parse HEAD:one` && - two=`git rev-parse HEAD:two` && + one=$(git rev-parse HEAD:one) && + two=$(git rev-parse HEAD:two) && echo happy. ' @@ -34,9 +34,9 @@ test_expect_success 'eol=lf puts LFs in normalized file' ' ! has_cr one && ! has_cr two && - onediff=`git diff one` && - twodiff=`git diff two` && - test -z "$onediff" -a -z "$twodiff" + onediff=$(git diff one) && + twodiff=$(git diff two) && + test -z "$onediff" && test -z "$twodiff" ' test_expect_success 'eol=crlf puts CRLFs in normalized file' ' @@ -47,9 +47,9 @@ test_expect_success 'eol=crlf puts CRLFs in normalized file' ' has_cr one && ! has_cr two && - onediff=`git diff one` && - twodiff=`git diff two` && - test -z "$onediff" -a -z "$twodiff" + onediff=$(git diff one) && + twodiff=$(git diff two) && + test -z "$onediff" && test -z "$twodiff" ' test_expect_success 'autocrlf=true overrides eol=lf' ' @@ -61,9 +61,9 @@ test_expect_success 'autocrlf=true overrides eol=lf' ' has_cr one && has_cr two && - onediff=`git diff one` && - twodiff=`git diff two` && - test -z "$onediff" -a -z "$twodiff" + onediff=$(git diff one) && + twodiff=$(git diff two) && + test -z "$onediff" && test -z "$twodiff" ' test_expect_success 'autocrlf=true overrides unset eol' ' @@ -75,9 +75,9 @@ test_expect_success 'autocrlf=true overrides unset eol' ' has_cr one && has_cr two && - onediff=`git diff one` && - twodiff=`git diff two` && - test -z "$onediff" -a -z "$twodiff" + onediff=$(git diff one) && + twodiff=$(git diff two) && + test -z "$onediff" && test -z "$twodiff" ' test_done diff --git a/t/t0027-auto-crlf.sh b/t/t0027-auto-crlf.sh new file mode 100755 index 0000000000..72dd3e8bb4 --- /dev/null +++ b/t/t0027-auto-crlf.sh @@ -0,0 +1,265 @@ +#!/bin/sh + +test_description='CRLF conversion all combinations' + +. ./test-lib.sh + +if ! test_have_prereq EXPENSIVE +then + skip_all="EXPENSIVE not set" + test_done +fi + + +compare_files() +{ + od -c <"$1" >"$1".expect && + od -c <"$2" >"$2".actual && + test_cmp "$1".expect "$2".actual && + rm "$1".expect "$2".actual +} + +compare_ws_file() +{ + pfx=$1 + exp=$2.expect + act=$pfx.actual.$3 + od -c <"$2" >"$exp" && + od -c <"$3" >"$act" && + test_cmp $exp $act && + rm $exp $act +} + +create_gitattributes() +{ + txtbin=$1 + case "$txtbin" in + auto) + echo "*.txt text=auto" >.gitattributes + ;; + text) + echo "*.txt text" >.gitattributes + ;; + -text) + echo "*.txt -text" >.gitattributes + ;; + *) + echo >.gitattributes + ;; + esac +} + +create_file_in_repo() +{ + crlf=$1 + txtbin=$2 + create_gitattributes "$txtbin" && + for f in LF CRLF LF_mix_CR CRLF_mix_LF CRLF_nul + do + pfx=crlf_${crlf}_attr_${txtbin}_$f.txt && + cp $f $pfx && git -c core.autocrlf=$crlf add $pfx + done && + git commit -m "core.autocrlf $crlf" +} + +check_files_in_repo() +{ + crlf=$1 + txtbin=$2 + lfname=$3 + crlfname=$4 + lfmixcrlf=$5 + lfmixcr=$6 + crlfnul=$7 + pfx=crlf_${crlf}_attr_${txtbin}_ && + compare_files $lfname ${pfx}LF.txt && + compare_files $crlfname ${pfx}CRLF.txt && + compare_files $lfmixcrlf ${pfx}CRLF_mix_LF.txt && + compare_files $lfmixcr ${pfx}LF_mix_CR.txt && + compare_files $crlfnul ${pfx}CRLF_nul.txt +} + + +check_files_in_ws() +{ + eol=$1 + crlf=$2 + txtbin=$3 + lfname=$4 + crlfname=$5 + lfmixcrlf=$6 + lfmixcr=$7 + crlfnul=$8 + create_gitattributes $txtbin && + git config core.autocrlf $crlf && + pfx=eol_${eol}_crlf_${crlf}_attr_${txtbin}_ && + src=crlf_false_attr__ && + for f in LF CRLF LF_mix_CR CRLF_mix_LF CRLF_nul + do + rm $src$f.txt && + if test -z "$eol"; then + git checkout $src$f.txt + else + git -c core.eol=$eol checkout $src$f.txt + fi + done + + + test_expect_success "checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$txtbin file=LF" " + compare_ws_file $pfx $lfname ${src}LF.txt + " + test_expect_success "checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$txtbin file=CRLF" " + compare_ws_file $pfx $crlfname ${src}CRLF.txt + " + test_expect_success "checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$txtbin file=CRLF_mix_LF" " + compare_ws_file $pfx $lfmixcrlf ${src}CRLF_mix_LF.txt + " + test_expect_success "checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$txtbin file=LF_mix_CR" " + compare_ws_file $pfx $lfmixcr ${src}LF_mix_CR.txt + " + test_expect_success "checkout core.eol=$eol core.autocrlf=$crlf gitattributes=$txtbin file=CRLF_nul" " + compare_ws_file $pfx $crlfnul ${src}CRLF_nul.txt + " +} + +####### +( + type od >/dev/null && + printf "line1Q\r\nline2\r\nline3" | q_to_nul >CRLF_nul && + cat >expect <<-EOF && + 0000000 l i n e 1 \0 \r \n l i n e 2 \r \n l + 0000020 i n e 3 + 0000024 +EOF + od -c CRLF_nul | sed -e "s/[ ][ ]*/ /g" -e "s/ *$//" >actual + test_cmp expect actual && + rm expect actual +) || { + skip_all="od not found or od -c not usable" + exit 0 + test_done +} + +test_expect_success 'setup master' ' + echo >.gitattributes && + git checkout -b master && + git add .gitattributes && + git commit -m "add .gitattributes" "" && + printf "line1\nline2\nline3" >LF && + printf "line1\r\nline2\r\nline3" >CRLF && + printf "line1\r\nline2\nline3" >CRLF_mix_LF && + printf "line1\nline2\rline3" >LF_mix_CR && + printf "line1\r\nline2\rline3" >CRLF_mix_CR && + printf "line1Q\nline2\nline3" | q_to_nul >LF_nul +' +# CRLF_nul had been created above + +test_expect_success 'create files' ' + create_file_in_repo false "" && + create_file_in_repo true "" && + create_file_in_repo input "" && + + create_file_in_repo false "auto" && + create_file_in_repo true "auto" && + create_file_in_repo input "auto" && + + create_file_in_repo false "text" && + create_file_in_repo true "text" && + create_file_in_repo input "text" && + + create_file_in_repo false "-text" && + create_file_in_repo true "-text" && + create_file_in_repo input "-text" && + rm -f *.txt && + git reset --hard +' + +test_expect_success 'commit empty gitattribues' ' + check_files_in_repo false "" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul && + check_files_in_repo true "" LF LF LF LF_mix_CR CRLF_nul && + check_files_in_repo input "" LF LF LF LF_mix_CR CRLF_nul +' + +test_expect_success 'commit text=auto' ' + check_files_in_repo false "auto" LF LF LF LF_mix_CR CRLF_nul && + check_files_in_repo true "auto" LF LF LF LF_mix_CR CRLF_nul && + check_files_in_repo input "auto" LF LF LF LF_mix_CR CRLF_nul +' + +test_expect_success 'commit text' ' + check_files_in_repo false "text" LF LF LF LF_mix_CR LF_nul && + check_files_in_repo true "text" LF LF LF LF_mix_CR LF_nul && + check_files_in_repo input "text" LF LF LF LF_mix_CR LF_nul +' + +test_expect_success 'commit -text' ' + check_files_in_repo false "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul && + check_files_in_repo true "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul && + check_files_in_repo input "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +' + +################################################################################ +# Check how files in the repo are changed when they are checked out +# How to read the table below: +# - check_files_in_ws will check multiple files, see below +# - parameter $1 : core.eol lf | crlf +# - parameter $2 : core.autocrlf false | true | input +# - parameter $3 : text in .gitattributs "" (empty) | auto | text | -text +# - parameter $4 : reference for a file with only LF in the repo +# - parameter $5 : reference for a file with only CRLF in the repo +# - parameter $6 : reference for a file with mixed LF and CRLF in the repo +# - parameter $7 : reference for a file with LF and CR in the repo (does somebody uses this ?) +# - parameter $8 : reference for a file with CRLF and a NUL (should be handled as binary when auto) + +check_files_in_ws lf false "" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws lf true "" CRLF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws lf input "" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul + +check_files_in_ws lf false "auto" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws lf true "auto" CRLF CRLF CRLF LF_mix_CR CRLF_nul +check_files_in_ws lf input "auto" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul + +check_files_in_ws lf false "text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws lf true "text" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul +check_files_in_ws lf input "text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul + +check_files_in_ws lf false "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws lf true "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws lf input "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul + +########### +#core.autocrlf=input is forbidden with core.eol=crlf +check_files_in_ws crlf false "" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws crlf true "" CRLF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul + +check_files_in_ws crlf false "auto" CRLF CRLF CRLF LF_mix_CR CRLF_nul +check_files_in_ws crlf true "auto" CRLF CRLF CRLF LF_mix_CR CRLF_nul + +check_files_in_ws crlf false "text" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul +check_files_in_ws crlf true "text" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul + +check_files_in_ws crlf false "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws crlf true "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul + +if test_have_prereq MINGW +then +check_files_in_ws "" false "" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws "" true "" CRLF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws "" false "auto" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws "" true "auto" CRLF CRLF CRLF LF_mix_CR CRLF_nul +check_files_in_ws "" false "text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws "" true "text" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul +check_files_in_ws "" false "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws "" true "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul + +check_files_in_ws native false "" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws native true "" CRLF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws native false "auto" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws native true "auto" CRLF CRLF CRLF LF_mix_CR CRLF_nul +check_files_in_ws native false "text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws native true "text" CRLF CRLF CRLF CRLF_mix_CR CRLF_nul +check_files_in_ws native false "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +check_files_in_ws native true "-text" LF CRLF CRLF_mix_LF LF_mix_CR CRLF_nul +fi + +test_done diff --git a/t/t0030-stripspace.sh b/t/t0030-stripspace.sh index a8e84d8546..0333dd9875 100755 --- a/t/t0030-stripspace.sh +++ b/t/t0030-stripspace.sh @@ -225,22 +225,22 @@ test_expect_success \ test_expect_success \ 'text without newline at end should end with newline' ' - test `printf "$ttt" | git stripspace | wc -l` -gt 0 && - test `printf "$ttt$ttt" | git stripspace | wc -l` -gt 0 && - test `printf "$ttt$ttt$ttt" | git stripspace | wc -l` -gt 0 && - test `printf "$ttt$ttt$ttt$ttt" | git stripspace | wc -l` -gt 0 + test $(printf "$ttt" | git stripspace | wc -l) -gt 0 && + test $(printf "$ttt$ttt" | git stripspace | wc -l) -gt 0 && + test $(printf "$ttt$ttt$ttt" | git stripspace | wc -l) -gt 0 && + test $(printf "$ttt$ttt$ttt$ttt" | git stripspace | wc -l) -gt 0 ' # text plus spaces at the end: test_expect_success \ 'text plus spaces without newline at end should end with newline' ' - test `printf "$ttt$sss" | git stripspace | wc -l` -gt 0 && - test `printf "$ttt$ttt$sss" | git stripspace | wc -l` -gt 0 && - test `printf "$ttt$ttt$ttt$sss" | git stripspace | wc -l` -gt 0 && - test `printf "$ttt$sss$sss" | git stripspace | wc -l` -gt 0 && - test `printf "$ttt$ttt$sss$sss" | git stripspace | wc -l` -gt 0 && - test `printf "$ttt$sss$sss$sss" | git stripspace | wc -l` -gt 0 + test $(printf "$ttt$sss" | git stripspace | wc -l) -gt 0 && + test $(printf "$ttt$ttt$sss" | git stripspace | wc -l) -gt 0 && + test $(printf "$ttt$ttt$ttt$sss" | git stripspace | wc -l) -gt 0 && + test $(printf "$ttt$sss$sss" | git stripspace | wc -l) -gt 0 && + test $(printf "$ttt$ttt$sss$sss" | git stripspace | wc -l) -gt 0 && + test $(printf "$ttt$sss$sss$sss" | git stripspace | wc -l) -gt 0 ' test_expect_success \ diff --git a/t/t0081-line-buffer.sh b/t/t0081-line-buffer.sh index bd83ed371a..25dba008f3 100755 --- a/t/t0081-line-buffer.sh +++ b/t/t0081-line-buffer.sh @@ -29,7 +29,7 @@ test_expect_success '0-length read, send along greeting' ' test_cmp expect actual ' -test_expect_success 'read from file descriptor' ' +test_expect_success NOT_MINGW 'read from file descriptor' ' rm -f input && echo hello >expect && echo hello >input && diff --git a/t/t0110-urlmatch-normalization.sh b/t/t0110-urlmatch-normalization.sh index 8d6096d4d1..410d5768ca 100755 --- a/t/t0110-urlmatch-normalization.sh +++ b/t/t0110-urlmatch-normalization.sh @@ -117,7 +117,7 @@ test_expect_success 'url general escapes' ' test "$(test-urlmatch-normalization -p "X://W?'\!'")" = "x://w/?'\!'" ' -test_expect_success 'url high-bit escapes' ' +test_expect_success !MINGW 'url high-bit escapes' ' test "$(test-urlmatch-normalization -p "$(cat "$tu-1")")" = "x://q/%01%02%03%04%05%06%07%08%0E%0F%10%11%12" && test "$(test-urlmatch-normalization -p "$(cat "$tu-2")")" = "x://q/%13%14%15%16%17%18%19%1B%1C%1D%1E%1F%7F" && test "$(test-urlmatch-normalization -p "$(cat "$tu-3")")" = "x://q/%80%81%82%83%84%85%86%87%88%89%8A%8B%8C%8D%8E%8F" && @@ -127,7 +127,10 @@ test_expect_success 'url high-bit escapes' ' test "$(test-urlmatch-normalization -p "$(cat "$tu-7")")" = "x://q/%C0%C1%C2%C3%C4%C5%C6%C7%C8%C9%CA%CB%CC%CD%CE%CF" && test "$(test-urlmatch-normalization -p "$(cat "$tu-8")")" = "x://q/%D0%D1%D2%D3%D4%D5%D6%D7%D8%D9%DA%DB%DC%DD%DE%DF" && test "$(test-urlmatch-normalization -p "$(cat "$tu-9")")" = "x://q/%E0%E1%E2%E3%E4%E5%E6%E7%E8%E9%EA%EB%EC%ED%EE%EF" && - test "$(test-urlmatch-normalization -p "$(cat "$tu-10")")" = "x://q/%F0%F1%F2%F3%F4%F5%F6%F7%F8%F9%FA%FB%FC%FD%FE%FF" && + test "$(test-urlmatch-normalization -p "$(cat "$tu-10")")" = "x://q/%F0%F1%F2%F3%F4%F5%F6%F7%F8%F9%FA%FB%FC%FD%FE%FF" +' + +test_expect_success 'url utf-8 escapes' ' test "$(test-urlmatch-normalization -p "$(cat "$tu-11")")" = "x://q/%C2%80%DF%BF%E0%A0%80%EF%BF%BD%F0%90%80%80%F0%AF%BF%BD" ' diff --git a/t/t0300-credentials.sh b/t/t0300-credentials.sh index 538ea5fb1c..57ea5a10c5 100755 --- a/t/t0300-credentials.sh +++ b/t/t0300-credentials.sh @@ -6,7 +6,7 @@ test_description='basic credential helper tests' test_expect_success 'setup helper scripts' ' cat >dump <<-\EOF && - whoami=`echo $0 | sed s/.*git-credential-//` + whoami=$(echo $0 | sed s/.*git-credential-//) echo >&2 "$whoami: $*" OIFS=$IFS IFS== diff --git a/t/t1000-read-tree-m-3way.sh b/t/t1000-read-tree-m-3way.sh index babcdd2343..a0b79b4839 100755 --- a/t/t1000-read-tree-m-3way.sh +++ b/t/t1000-read-tree-m-3way.sh @@ -519,10 +519,10 @@ test_expect_success \ 'rm -f .git/index F16 && echo F16 >F16 && git update-index --add F16 && - tree0=`git write-tree` && + tree0=$(git write-tree) && echo E16 >F16 && git update-index F16 && - tree1=`git write-tree` && + tree1=$(git write-tree) && read_tree_must_succeed -m $tree0 $tree1 $tree1 $tree0 && git ls-files --stage' diff --git a/t/t1001-read-tree-m-2way.sh b/t/t1001-read-tree-m-2way.sh index 3a24abf549..db1b6f5cf4 100755 --- a/t/t1001-read-tree-m-2way.sh +++ b/t/t1001-read-tree-m-2way.sh @@ -36,7 +36,7 @@ compare_change () { } check_cache_at () { - clean_if_empty=`git diff-files -- "$1"` + clean_if_empty=$(git diff-files -- "$1") case "$clean_if_empty" in '') echo "$1: clean" ;; ?*) echo "$1: dirty" ;; @@ -68,14 +68,14 @@ test_expect_success \ echo rezrov >rezrov && echo yomin >yomin && git update-index --add nitfol bozbar rezrov && - treeH=`git write-tree` && + treeH=$(git write-tree) && echo treeH $treeH && git ls-tree $treeH && cat bozbar-new >bozbar && git update-index --add frotz bozbar --force-remove rezrov && git ls-files --stage >M.out && - treeM=`git write-tree` && + treeM=$(git write-tree) && echo treeM $treeM && git ls-tree $treeM && git diff-tree $treeH $treeM' @@ -315,7 +315,7 @@ test_expect_success \ 'rm -f .git/index && echo DF >DF && git update-index --add DF && - treeDF=`git write-tree` && + treeDF=$(git write-tree) && echo treeDF $treeDF && git ls-tree $treeDF && @@ -323,7 +323,7 @@ test_expect_success \ mkdir DF && echo DF/DF >DF/DF && git update-index --add --remove DF DF/DF && - treeDFDF=`git write-tree` && + treeDFDF=$(git write-tree) && echo treeDFDF $treeDFDF && git ls-tree $treeDFDF && git ls-files --stage >DFDF.out' @@ -345,7 +345,7 @@ test_expect_success \ 'rm -f .git/index && : >a && git update-index --add a && - treeM=`git write-tree` && + treeM=$(git write-tree) && echo treeM $treeM && git ls-tree $treeM && git ls-files --stage >treeM.out && @@ -354,7 +354,7 @@ test_expect_success \ git update-index --remove a && mkdir a && : >a/b && - treeH=`git write-tree` && + treeH=$(git write-tree) && echo treeH $treeH && git ls-tree $treeH' @@ -372,7 +372,7 @@ test_expect_success \ mkdir c && : >c/d && git update-index --add a c/d && - treeM=`git write-tree` && + treeM=$(git write-tree) && echo treeM $treeM && git ls-tree $treeM && git ls-files --stage >treeM.out && @@ -381,7 +381,7 @@ test_expect_success \ mkdir a && : >a/b && git update-index --add --remove a a/b && - treeH=`git write-tree` && + treeH=$(git write-tree) && echo treeH $treeH && git ls-tree $treeH' diff --git a/t/t1002-read-tree-m-u-2way.sh b/t/t1002-read-tree-m-u-2way.sh index a847709a13..fed877b20f 100755 --- a/t/t1002-read-tree-m-u-2way.sh +++ b/t/t1002-read-tree-m-u-2way.sh @@ -21,7 +21,7 @@ compare_change () { } check_cache_at () { - clean_if_empty=`git diff-files -- "$1"` + clean_if_empty=$(git diff-files -- "$1") case "$clean_if_empty" in '') echo "$1: clean" ;; ?*) echo "$1: dirty" ;; @@ -41,14 +41,14 @@ test_expect_success \ echo bozbar >bozbar && echo rezrov >rezrov && git update-index --add nitfol bozbar rezrov && - treeH=`git write-tree` && + treeH=$(git write-tree) && echo treeH $treeH && git ls-tree $treeH && echo gnusto >bozbar && git update-index --add frotz bozbar --force-remove rezrov && git ls-files --stage >M.out && - treeM=`git write-tree` && + treeM=$(git write-tree) && echo treeM $treeM && git ls-tree $treeM && sum bozbar frotz nitfol >M.sum && @@ -318,7 +318,7 @@ test_expect_success \ 'rm -f .git/index && echo DF >DF && git update-index --add DF && - treeDF=`git write-tree` && + treeDF=$(git write-tree) && echo treeDF $treeDF && git ls-tree $treeDF && @@ -326,7 +326,7 @@ test_expect_success \ mkdir DF && echo DF/DF >DF/DF && git update-index --add --remove DF DF/DF && - treeDFDF=`git write-tree` && + treeDFDF=$(git write-tree) && echo treeDFDF $treeDFDF && git ls-tree $treeDFDF && git ls-files --stage >DFDF.out' diff --git a/t/t1003-read-tree-prefix.sh b/t/t1003-read-tree-prefix.sh index 8c6d67edda..b6111cd150 100755 --- a/t/t1003-read-tree-prefix.sh +++ b/t/t1003-read-tree-prefix.sh @@ -11,7 +11,7 @@ test_description='git read-tree --prefix test. test_expect_success setup ' echo hello >one && git update-index --add one && - tree=`git write-tree` && + tree=$(git write-tree) && echo tree is $tree ' diff --git a/t/t1004-read-tree-m-u-wf.sh b/t/t1004-read-tree-m-u-wf.sh index 3e72aff470..c70cf42300 100755 --- a/t/t1004-read-tree-m-u-wf.sh +++ b/t/t1004-read-tree-m-u-wf.sh @@ -30,7 +30,7 @@ test_expect_success 'two-way not clobbering' ' echo >file2 master creates untracked file2 && echo >subdir/file2 master creates untracked subdir/file2 && - if err=`read_tree_u_must_succeed -m -u master side 2>&1` + if err=$(read_tree_u_must_succeed -m -u master side 2>&1) then echo should have complained false @@ -43,7 +43,7 @@ echo file2 >.gitignore test_expect_success 'two-way with incorrect --exclude-per-directory (1)' ' - if err=`read_tree_u_must_succeed -m --exclude-per-directory=.gitignore master side 2>&1` + if err=$(read_tree_u_must_succeed -m --exclude-per-directory=.gitignore master side 2>&1) then echo should have complained false @@ -54,7 +54,7 @@ test_expect_success 'two-way with incorrect --exclude-per-directory (1)' ' test_expect_success 'two-way with incorrect --exclude-per-directory (2)' ' - if err=`read_tree_u_must_succeed -m -u --exclude-per-directory=foo --exclude-per-directory=.gitignore master side 2>&1` + if err=$(read_tree_u_must_succeed -m -u --exclude-per-directory=foo --exclude-per-directory=.gitignore master side 2>&1) then echo should have complained false @@ -95,7 +95,7 @@ test_expect_success 'three-way not clobbering a working tree file' ' git checkout master && echo >file3 file three created in master, untracked && echo >subdir/file3 file three created in master, untracked && - if err=`read_tree_u_must_succeed -m -u branch-point master side 2>&1` + if err=$(read_tree_u_must_succeed -m -u branch-point master side 2>&1) then echo should have complained false diff --git a/t/t1013-read-tree-submodule.sh b/t/t1013-read-tree-submodule.sh new file mode 100755 index 0000000000..20526aed34 --- /dev/null +++ b/t/t1013-read-tree-submodule.sh @@ -0,0 +1,12 @@ +#!/bin/sh + +test_description='read-tree can handle submodules' + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-submodule-update.sh + +test_submodule_switch "git read-tree -u -m" + +test_submodule_forced_switch "git read-tree -u --reset" + +test_done diff --git a/t/t1020-subdirectory.sh b/t/t1020-subdirectory.sh index 6902320e81..62c0d25af4 100755 --- a/t/t1020-subdirectory.sh +++ b/t/t1020-subdirectory.sh @@ -20,27 +20,27 @@ test_expect_success setup ' test_expect_success 'update-index and ls-files' ' git update-index --add one && - case "`git ls-files`" in + case "$(git ls-files)" in one) echo pass one ;; *) echo bad one; exit 1 ;; esac && ( cd dir && git update-index --add two && - case "`git ls-files`" in + case "$(git ls-files)" in two) echo pass two ;; *) echo bad two; exit 1 ;; esac ) && - case "`git ls-files`" in + case "$(git ls-files)" in dir/two"$LF"one) echo pass both ;; *) echo bad; exit 1 ;; esac ' test_expect_success 'cat-file' ' - two=`git ls-files -s dir/two` && - two=`expr "$two" : "[0-7]* \\([0-9a-f]*\\)"` && + two=$(git ls-files -s dir/two) && + two=$(expr "$two" : "[0-7]* \\([0-9a-f]*\\)") && echo "$two" && git cat-file -p "$two" >actual && cmp dir/two actual && @@ -55,18 +55,18 @@ rm -f actual dir/actual test_expect_success 'diff-files' ' echo a >>one && echo d >>dir/two && - case "`git diff-files --name-only`" in + case "$(git diff-files --name-only)" in dir/two"$LF"one) echo pass top ;; *) echo bad top; exit 1 ;; esac && # diff should not omit leading paths ( cd dir && - case "`git diff-files --name-only`" in + case "$(git diff-files --name-only)" in dir/two"$LF"one) echo pass subdir ;; *) echo bad subdir; exit 1 ;; esac && - case "`git diff-files --name-only .`" in + case "$(git diff-files --name-only .)" in dir/two) echo pass subdir limited ;; *) echo bad subdir limited; exit 1 ;; esac @@ -74,11 +74,11 @@ test_expect_success 'diff-files' ' ' test_expect_success 'write-tree' ' - top=`git write-tree` && + top=$(git write-tree) && echo $top && ( cd dir && - sub=`git write-tree` && + sub=$(git write-tree) && echo $sub && test "z$top" = "z$sub" ) @@ -96,7 +96,7 @@ test_expect_success 'checkout-index' ' test_expect_success 'read-tree' ' rm -f one dir/two && - tree=`git write-tree` && + tree=$(git write-tree) && read_tree_u_must_succeed --reset -u "$tree" && cmp one original.one && cmp dir/two original.two && diff --git a/t/t1050-large.sh b/t/t1050-large.sh index fd10528009..aea493646e 100755 --- a/t/t1050-large.sh +++ b/t/t1050-large.sh @@ -131,7 +131,7 @@ test_expect_success 'git-show a large file' ' ' test_expect_success 'index-pack' ' - git clone file://"`pwd`"/.git foo && + git clone file://"$(pwd)"/.git foo && GIT_DIR=non-existent git index-pack --strict --verify foo/.git/objects/pack/*.pack ' @@ -140,7 +140,7 @@ test_expect_success 'repack' ' ' test_expect_success 'pack-objects with large loose object' ' - SHA1=`git hash-object huge` && + SHA1=$(git hash-object huge) && test_create_repo loose && echo $SHA1 | git pack-objects --stdout | GIT_ALLOC_LIMIT=0 GIT_DIR=loose/.git git unpack-objects && diff --git a/t/t1300-repo-config.sh b/t/t1300-repo-config.sh index 58cd5435be..3f80ff0c14 100755 --- a/t/t1300-repo-config.sh +++ b/t/t1300-repo-config.sh @@ -1158,4 +1158,14 @@ test_expect_failure 'adding a key into an empty section reuses header' ' test_cmp expect .git/config ' +test_expect_success POSIXPERM,PERL 'preserves existing permissions' ' + chmod 0600 .git/config && + git config imap.pass Hunter2 && + perl -e \ + "die q(badset) if ((stat(q(.git/config)))[2] & 07777) != 0600" && + git config --rename-section imap pop && + perl -e \ + "die q(badrename) if ((stat(q(.git/config)))[2] & 07777) != 0600" +' + test_done diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index e130c528fe..0218e96366 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -235,7 +235,7 @@ test_expect_success \ '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 "warning: Log for ref '"$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 && @@ -253,7 +253,7 @@ test_expect_success \ '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)"' + test "warning: Log for ref '"$m unexpectedly ended on $ld"'." = "$(cat e)"' rm -f .git/$m .git/logs/$m expect @@ -350,22 +350,28 @@ test_expect_success 'stdin fails on unknown command' ' grep "fatal: unknown command: unknown $a" err ' -test_expect_success 'stdin fails on badly quoted input' ' +test_expect_success 'stdin fails on unbalanced quotes' ' echo "create $a \"master" >stdin && test_must_fail git update-ref --stdin <stdin 2>err && grep "fatal: badly quoted argument: \\\"master" err ' -test_expect_success 'stdin fails on arguments not separated by space' ' +test_expect_success 'stdin fails on invalid escape' ' + echo "create $a \"ma\zter\"" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: badly quoted argument: \\\"ma\\\\zter\\\"" err +' + +test_expect_success 'stdin fails on junk after quoted argument' ' echo "create \"$a\"master" >stdin && test_must_fail git update-ref --stdin <stdin 2>err && - grep "fatal: expected SP but got: master" err + grep "fatal: unexpected character after quoted argument: \\\"$a\\\"master" err ' test_expect_success 'stdin fails create with no ref' ' echo "create " >stdin && test_must_fail git update-ref --stdin <stdin 2>err && - grep "fatal: create line missing <ref>" err + grep "fatal: create: missing <ref>" err ' test_expect_success 'stdin fails create with bad ref name' ' @@ -377,19 +383,19 @@ test_expect_success 'stdin fails create with bad ref name' ' test_expect_success 'stdin fails create with no new value' ' echo "create $a" >stdin && test_must_fail git update-ref --stdin <stdin 2>err && - grep "fatal: create $a missing <newvalue>" err + grep "fatal: create $a: missing <newvalue>" err ' test_expect_success 'stdin fails create with too many arguments' ' echo "create $a $m $m" >stdin && test_must_fail git update-ref --stdin <stdin 2>err && - grep "fatal: create $a has extra input: $m" err + grep "fatal: create $a: extra input: $m" err ' test_expect_success 'stdin fails update with no ref' ' echo "update " >stdin && test_must_fail git update-ref --stdin <stdin 2>err && - grep "fatal: update line missing <ref>" err + grep "fatal: update: missing <ref>" err ' test_expect_success 'stdin fails update with bad ref name' ' @@ -401,19 +407,19 @@ test_expect_success 'stdin fails update with bad ref name' ' test_expect_success 'stdin fails update with no new value' ' echo "update $a" >stdin && test_must_fail git update-ref --stdin <stdin 2>err && - grep "fatal: update $a missing <newvalue>" err + grep "fatal: update $a: missing <newvalue>" err ' test_expect_success 'stdin fails update with too many arguments' ' echo "update $a $m $m $m" >stdin && test_must_fail git update-ref --stdin <stdin 2>err && - grep "fatal: update $a has extra input: $m" err + grep "fatal: update $a: extra input: $m" err ' test_expect_success 'stdin fails delete with no ref' ' echo "delete " >stdin && test_must_fail git update-ref --stdin <stdin 2>err && - grep "fatal: delete line missing <ref>" err + grep "fatal: delete: missing <ref>" err ' test_expect_success 'stdin fails delete with bad ref name' ' @@ -425,13 +431,13 @@ test_expect_success 'stdin fails delete with bad ref name' ' test_expect_success 'stdin fails delete with too many arguments' ' echo "delete $a $m $m" >stdin && test_must_fail git update-ref --stdin <stdin 2>err && - grep "fatal: delete $a has extra input: $m" err + grep "fatal: delete $a: extra input: $m" err ' test_expect_success 'stdin fails verify with too many arguments' ' echo "verify $a $m $m" >stdin && test_must_fail git update-ref --stdin <stdin 2>err && - grep "fatal: verify $a has extra input: $m" err + grep "fatal: verify $a: extra input: $m" err ' test_expect_success 'stdin fails option with unknown name' ' @@ -458,6 +464,24 @@ test_expect_success 'stdin create ref works' ' test_cmp expect actual ' +test_expect_success 'stdin succeeds with quoted argument' ' + git update-ref -d $a && + echo "create $a \"$m\"" >stdin && + git update-ref --stdin <stdin && + git rev-parse $m >expect && + git rev-parse $a >actual && + test_cmp expect actual +' + +test_expect_success 'stdin succeeds with escaped character' ' + git update-ref -d $a && + echo "create $a \"ma\\163ter\"" >stdin && + git update-ref --stdin <stdin && + git rev-parse $m >expect && + git rev-parse $a >actual && + test_cmp expect actual +' + test_expect_success 'stdin update ref creates with zero old value' ' echo "update $b $m $Z" >stdin && git update-ref --stdin <stdin && @@ -494,21 +518,21 @@ test_expect_success 'stdin update ref fails with wrong old value' ' test_expect_success 'stdin update ref fails with bad old value' ' echo "update $c $m does-not-exist" >stdin && test_must_fail git update-ref --stdin <stdin 2>err && - grep "fatal: invalid old value for ref $c: does-not-exist" err && + grep "fatal: update $c: invalid <oldvalue>: does-not-exist" err && test_must_fail git rev-parse --verify -q $c ' test_expect_success 'stdin create ref fails with bad new value' ' echo "create $c does-not-exist" >stdin && test_must_fail git update-ref --stdin <stdin 2>err && - grep "fatal: invalid new value for ref $c: does-not-exist" err && + grep "fatal: create $c: invalid <newvalue>: does-not-exist" err && test_must_fail git rev-parse --verify -q $c ' test_expect_success 'stdin create ref fails with zero new value' ' echo "create $c " >stdin && test_must_fail git update-ref --stdin <stdin 2>err && - grep "fatal: create $c given zero new value" err && + grep "fatal: create $c: zero <newvalue>" err && test_must_fail git rev-parse --verify -q $c ' @@ -532,7 +556,7 @@ test_expect_success 'stdin delete ref fails with wrong old value' ' test_expect_success 'stdin delete ref fails with zero old value' ' echo "delete $a " >stdin && test_must_fail git update-ref --stdin <stdin 2>err && - grep "fatal: delete $a given zero old value" err && + grep "fatal: delete $a: zero <oldvalue>" err && git rev-parse $m >expect && git rev-parse $a >actual && test_cmp expect actual @@ -673,7 +697,7 @@ test_expect_success 'stdin -z fails on unknown command' ' test_expect_success 'stdin -z fails create with no ref' ' printf $F "create " >stdin && test_must_fail git update-ref -z --stdin <stdin 2>err && - grep "fatal: create line missing <ref>" err + grep "fatal: create: missing <ref>" err ' test_expect_success 'stdin -z fails create with bad ref name' ' @@ -685,7 +709,7 @@ test_expect_success 'stdin -z fails create with bad ref name' ' test_expect_success 'stdin -z fails create with no new value' ' printf $F "create $a" >stdin && test_must_fail git update-ref -z --stdin <stdin 2>err && - grep "fatal: create $a missing <newvalue>" err + grep "fatal: create $a: unexpected end of input when reading <newvalue>" err ' test_expect_success 'stdin -z fails create with too many arguments' ' @@ -697,25 +721,39 @@ test_expect_success 'stdin -z fails create with too many arguments' ' test_expect_success 'stdin -z fails update with no ref' ' printf $F "update " >stdin && test_must_fail git update-ref -z --stdin <stdin 2>err && - grep "fatal: update line missing <ref>" err + grep "fatal: update: missing <ref>" err +' + +test_expect_success 'stdin -z fails update with too few args' ' + printf $F "update $a" "$m" >stdin && + test_must_fail git update-ref -z --stdin <stdin 2>err && + grep "fatal: update $a: unexpected end of input when reading <oldvalue>" err ' test_expect_success 'stdin -z fails update with bad ref name' ' - printf $F "update ~a" "$m" >stdin && + printf $F "update ~a" "$m" "" >stdin && test_must_fail git update-ref -z --stdin <stdin 2>err && grep "fatal: invalid ref format: ~a" err ' +test_expect_success 'stdin -z emits warning with empty new value' ' + git update-ref $a $m && + printf $F "update $a" "" "" >stdin && + git update-ref -z --stdin <stdin 2>err && + grep "warning: update $a: missing <newvalue>, treating as zero" err && + test_must_fail git rev-parse --verify -q $a +' + test_expect_success 'stdin -z fails update with no new value' ' printf $F "update $a" >stdin && test_must_fail git update-ref -z --stdin <stdin 2>err && - grep "fatal: update $a missing <newvalue>" err + grep "fatal: update $a: unexpected end of input when reading <newvalue>" err ' test_expect_success 'stdin -z fails update with no old value' ' printf $F "update $a" "$m" >stdin && test_must_fail git update-ref -z --stdin <stdin 2>err && - grep "fatal: update $a missing \\[<oldvalue>\\] NUL" err + grep "fatal: update $a: unexpected end of input when reading <oldvalue>" err ' test_expect_success 'stdin -z fails update with too many arguments' ' @@ -727,7 +765,7 @@ test_expect_success 'stdin -z fails update with too many arguments' ' test_expect_success 'stdin -z fails delete with no ref' ' printf $F "delete " >stdin && test_must_fail git update-ref -z --stdin <stdin 2>err && - grep "fatal: delete line missing <ref>" err + grep "fatal: delete: missing <ref>" err ' test_expect_success 'stdin -z fails delete with bad ref name' ' @@ -739,7 +777,7 @@ test_expect_success 'stdin -z fails delete with bad ref name' ' test_expect_success 'stdin -z fails delete with no old value' ' printf $F "delete $a" >stdin && test_must_fail git update-ref -z --stdin <stdin 2>err && - grep "fatal: delete $a missing \\[<oldvalue>\\] NUL" err + grep "fatal: delete $a: unexpected end of input when reading <oldvalue>" err ' test_expect_success 'stdin -z fails delete with too many arguments' ' @@ -757,7 +795,7 @@ test_expect_success 'stdin -z fails verify with too many arguments' ' test_expect_success 'stdin -z fails verify with no old value' ' printf $F "verify $a" >stdin && test_must_fail git update-ref -z --stdin <stdin 2>err && - grep "fatal: verify $a missing \\[<oldvalue>\\] NUL" err + grep "fatal: verify $a: unexpected end of input when reading <oldvalue>" err ' test_expect_success 'stdin -z fails option with unknown name' ' @@ -816,7 +854,7 @@ test_expect_success 'stdin -z update ref fails with wrong old value' ' test_expect_success 'stdin -z update ref fails with bad old value' ' printf $F "update $c" "$m" "does-not-exist" >stdin && test_must_fail git update-ref -z --stdin <stdin 2>err && - grep "fatal: invalid old value for ref $c: does-not-exist" err && + grep "fatal: update $c: invalid <oldvalue>: does-not-exist" err && test_must_fail git rev-parse --verify -q $c ' @@ -834,14 +872,14 @@ test_expect_success 'stdin -z create ref fails with bad new value' ' git update-ref -d "$c" && printf $F "create $c" "does-not-exist" >stdin && test_must_fail git update-ref -z --stdin <stdin 2>err && - grep "fatal: invalid new value for ref $c: does-not-exist" err && + grep "fatal: create $c: invalid <newvalue>: does-not-exist" err && test_must_fail git rev-parse --verify -q $c ' -test_expect_success 'stdin -z create ref fails with zero new value' ' +test_expect_success 'stdin -z create ref fails with empty new value' ' printf $F "create $c" "" >stdin && test_must_fail git update-ref -z --stdin <stdin 2>err && - grep "fatal: create $c given zero new value" err && + grep "fatal: create $c: missing <newvalue>" err && test_must_fail git rev-parse --verify -q $c ' @@ -865,7 +903,7 @@ test_expect_success 'stdin -z delete ref fails with wrong old value' ' test_expect_success 'stdin -z delete ref fails with zero old value' ' printf $F "delete $a" "$Z" >stdin && test_must_fail git update-ref -z --stdin <stdin 2>err && - grep "fatal: delete $a given zero old value" err && + grep "fatal: delete $a: zero <oldvalue>" err && git rev-parse $m >expect && git rev-parse $a >actual && test_cmp expect actual @@ -923,7 +961,7 @@ test_expect_success 'stdin -z update refs works with identity updates' ' test_expect_success 'stdin -z update refs fails with wrong old value' ' git update-ref $c $m && - printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "" "$Z" >stdin && + printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$m" "$Z" >stdin && test_must_fail git update-ref -z --stdin <stdin 2>err && grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err && git rev-parse $m >expect && diff --git a/t/t1402-check-ref-format.sh b/t/t1402-check-ref-format.sh index 1a5a5f39fd..4bc7141226 100755 --- a/t/t1402-check-ref-format.sh +++ b/t/t1402-check-ref-format.sh @@ -48,6 +48,7 @@ invalid_ref './foo/bar' invalid_ref 'foo/./bar' invalid_ref 'foo/bar/.' invalid_ref '.refs/foo' +invalid_ref 'refs/heads/foo.' invalid_ref 'heads/foo..bar' invalid_ref 'heads/foo?bar' valid_ref 'foo./bar' diff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh index 236b13a3ab..8cab06f90a 100755 --- a/t/t1410-reflog.sh +++ b/t/t1410-reflog.sh @@ -245,4 +245,12 @@ test_expect_success 'gc.reflogexpire=false' ' ' +test_expect_success 'checkout should not delete log for packed ref' ' + test $(git reflog master | wc -l) = 4 && + git branch foo && + git pack-refs --all && + git checkout foo && + test $(git reflog master | wc -l) = 4 +' + test_done diff --git a/t/t1507-rev-parse-upstream.sh b/t/t1507-rev-parse-upstream.sh index 178694ee63..1978947c41 100755 --- a/t/t1507-rev-parse-upstream.sh +++ b/t/t1507-rev-parse-upstream.sh @@ -121,7 +121,7 @@ test_expect_success 'merge my-side@{u} records the correct name' ' git branch -D new ;# can fail but is ok git branch -t new my-side@{u} && git merge -s ours new@{u} && - git show -s --pretty=format:%s >actual && + git show -s --pretty=tformat:%s >actual && echo "Merge remote-tracking branch ${sq}origin/side${sq}" >expect && test_cmp expect actual ) diff --git a/t/t1700-split-index.sh b/t/t1700-split-index.sh new file mode 100755 index 0000000000..94fb473e7c --- /dev/null +++ b/t/t1700-split-index.sh @@ -0,0 +1,194 @@ +#!/bin/sh + +test_description='split index mode tests' + +. ./test-lib.sh + +# We need total control of index splitting here +sane_unset GIT_TEST_SPLIT_INDEX + +test_expect_success 'enable split index' ' + git update-index --split-index && + test-dump-split-index .git/index >actual && + cat >expect <<EOF && +own 8299b0bcd1ac364e5f1d7768efb62fa2da79a339 +base 39d890139ee5356c7ef572216cebcd27aa41f9df +replacements: +deletions: +EOF + test_cmp expect actual +' + +test_expect_success 'add one file' ' + : >one && + git update-index --add one && + git ls-files --stage >ls-files.actual && + cat >ls-files.expect <<EOF && +100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one +EOF + test_cmp ls-files.expect ls-files.actual && + + test-dump-split-index .git/index | sed "/^own/d" >actual && + cat >expect <<EOF && +base 39d890139ee5356c7ef572216cebcd27aa41f9df +100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one +replacements: +deletions: +EOF + test_cmp expect actual +' + +test_expect_success 'disable split index' ' + git update-index --no-split-index && + git ls-files --stage >ls-files.actual && + cat >ls-files.expect <<EOF && +100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one +EOF + test_cmp ls-files.expect ls-files.actual && + + BASE=`test-dump-split-index .git/index | grep "^own" | sed "s/own/base/"` && + test-dump-split-index .git/index | sed "/^own/d" >actual && + cat >expect <<EOF && +not a split index +EOF + test_cmp expect actual +' + +test_expect_success 'enable split index again, "one" now belongs to base index"' ' + git update-index --split-index && + git ls-files --stage >ls-files.actual && + cat >ls-files.expect <<EOF && +100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one +EOF + test_cmp ls-files.expect ls-files.actual && + + test-dump-split-index .git/index | sed "/^own/d" >actual && + cat >expect <<EOF && +$BASE +replacements: +deletions: +EOF + test_cmp expect actual +' + +test_expect_success 'modify original file, base index untouched' ' + echo modified >one && + git update-index one && + git ls-files --stage >ls-files.actual && + cat >ls-files.expect <<EOF && +100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0 one +EOF + test_cmp ls-files.expect ls-files.actual && + + test-dump-split-index .git/index | sed "/^own/d" >actual && + q_to_tab >expect <<EOF && +$BASE +100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0Q +replacements: 0 +deletions: +EOF + test_cmp expect actual +' + +test_expect_success 'add another file, which stays index' ' + : >two && + git update-index --add two && + git ls-files --stage >ls-files.actual && + cat >ls-files.expect <<EOF && +100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0 one +100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 two +EOF + test_cmp ls-files.expect ls-files.actual && + + test-dump-split-index .git/index | sed "/^own/d" >actual && + q_to_tab >expect <<EOF && +$BASE +100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0Q +100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 two +replacements: 0 +deletions: +EOF + test_cmp expect actual +' + +test_expect_success 'remove file not in base index' ' + git update-index --force-remove two && + git ls-files --stage >ls-files.actual && + cat >ls-files.expect <<EOF && +100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0 one +EOF + test_cmp ls-files.expect ls-files.actual && + + test-dump-split-index .git/index | sed "/^own/d" >actual && + q_to_tab >expect <<EOF && +$BASE +100644 2e0996000b7e9019eabcad29391bf0f5c7702f0b 0Q +replacements: 0 +deletions: +EOF + test_cmp expect actual +' + +test_expect_success 'remove file in base index' ' + git update-index --force-remove one && + git ls-files --stage >ls-files.actual && + cat >ls-files.expect <<EOF && +EOF + test_cmp ls-files.expect ls-files.actual && + + test-dump-split-index .git/index | sed "/^own/d" >actual && + cat >expect <<EOF && +$BASE +replacements: +deletions: 0 +EOF + test_cmp expect actual +' + +test_expect_success 'add original file back' ' + : >one && + git update-index --add one && + git ls-files --stage >ls-files.actual && + cat >ls-files.expect <<EOF && +100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one +EOF + test_cmp ls-files.expect ls-files.actual && + + test-dump-split-index .git/index | sed "/^own/d" >actual && + cat >expect <<EOF && +$BASE +100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one +replacements: +deletions: 0 +EOF + test_cmp expect actual +' + +test_expect_success 'add new file' ' + : >two && + git update-index --add two && + git ls-files --stage >actual && + cat >expect <<EOF && +100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one +100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 two +EOF + test_cmp expect actual +' + +test_expect_success 'unify index, two files remain' ' + git update-index --no-split-index && + git ls-files --stage >ls-files.actual && + cat >ls-files.expect <<EOF && +100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 one +100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 0 two +EOF + test_cmp ls-files.expect ls-files.actual + + test-dump-split-index .git/index | sed "/^own/d" >actual && + cat >expect <<EOF && +not a split index +EOF + test_cmp expect actual +' + +test_done diff --git a/t/t2013-checkout-submodule.sh b/t/t2013-checkout-submodule.sh index 06b18f8bc1..6847f75822 100755 --- a/t/t2013-checkout-submodule.sh +++ b/t/t2013-checkout-submodule.sh @@ -3,6 +3,7 @@ test_description='checkout can handle submodules' . ./test-lib.sh +. "$TEST_DIRECTORY"/lib-submodule-update.sh test_expect_success 'setup' ' mkdir submodule && @@ -62,4 +63,8 @@ test_expect_success '"checkout <submodule>" honors submodule.*.ignore from .git/ ! test -s actual ' +test_submodule_switch "git checkout" + +test_submodule_forced_switch "git checkout -f" + test_done diff --git a/t/t2104-update-index-skip-worktree.sh b/t/t2104-update-index-skip-worktree.sh index 29c1fb10ca..cc830da58d 100755 --- a/t/t2104-update-index-skip-worktree.sh +++ b/t/t2104-update-index-skip-worktree.sh @@ -7,6 +7,8 @@ test_description='skip-worktree bit test' . ./test-lib.sh +sane_unset GIT_TEST_SPLIT_INDEX + test_set_index_version 3 cat >expect.full <<EOF diff --git a/t/t2107-update-index-basic.sh b/t/t2107-update-index-basic.sh index fe2fb17102..1bafb9098c 100755 --- a/t/t2107-update-index-basic.sh +++ b/t/t2107-update-index-basic.sh @@ -29,6 +29,10 @@ test_expect_success 'update-index -h with corrupt index' ' test_i18ngrep "[Uu]sage: git update-index" broken/usage ' +test_expect_success '--cacheinfo complains of missing arguments' ' + test_must_fail git update-index --cacheinfo +' + test_expect_success '--cacheinfo does not accept blob null sha1' ' echo content >file && git add file && diff --git a/t/t3032-merge-recursive-options.sh b/t/t3032-merge-recursive-options.sh index 5fd7bbb652..4029c9c8c0 100755 --- a/t/t3032-merge-recursive-options.sh +++ b/t/t3032-merge-recursive-options.sh @@ -14,7 +14,11 @@ test_description='merge-recursive options . ./test-lib.sh test_have_prereq SED_STRIPS_CR && SED_OPTIONS=-b -test_have_prereq GREP_STRIPS_CR && export GREP_OPTIONS=-U +if test_have_prereq GREP_STRIPS_CR +then + GREP_OPTIONS=-U + export GREP_OPTIONS +fi test_expect_success 'setup' ' conflict_hunks () { diff --git a/t/t3302-notes-index-expensive.sh b/t/t3302-notes-index-expensive.sh index e35d7811ac..8d44e04354 100755 --- a/t/t3302-notes-index-expensive.sh +++ b/t/t3302-notes-index-expensive.sh @@ -7,9 +7,7 @@ test_description='Test commit notes index (expensive!)' . ./test-lib.sh -test_set_prereq NOT_EXPENSIVE test -n "$GIT_NOTES_TIMING_TESTS" && test_set_prereq EXPENSIVE -test -x /usr/bin/time && test_set_prereq USR_BIN_TIME create_repo () { number_of_commits=$1 @@ -17,43 +15,43 @@ create_repo () { test -d .git || { git init && ( - while [ $nr -lt $number_of_commits ]; do + while test $nr -lt $number_of_commits + do nr=$(($nr+1)) mark=$(($nr+$nr)) notemark=$(($mark+1)) test_tick && - cat <<INPUT_END && -commit refs/heads/master -mark :$mark -committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE -data <<COMMIT -commit #$nr -COMMIT - -M 644 inline file -data <<EOF -file in commit #$nr -EOF - -blob -mark :$notemark -data <<EOF -note for commit #$nr -EOF - -INPUT_END - - echo "N :$notemark :$mark" >> note_commit + cat <<-INPUT_END && + commit refs/heads/master + mark :$mark + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + data <<COMMIT + commit #$nr + COMMIT + + M 644 inline file + data <<EOF + file in commit #$nr + EOF + + blob + mark :$notemark + data <<EOF + note for commit #$nr + EOF + + INPUT_END + echo "N :$notemark :$mark" >>note_commit done && test_tick && - cat <<INPUT_END && -commit refs/notes/commits -committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE -data <<COMMIT -notes -COMMIT + cat <<-INPUT_END && + commit refs/notes/commits + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE + data <<COMMIT + notes + COMMIT -INPUT_END + INPUT_END cat note_commit ) | @@ -65,62 +63,74 @@ INPUT_END test_notes () { count=$1 && git config core.notesRef refs/notes/commits && - git log | grep "^ " > output && + git log | grep "^ " >output && i=$count && - while [ $i -gt 0 ]; do + while test $i -gt 0 + do echo " commit #$i" && echo " note for commit #$i" && - i=$(($i-1)); - done > expect && + i=$(($i-1)) + done >expect && test_cmp expect output } -cat > time_notes << \EOF +write_script time_notes <<\EOF mode=$1 i=1 - while [ $i -lt $2 ]; do + while test $i -lt $2 + do case $1 in no-notes) - GIT_NOTES_REF=non-existing; export GIT_NOTES_REF - ;; + GIT_NOTES_REF=non-existing + export GIT_NOTES_REF + ;; notes) unset GIT_NOTES_REF - ;; + ;; esac - git log >/dev/null + git log i=$(($i+1)) - done + done >/dev/null EOF time_notes () { for mode in no-notes notes do echo $mode - /usr/bin/time "$SHELL_PATH" ../time_notes $mode $1 + /usr/bin/time ../time_notes $mode $1 done } do_tests () { - pr=$1 - count=$2 - - test_expect_success $pr 'setup / mkdir' ' - mkdir $count && - cd $count + count=$1 pr=${2-} + + test_expect_success $pr "setup $count" ' + mkdir "$count" && + ( + cd "$count" && + create_repo "$count" + ) ' - test_expect_success $pr "setup $count" "create_repo $count" - - test_expect_success $pr 'notes work' "test_notes $count" - - test_expect_success USR_BIN_TIME,$pr 'notes timing with /usr/bin/time' "time_notes 100" + test_expect_success $pr 'notes work' ' + ( + cd "$count" && + test_notes "$count" + ) + ' - test_expect_success $pr 'teardown / cd ..' 'cd ..' + test_expect_success "USR_BIN_TIME${pr:+,$pr}" 'notes timing with /usr/bin/time' ' + ( + cd "$count" && + time_notes 100 + ) + ' } -do_tests NOT_EXPENSIVE 10 -for count in 100 1000 10000; do - do_tests EXPENSIVE $count +do_tests 10 +for count in 100 1000 10000 +do + do_tests "$count" EXPENSIVE done test_done diff --git a/t/t3400-rebase.sh b/t/t3400-rebase.sh index 80e0a951ea..47b5682662 100755 --- a/t/t3400-rebase.sh +++ b/t/t3400-rebase.sh @@ -169,6 +169,29 @@ test_expect_success 'default to common base in @{upstream}s reflog if no upstrea test_cmp expect actual ' +test_expect_success 'cherry-picked commits and fork-point work together' ' + git checkout default-base && + echo Amended >A && + git commit -a --no-edit --amend && + test_commit B B && + test_commit new_B B "New B" && + test_commit C C && + git checkout default && + git reset --hard default-base@{4} && + test_commit D D && + git cherry-pick -2 default-base^ && + test_commit final_B B "Final B" && + git rebase && + echo Amended >expect && + test_cmp A expect && + echo "Final B" >expect && + test_cmp B expect && + echo C >expect && + test_cmp C expect && + echo D >expect && + test_cmp D expect +' + test_expect_success 'rebase -q is quiet' ' git checkout -b quiet topic && git rebase -q master >output.out 2>&1 && diff --git a/t/t3402-rebase-merge.sh b/t/t3402-rebase-merge.sh index be8c1d5ef9..5a27ec9b5e 100755 --- a/t/t3402-rebase-merge.sh +++ b/t/t3402-rebase-merge.sh @@ -33,6 +33,7 @@ test_expect_success setup ' tr "[a-z]" "[A-Z]" <original >newfile && git add newfile && git commit -a -m"side edits further." && + git branch second-side && tr "[a-m]" "[A-M]" <original >newfile && rm -f original && @@ -41,6 +42,7 @@ test_expect_success setup ' git branch test-rebase side && git branch test-rebase-pick side && git branch test-reference-pick side && + git branch test-conflicts side && git checkout -b test-merge side ' @@ -138,4 +140,17 @@ test_expect_success 'rebase -s funny -Xopt' ' test -f funny.was.run ' +test_expect_success 'rebase --skip works with two conflicts in a row' ' + git checkout second-side && + tr "[A-Z]" "[a-z]" <newfile >tmp && + mv tmp newfile && + git commit -a -m"edit conflicting with side" && + tr "[d-f]" "[D-F]" <newfile >tmp && + mv tmp newfile && + git commit -a -m"another edit conflicting with side" && + test_must_fail git rebase --merge test-conflicts && + test_must_fail git rebase --skip && + git rebase --skip +' + test_done diff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh index c0023a5b4f..8197ed29a9 100755 --- a/t/t3404-rebase-interactive.sh +++ b/t/t3404-rebase-interactive.sh @@ -67,6 +67,14 @@ test_expect_success 'setup' ' SHELL= export SHELL +test_expect_success 'rebase --keep-empty' ' + git checkout -b emptybranch master && + git commit --allow-empty -m "empty" && + git rebase --keep-empty -i HEAD~2 && + git log --oneline >actual && + test_line_count = 6 actual +' + test_expect_success 'rebase -i with the exec command' ' git checkout master && ( diff --git a/t/t3419-rebase-patch-id.sh b/t/t3419-rebase-patch-id.sh index e70ac10a0c..9292b499f3 100755 --- a/t/t3419-rebase-patch-id.sh +++ b/t/t3419-rebase-patch-id.sh @@ -4,12 +4,9 @@ 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() -{ +count () { i=0 while test $i -lt $1 do @@ -18,8 +15,7 @@ count() done } -scramble() -{ +scramble () { i=0 while read x do @@ -28,12 +24,11 @@ scramble() echo "$x" fi i=$((($i+1) % 10)) - done < "$1" > "$1.new" + done <"$1" >"$1.new" mv -f "$1.new" "$1" } -run() -{ +run () { echo \$ "$@" /usr/bin/time "$@" >/dev/null } @@ -43,10 +38,8 @@ test_expect_success 'setup' ' git tag root ' -do_tests() -{ - pr=$1 - nlines=$2 +do_tests () { + nlines=$1 pr=${2-} test_expect_success $pr "setup: $nlines lines" " rm -f .gitattributes && @@ -103,7 +96,7 @@ do_tests() " } -do_tests NOT_EXPENSIVE 500 -do_tests EXPENSIVE 50000 +do_tests 500 +do_tests 50000 EXPENSIVE test_done diff --git a/t/t3420-rebase-autostash.sh b/t/t3420-rebase-autostash.sh index 90eb26493c..d783f03d3f 100755 --- a/t/t3420-rebase-autostash.sh +++ b/t/t3420-rebase-autostash.sh @@ -167,4 +167,19 @@ testrebase "" .git/rebase-apply testrebase " --merge" .git/rebase-merge testrebase " --interactive" .git/rebase-merge +test_expect_success 'abort rebase -i with --autostash' ' + test_when_finished "git reset --hard" && + echo uncommited-content >file0 && + ( + write_script abort-editor.sh <<-\EOF && + echo >"$1" + EOF + test_set_editor "$(pwd)/abort-editor.sh" && + test_must_fail git rebase -i --autostash HEAD^ && + rm -f abort-editor.sh + ) && + echo uncommited-content >expected && + test_cmp expected file0 +' + test_done diff --git a/t/t3426-rebase-submodule.sh b/t/t3426-rebase-submodule.sh new file mode 100755 index 0000000000..d5b896d445 --- /dev/null +++ b/t/t3426-rebase-submodule.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +test_description='rebase can handle submodules' + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-submodule-update.sh +. "$TEST_DIRECTORY"/lib-rebase.sh + +git_rebase () { + git status -su >expect && + ls -1pR * >>expect && + git checkout -b ours HEAD && + echo x >>file1 && + git add file1 && + git commit -m add_x && + git revert HEAD && + git status -su >actual && + ls -1pR * >>actual && + test_cmp expect actual && + git rebase "$1" +} + +test_submodule_switch "git_rebase" + +git_rebase_interactive () { + git status -su >expect && + ls -1pR * >>expect && + git checkout -b ours HEAD && + echo x >>file1 && + git add file1 && + git commit -m add_x && + git revert HEAD && + git status -su >actual && + ls -1pR * >>actual && + test_cmp expect actual && + set_fake_editor && + echo "fake-editor.sh" >.git/info/exclude && + git rebase -i "$1" +} + +KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1 +# The real reason "replace directory with submodule" fails is because a +# directory "sub1" exists, but we reuse the suppression added for merge here +test_submodule_switch "git_rebase_interactive" + +test_done diff --git a/t/t3508-cherry-pick-many-commits.sh b/t/t3508-cherry-pick-many-commits.sh index 19c99d7ef1..b457333e18 100755 --- a/t/t3508-cherry-pick-many-commits.sh +++ b/t/t3508-cherry-pick-many-commits.sh @@ -65,12 +65,15 @@ test_expect_success 'output to keep user entertained during multi-pick' ' cat <<-\EOF >expected && [master OBJID] second Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:14:13 2005 -0700 1 file changed, 1 insertion(+) [master OBJID] third Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:15:13 2005 -0700 1 file changed, 1 insertion(+) [master OBJID] fourth Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:16:13 2005 -0700 1 file changed, 1 insertion(+) EOF @@ -98,14 +101,17 @@ test_expect_success 'output during multi-pick indicates merge strategy' ' Trying simple merge. [master OBJID] second Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:14:13 2005 -0700 1 file changed, 1 insertion(+) Trying simple merge. [master OBJID] third Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:15:13 2005 -0700 1 file changed, 1 insertion(+) Trying simple merge. [master OBJID] fourth Author: A U Thor <author@example.com> + Date: Thu Apr 7 15:16:13 2005 -0700 1 file changed, 1 insertion(+) EOF diff --git a/t/t3512-cherry-pick-submodule.sh b/t/t3512-cherry-pick-submodule.sh new file mode 100755 index 0000000000..6863b7bb6f --- /dev/null +++ b/t/t3512-cherry-pick-submodule.sh @@ -0,0 +1,13 @@ +#!/bin/sh + +test_description='cherry-pick can handle submodules' + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-submodule-update.sh + +KNOWN_FAILURE_CHERRY_PICK_SEES_EMPTY_COMMIT=1 +KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1 +KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1 +test_submodule_switch "git cherry-pick" + +test_done diff --git a/t/t3513-revert-submodule.sh b/t/t3513-revert-submodule.sh new file mode 100755 index 0000000000..a1c4e0216f --- /dev/null +++ b/t/t3513-revert-submodule.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +test_description='revert can handle submodules' + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-submodule-update.sh + +# Create a revert that moves from HEAD (including any test modifications to +# the work tree) to $1 by first checking out $1 and reverting it. Reverting +# the revert is the transition we test for. We tar the current work tree +# first so we can restore the work tree test setup after doing the checkout +# and revert. We test here that the restored work tree content is identical +# to that at the beginning. The last revert is then tested by the framework. +git_revert () { + git status -su >expect && + ls -1pR * >>expect && + tar czf "$TRASH_DIRECTORY/tmp.tgz" * && + git checkout "$1" && + git revert HEAD && + rm -rf * && + tar xzf "$TRASH_DIRECTORY/tmp.tgz" && + git status -su >actual && + ls -1pR * >>actual && + test_cmp expect actual && + git revert HEAD +} + +KNOWN_FAILURE_CHERRY_PICK_SEES_EMPTY_COMMIT=1 +KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1 +test_submodule_switch "git_revert" + +test_done diff --git a/t/t3901-i18n-patch.sh b/t/t3901-i18n-patch.sh index 31a5770b34..55c8a2f576 100755 --- a/t/t3901-i18n-patch.sh +++ b/t/t3901-i18n-patch.sh @@ -54,10 +54,13 @@ test_expect_success setup ' git add yours && git commit -s -m "Second on side" && - # the second one on the side branch is ISO-8859-1 - git config i18n.commitencoding ISO8859-1 && - # use author and committer name in ISO-8859-1 to match it. - . "$TEST_DIRECTORY"/t3901-8859-1.txt && + if test_have_prereq NOT_MINGW + then + # the second one on the side branch is ISO-8859-1 + git config i18n.commitencoding ISO8859-1 && + # use author and committer name in ISO-8859-1 to match it. + . "$TEST_DIRECTORY"/t3901-8859-1.txt + fi && test_tick && echo Yet another >theirs && git add theirs && @@ -119,7 +122,7 @@ test_expect_success 'rebase (U/L)' ' check_encoding 2 ' -test_expect_success 'rebase (L/L)' ' +test_expect_success NOT_MINGW 'rebase (L/L)' ' # In this test we want ISO-8859-1 encoded commits as the result git config i18n.commitencoding ISO8859-1 && git config i18n.logoutputencoding ISO8859-1 && @@ -131,7 +134,7 @@ test_expect_success 'rebase (L/L)' ' check_encoding 2 8859 ' -test_expect_success 'rebase (L/U)' ' +test_expect_success NOT_MINGW 'rebase (L/U)' ' # This is pathological -- use UTF-8 as intermediate form # to get ISO-8859-1 results. git config i18n.commitencoding ISO8859-1 && @@ -159,7 +162,7 @@ test_expect_success 'cherry-pick(U/U)' ' check_encoding 3 ' -test_expect_success 'cherry-pick(L/L)' ' +test_expect_success NOT_MINGW 'cherry-pick(L/L)' ' # Both the commitencoding and logoutputencoding is set to ISO-8859-1 git config i18n.commitencoding ISO8859-1 && @@ -189,7 +192,7 @@ test_expect_success 'cherry-pick(U/L)' ' check_encoding 3 ' -test_expect_success 'cherry-pick(L/U)' ' +test_expect_success NOT_MINGW 'cherry-pick(L/U)' ' # Again, the commitencoding is set to ISO-8859-1 but # logoutputencoding is set to UTF-8. diff --git a/t/t3905-stash-include-untracked.sh b/t/t3905-stash-include-untracked.sh index a5e7e6b2ba..f372fc8ca8 100755 --- a/t/t3905-stash-include-untracked.sh +++ b/t/t3905-stash-include-untracked.sh @@ -96,8 +96,8 @@ test_expect_success 'stash pop after save --include-untracked leaves files untra git stash pop && git status --porcelain >actual && test_cmp expect actual && - test "1" = "`cat file2`" && - test untracked = "`cat untracked/untracked`" + test "1" = "$(cat file2)" && + test untracked = "$(cat untracked/untracked)" ' git clean --force --quiet -d diff --git a/t/t3906-stash-submodule.sh b/t/t3906-stash-submodule.sh new file mode 100755 index 0000000000..d7219d6f8f --- /dev/null +++ b/t/t3906-stash-submodule.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +test_description='stash apply can handle submodules' + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-submodule-update.sh + +git_stash () { + git status -su >expect && + ls -1pR * >>expect && + git read-tree -u -m "$1" && + git stash && + git status -su >actual && + ls -1pR * >>actual && + test_cmp expect actual && + git stash apply +} + +KNOWN_FAILURE_STASH_DOES_IGNORE_SUBMODULE_CHANGES=1 +KNOWN_FAILURE_CHERRY_PICK_SEES_EMPTY_COMMIT=1 +KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1 +test_submodule_switch "git_stash" + +test_done diff --git a/t/t3910-mac-os-precompose.sh b/t/t3910-mac-os-precompose.sh index e4ba6013e4..831935665e 100755 --- a/t/t3910-mac-os-precompose.sh +++ b/t/t3910-mac-os-precompose.sh @@ -14,13 +14,13 @@ then fi # create utf-8 variables -Adiarnfc=`printf '\303\204'` -Adiarnfd=`printf 'A\314\210'` +Adiarnfc=$(printf '\303\204') +Adiarnfd=$(printf 'A\314\210') -Odiarnfc=`printf '\303\226'` -Odiarnfd=`printf 'O\314\210'` -AEligatu=`printf '\303\206'` -Invalidu=`printf '\303\377'` +Odiarnfc=$(printf '\303\226') +Odiarnfd=$(printf 'O\314\210') +AEligatu=$(printf '\303\206') +Invalidu=$(printf '\303\377') #Create a string with 255 bytes (decomposed) @@ -35,7 +35,7 @@ Alongc=$Alongc$Alongc$Alongc$Alongc$Alongc #250 Byte Alongc=$Alongc$AEligatu$AEligatu #254 Byte test_expect_success "detect if nfd needed" ' - precomposeunicode=`git config core.precomposeunicode` && + precomposeunicode=$(git config core.precomposeunicode) && test "$precomposeunicode" = true && git config core.precomposeunicode true ' @@ -140,13 +140,23 @@ test_expect_success "Add long precomposed filename" ' git add * && git commit -m "Long filename" ' + +test_expect_failure 'handle existing decomposed filenames' ' + echo content >"verbatim.$Adiarnfd" && + git -c core.precomposeunicode=false add "verbatim.$Adiarnfd" && + git commit -m "existing decomposed file" && + >expect && + git ls-files --exclude-standard -o "verbatim*" >untracked && + test_cmp expect untracked +' + # Test if the global core.precomposeunicode stops autosensing # Must be the last test case test_expect_success "respect git config --global core.precomposeunicode" ' git config --global core.precomposeunicode true && rm -rf .git && git init && - precomposeunicode=`git config core.precomposeunicode` && + precomposeunicode=$(git config core.precomposeunicode) && test "$precomposeunicode" = "true" ' diff --git a/t/t4006-diff-mode.sh b/t/t4006-diff-mode.sh index 05911492ca..76f643b2c2 100755 --- a/t/t4006-diff-mode.sh +++ b/t/t4006-diff-mode.sh @@ -13,7 +13,7 @@ sed_script='s/\(:100644 100755\) \('"$_x40"'\) \2 /\1 X X /' test_expect_success 'setup' ' echo frotz >rezrov && git update-index --add rezrov && - tree=`git write-tree` && + tree=$(git write-tree) && echo $tree ' diff --git a/t/t4010-diff-pathspec.sh b/t/t4010-diff-pathspec.sh index 2bb973655b..bf07841866 100755 --- a/t/t4010-diff-pathspec.sh +++ b/t/t4010-diff-pathspec.sh @@ -18,7 +18,7 @@ test_expect_success \ mkdir path1 && echo rezrov >path1/file1 && git update-index --add file0 path1/file1 && - tree=`git write-tree` && + tree=$(git write-tree) && echo "$tree" && echo nitfol >file0 && echo yomin >path1/file1 && @@ -131,7 +131,7 @@ test_expect_success 'diff multiple wildcard pathspecs' ' mkdir path2 && echo rezrov >path2/file1 && git update-index --add path2/file1 && - tree3=`git write-tree` && + tree3=$(git write-tree) && git diff --name-only $tree $tree3 -- "path2*1" "path1*1" >actual && cat <<-\EOF >expect && path1/file1 diff --git a/t/t4012-diff-binary.sh b/t/t4012-diff-binary.sh index 1215ae544b..643d729157 100755 --- a/t/t4012-diff-binary.sh +++ b/t/t4012-diff-binary.sh @@ -67,18 +67,18 @@ test_expect_success C_LOCALE_OUTPUT 'apply detecting corrupt patch correctly' ' git diff >output && sed -e "s/-CIT/xCIT/" <output >broken && test_must_fail git apply --stat --summary broken 2>detected && - detected=`cat detected` && - detected=`expr "$detected" : "fatal.*at line \\([0-9]*\\)\$"` && - detected=`sed -ne "${detected}p" broken` && + detected=$(cat detected) && + detected=$(expr "$detected" : "fatal.*at line \\([0-9]*\\)\$") && + detected=$(sed -ne "${detected}p" broken) && test "$detected" = xCIT ' test_expect_success C_LOCALE_OUTPUT 'apply detecting corrupt patch correctly' ' git diff --binary | sed -e "s/-CIT/xCIT/" >broken && test_must_fail git apply --stat --summary broken 2>detected && - detected=`cat detected` && - detected=`expr "$detected" : "fatal.*at line \\([0-9]*\\)\$"` && - detected=`sed -ne "${detected}p" broken` && + detected=$(cat detected) && + detected=$(expr "$detected" : "fatal.*at line \\([0-9]*\\)\$") && + detected=$(sed -ne "${detected}p" broken) && test "$detected" = xCIT ' @@ -88,7 +88,7 @@ test_expect_success 'initial commit' 'git commit -a -m initial' test_expect_success 'diff-index with --binary' ' echo AIT >a && mv b e && echo CIT >c && cat e >d && git update-index --add --remove a b c d e && - tree0=`git write-tree` && + tree0=$(git write-tree) && git diff --cached --binary >current && git apply --stat --summary current ' @@ -96,7 +96,7 @@ test_expect_success 'diff-index with --binary' ' test_expect_success 'apply binary patch' ' git reset --hard && git apply --binary --index <current && - tree1=`git write-tree` && + tree1=$(git write-tree) && test "$tree1" = "$tree0" ' diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh index e77c09c37e..6ec6072118 100755 --- a/t/t4013-diff-various.sh +++ b/t/t4013-diff-various.sh @@ -107,14 +107,14 @@ test_expect_success setup ' +*++ [initial] Initial EOF -V=`git version | sed -e 's/^git version //' -e 's/\./\\./g'` +V=$(git version | sed -e 's/^git version //' -e 's/\./\\./g') while read cmd do case "$cmd" in '' | '#'*) continue ;; esac - test=`echo "$cmd" | sed -e 's|[/ ][/ ]*|_|g'` - pfx=`printf "%04d" $test_count` + test=$(echo "$cmd" | sed -e 's|[/ ][/ ]*|_|g') + pfx=$(printf "%04d" $test_count) expect="$TEST_DIRECTORY/t4013/diff.$test" actual="$pfx-diff.$test" @@ -324,4 +324,14 @@ test_expect_success 'diff --cached -- file on unborn branch' ' test_cmp "$TEST_DIRECTORY/t4013/diff.diff_--cached_--_file0" result ' +test_expect_success 'diff-tree --stdin with log formatting' ' + cat >expect <<-\EOF && + Side + Third + Second + EOF + git rev-list master | git diff-tree --stdin --format=%s -s >actual && + test_cmp expect actual +' + test_done diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index 9c80633146..256affce89 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -43,7 +43,7 @@ test_expect_success setup ' test_expect_success "format-patch --ignore-if-in-upstream" ' git format-patch --stdout master..side >patch0 && - cnt=`grep "^From " patch0 | wc -l` && + cnt=$(grep "^From " patch0 | wc -l) && test $cnt = 3 ' @@ -52,7 +52,7 @@ test_expect_success "format-patch --ignore-if-in-upstream" ' git format-patch --stdout \ --ignore-if-in-upstream master..side >patch1 && - cnt=`grep "^From " patch1 | wc -l` && + cnt=$(grep "^From " patch1 | wc -l) && test $cnt = 2 ' @@ -69,7 +69,7 @@ test_expect_success "format-patch doesn't consider merge commits" ' git checkout -b merger master && test_tick && git merge --no-ff slave && - cnt=`git format-patch -3 --stdout | grep "^From " | wc -l` && + cnt=$(git format-patch -3 --stdout | grep "^From " | wc -l) && test $cnt = 3 ' @@ -77,7 +77,7 @@ test_expect_success "format-patch result applies" ' git checkout -b rebuild-0 master && git am -3 patch0 && - cnt=`git rev-list master.. | wc -l` && + cnt=$(git rev-list master.. | wc -l) && test $cnt = 2 ' @@ -85,7 +85,7 @@ test_expect_success "format-patch --ignore-if-in-upstream result applies" ' git checkout -b rebuild-1 master && git am -3 patch1 && - cnt=`git rev-list master.. | wc -l` && + cnt=$(git rev-list master.. | wc -l) && test $cnt = 2 ' @@ -762,6 +762,67 @@ test_expect_success 'format-patch --signature="" suppresses signatures' ' ! grep "^-- \$" output ' +test_expect_success 'prepare mail-signature input' ' + cat >mail-signature <<-\EOF + + Test User <test.email@kernel.org> + http://git.kernel.org/cgit/git/git.git + + git.kernel.org/?p=git/git.git;a=summary + + EOF +' + +test_expect_success '--signature-file=file works' ' + git format-patch --stdout --signature-file=mail-signature -1 >output && + check_patch output && + sed -e "1,/^-- \$/d" <output >actual && + { + cat mail-signature && echo + } >expect && + test_cmp expect actual +' + +test_expect_success 'format.signaturefile works' ' + test_config format.signaturefile mail-signature && + git format-patch --stdout -1 >output && + check_patch output && + sed -e "1,/^-- \$/d" <output >actual && + { + cat mail-signature && echo + } >expect && + test_cmp expect actual +' + +test_expect_success '--no-signature suppresses format.signaturefile ' ' + test_config format.signaturefile mail-signature && + git format-patch --stdout --no-signature -1 >output && + check_patch output && + ! grep "^-- \$" output +' + +test_expect_success '--signature-file overrides format.signaturefile' ' + cat >other-mail-signature <<-\EOF + Use this other signature instead of mail-signature. + EOF + test_config format.signaturefile mail-signature && + git format-patch --stdout \ + --signature-file=other-mail-signature -1 >output && + check_patch output && + sed -e "1,/^-- \$/d" <output >actual && + { + cat other-mail-signature && echo + } >expect && + test_cmp expect actual +' + +test_expect_success '--signature overrides format.signaturefile' ' + test_config format.signaturefile mail-signature && + git format-patch --stdout --signature="my sig" -1 >output && + check_patch output && + grep "my sig" output +' + test_expect_success TTY 'format-patch --stdout paginates' ' rm -f pager_used && test_terminal env GIT_PAGER="wc >pager_used" git format-patch --stdout --all && diff --git a/t/t4018-diff-funcname.sh b/t/t4018-diff-funcname.sh index 34591c23da..1dbaa3864a 100755 --- a/t/t4018-diff-funcname.sh +++ b/t/t4018-diff-funcname.sh @@ -52,15 +52,15 @@ do echo "*.java diff=$p" >.gitattributes && test_expect_code 1 git diff --no-index \ A.java B.java 2>msg && - ! test_i18ngrep fatal msg && - ! test_i18ngrep error msg + test_i18ngrep ! fatal msg && + test_i18ngrep ! error msg ' test_expect_success "builtin $p wordRegex pattern compiles" ' echo "*.java diff=$p" >.gitattributes && test_expect_code 1 git diff --no-index --word-diff \ A.java B.java 2>msg && - ! test_i18ngrep fatal msg && - ! test_i18ngrep error msg + test_i18ngrep ! fatal msg && + test_i18ngrep ! error msg ' done diff --git a/t/t4036-format-patch-signer-mime.sh b/t/t4036-format-patch-signer-mime.sh index ba43f18549..98d9713d8b 100755 --- a/t/t4036-format-patch-signer-mime.sh +++ b/t/t4036-format-patch-signer-mime.sh @@ -42,7 +42,7 @@ test_expect_success 'attach and signoff do not duplicate mime headers' ' GIT_COMMITTER_NAME="はまの ふにおう" \ git format-patch -s --stdout -1 --attach >output && - test `grep -ci ^MIME-Version: output` = 1 + test $(grep -ci ^MIME-Version: output) = 1 ' diff --git a/t/t4038-diff-combined.sh b/t/t4038-diff-combined.sh index 1019d7b35f..41913c3aa3 100755 --- a/t/t4038-diff-combined.sh +++ b/t/t4038-diff-combined.sh @@ -94,7 +94,7 @@ test_expect_success 'setup for --cc --raw' ' blob=$(echo file | git hash-object --stdin -w) && base_tree=$(echo "100644 blob $blob file" | git mktree) && trees= && - for i in `test_seq 1 40` + for i in $(test_seq 1 40) do blob=$(echo file$i | git hash-object --stdin -w) && trees="$trees$(echo "100644 blob $blob file" | git mktree)$LF" diff --git a/t/t4039-diff-assume-unchanged.sh b/t/t4039-diff-assume-unchanged.sh index 9d9498bd95..23c0e357a7 100755 --- a/t/t4039-diff-assume-unchanged.sh +++ b/t/t4039-diff-assume-unchanged.sh @@ -28,4 +28,15 @@ test_expect_success 'diff-files does not examine assume-unchanged entries' ' test -z "$(git diff-files -- one)" ' +test_expect_success POSIXPERM 'find-copies-harder is not confused by mode bits' ' + echo content >exec && + chmod +x exec && + git add exec && + git commit -m exec && + git update-index --assume-unchanged exec && + >expect && + git diff-files --find-copies-harder -- exec >actual && + test_cmp expect actual +' + test_done diff --git a/t/t4041-diff-submodule-option.sh b/t/t4041-diff-submodule-option.sh index 1751c83307..e4328964a7 100755 --- a/t/t4041-diff-submodule-option.sh +++ b/t/t4041-diff-submodule-option.sh @@ -11,6 +11,9 @@ This test tries to verify the sanity of the --submodule option of git diff. . ./test-lib.sh +# Tested non-UTF-8 encoding +test_encoding="ISO8859-1" + # String "added" in German (translated with Google Translate), encoded in UTF-8, # used in sample commit log messages in add_file() function below. added=$(printf "hinzugef\303\274gt") @@ -23,8 +26,10 @@ add_file () { echo "$name" >"$name" && git add "$name" && test_tick && - msg_added_iso88591=$(echo "Add $name ($added $name)" | iconv -f utf-8 -t iso8859-1) && - git -c 'i18n.commitEncoding=iso8859-1' commit -m "$msg_added_iso88591" + # "git commit -m" would break MinGW, as Windows refuse to pass + # $test_encoding encoded parameter to git. + echo "Add $name ($added $name)" | iconv -f utf-8 -t $test_encoding | + git -c "i18n.commitEncoding=$test_encoding" commit -F - done >/dev/null && git rev-parse --short --verify HEAD ) diff --git a/t/t4057-diff-combined-paths.sh b/t/t4057-diff-combined-paths.sh index 097e63215e..dff36b77ec 100755 --- a/t/t4057-diff-combined-paths.sh +++ b/t/t4057-diff-combined-paths.sh @@ -5,7 +5,7 @@ test_description='combined diff show only paths that are different to all parent . ./test-lib.sh # verify that diffc.expect matches output of -# `git diff -c --name-only HEAD HEAD^ HEAD^2` +# $(git diff -c --name-only HEAD HEAD^ HEAD^2) diffc_verify () { git diff -c --name-only HEAD HEAD^ HEAD^2 >diffc.actual && test_cmp diffc.expect diffc.actual diff --git a/t/t4102-apply-rename.sh b/t/t4102-apply-rename.sh index 49e2d6c349..fae305979a 100755 --- a/t/t4102-apply-rename.sh +++ b/t/t4102-apply-rename.sh @@ -52,6 +52,6 @@ EOF test_expect_success 'apply copy' \ 'git apply --index --stat --summary --apply test-patch && - test "$(cat bar)" = "This is bar" -a "$(cat foo)" = "This is foo"' + test "$(cat bar)" = "This is bar" && test "$(cat foo)" = "This is foo"' test_done diff --git a/t/t4107-apply-ignore-whitespace.sh b/t/t4107-apply-ignore-whitespace.sh index b04fc8fc12..9e29b5262d 100755 --- a/t/t4107-apply-ignore-whitespace.sh +++ b/t/t4107-apply-ignore-whitespace.sh @@ -111,7 +111,6 @@ sed -e 's/T/ /g' > main.c.final <<\EOF #include <stdio.h> void print_int(int num); -T/* a comment */ int func(int num); int main() { @@ -154,7 +153,8 @@ test_expect_success 'patch2 reverse applies with --ignore-space-change' ' git config apply.ignorewhitespace change test_expect_success 'patch2 applies (apply.ignorewhitespace = change)' ' - git apply patch2.patch + git apply patch2.patch && + test_cmp main.c.final main.c ' test_expect_success 'patch3 fails (missing string at EOL)' ' @@ -165,12 +165,8 @@ test_expect_success 'patch4 fails (missing EOL at EOF)' ' test_must_fail git apply patch4.patch ' -test_expect_success 'patch5 applies (leading whitespace)' ' - git apply patch5.patch -' - -test_expect_success 'patches do not mangle whitespace' ' - test_cmp main.c main.c.final +test_expect_success 'patch5 fails (leading whitespace differences matter)' ' + test_must_fail git apply patch5.patch ' test_expect_success 're-create file (with --ignore-whitespace)' ' diff --git a/t/t4116-apply-reverse.sh b/t/t4116-apply-reverse.sh index 1e4d4380bf..ce8567f496 100755 --- a/t/t4116-apply-reverse.sh +++ b/t/t4116-apply-reverse.sh @@ -30,10 +30,10 @@ test_expect_success setup ' test_expect_success 'apply in forward' ' - T0=`git rev-parse "second^{tree}"` && + T0=$(git rev-parse "second^{tree}") && git reset --hard initial && git apply --index --binary patch && - T1=`git write-tree` && + T1=$(git write-tree) && test "$T0" = "$T1" ' @@ -62,22 +62,22 @@ test_expect_success 'setup separate repository lacking postimage' ' test_expect_success 'apply in forward without postimage' ' - T0=`git rev-parse "second^{tree}"` && + T0=$(git rev-parse "second^{tree}") && ( cd initial && git apply --index --binary ../patch && - T1=`git write-tree` && + T1=$(git write-tree) && test "$T0" = "$T1" ) ' test_expect_success 'apply in reverse without postimage' ' - T0=`git rev-parse "initial^{tree}"` && + T0=$(git rev-parse "initial^{tree}") && ( cd second && git apply --index --binary --reverse ../patch && - T1=`git write-tree` && + T1=$(git write-tree) && test "$T0" = "$T1" ) ' diff --git a/t/t4119-apply-config.sh b/t/t4119-apply-config.sh index 3d0384daa8..c393be691b 100755 --- a/t/t4119-apply-config.sh +++ b/t/t4119-apply-config.sh @@ -68,7 +68,7 @@ test_expect_success 'apply --whitespace=strip from config' ' check_result sub/file1 ' -D=`pwd` +D=$(pwd) test_expect_success 'apply --whitespace=strip in subdir' ' diff --git a/t/t4137-apply-submodule.sh b/t/t4137-apply-submodule.sh new file mode 100755 index 0000000000..a9bd40a6d0 --- /dev/null +++ b/t/t4137-apply-submodule.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +test_description='git apply handling submodules' + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-submodule-update.sh + +apply_index () { + git diff --ignore-submodules=dirty "..$1" | git apply --index - +} + +test_submodule_switch "apply_index" + +apply_3way () { + git diff --ignore-submodules=dirty "..$1" | git apply --3way - +} + +test_submodule_switch "apply_3way" + +test_done diff --git a/t/t4201-shortlog.sh b/t/t4201-shortlog.sh index 42866992cf..565c020c45 100755 --- a/t/t4201-shortlog.sh +++ b/t/t4201-shortlog.sh @@ -93,7 +93,7 @@ test_expect_success 'output from user-defined format is re-wrapped' ' test_cmp expect log.predictable ' -test_expect_success 'shortlog wrapping' ' +test_expect_success NOT_MINGW 'shortlog wrapping' ' cat >expect <<\EOF && A U Thor (5): Test @@ -114,7 +114,7 @@ EOF test_cmp expect out ' -test_expect_success 'shortlog from non-git directory' ' +test_expect_success NOT_MINGW 'shortlog from non-git directory' ' git log HEAD >log && GIT_DIR=non-existing git shortlog -w <log >out && test_cmp expect out @@ -159,7 +159,7 @@ $DSCHO (2): EOF -test_expect_success 'shortlog encoding' ' +test_expect_success NOT_MINGW 'shortlog encoding' ' git reset --hard "$commit" && git config --unset i18n.commitencoding && echo 2 > a1 && @@ -188,4 +188,10 @@ test_expect_success 'shortlog ignores commits with missing authors' ' test_cmp expect actual ' +test_expect_success 'shortlog with revision pseudo options' ' + git shortlog --all && + git shortlog --branches && + git shortlog --exclude=refs/heads/m* --all +' + test_done diff --git a/t/t4202-log.sh b/t/t4202-log.sh index cb03d28769..99ab7ca21f 100755 --- a/t/t4202-log.sh +++ b/t/t4202-log.sh @@ -3,6 +3,7 @@ test_description='git log' . ./test-lib.sh +. "$TEST_DIRECTORY/lib-gpg.sh" test_expect_success setup ' @@ -841,4 +842,34 @@ test_expect_success 'dotdot is a parent directory' ' test_cmp expect actual ' +test_expect_success GPG 'log --graph --show-signature' ' + test_when_finished "git reset --hard && git checkout master" && + git checkout -b signed master && + echo foo >foo && + git add foo && + git commit -S -m signed_commit && + git log --graph --show-signature -n1 signed >actual && + grep "^| gpg: Signature made" actual && + grep "^| gpg: Good signature" actual +' + +test_expect_success GPG 'log --graph --show-signature for merged tag' ' + test_when_finished "git reset --hard && git checkout master" && + git checkout -b plain master && + echo aaa >bar && + git add bar && + git commit -m bar_commit && + git checkout -b tagged master && + echo bbb >baz && + git add baz && + git commit -m baz_commit && + git tag -s -m signed_tag_msg signed_tag && + git checkout plain && + git merge --no-ff -m msg signed_tag && + git log --graph --show-signature -n1 plain >actual && + grep "^|\\\ merged tag" actual && + grep "^| | gpg: Signature made" actual && + grep "^| | gpg: Good signature" actual +' + test_done diff --git a/t/t4204-patch-id.sh b/t/t4204-patch-id.sh index d2c930de87..baa9d3c82e 100755 --- a/t/t4204-patch-id.sh +++ b/t/t4204-patch-id.sh @@ -5,27 +5,44 @@ test_description='git patch-id' . ./test-lib.sh test_expect_success 'setup' ' - test_commit initial foo a && - test_commit first foo b && - git checkout -b same HEAD^ && - test_commit same-msg foo b && - git checkout -b notsame HEAD^ && - test_commit notsame-msg foo c + as="a a a a a a a a" && # eight a + test_write_lines $as >foo && + test_write_lines $as >bar && + git add foo bar && + git commit -a -m initial && + test_write_lines $as b >foo && + test_write_lines $as b >bar && + git commit -a -m first && + git checkout -b same master && + git commit --amend -m same-msg && + git checkout -b notsame master && + echo c >foo && + echo c >bar && + git commit --amend -a -m notsame-msg && + test_write_lines bar foo >bar-then-foo && + test_write_lines foo bar >foo-then-bar ' test_expect_success 'patch-id output is well-formed' ' - git log -p -1 | git patch-id > output && + git log -p -1 | git patch-id >output && grep "^[a-f0-9]\{40\} $(git rev-parse HEAD)$" output ' +#calculate patch id. Make sure output is not empty. calc_patch_id () { - git patch-id | - sed "s# .*##" > patch-id_"$1" + name="$1" + shift + git patch-id "$@" | + sed "s/ .*//" >patch-id_"$name" && + test_line_count -gt 0 patch-id_"$name" +} + +get_top_diff () { + git log -p -1 "$@" -O bar-then-foo -- } get_patch_id () { - git log -p -1 "$1" | git patch-id | - sed "s# .*##" > patch-id_"$1" + get_top_diff "$1" | calc_patch_id "$@" } test_expect_success 'patch-id detects equality' ' @@ -45,8 +62,8 @@ test_expect_success 'patch-id supports git-format-patch output' ' git checkout same && git format-patch -1 --stdout | calc_patch_id same && test_cmp patch-id_master patch-id_same && - set `git format-patch -1 --stdout | git patch-id` && - test "$2" = `git rev-parse HEAD` + set $(git format-patch -1 --stdout | git patch-id) && + test "$2" = $(git rev-parse HEAD) ' test_expect_success 'whitespace is irrelevant in footer' ' @@ -56,6 +73,69 @@ test_expect_success 'whitespace is irrelevant in footer' ' test_cmp patch-id_master patch-id_same ' +cmp_patch_id () { + if + test "$1" = "relevant" + then + ! test_cmp patch-id_"$2" patch-id_"$3" + else + test_cmp patch-id_"$2" patch-id_"$3" + fi +} + +test_patch_id_file_order () { + relevant="$1" + shift + name="order-${1}-$relevant" + shift + get_top_diff "master" | calc_patch_id "$name" "$@" && + git checkout same && + git format-patch -1 --stdout -O foo-then-bar | + calc_patch_id "ordered-$name" "$@" && + cmp_patch_id $relevant "$name" "ordered-$name" + +} + +# combined test for options: add more tests here to make them +# run with all options +test_patch_id () { + test_patch_id_file_order "$@" +} + +# small tests with detailed diagnostic for basic options. +test_expect_success 'file order is irrelevant with --stable' ' + test_patch_id_file_order irrelevant --stable --stable +' + +test_expect_success 'file order is relevant with --unstable' ' + test_patch_id_file_order relevant --unstable --unstable +' + +#Now test various option combinations. +test_expect_success 'default is unstable' ' + test_patch_id relevant default +' + +test_expect_success 'patchid.stable = true is stable' ' + test_config patchid.stable true && + test_patch_id irrelevant patchid.stable=true +' + +test_expect_success 'patchid.stable = false is unstable' ' + test_config patchid.stable false && + test_patch_id relevant patchid.stable=false +' + +test_expect_success '--unstable overrides patchid.stable = true' ' + test_config patchid.stable true && + test_patch_id relevant patchid.stable=true--unstable --unstable +' + +test_expect_success '--stable overrides patchid.stable = false' ' + test_config patchid.stable false && + test_patch_id irrelevant patchid.stable=false--stable --stable +' + test_expect_success 'patch-id supports git-format-patch MIME output' ' get_patch_id master && git checkout same && diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index 2a6278bb33..349c531989 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -7,6 +7,9 @@ test_description='Test pretty formats' . ./test-lib.sh +# Tested non-UTF-8 encoding +test_encoding="ISO8859-1" + sample_utf8_part=$(printf "f\303\244ng") commit_msg () { @@ -27,8 +30,8 @@ test_expect_success 'set up basic repos' ' >bar && git add foo && test_tick && - git config i18n.commitEncoding iso8859-1 && - git commit -m "$(commit_msg iso8859-1)" && + git config i18n.commitEncoding $test_encoding && + commit_msg $test_encoding | git commit -F - && git add bar && test_tick && git commit -m "add bar" && @@ -56,8 +59,8 @@ test_expect_success 'alias user-defined format' ' test_cmp expected actual ' -test_expect_success 'alias user-defined tformat with %s (iso8859-1 encoding)' ' - git config i18n.logOutputEncoding iso8859-1 && +test_expect_success 'alias user-defined tformat with %s (ISO8859-1 encoding)' ' + git config i18n.logOutputEncoding $test_encoding && git log --oneline >expected-s && git log --pretty="tformat:%h %s" >actual-s && git config --unset i18n.logOutputEncoding && @@ -141,9 +144,7 @@ test_expect_success 'setup more commits' ' ' test_expect_success 'left alignment formatting' ' - git log --pretty="format:%<(40)%s" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%<(40)%s" >actual && qz_to_tab_space <<EOF >expected && message two Z message one Z @@ -153,10 +154,19 @@ EOF test_cmp expected actual ' +test_expect_success 'left alignment formatting. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(40)%s" >actual && + qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected && +message two Z +message one Z +add bar Z +$(commit_msg) Z +EOF + test_cmp expected actual +' + test_expect_success 'left alignment formatting at the nth column' ' - git log --pretty="format:%h %<|(40)%s" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%h %<|(40)%s" >actual && qz_to_tab_space <<EOF >expected && $head1 message two Z $head2 message one Z @@ -166,10 +176,19 @@ EOF test_cmp expected actual ' +test_expect_success 'left alignment formatting at the nth column. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %<|(40)%s" >actual && + qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected && +$head1 message two Z +$head2 message one Z +$head3 add bar Z +$head4 $(commit_msg) Z +EOF + test_cmp expected actual +' + test_expect_success 'left alignment formatting with no padding' ' - git log --pretty="format:%<(1)%s" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%<(1)%s" >actual && cat <<EOF >expected && message two message one @@ -179,10 +198,19 @@ EOF test_cmp expected actual ' +test_expect_success 'left alignment formatting with no padding. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(1)%s" >actual && + cat <<EOF | iconv -f utf-8 -t $test_encoding >expected && +message two +message one +add bar +$(commit_msg) +EOF + test_cmp expected actual +' + test_expect_success 'left alignment formatting with trunc' ' - git log --pretty="format:%<(10,trunc)%s" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%<(10,trunc)%s" >actual && qz_to_tab_space <<EOF >expected && message .. message .. @@ -192,10 +220,19 @@ EOF test_cmp expected actual ' +test_expect_success 'left alignment formatting with trunc. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s" >actual && + qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected && +message .. +message .. +add bar Z +initial... +EOF + test_cmp expected actual +' + test_expect_success 'left alignment formatting with ltrunc' ' - git log --pretty="format:%<(10,ltrunc)%s" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%<(10,ltrunc)%s" >actual && qz_to_tab_space <<EOF >expected && ..sage two ..sage one @@ -205,10 +242,19 @@ EOF test_cmp expected actual ' +test_expect_success 'left alignment formatting with ltrunc. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,ltrunc)%s" >actual && + qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected && +..sage two +..sage one +add bar Z +..${sample_utf8_part}lich +EOF + test_cmp expected actual +' + test_expect_success 'left alignment formatting with mtrunc' ' - git log --pretty="format:%<(10,mtrunc)%s" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%<(10,mtrunc)%s" >actual && qz_to_tab_space <<EOF >expected && mess.. two mess.. one @@ -218,10 +264,19 @@ EOF test_cmp expected actual ' +test_expect_success 'left alignment formatting with mtrunc. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,mtrunc)%s" >actual && + qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected && +mess.. two +mess.. one +add bar Z +init..lich +EOF + test_cmp expected actual +' + test_expect_success 'right alignment formatting' ' - git log --pretty="format:%>(40)%s" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%>(40)%s" >actual && qz_to_tab_space <<EOF >expected && Z message two Z message one @@ -231,10 +286,19 @@ EOF test_cmp expected actual ' +test_expect_success 'right alignment formatting. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%>(40)%s" >actual && + qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected && +Z message two +Z message one +Z add bar +Z $(commit_msg) +EOF + test_cmp expected actual +' + test_expect_success 'right alignment formatting at the nth column' ' - git log --pretty="format:%h %>|(40)%s" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%h %>|(40)%s" >actual && qz_to_tab_space <<EOF >expected && $head1 message two $head2 message one @@ -244,10 +308,19 @@ EOF test_cmp expected actual ' +test_expect_success 'right alignment formatting at the nth column. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %>|(40)%s" >actual && + qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected && +$head1 message two +$head2 message one +$head3 add bar +$head4 $(commit_msg) +EOF + test_cmp expected actual +' + test_expect_success 'right alignment formatting with no padding' ' - git log --pretty="format:%>(1)%s" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%>(1)%s" >actual && cat <<EOF >expected && message two message one @@ -257,10 +330,19 @@ EOF test_cmp expected actual ' +test_expect_success 'right alignment formatting with no padding. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%>(1)%s" >actual && + cat <<EOF | iconv -f utf-8 -t $test_encoding >expected && +message two +message one +add bar +$(commit_msg) +EOF + test_cmp expected actual +' + test_expect_success 'center alignment formatting' ' - git log --pretty="format:%><(40)%s" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%><(40)%s" >actual && qz_to_tab_space <<EOF >expected && Z message two Z Z message one Z @@ -270,10 +352,18 @@ EOF test_cmp expected actual ' +test_expect_success 'center alignment formatting. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%><(40)%s" >actual && + qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected && +Z message two Z +Z message one Z +Z add bar Z +Z $(commit_msg) Z +EOF + test_cmp expected actual +' test_expect_success 'center alignment formatting at the nth column' ' - git log --pretty="format:%h %><|(40)%s" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%h %><|(40)%s" >actual && qz_to_tab_space <<EOF >expected && $head1 message two Z $head2 message one Z @@ -283,10 +373,19 @@ EOF test_cmp expected actual ' +test_expect_success 'center alignment formatting at the nth column. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %><|(40)%s" >actual && + qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected && +$head1 message two Z +$head2 message one Z +$head3 add bar Z +$head4 $(commit_msg) Z +EOF + test_cmp expected actual +' + test_expect_success 'center alignment formatting with no padding' ' - git log --pretty="format:%><(1)%s" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%><(1)%s" >actual && cat <<EOF >expected && message two message one @@ -296,11 +395,23 @@ EOF test_cmp expected actual ' +# save HEAD's SHA-1 digest (with no abbreviations) to use it below +# as far as the next test amends HEAD +old_head1=$(git rev-parse --verify HEAD~0) +test_expect_success 'center alignment formatting with no padding. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%><(1)%s" >actual && + cat <<EOF | iconv -f utf-8 -t $test_encoding >expected && +message two +message one +add bar +$(commit_msg) +EOF + test_cmp expected actual +' + test_expect_success 'left/right alignment formatting with stealing' ' git commit --amend -m short --author "long long long <long@me.com>" && - git log --pretty="format:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual && - # complete the incomplete line at the end - echo >>actual && + git log --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual && cat <<EOF >expected && short long long long message .. A U Thor @@ -309,6 +420,20 @@ initial... A U Thor EOF test_cmp expected actual ' +test_expect_success 'left/right alignment formatting with stealing. i18n.logOutputEncoding' ' + git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual && + cat <<EOF | iconv -f utf-8 -t $test_encoding >expected && +short long long long +message .. A U Thor +add bar A U Thor +initial... A U Thor +EOF + test_cmp expected actual +' + +# get new digests (with no abbreviations) +head1=$(git rev-parse --verify HEAD~0) && +head2=$(git rev-parse --verify HEAD~1) && test_expect_success 'log decoration properly follows tag chain' ' git tag -a tag1 -m tag1 && @@ -317,9 +442,9 @@ test_expect_success 'log decoration properly follows tag chain' ' git commit --amend -m shorter && git log --no-walk --tags --pretty="%H %d" --decorate=full >actual && cat <<EOF >expected && -6a908c10688b2503073c39c9ba26322c73902bb5 (tag: refs/tags/tag2) -9f716384d92283fb915a4eee5073f030638e05f9 (tag: refs/tags/message-one) -b87e4cccdb77336ea79d89224737be7ea8e95367 (tag: refs/tags/message-two) +$head1 (tag: refs/tags/tag2) +$head2 (tag: refs/tags/message-one) +$old_head1 (tag: refs/tags/message-two) EOF sort actual >actual1 && test_cmp expected actual1 diff --git a/t/t4210-log-i18n.sh b/t/t4210-log-i18n.sh index 52a74729ba..9110404e55 100755 --- a/t/t4210-log-i18n.sh +++ b/t/t4210-log-i18n.sh @@ -34,7 +34,7 @@ test_expect_success 'log --grep searches in log output encoding (utf8)' ' test_cmp expect actual ' -test_expect_success 'log --grep searches in log output encoding (latin1)' ' +test_expect_success NOT_MINGW 'log --grep searches in log output encoding (latin1)' ' cat >expect <<-\EOF && latin1 utf8 @@ -43,7 +43,7 @@ test_expect_success 'log --grep searches in log output encoding (latin1)' ' test_cmp expect actual ' -test_expect_success 'log --grep does not find non-reencoded values (utf8)' ' +test_expect_success NOT_MINGW 'log --grep does not find non-reencoded values (utf8)' ' >expect && git log --encoding=utf8 --format=%s --grep=$latin1_e >actual && test_cmp expect actual diff --git a/t/t4255-am-submodule.sh b/t/t4255-am-submodule.sh new file mode 100755 index 0000000000..8bde7dbb6d --- /dev/null +++ b/t/t4255-am-submodule.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +test_description='git am handling submodules' + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-submodule-update.sh + +am () { + git format-patch --stdout --ignore-submodules=dirty "..$1" | git am - +} + +test_submodule_switch "am" + +am_3way () { + git format-patch --stdout --ignore-submodules=dirty "..$1" | git am --3way - +} + +KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1 +test_submodule_switch "am_3way" + +test_done diff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh index 1cf0a4e103..7b8babd89b 100755 --- a/t/t5000-tar-tree.sh +++ b/t/t5000-tar-tree.sh @@ -72,7 +72,7 @@ check_tar() { for header in *.paxheader do data=${header%.paxheader}.data && - if test -h $data -o -e $data + if test -h $data || test -e $data then path=$(get_pax_header $header path) && if test -n "$path" @@ -119,14 +119,10 @@ test_expect_success \ 'echo ignore me >a/ignored && echo ignored export-ignore >.git/info/attributes' -test_expect_success \ - 'add files to repository' \ - 'find a -type f | xargs git update-index --add && - find a -type l | xargs git update-index --add && - treeid=`git write-tree` && - echo $treeid >treeid && - git update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \ - git commit-tree $treeid </dev/null)' +test_expect_success 'add files to repository' ' + git add a && + GIT_COMMITTER_DATE="2005-05-27 22:00" git commit -m initial +' test_expect_success 'setup export-subst' ' echo "substfile?" export-subst >>.git/info/attributes && @@ -164,7 +160,7 @@ check_tar with_olde-prefix olde- test_expect_success 'git archive on large files' ' test_config core.bigfilethreshold 1 && git archive HEAD >b3.tar && - test_cmp b.tar b3.tar + test_cmp_bin b.tar b3.tar ' test_expect_success \ @@ -173,15 +169,15 @@ test_expect_success \ test_expect_success \ 'git archive vs. the same in a bare repo' \ - 'test_cmp b.tar b3.tar' + 'test_cmp_bin b.tar b3.tar' test_expect_success 'git archive with --output' \ 'git archive --output=b4.tar HEAD && - test_cmp b.tar b4.tar' + test_cmp_bin b.tar b4.tar' test_expect_success 'git archive --remote' \ 'git archive --remote=. HEAD >b5.tar && - test_cmp b.tar b5.tar' + test_cmp_bin b.tar b5.tar' test_expect_success \ 'validate file modification time' \ @@ -198,7 +194,7 @@ test_expect_success \ test_expect_success 'git archive with --output, override inferred format' ' git archive --format=tar --output=d4.zip HEAD && - test_cmp b.tar d4.zip + test_cmp_bin b.tar d4.zip ' test_expect_success \ @@ -207,7 +203,7 @@ test_expect_success \ test_expect_success 'clients cannot access unreachable commits' ' test_commit unreachable && - sha1=`git rev-parse HEAD` && + sha1=$(git rev-parse HEAD) && git reset --hard HEAD^ && git archive $sha1 >remote.tar && test_must_fail git archive --remote=. $sha1 >remote.tar @@ -215,7 +211,7 @@ test_expect_success 'clients cannot access unreachable commits' ' test_expect_success 'upload-archive can allow unreachable commits' ' test_commit unreachable1 && - sha1=`git rev-parse HEAD` && + sha1=$(git rev-parse HEAD) && git reset --hard HEAD^ && git archive $sha1 >remote.tar && test_config uploadarchive.allowUnreachable true && @@ -244,34 +240,34 @@ test_expect_success 'archive --list shows only enabled remote filters' ' test_expect_success 'invoke tar filter by format' ' git archive --format=tar.foo HEAD >config.tar.foo && tr ab ba <config.tar.foo >config.tar && - test_cmp b.tar config.tar && + test_cmp_bin b.tar config.tar && git archive --format=bar HEAD >config.bar && tr ab ba <config.bar >config.tar && - test_cmp b.tar config.tar + test_cmp_bin b.tar config.tar ' test_expect_success 'invoke tar filter by extension' ' git archive -o config-implicit.tar.foo HEAD && - test_cmp config.tar.foo config-implicit.tar.foo && + test_cmp_bin config.tar.foo config-implicit.tar.foo && git archive -o config-implicit.bar HEAD && - test_cmp config.tar.foo config-implicit.bar + test_cmp_bin config.tar.foo config-implicit.bar ' test_expect_success 'default output format remains tar' ' git archive -o config-implicit.baz HEAD && - test_cmp b.tar config-implicit.baz + test_cmp_bin b.tar config-implicit.baz ' test_expect_success 'extension matching requires dot' ' git archive -o config-implicittar.foo HEAD && - test_cmp b.tar config-implicittar.foo + test_cmp_bin b.tar config-implicittar.foo ' test_expect_success 'only enabled filters are available remotely' ' test_must_fail git archive --remote=. --format=tar.foo HEAD \ >remote.tar.foo && git archive --remote=. --format=bar >remote.bar HEAD && - test_cmp remote.bar config.bar + test_cmp_bin remote.bar config.bar ' test_expect_success GZIP 'git archive --format=tgz' ' @@ -280,27 +276,27 @@ test_expect_success GZIP 'git archive --format=tgz' ' test_expect_success GZIP 'git archive --format=tar.gz' ' git archive --format=tar.gz HEAD >j1.tar.gz && - test_cmp j.tgz j1.tar.gz + test_cmp_bin j.tgz j1.tar.gz ' test_expect_success GZIP 'infer tgz from .tgz filename' ' git archive --output=j2.tgz HEAD && - test_cmp j.tgz j2.tgz + test_cmp_bin j.tgz j2.tgz ' test_expect_success GZIP 'infer tgz from .tar.gz filename' ' git archive --output=j3.tar.gz HEAD && - test_cmp j.tgz j3.tar.gz + test_cmp_bin j.tgz j3.tar.gz ' test_expect_success GZIP 'extract tgz file' ' gzip -d -c <j.tgz >j.tar && - test_cmp b.tar j.tar + test_cmp_bin b.tar j.tar ' test_expect_success GZIP 'remote tar.gz is allowed by default' ' git archive --remote=. --format=tar.gz HEAD >remote.tar.gz && - test_cmp j.tgz remote.tar.gz + test_cmp_bin j.tgz remote.tar.gz ' test_expect_success GZIP 'remote tar.gz can be disabled' ' diff --git a/t/t5001-archive-attr.sh b/t/t5001-archive-attr.sh index 51dedab29b..b04d955bfa 100755 --- a/t/t5001-archive-attr.sh +++ b/t/t5001-archive-attr.sh @@ -68,7 +68,7 @@ test_expect_missing worktree2/ignored-by-worktree test_expect_success 'git archive vs. bare' ' (cd bare && git archive HEAD) >bare-archive.tar && - test_cmp archive.tar bare-archive.tar + test_cmp_bin archive.tar bare-archive.tar ' test_expect_success 'git archive with worktree attributes, bare' ' diff --git a/t/t5003-archive-zip.sh b/t/t5003-archive-zip.sh index c72f71eb18..c929db5633 100755 --- a/t/t5003-archive-zip.sh +++ b/t/t5003-archive-zip.sh @@ -61,14 +61,10 @@ test_expect_success \ 'echo ignore me >a/ignored && echo ignored export-ignore >.git/info/attributes' -test_expect_success \ - 'add files to repository' \ - 'find a -type f | xargs git update-index --add && - find a -type l | xargs git update-index --add && - treeid=`git write-tree` && - echo $treeid >treeid && - git update-ref HEAD $(TZ=GMT GIT_COMMITTER_DATE="2005-05-27 22:00:00" \ - git commit-tree $treeid </dev/null)' +test_expect_success 'add files to repository' ' + git add a && + GIT_COMMITTER_DATE="2005-05-27 22:00" git commit -m initial +' test_expect_success 'setup export-subst' ' echo "substfile?" export-subst >>.git/info/attributes && @@ -97,15 +93,15 @@ test_expect_success \ test_expect_success \ 'git archive --format=zip vs. the same in a bare repo' \ - 'test_cmp d.zip d1.zip' + 'test_cmp_bin d.zip d1.zip' test_expect_success 'git archive --format=zip with --output' \ 'git archive --format=zip --output=d2.zip HEAD && - test_cmp d.zip d2.zip' + test_cmp_bin d.zip d2.zip' test_expect_success 'git archive with --output, inferring format' ' git archive --output=d3.zip HEAD && - test_cmp d.zip d3.zip + test_cmp_bin d.zip d3.zip ' test_expect_success \ diff --git a/t/t5004-archive-corner-cases.sh b/t/t5004-archive-corner-cases.sh index 67f3b54bed..305bcac6b7 100755 --- a/t/t5004-archive-corner-cases.sh +++ b/t/t5004-archive-corner-cases.sh @@ -45,7 +45,7 @@ test_expect_success HEADER_ONLY_TAR_OK 'tar archive of commit with empty tree' ' test_expect_success 'tar archive of empty tree is empty' ' git archive --format=tar HEAD: >empty.tar && perl -e "print \"\\0\" x 10240" >10knuls.tar && - test_cmp 10knuls.tar empty.tar + test_cmp_bin 10knuls.tar empty.tar ' test_expect_success 'tar archive of empty tree with prefix' ' diff --git a/t/t5150-request-pull.sh b/t/t5150-request-pull.sh index 75d6b3843a..82c33b88e7 100755 --- a/t/t5150-request-pull.sh +++ b/t/t5150-request-pull.sh @@ -223,7 +223,13 @@ test_expect_success 'pull request format' ' git request-pull initial "$downstream_url" tags/full:refs/tags/full ) >request && sed -nf fuzz.sed <request >request.fuzzy && - test_i18ncmp expect request.fuzzy + test_i18ncmp expect request.fuzzy && + + ( + cd local && + git request-pull initial "$downstream_url" full + ) >request && + grep " tags/full\$" request ' test_expect_success 'request-pull ignores OPTIONS_KEEPDASHDASH poison' ' diff --git a/t/t5310-pack-bitmaps.sh b/t/t5310-pack-bitmaps.sh index f4f02ba918..0580258c91 100755 --- a/t/t5310-pack-bitmaps.sh +++ b/t/t5310-pack-bitmaps.sh @@ -18,7 +18,7 @@ test_expect_success 'setup repo with moderate-sized history' ' git checkout master && blob=$(echo tagged-blob | git hash-object -w --stdin) && git tag tagged-blob $blob && - git config pack.writebitmaps true && + git config repack.writebitmaps true && git config pack.writebitmaphashcache true ' diff --git a/t/t5403-post-checkout-hook.sh b/t/t5403-post-checkout-hook.sh index 1753ef2b91..fc898c9eac 100755 --- a/t/t5403-post-checkout-hook.sh +++ b/t/t5403-post-checkout-hook.sh @@ -39,7 +39,7 @@ test_expect_success 'post-checkout receives the right arguments with HEAD unchan old=$(awk "{print \$1}" clone1/.git/post-checkout.args) && new=$(awk "{print \$2}" clone1/.git/post-checkout.args) && flag=$(awk "{print \$3}" clone1/.git/post-checkout.args) && - test $old = $new -a $flag = 1 + test $old = $new && test $flag = 1 ' test_expect_success 'post-checkout runs as expected ' ' @@ -52,7 +52,7 @@ test_expect_success 'post-checkout args are correct with git checkout -b ' ' old=$(awk "{print \$1}" clone1/.git/post-checkout.args) && new=$(awk "{print \$2}" clone1/.git/post-checkout.args) && flag=$(awk "{print \$3}" clone1/.git/post-checkout.args) && - test $old = $new -a $flag = 1 + test $old = $new && test $flag = 1 ' test_expect_success 'post-checkout receives the right args with HEAD changed ' ' @@ -60,7 +60,7 @@ test_expect_success 'post-checkout receives the right args with HEAD changed ' ' old=$(awk "{print \$1}" clone2/.git/post-checkout.args) && new=$(awk "{print \$2}" clone2/.git/post-checkout.args) && flag=$(awk "{print \$3}" clone2/.git/post-checkout.args) && - test $old != $new -a $flag = 1 + test $old != $new && test $flag = 1 ' test_expect_success 'post-checkout receives the right args when not switching branches ' ' @@ -68,7 +68,7 @@ test_expect_success 'post-checkout receives the right args when not switching br old=$(awk "{print \$1}" clone2/.git/post-checkout.args) && new=$(awk "{print \$2}" clone2/.git/post-checkout.args) && flag=$(awk "{print \$3}" clone2/.git/post-checkout.args) && - test $old = $new -a $flag = 0 + test $old = $new && test $flag = 0 ' if test "$(git config --bool core.filemode)" = true; then diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh index 29d59ef9fa..d78f3201f4 100755 --- a/t/t5510-fetch.sh +++ b/t/t5510-fetch.sh @@ -447,6 +447,43 @@ test_expect_success 'explicit pull should update tracking' ' ) ' +test_expect_success 'explicit --refmap is allowed only with command-line refspec' ' + cd "$D" && + ( + cd three && + test_must_fail git fetch --refmap="*:refs/remotes/none/*" + ) +' + +test_expect_success 'explicit --refmap option overrides remote.*.fetch' ' + cd "$D" && + git branch -f side && + ( + cd three && + git update-ref refs/remotes/origin/master base-origin-master && + o=$(git rev-parse --verify refs/remotes/origin/master) && + git fetch --refmap="refs/heads/*:refs/remotes/other/*" origin master && + n=$(git rev-parse --verify refs/remotes/origin/master) && + test "$o" = "$n" && + test_must_fail git rev-parse --verify refs/remotes/origin/side && + git rev-parse --verify refs/remotes/other/master + ) +' + +test_expect_success 'explicitly empty --refmap option disables remote.*.fetch' ' + cd "$D" && + git branch -f side && + ( + cd three && + git update-ref refs/remotes/origin/master base-origin-master && + o=$(git rev-parse --verify refs/remotes/origin/master) && + git fetch --refmap="" origin master && + n=$(git rev-parse --verify refs/remotes/origin/master) && + test "$o" = "$n" && + test_must_fail git rev-parse --verify refs/remotes/origin/side + ) +' + test_expect_success 'configured fetch updates tracking' ' cd "$D" && diff --git a/t/t5511-refspec.sh b/t/t5511-refspec.sh index c28932216b..de6db86ccf 100755 --- a/t/t5511-refspec.sh +++ b/t/t5511-refspec.sh @@ -5,7 +5,6 @@ test_description='refspec parsing' . ./test-lib.sh test_refspec () { - kind=$1 refspec=$2 expect=$3 git config remote.frotz.url "." && git config --remove-section remote.frotz && @@ -84,4 +83,9 @@ test_refspec push 'refs/heads/*/*/for-linus:refs/remotes/mine/*' invalid test_refspec fetch 'refs/heads/*/for-linus:refs/remotes/mine/*' test_refspec push 'refs/heads/*/for-linus:refs/remotes/mine/*' +good=$(printf '\303\204') +test_refspec fetch "refs/heads/${good}" +bad=$(printf '\011tab') +test_refspec fetch "refs/heads/${bad}" invalid + test_done diff --git a/t/t5537-fetch-shallow.sh b/t/t5537-fetch-shallow.sh index be951a4679..a980574682 100755 --- a/t/t5537-fetch-shallow.sh +++ b/t/t5537-fetch-shallow.sh @@ -173,33 +173,6 @@ EOF ) ' -if test -n "$NO_CURL" -o -z "$GIT_TEST_HTTPD"; then - say 'skipping remaining tests, git built without http support' - test_done -fi - -LIB_HTTPD_PORT=${LIB_HTTPD_PORT-'5537'} -. "$TEST_DIRECTORY"/lib-httpd.sh -start_httpd - -test_expect_success 'clone http repository' ' - git clone --bare --no-local shallow "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && - git clone $HTTPD_URL/smart/repo.git clone && - ( - cd clone && - git fsck && - git log --format=%s origin/master >actual && - cat <<EOF >expect && -7 -6 -5 -4 -3 -EOF - test_cmp expect actual - ) -' - test_expect_success POSIXPERM,SANITY 'shallow fetch from a read-only repo' ' cp -R .git read-only.git && find read-only.git -print | xargs chmod -w && @@ -213,5 +186,4 @@ EOF test_cmp expect actual ' -stop_httpd test_done diff --git a/t/t5538-push-shallow.sh b/t/t5538-push-shallow.sh index 8e54ac5746..ceee95b8a4 100755 --- a/t/t5538-push-shallow.sh +++ b/t/t5538-push-shallow.sh @@ -120,63 +120,4 @@ EOF git cat-file blob `echo 1|git hash-object --stdin` >/dev/null ) ' - -if test -n "$NO_CURL" -o -z "$GIT_TEST_HTTPD"; then - say 'skipping remaining tests, git built without http support' - test_done -fi - -. "$TEST_DIRECTORY"/lib-httpd.sh -start_httpd - -test_expect_success 'push to shallow repo via http' ' - git clone --bare --no-local shallow "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && - ( - cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && - git config http.receivepack true - ) && - ( - cd full && - commit 9 && - git push $HTTPD_URL/smart/repo.git +master:refs/remotes/top/master - ) && - ( - cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && - git fsck && - git log --format=%s top/master >actual && - cat <<EOF >expect && -9 -4 -3 -EOF - test_cmp expect actual - ) -' - -test_expect_success 'push from shallow repo via http' ' - mv "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" shallow-upstream.git && - git clone --bare --no-local full "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && - ( - cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && - git config http.receivepack true - ) && - commit 10 && - git push $HTTPD_URL/smart/repo.git +master:refs/remotes/top/master && - ( - cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && - git fsck && - git log --format=%s top/master >actual && - cat <<EOF >expect && -10 -1 -4 -3 -2 -1 -EOF - test_cmp expect actual - ) -' - -stop_httpd test_done diff --git a/t/t5539-fetch-http-shallow.sh b/t/t5539-fetch-http-shallow.sh index 94553e1039..b46118846c 100755 --- a/t/t5539-fetch-http-shallow.sh +++ b/t/t5539-fetch-http-shallow.sh @@ -54,6 +54,7 @@ EOF test_expect_success 'no shallow lines after receiving ACK ready' ' ( cd shallow && + test_tick && for i in $(test_seq 15) do git checkout --orphan unrelated$i && diff --git a/t/t5542-push-http-shallow.sh b/t/t5542-push-http-shallow.sh new file mode 100755 index 0000000000..2a691e09eb --- /dev/null +++ b/t/t5542-push-http-shallow.sh @@ -0,0 +1,100 @@ +#!/bin/sh + +test_description='push from/to a shallow clone over http' + +. ./test-lib.sh + +if test -n "$NO_CURL"; then + say 'skipping test, git built without http support' + test_done +fi + +. "$TEST_DIRECTORY"/lib-httpd.sh +start_httpd + +commit() { + echo "$1" >tracked && + git add tracked && + git commit -m "$1" +} + +test_expect_success 'setup' ' + git config --global transfer.fsckObjects true && + commit 1 && + commit 2 && + commit 3 && + commit 4 && + git clone . full && + ( + git init full-abc && + cd full-abc && + commit a && + commit b && + commit c + ) && + git clone --no-local --depth=2 .git shallow && + git --git-dir=shallow/.git log --format=%s >actual && + cat <<EOF >expect && +4 +3 +EOF + test_cmp expect actual && + git clone --no-local --depth=2 full-abc/.git shallow2 && + git --git-dir=shallow2/.git log --format=%s >actual && + cat <<EOF >expect && +c +b +EOF + test_cmp expect actual +' + +test_expect_success 'push to shallow repo via http' ' + git clone --bare --no-local shallow "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && + ( + cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && + git config http.receivepack true + ) && + ( + cd full && + commit 9 && + git push $HTTPD_URL/smart/repo.git +master:refs/remotes/top/master + ) && + ( + cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && + git fsck && + git log --format=%s top/master >actual && + cat <<EOF >expect && +9 +4 +3 +EOF + test_cmp expect actual + ) +' + +test_expect_success 'push from shallow repo via http' ' + mv "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" shallow-upstream.git && + git clone --bare --no-local full "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && + ( + cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && + git config http.receivepack true + ) && + commit 10 && + git push $HTTPD_URL/smart/repo.git +master:refs/remotes/top/master && + ( + cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && + git fsck && + git log --format=%s top/master >actual && + cat <<EOF >expect && +10 +4 +3 +2 +1 +EOF + test_cmp expect actual + ) +' + +stop_httpd +test_done diff --git a/t/t5550-http-fetch-dumb.sh b/t/t5550-http-fetch-dumb.sh index 1a3a2b6c1a..ac71418a1b 100755 --- a/t/t5550-http-fetch-dumb.sh +++ b/t/t5550-http-fetch-dumb.sh @@ -171,5 +171,30 @@ test_expect_success 'did not use upload-pack service' ' test_cmp exp act ' +test_expect_success 'git client shows text/plain errors' ' + test_must_fail git clone "$HTTPD_URL/error/text" 2>stderr && + grep "this is the error message" stderr +' + +test_expect_success 'git client does not show html errors' ' + test_must_fail git clone "$HTTPD_URL/error/html" 2>stderr && + ! grep "this is the error message" stderr +' + +test_expect_success 'git client shows text/plain with a charset' ' + test_must_fail git clone "$HTTPD_URL/error/charset" 2>stderr && + grep "this is the error message" stderr +' + +test_expect_success 'http error messages are reencoded' ' + test_must_fail git clone "$HTTPD_URL/error/utf16" 2>stderr && + grep "this is the error message" stderr +' + +test_expect_success 'reencoding is robust to whitespace oddities' ' + test_must_fail git clone "$HTTPD_URL/error/odd-spacing" 2>stderr && + grep "this is the error message" stderr +' + stop_httpd test_done diff --git a/t/t5551-http-fetch-smart.sh b/t/t5551-http-fetch-smart.sh index e07eaf35f1..6cbc12d9a7 100755 --- a/t/t5551-http-fetch-smart.sh +++ b/t/t5551-http-fetch-smart.sh @@ -213,8 +213,6 @@ test_expect_success 'cookies stored in http.cookiefile when http.savecookies set test_cmp expect_cookies.txt cookies_tail.txt ' -test -n "$GIT_TEST_LONG" && test_set_prereq EXPENSIVE - test_expect_success EXPENSIVE 'create 50,000 tags in the repo' ' ( cd "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && @@ -240,8 +238,7 @@ test_expect_success EXPENSIVE 'create 50,000 tags in the repo' ' ' test_expect_success EXPENSIVE 'clone the 50,000 tag repo to check OS command line overflow' ' - git clone $HTTPD_URL/smart/repo.git too-many-refs 2>err && - test_line_count = 0 err && + git clone $HTTPD_URL/smart/repo.git too-many-refs && ( cd too-many-refs && test $(git for-each-ref refs/tags | wc -l) = 50000 diff --git a/t/t5560-http-backend-noserver.sh b/t/t5560-http-backend-noserver.sh index 9be9ae3436..aa73eeaef8 100755 --- a/t/t5560-http-backend-noserver.sh +++ b/t/t5560-http-backend-noserver.sh @@ -5,12 +5,16 @@ test_description='test git-http-backend-noserver' HTTPD_DOCUMENT_ROOT_PATH="$TRASH_DIRECTORY" -test_have_prereq GREP_STRIPS_CR && export GREP_OPTIONS=-U +if test_have_prereq GREP_STRIPS_CR +then + GREP_OPTIONS=-U + export GREP_OPTIONS +fi run_backend() { echo "$2" | - QUERY_STRING="${1#*\?}" \ - PATH_TRANSLATED="$HTTPD_DOCUMENT_ROOT_PATH/${1%%\?*}" \ + QUERY_STRING="${1#*[?]}" \ + PATH_TRANSLATED="$HTTPD_DOCUMENT_ROOT_PATH/${1%%[?]*}" \ git http-backend >act.out 2>act.err } diff --git a/t/t5572-pull-submodule.sh b/t/t5572-pull-submodule.sh new file mode 100755 index 0000000000..accfa5cc0c --- /dev/null +++ b/t/t5572-pull-submodule.sh @@ -0,0 +1,45 @@ +#!/bin/sh + +test_description='pull can handle submodules' + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-submodule-update.sh + +reset_branch_to_HEAD () { + git branch -D "$1" && + git checkout -b "$1" HEAD && + git branch --set-upstream-to="origin/$1" "$1" +} + +git_pull () { + reset_branch_to_HEAD "$1" && + git pull +} + +# pulls without conflicts +test_submodule_switch "git_pull" + +git_pull_ff () { + reset_branch_to_HEAD "$1" && + git pull --ff +} + +test_submodule_switch "git_pull_ff" + +git_pull_ff_only () { + reset_branch_to_HEAD "$1" && + git pull --ff-only +} + +test_submodule_switch "git_pull_ff_only" + +git_pull_noff () { + reset_branch_to_HEAD "$1" && + git pull --no-ff +} + +KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1 +KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1 +test_submodule_switch "git_pull_noff" + +test_done diff --git a/t/t5801-remote-helpers.sh b/t/t5801-remote-helpers.sh index 25fd2e7f46..2419407546 100755 --- a/t/t5801-remote-helpers.sh +++ b/t/t5801-remote-helpers.sh @@ -87,13 +87,29 @@ test_expect_success 'push new branch by name' ' compare_refs local HEAD server refs/heads/new-name ' -test_expect_failure 'push new branch with old:new refspec' ' +test_expect_success 'push new branch with old:new refspec' ' (cd local && git push origin new-name:new-refspec ) && compare_refs local HEAD server refs/heads/new-refspec ' +test_expect_success 'push new branch with HEAD:new refspec' ' + (cd local && + git checkout new-name + git push origin HEAD:new-refspec-2 + ) && + compare_refs local HEAD server refs/heads/new-refspec-2 +' + +test_expect_success 'push delete branch' ' + (cd local && + git push origin :new-name + ) && + test_must_fail git --git-dir="server/.git" \ + rev-parse --verify refs/heads/new-name +' + test_expect_success 'forced push' ' (cd local && git checkout -b force-test && @@ -212,19 +228,30 @@ test_expect_success 'push update refs failure' ' echo "update fail" >>file && git commit -a -m "update fail" && git rev-parse --verify testgit/origin/heads/update >expect && - GIT_REMOTE_TESTGIT_PUSH_ERROR="non-fast forward" && - export GIT_REMOTE_TESTGIT_PUSH_ERROR && - test_expect_code 1 git push origin update && + test_expect_code 1 env GIT_REMOTE_TESTGIT_FAILURE="non-fast forward" \ + git push origin update && git rev-parse --verify testgit/origin/heads/update >actual && test_cmp expect actual ) ' +clean_mark () { + cut -f 2 -d ' ' "$1" | + git cat-file --batch-check | + grep commit | + sort >$(basename "$1") +} + +cmp_marks () { + test_when_finished "rm -rf git.marks testgit.marks" && + clean_mark ".git/testgit/$1/git.marks" && + clean_mark ".git/testgit/$1/testgit.marks" && + test_cmp git.marks testgit.marks +} + test_expect_success 'proper failure checks for fetching' ' - (GIT_REMOTE_TESTGIT_FAILURE=1 && - export GIT_REMOTE_TESTGIT_FAILURE && - cd local && - test_must_fail git fetch 2> error && + (cd local && + test_must_fail env GIT_REMOTE_TESTGIT_FAILURE=1 git fetch 2>error && cat error && grep -q "Error while running fast-import" error ) @@ -232,7 +259,11 @@ test_expect_success 'proper failure checks for fetching' ' test_expect_success 'proper failure checks for pushing' ' (cd local && - test_must_fail env GIT_REMOTE_TESTGIT_FAILURE=1 git push --all + git checkout -b crash master && + echo crash >>file && + git commit -a -m crash && + test_must_fail env GIT_REMOTE_TESTGIT_FAILURE=1 git push --all && + cmp_marks origin ) ' diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh index 9d9d9de08e..a02a45afd2 100755 --- a/t/t6006-rev-list-format.sh +++ b/t/t6006-rev-list-format.sh @@ -9,26 +9,39 @@ test_description='git rev-list --pretty=format test' . "$TEST_DIRECTORY"/lib-terminal.sh test_tick +# Tested non-UTF-8 encoding +test_encoding="ISO8859-1" + # String "added" in German # (translated with Google Translate), # encoded in UTF-8, used as a commit log message below. -added=$(printf "added (hinzugef\303\274gt) foo") -added_iso88591=$(echo "$added" | iconv -f utf-8 -t iso8859-1) +added_utf8_part=$(printf "\303\274") +added_utf8_part_iso88591=$(echo "$added_utf8_part" | iconv -f utf-8 -t $test_encoding) +added=$(printf "added (hinzugef${added_utf8_part}gt) foo") +added_iso88591=$(echo "$added" | iconv -f utf-8 -t $test_encoding) # same but "changed" -changed=$(printf "changed (ge\303\244ndert) foo") -changed_iso88591=$(echo "$changed" | iconv -f utf-8 -t iso8859-1) +changed_utf8_part=$(printf "\303\244") +changed_utf8_part_iso88591=$(echo "$changed_utf8_part" | iconv -f utf-8 -t $test_encoding) +changed=$(printf "changed (ge${changed_utf8_part}ndert) foo") +changed_iso88591=$(echo "$changed" | iconv -f utf-8 -t $test_encoding) + +# Count of char to truncate +# Number is chosen so, that non-ACSII characters +# (see $added_utf8_part and $changed_utf8_part) +# fall into truncated parts of appropriate words both from left and right +truncate_count=20 test_expect_success 'setup' ' : >foo && git add foo && - git config i18n.commitEncoding iso8859-1 && - git commit -m "$added_iso88591" && + git config i18n.commitEncoding $test_encoding && + echo "$added_iso88591" | git commit -F - && head1=$(git rev-parse --verify HEAD) && head1_short=$(git rev-parse --verify --short $head1) && tree1=$(git rev-parse --verify HEAD:) && tree1_short=$(git rev-parse --verify --short $tree1) && echo "$changed" > foo && - git commit -a -m "$changed_iso88591" && + echo "$changed_iso88591" | git commit -a -F - && head2=$(git rev-parse --verify HEAD) && head2_short=$(git rev-parse --verify --short $head2) && tree2=$(git rev-parse --verify HEAD:) && @@ -124,9 +137,9 @@ EOF test_format encoding %e <<EOF commit $head2 -iso8859-1 +$test_encoding commit $head1 -iso8859-1 +$test_encoding EOF test_format subject %s <<EOF @@ -136,6 +149,13 @@ commit $head1 $added EOF +test_format subject-truncated "%<($truncate_count,trunc)%s" <<EOF +commit $head2 +changed (ge${changed_utf8_part}ndert).. +commit $head1 +added (hinzugef${added_utf8_part}gt.. +EOF + test_format body %b <<EOF commit $head2 commit $head1 @@ -203,16 +223,16 @@ test_expect_success '%C(auto) respects --color=auto (stdout not tty)' ' ) ' -iconv -f utf-8 -t iso8859-1 > commit-msg <<EOF +iconv -f utf-8 -t $test_encoding > commit-msg <<EOF Test printing of complex bodies This commit message is much longer than the others, -and it will be encoded in iso8859-1. We should therefore -include an iso8859 character: ¡bueno! +and it will be encoded in $test_encoding. We should therefore +include an ISO8859 character: ¡bueno! EOF test_expect_success 'setup complex body' ' - git config i18n.commitencoding iso8859-1 && + git config i18n.commitencoding $test_encoding && echo change2 >foo && git commit -a -F commit-msg && head3=$(git rev-parse --verify HEAD) && head3_short=$(git rev-parse --short $head3) @@ -220,11 +240,11 @@ test_expect_success 'setup complex body' ' test_format complex-encoding %e <<EOF commit $head3 -iso8859-1 +$test_encoding commit $head2 -iso8859-1 +$test_encoding commit $head1 -iso8859-1 +$test_encoding EOF test_format complex-subject %s <<EOF @@ -236,20 +256,47 @@ commit $head1 $added_iso88591 EOF +test_format complex-subject-trunc "%<($truncate_count,trunc)%s" <<EOF +commit $head3 +Test printing of c.. +commit $head2 +changed (ge${changed_utf8_part_iso88591}ndert).. +commit $head1 +added (hinzugef${added_utf8_part_iso88591}gt.. +EOF + +test_format complex-subject-mtrunc "%<($truncate_count,mtrunc)%s" <<EOF +commit $head3 +Test prin..ex bodies +commit $head2 +changed (..dert) foo +commit $head1 +added (hi..f${added_utf8_part_iso88591}gt) foo +EOF + +test_format complex-subject-ltrunc "%<($truncate_count,ltrunc)%s" <<EOF +commit $head3 +.. of complex bodies +commit $head2 +..ged (ge${changed_utf8_part_iso88591}ndert) foo +commit $head1 +.. (hinzugef${added_utf8_part_iso88591}gt) foo +EOF + test_expect_success 'prepare expected messages (for test %b)' ' cat <<-EOF >expected.utf-8 && commit $head3 This commit message is much longer than the others, - and it will be encoded in iso8859-1. We should therefore - include an iso8859 character: ¡bueno! + and it will be encoded in $test_encoding. We should therefore + include an ISO8859 character: ¡bueno! commit $head2 commit $head1 EOF - iconv -f utf-8 -t iso8859-1 expected.utf-8 >expected.iso8859-1 + iconv -f utf-8 -t $test_encoding expected.utf-8 >expected.ISO8859-1 ' -test_format complex-body %b <expected.iso8859-1 +test_format complex-body %b <expected.ISO8859-1 # Git uses i18n.commitEncoding if no i18n.logOutputEncoding set # so unset i18n.commitEncoding to test encoding conversion @@ -264,6 +311,33 @@ commit $head1 $added EOF +test_format complex-subject-commitencoding-unset-trunc "%<($truncate_count,trunc)%s" <<EOF +commit $head3 +Test printing of c.. +commit $head2 +changed (ge${changed_utf8_part}ndert).. +commit $head1 +added (hinzugef${added_utf8_part}gt.. +EOF + +test_format complex-subject-commitencoding-unset-mtrunc "%<($truncate_count,mtrunc)%s" <<EOF +commit $head3 +Test prin..ex bodies +commit $head2 +changed (..dert) foo +commit $head1 +added (hi..f${added_utf8_part}gt) foo +EOF + +test_format complex-subject-commitencoding-unset-ltrunc "%<($truncate_count,ltrunc)%s" <<EOF +commit $head3 +.. of complex bodies +commit $head2 +..ged (ge${changed_utf8_part}ndert) foo +commit $head1 +.. (hinzugef${added_utf8_part}gt) foo +EOF + test_format complex-body-commitencoding-unset %b <expected.utf-8 test_expect_success '%x00 shows NUL' ' @@ -394,4 +468,10 @@ test_expect_success 'single-character name is parsed correctly' ' test_cmp expect actual ' +test_expect_success 'unused %G placeholders are passed through' ' + echo "%GX %G" >expect && + git log -1 --format="%GX %G" >actual && + test_cmp expect actual +' + test_done diff --git a/t/t6023-merge-file.sh b/t/t6023-merge-file.sh index 432f086c06..3758961765 100755 --- a/t/t6023-merge-file.sh +++ b/t/t6023-merge-file.sh @@ -77,12 +77,29 @@ test_expect_success "merge without conflict (--quiet)" \ "git merge-file --quiet test.txt orig.txt new2.txt" cp new1.txt test2.txt -test_expect_success "merge without conflict (missing LF at EOF)" \ - "git merge-file test2.txt orig.txt new2.txt" +test_expect_failure "merge without conflict (missing LF at EOF)" \ + "git merge-file test2.txt orig.txt new4.txt" -test_expect_success "merge result added missing LF" \ +test_expect_failure "merge result added missing LF" \ "test_cmp test.txt test2.txt" +cp new4.txt test3.txt +test_expect_success "merge without conflict (missing LF at EOF, away from change in the other file)" \ + "git merge-file --quiet test3.txt new2.txt new3.txt" + +cat > expect.txt << EOF +DOMINUS regit me, +et nihil mihi deerit. +In loco pascuae ibi me collocavit, +super aquam refectionis educavit me; +animam meam convertit, +deduxit me super semitas jusitiae, +EOF +printf "propter nomen suum." >> expect.txt + +test_expect_success "merge does not add LF away of change" \ + "test_cmp test3.txt expect.txt" + cp test.txt backup.txt test_expect_success "merge with conflicts" \ "test_must_fail git merge-file test.txt orig.txt new3.txt" @@ -107,6 +124,55 @@ EOF test_expect_success "expected conflict markers" "test_cmp test.txt expect.txt" cp backup.txt test.txt + +cat > expect.txt << EOF +Dominus regit me, et nihil mihi deerit. +In loco pascuae ibi me collocavit, +super aquam refectionis educavit me; +animam meam convertit, +deduxit me super semitas jusitiae, +propter nomen suum. +Nam et si ambulavero in medio umbrae mortis, +non timebo mala, quoniam tu mecum es: +virga tua et baculus tuus ipsa me consolata sunt. +EOF +test_expect_success "merge conflicting with --ours" \ + "git merge-file --ours test.txt orig.txt new3.txt && test_cmp test.txt expect.txt" +cp backup.txt test.txt + +cat > expect.txt << EOF +DOMINUS regit me, +et nihil mihi deerit. +In loco pascuae ibi me collocavit, +super aquam refectionis educavit me; +animam meam convertit, +deduxit me super semitas jusitiae, +propter nomen suum. +Nam et si ambulavero in medio umbrae mortis, +non timebo mala, quoniam tu mecum es: +virga tua et baculus tuus ipsa me consolata sunt. +EOF +test_expect_success "merge conflicting with --theirs" \ + "git merge-file --theirs test.txt orig.txt new3.txt && test_cmp test.txt expect.txt" +cp backup.txt test.txt + +cat > expect.txt << EOF +Dominus regit me, et nihil mihi deerit. +DOMINUS regit me, +et nihil mihi deerit. +In loco pascuae ibi me collocavit, +super aquam refectionis educavit me; +animam meam convertit, +deduxit me super semitas jusitiae, +propter nomen suum. +Nam et si ambulavero in medio umbrae mortis, +non timebo mala, quoniam tu mecum es: +virga tua et baculus tuus ipsa me consolata sunt. +EOF +test_expect_success "merge conflicting with --union" \ + "git merge-file --union test.txt orig.txt new3.txt && test_cmp test.txt expect.txt" +cp backup.txt test.txt + test_expect_success "merge with conflicts, using -L" \ "test_must_fail git merge-file -L 1 -L 2 test.txt orig.txt new3.txt" @@ -260,4 +326,23 @@ test_expect_success 'marker size' ' test_cmp expect actual ' +printf "line1\nline2\nline3" >nolf-orig.txt +printf "line1\nline2\nline3x" >nolf-diff1.txt +printf "line1\nline2\nline3y" >nolf-diff2.txt + +test_expect_success 'conflict at EOF without LF resolved by --ours' \ + 'git merge-file -p --ours nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >output.txt && + printf "line1\nline2\nline3x" >expect.txt && + test_cmp expect.txt output.txt' + +test_expect_success 'conflict at EOF without LF resolved by --theirs' \ + 'git merge-file -p --theirs nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >output.txt && + printf "line1\nline2\nline3y" >expect.txt && + test_cmp expect.txt output.txt' + +test_expect_success 'conflict at EOF without LF resolved by --union' \ + 'git merge-file -p --union nolf-diff1.txt nolf-orig.txt nolf-diff2.txt >output.txt && + printf "line1\nline2\nline3x\nline3y" >expect.txt && + test_cmp expect.txt output.txt' + test_done diff --git a/t/t6039-merge-ignorecase.sh b/t/t6039-merge-ignorecase.sh new file mode 100755 index 0000000000..a977653147 --- /dev/null +++ b/t/t6039-merge-ignorecase.sh @@ -0,0 +1,53 @@ +#!/bin/sh + +test_description='git-merge with case-changing rename on case-insensitive file system' + +. ./test-lib.sh + +if ! test_have_prereq CASE_INSENSITIVE_FS +then + skip_all='skipping case insensitive tests - case sensitive file system' + test_done +fi + +test_expect_success 'merge with case-changing rename' ' + test $(git config core.ignorecase) = true && + >TestCase && + git add TestCase && + git commit -m "add TestCase" && + git tag baseline + git checkout -b with-camel && + >foo && + git add foo && + git commit -m "intervening commit" && + git checkout master && + git rm TestCase && + >testcase && + git add testcase && + git commit -m "rename to testcase" && + git checkout with-camel && + git merge master -m "merge" && + test_path_is_file testcase +' + +test_expect_success 'merge with case-changing rename on both sides' ' + git checkout master && + git reset --hard baseline && + git branch -D with-camel && + git checkout -b with-camel && + git mv TestCase testcase && + git commit -m "recase on branch" && + >foo && + git add foo && + git commit -m "intervening commit" && + git checkout master && + git rm TestCase && + >testcase && + git add testcase && + git commit -m "rename to testcase" && + git checkout with-camel && + git merge master -m "merge" && + test_path_is_file testcase +' + +test_done diff --git a/t/t6041-bisect-submodule.sh b/t/t6041-bisect-submodule.sh new file mode 100755 index 0000000000..c6b7aa6977 --- /dev/null +++ b/t/t6041-bisect-submodule.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +test_description='bisect can handle submodules' + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-submodule-update.sh + +git_bisect () { + git status -su >expect && + ls -1pR * >>expect && + tar czf "$TRASH_DIRECTORY/tmp.tgz" * && + GOOD=$(git rev-parse --verify HEAD) && + git checkout "$1" && + echo "foo" >bar && + git add bar && + git commit -m "bisect bad" && + BAD=$(git rev-parse --verify HEAD) && + git reset --hard HEAD^^ && + git submodule update && + git bisect start && + git bisect good $GOOD && + rm -rf * && + tar xzf "$TRASH_DIRECTORY/tmp.tgz" && + git status -su >actual && + ls -1pR * >>actual && + test_cmp expect actual && + git bisect bad $BAD +} + +test_submodule_switch "git_bisect" + +test_done diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh index 719a11673b..4d5a25eedf 100755 --- a/t/t6050-replace.sh +++ b/t/t6050-replace.sh @@ -7,8 +7,9 @@ test_description='Tests replace refs functionality' exec </dev/null . ./test-lib.sh +. "$TEST_DIRECTORY/lib-gpg.sh" -add_and_commit_file() +add_and_commit_file () { _file="$1" _msg="$2" @@ -18,6 +19,38 @@ add_and_commit_file() git commit --quiet -m "$_file: $_msg" } +commit_buffer_contains_parents () +{ + git cat-file commit "$1" >payload && + sed -n -e '/^$/q' -e '/^parent /p' <payload >actual && + shift && + for _parent + do + echo "parent $_parent" + done >expected && + test_cmp expected actual +} + +commit_peeling_shows_parents () +{ + _parent_number=1 + _commit="$1" + shift && + for _parent + do + _found=$(git rev-parse --verify $_commit^$_parent_number) || return 1 + test "$_found" = "$_parent" || return 1 + _parent_number=$(( $_parent_number + 1 )) + done && + test_must_fail git rev-parse --verify $_commit^$_parent_number +} + +commit_has_parents () +{ + commit_buffer_contains_parents "$@" && + commit_peeling_shows_parents "$@" +} + HASH1= HASH2= HASH3= @@ -27,36 +60,36 @@ HASH6= HASH7= test_expect_success 'set up buggy branch' ' - echo "line 1" >> hello && - echo "line 2" >> hello && - echo "line 3" >> hello && - echo "line 4" >> hello && + echo "line 1" >>hello && + echo "line 2" >>hello && + echo "line 3" >>hello && + echo "line 4" >>hello && add_and_commit_file hello "4 lines" && HASH1=$(git rev-parse --verify HEAD) && - echo "line BUG" >> hello && - echo "line 6" >> hello && - echo "line 7" >> hello && - echo "line 8" >> hello && + echo "line BUG" >>hello && + echo "line 6" >>hello && + echo "line 7" >>hello && + echo "line 8" >>hello && add_and_commit_file hello "4 more lines with a BUG" && HASH2=$(git rev-parse --verify HEAD) && - echo "line 9" >> hello && - echo "line 10" >> hello && + echo "line 9" >>hello && + echo "line 10" >>hello && add_and_commit_file hello "2 more lines" && HASH3=$(git rev-parse --verify HEAD) && - echo "line 11" >> hello && + echo "line 11" >>hello && add_and_commit_file hello "1 more line" && HASH4=$(git rev-parse --verify HEAD) && - sed -e "s/BUG/5/" hello > hello.new && + sed -e "s/BUG/5/" hello >hello.new && mv hello.new hello && add_and_commit_file hello "BUG fixed" && HASH5=$(git rev-parse --verify HEAD) && - echo "line 12" >> hello && - echo "line 13" >> hello && + echo "line 12" >>hello && + echo "line 13" >>hello && add_and_commit_file hello "2 more lines" && HASH6=$(git rev-parse --verify HEAD) && - echo "line 14" >> hello && - echo "line 15" >> hello && - echo "line 16" >> hello && + echo "line 14" >>hello && + echo "line 15" >>hello && + echo "line 16" >>hello && add_and_commit_file hello "again 3 more lines" && HASH7=$(git rev-parse --verify HEAD) ' @@ -95,7 +128,7 @@ test_expect_success 'tag replaced commit' ' ' test_expect_success '"git fsck" works' ' - git fsck master > fsck_master.out && + git fsck master >fsck_master.out && grep "dangling commit $R" fsck_master.out && grep "dangling tag $(cat .git/refs/tags/mytag)" fsck_master.out && test -z "$(git fsck)" @@ -217,14 +250,14 @@ test_expect_success 'fetch branch with replacement' ' ( cd clone_dir && git fetch origin refs/heads/tofetch:refs/heads/parallel3 && - git log --pretty=oneline parallel3 > output.txt && + git log --pretty=oneline parallel3 >output.txt && ! grep $PARA3 output.txt && - git show $PARA3 > para3.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 && + git log --pretty=oneline parallel3 >output.txt && grep $PARA3 output.txt && - git show $PARA3 > para3.txt && + git show $PARA3 >para3.txt && grep "O Thor" para3.txt ) ' @@ -302,7 +335,7 @@ test_expect_success 'test --format medium' ' echo "$PARA3 -> $S" && echo "$MYTAG -> $HASH1" } | sort >expected && - git replace -l --format medium | sort > actual && + git replace -l --format medium | sort >actual && test_cmp expected actual ' @@ -314,14 +347,97 @@ test_expect_success 'test --format long' ' echo "$PARA3 (commit) -> $S (commit)" && echo "$MYTAG (tag) -> $HASH1 (commit)" } | sort >expected && - git replace --format=long | sort > actual && + git replace --format=long | sort >actual && test_cmp expected actual ' +test_expect_success 'setup a fake editor' ' + write_script fakeeditor <<-\EOF + sed -e "s/A U Thor/A fake Thor/" "$1" >"$1.new" + mv "$1.new" "$1" + EOF +' + +test_expect_success '--edit with and without already replaced object' ' + test_must_fail env GIT_EDITOR=./fakeeditor git replace --edit "$PARA3" && + GIT_EDITOR=./fakeeditor git replace --force --edit "$PARA3" && + git replace -l | grep "$PARA3" && + git cat-file commit "$PARA3" | grep "A fake Thor" && + git replace -d "$PARA3" && + GIT_EDITOR=./fakeeditor git replace --edit "$PARA3" && + git replace -l | grep "$PARA3" && + git cat-file commit "$PARA3" | grep "A fake Thor" +' + +test_expect_success '--edit and change nothing or command failed' ' + git replace -d "$PARA3" && + test_must_fail env GIT_EDITOR=true git replace --edit "$PARA3" && + test_must_fail env GIT_EDITOR="./fakeeditor;false" git replace --edit "$PARA3" && + GIT_EDITOR=./fakeeditor git replace --edit "$PARA3" && + git replace -l | grep "$PARA3" && + git cat-file commit "$PARA3" | grep "A fake Thor" +' + test_expect_success 'replace ref cleanup' ' test -n "$(git replace)" && git replace -d $(git replace) && test -z "$(git replace)" ' +test_expect_success '--graft with and without already replaced object' ' + test $(git log --oneline | wc -l) = 7 && + git replace --graft $HASH5 && + test $(git log --oneline | wc -l) = 3 && + commit_has_parents $HASH5 && + test_must_fail git replace --graft $HASH5 $HASH4 $HASH3 && + git replace --force -g $HASH5 $HASH4 $HASH3 && + commit_has_parents $HASH5 $HASH4 $HASH3 && + git replace -d $HASH5 +' + +test_expect_success GPG 'set up a signed commit' ' + echo "line 17" >>hello && + echo "line 18" >>hello && + git add hello && + test_tick && + git commit --quiet -S -m "hello: 2 more lines in a signed commit" && + HASH8=$(git rev-parse --verify HEAD) && + git verify-commit $HASH8 +' + +test_expect_success GPG '--graft with a signed commit' ' + git cat-file commit $HASH8 >orig && + git replace --graft $HASH8 && + git cat-file commit $HASH8 >repl && + commit_has_parents $HASH8 && + test_must_fail git verify-commit $HASH8 && + sed -n -e "/^tree /p" -e "/^author /p" -e "/^committer /p" orig >expected && + echo >>expected && + sed -e "/^$/q" repl >actual && + test_cmp expected actual && + git replace -d $HASH8 +' + +test_expect_success GPG 'set up a merge commit with a mergetag' ' + git reset --hard HEAD && + git checkout -b test_branch HEAD~2 && + echo "line 1 from test branch" >>hello && + echo "line 2 from test branch" >>hello && + git add hello && + test_tick && + git commit -m "hello: 2 more lines from a test branch" && + HASH9=$(git rev-parse --verify HEAD) && + git tag -s -m "tag for testing with a mergetag" test_tag HEAD && + git checkout master && + git merge -s ours test_tag && + HASH10=$(git rev-parse --verify HEAD) && + git cat-file commit $HASH10 | grep "^mergetag object" +' + +test_expect_success GPG '--graft on a commit with a mergetag' ' + test_must_fail git replace --graft $HASH10 $HASH8^1 && + git replace --graft $HASH10 $HASH8^1 $HASH9 && + git replace -d $HASH10 +' + test_done diff --git a/t/t7001-mv.sh b/t/t7001-mv.sh index 34fb1afbb3..54d78079e8 100755 --- a/t/t7001-mv.sh +++ b/t/t7001-mv.sh @@ -308,7 +308,7 @@ test_expect_success 'git mv moves a submodule with a .git directory and no .gitm ( cd sub && rm -f .git && - cp -a ../.git/modules/sub .git && + cp -R -P -p ../.git/modules/sub .git && GIT_WORK_TREE=. git config --unset core.worktree ) && mkdir mod && @@ -331,7 +331,7 @@ test_expect_success 'git mv moves a submodule with a .git directory and .gitmodu ( cd sub && rm -f .git && - cp -a ../.git/modules/sub .git && + cp -R -P -p ../.git/modules/sub .git && GIT_WORK_TREE=. git config --unset core.worktree ) && mkdir mod && diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh index 9496736a89..66643e4bd7 100755 --- a/t/t7003-filter-branch.sh +++ b/t/t7003-filter-branch.sh @@ -308,6 +308,17 @@ test_expect_success 'Prune empty commits' ' test_cmp expect actual ' +test_expect_success 'prune empty collapsed merges' ' + test_config merge.ff false && + git rev-list HEAD >expect && + test_commit to_remove_2 && + git reset --hard HEAD^ && + test_merge non-ff to_remove_2 && + git filter-branch -f --index-filter "git update-index --remove to_remove_2.t" --prune-empty HEAD && + git rev-list HEAD >actual && + test_cmp expect actual +' + test_expect_success '--remap-to-ancestor with filename filters' ' git checkout master && git reset --hard A && diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh index 143a8ea605..0366653088 100755 --- a/t/t7004-tag.sh +++ b/t/t7004-tag.sh @@ -1385,41 +1385,103 @@ test_expect_success 'lexical sort' ' git tag foo1.6 && git tag foo1.10 && git tag -l --sort=refname "foo*" >actual && - cat >expect <<EOF && -foo1.10 -foo1.3 -foo1.6 -EOF + cat >expect <<-\EOF && + foo1.10 + foo1.3 + foo1.6 + EOF test_cmp expect actual ' test_expect_success 'version sort' ' git tag -l --sort=version:refname "foo*" >actual && - cat >expect <<EOF && -foo1.3 -foo1.6 -foo1.10 -EOF + cat >expect <<-\EOF && + foo1.3 + foo1.6 + foo1.10 + EOF test_cmp expect actual ' test_expect_success 'reverse version sort' ' git tag -l --sort=-version:refname "foo*" >actual && - cat >expect <<EOF && -foo1.10 -foo1.6 -foo1.3 -EOF + cat >expect <<-\EOF && + foo1.10 + foo1.6 + foo1.3 + EOF test_cmp expect actual ' test_expect_success 'reverse lexical sort' ' git tag -l --sort=-refname "foo*" >actual && - cat >expect <<EOF && -foo1.6 -foo1.3 -foo1.10 -EOF + cat >expect <<-\EOF && + foo1.6 + foo1.3 + foo1.10 + EOF + test_cmp expect actual +' + +test_expect_success 'configured lexical sort' ' + git config tag.sort "v:refname" && + git tag -l "foo*" >actual && + cat >expect <<-\EOF && + foo1.3 + foo1.6 + foo1.10 + EOF + test_cmp expect actual +' + +test_expect_success 'option override configured sort' ' + git tag -l --sort=-refname "foo*" >actual && + cat >expect <<-\EOF && + foo1.6 + foo1.3 + foo1.10 + EOF + test_cmp expect actual +' + +test_expect_success 'invalid sort parameter on command line' ' + test_must_fail git tag -l --sort=notvalid "foo*" >actual +' + +test_expect_success 'invalid sort parameter in configuratoin' ' + git config tag.sort "v:notvalid" && + git tag -l "foo*" >actual && + cat >expect <<-\EOF && + foo1.10 + foo1.3 + foo1.6 + EOF + test_cmp expect actual +' + +run_with_limited_stack () { + (ulimit -s 64 && "$@") +} + +test_lazy_prereq ULIMIT 'run_with_limited_stack true' + +# we require ulimit, this excludes Windows +test_expect_success ULIMIT '--contains works in a deep repo' ' + >expect && + i=1 && + while test $i -lt 4000 + do + echo "commit refs/heads/master +committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200 +data <<EOF +commit #$i +EOF" + test $i = 1 && echo "from refs/heads/master^0" + i=$(($i + 1)) + done | git fast-import && + git checkout master && + git tag far-far-away HEAD^ && + run_with_limited_stack git tag --contains HEAD >actual && test_cmp expect actual ' diff --git a/t/t7007-show.sh b/t/t7007-show.sh index e41fa00b80..1b824fe5ed 100755 --- a/t/t7007-show.sh +++ b/t/t7007-show.sh @@ -24,7 +24,8 @@ test_expect_success 'set up a bit of history' ' git tag -m "annotated tag" annotated && git checkout -b side HEAD^^ && test_commit side2 && - test_commit side3 + test_commit side3 && + test_merge merge main3 ' test_expect_success 'showing two commits' ' @@ -109,8 +110,11 @@ test_expect_success 'showing range' ' ' test_expect_success '-s suppresses diff' ' - echo main3 >expect && - git show -s --format=%s main3 >actual && + cat >expect <<-\EOF && + merge + main3 + EOF + git show -s --format=%s merge main3 >actual && test_cmp expect actual ' diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh index 450529404c..98bcfe21aa 100755 --- a/t/t7102-reset.sh +++ b/t/t7102-reset.sh @@ -22,6 +22,9 @@ commit_msg () { fi } +# Tested non-UTF-8 encoding +test_encoding="ISO8859-1" + test_expect_success 'creating initial files and commits' ' test_tick && echo "1st file" >first && @@ -41,7 +44,9 @@ test_expect_success 'creating initial files and commits' ' echo "1st line 2nd file" >secondfile && echo "2nd line 2nd file" >>secondfile && - git -c "i18n.commitEncoding=iso8859-1" commit -a -m "$(commit_msg iso8859-1)" && + # "git commit -m" would break MinGW, as Windows refuse to pass + # $test_encoding encoded parameter to git. + commit_msg $test_encoding | git -c "i18n.commitEncoding=$test_encoding" commit -a -F - && head5=$(git rev-parse --verify HEAD) ' # git log --pretty=oneline # to see those SHA1 involved @@ -64,10 +69,10 @@ test_expect_success 'reset --hard message' ' test_cmp .expected .actual ' -test_expect_success 'reset --hard message (iso8859-1 logoutputencoding)' ' +test_expect_success 'reset --hard message (ISO8859-1 logoutputencoding)' ' hex=$(git log -1 --format="%h") && - git -c "i18n.logOutputEncoding=iso8859-1" reset --hard > .actual && - echo HEAD is now at $hex $(commit_msg iso8859-1) > .expected && + git -c "i18n.logOutputEncoding=$test_encoding" reset --hard > .actual && + echo HEAD is now at $hex $(commit_msg $test_encoding) > .expected && test_cmp .expected .actual ' @@ -331,7 +336,9 @@ test_expect_success 'redoing the last two commits should succeed' ' echo "1st line 2nd file" >secondfile && echo "2nd line 2nd file" >>secondfile && - git -c "i18n.commitEncoding=iso8859-1" commit -a -m "$(commit_msg iso8859-1)" && + # "git commit -m" would break MinGW, as Windows refuse to pass + # $test_encoding encoded parameter to git. + commit_msg $test_encoding | git -c "i18n.commitEncoding=$test_encoding" commit -a -F - && check_changes $head5 ' diff --git a/t/t7112-reset-submodule.sh b/t/t7112-reset-submodule.sh new file mode 100755 index 0000000000..2eda6adeb1 --- /dev/null +++ b/t/t7112-reset-submodule.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +test_description='reset can handle submodules' + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-submodule-update.sh + +test_submodule_switch "git reset --keep" + +test_submodule_switch "git reset --merge" + +test_submodule_forced_switch "git reset --hard" + +test_done diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh index 74de814aec..04118ad75b 100755 --- a/t/t7300-clean.sh +++ b/t/t7300-clean.sh @@ -426,10 +426,10 @@ test_expect_success SANITY 'removal failure' ' mkdir foo && touch foo/bar && + test_when_finished "chmod 755 foo" && (exec <foo/bar && chmod 0 foo && - test_must_fail git clean -f -d && - chmod 755 foo) + test_must_fail git clean -f -d) ' test_expect_success 'nested git work tree' ' diff --git a/t/t7500-commit.sh b/t/t7500-commit.sh index bdc1f29503..116885a260 100755 --- a/t/t7500-commit.sh +++ b/t/t7500-commit.sh @@ -223,7 +223,8 @@ test_expect_success 'Commit without message is allowed with --allow-empty-messag git add foo && >empty && git commit --allow-empty-message <empty && - commit_msg_is "" + commit_msg_is "" && + git tag empty-message-commit ' test_expect_success 'Commit without message is no-no without --allow-empty-message' ' @@ -240,6 +241,14 @@ test_expect_success 'Commit a message with --allow-empty-message' ' commit_msg_is "hello there" ' +test_expect_success 'commit -C empty respects --allow-empty-message' ' + echo more >>foo && + git add foo && + test_must_fail git commit -C empty-message-commit && + git commit -C empty-message-commit --allow-empty-message && + commit_msg_is "" +' + commit_for_rebase_autosquash_setup () { echo "first content line" >>foo && git add foo && diff --git a/t/t7501-commit.sh b/t/t7501-commit.sh index d58b097ff3..63e04277f9 100755 --- a/t/t7501-commit.sh +++ b/t/t7501-commit.sh @@ -346,8 +346,21 @@ 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 'commit mentions forced date in output' ' + git commit --amend --date=2010-01-02T03:04:05 >output && + grep "Date: *Sat Jan 2 03:04:05 2010" output +' + +test_expect_success 'commit complains about completely bogus dates' ' + test_must_fail git commit --amend --date=seventeen +' + +test_expect_success 'commit --date allows approxidate' ' + git commit --amend \ + --date="midnight the 12th of october, anno domini 1979" && + echo "Fri Oct 12 00:00:00 1979 +0000" >expect && + git log -1 --format=%ad >actual && + test_cmp expect actual ' test_expect_success 'sign off (1)' ' diff --git a/t/t7502-commit.sh b/t/t7502-commit.sh index 9a3f3a1b41..051489ea33 100755 --- a/t/t7502-commit.sh +++ b/t/t7502-commit.sh @@ -344,6 +344,13 @@ test_expect_success 'message shows author when it is not equal to committer' ' .git/COMMIT_EDITMSG ' +test_expect_success 'message shows date when it is explicitly set' ' + git commit --allow-empty -e -m foo --date="2010-01-02T03:04:05" && + test_i18ngrep \ + "^# Date: *Sat Jan 2 03:04:05 2010 +0000" \ + .git/COMMIT_EDITMSG +' + test_expect_success AUTOIDENT 'message shows committer when it is automatic' ' echo >>negative && @@ -563,4 +570,30 @@ test_expect_success 'commit --status with custom comment character' ' test_i18ngrep "^; Changes to be committed:" .git/COMMIT_EDITMSG ' +test_expect_success 'switch core.commentchar' ' + test_commit "#foo" foo && + GIT_EDITOR=.git/FAKE_EDITOR git -c core.commentChar=auto commit --amend && + test_i18ngrep "^; Changes to be committed:" .git/COMMIT_EDITMSG +' + +test_expect_success 'switch core.commentchar but out of options' ' + cat >text <<\EOF && +# 1 +; 2 +@ 3 +! 4 +$ 5 +% 6 +^ 7 +& 8 +| 9 +: 10 +EOF + git commit --amend -F text && + ( + test_set_editor .git/FAKE_EDITOR && + test_must_fail git -c core.commentChar=auto commit --amend + ) +' + test_done diff --git a/t/t7508-status.sh b/t/t7508-status.sh index c987b5ed65..8ed5788808 100755 --- a/t/t7508-status.sh +++ b/t/t7508-status.sh @@ -1350,8 +1350,7 @@ test_expect_success "status (core.commentchar with submodule summary)" ' test_expect_success "status (core.commentchar with two chars with submodule summary)" ' test_config core.commentchar ";;" && - git -c status.displayCommentPrefix=true status >output && - test_i18ncmp expect output + test_must_fail git -c status.displayCommentPrefix=true status ' test_expect_success "--ignore-submodules=all suppresses submodule summary" ' @@ -1380,7 +1379,32 @@ EOF test_i18ncmp expect output ' -test_expect_success '.gitmodules ignore=all suppresses submodule summary' ' +test_expect_success '.gitmodules ignore=all suppresses unstaged submodule summary' ' + cat > expect << EOF && +On branch master +Changes to be committed: + (use "git reset HEAD <file>..." to unstage) + + modified: sm + +Changes not staged for commit: + (use "git add <file>..." to update what will be committed) + (use "git checkout -- <file>..." to discard changes in working directory) + + modified: dir1/modified + +Untracked files: + (use "git add <file>..." to include in what will be committed) + + .gitmodules + dir1/untracked + dir2/modified + dir2/untracked + expect + output + untracked + +EOF git config --add -f .gitmodules submodule.subname.ignore all && git config --add -f .gitmodules submodule.subname.path sm && git status > output && @@ -1388,7 +1412,7 @@ test_expect_success '.gitmodules ignore=all suppresses submodule summary' ' git config -f .gitmodules --remove-section submodule.subname ' -test_expect_success '.git/config ignore=all suppresses submodule summary' ' +test_expect_success '.git/config ignore=all suppresses unstaged submodule summary' ' git config --add -f .gitmodules submodule.subname.ignore none && git config --add -f .gitmodules submodule.subname.path sm && git config --add submodule.subname.ignore all && @@ -1461,4 +1485,49 @@ test_expect_success 'Restore default test environment' ' git config --unset status.showUntrackedFiles ' +test_expect_success 'git commit will commit a staged but ignored submodule' ' + git config --add -f .gitmodules submodule.subname.ignore all && + git config --add -f .gitmodules submodule.subname.path sm && + git config --add submodule.subname.ignore all && + git status -s --ignore-submodules=dirty >output && + test_i18ngrep "^M. sm" output && + GIT_EDITOR="echo hello >>\"\$1\"" && + export GIT_EDITOR && + git commit -uno && + git status -s --ignore-submodules=dirty >output && + test_i18ngrep ! "^M. sm" output +' + +test_expect_success 'git commit --dry-run will show a staged but ignored submodule' ' + git reset HEAD^ && + git add sm && + cat >expect << EOF && +On branch master +Changes to be committed: + (use "git reset HEAD <file>..." to unstage) + + modified: sm + +Changes not staged for commit: + (use "git add <file>..." to update what will be committed) + (use "git checkout -- <file>..." to discard changes in working directory) + + modified: dir1/modified + +Untracked files not listed (use -u option to show untracked files) +EOF + git commit -uno --dry-run >output && + test_i18ncmp expect output && + git status -s --ignore-submodules=dirty >output && + test_i18ngrep "^M. sm" output +' + +test_expect_success 'git commit -m will commit a staged but ignored submodule' ' + git commit -uno -m message && + git status -s --ignore-submodules=dirty >output && + test_i18ngrep ! "^M. sm" output && + git config --remove-section submodule.subname && + git config -f .gitmodules --remove-section submodule.subname +' + test_done diff --git a/t/t7509-commit.sh b/t/t7509-commit.sh index b61fd3c3c4..9ac794052d 100755 --- a/t/t7509-commit.sh +++ b/t/t7509-commit.sh @@ -77,6 +77,7 @@ test_expect_success '--amend option copies authorship' ' git commit -a --amend -m "amend test" && author_header Initial >expect && author_header HEAD >actual && + test_cmp expect actual && echo "amend test" >expect && message_body HEAD >actual && diff --git a/t/t7510-signed-commit.sh b/t/t7510-signed-commit.sh index 5ddac1a9f7..474dab381a 100755 --- a/t/t7510-signed-commit.sh +++ b/t/t7510-signed-commit.sh @@ -43,44 +43,74 @@ test_expect_success GPG 'create signed commits' ' test_tick && git rebase -f HEAD^^ && git tag sixth-signed HEAD^ && git tag seventh-signed + + echo 8 >file && test_tick && git commit -a -m eighth -SB7227189 && + git tag eighth-signed-alt ' -test_expect_success GPG 'show signatures' ' +test_expect_success GPG 'verify and show signatures' ' ( - for commit in initial second merge fourth-signed fifth-signed sixth-signed master + for commit in initial second merge fourth-signed fifth-signed sixth-signed seventh-signed do + git verify-commit $commit && git show --pretty=short --show-signature $commit >actual && - grep "Good signature from" actual || exit 1 - ! grep "BAD signature from" actual || exit 1 - echo $commit OK + grep "Good signature from" actual && + ! grep "BAD signature from" actual && + echo $commit OK || exit 1 done ) && ( for commit in merge^2 fourth-unsigned sixth-unsigned seventh-unsigned do + test_must_fail git verify-commit $commit && git show --pretty=short --show-signature $commit >actual && - grep "Good signature from" actual && exit 1 - ! grep "BAD signature from" actual || exit 1 - echo $commit OK + ! grep "Good signature from" actual && + ! grep "BAD signature from" actual && + echo $commit OK || exit 1 + done + ) && + ( + for commit in eighth-signed-alt + do + git show --pretty=short --show-signature $commit >actual && + grep "Good signature from" actual && + ! grep "BAD signature from" actual && + grep "not certified" actual && + echo $commit OK || exit 1 done ) ' +test_expect_success GPG 'show signed commit with signature' ' + git show -s initial >commit && + git show -s --show-signature initial >show && + git verify-commit -v initial >verify.1 2>verify.2 && + git cat-file commit initial >cat && + grep -v "gpg: " show >show.commit && + grep "gpg: " show >show.gpg && + grep -v "^ " cat | grep -v "^gpgsig " >cat.commit && + test_cmp show.commit commit && + test_cmp show.gpg verify.2 && + test_cmp cat.commit verify.1 +' + test_expect_success GPG 'detect fudged signature' ' - git cat-file commit master >raw && + git cat-file commit seventh-signed >raw && sed -e "s/seventh/7th forged/" raw >forged1 && git hash-object -w -t commit forged1 >forged1.commit && + ! git verify-commit $(cat forged1.commit) && git show --pretty=short --show-signature $(cat forged1.commit) >actual1 && grep "BAD signature from" actual1 && ! grep "Good signature from" actual1 ' test_expect_success GPG 'detect fudged signature with NUL' ' - git cat-file commit master >raw && + git cat-file commit seventh-signed >raw && cat raw >forged2 && echo Qwik | tr "Q" "\000" >>forged2 && git hash-object -w -t commit forged2 >forged2.commit && + ! git verify-commit $(cat forged2.commit) && git show --pretty=short --show-signature $(cat forged2.commit) >actual2 && grep "BAD signature from" actual2 && ! grep "Good signature from" actual2 @@ -89,9 +119,50 @@ test_expect_success GPG 'detect fudged signature with NUL' ' test_expect_success GPG 'amending already signed commit' ' git checkout fourth-signed^0 && git commit --amend -S --no-edit && + git verify-commit HEAD && git show -s --show-signature HEAD >actual && grep "Good signature from" actual && ! grep "BAD signature from" actual ' +test_expect_success GPG 'show good signature with custom format' ' + cat >expect <<-\EOF && + G + 13B6F51ECDDE430D + C O Mitter <committer@example.com> + EOF + git log -1 --format="%G?%n%GK%n%GS" sixth-signed >actual && + test_cmp expect actual +' + +test_expect_success GPG 'show bad signature with custom format' ' + cat >expect <<-\EOF && + B + 13B6F51ECDDE430D + C O Mitter <committer@example.com> + EOF + git log -1 --format="%G?%n%GK%n%GS" $(cat forged1.commit) >actual && + test_cmp expect actual +' + +test_expect_success GPG 'show unknown signature with custom format' ' + cat >expect <<-\EOF && + U + 61092E85B7227189 + Eris Discordia <discord@example.net> + EOF + git log -1 --format="%G?%n%GK%n%GS" eighth-signed-alt >actual && + test_cmp expect actual +' + +test_expect_success GPG 'show lack of signature with custom format' ' + cat >expect <<-\EOF && + N + + + EOF + git log -1 --format="%G?%n%GK%n%GS" seventh-unsigned >actual && + test_cmp expect actual +' + test_done diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh index 10aa028017..b16462132f 100755 --- a/t/t7600-merge.sh +++ b/t/t7600-merge.sh @@ -57,11 +57,10 @@ create_merge_msgs () { git log --no-merges ^HEAD c2 c3 } >squash.1-5-9 && : >msg.nologff && - echo >msg.nolognoff && + : >msg.nolognoff && { echo "* tag 'c3':" && - echo " commit 3" && - echo + echo " commit 3" } >msg.log } @@ -71,7 +70,7 @@ verify_merge () { git diff --exit-code && if test -n "$3" then - git show -s --pretty=format:%s HEAD >msg.act && + git show -s --pretty=tformat:%s HEAD >msg.act && test_cmp "$3" msg.act fi } @@ -620,10 +619,10 @@ test_expect_success 'merge early part of c2' ' git tag c6 && git branch -f c5-branch c5 && git merge c5-branch~1 && - git show -s --pretty=format:%s HEAD >actual.branch && + git show -s --pretty=tformat:%s HEAD >actual.branch && git reset --keep HEAD^ && git merge c5~1 && - git show -s --pretty=format:%s HEAD >actual.tag && + git show -s --pretty=tformat:%s HEAD >actual.tag && test_cmp expected.branch actual.branch && test_cmp expected.tag actual.tag ' diff --git a/t/t7613-merge-submodule.sh b/t/t7613-merge-submodule.sh new file mode 100755 index 0000000000..d1e9fcc781 --- /dev/null +++ b/t/t7613-merge-submodule.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +test_description='merge can handle submodules' + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-submodule-update.sh + +# merges without conflicts +test_submodule_switch "git merge" + +test_submodule_switch "git merge --ff" + +test_submodule_switch "git merge --ff-only" + +KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1 +KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1 +test_submodule_switch "git merge --no-ff" + +test_done diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 284018e3cd..021c5479bd 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -21,7 +21,7 @@ test_expect_success 'objects in packs marked .keep are not repacked' ' objsha1=$(git verify-pack -v pack-$packsha1.idx | head -n 1 | sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") && mv pack-* .git/objects/pack/ && - git repack --no-pack-kept-objects -A -d -l && + git repack -A -d -l && git prune-packed && for p in .git/objects/pack/*.idx; do idx=$(basename $p) @@ -35,9 +35,25 @@ test_expect_success 'objects in packs marked .keep are not repacked' ' test -z "$found_duplicate_object" ' -test_expect_success 'writing bitmaps can duplicate .keep objects' ' +test_expect_success 'writing bitmaps via command-line can duplicate .keep objects' ' # build on $objsha1, $packsha1, and .keep state from previous - git repack -Adl && + git repack -Adbl && + test_when_finished "found_duplicate_object=" && + for p in .git/objects/pack/*.idx; do + idx=$(basename $p) + test "pack-$packsha1.idx" = "$idx" && continue + if git verify-pack -v $p | egrep "^$objsha1"; then + found_duplicate_object=1 + echo "DUPLICATE OBJECT FOUND" + break + fi + done && + test "$found_duplicate_object" = 1 +' + +test_expect_success 'writing bitmaps via config can duplicate .keep objects' ' + # build on $objsha1, $packsha1, and .keep state from previous + git -c repack.writebitmaps=true repack -Adl && test_when_finished "found_duplicate_object=" && for p in .git/objects/pack/*.idx; do idx=$(basename $p) diff --git a/t/t7702-repack-cyclic-alternate.sh b/t/t7702-repack-cyclic-alternate.sh new file mode 100755 index 0000000000..93b74867ac --- /dev/null +++ b/t/t7702-repack-cyclic-alternate.sh @@ -0,0 +1,24 @@ +#!/bin/sh +# +# Copyright (c) 2014 Ephrim Khong +# + +test_description='repack involving cyclic alternate' +. ./test-lib.sh + +test_expect_success setup ' + GIT_OBJECT_DIRECTORY=.git//../.git/objects && + export GIT_OBJECT_DIRECTORY && + touch a && + git add a && + git commit -m 1 && + git repack -adl && + echo "$(pwd)"/.git/objects/../objects >.git/objects/info/alternates +' + +test_expect_success 're-packing repository with itsself as alternate' ' + git repack -adl && + git fsck +' + +test_done diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh index 5a193c500d..dc30a514bf 100755 --- a/t/t7800-difftool.sh +++ b/t/t7800-difftool.sh @@ -58,7 +58,7 @@ test_expect_success PERL 'custom tool commands override built-ins' ' test_expect_success PERL 'difftool ignores bad --tool values' ' : >expect && - test_expect_code 1 \ + test_must_fail \ git difftool --no-prompt --tool=bad-tool branch >actual && test_cmp expect actual ' diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh index 63b3039243..40615debc4 100755 --- a/t/t7810-grep.sh +++ b/t/t7810-grep.sh @@ -1096,11 +1096,6 @@ test_expect_success 'grep -E pattern with grep.patternType=fixed' ' test_cmp expected actual ' -test_config() { - git config "$1" "$2" && - test_when_finished "git config --unset $1" -} - cat >expected <<EOF hello.c<RED>:<RESET>int main(int argc, const char **argv) hello.c<RED>-<RESET>{ diff --git a/t/t8003-blame-corner-cases.sh b/t/t8003-blame-corner-cases.sh index e7cac1db55..2a3469bcbe 100755 --- a/t/t8003-blame-corner-cases.sh +++ b/t/t8003-blame-corner-cases.sh @@ -191,4 +191,13 @@ test_expect_success 'indent of line numbers, ten lines' ' test $(grep -c " " actual) = 9 ' +test_expect_success 'blaming files with CRLF newlines' ' + git config core.autocrlf false && + printf "testcase\r\n" >crlffile && + git add crlffile && + git commit -m testcase && + git -c core.autocrlf=input blame crlffile >actual && + grep "A U Thor" actual +' + test_done diff --git a/t/t8005-blame-i18n.sh b/t/t8005-blame-i18n.sh index cb390559f9..a6e73d0635 100755 --- a/t/t8005-blame-i18n.sh +++ b/t/t8005-blame-i18n.sh @@ -33,7 +33,7 @@ author $SJIS_NAME summary $SJIS_MSG EOF -test_expect_success \ +test_expect_success NOT_MINGW \ 'blame respects i18n.commitencoding' ' git blame --incremental file | \ egrep "^(author|summary) " > actual && @@ -49,7 +49,7 @@ author $EUC_JAPAN_NAME summary $EUC_JAPAN_MSG EOF -test_expect_success \ +test_expect_success NOT_MINGW \ 'blame respects i18n.logoutputencoding' ' git config i18n.logoutputencoding eucJP && git blame --incremental file | \ @@ -66,7 +66,7 @@ author $UTF8_NAME summary $UTF8_MSG EOF -test_expect_success \ +test_expect_success NOT_MINGW \ 'blame respects --encoding=UTF-8' ' git blame --incremental --encoding=UTF-8 file | \ egrep "^(author|summary) " > actual && @@ -82,7 +82,7 @@ author $UTF8_NAME summary $UTF8_MSG EOF -test_expect_success \ +test_expect_success NOT_MINGW \ 'blame respects --encoding=none' ' git blame --incremental --encoding=none file | \ egrep "^(author|summary) " > actual && diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index 1ecdacb6fd..19a3ced600 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -1334,6 +1334,51 @@ test_expect_success $PREREQ '--force sends cover letter template anyway' ' test -n "$(ls msgtxt*)" ' +test_cover_addresses () { + header="$1" + shift + clean_fake_sendmail && + rm -fr outdir && + git format-patch --cover-letter -2 -o outdir && + cover=`echo outdir/0000-*.patch` && + mv $cover cover-to-edit.patch && + perl -pe "s/^From:/$header: extra\@address.com\nFrom:/" cover-to-edit.patch >"$cover" && + git send-email \ + --force \ + --from="Example <nobody@example.com>" \ + --no-to --no-cc \ + "$@" \ + --smtp-server="$(pwd)/fake.sendmail" \ + outdir/0000-*.patch \ + outdir/0001-*.patch \ + outdir/0002-*.patch \ + 2>errors >out && + grep "^$header: extra@address.com" msgtxt1 >to1 && + grep "^$header: extra@address.com" msgtxt2 >to2 && + grep "^$header: extra@address.com" msgtxt3 >to3 && + test_line_count = 1 to1 && + test_line_count = 1 to2 && + test_line_count = 1 to3 +} + +test_expect_success $PREREQ 'to-cover adds To to all mail' ' + test_cover_addresses "To" --to-cover +' + +test_expect_success $PREREQ 'cc-cover adds Cc to all mail' ' + test_cover_addresses "Cc" --cc-cover +' + +test_expect_success $PREREQ 'tocover adds To to all mail' ' + test_config sendemail.tocover true && + test_cover_addresses "To" +' + +test_expect_success $PREREQ 'cccover adds Cc to all mail' ' + test_config sendemail.cccover true && + test_cover_addresses "Cc" +' + test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' ' clean_fake_sendmail && echo "alias sbd somebody@example.org" >.mailrc && diff --git a/t/t9107-git-svn-migrate.sh b/t/t9107-git-svn-migrate.sh index ee73013eed..6e69fc4c65 100755 --- a/t/t9107-git-svn-migrate.sh +++ b/t/t9107-git-svn-migrate.sh @@ -45,27 +45,27 @@ test_expect_success 'initialize old-style (v0) git svn layout' ' test_expect_success 'initialize a multi-repository repo' ' git svn init "$svnrepo" -T trunk -t tags -b branches && git config --get-all svn-remote.svn.fetch > fetch.out && - grep "^trunk:refs/remotes/trunk$" fetch.out && + grep "^trunk:refs/remotes/origin/trunk$" fetch.out && test -n "`git config --get svn-remote.svn.branches \ - "^branches/\*:refs/remotes/\*$"`" && + "^branches/\*:refs/remotes/origin/\*$"`" && test -n "`git config --get svn-remote.svn.tags \ - "^tags/\*:refs/remotes/tags/\*$"`" && + "^tags/\*:refs/remotes/origin/tags/\*$"`" && git config --unset svn-remote.svn.branches \ - "^branches/\*:refs/remotes/\*$" && + "^branches/\*:refs/remotes/origin/\*$" && git config --unset svn-remote.svn.tags \ - "^tags/\*:refs/remotes/tags/\*$" && - git config --add svn-remote.svn.fetch "branches/a:refs/remotes/a" && - git config --add svn-remote.svn.fetch "branches/b:refs/remotes/b" && + "^tags/\*:refs/remotes/origin/tags/\*$" && + git config --add svn-remote.svn.fetch "branches/a:refs/remotes/origin/a" && + git config --add svn-remote.svn.fetch "branches/b:refs/remotes/origin/b" && for i in tags/0.1 tags/0.2 tags/0.3; do git config --add svn-remote.svn.fetch \ - $i:refs/remotes/$i || exit 1; done && + $i:refs/remotes/origin/$i || exit 1; done && git config --get-all svn-remote.svn.fetch > fetch.out && - grep "^trunk:refs/remotes/trunk$" fetch.out && - grep "^branches/a:refs/remotes/a$" fetch.out && - grep "^branches/b:refs/remotes/b$" fetch.out && - grep "^tags/0\.1:refs/remotes/tags/0\.1$" fetch.out && - grep "^tags/0\.2:refs/remotes/tags/0\.2$" fetch.out && - grep "^tags/0\.3:refs/remotes/tags/0\.3$" fetch.out && + grep "^trunk:refs/remotes/origin/trunk$" fetch.out && + grep "^branches/a:refs/remotes/origin/a$" fetch.out && + grep "^branches/b:refs/remotes/origin/b$" fetch.out && + grep "^tags/0\.1:refs/remotes/origin/tags/0\.1$" fetch.out && + grep "^tags/0\.2:refs/remotes/origin/tags/0\.2$" fetch.out && + grep "^tags/0\.3:refs/remotes/origin/tags/0\.3$" fetch.out && grep "^:refs/${remotes_git_svn}" fetch.out ' @@ -73,14 +73,14 @@ test_expect_success 'initialize a multi-repository repo' ' test_expect_success 'multi-fetch works on partial urls + paths' " git svn multi-fetch && for i in trunk a b tags/0.1 tags/0.2 tags/0.3; do - git rev-parse --verify refs/remotes/\$i^0 >> refs.out || exit 1; + git rev-parse --verify refs/remotes/origin/\$i^0 >> refs.out || exit 1; done && test -z \"\`sort < refs.out | uniq -d\`\" && for i in trunk a b tags/0.1 tags/0.2 tags/0.3; do for j in trunk a b tags/0.1 tags/0.2 tags/0.3; do if test \$j != \$i; then continue; fi - test -z \"\`git diff refs/remotes/\$i \ - refs/remotes/\$j\`\" ||exit 1; done; done + test -z \"\`git diff refs/remotes/origin/\$i \ + refs/remotes/origin/\$j\`\" ||exit 1; done; done " test_expect_success 'migrate --minimize on old inited layout' ' @@ -98,27 +98,27 @@ test_expect_success 'migrate --minimize on old inited layout' ' git svn migrate --minimize && test -z "`git config -l | grep "^svn-remote\.git-svn\."`" && git config --get-all svn-remote.svn.fetch > fetch.out && - grep "^trunk:refs/remotes/trunk$" fetch.out && - grep "^branches/a:refs/remotes/a$" fetch.out && - grep "^branches/b:refs/remotes/b$" fetch.out && - grep "^tags/0\.1:refs/remotes/tags/0\.1$" fetch.out && - grep "^tags/0\.2:refs/remotes/tags/0\.2$" fetch.out && - grep "^tags/0\.3:refs/remotes/tags/0\.3$" fetch.out && + grep "^trunk:refs/remotes/origin/trunk$" fetch.out && + grep "^branches/a:refs/remotes/origin/a$" fetch.out && + grep "^branches/b:refs/remotes/origin/b$" fetch.out && + grep "^tags/0\.1:refs/remotes/origin/tags/0\.1$" fetch.out && + grep "^tags/0\.2:refs/remotes/origin/tags/0\.2$" fetch.out && + grep "^tags/0\.3:refs/remotes/origin/tags/0\.3$" fetch.out && grep "^:refs/${remotes_git_svn}" fetch.out ' test_expect_success ".rev_db auto-converted to .rev_map.UUID" ' git svn fetch -i trunk && - test -z "$(ls "$GIT_DIR"/svn/refs/remotes/trunk/.rev_db.* 2>/dev/null)" && - expect="$(ls "$GIT_DIR"/svn/refs/remotes/trunk/.rev_map.*)" && + test -z "$(ls "$GIT_DIR"/svn/refs/remotes/origin/trunk/.rev_db.* 2>/dev/null)" && + expect="$(ls "$GIT_DIR"/svn/refs/remotes/origin/trunk/.rev_map.*)" && test -n "$expect" && rev_db="$(echo $expect | sed -e "s,_map,_db,")" && convert_to_rev_db "$expect" "$rev_db" && rm -f "$expect" && test -f "$rev_db" && git svn fetch -i trunk && - test -z "$(ls "$GIT_DIR"/svn/refs/remotes/trunk/.rev_db.* 2>/dev/null)" && - test ! -e "$GIT_DIR"/svn/refs/remotes/trunk/.rev_db && + test -z "$(ls "$GIT_DIR"/svn/refs/remotes/origin/trunk/.rev_db.* 2>/dev/null)" && + test ! -e "$GIT_DIR"/svn/refs/remotes/origin/trunk/.rev_db && test -f "$expect" ' diff --git a/t/t9114-git-svn-dcommit-merge.sh b/t/t9114-git-svn-dcommit-merge.sh index d33d714006..fb41876677 100755 --- a/t/t9114-git-svn-dcommit-merge.sh +++ b/t/t9114-git-svn-dcommit-merge.sh @@ -48,7 +48,7 @@ test_expect_success 'setup svn repository' ' test_expect_success 'setup git mirror and merge' ' git svn init "$svnrepo" -t tags -T trunk -b branches && git svn fetch && - git checkout -b svn remotes/trunk && + git checkout -b svn remotes/origin/trunk && git checkout -b merge && echo new file > new_file && git add new_file && @@ -81,7 +81,7 @@ test_debug 'gitk --all & sleep 1' test_expect_success 'verify post-merge ancestry' " test x\`git rev-parse --verify refs/heads/svn\` = \ - x\`git rev-parse --verify refs/remotes/trunk \` && + x\`git rev-parse --verify refs/remotes/origin/trunk \` && test x\`git rev-parse --verify refs/heads/svn^2\` = \ x\`git rev-parse --verify refs/heads/merge\` && git cat-file commit refs/heads/svn^ | grep '^friend$' diff --git a/t/t9116-git-svn-log.sh b/t/t9116-git-svn-log.sh index cf4c05261b..45773ee560 100755 --- a/t/t9116-git-svn-log.sh +++ b/t/t9116-git-svn-log.sh @@ -20,20 +20,20 @@ test_expect_success 'setup repository and import' ' ) && git svn init "$svnrepo" -T trunk -b branches -t tags && git svn fetch && - git reset --hard trunk && + git reset --hard origin/trunk && echo bye >> README && git commit -a -m bye && git svn dcommit && - git reset --hard a && + git reset --hard origin/a && echo why >> FEEDME && git update-index --add FEEDME && git commit -m feedme && git svn dcommit && - git reset --hard trunk && + git reset --hard origin/trunk && echo aye >> README && git commit -a -m aye && git svn dcommit && - git reset --hard b && + git reset --hard origin/b && echo spy >> README && git commit -a -m spy && echo try >> README && @@ -42,26 +42,26 @@ test_expect_success 'setup repository and import' ' ' test_expect_success 'run log' " - git reset --hard a && - git svn log -r2 trunk | grep ^r2 && - git svn log -r4 trunk | grep ^r4 && + git reset --hard origin/a && + git svn log -r2 origin/trunk | grep ^r2 && + git svn log -r4 origin/trunk | grep ^r4 && git svn log -r3 | grep ^r3 " test_expect_success 'run log against a from trunk' " - git reset --hard trunk && - git svn log -r3 a | grep ^r3 + git reset --hard origin/trunk && + git svn log -r3 origin/a | grep ^r3 " printf 'r1 \nr2 \nr4 \n' > expected-range-r1-r2-r4 test_expect_success 'test ascending revision range' " - git reset --hard trunk && + git reset --hard origin/trunk && git svn log -r 1:4 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r1-r2-r4 - " test_expect_success 'test ascending revision range with --show-commit' " - git reset --hard trunk && + git reset --hard origin/trunk && git svn log --show-commit -r 1:4 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r1-r2-r4 - " @@ -69,7 +69,7 @@ test_expect_success 'test ascending revision range with --show-commit (sha1)' " git svn find-rev r1 >expected-range-r1-r2-r4-sha1 && git svn find-rev r2 >>expected-range-r1-r2-r4-sha1 && git svn find-rev r4 >>expected-range-r1-r2-r4-sha1 && - git reset --hard trunk && + git reset --hard origin/trunk && git svn log --show-commit -r 1:4 | grep '^r[0-9]' | cut -d'|' -f2 >out && git rev-parse \$(cat out) >actual && test_cmp expected-range-r1-r2-r4-sha1 actual @@ -78,67 +78,67 @@ test_expect_success 'test ascending revision range with --show-commit (sha1)' " printf 'r4 \nr2 \nr1 \n' > expected-range-r4-r2-r1 test_expect_success 'test descending revision range' " - git reset --hard trunk && + git reset --hard origin/trunk && git svn log -r 4:1 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r4-r2-r1 - " printf 'r1 \nr2 \n' > expected-range-r1-r2 test_expect_success 'test ascending revision range with unreachable revision' " - git reset --hard trunk && + git reset --hard origin/trunk && git svn log -r 1:3 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r1-r2 - " printf 'r2 \nr1 \n' > expected-range-r2-r1 test_expect_success 'test descending revision range with unreachable revision' " - git reset --hard trunk && + git reset --hard origin/trunk && git svn log -r 3:1 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r2-r1 - " printf 'r2 \n' > expected-range-r2 test_expect_success 'test ascending revision range with unreachable upper boundary revision and 1 commit' " - git reset --hard trunk && + git reset --hard origin/trunk && git svn log -r 2:3 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r2 - " test_expect_success 'test descending revision range with unreachable upper boundary revision and 1 commit' " - git reset --hard trunk && + git reset --hard origin/trunk && git svn log -r 3:2 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r2 - " printf 'r4 \n' > expected-range-r4 test_expect_success 'test ascending revision range with unreachable lower boundary revision and 1 commit' " - git reset --hard trunk && + git reset --hard origin/trunk && git svn log -r 3:4 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r4 - " test_expect_success 'test descending revision range with unreachable lower boundary revision and 1 commit' " - git reset --hard trunk && + git reset --hard origin/trunk && git svn log -r 4:3 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r4 - " printf -- '------------------------------------------------------------------------\n' > expected-separator test_expect_success 'test ascending revision range with unreachable boundary revisions and no commits' " - git reset --hard trunk && + git reset --hard origin/trunk && git svn log -r 5:6 | test_cmp expected-separator - " test_expect_success 'test descending revision range with unreachable boundary revisions and no commits' " - git reset --hard trunk && + git reset --hard origin/trunk && git svn log -r 6:5 | test_cmp expected-separator - " test_expect_success 'test ascending revision range with unreachable boundary revisions and 1 commit' " - git reset --hard trunk && + git reset --hard origin/trunk && git svn log -r 3:5 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r4 - " test_expect_success 'test descending revision range with unreachable boundary revisions and 1 commit' " - git reset --hard trunk && + git reset --hard origin/trunk && git svn log -r 5:3 | grep '^r[0-9]' | cut -d'|' -f1 | test_cmp expected-range-r4 - " diff --git a/t/t9117-git-svn-init-clone.sh b/t/t9117-git-svn-init-clone.sh index 69e9c0db5d..a66f43c6b1 100755 --- a/t/t9117-git-svn-init-clone.sh +++ b/t/t9117-git-svn-init-clone.sh @@ -83,36 +83,36 @@ EOF rm -f expect actual } -test_expect_success 'init with -s/-T/-b/-t without --prefix warns' ' +test_expect_success 'init with -s/-T/-b/-t assumes --prefix=origin/' ' test ! -d project && git svn init -s "$svnrepo"/project project 2>warning && - grep -q prefix warning && - test_svn_configured_prefix "" && + test_must_fail grep -q prefix warning && + test_svn_configured_prefix "origin/" && rm -rf project && rm -f warning ' -test_expect_success 'clone with -s/-T/-b/-t without --prefix warns' ' +test_expect_success 'clone with -s/-T/-b/-t assumes --prefix=origin/' ' test ! -d project && git svn clone -s "$svnrepo"/project 2>warning && - grep -q prefix warning && - test_svn_configured_prefix "" && + test_must_fail grep -q prefix warning && + test_svn_configured_prefix "origin/" && rm -rf project && rm -f warning ' -test_expect_success 'init with -s/-T/-b/-t and --prefix does not warn' ' +test_expect_success 'init with -s/-T/-b/-t and --prefix "" still works' ' test ! -d project && - git svn init -s "$svnrepo"/project project --prefix="" 2>warning && + git svn init -s "$svnrepo"/project project --prefix "" 2>warning && test_must_fail grep -q prefix warning && test_svn_configured_prefix "" && rm -rf project && rm -f warning ' -test_expect_success 'clone with -s/-T/-b/-t and --prefix does not warn' ' +test_expect_success 'clone with -s/-T/-b/-t and --prefix "" still works' ' test ! -d project && - git svn clone -s "$svnrepo"/project --prefix="" 2>warning && + git svn clone -s "$svnrepo"/project --prefix "" 2>warning && test_must_fail grep -q prefix warning && test_svn_configured_prefix "" && rm -rf project && diff --git a/t/t9118-git-svn-funky-branch-names.sh b/t/t9118-git-svn-funky-branch-names.sh index 15f93b4c28..ed4d1369cc 100755 --- a/t/t9118-git-svn-funky-branch-names.sh +++ b/t/t9118-git-svn-funky-branch-names.sh @@ -41,20 +41,20 @@ test_expect_success 'test clone with funky branch names' ' git svn clone -s "$svnrepo/pr ject" project && ( cd project && - git rev-parse "refs/remotes/fun%20plugin" && - git rev-parse "refs/remotes/more%20fun%20plugin!" && - git rev-parse "refs/remotes/$scary_ref" && - git rev-parse "refs/remotes/%2Eleading_dot" && - git rev-parse "refs/remotes/trailing_dot%2E" && - git rev-parse "refs/remotes/trailing_dotlock%2Elock" && - git rev-parse "refs/remotes/$non_reflog" + git rev-parse "refs/remotes/origin/fun%20plugin" && + git rev-parse "refs/remotes/origin/more%20fun%20plugin!" && + git rev-parse "refs/remotes/origin/$scary_ref" && + git rev-parse "refs/remotes/origin/%2Eleading_dot" && + git rev-parse "refs/remotes/origin/trailing_dot%2E" && + git rev-parse "refs/remotes/origin/trailing_dotlock%2Elock" && + git rev-parse "refs/remotes/origin/$non_reflog" ) ' test_expect_success 'test dcommit to funky branch' " ( cd project && - git reset --hard 'refs/remotes/more%20fun%20plugin!' && + git reset --hard 'refs/remotes/origin/more%20fun%20plugin!' && echo hello >> foo && git commit -m 'hello' -- foo && git svn dcommit @@ -64,7 +64,7 @@ test_expect_success 'test dcommit to funky branch' " test_expect_success 'test dcommit to scary branch' ' ( cd project && - git reset --hard "refs/remotes/$scary_ref" && + git reset --hard "refs/remotes/origin/$scary_ref" && echo urls are scary >> foo && git commit -m "eep" -- foo && git svn dcommit @@ -74,7 +74,7 @@ test_expect_success 'test dcommit to scary branch' ' test_expect_success 'test dcommit to trailing_dotlock branch' ' ( cd project && - git reset --hard "refs/remotes/trailing_dotlock%2Elock" && + git reset --hard "refs/remotes/origin/trailing_dotlock%2Elock" && echo who names branches like this anyway? >> foo && git commit -m "bar" -- foo && git svn dcommit diff --git a/t/t9120-git-svn-clone-with-percent-escapes.sh b/t/t9120-git-svn-clone-with-percent-escapes.sh index 1d92c05035..1c84ce1023 100755 --- a/t/t9120-git-svn-clone-with-percent-escapes.sh +++ b/t/t9120-git-svn-clone-with-percent-escapes.sh @@ -58,19 +58,19 @@ test_expect_success 'test clone --stdlayout with percent escapes' ' git svn clone --stdlayout "$svnrepo/pr%20ject" percent && ( cd percent && - git rev-parse refs/remotes/trunk^0 && - git rev-parse refs/remotes/b^0 && - git rev-parse refs/remotes/tags/v1^0 + git rev-parse refs/remotes/origin/trunk^0 && + git rev-parse refs/remotes/origin/b^0 && + git rev-parse refs/remotes/origin/tags/v1^0 ) ' test_expect_success 'test clone -s with unescaped space' ' - git svn clone -s "$svnrepo/pr ject" space && + git svn clone -s "$svnrepo/pr ject" --prefix origin/ space && ( cd space && - git rev-parse refs/remotes/trunk^0 && - git rev-parse refs/remotes/b^0 && - git rev-parse refs/remotes/tags/v1^0 + git rev-parse refs/remotes/origin/trunk^0 && + git rev-parse refs/remotes/origin/b^0 && + git rev-parse refs/remotes/origin/tags/v1^0 ) ' diff --git a/t/t9125-git-svn-multi-glob-branch-names.sh b/t/t9125-git-svn-multi-glob-branch-names.sh index 096abd1fe5..0d53fc9014 100755 --- a/t/t9125-git-svn-multi-glob-branch-names.sh +++ b/t/t9125-git-svn-multi-glob-branch-names.sh @@ -20,14 +20,14 @@ test_expect_success 'test clone with multi-glob in branch names' ' git svn clone -T trunk -b branches/*/* -t tags \ "$svnrepo/project" project && (cd project && - git rev-parse "refs/remotes/v14.1/beta" && - git rev-parse "refs/remotes/v14.1/gold" + git rev-parse "refs/remotes/origin/v14.1/beta" && + git rev-parse "refs/remotes/origin/v14.1/gold" ) ' test_expect_success 'test dcommit to multi-globbed branch' " (cd project && - git reset --hard 'refs/remotes/v14.1/gold' && + git reset --hard 'refs/remotes/origin/v14.1/gold' && echo hello >> foo && git commit -m 'hello' -- foo && git svn dcommit diff --git a/t/t9128-git-svn-cmd-branch.sh b/t/t9128-git-svn-cmd-branch.sh index 4b034a67f3..4e95f791db 100755 --- a/t/t9128-git-svn-cmd-branch.sh +++ b/t/t9128-git-svn-cmd-branch.sh @@ -29,30 +29,30 @@ test_expect_success 'initialize svnrepo' ' test_expect_success 'import into git' ' git svn init --stdlayout "$svnrepo" && git svn fetch && - git checkout remotes/trunk + git checkout remotes/origin/trunk ' test_expect_success 'git svn branch tests' ' git svn branch a && base=$(git rev-parse HEAD:) && - test $base = $(git rev-parse remotes/a:) && + test $base = $(git rev-parse remotes/origin/a:) && git svn branch -m "created branch b blah" b && - test $base = $(git rev-parse remotes/b:) && + test $base = $(git rev-parse remotes/origin/b:) && test_must_fail git branch -m "no branchname" && git svn branch -n c && - test_must_fail git rev-parse remotes/c && + test_must_fail git rev-parse remotes/origin/c && test_must_fail git svn branch a && git svn branch -t tag1 && - test $base = $(git rev-parse remotes/tags/tag1:) && + test $base = $(git rev-parse remotes/origin/tags/tag1:) && git svn branch --tag tag2 && - test $base = $(git rev-parse remotes/tags/tag2:) && + test $base = $(git rev-parse remotes/origin/tags/tag2:) && git svn tag tag3 && - test $base = $(git rev-parse remotes/tags/tag3:) && + test $base = $(git rev-parse remotes/origin/tags/tag3:) && git svn tag -m "created tag4 foo" tag4 && - test $base = $(git rev-parse remotes/tags/tag4:) && + test $base = $(git rev-parse remotes/origin/tags/tag4:) && test_must_fail git svn tag -m "no tagname" && git svn tag -n tag5 && - test_must_fail git rev-parse remotes/tags/tag5 && + test_must_fail git rev-parse remotes/origin/tags/tag5 && test_must_fail git svn tag tag1 ' diff --git a/t/t9135-git-svn-moved-branch-empty-file.sh b/t/t9135-git-svn-moved-branch-empty-file.sh index 5280e5f1e4..93db45db7d 100755 --- a/t/t9135-git-svn-moved-branch-empty-file.sh +++ b/t/t9135-git-svn-moved-branch-empty-file.sh @@ -12,7 +12,7 @@ test_expect_success 'clone using git svn' 'git svn clone -s "$svnrepo" x' test_expect_success 'test that b1 exists and is empty' ' ( cd x && - git reset --hard branch-c && + git reset --hard origin/branch-c && test -f b1 && ! test -s b1 ) diff --git a/t/t9138-git-svn-authors-prog.sh b/t/t9138-git-svn-authors-prog.sh index 83cc5fc9d1..2937f4c265 100755 --- a/t/t9138-git-svn-authors-prog.sh +++ b/t/t9138-git-svn-authors-prog.sh @@ -7,40 +7,39 @@ test_description='git svn authors prog tests' . ./lib-git-svn.sh -cat > svn-authors-prog <<'EOF' -#!/usr/bin/perl -$_ = shift; -if (s/-sub$//) { - print "$_ <$_\@sub.example.com>\n"; -} -else { - print "$_ <$_\@example.com>\n"; -} +write_script svn-authors-prog "$PERL_PATH" <<-\EOF + $_ = shift; + if (s/-sub$//) { + print "$_ <$_\@sub.example.com>\n"; + } else { + print "$_ <$_\@example.com>\n"; + } EOF -chmod +x svn-authors-prog -cat > svn-authors <<'EOF' -ff = FFFFFFF FFFFFFF <fFf@other.example.com> -EOF +test_expect_success 'svn-authors setup' ' + cat >svn-authors <<-\EOF + ff = FFFFFFF FFFFFFF <fFf@other.example.com> + EOF +' test_expect_success 'setup svnrepo' ' for i in aa bb cc-sub dd-sub ee-foo ff do svn mkdir -m $i --username $i "$svnrepo"/$i done - ' +' test_expect_success 'import authors with prog and file' ' git svn clone --authors-prog=./svn-authors-prog \ --authors-file=svn-authors "$svnrepo" x - ' +' test_expect_success 'imported 6 revisions successfully' ' ( cd x test "`git rev-list refs/remotes/git-svn | wc -l`" -eq 6 ) - ' +' test_expect_success 'authors-prog ran correctly' ' ( @@ -56,7 +55,7 @@ test_expect_success 'authors-prog ran correctly' ' git rev-list -1 --pretty=raw refs/remotes/git-svn~5 | \ grep "^author aa <aa@example\.com> " ) - ' +' test_expect_success 'authors-file overrode authors-prog' ' ( @@ -64,7 +63,7 @@ test_expect_success 'authors-file overrode authors-prog' ' git rev-list -1 --pretty=raw refs/remotes/git-svn | \ grep "^author FFFFFFF FFFFFFF <fFf@other\.example\.com> " ) - ' +' git --git-dir=x/.git config --unset svn.authorsfile git --git-dir=x/.git config --unset svn.authorsprog diff --git a/t/t9141-git-svn-multiple-branches.sh b/t/t9141-git-svn-multiple-branches.sh index 3cd06718eb..8e7f7d68b7 100755 --- a/t/t9141-git-svn-multiple-branches.sh +++ b/t/t9141-git-svn-multiple-branches.sh @@ -66,18 +66,18 @@ test_expect_success 'clone multiple branch and tag paths' ' -t tags_A/* --tags tags_B \ "$svnrepo/project" git_project && ( cd git_project && - git rev-parse refs/remotes/first && - git rev-parse refs/remotes/second && - git rev-parse refs/remotes/1 && - git rev-parse refs/remotes/2 && - git rev-parse refs/remotes/tags/1.0 && - git rev-parse refs/remotes/tags/2.0 && - git rev-parse refs/remotes/tags/3.0 && - git rev-parse refs/remotes/tags/4.0 && - git rev-parse refs/remotes/tags/v5 && - git rev-parse refs/remotes/tags/v6 && - git rev-parse refs/remotes/tags/v7 && - git rev-parse refs/remotes/tags/v8 + git rev-parse refs/remotes/origin/first && + git rev-parse refs/remotes/origin/second && + git rev-parse refs/remotes/origin/1 && + git rev-parse refs/remotes/origin/2 && + git rev-parse refs/remotes/origin/tags/1.0 && + git rev-parse refs/remotes/origin/tags/2.0 && + git rev-parse refs/remotes/origin/tags/3.0 && + git rev-parse refs/remotes/origin/tags/4.0 && + git rev-parse refs/remotes/origin/tags/v5 && + git rev-parse refs/remotes/origin/tags/v6 && + git rev-parse refs/remotes/origin/tags/v7 && + git rev-parse refs/remotes/origin/tags/v8 ) ' @@ -85,8 +85,8 @@ test_expect_success 'Multiple branch or tag paths require -d' ' ( cd git_project && test_must_fail git svn branch -m "No new branch" Nope && test_must_fail git svn tag -m "No new tag" Tagless && - test_must_fail git rev-parse refs/remotes/Nope && - test_must_fail git rev-parse refs/remotes/tags/Tagless + test_must_fail git rev-parse refs/remotes/origin/Nope && + test_must_fail git rev-parse refs/remotes/origin/tags/Tagless ) && ( cd svn_project && svn_cmd up && diff --git a/t/t9145-git-svn-master-branch.sh b/t/t9145-git-svn-master-branch.sh index 16852d26ae..6559137493 100755 --- a/t/t9145-git-svn-master-branch.sh +++ b/t/t9145-git-svn-master-branch.sh @@ -17,7 +17,7 @@ test_expect_success 'git svn clone --stdlayout sets up trunk as master' ' git svn clone -s "$svnrepo" g && ( cd g && - test x`git rev-parse --verify refs/remotes/trunk^0` = \ + test x`git rev-parse --verify refs/remotes/origin/trunk^0` = \ x`git rev-parse --verify refs/heads/master^0` ) ' diff --git a/t/t9155-git-svn-fetch-deleted-tag.sh b/t/t9155-git-svn-fetch-deleted-tag.sh index a486a98f84..184336f346 100755 --- a/t/t9155-git-svn-fetch-deleted-tag.sh +++ b/t/t9155-git-svn-fetch-deleted-tag.sh @@ -35,8 +35,8 @@ test_expect_success 'fetch deleted tags from same revision with checksum error' cd git_project && git svn fetch && - git diff --exit-code mybranch:trunk/subdir/file tags/mytag:file && - git diff --exit-code master:subdir/file tags/mytag^:file + git diff --exit-code origin/mybranch:trunk/subdir/file origin/tags/mytag:file && + git diff --exit-code master:subdir/file origin/tags/mytag^:file ' test_done diff --git a/t/t9156-git-svn-fetch-deleted-tag-2.sh b/t/t9156-git-svn-fetch-deleted-tag-2.sh index 5ce7e2f3b0..7a6e33ba3c 100755 --- a/t/t9156-git-svn-fetch-deleted-tag-2.sh +++ b/t/t9156-git-svn-fetch-deleted-tag-2.sh @@ -36,9 +36,9 @@ test_expect_success 'fetch deleted tags from same revision with no checksum erro cd git_project && git svn fetch && - git diff --exit-code master:subdir3/file tags/mytag:file && - git diff --exit-code master:subdir2/file tags/mytag^:file && - git diff --exit-code master:subdir1/file tags/mytag^^:file + git diff --exit-code master:subdir3/file origin/tags/mytag:file && + git diff --exit-code master:subdir2/file origin/tags/mytag^:file && + git diff --exit-code master:subdir1/file origin/tags/mytag^^:file ' test_done diff --git a/t/t9161-git-svn-mergeinfo-push.sh b/t/t9161-git-svn-mergeinfo-push.sh index 1eab7015c7..6cb0909afe 100755 --- a/t/t9161-git-svn-mergeinfo-push.sh +++ b/t/t9161-git-svn-mergeinfo-push.sh @@ -18,8 +18,8 @@ test_expect_success 'load svn dump' " test_expect_success 'propagate merge information' ' git config svn.pushmergeinfo yes && - git checkout svnb1 && - git merge --no-ff svnb2 && + git checkout origin/svnb1 && + git merge --no-ff origin/svnb2 && git svn dcommit ' @@ -29,7 +29,7 @@ test_expect_success 'check svn:mergeinfo' ' ' test_expect_success 'merge another branch' ' - git merge --no-ff svnb3 && + git merge --no-ff origin/svnb3 && git svn dcommit ' @@ -40,7 +40,7 @@ test_expect_success 'check primary parent mergeinfo respected' ' ' test_expect_success 'merge existing merge' ' - git merge --no-ff svnb4 && + git merge --no-ff origin/svnb4 && git svn dcommit ' @@ -53,7 +53,7 @@ test_expect_success "check both parents' mergeinfo respected" ' ' test_expect_success 'make further commits to branch' ' - git checkout svnb2 && + git checkout origin/svnb2 && touch newb2file && git add newb2file && git commit -m "later b2 commit" && @@ -64,8 +64,8 @@ test_expect_success 'make further commits to branch' ' ' test_expect_success 'second forward merge' ' - git checkout svnb1 && - git merge --no-ff svnb2 && + git checkout origin/svnb1 && + git merge --no-ff origin/svnb2 && git svn dcommit ' @@ -78,8 +78,8 @@ test_expect_success 'check new mergeinfo added' ' ' test_expect_success 'reintegration merge' ' - git checkout svnb4 && - git merge --no-ff svnb1 && + git checkout origin/svnb4 && + git merge --no-ff origin/svnb1 && git svn dcommit ' @@ -92,11 +92,11 @@ test_expect_success 'check reintegration mergeinfo' ' ' test_expect_success 'dcommit a merge at the top of a stack' ' - git checkout svnb1 && + git checkout origin/svnb1 && touch anotherfile && git add anotherfile && git commit -m "a commit" && - git merge svnb4 && + git merge origin/svnb4 && git svn dcommit ' diff --git a/t/t9163-git-svn-reset-clears-caches.sh b/t/t9163-git-svn-reset-clears-caches.sh index cd4c662ba2..d6245cee08 100755 --- a/t/t9163-git-svn-reset-clears-caches.sh +++ b/t/t9163-git-svn-reset-clears-caches.sh @@ -70,9 +70,9 @@ test_expect_success 'rebase looses SVN merge (m)' ' # test_expect_success 'reset and fetch gets the SVN merge (m) correctly' ' git svn reset -r 3 && - git reset --hard trunk && + git reset --hard origin/trunk && git svn fetch && - test 2 = $(git cat-file -p trunk|grep parent|wc -l) + test 2 = $(git cat-file -p origin/trunk|grep parent|wc -l) ' test_done diff --git a/t/t9165-git-svn-fetch-merge-branch-of-branch.sh b/t/t9165-git-svn-fetch-merge-branch-of-branch.sh index 13ae7e33f9..fa3ef3b1f7 100755 --- a/t/t9165-git-svn-fetch-merge-branch-of-branch.sh +++ b/t/t9165-git-svn-fetch-merge-branch-of-branch.sh @@ -53,7 +53,7 @@ test_expect_success 'clone svn repo' ' ' test_expect_success 'verify merge commit' 'x=$(git rev-parse HEAD^2) && - y=$(git rev-parse branch2) && + y=$(git rev-parse origin/branch2) && test "x$x" = "x$y" ' diff --git a/t/t9166-git-svn-fetch-merge-branch-of-branch2.sh b/t/t9166-git-svn-fetch-merge-branch-of-branch2.sh index af0ec0e2e3..52f2e46a5b 100755 --- a/t/t9166-git-svn-fetch-merge-branch-of-branch2.sh +++ b/t/t9166-git-svn-fetch-merge-branch-of-branch2.sh @@ -46,7 +46,7 @@ test_expect_success 'clone svn repo' ' ' test_expect_success 'verify merge commit' 'x=$(git rev-parse HEAD^2) && - y=$(git rev-parse branch2) && + y=$(git rev-parse origin/branch2) && test "x$x" = "x$y" ' diff --git a/t/t9167-git-svn-cmd-branch-subproject.sh b/t/t9167-git-svn-cmd-branch-subproject.sh index 53def876ed..ba35fc06fc 100755 --- a/t/t9167-git-svn-cmd-branch-subproject.sh +++ b/t/t9167-git-svn-cmd-branch-subproject.sh @@ -31,7 +31,7 @@ test_expect_success 'import into git' ' git svn init --trunk=trunk/project --branches=branches/*/project \ --tags=tags/*/project "$svnrepo" && git svn fetch && - git checkout remotes/trunk + git checkout remotes/origin/trunk ' test_expect_success 'git svn branch tests' ' diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh index 27263dfb80..5fc9ef262a 100755 --- a/t/t9300-fast-import.sh +++ b/t/t9300-fast-import.sh @@ -2999,4 +2999,22 @@ test_expect_success 'T: ls root tree' ' test_cmp expect actual ' +test_expect_success 'T: delete branch' ' + git branch to-delete && + git fast-import <<-EOF && + reset refs/heads/to-delete + from 0000000000000000000000000000000000000000 + EOF + test_must_fail git rev-parse --verify refs/heads/to-delete +' + +test_expect_success 'T: empty reset doesnt delete branch' ' + git branch not-to-delete && + git fast-import <<-EOF && + reset refs/heads/not-to-delete + EOF + git show-ref && + git rev-parse --verify refs/heads/not-to-delete +' + test_done diff --git a/t/t9350-fast-export.sh b/t/t9350-fast-export.sh index 2312dec8f0..66c8b0a371 100755 --- a/t/t9350-fast-export.sh +++ b/t/t9350-fast-export.sh @@ -504,4 +504,22 @@ test_expect_success 'refs are updated even if no commits need to be exported' ' test_cmp expected actual ' +test_expect_success 'use refspec' ' + git fast-export --refspec refs/heads/master:refs/heads/foobar master | \ + grep "^commit " | sort | uniq > actual && + echo "commit refs/heads/foobar" > expected && + test_cmp expected actual +' + +test_expect_success 'delete refspec' ' + git branch to-delete && + git fast-export --refspec :refs/heads/to-delete to-delete ^to-delete > actual && + cat > expected <<-EOF && + reset refs/heads/to-delete + from 0000000000000000000000000000000000000000 + + EOF + test_cmp expected actual +' + test_done diff --git a/t/t9800-git-p4-basic.sh b/t/t9800-git-p4-basic.sh index 665607c9cb..5b562122a1 100755 --- a/t/t9800-git-p4-basic.sh +++ b/t/t9800-git-p4-basic.sh @@ -145,7 +145,7 @@ test_expect_success 'exit when p4 fails to produce marshaled output' ' test_expect_code 1 git p4 clone --dest="$git" //depot >errs 2>&1 ) && cat errs && - ! test_i18ngrep Traceback errs + test_i18ngrep ! Traceback errs ' # Hide a file from p4d, make sure we catch its complaint. This won't fail in diff --git a/t/t9807-git-p4-submit.sh b/t/t9807-git-p4-submit.sh index 4caf36e006..1f74a88385 100755 --- a/t/t9807-git-p4-submit.sh +++ b/t/t9807-git-p4-submit.sh @@ -403,7 +403,8 @@ test_expect_success 'submit --prepare-p4-only' ' git commit -m "prep only add" && git p4 submit --prepare-p4-only >out && test_i18ngrep "prepared for submission" out && - test_i18ngrep "must be deleted" out + test_i18ngrep "must be deleted" out && + test_i18ngrep ! "everything below this line is just the diff" out ) && ( cd "$cli" && diff --git a/t/t9814-git-p4-rename.sh b/t/t9814-git-p4-rename.sh index be802e0e16..95f4421f71 100755 --- a/t/t9814-git-p4-rename.sh +++ b/t/t9814-git-p4-rename.sh @@ -177,7 +177,10 @@ test_expect_success 'detect copies' ' level=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/C0*//") && test -n "$level" && test "$level" -gt 0 && test "$level" -lt 98 && src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) && - test "$src" = file10 -o "$src" = file11 && + case "$src" in + file10 | file11) : ;; # happy + *) false ;; # not + && git config git-p4.detectCopies $(($level + 2)) && git p4 submit && p4 filelog //depot/file12 && @@ -191,7 +194,10 @@ test_expect_success 'detect copies' ' level=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f1 | cut -d" " -f5 | sed "s/C0*//") && test -n "$level" && test "$level" -gt 2 && test "$level" -lt 100 && src=$(git diff-tree -r -C --find-copies-harder HEAD | sed 1d | cut -f2) && - test "$src" = file10 -o "$src" = file11 -o "$src" = file12 && + case "$src" in + file10 | file11 | file12) : ;; # happy + *) false ;; # not + && git config git-p4.detectCopies $(($level - 2)) && git p4 submit && p4 filelog //depot/file13 && diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 2d4beb5e50..f10a75290e 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -212,9 +212,18 @@ test_expect_success '__gitdir - non-existing $GIT_DIR' ' ) ' +function pwd_P_W () { + if test_have_prereq MINGW + then + pwd -W + else + pwd -P + fi +} + test_expect_success '__gitdir - gitfile in cwd' ' - echo "$(pwd -P)/otherrepo/.git" >expected && - echo "gitdir: $TRASH_DIRECTORY/otherrepo/.git" >subdir/.git && + echo "$(pwd_P_W)/otherrepo/.git" >expected && + echo "gitdir: $(pwd_P_W)/otherrepo/.git" >subdir/.git && test_when_finished "rm -f subdir/.git" && ( cd subdir && @@ -224,8 +233,8 @@ test_expect_success '__gitdir - gitfile in cwd' ' ' test_expect_success '__gitdir - gitfile in parent' ' - echo "$(pwd -P)/otherrepo/.git" >expected && - echo "gitdir: $TRASH_DIRECTORY/otherrepo/.git" >subdir/.git && + echo "$(pwd_P_W)/otherrepo/.git" >expected && + echo "gitdir: $(pwd_P_W)/otherrepo/.git" >subdir/.git && test_when_finished "rm -f subdir/.git" && ( cd subdir/subsubdir && @@ -550,6 +559,33 @@ test_expect_success 'complete files' ' test_completion "git add mom" "momified" ' +test_expect_success "completion uses <cmd> completion for alias: !sh -c 'git <cmd> ...'" ' + test_config alias.co "!sh -c '"'"'git checkout ...'"'"'" && + test_completion "git co m" <<-\EOF + master Z + mybranch Z + mytag Z + EOF +' + +test_expect_success 'completion uses <cmd> completion for alias: !f () { VAR=val git <cmd> ... }' ' + test_config alias.co "!f () { VAR=val git checkout ... ; } f" && + test_completion "git co m" <<-\EOF + master Z + mybranch Z + mytag Z + EOF +' + +test_expect_success 'completion used <cmd> completion for alias: !f() { : git <cmd> ; ... }' ' + test_config alias.co "!f() { : git checkout ; if ... } f" && + test_completion "git co m" <<-\EOF + master Z + mybranch Z + mytag Z + EOF +' + test_expect_failure 'complete with tilde expansion' ' git init tmp && cd tmp && test_when_finished "cd .. && rm -rf tmp" && diff --git a/t/t9903-bash-prompt.sh b/t/t9903-bash-prompt.sh index 59f875e830..9150984184 100755 --- a/t/t9903-bash-prompt.sh +++ b/t/t9903-bash-prompt.sh @@ -452,53 +452,53 @@ test_expect_success 'prompt - format string starting with dash' ' ' test_expect_success 'prompt - pc mode' ' - printf "BEFORE: (master):AFTER" >expected && + printf "BEFORE: (\${__git_ps1_branch_name}):AFTER\\nmaster" >expected && printf "" >expected_output && ( __git_ps1 "BEFORE:" ":AFTER" >"$actual" && test_cmp expected_output "$actual" && - printf "%s" "$PS1" >"$actual" + printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" ) && test_cmp expected "$actual" ' test_expect_success 'prompt - bash color pc mode - branch name' ' - printf "BEFORE: (${c_green}master${c_clear}):AFTER" >expected && + printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear}):AFTER\\nmaster" >expected && ( GIT_PS1_SHOWCOLORHINTS=y && __git_ps1 "BEFORE:" ":AFTER" >"$actual" - printf "%s" "$PS1" >"$actual" + printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" ) && test_cmp expected "$actual" ' test_expect_success 'prompt - bash color pc mode - detached head' ' - printf "BEFORE: (${c_red}(%s...)${c_clear}):AFTER" $(git log -1 --format="%h" b1^) >expected && + printf "BEFORE: (${c_red}\${__git_ps1_branch_name}${c_clear}):AFTER\\n(%s...)" $(git log -1 --format="%h" b1^) >expected && git checkout b1^ && test_when_finished "git checkout master" && ( GIT_PS1_SHOWCOLORHINTS=y && __git_ps1 "BEFORE:" ":AFTER" && - printf "%s" "$PS1" >"$actual" + printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" ) && test_cmp expected "$actual" ' test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty worktree' ' - printf "BEFORE: (${c_green}master${c_clear} ${c_red}*${c_clear}):AFTER" >expected && + printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_red}*${c_clear}):AFTER\\nmaster" >expected && echo "dirty" >file && test_when_finished "git reset --hard" && ( GIT_PS1_SHOWDIRTYSTATE=y && GIT_PS1_SHOWCOLORHINTS=y && __git_ps1 "BEFORE:" ":AFTER" && - printf "%s" "$PS1" >"$actual" + printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" ) && test_cmp expected "$actual" ' test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index' ' - printf "BEFORE: (${c_green}master${c_clear} ${c_green}+${c_clear}):AFTER" >expected && + printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_green}+${c_clear}):AFTER\\nmaster" >expected && echo "dirty" >file && test_when_finished "git reset --hard" && git add -u && @@ -506,13 +506,13 @@ test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirt GIT_PS1_SHOWDIRTYSTATE=y && GIT_PS1_SHOWCOLORHINTS=y && __git_ps1 "BEFORE:" ":AFTER" && - printf "%s" "$PS1" >"$actual" + printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" ) && test_cmp expected "$actual" ' test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirty index and worktree' ' - printf "BEFORE: (${c_green}master${c_clear} ${c_red}*${c_green}+${c_clear}):AFTER" >expected && + printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_red}*${c_green}+${c_clear}):AFTER\\nmaster" >expected && echo "dirty index" >file && test_when_finished "git reset --hard" && git add -u && @@ -521,25 +521,25 @@ test_expect_success 'prompt - bash color pc mode - dirty status indicator - dirt GIT_PS1_SHOWCOLORHINTS=y && GIT_PS1_SHOWDIRTYSTATE=y && __git_ps1 "BEFORE:" ":AFTER" && - printf "%s" "$PS1" >"$actual" + printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" ) && test_cmp expected "$actual" ' test_expect_success 'prompt - bash color pc mode - dirty status indicator - before root commit' ' - printf "BEFORE: (${c_green}master${c_clear} ${c_green}#${c_clear}):AFTER" >expected && + printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_green}#${c_clear}):AFTER\\nmaster" >expected && ( GIT_PS1_SHOWDIRTYSTATE=y && GIT_PS1_SHOWCOLORHINTS=y && cd otherrepo && __git_ps1 "BEFORE:" ":AFTER" && - printf "%s" "$PS1" >"$actual" + printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" ) && test_cmp expected "$actual" ' test_expect_success 'prompt - bash color pc mode - inside .git directory' ' - printf "BEFORE: (${c_green}GIT_DIR!${c_clear}):AFTER" >expected && + printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear}):AFTER\\nGIT_DIR!" >expected && echo "dirty" >file && test_when_finished "git reset --hard" && ( @@ -547,13 +547,13 @@ test_expect_success 'prompt - bash color pc mode - inside .git directory' ' GIT_PS1_SHOWCOLORHINTS=y && cd .git && __git_ps1 "BEFORE:" ":AFTER" && - printf "%s" "$PS1" >"$actual" + printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" ) && test_cmp expected "$actual" ' test_expect_success 'prompt - bash color pc mode - stash status indicator' ' - printf "BEFORE: (${c_green}master${c_clear} ${c_lblue}\$${c_clear}):AFTER" >expected && + printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_lblue}\$${c_clear}):AFTER\\nmaster" >expected && echo 2 >file && git stash && test_when_finished "git stash drop" && @@ -561,18 +561,18 @@ test_expect_success 'prompt - bash color pc mode - stash status indicator' ' GIT_PS1_SHOWSTASHSTATE=y && GIT_PS1_SHOWCOLORHINTS=y && __git_ps1 "BEFORE:" ":AFTER" && - printf "%s" "$PS1" >"$actual" + printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" ) && test_cmp expected "$actual" ' test_expect_success 'prompt - bash color pc mode - untracked files status indicator' ' - printf "BEFORE: (${c_green}master${c_clear} ${c_red}%%${c_clear}):AFTER" >expected && + printf "BEFORE: (${c_green}\${__git_ps1_branch_name}${c_clear} ${c_red}%%${c_clear}):AFTER\\nmaster" >expected && ( GIT_PS1_SHOWUNTRACKEDFILES=y && GIT_PS1_SHOWCOLORHINTS=y && __git_ps1 "BEFORE:" ":AFTER" && - printf "%s" "$PS1" >"$actual" + printf "%s\\n%s" "$PS1" "${__git_ps1_branch_name}" >"$actual" ) && test_cmp expected "$actual" ' @@ -582,7 +582,7 @@ test_expect_success 'prompt - zsh color pc mode' ' ( ZSH_VERSION=5.0.0 && GIT_PS1_SHOWCOLORHINTS=y && - __git_ps1 "BEFORE:" ":AFTER" >"$actual" + __git_ps1 "BEFORE:" ":AFTER" && printf "%s" "$PS1" >"$actual" ) && test_cmp expected "$actual" diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 158e10a67e..dafd6ad21a 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -489,6 +489,17 @@ test_path_is_dir () { fi } +# Check if the directory exists and is empty as expected, barf otherwise. +test_dir_is_empty () { + test_path_is_dir "$1" && + if test -n "$(ls -a1 "$1" | egrep -v '^\.\.?$')" + then + echo "Directory '$1' is not empty, it contains:" + ls -la "$1" + return 1 + fi +} + test_path_is_missing () { if [ -e "$1" ] then @@ -542,7 +553,7 @@ test_must_fail () { if test $exit_code = 0; then echo >&2 "test_must_fail: command succeeded: $*" return 1 - elif test $exit_code -gt 129 -a $exit_code -le 192; then + elif test $exit_code -gt 129 && test $exit_code -le 192; then echo >&2 "test_must_fail: died by signal: $*" return 1 elif test $exit_code = 127; then @@ -569,7 +580,7 @@ test_must_fail () { test_might_fail () { "$@" exit_code=$? - if test $exit_code -gt 129 -a $exit_code -le 192; then + if test $exit_code -gt 129 && test $exit_code -le 192; then echo >&2 "test_might_fail: died by signal: $*" return 1 elif test $exit_code = 127; then @@ -617,6 +628,12 @@ test_cmp() { $GIT_TEST_CMP "$@" } +# test_cmp_bin - helper to compare binary files + +test_cmp_bin() { + cmp "$@" +} + # Check if the file expected to be empty is indeed empty, and barfs # otherwise. @@ -717,6 +734,11 @@ test_ln_s_add () { fi } +# This function writes out its parameters, one per line +test_write_lines () { + printf "%s\n" "$@" +} + perl () { command "$PERL_PATH" "$@" } diff --git a/t/test-lib.sh b/t/test-lib.sh index c081668dfe..b1bc65bfb5 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -91,6 +91,7 @@ unset VISUAL EMAIL LANGUAGE COLUMNS $("$PERL_PATH" -e ' VALGRIND UNZIP PERF_ + CURL_VERBOSE )); my @vars = grep(/^GIT_/ && !/^GIT_($ok)/o, @env); print join("\n", @vars); @@ -108,6 +109,10 @@ export GIT_AUTHOR_EMAIL GIT_AUTHOR_NAME export GIT_COMMITTER_EMAIL GIT_COMMITTER_NAME export EDITOR +# Tests using GIT_TRACE typically don't want <timestamp> <file>:<line> output +GIT_TRACE_BARE=1 +export GIT_TRACE_BARE + if test -n "${TEST_GIT_INDEX_VERSION:+isset}" then GIT_INDEX_VERSION="$TEST_GIT_INDEX_VERSION" @@ -191,6 +196,14 @@ do immediate=t; shift ;; -l|--l|--lo|--lon|--long|--long-|--long-t|--long-te|--long-tes|--long-test|--long-tests) GIT_TEST_LONG=t; export GIT_TEST_LONG; shift ;; + -r) + shift; test "$#" -ne 0 || { + echo 'error: -r requires an argument' >&2; + exit 1; + } + run_list=$1; shift ;; + --run=*) + run_list=$(expr "z$1" : 'z[^=]*=\(.*\)'); shift ;; -h|--h|--he|--hel|--help) help=t; shift ;; -v|--v|--ve|--ver|--verb|--verbo|--verbos|--verbose) @@ -366,6 +379,99 @@ match_pattern_list () { return 1 } +match_test_selector_list () { + title="$1" + shift + arg="$1" + shift + test -z "$1" && return 0 + + # Both commas and whitespace are accepted as separators. + OLDIFS=$IFS + IFS=' ,' + set -- $1 + IFS=$OLDIFS + + # If the first selector is negative we include by default. + include= + case "$1" in + !*) include=t ;; + esac + + for selector + do + orig_selector=$selector + + positive=t + case "$selector" in + !*) + positive= + selector=${selector##?} + ;; + esac + + test -z "$selector" && continue + + case "$selector" in + *-*) + if expr "z${selector%%-*}" : "z[0-9]*[^0-9]" >/dev/null + then + echo "error: $title: invalid non-numeric in range" \ + "start: '$orig_selector'" >&2 + exit 1 + fi + if expr "z${selector#*-}" : "z[0-9]*[^0-9]" >/dev/null + then + echo "error: $title: invalid non-numeric in range" \ + "end: '$orig_selector'" >&2 + exit 1 + fi + ;; + *) + if expr "z$selector" : "z[0-9]*[^0-9]" >/dev/null + then + echo "error: $title: invalid non-numeric in test" \ + "selector: '$orig_selector'" >&2 + exit 1 + fi + esac + + # Short cut for "obvious" cases + test -z "$include" && test -z "$positive" && continue + test -n "$include" && test -n "$positive" && continue + + case "$selector" in + -*) + if test $arg -le ${selector#-} + then + include=$positive + fi + ;; + *-) + if test $arg -ge ${selector%-} + then + include=$positive + fi + ;; + *-*) + if test ${selector%%-*} -le $arg \ + && test $arg -le ${selector#*-} + then + include=$positive + fi + ;; + *) + if test $arg -eq $selector + then + include=$positive + fi + ;; + esac + done + + test -n "$include" +} + maybe_teardown_verbose () { test -z "$verbose_only" && return exec 4>/dev/null 3>/dev/null @@ -452,25 +558,35 @@ test_finish_ () { test_skip () { to_skip= + skipped_reason= if match_pattern_list $this_test.$test_count $GIT_SKIP_TESTS then to_skip=t + skipped_reason="GIT_SKIP_TESTS" fi 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" != "$test_prereq" then of_prereq=" of $test_prereq" fi + skipped_reason="missing $missing_prereq${of_prereq}" + fi + if test -z "$to_skip" && test -n "$run_list" && + ! match_test_selector_list '--run' $test_count "$run_list" + then + to_skip=t + skipped_reason="--run" + fi + case "$to_skip" in + t) say_color skip >&3 "skipping test: $@" - say_color skip "ok $test_count # skip $1 (missing $missing_prereq${of_prereq})" + say_color skip "ok $test_count # skip $1 ($skipped_reason)" : true ;; *) @@ -864,6 +980,14 @@ test_lazy_prereq AUTOIDENT ' git var GIT_AUTHOR_IDENT ' +test_lazy_prereq EXPENSIVE ' + test -n "$GIT_TEST_LONG" +' + +test_lazy_prereq USR_BIN_TIME ' + test -x /usr/bin/time +' + # When the tests are run as root, permission tests will report that # things are writable when they shouldn't be. test -w / || test_set_prereq SANITY |