diff options
Diffstat (limited to 't')
118 files changed, 2366 insertions, 570 deletions
@@ -1,7 +1,7 @@ -Core GIT Tests +Core Git Tests ============== -This directory holds many test scripts for core GIT tools. The +This directory holds many test scripts for core Git tools. The first part of this short document describes how to run the tests and read their output. @@ -1117,21 +1117,21 @@ Tips for Writing Tests As with any programming projects, existing programs are the best source of the information. However, do _not_ emulate t0000-basic.sh when writing your tests. The test is special in -that it tries to validate the very core of GIT. For example, it +that it tries to validate the very core of Git. For example, it knows that there will be 256 subdirectories under .git/objects/, and it knows that the object ID of an empty tree is a certain 40-byte string. This is deliberately done so in t0000-basic.sh because the things the very basic core test tries to achieve is -to serve as a basis for people who are changing the GIT internal +to serve as a basis for people who are changing the Git internals drastically. For these people, after making certain changes, not seeing failures from the basic test _is_ a failure. And -such drastic changes to the core GIT that even changes these +such drastic changes to the core Git that even changes these otherwise supposedly stable object IDs should be accompanied by an update to t0000-basic.sh. However, other tests that simply rely on basic parts of the core -GIT working properly should not have that level of intimate -knowledge of the core GIT internals. If all the test scripts +Git working properly should not have that level of intimate +knowledge of the core Git internals. If all the test scripts hardcoded the object IDs like t0000-basic.sh does, that defeats the purpose of t0000-basic.sh, which is to isolate that level of validation in one place. Your test also ends up needing diff --git a/t/helper/test-oid-array.c b/t/helper/test-oid-array.c index ce9fd5f091..b16cd0b11b 100644 --- a/t/helper/test-oid-array.c +++ b/t/helper/test-oid-array.c @@ -12,6 +12,9 @@ int cmd__oid_array(int argc, const char **argv) { struct oid_array array = OID_ARRAY_INIT; struct strbuf line = STRBUF_INIT; + int nongit_ok; + + setup_git_directory_gently(&nongit_ok); while (strbuf_getline(&line, stdin) != EOF) { const char *arg; diff --git a/t/helper/test-pkt-line.c b/t/helper/test-pkt-line.c index 12ca698e17..69152958e5 100644 --- a/t/helper/test-pkt-line.c +++ b/t/helper/test-pkt-line.c @@ -46,6 +46,9 @@ static void unpack(void) case PACKET_READ_DELIM: printf("0001\n"); break; + case PACKET_READ_RESPONSE_END: + printf("0002\n"); + break; } } } @@ -75,6 +78,7 @@ static void unpack_sideband(void) case PACKET_READ_FLUSH: return; case PACKET_READ_DELIM: + case PACKET_READ_RESPONSE_END: break; } } diff --git a/t/helper/test-reach.c b/t/helper/test-reach.c index a0272178b7..14a3655442 100644 --- a/t/helper/test-reach.c +++ b/t/helper/test-reach.c @@ -67,7 +67,7 @@ int cmd__reach(int ac, const char **av) die("failed to load commit for input %s resulting in oid %s\n", buf.buf, oid_to_hex(&oid)); - c = object_as_type(r, peeled, OBJ_COMMIT, 0); + c = object_as_type(peeled, OBJ_COMMIT, 0); if (!c) die("failed to load commit for input %s resulting in oid %s\n", @@ -108,7 +108,7 @@ int cmd__reach(int ac, const char **av) else if (!strcmp(av[1], "in_merge_bases")) printf("%s(A,B):%d\n", av[1], in_merge_bases(A, B)); else if (!strcmp(av[1], "is_descendant_of")) - printf("%s(A,X):%d\n", av[1], is_descendant_of(A, X)); + printf("%s(A,X):%d\n", av[1], repo_is_descendant_of(r, A, X)); else if (!strcmp(av[1], "get_merge_bases_many")) { struct commit_list *list = get_merge_bases_many(A, X_nr, X_array); printf("%s(A,X):\n", av[1]); diff --git a/t/helper/test-ref-store.c b/t/helper/test-ref-store.c index 799fc00aa1..759e69dc54 100644 --- a/t/helper/test-ref-store.c +++ b/t/helper/test-ref-store.c @@ -37,7 +37,7 @@ static const char **get_store(const char **argv, struct ref_store **refs) *refs = get_submodule_ref_store(gitdir); } else if (skip_prefix(argv[0], "worktree:", &gitdir)) { - struct worktree **p, **worktrees = get_worktrees(0); + struct worktree **p, **worktrees = get_worktrees(); for (p = worktrees; *p; p++) { struct worktree *wt = *p; diff --git a/t/helper/test-regex.c b/t/helper/test-regex.c index 10284cc56f..d6f28ca8d1 100644 --- a/t/helper/test-regex.c +++ b/t/helper/test-regex.c @@ -1,5 +1,4 @@ #include "test-tool.h" -#include "git-compat-util.h" #include "gettext.h" struct reg_flag { @@ -8,12 +7,13 @@ struct reg_flag { }; static struct reg_flag reg_flags[] = { - { "EXTENDED", REG_EXTENDED }, - { "NEWLINE", REG_NEWLINE }, - { "ICASE", REG_ICASE }, - { "NOTBOL", REG_NOTBOL }, + { "EXTENDED", REG_EXTENDED }, + { "NEWLINE", REG_NEWLINE }, + { "ICASE", REG_ICASE }, + { "NOTBOL", REG_NOTBOL }, + { "NOTEOL", REG_NOTEOL }, #ifdef REG_STARTEND - { "STARTEND", REG_STARTEND }, + { "STARTEND", REG_STARTEND }, #endif { NULL, 0 } }; @@ -41,36 +41,74 @@ int cmd__regex(int argc, const char **argv) { const char *pat; const char *str; - int flags = 0; + int ret, silent = 0, flags = 0; regex_t r; regmatch_t m[1]; - - if (argc == 2 && !strcmp(argv[1], "--bug")) - return test_regex_bug(); - else if (argc < 3) - usage("test-tool regex --bug\n" - "test-tool regex <pattern> <string> [<options>]"); + char errbuf[64]; argv++; - pat = *argv++; - str = *argv++; - while (*argv) { - struct reg_flag *rf; - for (rf = reg_flags; rf->name; rf++) - if (!strcmp(*argv, rf->name)) { - flags |= rf->flag; - break; - } - if (!rf->name) - die("do not recognize %s", *argv); + argc--; + + if (!argc) + goto usage; + + if (!strcmp(*argv, "--bug")) { + if (argc == 1) + return test_regex_bug(); + else + goto usage; + } + if (!strcmp(*argv, "--silent")) { + silent = 1; argv++; + argc--; + } + if (!argc) + goto usage; + + pat = *argv++; + if (argc == 1) + str = NULL; + else { + str = *argv++; + while (*argv) { + struct reg_flag *rf; + for (rf = reg_flags; rf->name; rf++) + if (!strcmp(*argv, rf->name)) { + flags |= rf->flag; + break; + } + if (!rf->name) + die("do not recognize flag %s", *argv); + argv++; + } } git_setup_gettext(); - if (regcomp(&r, pat, flags)) - die("failed regcomp() for pattern '%s'", pat); - if (regexec(&r, str, 1, m, 0)) - return 1; + ret = regcomp(&r, pat, flags); + if (ret) { + if (silent) + return ret; + + regerror(ret, &r, errbuf, sizeof(errbuf)); + die("failed regcomp() for pattern '%s' (%s)", pat, errbuf); + } + if (!str) + return 0; + + ret = regexec(&r, str, 1, m, 0); + if (ret) { + if (silent || ret == REG_NOMATCH) + return ret; + + regerror(ret, &r, errbuf, sizeof(errbuf)); + die("failed regexec() for subject '%s' (%s)", str, errbuf); + } return 0; +usage: + usage("\ttest-tool regex --bug\n" + "\ttest-tool regex [--silent] <pattern>\n" + "\ttest-tool regex [--silent] <pattern> <string> [<options>]"); + return -1; } diff --git a/t/lib-git-svn.sh b/t/lib-git-svn.sh index 7d248e6588..547eb3c31a 100644 --- a/t/lib-git-svn.sh +++ b/t/lib-git-svn.sh @@ -78,21 +78,24 @@ maybe_start_httpd () { } convert_to_rev_db () { - perl -w -- - "$@" <<\EOF + perl -w -- - "$(test_oid rawsz)" "$@" <<\EOF use strict; +my $oidlen = shift; @ARGV == 2 or die "usage: convert_to_rev_db <input> <output>"; +my $record_size = $oidlen + 4; +my $hexlen = $oidlen * 2; open my $wr, '+>', $ARGV[1] or die "$!: couldn't open: $ARGV[1]"; open my $rd, '<', $ARGV[0] or die "$!: couldn't open: $ARGV[0]"; my $size = (stat($rd))[7]; -($size % 24) == 0 or die "Inconsistent size: $size"; -while (sysread($rd, my $buf, 24) == 24) { - my ($r, $c) = unpack('NH40', $buf); - my $offset = $r * 41; +($size % $record_size) == 0 or die "Inconsistent size: $size"; +while (sysread($rd, my $buf, $record_size) == $record_size) { + my ($r, $c) = unpack("NH$hexlen", $buf); + my $offset = $r * ($hexlen + 1); seek $wr, 0, 2 or die $!; my $pos = tell $wr; if ($pos < $offset) { - for (1 .. (($offset - $pos) / 41)) { - print $wr (('0' x 40),"\n") or die $!; + for (1 .. (($offset - $pos) / ($hexlen + 1))) { + print $wr (('0' x $hexlen),"\n") or die $!; } } seek $wr, $offset, 0 or die $!; diff --git a/t/lib-httpd.sh b/t/lib-httpd.sh index 1449ee95e9..d2edfa4c50 100644 --- a/t/lib-httpd.sh +++ b/t/lib-httpd.sh @@ -129,6 +129,8 @@ install_script () { prepare_httpd() { mkdir -p "$HTTPD_DOCUMENT_ROOT_PATH" cp "$TEST_PATH"/passwd "$HTTPD_ROOT_PATH" + install_script incomplete-length-upload-pack-v2-http.sh + install_script incomplete-body-upload-pack-v2-http.sh install_script broken-smart-http.sh install_script error-smart-http.sh install_script error.sh diff --git a/t/lib-httpd/apache.conf b/t/lib-httpd/apache.conf index 994e5290d6..afa91e38b0 100644 --- a/t/lib-httpd/apache.conf +++ b/t/lib-httpd/apache.conf @@ -117,6 +117,8 @@ Alias /auth/dumb/ www/auth/dumb/ SetEnv GIT_EXEC_PATH ${GIT_EXEC_PATH} SetEnv GIT_HTTP_EXPORT_ALL </LocationMatch> +ScriptAlias /smart/incomplete_length/git-upload-pack incomplete-length-upload-pack-v2-http.sh/ +ScriptAlias /smart/incomplete_body/git-upload-pack incomplete-body-upload-pack-v2-http.sh/ ScriptAliasMatch /error_git_upload_pack/(.*)/git-upload-pack error.sh/ ScriptAliasMatch /smart_*[^/]*/(.*) ${GIT_EXEC_PATH}/git-http-backend/$1 ScriptAlias /broken_smart/ broken-smart-http.sh/ @@ -126,6 +128,12 @@ ScriptAliasMatch /one_time_perl/(.*) apply-one-time-perl.sh/$1 <Directory ${GIT_EXEC_PATH}> Options FollowSymlinks </Directory> +<Files incomplete-length-upload-pack-v2-http.sh> + Options ExecCGI +</Files> +<Files incomplete-body-upload-pack-v2-http.sh> + Options ExecCGI +</Files> <Files broken-smart-http.sh> Options ExecCGI </Files> diff --git a/t/lib-httpd/incomplete-body-upload-pack-v2-http.sh b/t/lib-httpd/incomplete-body-upload-pack-v2-http.sh new file mode 100644 index 0000000000..90e73ef8d5 --- /dev/null +++ b/t/lib-httpd/incomplete-body-upload-pack-v2-http.sh @@ -0,0 +1,3 @@ +printf "Content-Type: text/%s\n" "application/x-git-upload-pack-result" +echo +printf "%s%s" "0079" "45" diff --git a/t/lib-httpd/incomplete-length-upload-pack-v2-http.sh b/t/lib-httpd/incomplete-length-upload-pack-v2-http.sh new file mode 100644 index 0000000000..dce552e348 --- /dev/null +++ b/t/lib-httpd/incomplete-length-upload-pack-v2-http.sh @@ -0,0 +1,3 @@ +printf "Content-Type: text/%s\n" "application/x-git-upload-pack-result" +echo +printf "%s" "00" diff --git a/t/lib-submodule-update.sh b/t/lib-submodule-update.sh index 64fc6487dd..07c822c8ff 100644 --- a/t/lib-submodule-update.sh +++ b/t/lib-submodule-update.sh @@ -183,7 +183,7 @@ test_git_directory_is_unchanged () { ) } -test_git_directory_exists() { +test_git_directory_exists () { test -e ".git/modules/$1" && if test -f sub1/.git then @@ -303,13 +303,17 @@ test_submodule_content () { # update" is run. And even then that command doesn't delete the work tree of # a removed submodule. # +# The first argument of the callback function will be the name of the submodule. +# # Removing a submodule containing a .git directory must fail even when forced -# to protect the history! +# to protect the history! If we are testing this case, the second argument of +# the callback function will be 'test_must_fail', else it will be the empty +# string. # -# Internal function; use test_submodule_switch() or -# test_submodule_forced_switch() instead. -test_submodule_switch_common() { +# Internal function; use test_submodule_switch_func(), test_submodule_switch(), +# or test_submodule_forced_switch() instead. +test_submodule_switch_common () { command="$1" ######################### Appearing submodule ######################### # Switching to a commit letting a submodule appear creates empty dir ... @@ -443,7 +447,7 @@ test_submodule_switch_common() { ( cd submodule_update && git branch -t replace_sub1_with_directory origin/replace_sub1_with_directory && - test_must_fail $command replace_sub1_with_directory && + $command replace_sub1_with_directory test_must_fail && test_superproject_content origin/add_sub1 && test_submodule_content sub1 origin/add_sub1 ) @@ -456,7 +460,7 @@ test_submodule_switch_common() { 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 && + $command replace_sub1_with_directory test_must_fail && test_superproject_content origin/add_sub1 && test_git_directory_is_unchanged sub1 && test_submodule_content sub1 origin/add_sub1 @@ -470,7 +474,7 @@ test_submodule_switch_common() { ( cd submodule_update && git branch -t replace_sub1_with_file origin/replace_sub1_with_file && - test_must_fail $command replace_sub1_with_file && + $command replace_sub1_with_file test_must_fail && test_superproject_content origin/add_sub1 && test_submodule_content sub1 origin/add_sub1 ) @@ -484,7 +488,7 @@ test_submodule_switch_common() { 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 && + $command replace_sub1_with_file test_must_fail && test_superproject_content origin/add_sub1 && test_git_directory_is_unchanged sub1 && test_submodule_content sub1 origin/add_sub1 @@ -559,15 +563,28 @@ test_submodule_switch_common() { # conditions, set the appropriate KNOWN_FAILURE_* variable used in the tests # below to 1. # -# Use as follows: +# The first argument of the callback function will be the name of the submodule. +# +# Removing a submodule containing a .git directory must fail even when forced +# to protect the history! If we are testing this case, the second argument of +# the callback function will be 'test_must_fail', else it will be the empty +# string. +# +# The following example uses `git some-command` as an example command to be +# tested. It updates the worktree and index to match a target, but not any +# submodule directories. # # my_func () { -# target=$1 -# # Do something here that updates the worktree and index to match target, -# # but not any submodule directories. +# ...prepare for `git some-command` to be run... +# $2 git some-command "$1" && +# if test -n "$2" +# then +# return +# fi && +# ...check the state after git some-command is run... # } -# test_submodule_switch "my_func" -test_submodule_switch () { +# test_submodule_switch_func "my_func" +test_submodule_switch_func () { command="$1" test_submodule_switch_common "$command" @@ -580,17 +597,33 @@ test_submodule_switch () { cd submodule_update && git branch -t add_sub1 origin/add_sub1 && >sub1 && - test_must_fail $command add_sub1 && + $command add_sub1 test_must_fail && test_superproject_content origin/no_submodule && test_must_be_empty sub1 ) ' } +# Ensures that the that the arg either contains "test_must_fail" or is empty. +may_only_be_test_must_fail () { + test -z "$1" || test "$1" = test_must_fail || die +} + +git_test_func () { + may_only_be_test_must_fail "$2" && + $2 git $gitcmd "$1" +} + +test_submodule_switch () { + gitcmd="$1" + test_submodule_switch_func "git_test_func" +} + # Same as test_submodule_switch(), except that throwing away local changes in # the superproject is allowed. test_submodule_forced_switch () { - command="$1" + gitcmd="$1" + command="git_test_func" KNOWN_FAILURE_FORCED_SWITCH_TESTS=1 test_submodule_switch_common "$command" @@ -631,8 +664,8 @@ test_submodule_forced_switch () { # Internal function; use test_submodule_switch_recursing_with_args() or # test_submodule_forced_switch_recursing_with_args() instead. -test_submodule_recursing_with_args_common() { - command="$1" +test_submodule_recursing_with_args_common () { + command="$1 --recurse-submodules" ######################### Appearing submodule ######################### # Switching to a commit letting a submodule appear checks it out ... @@ -840,7 +873,7 @@ test_submodule_recursing_with_args_common() { # test_submodule_switch_recursing_with_args "$GIT_COMMAND" test_submodule_switch_recursing_with_args () { cmd_args="$1" - command="git $cmd_args --recurse-submodules" + command="git $cmd_args" test_submodule_recursing_with_args_common "$command" RESULTDS=success @@ -957,7 +990,7 @@ test_submodule_switch_recursing_with_args () { # away local changes in the superproject is allowed. test_submodule_forced_switch_recursing_with_args () { cmd_args="$1" - command="git $cmd_args --recurse-submodules" + command="git $cmd_args" test_submodule_recursing_with_args_common "$command" RESULT=success diff --git a/t/perf/p1400-update-ref.sh b/t/perf/p1400-update-ref.sh new file mode 100755 index 0000000000..d275a81248 --- /dev/null +++ b/t/perf/p1400-update-ref.sh @@ -0,0 +1,32 @@ +#!/bin/sh + +test_description="Tests performance of update-ref" + +. ./perf-lib.sh + +test_perf_fresh_repo + +test_expect_success "setup" ' + test_commit PRE && + test_commit POST && + printf "create refs/heads/%d PRE\n" $(test_seq 1000) >create && + printf "update refs/heads/%d POST PRE\n" $(test_seq 1000) >update && + printf "delete refs/heads/%d POST\n" $(test_seq 1000) >delete +' + +test_perf "update-ref" ' + for i in $(test_seq 1000) + do + git update-ref refs/heads/branch PRE && + git update-ref refs/heads/branch POST PRE && + git update-ref -d refs/heads/branch + done +' + +test_perf "update-ref --stdin" ' + git update-ref --stdin <create && + git update-ref --stdin <update && + git update-ref --stdin <delete +' + +test_done diff --git a/t/t0001-init.sh b/t/t0001-init.sh index 1edd5aeb8f..6d2467995e 100755 --- a/t/t0001-init.sh +++ b/t/t0001-init.sh @@ -464,4 +464,30 @@ test_expect_success MINGW 'redirect std handles' ' grep "Needed a single revision" output.txt ' +test_expect_success '--initial-branch' ' + git init --initial-branch=hello initial-branch-option && + git -C initial-branch-option symbolic-ref HEAD >actual && + echo refs/heads/hello >expect && + test_cmp expect actual && + + : re-initializing should not change the branch name && + git init --initial-branch=ignore initial-branch-option 2>err && + test_i18ngrep "ignored --initial-branch" err && + git -C initial-branch-option symbolic-ref HEAD >actual && + grep hello actual +' + +test_expect_success 'overridden default initial branch name (config)' ' + test_config_global init.defaultBranch nmb && + git init initial-branch-config && + git -C initial-branch-config symbolic-ref HEAD >actual && + grep nmb actual +' + +test_expect_success 'invalid default branch name' ' + test_config_global init.defaultBranch "with space" && + test_must_fail git init initial-branch-invalid 2>err && + test_i18ngrep "invalid branch name" err +' + test_done diff --git a/t/t0002-gitfile.sh b/t/t0002-gitfile.sh index 0aa9908ea1..960ed150cb 100755 --- a/t/t0002-gitfile.sh +++ b/t/t0002-gitfile.sh @@ -62,7 +62,7 @@ test_expect_success 'check commit-tree' ' ' test_expect_success 'check rev-list' ' - echo $SHA >"$REAL/HEAD" && + git update-ref "HEAD" "$SHA" && test "$SHA" = "$(git rev-list HEAD)" ' diff --git a/t/t0410-partial-clone.sh b/t/t0410-partial-clone.sh index a3988bd4b8..463dc3a8be 100755 --- a/t/t0410-partial-clone.sh +++ b/t/t0410-partial-clone.sh @@ -30,6 +30,29 @@ test_expect_success 'extensions.partialclone without filter' ' git -C client fetch origin ' +test_expect_success 'convert shallow clone to partial clone' ' + rm -fr server client && + test_create_repo server && + test_commit -C server my_commit 1 && + test_commit -C server my_commit2 1 && + git clone --depth=1 "file://$(pwd)/server" client && + git -C client fetch --unshallow --filter="blob:none" && + test_cmp_config -C client true remote.origin.promisor && + test_cmp_config -C client blob:none remote.origin.partialclonefilter && + test_cmp_config -C client 1 core.repositoryformatversion +' + +test_expect_success 'convert shallow clone to partial clone must fail with any extension' ' + rm -fr server client && + test_create_repo server && + test_commit -C server my_commit 1 && + test_commit -C server my_commit2 1 && + git clone --depth=1 "file://$(pwd)/server" client && + test_cmp_config -C client 0 core.repositoryformatversion && + git -C client config extensions.partialclone origin && + test_must_fail git -C client fetch --unshallow --filter="blob:none" +' + test_expect_success 'missing reflog object, but promised by a commit, passes fsck' ' rm -rf repo && test_create_repo repo && diff --git a/t/t1013-read-tree-submodule.sh b/t/t1013-read-tree-submodule.sh index 91a6fafcb4..b6df7444c0 100755 --- a/t/t1013-read-tree-submodule.sh +++ b/t/t1013-read-tree-submodule.sh @@ -12,8 +12,8 @@ test_submodule_switch_recursing_with_args "read-tree -u -m" test_submodule_forced_switch_recursing_with_args "read-tree -u --reset" -test_submodule_switch "git read-tree -u -m" +test_submodule_switch "read-tree -u -m" -test_submodule_forced_switch "git read-tree -u --reset" +test_submodule_forced_switch "read-tree -u --reset" test_done diff --git a/t/t1050-large.sh b/t/t1050-large.sh index 184b479a21..6a56d1ca24 100755 --- a/t/t1050-large.sh +++ b/t/t1050-large.sh @@ -12,6 +12,7 @@ file_size () { } test_expect_success setup ' + test_oid_init && # clone does not allow us to pass core.bigfilethreshold to # new repos, so set core.bigfilethreshold globally git config --global core.bigfilethreshold 200k && @@ -64,7 +65,7 @@ test_expect_success 'add a large file or two' ' test $count = 1 && cnt=$(git show-index <"$idx" | wc -l) && test $cnt = 2 && - for l in .git/objects/??/?????????????????????????????????????? + for l in .git/objects/$OIDPATH_REGEX do test_path_is_file "$l" || continue bad=t @@ -177,7 +178,8 @@ test_expect_success 'git-show a large file' ' test_expect_success 'index-pack' ' git clone file://"$(pwd)"/.git foo && - GIT_DIR=non-existent git index-pack --strict --verify foo/.git/objects/pack/*.pack + GIT_DIR=non-existent git index-pack --object-format=$(test_oid algo) \ + --strict --verify foo/.git/objects/pack/*.pack ' test_expect_success 'repack' ' diff --git a/t/t1090-sparse-checkout-scope.sh b/t/t1090-sparse-checkout-scope.sh index 40cc004326..f35a73dd20 100755 --- a/t/t1090-sparse-checkout-scope.sh +++ b/t/t1090-sparse-checkout-scope.sh @@ -63,7 +63,6 @@ test_expect_success 'in partial clone, sparse checkout only fetches needed blobs git -C server commit -m message && test_config -C client core.sparsecheckout 1 && - test_config -C client extensions.partialclone origin && echo "!/*" >client/.git/info/sparse-checkout && echo "/a" >>client/.git/info/sparse-checkout && git -C client fetch --filter=blob:none origin && diff --git a/t/t1091-sparse-checkout-builtin.sh b/t/t1091-sparse-checkout-builtin.sh index 88cdde255c..7cd45fc139 100755 --- a/t/t1091-sparse-checkout-builtin.sh +++ b/t/t1091-sparse-checkout-builtin.sh @@ -100,6 +100,28 @@ test_expect_success 'clone --sparse' ' check_files clone a ' +test_expect_success 'interaction with clone --no-checkout (unborn index)' ' + git clone --no-checkout "file://$(pwd)/repo" clone_no_checkout && + git -C clone_no_checkout sparse-checkout init --cone && + git -C clone_no_checkout sparse-checkout set folder1 && + + git -C clone_no_checkout sparse-checkout list >actual && + cat >expect <<-\EOF && + folder1 + EOF + test_cmp expect actual && + + # nothing checked out, expect "No such file or directory" + ! ls clone_no_checkout/* >actual && + test_must_be_empty actual && + test_path_is_missing clone_no_checkout/.git/index && + + # No branch is checked out until we manually switch to one + git -C clone_no_checkout switch master && + test_path_is_file clone_no_checkout/.git/index && + check_files clone_no_checkout a folder1 +' + test_expect_success 'set enables config' ' git init empty-config && ( diff --git a/t/t1302-repo-version.sh b/t/t1302-repo-version.sh index ce4cff13bb..d60c042ce8 100755 --- a/t/t1302-repo-version.sh +++ b/t/t1302-repo-version.sh @@ -8,6 +8,10 @@ test_description='Test repository version check' . ./test-lib.sh test_expect_success 'setup' ' + test_oid_cache <<-\EOF && + version sha1:0 + version sha256:1 + EOF cat >test.patch <<-\EOF && diff --git a/test.txt b/test.txt new file mode 100644 @@ -23,7 +27,7 @@ test_expect_success 'setup' ' ' test_expect_success 'gitdir selection on normal repos' ' - echo 0 >expect && + echo $(test_oid version) >expect && git config core.repositoryformatversion >actual && git -C test config core.repositoryformatversion >actual2 && test_cmp expect actual && diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index e1197ac818..27171f8261 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -37,15 +37,15 @@ test_expect_success setup ' test_expect_success "create $m" ' git update-ref $m $A && - test $A = $(cat .git/$m) + test $A = $(git show-ref -s --verify $m) ' test_expect_success "create $m with oldvalue verification" ' git update-ref $m $B $A && - test $B = $(cat .git/$m) + test $B = $(git show-ref -s --verify $m) ' test_expect_success "fail to delete $m with stale ref" ' test_must_fail git update-ref -d $m $A && - test $B = "$(cat .git/$m)" + test $B = "$(git show-ref -s --verify $m)" ' test_expect_success "delete $m" ' test_when_finished "rm -f .git/$m" && @@ -56,7 +56,7 @@ test_expect_success "delete $m" ' test_expect_success "delete $m without oldvalue verification" ' test_when_finished "rm -f .git/$m" && git update-ref $m $A && - test $A = $(cat .git/$m) && + test $A = $(git show-ref -s --verify $m) && git update-ref -d $m && test_path_is_missing .git/$m ' @@ -69,15 +69,15 @@ test_expect_success "fail to create $n" ' test_expect_success "create $m (by HEAD)" ' git update-ref HEAD $A && - test $A = $(cat .git/$m) + test $A = $(git show-ref -s --verify $m) ' test_expect_success "create $m (by HEAD) with oldvalue verification" ' git update-ref HEAD $B $A && - test $B = $(cat .git/$m) + test $B = $(git show-ref -s --verify $m) ' test_expect_success "fail to delete $m (by HEAD) with stale ref" ' test_must_fail git update-ref -d HEAD $A && - test $B = $(cat .git/$m) + test $B = $(git show-ref -s --verify $m) ' test_expect_success "delete $m (by HEAD)" ' test_when_finished "rm -f .git/$m" && @@ -178,14 +178,14 @@ test_expect_success '--no-create-reflog overrides core.logAllRefUpdates=always' test_expect_success "create $m (by HEAD)" ' git update-ref HEAD $A && - test $A = $(cat .git/$m) + test $A = $(git show-ref -s --verify $m) ' test_expect_success 'pack refs' ' git pack-refs --all ' test_expect_success "move $m (by HEAD)" ' git update-ref HEAD $B $A && - test $B = $(cat .git/$m) + test $B = $(git show-ref -s --verify $m) ' test_expect_success "delete $m (by HEAD) should remove both packed and loose $m" ' test_when_finished "rm -f .git/$m" && @@ -255,7 +255,7 @@ test_expect_success '(not) change HEAD with wrong SHA1' ' ' test_expect_success "(not) changed .git/$m" ' test_when_finished "rm -f .git/$m" && - ! test $B = $(cat .git/$m) + ! test $B = $(git show-ref -s --verify $m) ' rm -f .git/logs/refs/heads/master @@ -263,19 +263,19 @@ test_expect_success "create $m (logged by touch)" ' test_config core.logAllRefUpdates false && GIT_COMMITTER_DATE="2005-05-26 23:30" \ git update-ref --create-reflog HEAD $A -m "Initial Creation" && - test $A = $(cat .git/$m) + test $A = $(git show-ref -s --verify $m) ' test_expect_success "update $m (logged by touch)" ' test_config core.logAllRefUpdates false && GIT_COMMITTER_DATE="2005-05-26 23:31" \ git update-ref HEAD $B $A -m "Switch" && - test $B = $(cat .git/$m) + test $B = $(git show-ref -s --verify $m) ' test_expect_success "set $m (logged by touch)" ' test_config core.logAllRefUpdates false && GIT_COMMITTER_DATE="2005-05-26 23:41" \ git update-ref HEAD $A && - test $A = $(cat .git/$m) + test $A = $(git show-ref -s --verify $m) ' test_expect_success 'empty directory removal' ' @@ -319,19 +319,19 @@ test_expect_success "create $m (logged by config)" ' test_config core.logAllRefUpdates true && GIT_COMMITTER_DATE="2005-05-26 23:32" \ git update-ref HEAD $A -m "Initial Creation" && - test $A = $(cat .git/$m) + test $A = $(git show-ref -s --verify $m) ' test_expect_success "update $m (logged by config)" ' test_config core.logAllRefUpdates true && GIT_COMMITTER_DATE="2005-05-26 23:33" \ git update-ref HEAD'" $B $A "'-m "Switch" && - test $B = $(cat .git/$m) + test $B = $(git show-ref -s --verify $m) ' test_expect_success "set $m (logged by config)" ' test_config core.logAllRefUpdates true && GIT_COMMITTER_DATE="2005-05-26 23:43" \ git update-ref HEAD $A && - test $A = $(cat .git/$m) + test $A = $(git show-ref -s --verify $m) ' cat >expect <<EOF diff --git a/t/t1416-ref-transaction-hooks.sh b/t/t1416-ref-transaction-hooks.sh new file mode 100755 index 0000000000..da58d867a5 --- /dev/null +++ b/t/t1416-ref-transaction-hooks.sh @@ -0,0 +1,109 @@ +#!/bin/sh + +test_description='reference transaction hooks' + +. ./test-lib.sh + +test_expect_success setup ' + mkdir -p .git/hooks && + test_commit PRE && + test_commit POST && + POST_OID=$(git rev-parse POST) +' + +test_expect_success 'hook allows updating ref if successful' ' + test_when_finished "rm .git/hooks/reference-transaction" && + git reset --hard PRE && + write_script .git/hooks/reference-transaction <<-\EOF && + echo "$*" >>actual + EOF + cat >expect <<-EOF && + prepared + committed + EOF + git update-ref HEAD POST && + test_cmp expect actual +' + +test_expect_success 'hook aborts updating ref in prepared state' ' + test_when_finished "rm .git/hooks/reference-transaction" && + git reset --hard PRE && + write_script .git/hooks/reference-transaction <<-\EOF && + if test "$1" = prepared + then + exit 1 + fi + EOF + test_must_fail git update-ref HEAD POST 2>err && + test_i18ngrep "ref updates aborted by hook" err +' + +test_expect_success 'hook gets all queued updates in prepared state' ' + test_when_finished "rm .git/hooks/reference-transaction actual" && + git reset --hard PRE && + write_script .git/hooks/reference-transaction <<-\EOF && + if test "$1" = prepared + then + while read -r line + do + printf "%s\n" "$line" + done >actual + fi + EOF + cat >expect <<-EOF && + $ZERO_OID $POST_OID HEAD + $ZERO_OID $POST_OID refs/heads/master + EOF + git update-ref HEAD POST <<-EOF && + update HEAD $ZERO_OID $POST_OID + update refs/heads/master $ZERO_OID $POST_OID + EOF + test_cmp expect actual +' + +test_expect_success 'hook gets all queued updates in committed state' ' + test_when_finished "rm .git/hooks/reference-transaction actual" && + git reset --hard PRE && + write_script .git/hooks/reference-transaction <<-\EOF && + if test "$1" = committed + then + while read -r line + do + printf "%s\n" "$line" + done >actual + fi + EOF + cat >expect <<-EOF && + $ZERO_OID $POST_OID HEAD + $ZERO_OID $POST_OID refs/heads/master + EOF + git update-ref HEAD POST && + test_cmp expect actual +' + +test_expect_success 'hook gets all queued updates in aborted state' ' + test_when_finished "rm .git/hooks/reference-transaction actual" && + git reset --hard PRE && + write_script .git/hooks/reference-transaction <<-\EOF && + if test "$1" = aborted + then + while read -r line + do + printf "%s\n" "$line" + done >actual + fi + EOF + cat >expect <<-EOF && + $ZERO_OID $POST_OID HEAD + $ZERO_OID $POST_OID refs/heads/master + EOF + git update-ref --stdin <<-EOF && + start + update HEAD POST $ZERO_OID + update refs/heads/master POST $ZERO_OID + abort + EOF + test_cmp expect actual +' + +test_done diff --git a/t/t1450-fsck.sh b/t/t1450-fsck.sh index 91a6e34f38..344a2aad82 100755 --- a/t/t1450-fsck.sh +++ b/t/t1450-fsck.sh @@ -257,21 +257,34 @@ test_expect_success 'tree object with duplicate entries' ' test_i18ngrep "error in tree .*contains duplicate file entries" out ' -test_expect_success 'tree object with dublicate names' ' - test_when_finished "remove_object \$blob" && - test_when_finished "remove_object \$tree" && - test_when_finished "remove_object \$badtree" && - blob=$(echo blob | git hash-object -w --stdin) && - printf "100644 blob %s\t%s\n" $blob x.2 >tree && - tree=$(git mktree <tree) && - printf "100644 blob %s\t%s\n" $blob x.1 >badtree && - printf "100644 blob %s\t%s\n" $blob x >>badtree && - printf "040000 tree %s\t%s\n" $tree x >>badtree && - badtree=$(git mktree <badtree) && - test_must_fail git fsck 2>out && - test_i18ngrep "$badtree" out && - test_i18ngrep "error in tree .*contains duplicate file entries" out -' +check_duplicate_names () { + expect=$1 && + shift && + names=$@ && + test_expect_$expect "tree object with duplicate names: $names" ' + test_when_finished "remove_object \$blob" && + test_when_finished "remove_object \$tree" && + test_when_finished "remove_object \$badtree" && + blob=$(echo blob | git hash-object -w --stdin) && + printf "100644 blob %s\t%s\n" $blob x.2 >tree && + tree=$(git mktree <tree) && + for name in $names + do + case "$name" in + */) printf "040000 tree %s\t%s\n" $tree "${name%/}" ;; + *) printf "100644 blob %s\t%s\n" $blob "$name" ;; + esac + done >badtree && + badtree=$(git mktree <badtree) && + test_must_fail git fsck 2>out && + test_i18ngrep "$badtree" out && + test_i18ngrep "error in tree .*contains duplicate file entries" out + ' +} + +check_duplicate_names success x x.1 x/ +check_duplicate_names success x x.1.2 x.1/ x/ +check_duplicate_names success x x.1 x.1.2 x/ test_expect_success 'unparseable tree object' ' test_oid_cache <<-\EOF && diff --git a/t/t1506-rev-parse-diagnosis.sh b/t/t1506-rev-parse-diagnosis.sh index 52edcbdcc3..dbf690b9c1 100755 --- a/t/t1506-rev-parse-diagnosis.sh +++ b/t/t1506-rev-parse-diagnosis.sh @@ -207,7 +207,7 @@ test_expect_success 'arg before dashdash must be a revision (ambiguous)' ' { # we do not want to use rev-parse here, because # we are testing it - cat .git/refs/heads/foobar && + git show-ref -s refs/heads/foobar && printf "%s\n" -- } >expect && git rev-parse foobar -- >actual && diff --git a/t/t1507-rev-parse-upstream.sh b/t/t1507-rev-parse-upstream.sh index dfc0d96d8a..f213aa8053 100755 --- a/t/t1507-rev-parse-upstream.sh +++ b/t/t1507-rev-parse-upstream.sh @@ -137,7 +137,7 @@ test_expect_success 'merge my-side@{u} records the correct name' ' git branch -t new my-side@{u} && git merge -s ours new@{u} && git show -s --pretty=tformat:%s >actual && - echo "Merge remote-tracking branch ${SQ}origin/side${SQ}" >expect && + echo "Merge remote-tracking branch ${SQ}origin/side${SQ} into master" >expect && test_cmp expect actual ) ' diff --git a/t/t2013-checkout-submodule.sh b/t/t2013-checkout-submodule.sh index 8f86b5f4b2..b2bdd1fcb4 100755 --- a/t/t2013-checkout-submodule.sh +++ b/t/t2013-checkout-submodule.sh @@ -68,8 +68,8 @@ test_submodule_switch_recursing_with_args "checkout" test_submodule_forced_switch_recursing_with_args "checkout -f" -test_submodule_switch "git checkout" +test_submodule_switch "checkout" -test_submodule_forced_switch "git checkout -f" +test_submodule_forced_switch "checkout -f" test_done diff --git a/t/t2018-checkout-branch.sh b/t/t2018-checkout-branch.sh index 21583154d8..5f761bc616 100755 --- a/t/t2018-checkout-branch.sh +++ b/t/t2018-checkout-branch.sh @@ -260,4 +260,14 @@ test_expect_success 'checkout -b to a new branch preserves mergeable changes des test_cmp expect actual ' +test_expect_success 'checkout -b rejects an invalid start point' ' + test_must_fail git checkout -b branch4 file1 2>err && + test_i18ngrep "is not a commit" err +' + +test_expect_success 'checkout -b rejects an extra path argument' ' + test_must_fail git checkout -b branch5 branch1 file1 2>err && + test_i18ngrep "Cannot update paths and switch to branch" err +' + test_done diff --git a/t/t2027-checkout-track.sh b/t/t2027-checkout-track.sh new file mode 100755 index 0000000000..bcba1bf90c --- /dev/null +++ b/t/t2027-checkout-track.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +test_description='tests for git branch --track' + +. ./test-lib.sh + +test_expect_success 'setup' ' + test_commit one && + test_commit two +' + +test_expect_success 'checkout --track -b creates a new tracking branch' ' + git checkout --track -b branch1 master && + test $(git rev-parse --abbrev-ref HEAD) = branch1 && + test $(git config --get branch.branch1.remote) = . && + test $(git config --get branch.branch1.merge) = refs/heads/master +' + +test_expect_success 'checkout --track -b rejects an extra path argument' ' + test_must_fail git checkout --track -b branch2 master one.t 2>err && + test_i18ngrep "cannot be used with updating paths" err +' + +test_done diff --git a/t/t2060-switch.sh b/t/t2060-switch.sh index f9efa29dfb..2c1b8c0d6d 100755 --- a/t/t2060-switch.sh +++ b/t/t2060-switch.sh @@ -68,6 +68,14 @@ test_expect_success 'new orphan branch from empty' ' test_cmp expected tracked-files ' +test_expect_success 'orphan branch works with --discard-changes' ' + test_when_finished git switch master && + echo foo >foo.txt && + git switch --discard-changes --orphan new-orphan2 && + git ls-files >tracked-files && + test_must_be_empty tracked-files +' + test_expect_success 'switching ignores file of same branch name' ' test_when_finished git switch master && : >first-branch && diff --git a/t/t2203-add-intent.sh b/t/t2203-add-intent.sh index 5bbe8dcce4..cf0175ad6e 100755 --- a/t/t2203-add-intent.sh +++ b/t/t2203-add-intent.sh @@ -232,17 +232,53 @@ test_expect_success 'double rename detection in status' ' ) ' -test_expect_success 'diff-files/diff-cached shows ita as new/not-new files' ' +test_expect_success 'i-t-a files shown as new for "diff", "diff-files"; not-new for "diff --cached"' ' git reset --hard && - echo new >new-ita && - git add -N new-ita && + : >empty && + content="foo" && + echo "$content" >not-empty && + + hash_e=$(git hash-object empty) && + hash_n=$(git hash-object not-empty) && + + cat >expect.diff_p <<-EOF && + diff --git a/empty b/empty + new file mode 100644 + index 0000000..$(git rev-parse --short $hash_e) + diff --git a/not-empty b/not-empty + new file mode 100644 + index 0000000..$(git rev-parse --short $hash_n) + --- /dev/null + +++ b/not-empty + @@ -0,0 +1 @@ + +$content + EOF + cat >expect.diff_s <<-EOF && + create mode 100644 empty + create mode 100644 not-empty + EOF + cat >expect.diff_a <<-EOF && + :000000 100644 0000000 0000000 A$(printf "\t")empty + :000000 100644 0000000 0000000 A$(printf "\t")not-empty + EOF + + git add -N empty not-empty && + + git diff >actual && + test_cmp expect.diff_p actual && + git diff --summary >actual && - echo " create mode 100644 new-ita" >expected && - test_cmp expected actual && - git diff --cached --summary >actual2 && - test_must_be_empty actual2 -' + test_cmp expect.diff_s actual && + + git diff-files -p >actual && + test_cmp expect.diff_p actual && + git diff-files --abbrev >actual && + test_cmp expect.diff_a actual && + + git diff --cached >actual && + test_must_be_empty actual +' test_expect_success '"diff HEAD" includes ita as new files' ' git reset --hard && diff --git a/t/t2401-worktree-prune.sh b/t/t2401-worktree-prune.sh index b7d6d5d45a..a6ce7f590b 100755 --- a/t/t2401-worktree-prune.sh +++ b/t/t2401-worktree-prune.sh @@ -92,4 +92,28 @@ test_expect_success 'not prune proper checkouts' ' test -d .git/worktrees/nop ' +test_expect_success 'prune duplicate (linked/linked)' ' + test_when_finished rm -fr .git/worktrees w1 w2 && + git worktree add --detach w1 && + git worktree add --detach w2 && + sed "s/w2/w1/" .git/worktrees/w2/gitdir >.git/worktrees/w2/gitdir.new && + mv .git/worktrees/w2/gitdir.new .git/worktrees/w2/gitdir && + git worktree prune --verbose >actual && + test_i18ngrep "duplicate entry" actual && + test -d .git/worktrees/w1 && + ! test -d .git/worktrees/w2 +' + +test_expect_success 'prune duplicate (main/linked)' ' + test_when_finished rm -fr repo wt && + test_create_repo repo && + test_commit -C repo x && + git -C repo worktree add --detach ../wt && + rm -fr wt && + mv repo wt && + git -C wt worktree prune --verbose >actual && + test_i18ngrep "duplicate entry" actual && + ! test -d .git/worktrees/wt +' + test_done diff --git a/t/t2403-worktree-move.sh b/t/t2403-worktree-move.sh index 939d18d728..a4e1a178e0 100755 --- a/t/t2403-worktree-move.sh +++ b/t/t2403-worktree-move.sh @@ -112,6 +112,27 @@ test_expect_success 'move locked worktree (force)' ' git worktree move --force --force flump ploof ' +test_expect_success 'refuse to move worktree atop existing path' ' + >bobble && + git worktree add --detach beeble && + test_must_fail git worktree move beeble bobble +' + +test_expect_success 'move atop existing but missing worktree' ' + git worktree add --detach gnoo && + git worktree add --detach pneu && + rm -fr pneu && + test_must_fail git worktree move gnoo pneu && + git worktree move --force gnoo pneu && + + git worktree add --detach nu && + git worktree lock nu && + rm -fr nu && + test_must_fail git worktree move pneu nu && + test_must_fail git worktree --force move pneu nu && + git worktree move --force --force pneu nu +' + test_expect_success 'move a repo with uninitialized submodule' ' git init withsub && ( diff --git a/t/t2404-worktree-config.sh b/t/t2404-worktree-config.sh index 286121d8de..9536d10919 100755 --- a/t/t2404-worktree-config.sh +++ b/t/t2404-worktree-config.sh @@ -23,8 +23,10 @@ test_expect_success 'config --worktree without extension' ' ' test_expect_success 'enable worktreeConfig extension' ' + git config core.repositoryformatversion 1 && git config extensions.worktreeConfig true && - test_cmp_config true extensions.worktreeConfig + test_cmp_config true extensions.worktreeConfig && + test_cmp_config 1 core.repositoryformatversion ' test_expect_success 'config is shared as before' ' diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh index 411a70b0ce..b6aa04bbec 100755 --- a/t/t3200-branch.sh +++ b/t/t3200-branch.sh @@ -323,11 +323,11 @@ test_expect_success 'git branch --list -v with --abbrev' ' test_expect_success 'git branch --column' ' COLUMNS=81 git branch --column=column >actual && - cat >expected <<\EOF && + cat >expect <<\EOF && a/b/c bam foo l * master mb o/o q abc bar j/k m/m master2 n o/p r EOF - test_cmp expected actual + test_cmp expect actual ' test_expect_success 'git branch --column with an extremely long branch name' ' @@ -336,7 +336,7 @@ test_expect_success 'git branch --column with an extremely long branch name' ' test_when_finished "git branch -d $long" && git branch $long && COLUMNS=80 git branch --column=column >actual && - cat >expected <<EOF && + cat >expect <<EOF && a/b/c abc bam @@ -355,7 +355,7 @@ test_expect_success 'git branch --column with an extremely long branch name' ' r $long EOF - test_cmp expected actual + test_cmp expect actual ' test_expect_success 'git branch with column.*' ' @@ -364,11 +364,11 @@ test_expect_success 'git branch with column.*' ' COLUMNS=80 git branch >actual && git config --unset column.branch && git config --unset column.ui && - cat >expected <<\EOF && + cat >expect <<\EOF && a/b/c bam foo l * master mb o/o q abc bar j/k m/m master2 n o/p r EOF - test_cmp expected actual + test_cmp expect actual ' test_expect_success 'git branch --column -v should fail' ' @@ -379,7 +379,7 @@ test_expect_success 'git branch -v with column.ui ignored' ' git config column.ui column && COLUMNS=80 git branch -v | cut -c -10 | sed "s/ *$//" >actual && git config --unset column.ui && - cat >expected <<\EOF && + cat >expect <<\EOF && a/b/c abc bam @@ -397,12 +397,12 @@ test_expect_success 'git branch -v with column.ui ignored' ' q r EOF - test_cmp expected actual + test_cmp expect actual ' mv .git/config .git/config-saved -test_expect_success 'git branch -m q q2 without config should succeed' ' +test_expect_success SHA1 'git branch -m q q2 without config should succeed' ' git branch -m q q2 && git branch -m q2 q ' @@ -835,32 +835,42 @@ test_expect_success 'branch from tag w/--track causes failure' ' ' test_expect_success '--set-upstream-to fails on multiple branches' ' - test_must_fail git branch --set-upstream-to master a b c + echo "fatal: too many arguments to set new upstream" >expect && + test_must_fail git branch --set-upstream-to master a b c 2>err && + test_i18ncmp expect err ' test_expect_success '--set-upstream-to fails on detached HEAD' ' git checkout HEAD^{} && - test_must_fail git branch --set-upstream-to master && - git checkout - + test_when_finished git checkout - && + echo "fatal: could not set upstream of HEAD to master when it does not point to any branch." >expect && + test_must_fail git branch --set-upstream-to master 2>err && + test_i18ncmp expect err ' test_expect_success '--set-upstream-to fails on a missing dst branch' ' - test_must_fail git branch --set-upstream-to master does-not-exist + echo "fatal: branch '"'"'does-not-exist'"'"' does not exist" >expect && + test_must_fail git branch --set-upstream-to master does-not-exist 2>err && + test_i18ncmp expect err ' test_expect_success '--set-upstream-to fails on a missing src branch' ' - test_must_fail git branch --set-upstream-to does-not-exist master + test_must_fail git branch --set-upstream-to does-not-exist master 2>err && + test_i18ngrep "the requested upstream branch '"'"'does-not-exist'"'"' does not exist" err ' test_expect_success '--set-upstream-to fails on a non-ref' ' - test_must_fail git branch --set-upstream-to HEAD^{} + echo "fatal: Cannot setup tracking information; starting point '"'"'HEAD^{}'"'"' is not a branch." >expect && + test_must_fail git branch --set-upstream-to HEAD^{} 2>err && + test_i18ncmp expect err ' test_expect_success '--set-upstream-to fails on locked config' ' test_when_finished "rm -f .git/config.lock" && >.git/config.lock && git branch locked && - test_must_fail git branch --set-upstream-to locked + test_must_fail git branch --set-upstream-to locked 2>err && + test_i18ngrep "could not lock config file .git/config: File exists" err ' test_expect_success 'use --set-upstream-to modify HEAD' ' @@ -881,14 +891,17 @@ test_expect_success 'use --set-upstream-to modify a particular branch' ' ' test_expect_success '--unset-upstream should fail if given a non-existent branch' ' - test_must_fail git branch --unset-upstream i-dont-exist + echo "fatal: Branch '"'"'i-dont-exist'"'"' has no upstream information" >expect && + test_must_fail git branch --unset-upstream i-dont-exist 2>err && + test_i18ncmp expect err ' test_expect_success '--unset-upstream should fail if config is locked' ' test_when_finished "rm -f .git/config.lock" && git branch --set-upstream-to locked && >.git/config.lock && - test_must_fail git branch --unset-upstream + test_must_fail git branch --unset-upstream 2>err && + test_i18ngrep "could not lock config file .git/config: File exists" err ' test_expect_success 'test --unset-upstream on HEAD' ' @@ -900,17 +913,23 @@ test_expect_success 'test --unset-upstream on HEAD' ' test_must_fail git config branch.master.remote && test_must_fail git config branch.master.merge && # fail for a branch without upstream set - test_must_fail git branch --unset-upstream + echo "fatal: Branch '"'"'master'"'"' has no upstream information" >expect && + test_must_fail git branch --unset-upstream 2>err && + test_i18ncmp expect err ' test_expect_success '--unset-upstream should fail on multiple branches' ' - test_must_fail git branch --unset-upstream a b c + echo "fatal: too many arguments to unset upstream" >expect && + test_must_fail git branch --unset-upstream a b c 2>err && + test_i18ncmp expect err ' test_expect_success '--unset-upstream should fail on detached HEAD' ' git checkout HEAD^{} && - test_must_fail git branch --unset-upstream && - git checkout - + test_when_finished git checkout - && + echo "fatal: could not unset upstream of HEAD when it does not point to any branch." >expect && + test_must_fail git branch --unset-upstream 2>err && + test_i18ncmp expect err ' test_expect_success 'test --unset-upstream on a particular branch' ' @@ -922,17 +941,17 @@ test_expect_success 'test --unset-upstream on a particular branch' ' ' test_expect_success 'disabled option --set-upstream fails' ' - test_must_fail git branch --set-upstream origin/master + test_must_fail git branch --set-upstream origin/master ' test_expect_success '--set-upstream-to notices an error to set branch as own upstream' ' git branch --set-upstream-to refs/heads/my13 my13 2>actual && - cat >expected <<-\EOF && + cat >expect <<-\EOF && warning: Not setting branch my13 as its own upstream. EOF test_expect_code 1 git config branch.my13.remote && test_expect_code 1 git config branch.my13.merge && - test_i18ncmp expected actual + test_i18ncmp expect actual ' # Keep this test last, as it changes the current branch diff --git a/t/t3426-rebase-submodule.sh b/t/t3426-rebase-submodule.sh index a2bba04ba9..0ad3a07bf4 100755 --- a/t/t3426-rebase-submodule.sh +++ b/t/t3426-rebase-submodule.sh @@ -17,10 +17,11 @@ git_rebase () { git status -su >actual && ls -1pR * >>actual && test_cmp expect actual && - git rebase "$1" + may_only_be_test_must_fail "$2" && + $2 git rebase "$1" } -test_submodule_switch "git_rebase" +test_submodule_switch_func "git_rebase" git_rebase_interactive () { git status -su >expect && @@ -35,10 +36,11 @@ git_rebase_interactive () { test_cmp expect actual && set_fake_editor && echo "fake-editor.sh" >.git/info/exclude && - git rebase -i "$1" + may_only_be_test_must_fail "$2" && + $2 git rebase -i "$1" } -test_submodule_switch "git_rebase_interactive" +test_submodule_switch_func "git_rebase_interactive" test_expect_success 'rebase interactive ignores modified submodules' ' test_when_finished "rm -rf super sub" && diff --git a/t/t3430-rebase-merges.sh b/t/t3430-rebase-merges.sh index a1bc3e2001..b454f400eb 100755 --- a/t/t3430-rebase-merges.sh +++ b/t/t3430-rebase-merges.sh @@ -420,7 +420,7 @@ test_expect_success 'with --autosquash and --exec' ' git commit --fixup B B.t && write_script show.sh <<-\EOF && subject="$(git show -s --format=%s HEAD)" - content="$(git diff HEAD^! | tail -n 1)" + content="$(git diff HEAD^ HEAD | tail -n 1)" echo "$subject: $content" EOF test_tick && diff --git a/t/t3512-cherry-pick-submodule.sh b/t/t3512-cherry-pick-submodule.sh index bd78287841..6ece1d8573 100755 --- a/t/t3512-cherry-pick-submodule.sh +++ b/t/t3512-cherry-pick-submodule.sh @@ -7,7 +7,7 @@ test_description='cherry-pick can handle submodules' 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_submodule_switch "cherry-pick" test_expect_success 'unrelated submodule/file conflict is ignored' ' test_create_repo sub && diff --git a/t/t3513-revert-submodule.sh b/t/t3513-revert-submodule.sh index 5e39fcdb66..a759f12cbb 100755 --- a/t/t3513-revert-submodule.sh +++ b/t/t3513-revert-submodule.sh @@ -15,7 +15,12 @@ git_revert () { git status -su >expect && ls -1pR * >>expect && tar cf "$TRASH_DIRECTORY/tmp.tar" * && - git checkout "$1" && + may_only_be_test_must_fail "$2" && + $2 git checkout "$1" && + if test -n "$2" + then + return + fi && git revert HEAD && rm -rf * && tar xf "$TRASH_DIRECTORY/tmp.tar" && @@ -26,6 +31,6 @@ git_revert () { } KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1 -test_submodule_switch "git_revert" +test_submodule_switch_func "git_revert" test_done diff --git a/t/t3701-add-interactive.sh b/t/t3701-add-interactive.sh index b3d8bb7577..49decbac71 100755 --- a/t/t3701-add-interactive.sh +++ b/t/t3701-add-interactive.sh @@ -412,6 +412,25 @@ test_expect_success 'deleting an empty file' ' diff_cmp expected diff ' +test_expect_success 'adding an empty file' ' + git init added && + ( + cd added && + test_commit initial && + >empty && + git add empty && + test_tick && + git commit -m empty && + git tag added-file && + git reset --hard HEAD^ && + test_path_is_missing empty && + + echo y | git checkout -p added-file -- >actual && + test_path_is_file empty && + test_i18ngrep "Apply addition to index and worktree" actual + ) +' + test_expect_success 'split hunk setup' ' git reset --hard && test_write_lines 10 20 30 40 50 60 >test && diff --git a/t/t3906-stash-submodule.sh b/t/t3906-stash-submodule.sh index b93d1d74da..a52e53dd2d 100755 --- a/t/t3906-stash-submodule.sh +++ b/t/t3906-stash-submodule.sh @@ -8,7 +8,12 @@ test_description='stash can handle submodules' git_stash () { git status -su >expect && ls -1pR * >>expect && - git read-tree -u -m "$1" && + may_only_be_test_must_fail "$2" && + $2 git read-tree -u -m "$1" && + if test -n "$2" + then + return + fi && git stash && git status -su >actual && ls -1pR * >>actual && @@ -19,7 +24,7 @@ git_stash () { 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_submodule_switch_func "git_stash" setup_basic () { test_when_finished "rm -rf main sub" && diff --git a/t/t4013-diff-various.sh b/t/t4013-diff-various.sh index 3f60f7d96c..43267d6024 100755 --- a/t/t4013-diff-various.sh +++ b/t/t4013-diff-various.sh @@ -117,12 +117,12 @@ test_expect_success setup ' : <<\EOF ! [initial] Initial - * [master] Merge branch 'side' + * [master] Merge branch 'side' into master ! [rearrange] Rearranged lines in dir/sub ! [side] Side ---- + [rearrange] Rearranged lines in dir/sub - - [master] Merge branch 'side' + - [master] Merge branch 'side' into master * + [side] Side * [master^] Third * [master~2] Second diff --git a/t/t4013/diff.log_--decorate=full_--all b/t/t4013/diff.log_--decorate=full_--all index 3f9b872ece..c56783b985 100644 --- a/t/t4013/diff.log_--decorate=full_--all +++ b/t/t4013/diff.log_--decorate=full_--all @@ -31,7 +31,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <author@example.com> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a (refs/heads/side) Author: A U Thor <author@example.com> diff --git a/t/t4013/diff.log_--decorate_--all b/t/t4013/diff.log_--decorate_--all index f5e20e1e14..1cbdc038f4 100644 --- a/t/t4013/diff.log_--decorate_--all +++ b/t/t4013/diff.log_--decorate_--all @@ -31,7 +31,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <author@example.com> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a (side) Author: A U Thor <author@example.com> diff --git a/t/t4013/diff.log_--patch-with-stat_--summary_master_--_dir_ b/t/t4013/diff.log_--patch-with-stat_--summary_master_--_dir_ index a18f1472a9..f5b1b6516b 100644 --- a/t/t4013/diff.log_--patch-with-stat_--summary_master_--_dir_ +++ b/t/t4013/diff.log_--patch-with-stat_--summary_master_--_dir_ @@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <author@example.com> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a Author: A U Thor <author@example.com> diff --git a/t/t4013/diff.log_--patch-with-stat_master b/t/t4013/diff.log_--patch-with-stat_master index ae425c4672..af23803cdc 100644 --- a/t/t4013/diff.log_--patch-with-stat_master +++ b/t/t4013/diff.log_--patch-with-stat_master @@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <author@example.com> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a Author: A U Thor <author@example.com> diff --git a/t/t4013/diff.log_--patch-with-stat_master_--_dir_ b/t/t4013/diff.log_--patch-with-stat_master_--_dir_ index d5207cadf4..814098fbf8 100644 --- a/t/t4013/diff.log_--patch-with-stat_master_--_dir_ +++ b/t/t4013/diff.log_--patch-with-stat_master_--_dir_ @@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <author@example.com> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a Author: A U Thor <author@example.com> diff --git a/t/t4013/diff.log_--root_--cc_--patch-with-stat_--summary_master b/t/t4013/diff.log_--root_--cc_--patch-with-stat_--summary_master index 0fc1e8cd71..b927fe4a98 100644 --- a/t/t4013/diff.log_--root_--cc_--patch-with-stat_--summary_master +++ b/t/t4013/diff.log_--root_--cc_--patch-with-stat_--summary_master @@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <author@example.com> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master dir/sub | 2 ++ file0 | 3 +++ diff --git a/t/t4013/diff.log_--root_--patch-with-stat_--summary_master b/t/t4013/diff.log_--root_--patch-with-stat_--summary_master index dffc09dde9..6db3cea329 100644 --- a/t/t4013/diff.log_--root_--patch-with-stat_--summary_master +++ b/t/t4013/diff.log_--root_--patch-with-stat_--summary_master @@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <author@example.com> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a Author: A U Thor <author@example.com> diff --git a/t/t4013/diff.log_--root_--patch-with-stat_master b/t/t4013/diff.log_--root_--patch-with-stat_master index 55aa98012d..98e9c320c3 100644 --- a/t/t4013/diff.log_--root_--patch-with-stat_master +++ b/t/t4013/diff.log_--root_--patch-with-stat_master @@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <author@example.com> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a Author: A U Thor <author@example.com> diff --git a/t/t4013/diff.log_--root_-c_--patch-with-stat_--summary_master b/t/t4013/diff.log_--root_-c_--patch-with-stat_--summary_master index 019d85f7de..b61b1117ae 100644 --- a/t/t4013/diff.log_--root_-c_--patch-with-stat_--summary_master +++ b/t/t4013/diff.log_--root_-c_--patch-with-stat_--summary_master @@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <author@example.com> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master dir/sub | 2 ++ file0 | 3 +++ diff --git a/t/t4013/diff.log_--root_-p_master b/t/t4013/diff.log_--root_-p_master index b42c334439..345bd9e8a9 100644 --- a/t/t4013/diff.log_--root_-p_master +++ b/t/t4013/diff.log_--root_-p_master @@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <author@example.com> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a Author: A U Thor <author@example.com> diff --git a/t/t4013/diff.log_--root_master b/t/t4013/diff.log_--root_master index e8f46159da..db56b1fe6b 100644 --- a/t/t4013/diff.log_--root_master +++ b/t/t4013/diff.log_--root_master @@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <author@example.com> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a Author: A U Thor <author@example.com> diff --git a/t/t4013/diff.log_-m_-p_--first-parent_master b/t/t4013/diff.log_-m_-p_--first-parent_master index 7a0073f529..bcadb50e26 100644 --- a/t/t4013/diff.log_-m_-p_--first-parent_master +++ b/t/t4013/diff.log_-m_-p_--first-parent_master @@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <author@example.com> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master diff --git a/dir/sub b/dir/sub index cead32e..992913c 100644 diff --git a/t/t4013/diff.log_-m_-p_master b/t/t4013/diff.log_-m_-p_master index 9ca62a01ed..2acf43a9fb 100644 --- a/t/t4013/diff.log_-m_-p_master +++ b/t/t4013/diff.log_-m_-p_master @@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <author@example.com> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master diff --git a/dir/sub b/dir/sub index cead32e..992913c 100644 @@ -33,7 +33,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <author@example.com> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master diff --git a/dir/sub b/dir/sub index 7289e35..992913c 100644 diff --git a/t/t4013/diff.log_-p_--first-parent_master b/t/t4013/diff.log_-p_--first-parent_master index 3fc896d424..c6a5876d80 100644 --- a/t/t4013/diff.log_-p_--first-parent_master +++ b/t/t4013/diff.log_-p_--first-parent_master @@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <author@example.com> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master commit 9a6d4949b6b76956d9d5e26f2791ec2ceff5fdc0 Author: A U Thor <author@example.com> diff --git a/t/t4013/diff.log_-p_master b/t/t4013/diff.log_-p_master index bf1326dc36..1841cded94 100644 --- a/t/t4013/diff.log_-p_master +++ b/t/t4013/diff.log_-p_master @@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <author@example.com> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a Author: A U Thor <author@example.com> diff --git a/t/t4013/diff.log_master b/t/t4013/diff.log_master index a8f6ce5abd..f8ec445eb3 100644 --- a/t/t4013/diff.log_master +++ b/t/t4013/diff.log_master @@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <author@example.com> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master commit c7a2ab9e8eac7b117442a607d5a9b3950ae34d5a Author: A U Thor <author@example.com> diff --git a/t/t4013/diff.show_--first-parent_master b/t/t4013/diff.show_--first-parent_master index 3dcbe473a0..94548f4598 100644 --- a/t/t4013/diff.show_--first-parent_master +++ b/t/t4013/diff.show_--first-parent_master @@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <author@example.com> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master diff --git a/dir/sub b/dir/sub index cead32e..992913c 100644 diff --git a/t/t4013/diff.show_-c_master b/t/t4013/diff.show_-c_master index 81aba8da96..1c46ed64fd 100644 --- a/t/t4013/diff.show_-c_master +++ b/t/t4013/diff.show_-c_master @@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <author@example.com> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master diff --combined dir/sub index cead32e,7289e35..992913c diff --git a/t/t4013/diff.show_-m_master b/t/t4013/diff.show_-m_master index 4ea2ee453d..7559fc22f8 100644 --- a/t/t4013/diff.show_-m_master +++ b/t/t4013/diff.show_-m_master @@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <author@example.com> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master diff --git a/dir/sub b/dir/sub index cead32e..992913c 100644 @@ -33,7 +33,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <author@example.com> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master diff --git a/dir/sub b/dir/sub index 7289e35..992913c 100644 diff --git a/t/t4013/diff.show_master b/t/t4013/diff.show_master index fb08ce0e46..57091c5d90 100644 --- a/t/t4013/diff.show_master +++ b/t/t4013/diff.show_master @@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <author@example.com> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master diff --cc dir/sub index cead32e,7289e35..992913c diff --git a/t/t4013/diff.whatchanged_--root_--cc_--patch-with-stat_--summary_master b/t/t4013/diff.whatchanged_--root_--cc_--patch-with-stat_--summary_master index 30aae7817b..5f13a71bb5 100644 --- a/t/t4013/diff.whatchanged_--root_--cc_--patch-with-stat_--summary_master +++ b/t/t4013/diff.whatchanged_--root_--cc_--patch-with-stat_--summary_master @@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <author@example.com> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master dir/sub | 2 ++ file0 | 3 +++ diff --git a/t/t4013/diff.whatchanged_--root_-c_--patch-with-stat_--summary_master b/t/t4013/diff.whatchanged_--root_-c_--patch-with-stat_--summary_master index d1d32bd34c..8acb88267b 100644 --- a/t/t4013/diff.whatchanged_--root_-c_--patch-with-stat_--summary_master +++ b/t/t4013/diff.whatchanged_--root_-c_--patch-with-stat_--summary_master @@ -4,7 +4,7 @@ Merge: 9a6d494 c7a2ab9 Author: A U Thor <author@example.com> Date: Mon Jun 26 00:04:00 2006 +0000 - Merge branch 'side' + Merge branch 'side' into master dir/sub | 2 ++ file0 | 3 +++ diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index db7e733af9..958c2da56e 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -81,16 +81,16 @@ test_expect_success 'format-patch --ignore-if-in-upstream handles tags' ' ' test_expect_success "format-patch doesn't consider merge commits" ' - git checkout -b slave master && + git checkout -b feature master && echo "Another line" >>file && test_tick && - git commit -am "Slave change #1" && + git commit -am "Feature branch change #1" && echo "Yet another line" >>file && test_tick && - git commit -am "Slave change #2" && + git commit -am "Feature branch change #2" && git checkout -b merger master && test_tick && - git merge --no-ff slave && + git merge --no-ff feature && git format-patch -3 --stdout >patch && grep "^From " patch >from && test_line_count = 3 from @@ -1602,6 +1602,19 @@ test_expect_success 'format patch ignores color.ui' ' test_cmp expect actual ' +test_expect_success 'format patch respects diff.relative' ' + rm -rf subdir && + mkdir subdir && + echo other content >subdir/file2 && + git add subdir/file2 && + git commit -F msg && + test_unconfig diff.relative && + git format-patch --relative=subdir --stdout -1 >expect && + test_config diff.relative true && + git -C subdir format-patch --stdout -1 >actual && + test_cmp expect actual +' + test_expect_success 'cover letter with invalid --cover-from-description and config' ' test_config branch.rebuild-1.description "config subject diff --git a/t/t4045-diff-relative.sh b/t/t4045-diff-relative.sh index 258808708e..7be1de736d 100755 --- a/t/t4045-diff-relative.sh +++ b/t/t4045-diff-relative.sh @@ -8,7 +8,8 @@ test_expect_success 'setup' ' echo content >file1 && mkdir subdir && echo other content >subdir/file2 && - blob=$(git hash-object subdir/file2) && + blob_file1=$(git hash-object file1) && + blob_file2=$(git hash-object subdir/file2) && git add . && git commit -m one ' @@ -18,7 +19,7 @@ check_diff () { shift expect=$1 shift - short_blob=$(git rev-parse --short $blob) + short_blob=$(git rev-parse --short $blob_file2) cat >expected <<-EOF diff --git a/$expect b/$expect new file mode 100644 @@ -70,7 +71,7 @@ check_raw () { expect=$1 shift cat >expected <<-EOF - :000000 100644 $ZERO_OID $blob A $expect + :000000 100644 $ZERO_OID $blob_file2 A $expect EOF test_expect_success "--raw $*" " git -C '$dir' diff --no-abbrev --raw $* HEAD^ >actual && @@ -86,4 +87,79 @@ do check_$type . dir/file2 --relative=sub done +check_diff_relative_option () { + dir=$1 + shift + expect=$1 + shift + relative_opt=$1 + shift + test_expect_success "config diff.relative $relative_opt -p $*" " + short_blob=\$(git rev-parse --short $blob_file2) && + cat >expected <<-EOF && + diff --git a/$expect b/$expect + new file mode 100644 + index 0000000..\$short_blob + --- /dev/null + +++ b/$expect + @@ -0,0 +1 @@ + +other content + EOF + test_config -C $dir diff.relative $relative_opt && + git -C '$dir' diff -p $* HEAD^ >actual && + test_cmp expected actual + " +} + +check_diff_no_relative_option () { + dir=$1 + shift + expect=$1 + shift + relative_opt=$1 + shift + test_expect_success "config diff.relative $relative_opt -p $*" " + short_blob_file1=\$(git rev-parse --short $blob_file1) && + short_blob_file2=\$(git rev-parse --short $blob_file2) && + cat >expected <<-EOF && + diff --git a/file1 b/file1 + new file mode 100644 + index 0000000..\$short_blob_file1 + --- /dev/null + +++ b/file1 + @@ -0,0 +1 @@ + +content + diff --git a/$expect b/$expect + new file mode 100644 + index 0000000..\$short_blob_file2 + --- /dev/null + +++ b/$expect + @@ -0,0 +1 @@ + +other content + EOF + test_config -C $dir diff.relative $relative_opt && + git -C '$dir' diff -p $* HEAD^ >actual && + test_cmp expected actual + " +} + +check_diff_no_relative_option . subdir/file2 false +check_diff_no_relative_option . subdir/file2 true --no-relative +check_diff_no_relative_option . subdir/file2 false --no-relative +check_diff_no_relative_option subdir subdir/file2 false +check_diff_no_relative_option subdir subdir/file2 true --no-relative +check_diff_no_relative_option subdir subdir/file2 false --no-relative + +check_diff_relative_option . file2 false --relative=subdir/ +check_diff_relative_option . file2 false --relative=subdir +check_diff_relative_option . file2 true --relative=subdir/ +check_diff_relative_option . file2 true --relative=subdir +check_diff_relative_option subdir file2 false --relative +check_diff_relative_option subdir file2 true --relative +check_diff_relative_option subdir file2 true +check_diff_relative_option subdir file2 false --no-relative --relative +check_diff_relative_option subdir file2 true --no-relative --relative +check_diff_relative_option . file2 false --no-relative --relative=subdir +check_diff_relative_option . file2 true --no-relative --relative=subdir + test_done diff --git a/t/t4068-diff-symmetric.sh b/t/t4068-diff-symmetric.sh new file mode 100755 index 0000000000..31d17a5af0 --- /dev/null +++ b/t/t4068-diff-symmetric.sh @@ -0,0 +1,91 @@ +#!/bin/sh + +test_description='behavior of diff with symmetric-diff setups' + +. ./test-lib.sh + +# build these situations: +# - normal merge with one merge base (br1...b2r); +# - criss-cross merge ie 2 merge bases (br1...master); +# - disjoint subgraph (orphan branch, br3...master). +# +# B---E <-- master +# / \ / +# A X +# \ / \ +# C---D--G <-- br1 +# \ / +# ---F <-- br2 +# +# H <-- br3 +# +# We put files into a few commits so that we can verify the +# output as well. + +test_expect_success setup ' + git commit --allow-empty -m A && + echo b >b && + git add b && + git commit -m B && + git checkout -b br1 HEAD^ && + echo c >c && + git add c && + git commit -m C && + git tag commit-C && + git merge -m D master && + git tag commit-D && + git checkout master && + git merge -m E commit-C && + git checkout -b br2 commit-C && + echo f >f && + git add f && + git commit -m F && + git checkout br1 && + git merge -m G br2 && + git checkout --orphan br3 && + git commit -m H +' + +test_expect_success 'diff with one merge base' ' + git diff commit-D...br1 >tmp && + tail -n 1 tmp >actual && + echo +f >expect && + test_cmp expect actual +' + +# The output (in tmp) can have +b or +c depending +# on which merge base (commit B or C) is picked. +# It should have one of those two, which comes out +# to seven lines. +test_expect_success 'diff with two merge bases' ' + git diff br1...master >tmp 2>err && + test_line_count = 7 tmp && + test_line_count = 1 err +' + +test_expect_success 'diff with no merge bases' ' + test_must_fail git diff br2...br3 >tmp 2>err && + test_i18ngrep "fatal: br2...br3: no merge base" err +' + +test_expect_success 'diff with too many symmetric differences' ' + test_must_fail git diff br1...master br2...br3 >tmp 2>err && + test_i18ngrep "usage" err +' + +test_expect_success 'diff with symmetric difference and extraneous arg' ' + test_must_fail git diff master br1...master >tmp 2>err && + test_i18ngrep "usage" err +' + +test_expect_success 'diff with two ranges' ' + test_must_fail git diff master br1..master br2..br3 >tmp 2>err && + test_i18ngrep "usage" err +' + +test_expect_success 'diff with ranges and extra arg' ' + test_must_fail git diff master br1..master commit-D >tmp 2>err && + test_i18ngrep "usage" err +' + +test_done diff --git a/t/t4137-apply-submodule.sh b/t/t4137-apply-submodule.sh index a9bd40a6d0..07d5262537 100755 --- a/t/t4137-apply-submodule.sh +++ b/t/t4137-apply-submodule.sh @@ -6,15 +6,19 @@ test_description='git apply handling submodules' . "$TEST_DIRECTORY"/lib-submodule-update.sh apply_index () { - git diff --ignore-submodules=dirty "..$1" | git apply --index - + git diff --ignore-submodules=dirty "..$1" >diff && + may_only_be_test_must_fail "$2" && + $2 git apply --index diff } -test_submodule_switch "apply_index" +test_submodule_switch_func "apply_index" apply_3way () { - git diff --ignore-submodules=dirty "..$1" | git apply --3way - + git diff --ignore-submodules=dirty "..$1" >diff && + may_only_be_test_must_fail "$2" && + $2 git apply --3way diff } -test_submodule_switch "apply_3way" +test_submodule_switch_func "apply_3way" test_done diff --git a/t/t4202-log.sh b/t/t4202-log.sh index f1ea7d97f5..fd9af658af 100755 --- a/t/t4202-log.sh +++ b/t/t4202-log.sh @@ -483,7 +483,7 @@ test_expect_success 'set up merge history' ' ' cat > expect <<\EOF -* Merge branch 'side' +* Merge branch 'side' into master |\ | * side-2 | * side-1 @@ -502,7 +502,7 @@ test_expect_success 'log --graph with merge' ' ' cat > expect <<\EOF -| | | * Merge branch 'side' +| | | * Merge branch 'side' into master | | | |\ | | | | * side-2 | | | | * side-1 @@ -521,7 +521,7 @@ test_expect_success 'log --graph --line-prefix="| | | " with merge' ' ' cat > expect.colors <<\EOF -* Merge branch 'side' +* Merge branch 'side' into master <BLUE>|<RESET><CYAN>\<RESET> <BLUE>|<RESET> * side-2 <BLUE>|<RESET> * side-1 @@ -555,7 +555,7 @@ cat > expect <<\EOF |\ Merge: A B | | Author: A U Thor <author@example.com> | | -| | Merge branch 'side' +| | Merge branch 'side' into master | | | * commit tags/side-2 | | Author: A U Thor <author@example.com> @@ -632,11 +632,11 @@ test_expect_success 'set up more tangled history' ' ' cat > expect <<\EOF -* Merge tag 'reach' +* Merge tag 'reach' into master |\ | \ | \ -*-. \ Merge tags 'octopus-a' and 'octopus-b' +*-. \ Merge tags 'octopus-a' and 'octopus-b' into master |\ \ \ * | | | seventh | | * | octopus-b @@ -646,14 +646,14 @@ cat > expect <<\EOF |/ / | * reach |/ -* Merge branch 'tangle' +* Merge branch 'tangle' into master |\ | * Merge branch 'side' (early part) into tangle | |\ | * \ Merge branch 'master' (early part) into tangle | |\ \ | * | | tangle-a -* | | | Merge branch 'side' +* | | | Merge branch 'side' into master |\ \ \ \ | * | | | side-2 | | |_|/ @@ -735,16 +735,16 @@ test_expect_success 'log.decorate configuration' ' test_expect_success 'decorate-refs with glob' ' cat >expect.decorate <<-\EOF && - Merge-tag-reach - Merge-tags-octopus-a-and-octopus-b + Merge-tag-reach-into-master + Merge-tags-octopus-a-and-octopus-b-into-master seventh octopus-b (octopus-b) octopus-a (octopus-a) reach EOF cat >expect.no-decorate <<-\EOF && - Merge-tag-reach - Merge-tags-octopus-a-and-octopus-b + Merge-tag-reach-into-master + Merge-tags-octopus-a-and-octopus-b-into-master seventh octopus-b octopus-a @@ -765,8 +765,8 @@ test_expect_success 'decorate-refs with glob' ' test_expect_success 'decorate-refs without globs' ' cat >expect.decorate <<-\EOF && - Merge-tag-reach - Merge-tags-octopus-a-and-octopus-b + Merge-tag-reach-into-master + Merge-tags-octopus-a-and-octopus-b-into-master seventh octopus-b octopus-a @@ -779,8 +779,8 @@ test_expect_success 'decorate-refs without globs' ' test_expect_success 'multiple decorate-refs' ' cat >expect.decorate <<-\EOF && - Merge-tag-reach - Merge-tags-octopus-a-and-octopus-b + Merge-tag-reach-into-master + Merge-tags-octopus-a-and-octopus-b-into-master seventh octopus-b (octopus-b) octopus-a (octopus-a) @@ -794,8 +794,8 @@ test_expect_success 'multiple decorate-refs' ' test_expect_success 'decorate-refs-exclude with glob' ' cat >expect.decorate <<-\EOF && - Merge-tag-reach (HEAD -> master) - Merge-tags-octopus-a-and-octopus-b + Merge-tag-reach-into-master (HEAD -> master) + Merge-tags-octopus-a-and-octopus-b-into-master seventh (tag: seventh) octopus-b (tag: octopus-b) octopus-a (tag: octopus-a) @@ -811,8 +811,8 @@ test_expect_success 'decorate-refs-exclude with glob' ' test_expect_success 'decorate-refs-exclude without globs' ' cat >expect.decorate <<-\EOF && - Merge-tag-reach (HEAD -> master) - Merge-tags-octopus-a-and-octopus-b + Merge-tag-reach-into-master (HEAD -> master) + Merge-tags-octopus-a-and-octopus-b-into-master seventh (tag: seventh) octopus-b (tag: octopus-b, octopus-b) octopus-a (tag: octopus-a, octopus-a) @@ -828,8 +828,8 @@ test_expect_success 'decorate-refs-exclude without globs' ' test_expect_success 'multiple decorate-refs-exclude' ' cat >expect.decorate <<-\EOF && - Merge-tag-reach (HEAD -> master) - Merge-tags-octopus-a-and-octopus-b + Merge-tag-reach-into-master (HEAD -> master) + Merge-tags-octopus-a-and-octopus-b-into-master seventh (tag: seventh) octopus-b (tag: octopus-b) octopus-a (tag: octopus-a) @@ -851,8 +851,8 @@ test_expect_success 'multiple decorate-refs-exclude' ' test_expect_success 'decorate-refs and decorate-refs-exclude' ' cat >expect.no-decorate <<-\EOF && - Merge-tag-reach (master) - Merge-tags-octopus-a-and-octopus-b + Merge-tag-reach-into-master (master) + Merge-tags-octopus-a-and-octopus-b-into-master seventh octopus-b octopus-a @@ -866,8 +866,8 @@ test_expect_success 'decorate-refs and decorate-refs-exclude' ' test_expect_success 'deocrate-refs and log.excludeDecoration' ' cat >expect.decorate <<-\EOF && - Merge-tag-reach (master) - Merge-tags-octopus-a-and-octopus-b + Merge-tag-reach-into-master (master) + Merge-tags-octopus-a-and-octopus-b-into-master seventh octopus-b (octopus-b) octopus-a (octopus-a) @@ -881,10 +881,10 @@ test_expect_success 'deocrate-refs and log.excludeDecoration' ' test_expect_success 'decorate-refs-exclude and simplify-by-decoration' ' cat >expect.decorate <<-\EOF && - Merge-tag-reach (HEAD -> master) + Merge-tag-reach-into-master (HEAD -> master) reach (tag: reach, reach) seventh (tag: seventh) - Merge-branch-tangle + Merge-branch-tangle-into-master Merge-branch-side-early-part-into-tangle (tangle) tangle-a (tag: tangle-a) EOF @@ -1068,7 +1068,7 @@ cat >expect <<\EOF |\ Merge: MERGE_PARENTS | | Author: A U Thor <author@example.com> | | -| | Merge branch 'tangle' +| | Merge branch 'tangle' into master | | | * commit COMMIT_OBJECT_NAME | |\ Merge: MERGE_PARENTS @@ -1102,7 +1102,7 @@ cat >expect <<\EOF |\ \ \ \ Merge: MERGE_PARENTS | | | | | Author: A U Thor <author@example.com> | | | | | -| | | | | Merge branch 'side' +| | | | | Merge branch 'side' into master | | | | | | * | | | commit COMMIT_OBJECT_NAME | | |_|/ Author: A U Thor <author@example.com> @@ -1343,7 +1343,7 @@ cat >expect <<\EOF *** |\ Merge: MERGE_PARENTS *** | | Author: A U Thor <author@example.com> *** | | -*** | | Merge branch 'tangle' +*** | | Merge branch 'tangle' into master *** | | *** | * commit COMMIT_OBJECT_NAME *** | |\ Merge: MERGE_PARENTS @@ -1377,7 +1377,7 @@ cat >expect <<\EOF *** |\ \ \ \ Merge: MERGE_PARENTS *** | | | | | Author: A U Thor <author@example.com> *** | | | | | -*** | | | | | Merge branch 'side' +*** | | | | | Merge branch 'side' into master *** | | | | | *** | * | | | commit COMMIT_OBJECT_NAME *** | | |_|/ Author: A U Thor <author@example.com> @@ -1540,8 +1540,8 @@ cat >expect <<-\EOF * reach | | A reach.t -* Merge branch 'tangle' -* Merge branch 'side' +* Merge branch 'tangle' into master +* Merge branch 'side' into master |\ | * side-2 | @@ -1562,8 +1562,8 @@ cat >expect <<-\EOF * reach | | reach.t -* Merge branch 'tangle' -* Merge branch 'side' +* Merge branch 'tangle' into master +* Merge branch 'side' into master |\ | * side-2 | @@ -1692,7 +1692,7 @@ test_expect_success GPG 'log --graph --show-signature for merged tag with missin GNUPGHOME=. git log --graph --show-signature -n1 plain-nokey >actual && grep "^|\\\ merged tag" actual && grep "^| | gpg: Signature made" actual && - grep "^| | gpg: Can'"'"'t check signature: \(public key not found\|No public key\)" actual + grep -E "^| | gpg: Can'"'"'t check signature: (public key not found|No public key)" actual ' test_expect_success GPG 'log --graph --show-signature for merged tag with bad signature' ' diff --git a/t/t4210-log-i18n.sh b/t/t4210-log-i18n.sh index c3792081e6..d2dfcf164e 100755 --- a/t/t4210-log-i18n.sh +++ b/t/t4210-log-i18n.sh @@ -10,6 +10,13 @@ latin1_e=$(printf '\351') # invalid UTF-8 invalid_e=$(printf '\303\50)') # ")" at end to close opening "(" +have_reg_illseq= +if test_have_prereq GETTEXT_LOCALE && + ! LC_ALL=$is_IS_locale test-tool regex --silent $latin1_e +then + have_reg_illseq=1 +fi + test_expect_success 'create commits in different encodings' ' test_tick && cat >msg <<-EOF && @@ -51,43 +58,77 @@ test_expect_success !MINGW 'log --grep does not find non-reencoded values (utf8) test_must_be_empty actual ' -test_expect_success !MINGW 'log --grep does not find non-reencoded values (latin1)' ' +test_expect_success 'log --grep does not find non-reencoded values (latin1)' ' git log --encoding=ISO-8859-1 --format=%s --grep=$utf8_e >actual && test_must_be_empty actual ' +triggers_undefined_behaviour () { + local engine=$1 + + case $engine in + fixed) + if test -n "$have_reg_illseq" && + ! test_have_prereq LIBPCRE2 + then + return 0 + fi + ;; + basic|extended) + if test -n "$have_reg_illseq" + then + return 0 + fi + ;; + esac + return 1 +} + +mismatched_git_log () { + local pattern=$1 + + LC_ALL=$is_IS_locale git log --encoding=ISO-8859-1 --format=%s \ + --grep=$pattern +} + for engine in fixed basic extended perl do prereq= if test $engine = "perl" then - prereq="PCRE" - else - prereq="" + prereq=PCRE fi force_regex= if test $engine != "fixed" then - force_regex=.* + force_regex='.*' fi - test_expect_success !MINGW,!REGEX_ILLSEQ,GETTEXT_LOCALE,$prereq "-c grep.patternType=$engine log --grep does not find non-reencoded values (latin1 + locale)" " - cat >expect <<-\EOF && - latin1 - utf8 - EOF - LC_ALL=\"$is_IS_locale\" git -c grep.patternType=$engine log --encoding=ISO-8859-1 --format=%s --grep=\"$force_regex$latin1_e\" >actual && - test_cmp expect actual - " - test_expect_success !MINGW,GETTEXT_LOCALE,$prereq "-c grep.patternType=$engine log --grep does not find non-reencoded values (latin1 + locale)" " - LC_ALL=\"$is_IS_locale\" git -c grep.patternType=$engine log --encoding=ISO-8859-1 --format=%s --grep=\"$force_regex$utf8_e\" >actual && - test_must_be_empty actual + test_expect_success $prereq "config grep.patternType=$engine" " + git config grep.patternType $engine " - test_expect_success !MINGW,!REGEX_ILLSEQ,GETTEXT_LOCALE,$prereq "-c grep.patternType=$engine log --grep does not die on invalid UTF-8 value (latin1 + locale + invalid needle)" " - LC_ALL=\"$is_IS_locale\" git -c grep.patternType=$engine log --encoding=ISO-8859-1 --format=%s --grep=\"$force_regex$invalid_e\" >actual && + test_expect_success GETTEXT_LOCALE,$prereq "log --grep does not find non-reencoded values (latin1 + locale)" " + mismatched_git_log '$force_regex$utf8_e' >actual && test_must_be_empty actual " + + if ! triggers_undefined_behaviour $engine + then + test_expect_success !MINGW,GETTEXT_LOCALE,$prereq "log --grep searches in log output encoding (latin1 + locale)" " + cat >expect <<-\EOF && + latin1 + utf8 + EOF + mismatched_git_log '$force_regex$latin1_e' >actual && + test_cmp expect actual + " + + test_expect_success GETTEXT_LOCALE,$prereq "log --grep does not die on invalid UTF-8 value (latin1 + locale + invalid needle)" " + mismatched_git_log '$force_regex$invalid_e' >actual && + test_must_be_empty actual + " + fi done test_done diff --git a/t/t4211-line-log.sh b/t/t4211-line-log.sh index cda58186c2..e186c83250 100755 --- a/t/t4211-line-log.sh +++ b/t/t4211-line-log.sh @@ -215,4 +215,80 @@ test_expect_success 'fancy rename following #2' ' test_cmp expect actual ' +# Create the following linear history, where each commit does what its +# subject line promises: +# +# * 66c6410 Modify func2() in file.c +# * 50834e5 Modify other-file +# * fe5851c Modify func1() in file.c +# * 8c7c7dd Add other-file +# * d5f4417 Add func1() and func2() in file.c +test_expect_success 'setup for checking line-log and parent oids' ' + git checkout --orphan parent-oids && + git reset --hard && + + cat >file.c <<-\EOF && + int func1() + { + return F1; + } + + int func2() + { + return F2; + } + EOF + git add file.c && + test_tick && + first_tick=$test_tick && + git commit -m "Add func1() and func2() in file.c" && + + echo 1 >other-file && + git add other-file && + test_tick && + git commit -m "Add other-file" && + + sed -e "s/F1/F1 + 1/" file.c >tmp && + mv tmp file.c && + git commit -a -m "Modify func1() in file.c" && + + echo 2 >other-file && + git commit -a -m "Modify other-file" && + + sed -e "s/F2/F2 + 2/" file.c >tmp && + mv tmp file.c && + git commit -a -m "Modify func2() in file.c" && + + head_oid=$(git rev-parse --short HEAD) && + prev_oid=$(git rev-parse --short HEAD^) && + root_oid=$(git rev-parse --short HEAD~4) +' + +# Parent oid should be from immediate parent. +test_expect_success 'parent oids without parent rewriting' ' + cat >expect <<-EOF && + $head_oid $prev_oid Modify func2() in file.c + $root_oid Add func1() and func2() in file.c + EOF + git log --format="%h %p %s" --no-patch -L:func2:file.c >actual && + test_cmp expect actual +' + +# Parent oid should be from the most recent ancestor touching func2(), +# i.e. in this case from the root commit. +test_expect_success 'parent oids with parent rewriting' ' + cat >expect <<-EOF && + $head_oid $root_oid Modify func2() in file.c + $root_oid Add func1() and func2() in file.c + EOF + git log --format="%h %p %s" --no-patch -L:func2:file.c --parents >actual && + test_cmp expect actual +' + +test_expect_success 'line-log with --before' ' + echo $root_oid >expect && + git log --format=%h --no-patch -L:func2:file.c --before=$first_tick >actual && + test_cmp expect actual +' + test_done diff --git a/t/t4255-am-submodule.sh b/t/t4255-am-submodule.sh index 0ba8194403..a7ba08f728 100755 --- a/t/t4255-am-submodule.sh +++ b/t/t4255-am-submodule.sh @@ -6,17 +6,21 @@ test_description='git am handling submodules' . "$TEST_DIRECTORY"/lib-submodule-update.sh am () { - git format-patch --stdout --ignore-submodules=dirty "..$1" | git am - + git format-patch --stdout --ignore-submodules=dirty "..$1" >patch && + may_only_be_test_must_fail "$2" && + $2 git am patch } -test_submodule_switch "am" +test_submodule_switch_func "am" am_3way () { - git format-patch --stdout --ignore-submodules=dirty "..$1" | git am --3way - + git format-patch --stdout --ignore-submodules=dirty "..$1" >patch && + may_only_be_test_must_fail "$2" && + $2 git am --3way patch } KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1 -test_submodule_switch "am_3way" +test_submodule_switch_func "am_3way" test_expect_success 'setup diff.submodule' ' test_commit one && diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh index 410a09b0dd..746cdb626e 100755 --- a/t/t5300-pack-object.sh +++ b/t/t5300-pack-object.sh @@ -12,7 +12,8 @@ TRASH=$(pwd) test_expect_success \ 'setup' \ - 'rm -f .git/index* && + 'test_oid_init && + rm -f .git/index* && perl -e "print \"a\" x 4096;" > a && perl -e "print \"b\" x 4096;" > b && perl -e "print \"c\" x 4096;" > c && @@ -412,18 +413,18 @@ test_expect_success 'set up pack for non-repo tests' ' ' test_expect_success 'index-pack --stdin complains of non-repo' ' - nongit test_must_fail git index-pack --stdin <foo.pack && + nongit test_must_fail git index-pack --object-format=$(test_oid algo) --stdin <foo.pack && test_path_is_missing non-repo/.git ' test_expect_success 'index-pack <pack> works in non-repo' ' - nongit git index-pack ../foo.pack && + nongit git index-pack --object-format=$(test_oid algo) ../foo.pack && test_path_is_file foo.idx ' test_expect_success 'index-pack --strict <pack> works in non-repo' ' rm -f foo.idx && - nongit git index-pack --strict ../foo.pack && + nongit git index-pack --strict --object-format=$(test_oid algo) ../foo.pack && test_path_is_file foo.idx ' diff --git a/t/t5302-pack-index.sh b/t/t5302-pack-index.sh index ad07f2f7fc..8981c9b90e 100755 --- a/t/t5302-pack-index.sh +++ b/t/t5302-pack-index.sh @@ -7,65 +7,65 @@ test_description='pack index with 64-bit offsets and object CRC' . ./test-lib.sh test_expect_success 'setup' ' - test_oid_init && - rawsz=$(test_oid rawsz) && - rm -rf .git && - git init && - git config pack.threads 1 && - i=1 && - while test $i -le 100 - do - iii=$(printf '%03i' $i) - test-tool genrandom "bar" 200 > wide_delta_$iii && - test-tool genrandom "baz $iii" 50 >> wide_delta_$iii && - test-tool genrandom "foo"$i 100 > deep_delta_$iii && - test-tool genrandom "foo"$(expr $i + 1) 100 >> deep_delta_$iii && - test-tool genrandom "foo"$(expr $i + 2) 100 >> deep_delta_$iii && - echo $iii >file_$iii && - test-tool genrandom "$iii" 8192 >>file_$iii && - git update-index --add file_$iii deep_delta_$iii wide_delta_$iii && - i=$(expr $i + 1) || return 1 - done && - { echo 101 && test-tool genrandom 100 8192; } >file_101 && - git update-index --add file_101 && - tree=$(git write-tree) && - commit=$(git commit-tree $tree </dev/null) && { - echo $tree && - git ls-tree $tree | sed -e "s/.* \\([0-9a-f]*\\) .*/\\1/" - } >obj-list && - git update-ref HEAD $commit + test_oid_init && + rawsz=$(test_oid rawsz) && + rm -rf .git && + git init && + git config pack.threads 1 && + i=1 && + while test $i -le 100 + do + iii=$(printf '%03i' $i) + test-tool genrandom "bar" 200 > wide_delta_$iii && + test-tool genrandom "baz $iii" 50 >> wide_delta_$iii && + test-tool genrandom "foo"$i 100 > deep_delta_$iii && + test-tool genrandom "foo"$(expr $i + 1) 100 >> deep_delta_$iii && + test-tool genrandom "foo"$(expr $i + 2) 100 >> deep_delta_$iii && + echo $iii >file_$iii && + test-tool genrandom "$iii" 8192 >>file_$iii && + git update-index --add file_$iii deep_delta_$iii wide_delta_$iii && + i=$(expr $i + 1) || return 1 + done && + { echo 101 && test-tool genrandom 100 8192; } >file_101 && + git update-index --add file_101 && + tree=$(git write-tree) && + commit=$(git commit-tree $tree </dev/null) && { + echo $tree && + git ls-tree $tree | sed -e "s/.* \\([0-9a-f]*\\) .*/\\1/" + } >obj-list && + git update-ref HEAD $commit ' -test_expect_success \ - 'pack-objects with index version 1' \ - 'pack1=$(git pack-objects --index-version=1 test-1 <obj-list) && - git verify-pack -v "test-1-${pack1}.pack"' +test_expect_success 'pack-objects with index version 1' ' + pack1=$(git pack-objects --index-version=1 test-1 <obj-list) && + git verify-pack -v "test-1-${pack1}.pack" +' -test_expect_success \ - 'pack-objects with index version 2' \ - 'pack2=$(git pack-objects --index-version=2 test-2 <obj-list) && - git verify-pack -v "test-2-${pack2}.pack"' +test_expect_success 'pack-objects with index version 2' ' + pack2=$(git pack-objects --index-version=2 test-2 <obj-list) && + git verify-pack -v "test-2-${pack2}.pack" +' -test_expect_success \ - 'both packs should be identical' \ - 'cmp "test-1-${pack1}.pack" "test-2-${pack2}.pack"' +test_expect_success 'both packs should be identical' ' + cmp "test-1-${pack1}.pack" "test-2-${pack2}.pack" +' -test_expect_success \ - 'index v1 and index v2 should be different' \ - '! cmp "test-1-${pack1}.idx" "test-2-${pack2}.idx"' +test_expect_success 'index v1 and index v2 should be different' ' + ! cmp "test-1-${pack1}.idx" "test-2-${pack2}.idx" +' -test_expect_success \ - 'index-pack with index version 1' \ - 'git index-pack --index-version=1 -o 1.idx "test-1-${pack1}.pack"' +test_expect_success 'index-pack with index version 1' ' + git index-pack --index-version=1 -o 1.idx "test-1-${pack1}.pack" +' -test_expect_success \ - 'index-pack with index version 2' \ - 'git index-pack --index-version=2 -o 2.idx "test-1-${pack1}.pack"' +test_expect_success 'index-pack with index version 2' ' + git index-pack --index-version=2 -o 2.idx "test-1-${pack1}.pack" +' -test_expect_success \ - 'index-pack results should match pack-objects ones' \ - 'cmp "test-1-${pack1}.idx" "1.idx" && - cmp "test-2-${pack2}.idx" "2.idx"' +test_expect_success 'index-pack results should match pack-objects ones' ' + cmp "test-1-${pack1}.idx" "1.idx" && + cmp "test-2-${pack2}.idx" "2.idx" +' test_expect_success 'index-pack --verify on index version 1' ' git index-pack --verify "test-1-${pack1}.pack" @@ -75,13 +75,13 @@ test_expect_success 'index-pack --verify on index version 2' ' git index-pack --verify "test-2-${pack2}.pack" ' -test_expect_success \ - 'pack-objects --index-version=2, is not accepted' \ - 'test_must_fail git pack-objects --index-version=2, test-3 <obj-list' +test_expect_success 'pack-objects --index-version=2, is not accepted' ' + test_must_fail git pack-objects --index-version=2, test-3 <obj-list +' -test_expect_success \ - 'index v2: force some 64-bit offsets with pack-objects' \ - 'pack3=$(git pack-objects --index-version=2,0x40000 test-3 <obj-list)' +test_expect_success 'index v2: force some 64-bit offsets with pack-objects' ' + pack3=$(git pack-objects --index-version=2,0x40000 test-3 <obj-list) +' if msg=$(git verify-pack -v "test-3-${pack3}.pack" 2>&1) || ! (echo "$msg" | grep "pack too large .* off_t") @@ -91,21 +91,21 @@ else say "# skipping tests concerning 64-bit offsets" fi -test_expect_success OFF64_T \ - 'index v2: verify a pack with some 64-bit offsets' \ - 'git verify-pack -v "test-3-${pack3}.pack"' +test_expect_success OFF64_T 'index v2: verify a pack with some 64-bit offsets' ' + git verify-pack -v "test-3-${pack3}.pack" +' -test_expect_success OFF64_T \ - '64-bit offsets: should be different from previous index v2 results' \ - '! cmp "test-2-${pack2}.idx" "test-3-${pack3}.idx"' +test_expect_success OFF64_T '64-bit offsets: should be different from previous index v2 results' ' + ! cmp "test-2-${pack2}.idx" "test-3-${pack3}.idx" +' -test_expect_success OFF64_T \ - 'index v2: force some 64-bit offsets with index-pack' \ - 'git index-pack --index-version=2,0x40000 -o 3.idx "test-1-${pack1}.pack"' +test_expect_success OFF64_T 'index v2: force some 64-bit offsets with index-pack' ' + git index-pack --index-version=2,0x40000 -o 3.idx "test-1-${pack1}.pack" +' -test_expect_success OFF64_T \ - '64-bit offsets: index-pack result should match pack-objects one' \ - 'cmp "test-3-${pack3}.idx" "3.idx"' +test_expect_success OFF64_T '64-bit offsets: index-pack result should match pack-objects one' ' + cmp "test-3-${pack3}.idx" "3.idx" +' test_expect_success OFF64_T 'index-pack --verify on 64-bit offset v2 (cheat)' ' # This cheats by knowing which lower offset should still be encoded @@ -120,135 +120,143 @@ test_expect_success OFF64_T 'index-pack --verify on 64-bit offset v2' ' # returns the object number for given object in given pack index index_obj_nr() { - idx_file=$1 - object_sha1=$2 - nr=0 - git show-index < $idx_file | - while read offs sha1 extra - do - nr=$(($nr + 1)) - test "$sha1" = "$object_sha1" || continue - echo "$(($nr - 1))" - break - done + idx_file=$1 + object_sha1=$2 + nr=0 + git show-index < $idx_file | + while read offs sha1 extra + do + nr=$(($nr + 1)) + test "$sha1" = "$object_sha1" || continue + echo "$(($nr - 1))" + break + done } # returns the pack offset for given object as found in given pack index index_obj_offset() { - idx_file=$1 - object_sha1=$2 - git show-index < $idx_file | grep $object_sha1 | - ( read offs extra && echo "$offs" ) + idx_file=$1 + object_sha1=$2 + git show-index < $idx_file | grep $object_sha1 | + ( read offs extra && echo "$offs" ) } -test_expect_success \ - '[index v1] 1) stream pack to repository' \ - 'git index-pack --index-version=1 --stdin < "test-1-${pack1}.pack" && - git prune-packed && - git count-objects | ( read nr rest && test "$nr" -eq 1 ) && - cmp "test-1-${pack1}.pack" ".git/objects/pack/pack-${pack1}.pack" && - cmp "test-1-${pack1}.idx" ".git/objects/pack/pack-${pack1}.idx"' +test_expect_success '[index v1] 1) stream pack to repository' ' + git index-pack --index-version=1 --stdin < "test-1-${pack1}.pack" && + git prune-packed && + git count-objects | ( read nr rest && test "$nr" -eq 1 ) && + cmp "test-1-${pack1}.pack" ".git/objects/pack/pack-${pack1}.pack" && + cmp "test-1-${pack1}.idx" ".git/objects/pack/pack-${pack1}.idx" +' test_expect_success \ - '[index v1] 2) create a stealth corruption in a delta base reference' \ - '# This test assumes file_101 is a delta smaller than 16 bytes. - # It should be against file_100 but we substitute its base for file_099 - sha1_101=$(git hash-object file_101) && - sha1_099=$(git hash-object file_099) && - offs_101=$(index_obj_offset 1.idx $sha1_101) && - nr_099=$(index_obj_nr 1.idx $sha1_099) && - chmod +w ".git/objects/pack/pack-${pack1}.pack" && - recordsz=$((rawsz + 4)) && - dd of=".git/objects/pack/pack-${pack1}.pack" seek=$(($offs_101 + 1)) \ - if=".git/objects/pack/pack-${pack1}.idx" \ - skip=$((4 + 256 * 4 + $nr_099 * recordsz)) \ - bs=1 count=$rawsz conv=notrunc && - git cat-file blob $sha1_101 > file_101_foo1' + '[index v1] 2) create a stealth corruption in a delta base reference' ' + # This test assumes file_101 is a delta smaller than 16 bytes. + # It should be against file_100 but we substitute its base for file_099 + sha1_101=$(git hash-object file_101) && + sha1_099=$(git hash-object file_099) && + offs_101=$(index_obj_offset 1.idx $sha1_101) && + nr_099=$(index_obj_nr 1.idx $sha1_099) && + chmod +w ".git/objects/pack/pack-${pack1}.pack" && + recordsz=$((rawsz + 4)) && + dd of=".git/objects/pack/pack-${pack1}.pack" seek=$(($offs_101 + 1)) \ + if=".git/objects/pack/pack-${pack1}.idx" \ + skip=$((4 + 256 * 4 + $nr_099 * recordsz)) \ + bs=1 count=$rawsz conv=notrunc && + git cat-file blob $sha1_101 > file_101_foo1 +' test_expect_success \ - '[index v1] 3) corrupted delta happily returned wrong data' \ - 'test -f file_101_foo1 && ! cmp file_101 file_101_foo1' + '[index v1] 3) corrupted delta happily returned wrong data' ' + test -f file_101_foo1 && ! cmp file_101 file_101_foo1 +' test_expect_success \ - '[index v1] 4) confirm that the pack is actually corrupted' \ - 'test_must_fail git fsck --full $commit' + '[index v1] 4) confirm that the pack is actually corrupted' ' + test_must_fail git fsck --full $commit +' test_expect_success \ - '[index v1] 5) pack-objects happily reuses corrupted data' \ - 'pack4=$(git pack-objects test-4 <obj-list) && - test -f "test-4-${pack4}.pack"' + '[index v1] 5) pack-objects happily reuses corrupted data' ' + pack4=$(git pack-objects test-4 <obj-list) && + test -f "test-4-${pack4}.pack" +' -test_expect_success \ - '[index v1] 6) newly created pack is BAD !' \ - 'test_must_fail git verify-pack -v "test-4-${pack4}.pack"' +test_expect_success '[index v1] 6) newly created pack is BAD !' ' + test_must_fail git verify-pack -v "test-4-${pack4}.pack" +' -test_expect_success \ - '[index v2] 1) stream pack to repository' \ - 'rm -f .git/objects/pack/* && - git index-pack --index-version=2 --stdin < "test-1-${pack1}.pack" && - git prune-packed && - git count-objects | ( read nr rest && test "$nr" -eq 1 ) && - cmp "test-1-${pack1}.pack" ".git/objects/pack/pack-${pack1}.pack" && - cmp "test-2-${pack1}.idx" ".git/objects/pack/pack-${pack1}.idx"' +test_expect_success '[index v2] 1) stream pack to repository' ' + rm -f .git/objects/pack/* && + git index-pack --index-version=2 --stdin < "test-1-${pack1}.pack" && + git prune-packed && + git count-objects | ( read nr rest && test "$nr" -eq 1 ) && + cmp "test-1-${pack1}.pack" ".git/objects/pack/pack-${pack1}.pack" && + cmp "test-2-${pack1}.idx" ".git/objects/pack/pack-${pack1}.idx" +' test_expect_success \ - '[index v2] 2) create a stealth corruption in a delta base reference' \ - '# This test assumes file_101 is a delta smaller than 16 bytes. - # It should be against file_100 but we substitute its base for file_099 - sha1_101=$(git hash-object file_101) && - sha1_099=$(git hash-object file_099) && - offs_101=$(index_obj_offset 1.idx $sha1_101) && - nr_099=$(index_obj_nr 1.idx $sha1_099) && - chmod +w ".git/objects/pack/pack-${pack1}.pack" && - dd of=".git/objects/pack/pack-${pack1}.pack" seek=$(($offs_101 + 1)) \ - if=".git/objects/pack/pack-${pack1}.idx" \ - skip=$((8 + 256 * 4 + $nr_099 * rawsz)) \ - bs=1 count=$rawsz conv=notrunc && - git cat-file blob $sha1_101 > file_101_foo2' + '[index v2] 2) create a stealth corruption in a delta base reference' ' + # This test assumes file_101 is a delta smaller than 16 bytes. + # It should be against file_100 but we substitute its base for file_099 + sha1_101=$(git hash-object file_101) && + sha1_099=$(git hash-object file_099) && + offs_101=$(index_obj_offset 1.idx $sha1_101) && + nr_099=$(index_obj_nr 1.idx $sha1_099) && + chmod +w ".git/objects/pack/pack-${pack1}.pack" && + dd of=".git/objects/pack/pack-${pack1}.pack" seek=$(($offs_101 + 1)) \ + if=".git/objects/pack/pack-${pack1}.idx" \ + skip=$((8 + 256 * 4 + $nr_099 * rawsz)) \ + bs=1 count=$rawsz conv=notrunc && + git cat-file blob $sha1_101 > file_101_foo2 +' test_expect_success \ - '[index v2] 3) corrupted delta happily returned wrong data' \ - 'test -f file_101_foo2 && ! cmp file_101 file_101_foo2' + '[index v2] 3) corrupted delta happily returned wrong data' ' + test -f file_101_foo2 && ! cmp file_101 file_101_foo2 +' test_expect_success \ - '[index v2] 4) confirm that the pack is actually corrupted' \ - 'test_must_fail git fsck --full $commit' + '[index v2] 4) confirm that the pack is actually corrupted' ' + test_must_fail git fsck --full $commit +' test_expect_success \ - '[index v2] 5) pack-objects refuses to reuse corrupted data' \ - 'test_must_fail git pack-objects test-5 <obj-list && - test_must_fail git pack-objects --no-reuse-object test-6 <obj-list' + '[index v2] 5) pack-objects refuses to reuse corrupted data' ' + test_must_fail git pack-objects test-5 <obj-list && + test_must_fail git pack-objects --no-reuse-object test-6 <obj-list +' test_expect_success \ - '[index v2] 6) verify-pack detects CRC mismatch' \ - 'rm -f .git/objects/pack/* && - git index-pack --index-version=2 --stdin < "test-1-${pack1}.pack" && - git verify-pack ".git/objects/pack/pack-${pack1}.pack" && - obj=$(git hash-object file_001) && - nr=$(index_obj_nr ".git/objects/pack/pack-${pack1}.idx" $obj) && - chmod +w ".git/objects/pack/pack-${pack1}.idx" && - printf xxxx | dd of=".git/objects/pack/pack-${pack1}.idx" conv=notrunc \ - bs=1 count=4 seek=$((8 + 256 * 4 + $(wc -l <obj-list) * rawsz + $nr * 4)) && - ( while read obj - do git cat-file -p $obj >/dev/null || exit 1 - done <obj-list ) && - test_must_fail git verify-pack ".git/objects/pack/pack-${pack1}.pack" + '[index v2] 6) verify-pack detects CRC mismatch' ' + rm -f .git/objects/pack/* && + git index-pack --index-version=2 --stdin < "test-1-${pack1}.pack" && + git verify-pack ".git/objects/pack/pack-${pack1}.pack" && + obj=$(git hash-object file_001) && + nr=$(index_obj_nr ".git/objects/pack/pack-${pack1}.idx" $obj) && + chmod +w ".git/objects/pack/pack-${pack1}.idx" && + printf xxxx | dd of=".git/objects/pack/pack-${pack1}.idx" conv=notrunc \ + bs=1 count=4 seek=$((8 + 256 * 4 + $(wc -l <obj-list) * rawsz + $nr * 4)) && + ( while read obj + do git cat-file -p $obj >/dev/null || exit 1 + done <obj-list ) && + test_must_fail git verify-pack ".git/objects/pack/pack-${pack1}.pack" ' test_expect_success 'running index-pack in the object store' ' - rm -f .git/objects/pack/* && - cp test-1-${pack1}.pack .git/objects/pack/pack-${pack1}.pack && - ( - cd .git/objects/pack && - git index-pack pack-${pack1}.pack - ) && - test -f .git/objects/pack/pack-${pack1}.idx + rm -f .git/objects/pack/* && + cp test-1-${pack1}.pack .git/objects/pack/pack-${pack1}.pack && + ( + cd .git/objects/pack && + git index-pack pack-${pack1}.pack + ) && + test -f .git/objects/pack/pack-${pack1}.idx ' test_expect_success 'index-pack --strict warns upon missing tagger in tag' ' - sha=$(git rev-parse HEAD) && - cat >wrong-tag <<EOF && + sha=$(git rev-parse HEAD) && + cat >wrong-tag <<EOF && object $sha type commit tag guten tag @@ -256,18 +264,18 @@ tag guten tag This is an invalid tag. EOF - tag=$(git hash-object -t tag -w --stdin <wrong-tag) && - pack1=$(echo $tag $sha | git pack-objects tag-test) && - echo remove tag object && - thirtyeight=${tag#??} && - rm -f .git/objects/${tag%$thirtyeight}/$thirtyeight && - git index-pack --strict tag-test-${pack1}.pack 2>err && - grep "^warning:.* expected .tagger. line" err + tag=$(git hash-object -t tag -w --stdin <wrong-tag) && + pack1=$(echo $tag $sha | git pack-objects tag-test) && + echo remove tag object && + thirtyeight=${tag#??} && + rm -f .git/objects/${tag%$thirtyeight}/$thirtyeight && + git index-pack --strict tag-test-${pack1}.pack 2>err && + grep "^warning:.* expected .tagger. line" err ' test_expect_success 'index-pack --fsck-objects also warns upon missing tagger in tag' ' - git index-pack --fsck-objects tag-test-${pack1}.pack 2>err && - grep "^warning:.* expected .tagger. line" err + git index-pack --fsck-objects tag-test-${pack1}.pack 2>err && + grep "^warning:.* expected .tagger. line" err ' test_done diff --git a/t/t5318-commit-graph.sh b/t/t5318-commit-graph.sh index 424599959c..26f332d6a3 100755 --- a/t/t5318-commit-graph.sh +++ b/t/t5318-commit-graph.sh @@ -46,15 +46,6 @@ test_expect_success 'create commits and repack' ' git repack ' -test_expect_success 'exit with correct error on bad input to --stdin-commits' ' - cd "$TRASH_DIRECTORY/full" && - echo HEAD | test_expect_code 1 git commit-graph write --stdin-commits 2>stderr && - test_i18ngrep "unexpected non-hex object ID: HEAD" stderr && - # valid tree OID, but not a commit OID - git rev-parse HEAD^{tree} | test_expect_code 1 git commit-graph write --stdin-commits 2>stderr && - test_i18ngrep "invalid commit object id" stderr -' - graph_git_two_modes() { git -c core.commitGraph=true $1 >output git -c core.commitGraph=false $1 >expect @@ -95,6 +86,22 @@ graph_read_expect() { test_cmp expect output } +test_expect_success 'exit with correct error on bad input to --stdin-commits' ' + cd "$TRASH_DIRECTORY/full" && + # invalid, non-hex OID + echo HEAD >in && + test_expect_code 1 git commit-graph write --stdin-commits <in 2>stderr && + test_i18ngrep "unexpected non-hex object ID: HEAD" stderr && + # non-existent OID + echo $ZERO_OID >in && + test_expect_code 1 git commit-graph write --stdin-commits <in 2>stderr && + test_i18ngrep "invalid object" stderr && + # valid commit and tree OID + git rev-parse HEAD HEAD^{tree} >in && + git commit-graph write --stdin-commits <in && + graph_read_expect 3 +' + test_expect_success 'write graph' ' cd "$TRASH_DIRECTORY/full" && git commit-graph write && @@ -140,7 +147,7 @@ test_expect_success 'Add more commits' ' test_expect_success 'commit-graph write progress off for redirected stderr' ' cd "$TRASH_DIRECTORY/full" && git commit-graph write 2>err && - test_line_count = 0 err + test_must_be_empty err ' test_expect_success 'commit-graph write force progress on for stderr' ' @@ -152,13 +159,34 @@ test_expect_success 'commit-graph write force progress on for stderr' ' test_expect_success 'commit-graph write with the --no-progress option' ' cd "$TRASH_DIRECTORY/full" && git commit-graph write --no-progress 2>err && - test_line_count = 0 err + test_must_be_empty err +' + +test_expect_success 'commit-graph write --stdin-commits progress off for redirected stderr' ' + cd "$TRASH_DIRECTORY/full" && + git rev-parse commits/5 >in && + git commit-graph write --stdin-commits <in 2>err && + test_must_be_empty err +' + +test_expect_success 'commit-graph write --stdin-commits force progress on for stderr' ' + cd "$TRASH_DIRECTORY/full" && + git rev-parse commits/5 >in && + GIT_PROGRESS_DELAY=0 git commit-graph write --stdin-commits --progress <in 2>err && + test_i18ngrep "Collecting commits from input" err +' + +test_expect_success 'commit-graph write --stdin-commits with the --no-progress option' ' + cd "$TRASH_DIRECTORY/full" && + git rev-parse commits/5 >in && + git commit-graph write --stdin-commits --no-progress <in 2>err && + test_must_be_empty err ' test_expect_success 'commit-graph verify progress off for redirected stderr' ' cd "$TRASH_DIRECTORY/full" && git commit-graph verify 2>err && - test_line_count = 0 err + test_must_be_empty err ' test_expect_success 'commit-graph verify force progress on for stderr' ' @@ -170,7 +198,7 @@ test_expect_success 'commit-graph verify force progress on for stderr' ' test_expect_success 'commit-graph verify with the --no-progress option' ' cd "$TRASH_DIRECTORY/full" && git commit-graph verify --no-progress 2>err && - test_line_count = 0 err + test_must_be_empty err ' # Current graph structure: diff --git a/t/t5500-fetch-pack.sh b/t/t5500-fetch-pack.sh index 8c54e34ef1..3557374312 100755 --- a/t/t5500-fetch-pack.sh +++ b/t/t5500-fetch-pack.sh @@ -871,9 +871,10 @@ test_expect_success 'shallow since with commit graph and already-seen commit' ' GIT_PROTOCOL=version=2 git upload-pack . <<-EOF >/dev/null 0012command=fetch + $(echo "object-format=$(test_oid algo)" | packetize) 00010013deepen-since 1 - 0032want $(git rev-parse other) - 0032have $(git rev-parse master) + $(echo "want $(git rev-parse other)" | packetize) + $(echo "have $(git rev-parse master)" | packetize) 0000 EOF ) @@ -999,7 +1000,6 @@ fetch_filter_blob_limit_zero () { test_config -C "$SERVER" uploadpack.allowfilter 1 && git clone "$URL" client && - test_config -C client extensions.partialclone origin && test_commit -C "$SERVER" two && diff --git a/t/t5505-remote.sh b/t/t5505-remote.sh index dda81b7d07..8d62edd98b 100755 --- a/t/t5505-remote.sh +++ b/t/t5505-remote.sh @@ -988,7 +988,7 @@ test_expect_success 'remote set-branches' ' +refs/heads/maint:refs/remotes/scratch/maint +refs/heads/master:refs/remotes/scratch/master +refs/heads/next:refs/remotes/scratch/next - +refs/heads/pu:refs/remotes/scratch/pu + +refs/heads/seen:refs/remotes/scratch/seen +refs/heads/t/topic:refs/remotes/scratch/t/topic EOF sort <<-\EOF >expect.setup-ffonly && @@ -998,7 +998,7 @@ test_expect_success 'remote set-branches' ' sort <<-\EOF >expect.respect-ffonly && refs/heads/master:refs/remotes/scratch/master +refs/heads/next:refs/remotes/scratch/next - +refs/heads/pu:refs/remotes/scratch/pu + +refs/heads/seen:refs/remotes/scratch/seen EOF git clone .git/ setbranches && @@ -1016,7 +1016,7 @@ test_expect_success 'remote set-branches' ' git config --get-all remote.scratch.fetch >config-result && sort <config-result >../actual.replace && - git remote set-branches --add scratch pu t/topic && + git remote set-branches --add scratch seen t/topic && git config --get-all remote.scratch.fetch >config-result && sort <config-result >../actual.add-two && @@ -1028,7 +1028,7 @@ test_expect_success 'remote set-branches' ' git config --get-all remote.scratch.fetch >config-result && sort <config-result >../actual.setup-ffonly && - git remote set-branches --add scratch pu && + git remote set-branches --add scratch seen && git config --get-all remote.scratch.fetch >config-result && sort <config-result >../actual.respect-ffonly ) && diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh index 9c6218f568..36ad20a849 100755 --- a/t/t5516-fetch-push.sh +++ b/t/t5516-fetch-push.sh @@ -747,42 +747,42 @@ test_expect_success 'deletion of a non-existent ref alone does trigger post-rece ' test_expect_success 'mixed ref updates, deletes, invalid deletes trigger hooks with correct input' ' - mk_test_with_hooks testrepo heads/master heads/next heads/pu && + mk_test_with_hooks testrepo heads/master heads/next heads/seen && orgmaster=$(cd testrepo && git show-ref -s --verify refs/heads/master) && newmaster=$(git show-ref -s --verify refs/heads/master) && orgnext=$(cd testrepo && git show-ref -s --verify refs/heads/next) && newnext=$ZERO_OID && - orgpu=$(cd testrepo && git show-ref -s --verify refs/heads/pu) && - newpu=$(git show-ref -s --verify refs/heads/master) && + orgseen=$(cd testrepo && git show-ref -s --verify refs/heads/seen) && + newseen=$(git show-ref -s --verify refs/heads/master) && git push testrepo refs/heads/master:refs/heads/master \ - refs/heads/master:refs/heads/pu :refs/heads/next \ + refs/heads/master:refs/heads/seen :refs/heads/next \ :refs/heads/nonexistent && ( cd testrepo/.git && cat >pre-receive.expect <<-EOF && $orgmaster $newmaster refs/heads/master $orgnext $newnext refs/heads/next - $orgpu $newpu refs/heads/pu + $orgseen $newseen refs/heads/seen $ZERO_OID $ZERO_OID refs/heads/nonexistent EOF cat >update.expect <<-EOF && refs/heads/master $orgmaster $newmaster refs/heads/next $orgnext $newnext - refs/heads/pu $orgpu $newpu + refs/heads/seen $orgseen $newseen refs/heads/nonexistent $ZERO_OID $ZERO_OID EOF cat >post-receive.expect <<-EOF && $orgmaster $newmaster refs/heads/master $orgnext $newnext refs/heads/next - $orgpu $newpu refs/heads/pu + $orgseen $newseen refs/heads/seen EOF cat >post-update.expect <<-EOF && refs/heads/master refs/heads/next - refs/heads/pu + refs/heads/seen EOF test_cmp pre-receive.expect pre-receive.actual && diff --git a/t/t5528-push-default.sh b/t/t5528-push-default.sh index 4d1e0c363e..f0a287d97d 100755 --- a/t/t5528-push-default.sh +++ b/t/t5528-push-default.sh @@ -98,6 +98,12 @@ test_expect_success 'push from/to new branch with upstream, matching and simple' test_push_failure upstream ' +test_expect_success '"matching" fails if none match' ' + git init --bare empty && + test_must_fail git push empty : 2>actual && + test_i18ngrep "Perhaps you should specify a branch" actual +' + test_expect_success 'push ambiguously named branch with upstream, matching and simple' ' git checkout -b ambiguous && test_config branch.ambiguous.remote parent1 && diff --git a/t/t5537-fetch-shallow.sh b/t/t5537-fetch-shallow.sh index d427a2d7f7..a55202d2d3 100755 --- a/t/t5537-fetch-shallow.sh +++ b/t/t5537-fetch-shallow.sh @@ -81,6 +81,20 @@ test_expect_success 'fetch --unshallow from shallow clone' ' ) ' +test_expect_success 'fetch --unshallow from a full clone' ' + git clone --no-local --depth=2 .git shallow3 && + ( + cd shallow3 && + git log --format=%s >actual && + test_write_lines 4 3 >expect && + test_cmp expect actual && + git -c fetch.writeCommitGraph fetch --unshallow && + git log origin/master --format=%s >actual && + test_write_lines 4 3 2 1 >expect && + test_cmp expect actual + ) +' + test_expect_success 'fetch something upstream has but hidden by clients shallow boundaries' ' # the blob "1" is available in .git but hidden by the # shallow2/.git/shallow and it should be resent diff --git a/t/t5540-http-push-webdav.sh b/t/t5540-http-push-webdav.sh index d476c33509..450321fddb 100755 --- a/t/t5540-http-push-webdav.sh +++ b/t/t5540-http-push-webdav.sh @@ -126,6 +126,22 @@ test_expect_success 'create and delete remote branch' ' test_must_fail git show-ref --verify refs/remotes/origin/dev ' +test_expect_success 'non-force push fails if not up to date' ' + git init --bare "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_conflict.git && + git -C "$HTTPD_DOCUMENT_ROOT_PATH"/test_repo_conflict.git update-server-info && + git clone $HTTPD_URL/dumb/test_repo_conflict.git "$ROOT_PATH"/c1 && + git clone $HTTPD_URL/dumb/test_repo_conflict.git "$ROOT_PATH"/c2 && + test_commit -C "$ROOT_PATH/c1" path1 && + git -C "$ROOT_PATH/c1" push origin HEAD && + git -C "$ROOT_PATH/c2" pull && + test_commit -C "$ROOT_PATH/c1" path2 && + git -C "$ROOT_PATH/c1" push origin HEAD && + test_commit -C "$ROOT_PATH/c2" path3 && + git -C "$ROOT_PATH/c1" log --graph --all && + git -C "$ROOT_PATH/c2" log --graph --all && + test_must_fail git -C "$ROOT_PATH/c2" push origin HEAD +' + test_expect_success 'MKCOL sends directory names with trailing slashes' ' ! grep "\"MKCOL.*[^/] HTTP/[^ ]*\"" < "$HTTPD_ROOT_PATH"/access.log diff --git a/t/t5541-http-push-smart.sh b/t/t5541-http-push-smart.sh index afc680d5e3..463d0f12e5 100755 --- a/t/t5541-http-push-smart.sh +++ b/t/t5541-http-push-smart.sh @@ -464,6 +464,21 @@ test_expect_success 'push status output scrubs password' ' grep "^To $HTTPD_URL/smart/test_repo.git" status ' +test_expect_success 'clone/fetch scrubs password from reflogs' ' + cd "$ROOT_PATH" && + git clone "$HTTPD_URL_USER_PASS/smart/test_repo.git" \ + reflog-test && + cd reflog-test && + test_commit prepare-for-force-fetch && + git switch -c away && + git fetch "$HTTPD_URL_USER_PASS/smart/test_repo.git" \ + +master:master && + # should have been scrubbed down to vanilla URL + git log -g master >reflog && + grep "$HTTPD_URL" reflog && + ! grep "$HTTPD_URL_USER_PASS" reflog +' + test_expect_success 'colorize errors/hints' ' cd "$ROOT_PATH"/test_repo_clone && test_must_fail git -c color.transport=always -c color.advice=always \ diff --git a/t/t5550-http-fetch-dumb.sh b/t/t5550-http-fetch-dumb.sh index 50485300eb..483578b2d7 100755 --- a/t/t5550-http-fetch-dumb.sh +++ b/t/t5550-http-fetch-dumb.sh @@ -50,6 +50,24 @@ test_expect_success 'create password-protected repository' ' "$HTTPD_DOCUMENT_ROOT_PATH/auth/dumb/repo.git" ' +test_expect_success 'create empty remote repository' ' + git init --bare "$HTTPD_DOCUMENT_ROOT_PATH/empty.git" && + (cd "$HTTPD_DOCUMENT_ROOT_PATH/empty.git" && + mkdir -p hooks && + write_script "hooks/post-update" <<-\EOF && + exec git update-server-info + EOF + hooks/post-update + ) +' + +test_expect_success 'empty dumb HTTP repository has default hash algorithm' ' + test_when_finished "rm -fr clone-empty" && + git clone $HTTPD_URL/dumb/empty.git clone-empty && + git -C clone-empty rev-parse --show-object-format >empty-format && + test "$(cat empty-format)" = "$(test_oid algo)" +' + setup_askpass_helper test_expect_success 'cloning password-protected repository can fail' ' @@ -199,6 +217,28 @@ test_expect_success 'fetch packed objects' ' git clone $HTTPD_URL/dumb/repo_pack.git ' +test_expect_success 'http-fetch --packfile' ' + # Arbitrary hash. Use rev-parse so that we get one of the correct + # length. + ARBITRARY=$(git -C "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git rev-parse HEAD) && + + git init packfileclient && + p=$(cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git && ls objects/pack/pack-*.pack) && + git -C packfileclient http-fetch --packfile=$ARBITRARY "$HTTPD_URL"/dumb/repo_pack.git/$p >out && + + grep "^keep.[0-9a-f]\{16,\}$" out && + cut -c6- out >packhash && + + # Ensure that the expected files are generated + test -e "packfileclient/.git/objects/pack/pack-$(cat packhash).pack" && + test -e "packfileclient/.git/objects/pack/pack-$(cat packhash).idx" && + test -e "packfileclient/.git/objects/pack/pack-$(cat packhash).keep" && + + # Ensure that it has the HEAD of repo_pack, at least + HASH=$(git -C "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git rev-parse HEAD) && + git -C packfileclient cat-file -e "$HASH" +' + test_expect_success 'fetch notices corrupt pack' ' cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git && (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git && @@ -214,6 +254,14 @@ test_expect_success 'fetch notices corrupt pack' ' ) ' +test_expect_success 'http-fetch --packfile with corrupt pack' ' + rm -rf packfileclient && + git init packfileclient && + p=$(cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad1.git && ls objects/pack/pack-*.pack) && + test_must_fail git -C packfileclient http-fetch --packfile \ + "$HTTPD_URL"/dumb/repo_bad1.git/$p +' + test_expect_success 'fetch notices corrupt idx' ' cp -R "$HTTPD_DOCUMENT_ROOT_PATH"/repo_pack.git "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git && (cd "$HTTPD_DOCUMENT_ROOT_PATH"/repo_bad2.git && diff --git a/t/t5551-http-fetch-smart.sh b/t/t5551-http-fetch-smart.sh index 6788aeface..e40e9ed52f 100755 --- a/t/t5551-http-fetch-smart.sh +++ b/t/t5551-http-fetch-smart.sh @@ -185,6 +185,40 @@ test_expect_success 'redirects send auth to new location' ' expect_askpass both user@host auth/smart/repo.git ' +test_expect_success 'GIT_TRACE_CURL redacts auth details' ' + rm -rf redact-auth trace && + set_askpass user@host pass@host && + GIT_TRACE_CURL="$(pwd)/trace" git clone --bare "$HTTPD_URL/auth/smart/repo.git" redact-auth && + expect_askpass both user@host && + + # Ensure that there is no "Basic" followed by a base64 string, but that + # the auth details are redacted + ! grep "Authorization: Basic [0-9a-zA-Z+/]" trace && + grep "Authorization: Basic <redacted>" trace +' + +test_expect_success 'GIT_CURL_VERBOSE redacts auth details' ' + rm -rf redact-auth trace && + set_askpass user@host pass@host && + GIT_CURL_VERBOSE=1 git clone --bare "$HTTPD_URL/auth/smart/repo.git" redact-auth 2>trace && + expect_askpass both user@host && + + # Ensure that there is no "Basic" followed by a base64 string, but that + # the auth details are redacted + ! grep "Authorization: Basic [0-9a-zA-Z+/]" trace && + grep "Authorization: Basic <redacted>" trace +' + +test_expect_success 'GIT_TRACE_CURL does not redact auth details if GIT_TRACE_REDACT=0' ' + rm -rf redact-auth trace && + set_askpass user@host pass@host && + GIT_TRACE_REDACT=0 GIT_TRACE_CURL="$(pwd)/trace" \ + git clone --bare "$HTTPD_URL/auth/smart/repo.git" redact-auth && + expect_askpass both user@host && + + grep "Authorization: Basic [0-9a-zA-Z+/]" trace +' + test_expect_success 'disable dumb http on server' ' git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \ config http.getanyfile false @@ -430,27 +464,39 @@ test_expect_success 'fetch by SHA-1 without tag following' ' --no-tags origin $(cat bar_hash) ' -test_expect_success 'GIT_REDACT_COOKIES redacts cookies' ' +test_expect_success 'cookies are redacted by default' ' rm -rf clone && echo "Set-Cookie: Foo=1" >cookies && echo "Set-Cookie: Bar=2" >>cookies && - GIT_TRACE_CURL=true GIT_REDACT_COOKIES=Bar,Baz \ + GIT_TRACE_CURL=true \ git -c "http.cookieFile=$(pwd)/cookies" clone \ $HTTPD_URL/smart/repo.git clone 2>err && - grep "Cookie:.*Foo=1" err && + grep "Cookie:.*Foo=<redacted>" err && grep "Cookie:.*Bar=<redacted>" err && + ! grep "Cookie:.*Foo=1" err && ! grep "Cookie:.*Bar=2" err ' -test_expect_success 'GIT_REDACT_COOKIES handles empty values' ' +test_expect_success 'empty values of cookies are also redacted' ' rm -rf clone && echo "Set-Cookie: Foo=" >cookies && - GIT_TRACE_CURL=true GIT_REDACT_COOKIES=Foo \ + GIT_TRACE_CURL=true \ git -c "http.cookieFile=$(pwd)/cookies" clone \ $HTTPD_URL/smart/repo.git clone 2>err && grep "Cookie:.*Foo=<redacted>" err ' +test_expect_success 'GIT_TRACE_REDACT=0 disables cookie redaction' ' + rm -rf clone && + echo "Set-Cookie: Foo=1" >cookies && + echo "Set-Cookie: Bar=2" >>cookies && + GIT_TRACE_REDACT=0 GIT_TRACE_CURL=true \ + git -c "http.cookieFile=$(pwd)/cookies" clone \ + $HTTPD_URL/smart/repo.git clone 2>err && + grep "Cookie:.*Foo=1" err && + grep "Cookie:.*Bar=2" err +' + test_expect_success 'GIT_TRACE_CURL_NO_DATA prevents data from being traced' ' rm -rf clone && GIT_TRACE_CURL=true \ diff --git a/t/t5562-http-backend-content-length.sh b/t/t5562-http-backend-content-length.sh index 3f4ac71f83..c6ec625497 100755 --- a/t/t5562-http-backend-content-length.sh +++ b/t/t5562-http-backend-content-length.sh @@ -46,6 +46,7 @@ ssize_b100dots() { } test_expect_success 'setup' ' + test_oid_init && HTTP_CONTENT_ENCODING="identity" && export HTTP_CONTENT_ENCODING && git config http.receivepack true && @@ -62,8 +63,8 @@ test_expect_success 'setup' ' test_copy_bytes 10 <fetch_body >fetch_body.trunc && hash_next=$(git commit-tree -p HEAD -m next HEAD^{tree}) && { - printf "%s %s refs/heads/newbranch\\0report-status\\n" \ - "$ZERO_OID" "$hash_next" | packetize && + printf "%s %s refs/heads/newbranch\\0report-status object-format=%s\\n" \ + "$ZERO_OID" "$hash_next" "$(test_oid algo)" | packetize && printf 0000 && echo "$hash_next" | git pack-objects --stdout } >push_body && diff --git a/t/t5572-pull-submodule.sh b/t/t5572-pull-submodule.sh index f916729a12..1d75e3b12b 100755 --- a/t/t5572-pull-submodule.sh +++ b/t/t5572-pull-submodule.sh @@ -13,34 +13,38 @@ reset_branch_to_HEAD () { git_pull () { reset_branch_to_HEAD "$1" && - git pull + may_only_be_test_must_fail "$2" && + $2 git pull } # pulls without conflicts -test_submodule_switch "git_pull" +test_submodule_switch_func "git_pull" git_pull_ff () { reset_branch_to_HEAD "$1" && - git pull --ff + may_only_be_test_must_fail "$2" && + $2 git pull --ff } -test_submodule_switch "git_pull_ff" +test_submodule_switch_func "git_pull_ff" git_pull_ff_only () { reset_branch_to_HEAD "$1" && - git pull --ff-only + may_only_be_test_must_fail "$2" && + $2 git pull --ff-only } -test_submodule_switch "git_pull_ff_only" +test_submodule_switch_func "git_pull_ff_only" git_pull_noff () { reset_branch_to_HEAD "$1" && - git pull --no-ff + may_only_be_test_must_fail "$2" && + $2 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_submodule_switch_func "git_pull_noff" test_expect_success 'pull --recurse-submodule setup' ' test_create_repo child && diff --git a/t/t5581-http-curl-verbose.sh b/t/t5581-http-curl-verbose.sh index 5129b0724f..927aad0820 100755 --- a/t/t5581-http-curl-verbose.sh +++ b/t/t5581-http-curl-verbose.sh @@ -20,7 +20,7 @@ test_expect_success 'failure in git-upload-pack is shown' ' test_might_fail env GIT_CURL_VERBOSE=1 \ git clone "$HTTPD_URL/error_git_upload_pack/smart/repo.git" \ 2>curl_log && - grep "< HTTP/1.1 500 Intentional Breakage" curl_log + grep "<= Recv header: HTTP/1.1 500 Intentional Breakage" curl_log ' test_done diff --git a/t/t5606-clone-options.sh b/t/t5606-clone-options.sh index 9e24ec88e6..e69427f881 100755 --- a/t/t5606-clone-options.sh +++ b/t/t5606-clone-options.sh @@ -35,4 +35,28 @@ test_expect_success 'redirected clone -v does show progress' ' ' +test_expect_success 'chooses correct default initial branch name' ' + git init --bare empty && + git -c init.defaultBranch=up clone empty whats-up && + test refs/heads/up = $(git -C whats-up symbolic-ref HEAD) && + test refs/heads/up = $(git -C whats-up config branch.up.merge) +' + +test_expect_success 'guesses initial branch name correctly' ' + git init --initial-branch=guess initial-branch && + test_commit -C initial-branch no-spoilers && + git -C initial-branch branch abc guess && + git clone initial-branch is-it && + test refs/heads/guess = $(git -C is-it symbolic-ref HEAD) && + + git -c init.defaultBranch=none init --bare no-head && + git -C initial-branch push ../no-head guess abc && + git clone no-head is-it2 && + test_must_fail git -C is-it2 symbolic-ref refs/remotes/origin/HEAD && + git -C no-head update-ref --no-deref HEAD refs/heads/guess && + git -c init.defaultBranch=guess clone no-head is-it3 && + test refs/remotes/origin/guess = \ + $(git -C is-it3 symbolic-ref refs/remotes/origin/HEAD) +' + test_done diff --git a/t/t5608-clone-2gb.sh b/t/t5608-clone-2gb.sh index eee0842888..4c476d2fa1 100755 --- a/t/t5608-clone-2gb.sh +++ b/t/t5608-clone-2gb.sh @@ -5,12 +5,11 @@ test_description='Test cloning a repository larger than 2 gigabyte' if ! test_bool_env GIT_TEST_CLONE_2GB false then - say 'Skipping expensive 2GB clone test; enable it with GIT_TEST_CLONE_2GB=t' -else - test_set_prereq CLONE_2GB + skip_all='expensive 2GB clone test; enable with GIT_TEST_CLONE_2GB=true' + test_done fi -test_expect_success CLONE_2GB 'setup' ' +test_expect_success 'setup' ' git config pack.compression 0 && git config pack.depth 0 && @@ -38,13 +37,13 @@ test_expect_success CLONE_2GB 'setup' ' ' -test_expect_success CLONE_2GB 'clone - bare' ' +test_expect_success 'clone - bare' ' git clone --bare --no-hardlinks . clone-bare ' -test_expect_success CLONE_2GB 'clone - with worktree, file:// protocol' ' +test_expect_success 'clone - with worktree, file:// protocol' ' git clone "file://$(pwd)" clone-wt diff --git a/t/t5701-git-serve.sh b/t/t5701-git-serve.sh index ffb9613885..a1f5fdc9fd 100755 --- a/t/t5701-git-serve.sh +++ b/t/t5701-git-serve.sh @@ -5,12 +5,17 @@ test_description='test protocol v2 server commands' . ./test-lib.sh test_expect_success 'test capability advertisement' ' + test_oid_cache <<-EOF && + wrong_algo sha1:sha256 + wrong_algo sha256:sha1 + EOF cat >expect <<-EOF && version 2 agent=git/$(git version | cut -d" " -f3) ls-refs fetch=shallow server-option + object-format=$(test_oid algo) 0000 EOF @@ -45,6 +50,7 @@ test_expect_success 'request invalid capability' ' test_expect_success 'request with no command' ' test-tool pkt-line pack >in <<-EOF && agent=git/test + object-format=$(test_oid algo) 0000 EOF test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in && @@ -54,6 +60,7 @@ test_expect_success 'request with no command' ' test_expect_success 'request invalid command' ' test-tool pkt-line pack >in <<-EOF && command=foo + object-format=$(test_oid algo) agent=git/test 0000 EOF @@ -61,6 +68,17 @@ test_expect_success 'request invalid command' ' test_i18ngrep "invalid command" err ' +test_expect_success 'wrong object-format' ' + test-tool pkt-line pack >in <<-EOF && + command=fetch + agent=git/test + object-format=$(test_oid wrong_algo) + 0000 + EOF + test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in && + test_i18ngrep "mismatched object format" err +' + # Test the basics of ls-refs # test_expect_success 'setup some refs and tags' ' @@ -74,6 +92,7 @@ test_expect_success 'setup some refs and tags' ' test_expect_success 'basics of ls-refs' ' test-tool pkt-line pack >in <<-EOF && command=ls-refs + object-format=$(test_oid algo) 0000 EOF @@ -96,6 +115,7 @@ test_expect_success 'basics of ls-refs' ' test_expect_success 'basic ref-prefixes' ' test-tool pkt-line pack >in <<-EOF && command=ls-refs + object-format=$(test_oid algo) 0001 ref-prefix refs/heads/master ref-prefix refs/tags/one @@ -116,6 +136,7 @@ test_expect_success 'basic ref-prefixes' ' test_expect_success 'refs/heads prefix' ' test-tool pkt-line pack >in <<-EOF && command=ls-refs + object-format=$(test_oid algo) 0001 ref-prefix refs/heads/ 0000 @@ -136,6 +157,7 @@ test_expect_success 'refs/heads prefix' ' test_expect_success 'peel parameter' ' test-tool pkt-line pack >in <<-EOF && command=ls-refs + object-format=$(test_oid algo) 0001 peel ref-prefix refs/tags/ @@ -157,6 +179,7 @@ test_expect_success 'peel parameter' ' test_expect_success 'symrefs parameter' ' test-tool pkt-line pack >in <<-EOF && command=ls-refs + object-format=$(test_oid algo) 0001 symrefs ref-prefix refs/heads/ @@ -178,6 +201,7 @@ test_expect_success 'symrefs parameter' ' test_expect_success 'sending server-options' ' test-tool pkt-line pack >in <<-EOF && command=ls-refs + object-format=$(test_oid algo) server-option=hello server-option=world 0001 @@ -200,6 +224,7 @@ test_expect_success 'unexpected lines are not allowed in fetch request' ' test-tool pkt-line pack >in <<-EOF && command=fetch + object-format=$(test_oid algo) 0001 this-is-not-a-command 0000 diff --git a/t/t5702-protocol-v2.sh b/t/t5702-protocol-v2.sh index 5039e66dc4..1b54c35b01 100755 --- a/t/t5702-protocol-v2.sh +++ b/t/t5702-protocol-v2.sh @@ -13,6 +13,7 @@ start_git_daemon --export-all --enable=receive-pack daemon_parent=$GIT_DAEMON_DOCUMENT_ROOT_PATH/parent test_expect_success 'create repo to be served by git-daemon' ' + test_oid_init && git init "$daemon_parent" && test_commit -C "$daemon_parent" one ' @@ -348,7 +349,6 @@ test_expect_success 'partial fetch' ' rm -rf client "$(pwd)/trace" && git init client && SERVER="file://$(pwd)/server" && - test_config -C client extensions.partialClone "$SERVER" && GIT_TRACE_PACKET="$(pwd)/trace" git -C client -c protocol.version=2 \ fetch --filter=blob:none "$SERVER" master:refs/heads/other && @@ -394,6 +394,7 @@ test_expect_success 'even with handcrafted request, filter does not work if not # Custom request that tries to filter even though it is not advertised. test-tool pkt-line pack >in <<-EOF && command=fetch + object-format=$(test_oid algo) 0001 want $(git -C server rev-parse master) filter blob:none @@ -586,6 +587,53 @@ test_expect_success 'clone with http:// using protocol v2' ' ! grep "Send header: Transfer-Encoding: chunked" log ' +test_expect_success 'clone repository with http:// using protocol v2 with incomplete pktline length' ' + test_when_finished "rm -f log" && + + git init "$HTTPD_DOCUMENT_ROOT_PATH/incomplete_length" && + test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/incomplete_length" file && + + test_must_fail env GIT_TRACE_PACKET="$(pwd)/log" GIT_TRACE_CURL="$(pwd)/log" git -c protocol.version=2 \ + clone "$HTTPD_URL/smart/incomplete_length" incomplete_length_child 2>err && + + # Client requested to use protocol v2 + grep "Git-Protocol: version=2" log && + # Server responded using protocol v2 + grep "git< version 2" log && + # Client reported appropriate failure + test_i18ngrep "bytes of length header were received" err +' + +test_expect_success 'clone repository with http:// using protocol v2 with incomplete pktline body' ' + test_when_finished "rm -f log" && + + git init "$HTTPD_DOCUMENT_ROOT_PATH/incomplete_body" && + test_commit -C "$HTTPD_DOCUMENT_ROOT_PATH/incomplete_body" file && + + test_must_fail env GIT_TRACE_PACKET="$(pwd)/log" GIT_TRACE_CURL="$(pwd)/log" git -c protocol.version=2 \ + clone "$HTTPD_URL/smart/incomplete_body" incomplete_body_child 2>err && + + # Client requested to use protocol v2 + grep "Git-Protocol: version=2" log && + # Server responded using protocol v2 + grep "git< version 2" log && + # Client reported appropriate failure + test_i18ngrep "bytes of body are still expected" err +' + +test_expect_success 'clone with http:// using protocol v2 and invalid parameters' ' + test_when_finished "rm -f log" && + + test_must_fail env GIT_TRACE_PACKET="$(pwd)/log" GIT_TRACE_CURL="$(pwd)/log" \ + git -c protocol.version=2 \ + clone --shallow-since=20151012 "$HTTPD_URL/smart/http_parent" http_child_invalid && + + # Client requested to use protocol v2 + grep "Git-Protocol: version=2" log && + # Server responded using protocol v2 + grep "git< version 2" log +' + test_expect_success 'clone big repository with http:// using protocol v2' ' test_when_finished "rm -f log" && @@ -748,6 +796,94 @@ test_expect_success 'when server does not send "ready", expect FLUSH' ' test_i18ngrep "expected no other sections to be sent after no .ready." err ' +configure_exclusion () { + git -C "$1" hash-object "$2" >objh && + git -C "$1" pack-objects "$HTTPD_DOCUMENT_ROOT_PATH/mypack" <objh >packh && + git -C "$1" config --add \ + "uploadpack.blobpackfileuri" \ + "$(cat objh) $(cat packh) $HTTPD_URL/dumb/mypack-$(cat packh).pack" && + cat objh +} + +test_expect_success 'part of packfile response provided as URI' ' + P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" && + rm -rf "$P" http_child log && + + git init "$P" && + git -C "$P" config "uploadpack.allowsidebandall" "true" && + + echo my-blob >"$P/my-blob" && + git -C "$P" add my-blob && + echo other-blob >"$P/other-blob" && + git -C "$P" add other-blob && + git -C "$P" commit -m x && + + configure_exclusion "$P" my-blob >h && + configure_exclusion "$P" other-blob >h2 && + + GIT_TRACE=1 GIT_TRACE_PACKET="$(pwd)/log" GIT_TEST_SIDEBAND_ALL=1 \ + git -c protocol.version=2 \ + -c fetch.uriprotocols=http,https \ + clone "$HTTPD_URL/smart/http_parent" http_child && + + # Ensure that my-blob and other-blob are in separate packfiles. + for idx in http_child/.git/objects/pack/*.idx + do + git verify-pack --verbose $idx >out && + { + grep "^[0-9a-f]\{16,\} " out || : + } >out.objectlist && + if test_line_count = 1 out.objectlist + then + if grep $(cat h) out + then + >hfound + fi && + if grep $(cat h2) out + then + >h2found + fi + fi + done && + test -f hfound && + test -f h2found && + + # Ensure that there are exactly 6 files (3 .pack and 3 .idx). + ls http_child/.git/objects/pack/* >filelist && + test_line_count = 6 filelist +' + +test_expect_success 'fetching with valid packfile URI but invalid hash fails' ' + P="$HTTPD_DOCUMENT_ROOT_PATH/http_parent" && + rm -rf "$P" http_child log && + + git init "$P" && + git -C "$P" config "uploadpack.allowsidebandall" "true" && + + echo my-blob >"$P/my-blob" && + git -C "$P" add my-blob && + echo other-blob >"$P/other-blob" && + git -C "$P" add other-blob && + git -C "$P" commit -m x && + + configure_exclusion "$P" my-blob >h && + # Configure a URL for other-blob. Just reuse the hash of the object as + # the hash of the packfile, since the hash does not matter for this + # test as long as it is not the hash of the pack, and it is of the + # expected length. + git -C "$P" hash-object other-blob >objh && + git -C "$P" pack-objects "$HTTPD_DOCUMENT_ROOT_PATH/mypack" <objh >packh && + git -C "$P" config --add \ + "uploadpack.blobpackfileuri" \ + "$(cat objh) $(cat objh) $HTTPD_URL/dumb/mypack-$(cat packh).pack" && + + test_must_fail env GIT_TEST_SIDEBAND_ALL=1 \ + git -c protocol.version=2 \ + -c fetch.uriprotocols=http,https \ + clone "$HTTPD_URL/smart/http_parent" http_child 2>err && + test_i18ngrep "pack downloaded from.*does not match expected hash" err +' + # DO NOT add non-httpd-specific tests here, because the last part of this # test script is only executed when httpd is available and enabled. diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh index 92ad5eeec0..748282f058 100755 --- a/t/t5703-upload-pack-ref-in-want.sh +++ b/t/t5703-upload-pack-ref-in-want.sh @@ -27,6 +27,15 @@ check_output () { test_cmp sorted_commits actual_commits } +write_command () { + echo "command=$1" + + if test "$(test_oid algo)" != sha1 + then + echo "object-format=$(test_oid algo)" + fi +} + # c(o/foo) d(o/bar) # \ / # b e(baz) f(master) @@ -65,7 +74,7 @@ test_expect_success 'config controls ref-in-want advertisement' ' test_expect_success 'invalid want-ref line' ' test-tool pkt-line pack >in <<-EOF && - command=fetch + $(write_command fetch) 0001 no-progress want-ref refs/heads/non-existent @@ -86,7 +95,7 @@ test_expect_success 'basic want-ref' ' oid=$(git rev-parse a) && test-tool pkt-line pack >in <<-EOF && - command=fetch + $(write_command fetch) 0001 no-progress want-ref refs/heads/master @@ -110,7 +119,7 @@ test_expect_success 'multiple want-ref lines' ' oid=$(git rev-parse b) && test-tool pkt-line pack >in <<-EOF && - command=fetch + $(write_command fetch) 0001 no-progress want-ref refs/heads/o/foo @@ -132,7 +141,7 @@ test_expect_success 'mix want and want-ref' ' git rev-parse e f >expected_commits && test-tool pkt-line pack >in <<-EOF && - command=fetch + $(write_command fetch) 0001 no-progress want-ref refs/heads/master @@ -155,7 +164,7 @@ test_expect_success 'want-ref with ref we already have commit for' ' oid=$(git rev-parse c) && test-tool pkt-line pack >in <<-EOF && - command=fetch + $(write_command fetch) 0001 no-progress want-ref refs/heads/o/foo diff --git a/t/t5704-protocol-violations.sh b/t/t5704-protocol-violations.sh index 950cfb21fe..5c941949b9 100755 --- a/t/t5704-protocol-violations.sh +++ b/t/t5704-protocol-violations.sh @@ -9,6 +9,7 @@ making sure that we do not segfault or otherwise behave badly.' test_expect_success 'extra delim packet in v2 ls-refs args' ' { packetize command=ls-refs && + packetize "object-format=$(test_oid algo)" && printf 0001 && # protocol expects 0000 flush here printf 0001 @@ -21,6 +22,7 @@ test_expect_success 'extra delim packet in v2 ls-refs args' ' test_expect_success 'extra delim packet in v2 fetch args' ' { packetize command=fetch && + packetize "object-format=$(test_oid algo)" && printf 0001 && # protocol expects 0000 flush here printf 0001 diff --git a/t/t5801/git-remote-testgit b/t/t5801/git-remote-testgit index 6b9f0b5dc7..1544d6dc6b 100755 --- a/t/t5801/git-remote-testgit +++ b/t/t5801/git-remote-testgit @@ -52,9 +52,11 @@ do test -n "$GIT_REMOTE_TESTGIT_SIGNED_TAGS" && echo "signed-tags" test -n "$GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE" && echo "no-private-update" echo 'option' + echo 'object-format' echo ;; list) + echo ":object-format $(git rev-parse --show-object-format=storage)" git for-each-ref --format='? %(refname)' 'refs/heads/' 'refs/tags/' head=$(git symbolic-ref HEAD) echo "@$head HEAD" @@ -139,6 +141,10 @@ do test $val = "true" && force="true" || force= echo "ok" ;; + object-format) + test $val = "true" && object_format="true" || object_format= + echo "ok" + ;; *) echo "unsupported" ;; diff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh index ac31faefa1..36d9b2b2e4 100755 --- a/t/t6030-bisect-porcelain.sh +++ b/t/t6030-bisect-porcelain.sh @@ -866,7 +866,9 @@ test_expect_success 'bisect cannot mix terms' ' test_expect_success 'bisect terms rejects invalid terms' ' git bisect reset && + test_must_fail git bisect start --term-good && test_must_fail git bisect start --term-good invalid..term && + test_must_fail git bisect start --term-bad && test_must_fail git bisect terms --term-bad invalid..term && test_must_fail git bisect terms --term-good bad && test_must_fail git bisect terms --term-good old && diff --git a/t/t6041-bisect-submodule.sh b/t/t6041-bisect-submodule.sh index 62b8a2e7bb..df1eff0fb8 100755 --- a/t/t6041-bisect-submodule.sh +++ b/t/t6041-bisect-submodule.sh @@ -10,7 +10,12 @@ git_bisect () { ls -1pR * >>expect && tar cf "$TRASH_DIRECTORY/tmp.tar" * && GOOD=$(git rev-parse --verify HEAD) && - git checkout "$1" && + may_only_be_test_must_fail "$2" && + $2 git checkout "$1" && + if test -n "$2" + then + return + fi && echo "foo" >bar && git add bar && git commit -m "bisect bad" && @@ -27,6 +32,6 @@ git_bisect () { git bisect bad $BAD } -test_submodule_switch "git_bisect" +test_submodule_switch_func "git_bisect" test_done diff --git a/t/t6050-replace.sh b/t/t6050-replace.sh index e7e64e085d..c80dc10b8f 100755 --- a/t/t6050-replace.sh +++ b/t/t6050-replace.sh @@ -135,7 +135,7 @@ test_expect_success 'tag replaced commit' ' test_expect_success '"git fsck" works' ' git fsck master >fsck_master.out && test_i18ngrep "dangling commit $R" fsck_master.out && - test_i18ngrep "dangling tag $(cat .git/refs/tags/mytag)" fsck_master.out && + test_i18ngrep "dangling tag $(git show-ref -s refs/tags/mytag)" fsck_master.out && test -z "$(git fsck)" ' diff --git a/t/t6132-pathspec-exclude.sh b/t/t6132-pathspec-exclude.sh index 2462b19ddd..30328b87f0 100755 --- a/t/t6132-pathspec-exclude.sh +++ b/t/t6132-pathspec-exclude.sh @@ -211,4 +211,37 @@ test_expect_success 't_e_i() exclude case #8' ' ) ' +test_expect_success 'grep --untracked PATTERN' ' + # This test is not an actual test of exclude patterns, rather it + # is here solely to ensure that if any tests are inserted, deleted, or + # changed above, that we still have untracked files with the expected + # contents for the NEXT two tests. + cat <<-\EOF >expect-grep && + actual + expect + sub/actual + sub/expect + EOF + git grep -l --untracked file -- >actual-grep && + test_cmp expect-grep actual-grep +' + +test_expect_success 'grep --untracked PATTERN :(exclude)DIR' ' + cat <<-\EOF >expect-grep && + actual + expect + EOF + git grep -l --untracked file -- ":(exclude)sub" >actual-grep && + test_cmp expect-grep actual-grep +' + +test_expect_success 'grep --untracked PATTERN :(exclude)*FILE' ' + cat <<-\EOF >expect-grep && + actual + sub/actual + EOF + git grep -l --untracked file -- ":(exclude)*expect" >actual-grep && + test_cmp expect-grep actual-grep +' + test_done diff --git a/t/t6200-fmt-merge-msg.sh b/t/t6200-fmt-merge-msg.sh index b15582a7a2..2b3fd498d0 100755 --- a/t/t6200-fmt-merge-msg.sh +++ b/t/t6200-fmt-merge-msg.sh @@ -79,7 +79,7 @@ test_expect_success GPG 'set up a signed tag' ' ' test_expect_success 'message for merging local branch' ' - echo "Merge branch ${apos}left${apos}" >expected && + echo "Merge branch ${apos}left${apos} into master" >expected && git checkout master && git fetch . left && @@ -103,11 +103,11 @@ test_expect_success GPG 'message for merging local tag signed by unknown key' ' GNUPGHOME=. git fmt-merge-msg <.git/FETCH_HEAD >actual 2>&1 && grep "^Merge tag ${apos}signed-good-tag${apos}" actual && grep "^# gpg: Signature made" actual && - grep "^# gpg: Can${apos}t check signature: \(public key not found\|No public key\)" actual + grep -E "^# gpg: Can${apos}t check signature: (public key not found|No public key)" actual ' test_expect_success 'message for merging external branch' ' - echo "Merge branch ${apos}left${apos} of $(pwd)" >expected && + echo "Merge branch ${apos}left${apos} of $(pwd) into master" >expected && git checkout master && git fetch "$(pwd)" left && @@ -118,7 +118,7 @@ test_expect_success 'message for merging external branch' ' test_expect_success '[merge] summary/log configuration' ' cat >expected <<-EOF && - Merge branch ${apos}left${apos} + Merge branch ${apos}left${apos} into master # By Another Author (3) and A U Thor (2) # Via Another Committer @@ -160,7 +160,7 @@ test_expect_success 'setup FETCH_HEAD' ' test_expect_success 'merge.log=3 limits shortlog length' ' cat >expected <<-EOF && - Merge branch ${apos}left${apos} + Merge branch ${apos}left${apos} into master # By Another Author (3) and A U Thor (2) # Via Another Committer @@ -177,7 +177,7 @@ test_expect_success 'merge.log=3 limits shortlog length' ' test_expect_success 'merge.log=5 shows all 5 commits' ' cat >expected <<-EOF && - Merge branch ${apos}left${apos} + Merge branch ${apos}left${apos} into master # By Another Author (3) and A U Thor (2) # Via Another Committer @@ -195,7 +195,7 @@ test_expect_success 'merge.log=5 shows all 5 commits' ' test_expect_success '--log=5 with custom comment character' ' cat >expected <<-EOF && - Merge branch ${apos}left${apos} + Merge branch ${apos}left${apos} into master x By Another Author (3) and A U Thor (2) x Via Another Committer @@ -212,14 +212,14 @@ test_expect_success '--log=5 with custom comment character' ' ' test_expect_success 'merge.log=0 disables shortlog' ' - echo "Merge branch ${apos}left${apos}" >expected && + echo "Merge branch ${apos}left${apos} into master" >expected && git -c merge.log=0 fmt-merge-msg <.git/FETCH_HEAD >actual && test_cmp expected actual ' test_expect_success '--log=3 limits shortlog length' ' cat >expected <<-EOF && - Merge branch ${apos}left${apos} + Merge branch ${apos}left${apos} into master # By Another Author (3) and A U Thor (2) # Via Another Committer @@ -236,7 +236,7 @@ test_expect_success '--log=3 limits shortlog length' ' test_expect_success '--log=5 shows all 5 commits' ' cat >expected <<-EOF && - Merge branch ${apos}left${apos} + Merge branch ${apos}left${apos} into master # By Another Author (3) and A U Thor (2) # Via Another Committer @@ -253,13 +253,13 @@ test_expect_success '--log=5 shows all 5 commits' ' ' test_expect_success '--no-log disables shortlog' ' - echo "Merge branch ${apos}left${apos}" >expected && + echo "Merge branch ${apos}left${apos} into master" >expected && git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual && test_cmp expected actual ' test_expect_success '--log=0 disables shortlog' ' - echo "Merge branch ${apos}left${apos}" >expected && + echo "Merge branch ${apos}left${apos} into master" >expected && git fmt-merge-msg --no-log <.git/FETCH_HEAD >actual && test_cmp expected actual ' @@ -300,7 +300,7 @@ test_expect_success 'fmt-merge-msg -m' ' test_expect_success 'setup: expected shortlog for two branches' ' cat >expected <<-EOF - Merge branches ${apos}left${apos} and ${apos}right${apos} + Merge branches ${apos}left${apos} and ${apos}right${apos} into master # By Another Author (3) and A U Thor (2) # Via Another Committer @@ -397,7 +397,7 @@ test_expect_success 'merge-msg with nothing to merge' ' test_expect_success 'merge-msg tag' ' cat >expected <<-EOF && - Merge tag ${apos}tag-r3${apos} + Merge tag ${apos}tag-r3${apos} into master * tag ${apos}tag-r3${apos}: Right #3 @@ -418,7 +418,7 @@ test_expect_success 'merge-msg tag' ' test_expect_success 'merge-msg two tags' ' cat >expected <<-EOF && - Merge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos} + Merge tags ${apos}tag-r3${apos} and ${apos}tag-l5${apos} into master * tag ${apos}tag-r3${apos}: Right #3 @@ -448,7 +448,7 @@ test_expect_success 'merge-msg two tags' ' test_expect_success 'merge-msg tag and branch' ' cat >expected <<-EOF && - Merge branch ${apos}left${apos}, tag ${apos}tag-r3${apos} + Merge branch ${apos}left${apos}, tag ${apos}tag-r3${apos} into master * tag ${apos}tag-r3${apos}: Right #3 @@ -479,7 +479,7 @@ test_expect_success 'merge-msg tag and branch' ' test_expect_success 'merge-msg lots of commits' ' { cat <<-EOF && - Merge branch ${apos}long${apos} + Merge branch ${apos}long${apos} into master * long: (35 commits) EOF @@ -516,7 +516,7 @@ test_expect_success 'merge-msg with "merging" an annotated tag' ' git fmt-merge-msg <.git/FETCH_HEAD >actual && { cat <<-\EOF - Merge tag '\''annote'\'' + Merge tag '\''annote'\'' into master An annotated one @@ -531,7 +531,7 @@ test_expect_success 'merge-msg with "merging" an annotated tag' ' git merge --no-commit --no-ff $annote && { cat <<-EOF - Merge tag '\''$annote'\'' + Merge tag '\''$annote'\'' into master An annotated one diff --git a/t/t7112-reset-submodule.sh b/t/t7112-reset-submodule.sh index 67346424a5..19830d9036 100755 --- a/t/t7112-reset-submodule.sh +++ b/t/t7112-reset-submodule.sh @@ -12,10 +12,10 @@ test_submodule_switch_recursing_with_args "reset --keep" test_submodule_forced_switch_recursing_with_args "reset --hard" -test_submodule_switch "git reset --keep" +test_submodule_switch "reset --keep" -test_submodule_switch "git reset --merge" +test_submodule_switch "reset --merge" -test_submodule_forced_switch "git reset --hard" +test_submodule_forced_switch "reset --hard" test_done diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh index 4fb447a143..aa19ff3a2e 100755 --- a/t/t7406-submodule-update.sh +++ b/t/t7406-submodule-update.sh @@ -70,6 +70,22 @@ test_expect_success 'setup a submodule tree' ' ) ' +test_expect_success 'update --remote falls back to using HEAD' ' + test_create_repo main-branch-submodule && + test_commit -C main-branch-submodule initial && + + test_create_repo main-branch && + git -C main-branch submodule add ../main-branch-submodule && + git -C main-branch commit -m add-submodule && + + git -C main-branch-submodule switch -c hello && + test_commit -C main-branch-submodule world && + + git clone --recursive main-branch main-branch-clone && + git -C main-branch-clone submodule update --remote main-branch-submodule && + test_path_exists main-branch-clone/main-branch-submodule/world.t +' + test_expect_success 'submodule update detaching the HEAD ' ' (cd super/submodule && git reset --hard HEAD~1 diff --git a/t/t7419-submodule-set-branch.sh b/t/t7419-submodule-set-branch.sh index fd25f786a3..3b925c302f 100755 --- a/t/t7419-submodule-set-branch.sh +++ b/t/t7419-submodule-set-branch.sh @@ -52,12 +52,13 @@ test_expect_success 'test submodule set-branch --branch' ' ' test_expect_success 'test submodule set-branch --default' ' + test_commit -C submodule c && (cd super && git submodule set-branch --default submodule && ! grep branch .gitmodules && git submodule update --remote && cat <<-\EOF >expect && - a + c EOF git -C submodule show -s --pretty=%s >actual && test_cmp expect actual @@ -65,6 +66,7 @@ test_expect_success 'test submodule set-branch --default' ' ' test_expect_success 'test submodule set-branch -b' ' + test_commit -C submodule b && (cd super && git submodule set-branch -b topic submodule && grep "branch = topic" .gitmodules && @@ -78,12 +80,13 @@ test_expect_success 'test submodule set-branch -b' ' ' test_expect_success 'test submodule set-branch -d' ' + test_commit -C submodule d && (cd super && git submodule set-branch -d submodule && ! grep branch .gitmodules && git submodule update --remote && cat <<-\EOF >expect && - a + d EOF git -C submodule show -s --pretty=%s >actual && test_cmp expect actual diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh index 5883a6adc3..1d45f9a4ed 100755 --- a/t/t7600-merge.sh +++ b/t/t7600-merge.sh @@ -14,9 +14,9 @@ Testing basic merge operations/option parsing. ! [c4] c4 ! [c5] c5 ! [c6] c6 - * [master] Merge commit 'c1' + * [master] Merge commit 'c1' into master -------- - - [master] Merge commit 'c1' + - [master] Merge commit 'c1' into master + * [c1] commit 1 + [c6] c6 + [c5] c5 @@ -44,8 +44,8 @@ test_write_lines '1 X' 2 '3 X' 4 '5 X' 6 7 8 '9 X' >result.1-3-5-9 test_write_lines 1 2 3 4 5 6 7 8 '9 Z' >result.9z create_merge_msgs () { - echo "Merge tag 'c2'" >msg.1-5 && - echo "Merge tags 'c2' and 'c3'" >msg.1-5-9 && + echo "Merge tag 'c2' into master" >msg.1-5 && + echo "Merge tags 'c2' and 'c3' into master" >msg.1-5-9 && { echo "Squashed commit of the following:" && echo && @@ -258,7 +258,7 @@ test_expect_success 'merge c3 with c7 with commit.cleanup = scissors' ' git commit --no-edit -a && cat >expect <<-\EOF && - Merge tag '"'"'c7'"'"' + Merge tag '"'"'c7'"'"' into master # ------------------------ >8 ------------------------ # Do not modify or remove the line above. @@ -808,10 +808,10 @@ test_expect_success 'merge with conflicted --autostash changes' ' ' cat >expected.branch <<\EOF -Merge branch 'c5-branch' (early part) +Merge branch 'c5-branch' (early part) into master EOF cat >expected.tag <<\EOF -Merge commit 'c5~1' +Merge commit 'c5~1' into master EOF test_expect_success 'merge early part of c2' ' diff --git a/t/t7608-merge-messages.sh b/t/t7608-merge-messages.sh index 8e7e0a5865..2af33f195b 100755 --- a/t/t7608-merge-messages.sh +++ b/t/t7608-merge-messages.sh @@ -16,7 +16,7 @@ test_expect_success 'merge local branch' ' git checkout master && test_commit master-2 && git merge local-branch && - check_oneline "Merge branch Qlocal-branchQ" + check_oneline "Merge branch Qlocal-branchQ into master" ' test_expect_success 'merge octopus branches' ' @@ -26,7 +26,7 @@ test_expect_success 'merge octopus branches' ' test_commit octopus-2 && git checkout master && git merge octopus-a octopus-b && - check_oneline "Merge branches Qoctopus-aQ and Qoctopus-bQ" + check_oneline "Merge branches Qoctopus-aQ and Qoctopus-bQ into master" ' test_expect_success 'merge tag' ' @@ -35,7 +35,7 @@ test_expect_success 'merge tag' ' git checkout master && test_commit master-3 && git merge tag-1 && - check_oneline "Merge tag Qtag-1Q" + check_oneline "Merge tag Qtag-1Q into master" ' test_expect_success 'ambiguous tag' ' @@ -44,7 +44,7 @@ test_expect_success 'ambiguous tag' ' git checkout master && test_commit master-4 && git merge ambiguous && - check_oneline "Merge tag QambiguousQ" + check_oneline "Merge tag QambiguousQ into master" ' test_expect_success 'remote-tracking branch' ' @@ -54,7 +54,7 @@ test_expect_success 'remote-tracking branch' ' git checkout master && test_commit master-5 && git merge origin/master && - check_oneline "Merge remote-tracking branch Qorigin/masterQ" + check_oneline "Merge remote-tracking branch Qorigin/masterQ into master" ' test_done diff --git a/t/t7613-merge-submodule.sh b/t/t7613-merge-submodule.sh index d1e9fcc781..04bf4be7d7 100755 --- a/t/t7613-merge-submodule.sh +++ b/t/t7613-merge-submodule.sh @@ -6,14 +6,14 @@ test_description='merge can handle submodules' . "$TEST_DIRECTORY"/lib-submodule-update.sh # merges without conflicts -test_submodule_switch "git merge" +test_submodule_switch "merge" -test_submodule_switch "git merge --ff" +test_submodule_switch "merge --ff" -test_submodule_switch "git merge --ff-only" +test_submodule_switch "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_submodule_switch "merge --no-ff" test_done diff --git a/t/t7800-difftool.sh b/t/t7800-difftool.sh index 29b92907e2..524f30f7dc 100755 --- a/t/t7800-difftool.sh +++ b/t/t7800-difftool.sh @@ -720,6 +720,14 @@ test_expect_success SYMLINKS 'difftool --dir-diff handles modified symlinks' ' test_cmp expect actual ' +test_expect_success 'add -N and difftool -d' ' + test_when_finished git reset --hard && + + test_write_lines A B C >intent-to-add && + git add -N intent-to-add && + git difftool --dir-diff --extcmd ls +' + test_expect_success 'outside worktree' ' echo 1 >1 && echo 2 >2 && diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index 90f61c3400..ec261085ec 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -42,7 +42,8 @@ clean_fake_sendmail () { } test_expect_success $PREREQ 'Extract patches' ' - patches=$(git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1) + patches=$(git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1) && + threaded_patches=$(git format-patch -o threaded -s --in-reply-to="format" HEAD^1) ' # Test no confirm early to ensure remaining tests will not hang @@ -1219,6 +1220,17 @@ test_expect_success $PREREQ 'threading but no chain-reply-to' ' grep "In-Reply-To: " stdout ' +test_expect_success $PREREQ 'override in-reply-to if no threading' ' + git send-email \ + --dry-run \ + --from="Example <nobody@example.com>" \ + --to=nobody@example.com \ + --no-thread \ + --in-reply-to="override" \ + $threaded_patches >stdout && + grep "In-Reply-To: <override>" stdout +' + test_expect_success $PREREQ 'sendemail.to works' ' git config --replace-all sendemail.to "Somebody <somebody@ex.com>" && git send-email \ diff --git a/t/t9020-remote-svn.sh b/t/t9020-remote-svn.sh index 6fca08e5e3..754c4a3284 100755 --- a/t/t9020-remote-svn.sh +++ b/t/t9020-remote-svn.sh @@ -48,8 +48,8 @@ test_expect_success REMOTE_SVN 'simple fetch' ' ' test_debug ' - cat .git/refs/svn/svnsim/master - cat .git/refs/remotes/svnsim/master + git show-ref -s refs/svn/svnsim/master + git show-ref -s refs/remotes/svnsim/master ' test_expect_success REMOTE_SVN 'repeated fetch, nothing shall change' ' @@ -84,6 +84,12 @@ test_expect_success REMOTE_SVN 'incremental imports must lead to the same head' test_cmp master.good .git/refs/remotes/svnsim/master ' +test_expect_success REMOTE_SVN 'respects configured default initial branch' ' + git -c init.defaultBranch=trunk remote add -f trunk \ + "testsvn::file://$TEST_DIRECTORY/t9154/svn.dump" && + git rev-parse --verify refs/remotes/trunk/trunk +' + test_debug 'git branch -a' test_done diff --git a/t/t9100-git-svn-basic.sh b/t/t9100-git-svn-basic.sh index 2c309a57d9..9f2d19ecc4 100755 --- a/t/t9100-git-svn-basic.sh +++ b/t/t9100-git-svn-basic.sh @@ -208,9 +208,10 @@ name='check imported tree checksums expected tree checksums' rm -f expected if test_have_prereq UTF8 then - echo tree dc68b14b733e4ec85b04ab6f712340edc5dc936e > expected + echo tree dc68b14b733e4ec85b04ab6f712340edc5dc936e > expected.sha1 + echo tree b95b55b29d771f5eb73aa9b9d52d02fe11a2538c2feb0829f754ce20a91d98eb > expected.sha256 fi -cat >> expected <<\EOF +cat >> expected.sha1 <<\EOF tree c3322890dcf74901f32d216f05c5044f670ce632 tree d3ccd5035feafd17b030c5732e7808cc49122853 tree d03e1630363d4881e68929d532746b20b0986b83 @@ -220,8 +221,20 @@ tree 149d63cd5878155c846e8c55d7d8487de283f89e tree d667270a1f7b109f5eb3aaea21ede14b56bfdd6e tree 8f51f74cf0163afc9ad68a4b1537288c4558b5a4 EOF +cat >> expected.sha256 <<\EOF +tree 8d12756699d0b5b110514240a0ff141f6cbf8891fd69ab05e5594196fb437c9f +tree 8187168d33f7d4ccb8c1cc6e99532810aaccb47658f35d19b3803072d1128d7a +tree 74e535d85da8ee25eb23d7b506790c5ab3ccdb1ba0826bd57625ed44ef361650 +tree 6fd7dd963e3cdca0cbd6368ed3cfcc8037cc154d2e7719d9d369a0952364fd95 +tree 1fd6cec6aa95102d69266e20419bb62ec2a06372d614b9850ef23ff204103bb4 +tree 6fd7dd963e3cdca0cbd6368ed3cfcc8037cc154d2e7719d9d369a0952364fd95 +tree deb2b7ac79cd8ce6f52af6a5a0a08691e94ba74a2ed55966bb27dbec551730eb +tree 59e2e936761188476a7752034e8aa0a822b34050c8504b0dfd946407f4bc9215 +EOF -test_expect_success POSIXPERM,SYMLINKS "$name" "test_cmp expected a" +test_expect_success POSIXPERM,SYMLINKS "$name" ' + test_cmp expected.$(test_oid algo) a +' test_expect_success 'exit if remote refs are ambigious' ' git config --add svn-remote.svn.fetch \ diff --git a/t/t9101-git-svn-props.sh b/t/t9101-git-svn-props.sh index c26c4b0927..8b5681dd68 100755 --- a/t/t9101-git-svn-props.sh +++ b/t/t9101-git-svn-props.sh @@ -160,11 +160,13 @@ cat >create-ignore.expect <<\EOF /no-such-file* EOF -cat >create-ignore-index.expect <<\EOF -100644 8c52e5dfcd0a8b6b6bcfe6b41b89bcbf493718a5 0 .gitignore -100644 8c52e5dfcd0a8b6b6bcfe6b41b89bcbf493718a5 0 deeply/.gitignore -100644 8c52e5dfcd0a8b6b6bcfe6b41b89bcbf493718a5 0 deeply/nested/.gitignore -100644 8c52e5dfcd0a8b6b6bcfe6b41b89bcbf493718a5 0 deeply/nested/directory/.gitignore +expectoid=$(git hash-object create-ignore.expect) + +cat >create-ignore-index.expect <<EOF +100644 $expectoid 0 .gitignore +100644 $expectoid 0 deeply/.gitignore +100644 $expectoid 0 deeply/nested/.gitignore +100644 $expectoid 0 deeply/nested/directory/.gitignore EOF test_expect_success 'test create-ignore' " diff --git a/t/t9104-git-svn-follow-parent.sh b/t/t9104-git-svn-follow-parent.sh index 5e0ad19177..67eed2fefc 100755 --- a/t/t9104-git-svn-follow-parent.sh +++ b/t/t9104-git-svn-follow-parent.sh @@ -161,6 +161,7 @@ test_expect_success "track initial change if it was only made to parent" ' ' test_expect_success "follow-parent is atomic" ' + record_size=$(($(test_oid rawsz) + 4)) && ( cd wc && svn_cmd up && @@ -186,7 +187,7 @@ test_expect_success "follow-parent is atomic" ' mkdir -p "$GIT_DIR"/svn/refs/remotes/flunk@18 && rev_map=$(cd "$GIT_DIR"/svn/refs/remotes/stunk && ls .rev_map*) && dd if="$GIT_DIR"/svn/refs/remotes/stunk/$rev_map \ - of="$GIT_DIR"/svn/refs/remotes/flunk@18/$rev_map bs=24 count=1 && + of="$GIT_DIR"/svn/refs/remotes/flunk@18/$rev_map bs=$record_size count=1 && rm -rf "$GIT_DIR"/svn/refs/remotes/stunk && git svn init --minimize-url -i flunk "$svnrepo"/flunk && git svn fetch -i flunk && diff --git a/t/t9108-git-svn-glob.sh b/t/t9108-git-svn-glob.sh index 6990f64364..d5939d4753 100755 --- a/t/t9108-git-svn-glob.sh +++ b/t/t9108-git-svn-glob.sh @@ -48,7 +48,7 @@ test_expect_success 'test refspec globbing' ' "tags/*/src/a:refs/remotes/tags/*" && git svn multi-fetch && git log --pretty=oneline refs/remotes/tags/end >actual && - sed -e "s/^.\{41\}//" actual >output.end && + cut -d" " -f2- actual >output.end && test_cmp expect.end output.end && test "$(git rev-parse refs/remotes/tags/end~1)" = \ "$(git rev-parse refs/remotes/branches/start)" && @@ -84,7 +84,7 @@ test_expect_success 'test left-hand-side only globbing' ' test $(git rev-parse refs/remotes/two/tags/end~3) = \ $(git rev-parse refs/remotes/two/branches/start) && git log --pretty=oneline refs/remotes/two/tags/end >actual && - sed -e "s/^.\{41\}//" actual >output.two && + cut -d" " -f2- actual >output.two && test_cmp expect.two output.two ' diff --git a/t/t9109-git-svn-multi-glob.sh b/t/t9109-git-svn-multi-glob.sh index c1e7542a37..648dcee1ea 100755 --- a/t/t9109-git-svn-multi-glob.sh +++ b/t/t9109-git-svn-multi-glob.sh @@ -48,7 +48,7 @@ test_expect_success 'test refspec globbing' ' "tags/*/src/a:refs/remotes/tags/*" && git svn multi-fetch && git log --pretty=oneline refs/remotes/tags/end >actual && - sed -e "s/^.\{41\}//" actual >output.end && + cut -d" " -f2- actual >output.end && test_cmp expect.end output.end && test "$(git rev-parse refs/remotes/tags/end~1)" = \ "$(git rev-parse refs/remotes/branches/v1/start)" && @@ -84,7 +84,7 @@ test_expect_success 'test left-hand-side only globbing' ' test $(git rev-parse refs/remotes/two/tags/end~3) = \ $(git rev-parse refs/remotes/two/branches/v1/start) && git log --pretty=oneline refs/remotes/two/tags/end >actual && - sed -e "s/^.\{41\}//" actual >output.two && + cut -d" " -f2- actual >output.two && test_cmp expect.two output.two ' cat > expect.four <<EOF @@ -135,7 +135,7 @@ test_expect_success 'test another branch' ' test $(git rev-parse refs/remotes/four/tags/next~2) = \ $(git rev-parse refs/remotes/four/branches/v2/start) && git log --pretty=oneline refs/remotes/four/tags/next >actual && - sed -e "s/^.\{41\}//" actual >output.four && + cut -d" " -f2- actual >output.four && test_cmp expect.four output.four ' diff --git a/t/t9168-git-svn-partially-globbed-names.sh b/t/t9168-git-svn-partially-globbed-names.sh index bdf6e84999..854b3419b2 100755 --- a/t/t9168-git-svn-partially-globbed-names.sh +++ b/t/t9168-git-svn-partially-globbed-names.sh @@ -49,7 +49,7 @@ test_expect_success 'test refspec prefixed globbing' ' "tags/t_*/src/a:refs/remotes/tags/t_*" && git svn multi-fetch && git log --pretty=oneline refs/remotes/tags/t_end >actual && - sed -e "s/^.\{41\}//" actual >output.end && + cut -d" " -f2- actual >output.end && test_cmp expect.end output.end && test "$(git rev-parse refs/remotes/tags/t_end~1)" = \ "$(git rev-parse refs/remotes/branches/b_start)" && @@ -87,7 +87,7 @@ test_expect_success 'test left-hand-side only prefixed globbing' ' test $(git rev-parse refs/remotes/two/tags/t_end~3) = \ $(git rev-parse refs/remotes/two/branches/b_start) && git log --pretty=oneline refs/remotes/two/tags/t_end >actual && - sed -e "s/^.\{41\}//" actual >output.two && + cut -d" " -f2- actual >output.two && test_cmp expect.two output.two ' @@ -129,7 +129,7 @@ test_expect_success 'test prefixed globs match just prefix' ' test $(git rev-parse refs/remotes/three/tags/t_~1) = \ $(git rev-parse refs/remotes/three/branches/b_) && git log --pretty=oneline refs/remotes/three/tags/t_ >actual && - sed -e "s/^.\{41\}//" actual >output.three && + cut -d" " -f2- actual >output.three && test_cmp expect.three output.three ' @@ -199,7 +199,7 @@ test_expect_success 'test globbing in the middle of the word' ' test $(git rev-parse refs/remotes/five/tags/fghij~1) = \ $(git rev-parse refs/remotes/five/branches/abcde) && git log --pretty=oneline refs/remotes/five/tags/fghij >actual && - sed -e "s/^.\{41\}//" actual >output.five && + cut -d" " -f2- actual >output.five && test_cmp expect.five output.five ' diff --git a/t/t9300-fast-import.sh b/t/t9300-fast-import.sh index 768257b29e..e151df81c0 100755 --- a/t/t9300-fast-import.sh +++ b/t/t9300-fast-import.sh @@ -410,6 +410,34 @@ test_expect_success 'B: accept empty committer' ' test -z "$out" ' +test_expect_success 'B: reject invalid timezone' ' + cat >input <<-INPUT_END && + commit refs/heads/invalid-timezone + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1234567890 +051800 + data <<COMMIT + empty commit + COMMIT + INPUT_END + + test_when_finished "git update-ref -d refs/heads/invalid-timezone" && + test_must_fail git fast-import <input +' + +test_expect_success 'B: accept invalid timezone with raw-permissive' ' + cat >input <<-INPUT_END && + commit refs/heads/invalid-timezone + committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 1234567890 +051800 + data <<COMMIT + empty commit + COMMIT + INPUT_END + + git init invalid-timezone && + git -C invalid-timezone fast-import --date-format=raw-permissive <input && + git -C invalid-timezone cat-file -p invalid-timezone >out && + grep "1234567890 [+]051800" out +' + test_expect_success 'B: accept and fixup committer with no name' ' cat >input <<-INPUT_END && commit refs/heads/empty-committer-2 diff --git a/t/t9351-fast-export-anonymize.sh b/t/t9351-fast-export-anonymize.sh index 897dc50907..5ac2c3b5ee 100755 --- a/t/t9351-fast-export-anonymize.sh +++ b/t/t9351-fast-export-anonymize.sh @@ -6,15 +6,24 @@ test_description='basic tests for fast-export --anonymize' test_expect_success 'setup simple repo' ' test_commit base && test_commit foo && + test_commit retain-me && git checkout -b other HEAD^ && mkdir subdir && test_commit subdir/bar && test_commit subdir/xyzzy && + fake_commit=$(echo $ZERO_OID | sed s/0/a/) && + git update-index --add --cacheinfo 160000,$fake_commit,link1 && + git update-index --add --cacheinfo 160000,$fake_commit,link2 && + git commit -m "add gitlink" && git tag -m "annotated tag" mytag ' test_expect_success 'export anonymized stream' ' - git fast-export --anonymize --all >stream + git fast-export --anonymize --all \ + --anonymize-map=retain-me \ + --anonymize-map=xyzzy:custom-name \ + --anonymize-map=other \ + >stream ' # this also covers commit messages @@ -26,12 +35,23 @@ test_expect_success 'stream omits path names' ' ! grep xyzzy stream ' -test_expect_success 'stream allows master as refname' ' - grep master stream +test_expect_success 'stream contains user-specified names' ' + grep retain-me stream && + grep custom-name stream +' + +test_expect_success 'stream omits gitlink oids' ' + # avoid relying on the whole oid to remain hash-agnostic; this is + # plenty to be unique within our test case + ! grep a000000000000000000 stream +' + +test_expect_success 'stream retains other as refname' ' + grep other stream ' test_expect_success 'stream omits other refnames' ' - ! grep other stream && + ! grep master stream && ! grep mytag stream ' @@ -57,7 +77,8 @@ test_expect_success 'import stream to new repository' ' test_expect_success 'result has two branches' ' git for-each-ref --format="%(refname)" refs/heads >branches && test_line_count = 2 branches && - other_branch=$(grep -v refs/heads/master branches) + other_branch=refs/heads/other && + main_branch=$(grep -v $other_branch branches) ' test_expect_success 'repo has original shape and timestamps' ' @@ -65,34 +86,35 @@ test_expect_success 'repo has original shape and timestamps' ' git log --format="%m %ct" --left-right --boundary "$@" } && (cd .. && shape master...other) >expect && - shape master...$other_branch >actual && + shape $main_branch...$other_branch >actual && test_cmp expect actual ' test_expect_success 'root tree has original shape' ' # the output entries are not necessarily in the same - # order, but we know at least that we will have one tree - # and one blob, so just check the sorted order - cat >expect <<-\EOF && - blob - tree - EOF + # order, but we should at least have the same set of + # object types. + git -C .. ls-tree HEAD >orig-root && + cut -d" " -f2 <orig-root | sort >expect && git ls-tree $other_branch >root && cut -d" " -f2 <root | sort >actual && test_cmp expect actual ' test_expect_success 'paths in subdir ended up in one tree' ' - cat >expect <<-\EOF && - blob - blob - EOF + git -C .. ls-tree other:subdir >orig-subdir && + cut -d" " -f2 <orig-subdir | sort >expect && tree=$(grep tree root | cut -f2) && git ls-tree $other_branch:$tree >tree && cut -d" " -f2 <tree >actual && test_cmp expect actual ' +test_expect_success 'identical gitlinks got identical oid' ' + awk "/commit/ { print \$3 }" <root | sort -u >commits && + test_line_count = 1 commits +' + test_expect_success 'tag points to branch tip' ' git rev-parse $other_branch >expect && git for-each-ref --format="%(*objectname)" | grep . >actual && diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 3c44af6940..8425b9a531 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -494,7 +494,7 @@ test_expect_success '__gitcomp - prefix' ' ' test_expect_success '__gitcomp - suffix' ' - test_gitcomp "branch.me" "master maint next pu" "branch." \ + test_gitcomp "branch.me" "master maint next seen" "branch." \ "ma" "." <<-\EOF branch.master.Z branch.maint.Z @@ -545,7 +545,7 @@ read -r -d "" refs <<-\EOF maint master next -pu +seen EOF test_expect_success '__gitcomp_nl - trailing space' ' @@ -1240,6 +1240,461 @@ test_expect_success '__git_complete_fetch_refspecs - fully qualified & prefix' ' test_cmp expected out ' +test_expect_success 'git switch - with no options, complete local branches and unique remote branch names for DWIM logic' ' + test_completion "git switch " <<-\EOF + branch-in-other Z + master Z + master-in-other Z + matching-branch Z + EOF +' + +test_expect_success 'git checkout - completes refs and unique remote branches for DWIM' ' + test_completion "git checkout " <<-\EOF + HEAD Z + branch-in-other Z + master Z + master-in-other Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/master-in-other Z + EOF +' + +test_expect_success 'git switch - with --no-guess, complete only local branches' ' + test_completion "git switch --no-guess " <<-\EOF + master Z + matching-branch Z + EOF +' + +test_expect_success 'git switch - with GIT_COMPLETION_CHECKOUT_NO_GUESS=1, complete only local branches' ' + GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git switch " <<-\EOF + master Z + matching-branch Z + EOF +' + +test_expect_success 'git switch - --guess overrides GIT_COMPLETION_CHECKOUT_NO_GUESS=1, complete local branches and unique remote names for DWIM logic' ' + GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git switch --guess " <<-\EOF + branch-in-other Z + master Z + master-in-other Z + matching-branch Z + EOF +' + +test_expect_success 'git switch - a later --guess overrides previous --no-guess, complete local and remote unique branches for DWIM' ' + test_completion "git switch --no-guess --guess " <<-\EOF + branch-in-other Z + master Z + master-in-other Z + matching-branch Z + EOF +' + +test_expect_success 'git switch - a later --no-guess overrides previous --guess, complete only local branches' ' + test_completion "git switch --guess --no-guess " <<-\EOF + master Z + matching-branch Z + EOF +' + +test_expect_success 'git checkout - with GIT_COMPLETION_NO_GUESS=1 only completes refs' ' + GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git checkout " <<-\EOF + HEAD Z + master Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/master-in-other Z + EOF +' + +test_expect_success 'git checkout - --guess overrides GIT_COMPLETION_NO_GUESS=1, complete refs and unique remote branches for DWIM' ' + GIT_COMPLETION_CHECKOUT_NO_GUESS=1 test_completion "git checkout --guess " <<-\EOF + HEAD Z + branch-in-other Z + master Z + master-in-other Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/master-in-other Z + EOF +' + +test_expect_success 'git checkout - with --no-guess, only completes refs' ' + test_completion "git checkout --no-guess " <<-\EOF + HEAD Z + master Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/master-in-other Z + EOF +' + +test_expect_success 'git checkout - a later --guess overrides previous --no-guess, complete refs and unique remote branches for DWIM' ' + test_completion "git checkout --no-guess --guess " <<-\EOF + HEAD Z + branch-in-other Z + master Z + master-in-other Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/master-in-other Z + EOF +' + +test_expect_success 'git checkout - a later --no-guess overrides previous --guess, complete only refs' ' + test_completion "git checkout --guess --no-guess " <<-\EOF + HEAD Z + master Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/master-in-other Z + EOF +' + +test_expect_success 'git switch - with --detach, complete all references' ' + test_completion "git switch --detach " <<-\EOF + HEAD Z + master Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/master-in-other Z + EOF +' + +test_expect_success 'git checkout - with --detach, complete only references' ' + test_completion "git checkout --detach " <<-\EOF + HEAD Z + master Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/master-in-other Z + EOF +' + +test_expect_success 'git switch - with -d, complete all references' ' + test_completion "git switch -d " <<-\EOF + HEAD Z + master Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/master-in-other Z + EOF +' + +test_expect_success 'git checkout - with -d, complete only references' ' + test_completion "git checkout -d " <<-\EOF + HEAD Z + master Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/master-in-other Z + EOF +' + +test_expect_success 'git switch - with --track, complete only remote branches' ' + test_completion "git switch --track " <<-\EOF + other/branch-in-other Z + other/master-in-other Z + EOF +' + +test_expect_success 'git checkout - with --track, complete only remote branches' ' + test_completion "git checkout --track " <<-\EOF + other/branch-in-other Z + other/master-in-other Z + EOF +' + +test_expect_success 'git switch - with --no-track, complete only local branch names' ' + test_completion "git switch --no-track " <<-\EOF + master Z + matching-branch Z + EOF +' + +test_expect_success 'git checkout - with --no-track, complete only local references' ' + test_completion "git checkout --no-track " <<-\EOF + HEAD Z + master Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/master-in-other Z + EOF +' + +test_expect_success 'git switch - with -c, complete all references' ' + test_completion "git switch -c new-branch " <<-\EOF + HEAD Z + master Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/master-in-other Z + EOF +' + +test_expect_success 'git switch - with -C, complete all references' ' + test_completion "git switch -C new-branch " <<-\EOF + HEAD Z + master Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/master-in-other Z + EOF +' + +test_expect_success 'git switch - with -c and --track, complete all references' ' + test_completion "git switch -c new-branch --track " <<-EOF + HEAD Z + master Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/master-in-other Z + EOF +' + +test_expect_success 'git switch - with -C and --track, complete all references' ' + test_completion "git switch -C new-branch --track " <<-EOF + HEAD Z + master Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/master-in-other Z + EOF +' + +test_expect_success 'git switch - with -c and --no-track, complete all references' ' + test_completion "git switch -c new-branch --no-track " <<-\EOF + HEAD Z + master Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/master-in-other Z + EOF +' + +test_expect_success 'git switch - with -C and --no-track, complete all references' ' + test_completion "git switch -C new-branch --no-track " <<-\EOF + HEAD Z + master Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/master-in-other Z + EOF +' + +test_expect_success 'git checkout - with -b, complete all references' ' + test_completion "git checkout -b new-branch " <<-\EOF + HEAD Z + master Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/master-in-other Z + EOF +' + +test_expect_success 'git checkout - with -B, complete all references' ' + test_completion "git checkout -B new-branch " <<-\EOF + HEAD Z + master Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/master-in-other Z + EOF +' + +test_expect_success 'git checkout - with -b and --track, complete all references' ' + test_completion "git checkout -b new-branch --track " <<-EOF + HEAD Z + master Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/master-in-other Z + EOF +' + +test_expect_success 'git checkout - with -B and --track, complete all references' ' + test_completion "git checkout -B new-branch --track " <<-EOF + HEAD Z + master Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/master-in-other Z + EOF +' + +test_expect_success 'git checkout - with -b and --no-track, complete all references' ' + test_completion "git checkout -b new-branch --no-track " <<-\EOF + HEAD Z + master Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/master-in-other Z + EOF +' + +test_expect_success 'git checkout - with -B and --no-track, complete all references' ' + test_completion "git checkout -B new-branch --no-track " <<-\EOF + HEAD Z + master Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/master-in-other Z + EOF +' + +test_expect_success 'git switch - for -c, complete local branches and unique remote branches' ' + test_completion "git switch -c " <<-\EOF + branch-in-other Z + master Z + master-in-other Z + matching-branch Z + EOF +' + +test_expect_success 'git switch - for -C, complete local branches and unique remote branches' ' + test_completion "git switch -C " <<-\EOF + branch-in-other Z + master Z + master-in-other Z + matching-branch Z + EOF +' + +test_expect_success 'git switch - for -c with --no-guess, complete local branches only' ' + test_completion "git switch --no-guess -c " <<-\EOF + master Z + matching-branch Z + EOF +' + +test_expect_success 'git switch - for -C with --no-guess, complete local branches only' ' + test_completion "git switch --no-guess -C " <<-\EOF + master Z + matching-branch Z + EOF +' + +test_expect_success 'git switch - for -c with --no-track, complete local branches only' ' + test_completion "git switch --no-track -c " <<-\EOF + master Z + matching-branch Z + EOF +' + +test_expect_success 'git switch - for -C with --no-track, complete local branches only' ' + test_completion "git switch --no-track -C " <<-\EOF + master Z + matching-branch Z + EOF +' + +test_expect_success 'git checkout - for -b, complete local branches and unique remote branches' ' + test_completion "git checkout -b " <<-\EOF + branch-in-other Z + master Z + master-in-other Z + matching-branch Z + EOF +' + +test_expect_success 'git checkout - for -B, complete local branches and unique remote branches' ' + test_completion "git checkout -B " <<-\EOF + branch-in-other Z + master Z + master-in-other Z + matching-branch Z + EOF +' + +test_expect_success 'git checkout - for -b with --no-guess, complete local branches only' ' + test_completion "git checkout --no-guess -b " <<-\EOF + master Z + matching-branch Z + EOF +' + +test_expect_success 'git checkout - for -B with --no-guess, complete local branches only' ' + test_completion "git checkout --no-guess -B " <<-\EOF + master Z + matching-branch Z + EOF +' + +test_expect_success 'git checkout - for -b with --no-track, complete local branches only' ' + test_completion "git checkout --no-track -b " <<-\EOF + master Z + matching-branch Z + EOF +' + +test_expect_success 'git checkout - for -B with --no-track, complete local branches only' ' + test_completion "git checkout --no-track -B " <<-\EOF + master Z + matching-branch Z + EOF +' + +test_expect_success 'git switch - with --orphan completes local branch names and unique remote branch names' ' + test_completion "git switch --orphan " <<-\EOF + branch-in-other Z + master Z + master-in-other Z + matching-branch Z + EOF +' + +test_expect_success 'git switch - --orphan with branch already provided completes nothing else' ' + test_completion "git switch --orphan master " <<-\EOF + + EOF +' + +test_expect_success 'git checkout - with --orphan completes local branch names and unique remote branch names' ' + test_completion "git checkout --orphan " <<-\EOF + branch-in-other Z + master Z + master-in-other Z + matching-branch Z + EOF +' + +test_expect_success 'git checkout - --orphan with branch already provided completes local refs for a start-point' ' + test_completion "git checkout --orphan master " <<-\EOF + HEAD Z + master Z + matching-branch Z + matching-tag Z + other/branch-in-other Z + other/master-in-other Z + EOF +' + test_expect_success 'teardown after ref completion' ' git branch -d matching-branch && git tag -d matching-tag && diff --git a/t/test-lib.sh b/t/test-lib.sh index 88bb797141..618a7c8d5b 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -1414,6 +1414,7 @@ test_oid_init ZERO_OID=$(test_oid zero) OID_REGEX=$(echo $ZERO_OID | sed -e 's/0/[0-9a-f]/g') +OIDPATH_REGEX=$(test_oid_to_path $ZERO_OID | sed -e 's/0/[0-9a-f]/g') EMPTY_TREE=$(test_oid empty_tree) EMPTY_BLOB=$(test_oid empty_blob) _z40=$ZERO_OID @@ -1489,12 +1490,6 @@ case $uname_s in test_set_prereq SED_STRIPS_CR test_set_prereq GREP_STRIPS_CR ;; -FreeBSD) - test_set_prereq REGEX_ILLSEQ - test_set_prereq POSIXPERM - test_set_prereq BSLASHPSPEC - test_set_prereq EXECKEEPSPID - ;; *) test_set_prereq POSIXPERM test_set_prereq BSLASHPSPEC |