diff options
Diffstat (limited to 't')
31 files changed, 1027 insertions, 263 deletions
diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c index 313a153209..229ed416b0 100644 --- a/t/helper/test-path-utils.c +++ b/t/helper/test-path-utils.c @@ -172,9 +172,22 @@ static struct test_data dirname_data[] = { { NULL, NULL } }; -static int is_dotgitmodules(const char *path) +static int check_dotfile(const char *x, const char **argv, + int (*is_hfs)(const char *), + int (*is_ntfs)(const char *)) { - return is_hfs_dotgitmodules(path) || is_ntfs_dotgitmodules(path); + int res = 0, expect = 1; + for (; *argv; argv++) { + if (!strcmp("--not", *argv)) + expect = !expect; + else if (expect != (is_hfs(*argv) || is_ntfs(*argv))) + res = error("'%s' is %s.git%s", *argv, + expect ? "not " : "", x); + else + fprintf(stderr, "ok: '%s' is %s.git%s\n", + *argv, expect ? "" : "not ", x); + } + return !!res; } static int cmp_by_st_size(const void *a, const void *b) @@ -382,17 +395,24 @@ int cmd__path_utils(int argc, const char **argv) return test_function(dirname_data, posix_dirname, argv[1]); if (argc > 2 && !strcmp(argv[1], "is_dotgitmodules")) { - int res = 0, expect = 1, i; - for (i = 2; i < argc; i++) - if (!strcmp("--not", argv[i])) - expect = !expect; - else if (expect != is_dotgitmodules(argv[i])) - res = error("'%s' is %s.gitmodules", argv[i], - expect ? "not " : ""); - else - fprintf(stderr, "ok: '%s' is %s.gitmodules\n", - argv[i], expect ? "" : "not "); - return !!res; + return check_dotfile("modules", argv + 2, + is_hfs_dotgitmodules, + is_ntfs_dotgitmodules); + } + if (argc > 2 && !strcmp(argv[1], "is_dotgitignore")) { + return check_dotfile("ignore", argv + 2, + is_hfs_dotgitignore, + is_ntfs_dotgitignore); + } + if (argc > 2 && !strcmp(argv[1], "is_dotgitattributes")) { + return check_dotfile("attributes", argv + 2, + is_hfs_dotgitattributes, + is_ntfs_dotgitattributes); + } + if (argc > 2 && !strcmp(argv[1], "is_dotmailmap")) { + return check_dotfile("mailmap", argv + 2, + is_hfs_dotmailmap, + is_ntfs_dotmailmap); } if (argc > 2 && !strcmp(argv[1], "file-size")) { diff --git a/t/helper/test-submodule-nested-repo-config.c b/t/helper/test-submodule-nested-repo-config.c index c5fd4527dc..e3f11ff5a7 100644 --- a/t/helper/test-submodule-nested-repo-config.c +++ b/t/helper/test-submodule-nested-repo-config.c @@ -18,7 +18,7 @@ int cmd__submodule_nested_repo_config(int argc, const char **argv) setup_git_directory(); - sub = submodule_from_path(the_repository, &null_oid, argv[1]); + sub = submodule_from_path(the_repository, null_oid(), argv[1]); if (repo_submodule_init(&subrepo, the_repository, sub)) { die_usage(argv, "Submodule not found."); } diff --git a/t/perf/p5600-partial-clone.sh b/t/perf/p5600-partial-clone.sh index ca785a3341..a965f2c4d6 100755 --- a/t/perf/p5600-partial-clone.sh +++ b/t/perf/p5600-partial-clone.sh @@ -35,4 +35,8 @@ test_perf 'count non-promisor commits' ' git -C bare.git rev-list --all --count --exclude-promisor-objects ' +test_perf 'gc' ' + git -C bare.git gc +' + test_done diff --git a/t/t0060-path-utils.sh b/t/t0060-path-utils.sh index 0ff06b5d1b..de4960783f 100755 --- a/t/t0060-path-utils.sh +++ b/t/t0060-path-utils.sh @@ -468,6 +468,36 @@ test_expect_success 'match .gitmodules' ' .gitmodules,:\$DATA ' +test_expect_success 'match .gitattributes' ' + test-tool path-utils is_dotgitattributes \ + .gitattributes \ + .git${u200c}attributes \ + .Gitattributes \ + .gitattributeS \ + GITATT~1 \ + GI7D29~1 +' + +test_expect_success 'match .gitignore' ' + test-tool path-utils is_dotgitignore \ + .gitignore \ + .git${u200c}ignore \ + .Gitignore \ + .gitignorE \ + GITIGN~1 \ + GI250A~1 +' + +test_expect_success 'match .mailmap' ' + test-tool path-utils is_dotmailmap \ + .mailmap \ + .mail${u200c}map \ + .Mailmap \ + .mailmaP \ + MAILMA~1 \ + MABA30~1 +' + test_expect_success MINGW 'is_valid_path() on Windows' ' test-tool path-utils is_valid_path \ win32 \ diff --git a/t/t1300-config.sh b/t/t1300-config.sh index e0dd5d65ce..9ff46f3b04 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -1374,16 +1374,29 @@ test_expect_success 'git --config-env=key=envvar support' ' cat >expect <<-\EOF && value value + value + value + false false EOF { ENVVAR=value git --config-env=core.name=ENVVAR config core.name && + ENVVAR=value git --config-env core.name=ENVVAR config core.name && ENVVAR=value git --config-env=foo.CamelCase=ENVVAR config foo.camelcase && - ENVVAR= git --config-env=foo.flag=ENVVAR config --bool foo.flag + ENVVAR=value git --config-env foo.CamelCase=ENVVAR config foo.camelcase && + ENVVAR= git --config-env=foo.flag=ENVVAR config --bool foo.flag && + ENVVAR= git --config-env foo.flag=ENVVAR config --bool foo.flag } >actual && test_cmp expect actual ' +test_expect_success 'git --config-env with missing value' ' + test_must_fail env ENVVAR=value git --config-env 2>error && + grep "no config key given for --config-env" error && + test_must_fail env ENVVAR=value git --config-env config core.name 2>error && + grep "invalid config format: config" error +' + test_expect_success 'git --config-env fails with invalid parameters' ' test_must_fail git --config-env=foo.flag config --bool foo.flag 2>error && test_i18ngrep "invalid config format: foo.flag" error && @@ -2059,6 +2072,91 @@ test_expect_success '--show-scope with --show-origin' ' test_cmp expect output ' +test_expect_success 'override global and system config' ' + test_when_finished rm -f "$HOME"/.config/git && + + cat >"$HOME"/.gitconfig <<-EOF && + [home] + config = true + EOF + mkdir -p "$HOME"/.config/git && + cat >"$HOME"/.config/git/config <<-EOF && + [xdg] + config = true + EOF + cat >.git/config <<-EOF && + [local] + config = true + EOF + cat >custom-global-config <<-EOF && + [global] + config = true + EOF + cat >custom-system-config <<-EOF && + [system] + config = true + EOF + + cat >expect <<-EOF && + global xdg.config=true + global home.config=true + local local.config=true + EOF + git config --show-scope --list >output && + test_cmp expect output && + + cat >expect <<-EOF && + system system.config=true + global global.config=true + local local.config=true + EOF + GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=custom-system-config GIT_CONFIG_GLOBAL=custom-global-config \ + git config --show-scope --list >output && + test_cmp expect output && + + cat >expect <<-EOF && + local local.config=true + EOF + GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=/dev/null GIT_CONFIG_GLOBAL=/dev/null \ + git config --show-scope --list >output && + test_cmp expect output +' + +test_expect_success 'override global and system config with missing file' ' + test_must_fail env GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=/dev/null git config --global --list && + test_must_fail env GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=does-not-exist git config --system --list && + GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=does-not-exist git version +' + +test_expect_success 'system override has no effect with GIT_CONFIG_NOSYSTEM' ' + # `git config --system` has different semantics compared to other + # commands as it ignores GIT_CONFIG_NOSYSTEM. We thus test whether the + # variable has an effect via a different proxy. + cat >alias-config <<-EOF && + [alias] + hello-world = !echo "hello world" + EOF + test_must_fail env GIT_CONFIG_NOSYSTEM=true GIT_CONFIG_SYSTEM=alias-config \ + git hello-world && + GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=alias-config \ + git hello-world >actual && + echo "hello world" >expect && + test_cmp expect actual +' + +test_expect_success 'write to overridden global and system config' ' + cat >expect <<EOF && +[config] + key = value +EOF + + GIT_CONFIG_GLOBAL=write-to-global git config --global config.key value && + test_cmp expect write-to-global && + + GIT_CONFIG_SYSTEM=write-to-system git config --system config.key value && + test_cmp expect write-to-system +' + for opt in --local --worktree do test_expect_success "$opt requires a repo" ' diff --git a/t/t3418-rebase-continue.sh b/t/t3418-rebase-continue.sh index 0838f4e798..f4c2ee02bc 100755 --- a/t/t3418-rebase-continue.sh +++ b/t/t3418-rebase-continue.sh @@ -282,12 +282,35 @@ test_expect_success '--reschedule-failed-exec' ' test_i18ngrep "has been rescheduled" err ' -test_expect_success 'rebase.reschedulefailedexec only affects `rebase -i`' ' - test_config rebase.reschedulefailedexec true && +test_expect_success 'rebase.rescheduleFailedExec only affects `rebase -i`' ' + test_config rebase.rescheduleFailedExec true && test_must_fail git rebase -x false HEAD^ && grep "^exec false" .git/rebase-merge/git-rebase-todo && git rebase --abort && git rebase HEAD^ ' +test_expect_success 'rebase.rescheduleFailedExec=true & --no-reschedule-failed-exec' ' + test_when_finished "git rebase --abort" && + test_config rebase.rescheduleFailedExec true && + test_must_fail git rebase -x false --no-reschedule-failed-exec HEAD~2 && + test_must_fail git rebase --continue 2>err && + ! grep "has been rescheduled" err +' + +test_expect_success 'new rebase.rescheduleFailedExec=true setting in an ongoing rebase is ignored' ' + test_when_finished "git rebase --abort" && + test_must_fail git rebase -x false HEAD~2 && + test_config rebase.rescheduleFailedExec true && + test_must_fail git rebase --continue 2>err && + ! grep "has been rescheduled" err +' + +test_expect_success 'there is no --no-reschedule-failed-exec in an ongoing rebase' ' + test_when_finished "git rebase --abort" && + test_must_fail git rebase -x false HEAD~2 && + test_expect_code 129 git rebase --continue --no-reschedule-failed-exec && + test_expect_code 129 git rebase --edit-todo --no-reschedule-failed-exec +' + test_done diff --git a/t/t3602-rm-sparse-checkout.sh b/t/t3602-rm-sparse-checkout.sh new file mode 100755 index 0000000000..e9e9a15c74 --- /dev/null +++ b/t/t3602-rm-sparse-checkout.sh @@ -0,0 +1,78 @@ +#!/bin/sh + +test_description='git rm in sparse checked out working trees' + +. ./test-lib.sh + +test_expect_success 'setup' " + mkdir -p sub/dir && + touch a b c sub/d sub/dir/e && + git add -A && + git commit -m files && + + cat >sparse_error_header <<-EOF && + The following pathspecs didn't match any eligible path, but they do match index + entries outside the current sparse checkout: + EOF + + cat >sparse_hint <<-EOF && + hint: Disable or modify the sparsity rules if you intend to update such entries. + hint: Disable this message with \"git config advice.updateSparsePath false\" + EOF + + echo b | cat sparse_error_header - >sparse_entry_b_error && + cat sparse_entry_b_error sparse_hint >b_error_and_hint +" + +for opt in "" -f --dry-run +do + test_expect_success "rm${opt:+ $opt} does not remove sparse entries" ' + git sparse-checkout set a && + test_must_fail git rm $opt b 2>stderr && + test_cmp b_error_and_hint stderr && + git ls-files --error-unmatch b + ' +done + +test_expect_success 'recursive rm does not remove sparse entries' ' + git reset --hard && + git sparse-checkout set sub/dir && + git rm -r sub && + git status --porcelain -uno >actual && + echo "D sub/dir/e" >expected && + test_cmp expected actual +' + +test_expect_success 'rm obeys advice.updateSparsePath' ' + git reset --hard && + git sparse-checkout set a && + test_must_fail git -c advice.updateSparsePath=false rm b 2>stderr && + test_cmp sparse_entry_b_error stderr +' + +test_expect_success 'do not advice about sparse entries when they do not match the pathspec' ' + git reset --hard && + git sparse-checkout set a && + test_must_fail git rm nonexistent 2>stderr && + grep "fatal: pathspec .nonexistent. did not match any files" stderr && + ! grep -F -f sparse_error_header stderr +' + +test_expect_success 'do not warn about sparse entries when pathspec matches dense entries' ' + git reset --hard && + git sparse-checkout set a && + git rm "[ba]" 2>stderr && + test_must_be_empty stderr && + git ls-files --error-unmatch b && + test_must_fail git ls-files --error-unmatch a +' + +test_expect_success 'do not warn about sparse entries with --ignore-unmatch' ' + git reset --hard && + git sparse-checkout set a && + git rm --ignore-unmatch b 2>stderr && + test_must_be_empty stderr && + git ls-files --error-unmatch b +' + +test_done diff --git a/t/t3700-add.sh b/t/t3700-add.sh index 171b323f50..4086e1ebbc 100755 --- a/t/t3700-add.sh +++ b/t/t3700-add.sh @@ -196,6 +196,12 @@ test_expect_success 'git add --refresh with pathspec' ' grep baz actual ' +test_expect_success 'git add --refresh correctly reports no match error' " + echo \"fatal: pathspec ':(icase)nonexistent' did not match any files\" >expect && + test_must_fail git add --refresh ':(icase)nonexistent' 2>actual && + test_cmp expect actual +" + test_expect_success POSIXPERM,SANITY 'git add should fail atomically upon an unreadable file' ' git reset --hard && date >foo1 && diff --git a/t/t3705-add-sparse-checkout.sh b/t/t3705-add-sparse-checkout.sh new file mode 100755 index 0000000000..2b1fd0d0ee --- /dev/null +++ b/t/t3705-add-sparse-checkout.sh @@ -0,0 +1,155 @@ +#!/bin/sh + +test_description='git add in sparse checked out working trees' + +. ./test-lib.sh + +SPARSE_ENTRY_BLOB="" + +# Optionally take a printf format string to write to the sparse_entry file +setup_sparse_entry () { + # 'sparse_entry' might already be in the index with the skip-worktree + # bit set. Remove it so that the subsequent git add can update it. + git update-index --force-remove sparse_entry && + if test $# -eq 1 + then + printf "$1" >sparse_entry + else + >sparse_entry + fi && + git add sparse_entry && + git update-index --skip-worktree sparse_entry && + SPARSE_ENTRY_BLOB=$(git rev-parse :sparse_entry) +} + +test_sparse_entry_unchanged () { + echo "100644 $SPARSE_ENTRY_BLOB 0 sparse_entry" >expected && + git ls-files --stage sparse_entry >actual && + test_cmp expected actual +} + +setup_gitignore () { + test_when_finished rm -f .gitignore && + cat >.gitignore <<-EOF + * + !/sparse_entry + EOF +} + +test_expect_success 'setup' " + cat >sparse_error_header <<-EOF && + The following pathspecs didn't match any eligible path, but they do match index + entries outside the current sparse checkout: + EOF + + cat >sparse_hint <<-EOF && + hint: Disable or modify the sparsity rules if you intend to update such entries. + hint: Disable this message with \"git config advice.updateSparsePath false\" + EOF + + echo sparse_entry | cat sparse_error_header - >sparse_entry_error && + cat sparse_entry_error sparse_hint >error_and_hint +" + +test_expect_success 'git add does not remove sparse entries' ' + setup_sparse_entry && + rm sparse_entry && + test_must_fail git add sparse_entry 2>stderr && + test_cmp error_and_hint stderr && + test_sparse_entry_unchanged +' + +test_expect_success 'git add -A does not remove sparse entries' ' + setup_sparse_entry && + rm sparse_entry && + setup_gitignore && + git add -A 2>stderr && + test_must_be_empty stderr && + test_sparse_entry_unchanged +' + +test_expect_success 'git add . does not remove sparse entries' ' + setup_sparse_entry && + rm sparse_entry && + setup_gitignore && + test_must_fail git add . 2>stderr && + + cat sparse_error_header >expect && + echo . >>expect && + cat sparse_hint >>expect && + + test_cmp expect stderr && + test_sparse_entry_unchanged +' + +for opt in "" -f -u --ignore-removal --dry-run +do + test_expect_success "git add${opt:+ $opt} does not update sparse entries" ' + setup_sparse_entry && + echo modified >sparse_entry && + test_must_fail git add $opt sparse_entry 2>stderr && + test_cmp error_and_hint stderr && + test_sparse_entry_unchanged + ' +done + +test_expect_success 'git add --refresh does not update sparse entries' ' + setup_sparse_entry && + git ls-files --debug sparse_entry | grep mtime >before && + test-tool chmtime -60 sparse_entry && + test_must_fail git add --refresh sparse_entry 2>stderr && + test_cmp error_and_hint stderr && + git ls-files --debug sparse_entry | grep mtime >after && + test_cmp before after +' + +test_expect_success 'git add --chmod does not update sparse entries' ' + setup_sparse_entry && + test_must_fail git add --chmod=+x sparse_entry 2>stderr && + test_cmp error_and_hint stderr && + test_sparse_entry_unchanged && + ! test -x sparse_entry +' + +test_expect_success 'git add --renormalize does not update sparse entries' ' + test_config core.autocrlf false && + setup_sparse_entry "LINEONE\r\nLINETWO\r\n" && + echo "sparse_entry text=auto" >.gitattributes && + test_must_fail git add --renormalize sparse_entry 2>stderr && + test_cmp error_and_hint stderr && + test_sparse_entry_unchanged +' + +test_expect_success 'git add --dry-run --ignore-missing warn on sparse path' ' + setup_sparse_entry && + rm sparse_entry && + test_must_fail git add --dry-run --ignore-missing sparse_entry 2>stderr && + test_cmp error_and_hint stderr && + test_sparse_entry_unchanged +' + +test_expect_success 'do not advice about sparse entries when they do not match the pathspec' ' + setup_sparse_entry && + test_must_fail git add nonexistent 2>stderr && + grep "fatal: pathspec .nonexistent. did not match any files" stderr && + ! grep -F -f sparse_error_header stderr +' + +test_expect_success 'do not warn when pathspec matches dense entries' ' + setup_sparse_entry && + echo modified >sparse_entry && + >dense_entry && + git add "*_entry" 2>stderr && + test_must_be_empty stderr && + test_sparse_entry_unchanged && + git ls-files --error-unmatch dense_entry +' + +test_expect_success 'add obeys advice.updateSparsePath' ' + setup_sparse_entry && + test_must_fail git -c advice.updateSparsePath=false add sparse_entry 2>stderr && + test_cmp sparse_entry_error stderr + +' + +test_done diff --git a/t/t4034-diff-words.sh b/t/t4034-diff-words.sh index ee7721ab91..561c582d16 100755 --- a/t/t4034-diff-words.sh +++ b/t/t4034-diff-words.sh @@ -184,6 +184,11 @@ test_expect_success 'word diff with a regular expression' ' word_diff --color-words="[a-z]+" ' +test_expect_success 'word diff with zero length matches' ' + cp expect.letter-runs-are-words expect && + word_diff --color-words="[a-z${LF}]*" +' + test_expect_success 'set up a diff driver' ' git config diff.testdriver.wordRegex "[^[:space:]]" && cat <<-\EOF >.gitattributes diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index cabdf7d57a..8272d94ce6 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -525,20 +525,25 @@ test_expect_success 'strbuf_utf8_replace() not producing NUL' ' ! grep Q actual ' -# ISO strict date format -test_expect_success 'ISO and ISO-strict date formats display the same values' ' - git log --format=%ai%n%ci | - sed -e "s/ /T/; s/ //; s/..\$/:&/" >expected && +# --date=[XXX] and corresponding %a[X] %c[X] format equivalency +test_expect_success '--date=iso-strict %ad%cd is the same as %aI%cI' ' + git log --format=%ad%n%cd --date=iso-strict >expected && git log --format=%aI%n%cI >actual && test_cmp expected actual ' -test_expect_success 'short date' ' +test_expect_success '--date=short %ad%cd is the same as %as%cs' ' git log --format=%ad%n%cd --date=short >expected && git log --format=%as%n%cs >actual && test_cmp expected actual ' +test_expect_success '--date=human %ad%cd is the same as %ah%ch' ' + git log --format=%ad%n%cd --date=human >expected && + git log --format=%ah%n%ch >actual && + test_cmp expected actual +' + # get new digests (with no abbreviations) test_expect_success 'set up log decoration tests' ' head1=$(git rev-parse --verify HEAD~0) && diff --git a/t/t5300-pack-object.sh b/t/t5300-pack-object.sh index 2fc5e68250..5c5e53f0be 100755 --- a/t/t5300-pack-object.sh +++ b/t/t5300-pack-object.sh @@ -8,125 +8,91 @@ test_description='git pack-object ' . ./test-lib.sh -TRASH=$(pwd) - -test_expect_success \ - 'setup' \ - '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 && - test-tool genrandom "seed a" 2097152 > a_big && - test-tool genrandom "seed b" 2097152 > b_big && - git update-index --add a a_big b b_big c && - cat c >d && echo foo >>d && git update-index --add d && - tree=$(git write-tree) && - commit=$(git commit-tree $tree </dev/null) && { - echo $tree && - echo $commit && - git ls-tree $tree | sed -e "s/.* \\([0-9a-f]*\\) .*/\\1/" - } >obj-list && { - git diff-tree --root -p $commit && - while read object - do - t=$(git cat-file -t $object) && - git cat-file $t $object || return 1 - done <obj-list - } >expect' - -test_expect_success \ - 'pack without delta' \ - 'packname_1=$(git pack-objects --window=0 test-1 <obj-list)' - -test_expect_success \ - 'pack-objects with bogus arguments' \ - 'test_must_fail git pack-objects --window=0 test-1 blah blah <obj-list' - -rm -fr .git2 -mkdir .git2 - -test_expect_success \ - 'unpack without delta' \ - "GIT_OBJECT_DIRECTORY=.git2/objects && - export GIT_OBJECT_DIRECTORY && - git init && - git unpack-objects -n <test-1-${packname_1}.pack && - git unpack-objects <test-1-${packname_1}.pack" - -unset GIT_OBJECT_DIRECTORY -cd "$TRASH/.git2" +test_expect_success 'setup' ' + 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 && + test-tool genrandom "seed a" 2097152 >a_big && + test-tool genrandom "seed b" 2097152 >b_big && + git update-index --add a a_big b b_big c && + cat c >d && echo foo >>d && git update-index --add d && + tree=$(git write-tree) && + commit=$(git commit-tree $tree </dev/null) && + { + echo $tree && + echo $commit && + git ls-tree $tree | sed -e "s/.* \\([0-9a-f]*\\) .*/\\1/" + } >obj-list && + { + git diff-tree --root -p $commit && + while read object + do + t=$(git cat-file -t $object) && + git cat-file $t $object || return 1 + done <obj-list + } >expect +' -test_expect_success \ - 'check unpack without delta' \ - '(cd ../.git && find objects -type f -print) | - while read path - do - cmp $path ../.git/$path || { - echo $path differs. - return 1 - } - done' -cd "$TRASH" +# usage: check_deltas <stderr_from_pack_objects> <cmp_op> <nr_deltas> +# e.g.: check_deltas stderr -gt 0 +check_deltas() { + deltas=$(perl -lne '/delta (\d+)/ and print $1' "$1") && + shift && + if ! test "$deltas" "$@" + then + echo >&2 "unexpected number of deltas (compared $delta $*)" + return 1 + fi +} + +test_expect_success 'pack without delta' ' + packname_1=$(git pack-objects --progress --window=0 test-1 \ + <obj-list 2>stderr) && + check_deltas stderr = 0 +' -test_expect_success \ - 'pack with REF_DELTA' \ - 'pwd && - packname_2=$(git pack-objects test-2 <obj-list)' +test_expect_success 'pack-objects with bogus arguments' ' + test_must_fail git pack-objects --window=0 test-1 blah blah <obj-list +' -rm -fr .git2 -mkdir .git2 +check_unpack () { + test_when_finished "rm -rf git2" && + git init --bare git2 && + git -C git2 unpack-objects -n <"$1".pack && + git -C git2 unpack-objects <"$1".pack && + (cd .git && find objects -type f -print) | + while read path + do + cmp git2/$path .git/$path || { + echo $path differs. + return 1 + } + done +} + +test_expect_success 'unpack without delta' ' + check_unpack test-1-${packname_1} +' -test_expect_success \ - 'unpack with REF_DELTA' \ - 'GIT_OBJECT_DIRECTORY=.git2/objects && - export GIT_OBJECT_DIRECTORY && - git init && - git unpack-objects -n <test-2-${packname_2}.pack && - git unpack-objects <test-2-${packname_2}.pack' - -unset GIT_OBJECT_DIRECTORY -cd "$TRASH/.git2" -test_expect_success \ - 'check unpack with REF_DELTA' \ - '(cd ../.git && find objects -type f -print) | - while read path - do - cmp $path ../.git/$path || { - echo $path differs. - return 1 - } - done' -cd "$TRASH" +test_expect_success 'pack with REF_DELTA' ' + packname_2=$(git pack-objects --progress test-2 <obj-list 2>stderr) && + check_deltas stderr -gt 0 +' -test_expect_success \ - 'pack with OFS_DELTA' \ - 'pwd && - packname_3=$(git pack-objects --delta-base-offset test-3 <obj-list)' +test_expect_success 'unpack with REF_DELTA' ' + check_unpack test-2-${packname_2} +' -rm -fr .git2 -mkdir .git2 +test_expect_success 'pack with OFS_DELTA' ' + packname_3=$(git pack-objects --progress --delta-base-offset test-3 \ + <obj-list 2>stderr) && + check_deltas stderr -gt 0 +' -test_expect_success \ - 'unpack with OFS_DELTA' \ - 'GIT_OBJECT_DIRECTORY=.git2/objects && - export GIT_OBJECT_DIRECTORY && - git init && - git unpack-objects -n <test-3-${packname_3}.pack && - git unpack-objects <test-3-${packname_3}.pack' - -unset GIT_OBJECT_DIRECTORY -cd "$TRASH/.git2" -test_expect_success \ - 'check unpack with OFS_DELTA' \ - '(cd ../.git && find objects -type f -print) | - while read path - do - cmp $path ../.git/$path || { - echo $path differs. - return 1 - } - done' -cd "$TRASH" +test_expect_success 'unpack with OFS_DELTA' ' + check_unpack test-3-${packname_3} +' test_expect_success 'compare delta flavors' ' perl -e '\'' @@ -135,55 +101,33 @@ test_expect_success 'compare delta flavors' ' '\'' test-2-$packname_2.pack test-3-$packname_3.pack ' -rm -fr .git2 -mkdir .git2 +check_use_objects () { + test_when_finished "rm -rf git2" && + git init --bare git2 && + cp "$1".pack "$1".idx git2/objects/pack && + ( + cd git2 && + git diff-tree --root -p $commit && + while read object + do + t=$(git cat-file -t $object) && + git cat-file $t $object || exit 1 + done + ) <obj-list >current && + cmp expect current +} -test_expect_success \ - 'use packed objects' \ - 'GIT_OBJECT_DIRECTORY=.git2/objects && - export GIT_OBJECT_DIRECTORY && - git init && - cp test-1-${packname_1}.pack test-1-${packname_1}.idx .git2/objects/pack && { - git diff-tree --root -p $commit && - while read object - do - t=$(git cat-file -t $object) && - git cat-file $t $object || return 1 - done <obj-list - } >current && - cmp expect current' +test_expect_success 'use packed objects' ' + check_use_objects test-1-${packname_1} +' -test_expect_success \ - 'use packed deltified (REF_DELTA) objects' \ - 'GIT_OBJECT_DIRECTORY=.git2/objects && - export GIT_OBJECT_DIRECTORY && - rm -f .git2/objects/pack/test-* && - cp test-2-${packname_2}.pack test-2-${packname_2}.idx .git2/objects/pack && { - git diff-tree --root -p $commit && - while read object - do - t=$(git cat-file -t $object) && - git cat-file $t $object || return 1 - done <obj-list - } >current && - cmp expect current' +test_expect_success 'use packed deltified (REF_DELTA) objects' ' + check_use_objects test-2-${packname_2} +' -test_expect_success \ - 'use packed deltified (OFS_DELTA) objects' \ - 'GIT_OBJECT_DIRECTORY=.git2/objects && - export GIT_OBJECT_DIRECTORY && - rm -f .git2/objects/pack/test-* && - cp test-3-${packname_3}.pack test-3-${packname_3}.idx .git2/objects/pack && { - git diff-tree --root -p $commit && - while read object - do - t=$(git cat-file -t $object) && - git cat-file $t $object || return 1 - done <obj-list - } >current && - cmp expect current' - -unset GIT_OBJECT_DIRECTORY +test_expect_success 'use packed deltified (OFS_DELTA) objects' ' + check_use_objects test-3-${packname_3} +' test_expect_success 'survive missing objects/pack directory' ' ( @@ -669,4 +613,9 @@ test_expect_success '--stdin-packs with broken links' ' ) ' +test_expect_success 'negative window clamps to 0' ' + git pack-objects --progress --window=-1 neg-window <obj-list 2>stderr && + check_deltas stderr = 0 +' + test_done diff --git a/t/t5304-prune.sh b/t/t5304-prune.sh index b447ce56a9..3475b06aeb 100755 --- a/t/t5304-prune.sh +++ b/t/t5304-prune.sh @@ -352,4 +352,20 @@ test_expect_success 'trivial prune with bitmaps enabled' ' test_must_fail git cat-file -e $blob ' +test_expect_success 'old reachable-from-recent retained with bitmaps' ' + git repack -adb && + to_drop=$(echo bitmap-from-recent-1 | git hash-object -w --stdin) && + test-tool chmtime -86400 .git/objects/$(test_oid_to_path $to_drop) && + to_save=$(echo bitmap-from-recent-2 | git hash-object -w --stdin) && + test-tool chmtime -86400 .git/objects/$(test_oid_to_path $to_save) && + tree=$(printf "100644 blob $to_save\tfile\n" | git mktree) && + test-tool chmtime -86400 .git/objects/$(test_oid_to_path $tree) && + commit=$(echo foo | git commit-tree $tree) && + git prune --expire=12.hours.ago && + git cat-file -e $commit && + git cat-file -e $tree && + git cat-file -e $to_save && + test_must_fail git cat-file -e $to_drop +' + test_done diff --git a/t/t5316-pack-delta-depth.sh b/t/t5316-pack-delta-depth.sh index a8c1bc0f66..759169d074 100755 --- a/t/t5316-pack-delta-depth.sh +++ b/t/t5316-pack-delta-depth.sh @@ -69,6 +69,7 @@ test_expect_success 'create series of packs' ' max_chain() { git index-pack --verify-stat-only "$1" >output && perl -lne ' + BEGIN { $len = 0 } /chain length = (\d+)/ and $len = $1; END { print $len } ' output @@ -94,4 +95,18 @@ test_expect_success '--depth limits depth' ' test_cmp expect actual ' +test_expect_success '--depth=0 disables deltas' ' + pack=$(git pack-objects --all --depth=0 </dev/null pack) && + echo 0 >expect && + max_chain pack-$pack.pack >actual && + test_cmp expect actual +' + +test_expect_success 'negative depth disables deltas' ' + pack=$(git pack-objects --all --depth=-1 </dev/null pack) && + echo 0 >expect && + max_chain pack-$pack.pack >actual && + test_cmp expect actual +' + test_done diff --git a/t/t5601-clone.sh b/t/t5601-clone.sh index 329ae599fd..c0688467e7 100755 --- a/t/t5601-clone.sh +++ b/t/t5601-clone.sh @@ -762,7 +762,7 @@ test_expect_success 'partial clone using HTTP' ' test_expect_success 'reject cloning shallow repository using HTTP' ' test_when_finished "rm -rf repo" && git clone --bare --no-local --depth=1 src "$HTTPD_DOCUMENT_ROOT_PATH/repo.git" && - test_must_fail git clone --reject-shallow $HTTPD_URL/smart/repo.git repo 2>err && + test_must_fail git -c protocol.version=2 clone --reject-shallow $HTTPD_URL/smart/repo.git repo 2>err && test_i18ngrep -e "source repository is shallow, reject to clone." err && git clone --no-reject-shallow $HTTPD_URL/smart/repo.git repo diff --git a/t/t5616-partial-clone.sh b/t/t5616-partial-clone.sh index 5cb415386e..cf3e82bdf5 100755 --- a/t/t5616-partial-clone.sh +++ b/t/t5616-partial-clone.sh @@ -548,6 +548,14 @@ test_expect_success 'fetch from a partial clone, protocol v2' ' grep "version 2" trace ' +test_expect_success 'repack does not loosen promisor objects' ' + rm -rf client trace && + git clone --bare --filter=blob:none "file://$(pwd)/srv.bare" client && + test_when_finished "rm -rf client trace" && + GIT_TRACE2_PERF="$(pwd)/trace" git -C client repack -A -d && + grep "loosen_unused_packed_objects/loosened:0" trace +' + . "$TEST_DIRECTORY"/lib-httpd.sh start_httpd diff --git a/t/t5701-git-serve.sh b/t/t5701-git-serve.sh index 509f379d49..73e74a9c54 100755 --- a/t/t5701-git-serve.sh +++ b/t/t5701-git-serve.sh @@ -19,6 +19,7 @@ test_expect_success 'test capability advertisement' ' fetch=shallow server-option object-format=$(test_oid algo) + object-info 0000 EOF @@ -240,4 +241,29 @@ test_expect_success 'unexpected lines are not allowed in fetch request' ' grep "unexpected line: .this-is-not-a-command." err ' +# Test the basics of object-info +# +test_expect_success 'basics of object-info' ' + test-tool pkt-line pack >in <<-EOF && + command=object-info + object-format=$(test_oid algo) + 0001 + size + oid $(git rev-parse two:two.t) + oid $(git rev-parse two:two.t) + 0000 + EOF + + cat >expect <<-EOF && + size + $(git rev-parse two:two.t) $(wc -c <two.t | xargs) + $(git rev-parse two:two.t) $(wc -c <two.t | xargs) + 0000 + EOF + + test-tool serve-v2 --stateless-rpc <in >out && + test-tool pkt-line unpack <out >actual && + test_cmp expect actual +' + test_done diff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh index 32bb66e1ed..a1baf4e451 100755 --- a/t/t6030-bisect-porcelain.sh +++ b/t/t6030-bisect-porcelain.sh @@ -922,6 +922,17 @@ test_expect_success 'bisect start takes options and revs in any order' ' test_cmp expected actual ' +# Bisect is started with --term-new and --term-old arguments, +# then skip. The HEAD should be changed. +test_expect_success 'bisect skip works with --term*' ' + git bisect reset && + git bisect start --term-new=fixed --term-old=unfixed HEAD $HASH1 && + hash_skipped_from=$(git rev-parse --verify HEAD) && + git bisect skip && + hash_skipped_to=$(git rev-parse --verify HEAD) && + test "$hash_skipped_from" != "$hash_skipped_to" +' + test_expect_success 'git bisect reset cleans bisection state properly' ' git bisect reset && git bisect start && diff --git a/t/t6112-rev-list-filters-objects.sh b/t/t6112-rev-list-filters-objects.sh index 31457d13b9..4ade105db3 100755 --- a/t/t6112-rev-list-filters-objects.sh +++ b/t/t6112-rev-list-filters-objects.sh @@ -159,6 +159,78 @@ test_expect_success 'verify blob:limit=1m' ' test_must_be_empty observed ' +# Test object:type=<type> filter. + +test_expect_success 'setup object-type' ' + test_create_repo object-type && + test_commit --no-tag -C object-type message blob && + git -C object-type tag tag -m tag-message +' + +test_expect_success 'verify object:type= fails with invalid type' ' + test_must_fail git -C object-type rev-list --objects --filter=object:type= HEAD && + test_must_fail git -C object-type rev-list --objects --filter=object:type=invalid HEAD +' + +test_expect_success 'verify object:type=blob prints blob and commit' ' + git -C object-type rev-parse HEAD >expected && + printf "%s blob\n" $(git -C object-type rev-parse HEAD:blob) >>expected && + git -C object-type rev-list --objects --filter=object:type=blob HEAD >actual && + test_cmp expected actual +' + +test_expect_success 'verify object:type=tree prints tree and commit' ' + ( + git -C object-type rev-parse HEAD && + printf "%s \n" $(git -C object-type rev-parse HEAD^{tree}) + ) >expected && + git -C object-type rev-list --objects --filter=object:type=tree HEAD >actual && + test_cmp expected actual +' + +test_expect_success 'verify object:type=commit prints commit' ' + git -C object-type rev-parse HEAD >expected && + git -C object-type rev-list --objects --filter=object:type=commit HEAD >actual && + test_cmp expected actual +' + +test_expect_success 'verify object:type=tag prints tag' ' + ( + git -C object-type rev-parse HEAD && + printf "%s tag\n" $(git -C object-type rev-parse tag) + ) >expected && + git -C object-type rev-list --objects --filter=object:type=tag tag >actual && + test_cmp expected actual +' + +test_expect_success 'verify object:type=blob prints only blob with --filter-provided-objects' ' + printf "%s blob\n" $(git -C object-type rev-parse HEAD:blob) >expected && + git -C object-type rev-list --objects \ + --filter=object:type=blob --filter-provided-objects HEAD >actual && + test_cmp expected actual +' + +test_expect_success 'verify object:type=tree prints only tree with --filter-provided-objects' ' + printf "%s \n" $(git -C object-type rev-parse HEAD^{tree}) >expected && + git -C object-type rev-list --objects \ + --filter=object:type=tree HEAD --filter-provided-objects >actual && + test_cmp expected actual +' + +test_expect_success 'verify object:type=commit prints only commit with --filter-provided-objects' ' + git -C object-type rev-parse HEAD >expected && + git -C object-type rev-list --objects \ + --filter=object:type=commit --filter-provided-objects HEAD >actual && + test_cmp expected actual +' + +test_expect_success 'verify object:type=tag prints only tag with --filter-provided-objects' ' + printf "%s tag\n" $(git -C object-type rev-parse tag) >expected && + git -C object-type rev-list --objects \ + --filter=object:type=tag --filter-provided-objects tag >actual && + test_cmp expected actual +' + # Test sparse:path=<path> filter. # !!!! # NOTE: sparse:path filter support has been dropped for security reasons, diff --git a/t/t6113-rev-list-bitmap-filters.sh b/t/t6113-rev-list-bitmap-filters.sh index 3f889949ca..4d8e09167e 100755 --- a/t/t6113-rev-list-bitmap-filters.sh +++ b/t/t6113-rev-list-bitmap-filters.sh @@ -10,7 +10,8 @@ test_expect_success 'set up bitmapped repo' ' test_commit much-larger-blob-one && git repack -adb && test_commit two && - test_commit much-larger-blob-two + test_commit much-larger-blob-two && + git tag tag ' test_expect_success 'filters fallback to non-bitmap traversal' ' @@ -75,4 +76,69 @@ test_expect_success 'tree:1 filter' ' test_cmp expect actual ' +test_expect_success 'object:type filter' ' + git rev-list --objects --filter=object:type=tag tag >expect && + git rev-list --use-bitmap-index \ + --objects --filter=object:type=tag tag >actual && + test_cmp expect actual && + + git rev-list --objects --filter=object:type=commit tag >expect && + git rev-list --use-bitmap-index \ + --objects --filter=object:type=commit tag >actual && + test_bitmap_traversal expect actual && + + git rev-list --objects --filter=object:type=tree tag >expect && + git rev-list --use-bitmap-index \ + --objects --filter=object:type=tree tag >actual && + test_bitmap_traversal expect actual && + + git rev-list --objects --filter=object:type=blob tag >expect && + git rev-list --use-bitmap-index \ + --objects --filter=object:type=blob tag >actual && + test_bitmap_traversal expect actual +' + +test_expect_success 'object:type filter with --filter-provided-objects' ' + git rev-list --objects --filter-provided-objects --filter=object:type=tag tag >expect && + git rev-list --use-bitmap-index \ + --objects --filter-provided-objects --filter=object:type=tag tag >actual && + test_cmp expect actual && + + git rev-list --objects --filter-provided-objects --filter=object:type=commit tag >expect && + git rev-list --use-bitmap-index \ + --objects --filter-provided-objects --filter=object:type=commit tag >actual && + test_bitmap_traversal expect actual && + + git rev-list --objects --filter-provided-objects --filter=object:type=tree tag >expect && + git rev-list --use-bitmap-index \ + --objects --filter-provided-objects --filter=object:type=tree tag >actual && + test_bitmap_traversal expect actual && + + git rev-list --objects --filter-provided-objects --filter=object:type=blob tag >expect && + git rev-list --use-bitmap-index \ + --objects --filter-provided-objects --filter=object:type=blob tag >actual && + test_bitmap_traversal expect actual +' + +test_expect_success 'combine filter' ' + git rev-list --objects --filter=blob:limit=1000 --filter=object:type=blob tag >expect && + git rev-list --use-bitmap-index \ + --objects --filter=blob:limit=1000 --filter=object:type=blob tag >actual && + test_bitmap_traversal expect actual +' + +test_expect_success 'combine filter with --filter-provided-objects' ' + git rev-list --objects --filter-provided-objects --filter=blob:limit=1000 --filter=object:type=blob tag >expect && + git rev-list --use-bitmap-index \ + --objects --filter-provided-objects --filter=blob:limit=1000 --filter=object:type=blob tag >actual && + test_bitmap_traversal expect actual && + + git cat-file --batch-check="%(objecttype) %(objectsize)" <actual >objects && + while read objecttype objectsize + do + test "$objecttype" = blob || return 1 + test "$objectsize" -le 1000 || return 1 + done <objects +' + test_done diff --git a/t/t6501-freshen-objects.sh b/t/t6501-freshen-objects.sh index 75210f012b..10662456ae 100755 --- a/t/t6501-freshen-objects.sh +++ b/t/t6501-freshen-objects.sh @@ -43,15 +43,25 @@ commit () { } maybe_repack () { - if test -n "$repack"; then + case "$title" in + loose) + : skip repack + ;; + repack) git repack -ad - fi + ;; + bitmap) + git repack -adb + ;; + *) + echo >&2 "unknown test type in maybe_repack" + return 1 + ;; + esac } -for repack in '' true; do - title=${repack:+repack} - title=${title:-loose} - +for title in loose repack bitmap +do test_expect_success "make repo completely empty ($title)" ' rm -rf .git && git init diff --git a/t/t7011-skip-worktree-reading.sh b/t/t7011-skip-worktree-reading.sh index 26852586ac..1761a2b1b9 100755 --- a/t/t7011-skip-worktree-reading.sh +++ b/t/t7011-skip-worktree-reading.sh @@ -132,11 +132,6 @@ test_expect_success 'diff-files does not examine skip-worktree dirty entries' ' test -z "$(git diff-files -- one)" ' -test_expect_success 'git-rm succeeds on skip-worktree absent entries' ' - setup_absent && - git rm 1 -' - test_expect_success 'commit on skip-worktree absent entries' ' git reset && setup_absent && diff --git a/t/t7012-skip-worktree-writing.sh b/t/t7012-skip-worktree-writing.sh index f2a8e76511..a1080b94e3 100755 --- a/t/t7012-skip-worktree-writing.sh +++ b/t/t7012-skip-worktree-writing.sh @@ -60,13 +60,6 @@ setup_absent() { git update-index --skip-worktree 1 } -test_absent() { - echo "100644 $EMPTY_BLOB 0 1" > expected && - git ls-files --stage 1 > result && - test_cmp expected result && - test ! -f 1 -} - setup_dirty() { git update-index --force-remove 1 && echo dirty > 1 && @@ -100,18 +93,6 @@ test_expect_success 'index setup' ' test_cmp expected result ' -test_expect_success 'git-add ignores worktree content' ' - setup_absent && - git add 1 && - test_absent -' - -test_expect_success 'git-add ignores worktree content' ' - setup_dirty && - git add 1 && - test_dirty -' - test_expect_success 'git-rm fails if worktree is dirty' ' setup_dirty && test_must_fail git rm 1 && diff --git a/t/t7406-submodule-update.sh b/t/t7406-submodule-update.sh index ff3ba5422e..f4f61fe554 100755 --- a/t/t7406-submodule-update.sh +++ b/t/t7406-submodule-update.sh @@ -1037,4 +1037,28 @@ test_expect_success 'submodule update --quiet passes quietness to merge/rebase' ) ' +test_expect_success 'submodule update --quiet passes quietness to fetch with a shallow clone' ' + test_when_finished "rm -rf super4 super5 super6" && + git clone . super4 && + (cd super4 && + git submodule add --quiet file://"$TRASH_DIRECTORY"/submodule submodule3 && + git commit -am "setup submodule3" + ) && + (cd submodule && + test_commit line6 file + ) && + git clone super4 super5 && + (cd super5 && + git submodule update --quiet --init --depth=1 submodule3 >out 2>err && + test_must_be_empty out && + test_must_be_empty err + ) && + git clone super4 super6 && + (cd super6 && + git submodule update --init --depth=1 submodule3 >out 2>err && + test_file_not_empty out && + test_file_not_empty err + ) +' + test_done diff --git a/t/t7415-submodule-names.sh b/t/t7450-bad-git-dotfiles.sh index f70368bc2e..41706c1c9f 100755 --- a/t/t7415-submodule-names.sh +++ b/t/t7450-bad-git-dotfiles.sh @@ -1,9 +1,16 @@ #!/bin/sh -test_description='check handling of .. in submodule names +test_description='check broken or malicious patterns in .git* files -Exercise the name-checking function on a variety of names, and then give a -real-world setup that confirms we catch this in practice. +Such as: + + - presence of .. in submodule names; + Exercise the name-checking function on a variety of names, and then give a + real-world setup that confirms we catch this in practice. + + - nested submodule names + + - symlinked .gitmodules, etc ' . ./test-lib.sh . "$TEST_DIRECTORY"/lib-pack.sh @@ -132,31 +139,84 @@ test_expect_success 'index-pack --strict works for non-repo pack' ' grep gitmodulesName output ' -test_expect_success 'fsck detects symlinked .gitmodules file' ' - git init symlink && - ( - cd symlink && - - # Make the tree directly to avoid index restrictions. - # - # Because symlinks store the target as a blob, choose - # a pathname that could be parsed as a .gitmodules file - # to trick naive non-symlink-aware checking. - tricky="[foo]bar=true" && - content=$(git hash-object -w ../.gitmodules) && - target=$(printf "$tricky" | git hash-object -w --stdin) && - { - printf "100644 blob $content\t$tricky\n" && - printf "120000 blob $target\t.gitmodules\n" - } | git mktree && - - # Check not only that we fail, but that it is due to the - # symlink detector; this grep string comes from the config - # variable name and will not be translated. - test_must_fail git fsck 2>output && - test_i18ngrep gitmodulesSymlink output - ) -' +check_dotx_symlink () { + fsck_must_fail=test_must_fail + fsck_prefix=error + refuse_index=t + case "$1" in + --warning) + fsck_must_fail= + fsck_prefix=warning + refuse_index= + shift + ;; + esac + + name=$1 + type=$2 + path=$3 + dir=symlink-$name-$type + + test_expect_success "set up repo with symlinked $name ($type)" ' + git init $dir && + ( + cd $dir && + + # Make the tree directly to avoid index restrictions. + # + # Because symlinks store the target as a blob, choose + # a pathname that could be parsed as a .gitmodules file + # to trick naive non-symlink-aware checking. + tricky="[foo]bar=true" && + content=$(git hash-object -w ../.gitmodules) && + target=$(printf "$tricky" | git hash-object -w --stdin) && + { + printf "100644 blob $content\t$tricky\n" && + printf "120000 blob $target\t$path\n" + } >bad-tree + ) && + tree=$(git -C $dir mktree <$dir/bad-tree) + ' + + test_expect_success "fsck detects symlinked $name ($type)" ' + ( + cd $dir && + + # Check not only that we fail, but that it is due to the + # symlink detector + $fsck_must_fail git fsck 2>output && + grep "$fsck_prefix.*tree $tree: ${name}Symlink" output + ) + ' + + test -n "$refuse_index" && + test_expect_success "refuse to load symlinked $name into index ($type)" ' + test_must_fail \ + git -C $dir \ + -c core.protectntfs \ + -c core.protecthfs \ + read-tree $tree 2>err && + grep "invalid path.*$name" err && + git -C $dir ls-files -s >out && + test_must_be_empty out + ' +} + +check_dotx_symlink gitmodules vanilla .gitmodules +check_dotx_symlink gitmodules ntfs ".gitmodules ." +check_dotx_symlink gitmodules hfs ".${u200c}gitmodules" + +check_dotx_symlink --warning gitattributes vanilla .gitattributes +check_dotx_symlink --warning gitattributes ntfs ".gitattributes ." +check_dotx_symlink --warning gitattributes hfs ".${u200c}gitattributes" + +check_dotx_symlink --warning gitignore vanilla .gitignore +check_dotx_symlink --warning gitignore ntfs ".gitignore ." +check_dotx_symlink --warning gitignore hfs ".${u200c}gitignore" + +check_dotx_symlink --warning mailmap vanilla .mailmap +check_dotx_symlink --warning mailmap ntfs ".mailmap ." +check_dotx_symlink --warning mailmap hfs ".${u200c}mailmap" test_expect_success 'fsck detects non-blob .gitmodules' ' git init non-blob && @@ -191,7 +251,7 @@ test_expect_success 'fsck detects corrupt .gitmodules' ' ) ' -test_expect_success MINGW 'prevent git~1 squatting on Windows' ' +test_expect_success WINDOWS 'prevent git~1 squatting on Windows' ' git init squatting && ( cd squatting && @@ -219,10 +279,13 @@ test_expect_success MINGW 'prevent git~1 squatting on Windows' ' test_tick && git -c core.protectNTFS=false commit -m "module" ) && - test_must_fail git -c core.protectNTFS=false \ - clone --recurse-submodules squatting squatting-clone 2>err && - test_i18ngrep -e "directory not empty" -e "not an empty directory" err && - ! grep gitdir squatting-clone/d/a/git~2 + if test_have_prereq MINGW + then + test_must_fail git -c core.protectNTFS=false \ + clone --recurse-submodules squatting squatting-clone 2>err && + test_i18ngrep -e "directory not empty" -e "not an empty directory" err && + ! grep gitdir squatting-clone/d/a/git~2 + fi ' test_expect_success 'git dirs of sibling submodules must not be nested' ' diff --git a/t/t7513-interpret-trailers.sh b/t/t7513-interpret-trailers.sh index 6602790b5f..04885d0a5e 100755 --- a/t/t7513-interpret-trailers.sh +++ b/t/t7513-interpret-trailers.sh @@ -51,6 +51,69 @@ test_expect_success 'setup' ' EOF ' +test_expect_success 'with cmd' ' + test_when_finished "git config --remove-section trailer.bug" && + git config trailer.bug.key "Bug-maker: " && + git config trailer.bug.ifExists "add" && + git config trailer.bug.cmd "echo \"maybe is\"" && + cat >expected2 <<-EOF && + + Bug-maker: maybe is him + Bug-maker: maybe is me + EOF + git interpret-trailers --trailer "bug: him" --trailer "bug:me" \ + >actual2 && + test_cmp expected2 actual2 +' + +test_expect_success 'with cmd and $1' ' + test_when_finished "git config --remove-section trailer.bug" && + git config trailer.bug.key "Bug-maker: " && + git config trailer.bug.ifExists "add" && + git config trailer.bug.cmd "echo \"\$1\" is" && + cat >expected2 <<-EOF && + + Bug-maker: him is him + Bug-maker: me is me + EOF + git interpret-trailers --trailer "bug: him" --trailer "bug:me" \ + >actual2 && + test_cmp expected2 actual2 +' + +test_expect_success 'with cmd and $1 with sh -c' ' + test_when_finished "git config --remove-section trailer.bug" && + git config trailer.bug.key "Bug-maker: " && + git config trailer.bug.ifExists "replace" && + git config trailer.bug.cmd "sh -c \"echo who is \"\$1\"\"" && + cat >expected2 <<-EOF && + + Bug-maker: who is me + EOF + git interpret-trailers --trailer "bug: him" --trailer "bug:me" \ + >actual2 && + test_cmp expected2 actual2 +' + +test_expect_success 'with cmd and $1 with shell script' ' + test_when_finished "git config --remove-section trailer.bug" && + git config trailer.bug.key "Bug-maker: " && + git config trailer.bug.ifExists "replace" && + git config trailer.bug.cmd "./echoscript" && + cat >expected2 <<-EOF && + + Bug-maker: who is me + EOF + cat >echoscript <<-EOF && + #!/bin/sh + echo who is "\$1" + EOF + chmod +x echoscript && + git interpret-trailers --trailer "bug: him" --trailer "bug:me" \ + >actual2 && + test_cmp expected2 actual2 +' + test_expect_success 'without config' ' sed -e "s/ Z\$/ /" >expected <<-\EOF && @@ -1274,6 +1337,27 @@ test_expect_success 'setup a commit' ' git commit -m "Add file a.txt" ' +test_expect_success 'cmd takes precedence over command' ' + test_when_finished "git config --unset trailer.fix.cmd" && + git config trailer.fix.ifExists "replace" && + git config trailer.fix.cmd "test -n \"\$1\" && git log -1 --oneline --format=\"%h (%aN)\" \ + --abbrev-commit --abbrev=14 \"\$1\" || true" && + git config trailer.fix.command "git log -1 --oneline --format=\"%h (%s)\" \ + --abbrev-commit --abbrev=14 \$ARG" && + FIXED=$(git log -1 --oneline --format="%h (%aN)" --abbrev-commit --abbrev=14 HEAD) && + cat complex_message_body >expected2 && + sed -e "s/ Z\$/ /" >>expected2 <<-EOF && + Fixes: $FIXED + Acked-by= Z + Reviewed-by: + Signed-off-by: Z + Signed-off-by: A U Thor <author@example.com> + EOF + git interpret-trailers --trailer "review:" --trailer "fix=HEAD" \ + <complex_message >actual2 && + test_cmp expected2 actual2 +' + test_expect_success 'with command using $ARG' ' git config trailer.fix.ifExists "replace" && git config trailer.fix.command "git log -1 --oneline --format=\"%h (%s)\" --abbrev-commit --abbrev=14 \$ARG" && diff --git a/t/t9117-git-svn-init-clone.sh b/t/t9117-git-svn-init-clone.sh index 044f65e916..62de819a44 100755 --- a/t/t9117-git-svn-init-clone.sh +++ b/t/t9117-git-svn-init-clone.sh @@ -7,12 +7,6 @@ test_description='git svn init/clone tests' . ./lib-git-svn.sh -# setup, run inside tmp so we don't have any conflicts with $svnrepo -set -e -rm -r .git -mkdir tmp -cd tmp - test_expect_success 'setup svnrepo' ' mkdir project project/trunk project/branches project/tags && echo foo > project/trunk/foo && diff --git a/t/t9148-git-svn-propset.sh b/t/t9148-git-svn-propset.sh index 102639090c..aebb28995e 100755 --- a/t/t9148-git-svn-propset.sh +++ b/t/t9148-git-svn-propset.sh @@ -7,19 +7,22 @@ test_description='git svn propset tests' . ./lib-git-svn.sh -foo_subdir2="subdir/subdir2/foo_subdir2" +test_expect_success 'setup propset via import' ' + test_when_finished "rm -rf import" && -set -e -mkdir import && -(set -e ; cd import - mkdir subdir - mkdir subdir/subdir2 - touch foo # for 'add props top level' - touch subdir/foo_subdir # for 'add props relative' - touch "$foo_subdir2" # for 'add props subdir' - svn_cmd import -m 'import for git svn' . "$svnrepo" >/dev/null -) -rm -rf import + foo_subdir2="subdir/subdir2/foo_subdir2" && + mkdir -p import/subdir/subdir2 && + ( + cd import && + # for "add props top level" + >foo && + # for "add props relative" + >subdir/foo_subdir && + # for "add props subdir" + >"$foo_subdir2" && + svn_cmd import -m "import for git svn" . "$svnrepo" + ) +' test_expect_success 'initialize git svn' ' git svn init "$svnrepo" diff --git a/t/t9801-git-p4-branch.sh b/t/t9801-git-p4-branch.sh index ff94c3f17d..50a6f8bad5 100755 --- a/t/t9801-git-p4-branch.sh +++ b/t/t9801-git-p4-branch.sh @@ -294,11 +294,13 @@ test_expect_success 'git p4 clone complex branches' ' test_path_is_file file3 && grep update file2 && git reset --hard p4/depot/branch4 && + git diff-tree --quiet HEAD && test_path_is_file file1 && test_path_is_file file2 && test_path_is_missing file3 && ! grep update file2 && git reset --hard p4/depot/branch5 && + git diff-tree --quiet HEAD && test_path_is_file file1 && test_path_is_file file2 && test_path_is_file file3 && diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index 4d732d6d4f..cb057ef161 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -1879,6 +1879,7 @@ test_expect_success '__git_find_on_cmdline - single match' ' ( words=(git command --opt list) && cword=${#words[@]} && + __git_cmd_idx=1 && __git_find_on_cmdline "add list remove" >actual ) && test_cmp expect actual @@ -1889,6 +1890,7 @@ test_expect_success '__git_find_on_cmdline - multiple matches' ' ( words=(git command -o --opt remove list add) && cword=${#words[@]} && + __git_cmd_idx=1 && __git_find_on_cmdline "add list remove" >actual ) && test_cmp expect actual @@ -1898,6 +1900,7 @@ test_expect_success '__git_find_on_cmdline - no match' ' ( words=(git command --opt branch) && cword=${#words[@]} && + __git_cmd_idx=1 && __git_find_on_cmdline "add list remove" >actual ) && test_must_be_empty actual @@ -1908,6 +1911,7 @@ test_expect_success '__git_find_on_cmdline - single match with index' ' ( words=(git command --opt list) && cword=${#words[@]} && + __git_cmd_idx=1 && __git_find_on_cmdline --show-idx "add list remove" >actual ) && test_cmp expect actual @@ -1918,6 +1922,7 @@ test_expect_success '__git_find_on_cmdline - multiple matches with index' ' ( words=(git command -o --opt remove list add) && cword=${#words[@]} && + __git_cmd_idx=1 && __git_find_on_cmdline --show-idx "add list remove" >actual ) && test_cmp expect actual @@ -1927,11 +1932,23 @@ test_expect_success '__git_find_on_cmdline - no match with index' ' ( words=(git command --opt branch) && cword=${#words[@]} && + __git_cmd_idx=1 && __git_find_on_cmdline --show-idx "add list remove" >actual ) && test_must_be_empty actual ' +test_expect_success '__git_find_on_cmdline - ignores matches before command with index' ' + echo "6 remove" >expect && + ( + words=(git -C remove command -o --opt remove list add) && + cword=${#words[@]} && + __git_cmd_idx=3 && + __git_find_on_cmdline --show-idx "add list remove" >actual + ) && + test_cmp expect actual +' + test_expect_success '__git_get_config_variables' ' cat >expect <<-EOF && name-1 @@ -2275,6 +2292,7 @@ do ( words=(git push '$flag' other ma) && cword=${#words[@]} cur=${words[cword-1]} && + __git_cmd_idx=1 && __git_complete_remote_or_refspec && print_comp ) && @@ -2288,6 +2306,7 @@ do ( words=(git push other '$flag' ma) && cword=${#words[@]} cur=${words[cword-1]} && + __git_cmd_idx=1 && __git_complete_remote_or_refspec && print_comp ) && diff --git a/t/test-lib.sh b/t/test-lib.sh index 3dec266221..adaa2db601 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -1459,6 +1459,7 @@ case $uname_s in test_set_prereq NATIVE_CRLF test_set_prereq SED_STRIPS_CR test_set_prereq GREP_STRIPS_CR + test_set_prereq WINDOWS GIT_TEST_CMP=mingw_test_cmp ;; *CYGWIN*) @@ -1467,6 +1468,7 @@ case $uname_s in test_set_prereq CYGWIN test_set_prereq SED_STRIPS_CR test_set_prereq GREP_STRIPS_CR + test_set_prereq WINDOWS ;; *) test_set_prereq POSIXPERM |