Merge branch 'hn/prep-tests-for-reftable'

Preliminary clean-up of tests before the main reftable changes
hits the codebase.

* hn/prep-tests-for-reftable: (22 commits)
  t1415: set REFFILES for test specific to storage format
  t4202: mark bogus head hash test with REFFILES
  t7003: check reflog existence only for REFFILES
  t7900: stop checking for loose refs
  t1404: mark tests that muck with .git directly as REFFILES.
  t2017: mark --orphan/logAllRefUpdates=false test as REFFILES
  t1414: mark corruption test with REFFILES
  t1407: require REFFILES for for_each_reflog test
  test-lib: provide test prereq REFFILES
  t5304: use "reflog expire --all" to clear the reflog
  t5304: restyle: trim empty lines, drop ':' before >
  t7003: use rev-parse rather than FS inspection
  t5000: inspect HEAD using git-rev-parse
  t5000: reformat indentation to the latest fashion
  t1301: fix typo in error message
  t1413: use tar to save and restore entire .git directory
  t1401-symbolic-ref: avoid direct filesystem access
  t1401: use tar to snapshot and restore repo state
  t5601: read HEAD using rev-parse
  t9300: check ref existence using test-helper rather than a file system check
  ...
maint
Junio C Hamano 2021-07-13 16:52:50 -07:00
commit c9780bb2ca
18 changed files with 170 additions and 159 deletions

View File

@ -1126,6 +1126,12 @@ use these, and "test_set_prereq" for how to define your own.


Git wasn't compiled with NO_PTHREADS=YesPlease. Git wasn't compiled with NO_PTHREADS=YesPlease.


- REFFILES

Test is specific to packed/loose ref storage, and should be
disabled for other ref storage backends


Tips for Writing Tests Tips for Writing Tests
---------------------- ----------------------



View File

@ -118,7 +118,7 @@ static int cmd_for_each_ref(struct ref_store *refs, const char **argv)


static int cmd_resolve_ref(struct ref_store *refs, const char **argv) static int cmd_resolve_ref(struct ref_store *refs, const char **argv)
{ {
struct object_id oid; struct object_id oid = *null_oid();
const char *refname = notnull(*argv++, "refname"); const char *refname = notnull(*argv++, "refname");
int resolve_flags = arg_flags(*argv++, "resolve-flags"); int resolve_flags = arg_flags(*argv++, "resolve-flags");
int flags; int flags;

View File

@ -124,7 +124,7 @@ test_expect_success POSIXPERM 'git reflog expire honors core.sharedRepository' '
: happy : happy
;; ;;
*) *)
echo Ooops, .git/logs/refs/heads/main is not 0662 [$actual] echo Ooops, .git/logs/refs/heads/main is not 066x [$actual]
false false
;; ;;
esac esac

View File

@ -7,17 +7,19 @@ test_description='basic symbolic-ref tests'
# the git repo, meaning that further tests will operate on # the git repo, meaning that further tests will operate on
# the surrounding git repo instead of the trash directory. # the surrounding git repo instead of the trash directory.
reset_to_sane() { reset_to_sane() {
echo ref: refs/heads/foo >.git/HEAD rm -rf .git &&
"$TAR" xf .git.tar
} }


test_expect_success 'symbolic-ref writes HEAD' ' test_expect_success 'setup' '
git symbolic-ref HEAD refs/heads/foo && git symbolic-ref HEAD refs/heads/foo &&
echo ref: refs/heads/foo >expect && test_commit file &&
test_cmp expect .git/HEAD "$TAR" cf .git.tar .git/
' '


test_expect_success 'symbolic-ref reads HEAD' ' test_expect_success 'symbolic-ref read/write roundtrip' '
echo refs/heads/foo >expect && git symbolic-ref HEAD refs/heads/read-write-roundtrip &&
echo refs/heads/read-write-roundtrip >expect &&
git symbolic-ref HEAD >actual && git symbolic-ref HEAD >actual &&
test_cmp expect actual test_cmp expect actual
' '
@ -25,12 +27,13 @@ test_expect_success 'symbolic-ref reads HEAD' '
test_expect_success 'symbolic-ref refuses non-ref for HEAD' ' test_expect_success 'symbolic-ref refuses non-ref for HEAD' '
test_must_fail git symbolic-ref HEAD foo test_must_fail git symbolic-ref HEAD foo
' '

reset_to_sane reset_to_sane


test_expect_success 'symbolic-ref refuses bare sha1' ' test_expect_success 'symbolic-ref refuses bare sha1' '
echo content >file && git add file && git commit -m one &&
test_must_fail git symbolic-ref HEAD $(git rev-parse HEAD) test_must_fail git symbolic-ref HEAD $(git rev-parse HEAD)
' '

reset_to_sane reset_to_sane


test_expect_success 'HEAD cannot be removed' ' test_expect_success 'HEAD cannot be removed' '
@ -42,16 +45,16 @@ reset_to_sane
test_expect_success 'symbolic-ref can be deleted' ' test_expect_success 'symbolic-ref can be deleted' '
git symbolic-ref NOTHEAD refs/heads/foo && git symbolic-ref NOTHEAD refs/heads/foo &&
git symbolic-ref -d NOTHEAD && git symbolic-ref -d NOTHEAD &&
test_path_is_file .git/refs/heads/foo && git rev-parse refs/heads/foo &&
test_path_is_missing .git/NOTHEAD test_must_fail git symbolic-ref NOTHEAD
' '
reset_to_sane reset_to_sane


test_expect_success 'symbolic-ref can delete dangling symref' ' test_expect_success 'symbolic-ref can delete dangling symref' '
git symbolic-ref NOTHEAD refs/heads/missing && git symbolic-ref NOTHEAD refs/heads/missing &&
git symbolic-ref -d NOTHEAD && git symbolic-ref -d NOTHEAD &&
test_path_is_missing .git/refs/heads/missing && test_must_fail git rev-parse refs/heads/missing &&
test_path_is_missing .git/NOTHEAD test_must_fail git symbolic-ref NOTHEAD
' '
reset_to_sane reset_to_sane



View File

@ -189,7 +189,7 @@ test_expect_success 'one new ref is a simple prefix of another' '


' '


test_expect_success 'empty directory should not fool rev-parse' ' test_expect_success REFFILES 'empty directory should not fool rev-parse' '
prefix=refs/e-rev-parse && prefix=refs/e-rev-parse &&
git update-ref $prefix/foo $C && git update-ref $prefix/foo $C &&
git pack-refs --all && git pack-refs --all &&
@ -199,7 +199,7 @@ test_expect_success 'empty directory should not fool rev-parse' '
test_cmp expected actual test_cmp expected actual
' '


test_expect_success 'empty directory should not fool for-each-ref' ' test_expect_success REFFILES 'empty directory should not fool for-each-ref' '
prefix=refs/e-for-each-ref && prefix=refs/e-for-each-ref &&
git update-ref $prefix/foo $C && git update-ref $prefix/foo $C &&
git for-each-ref $prefix >expected && git for-each-ref $prefix >expected &&
@ -209,14 +209,14 @@ test_expect_success 'empty directory should not fool for-each-ref' '
test_cmp expected actual test_cmp expected actual
' '


test_expect_success 'empty directory should not fool create' ' test_expect_success REFFILES 'empty directory should not fool create' '
prefix=refs/e-create && prefix=refs/e-create &&
mkdir -p .git/$prefix/foo/bar/baz && mkdir -p .git/$prefix/foo/bar/baz &&
printf "create %s $C\n" $prefix/foo | printf "create %s $C\n" $prefix/foo |
git update-ref --stdin git update-ref --stdin
' '


test_expect_success 'empty directory should not fool verify' ' test_expect_success REFFILES 'empty directory should not fool verify' '
prefix=refs/e-verify && prefix=refs/e-verify &&
git update-ref $prefix/foo $C && git update-ref $prefix/foo $C &&
git pack-refs --all && git pack-refs --all &&
@ -225,7 +225,7 @@ test_expect_success 'empty directory should not fool verify' '
git update-ref --stdin git update-ref --stdin
' '


test_expect_success 'empty directory should not fool 1-arg update' ' test_expect_success REFFILES 'empty directory should not fool 1-arg update' '
prefix=refs/e-update-1 && prefix=refs/e-update-1 &&
git update-ref $prefix/foo $C && git update-ref $prefix/foo $C &&
git pack-refs --all && git pack-refs --all &&
@ -234,7 +234,7 @@ test_expect_success 'empty directory should not fool 1-arg update' '
git update-ref --stdin git update-ref --stdin
' '


test_expect_success 'empty directory should not fool 2-arg update' ' test_expect_success REFFILES 'empty directory should not fool 2-arg update' '
prefix=refs/e-update-2 && prefix=refs/e-update-2 &&
git update-ref $prefix/foo $C && git update-ref $prefix/foo $C &&
git pack-refs --all && git pack-refs --all &&
@ -243,7 +243,7 @@ test_expect_success 'empty directory should not fool 2-arg update' '
git update-ref --stdin git update-ref --stdin
' '


test_expect_success 'empty directory should not fool 0-arg delete' ' test_expect_success REFFILES 'empty directory should not fool 0-arg delete' '
prefix=refs/e-delete-0 && prefix=refs/e-delete-0 &&
git update-ref $prefix/foo $C && git update-ref $prefix/foo $C &&
git pack-refs --all && git pack-refs --all &&
@ -252,7 +252,7 @@ test_expect_success 'empty directory should not fool 0-arg delete' '
git update-ref --stdin git update-ref --stdin
' '


test_expect_success 'empty directory should not fool 1-arg delete' ' test_expect_success REFFILES 'empty directory should not fool 1-arg delete' '
prefix=refs/e-delete-1 && prefix=refs/e-delete-1 &&
git update-ref $prefix/foo $C && git update-ref $prefix/foo $C &&
git pack-refs --all && git pack-refs --all &&
@ -466,7 +466,7 @@ test_expect_success 'incorrect old value blocks indirect no-deref delete' '
test_cmp expected output.err test_cmp expected output.err
' '


test_expect_success 'non-empty directory blocks create' ' test_expect_success REFFILES 'non-empty directory blocks create' '
prefix=refs/ne-create && prefix=refs/ne-create &&
mkdir -p .git/$prefix/foo/bar && mkdir -p .git/$prefix/foo/bar &&
: >.git/$prefix/foo/bar/baz.lock && : >.git/$prefix/foo/bar/baz.lock &&
@ -485,7 +485,7 @@ test_expect_success 'non-empty directory blocks create' '
test_cmp expected output.err test_cmp expected output.err
' '


test_expect_success 'broken reference blocks create' ' test_expect_success REFFILES 'broken reference blocks create' '
prefix=refs/broken-create && prefix=refs/broken-create &&
mkdir -p .git/$prefix && mkdir -p .git/$prefix &&
echo "gobbledigook" >.git/$prefix/foo && echo "gobbledigook" >.git/$prefix/foo &&
@ -504,7 +504,7 @@ test_expect_success 'broken reference blocks create' '
test_cmp expected output.err test_cmp expected output.err
' '


test_expect_success 'non-empty directory blocks indirect create' ' test_expect_success REFFILES 'non-empty directory blocks indirect create' '
prefix=refs/ne-indirect-create && prefix=refs/ne-indirect-create &&
git symbolic-ref $prefix/symref $prefix/foo && git symbolic-ref $prefix/symref $prefix/foo &&
mkdir -p .git/$prefix/foo/bar && mkdir -p .git/$prefix/foo/bar &&
@ -524,7 +524,7 @@ test_expect_success 'non-empty directory blocks indirect create' '
test_cmp expected output.err test_cmp expected output.err
' '


test_expect_success 'broken reference blocks indirect create' ' test_expect_success REFFILES 'broken reference blocks indirect create' '
prefix=refs/broken-indirect-create && prefix=refs/broken-indirect-create &&
git symbolic-ref $prefix/symref $prefix/foo && git symbolic-ref $prefix/symref $prefix/foo &&
echo "gobbledigook" >.git/$prefix/foo && echo "gobbledigook" >.git/$prefix/foo &&
@ -543,7 +543,7 @@ test_expect_success 'broken reference blocks indirect create' '
test_cmp expected output.err test_cmp expected output.err
' '


test_expect_success 'no bogus intermediate values during delete' ' test_expect_success REFFILES 'no bogus intermediate values during delete' '
prefix=refs/slow-transaction && prefix=refs/slow-transaction &&
# Set up a reference with differing loose and packed versions: # Set up a reference with differing loose and packed versions:
git update-ref $prefix/foo $C && git update-ref $prefix/foo $C &&
@ -600,7 +600,7 @@ test_expect_success 'no bogus intermediate values during delete' '
test_must_fail git rev-parse --verify --quiet $prefix/foo test_must_fail git rev-parse --verify --quiet $prefix/foo
' '


test_expect_success 'delete fails cleanly if packed-refs file is locked' ' test_expect_success REFFILES 'delete fails cleanly if packed-refs file is locked' '
prefix=refs/locked-packed-refs && prefix=refs/locked-packed-refs &&
# Set up a reference with differing loose and packed versions: # Set up a reference with differing loose and packed versions:
git update-ref $prefix/foo $C && git update-ref $prefix/foo $C &&
@ -616,7 +616,7 @@ test_expect_success 'delete fails cleanly if packed-refs file is locked' '
test_cmp unchanged actual test_cmp unchanged actual
' '


test_expect_success 'delete fails cleanly if packed-refs.new write fails' ' test_expect_success REFFILES 'delete fails cleanly if packed-refs.new write fails' '
# Setup and expectations are similar to the test above. # Setup and expectations are similar to the test above.
prefix=refs/failed-packed-refs && prefix=refs/failed-packed-refs &&
git update-ref $prefix/foo $C && git update-ref $prefix/foo $C &&

View File

@ -52,7 +52,14 @@ test_expect_success 'create_symref(FOO, refs/heads/main)' '
test_cmp expected actual test_cmp expected actual
' '


test_expect_success 'for_each_reflog()' ' # Some refs (refs/bisect/*, pseudorefs) are kept per worktree, so they should
# only appear in the for-each-reflog output if it is called from the correct
# worktree, which is exercised in this test. This test is poorly written (and
# therefore marked REFFILES) for mulitple reasons: 1) it creates invalidly
# formatted log entres. 2) it uses direct FS access for creating the reflogs. 3)
# PSEUDO-WT and refs/bisect/random do not create reflogs by default, so it is
# not testing a realistic scenario.
test_expect_success REFFILES 'for_each_reflog()' '
echo $ZERO_OID > .git/logs/PSEUDO-MAIN && echo $ZERO_OID > .git/logs/PSEUDO-MAIN &&
mkdir -p .git/logs/refs/bisect && mkdir -p .git/logs/refs/bisect &&
echo $ZERO_OID > .git/logs/refs/bisect/random && echo $ZERO_OID > .git/logs/refs/bisect/random &&

View File

@ -7,8 +7,7 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
. ./test-lib.sh . ./test-lib.sh


reset_state () { reset_state () {
git checkout main && rm -rf .git && "$TAR" xf .git-saved.tar
cp saved_reflog .git/logs/HEAD
} }


test_expect_success setup ' test_expect_success setup '
@ -17,7 +16,7 @@ test_expect_success setup '
git branch side && git branch side &&
test_tick && test_tick &&
git commit --allow-empty -m second && git commit --allow-empty -m second &&
cat .git/logs/HEAD >saved_reflog "$TAR" cf .git-saved.tar .git
' '


test_expect_success baseline ' test_expect_success baseline '

View File

@ -119,7 +119,9 @@ test_expect_success 'min/max age uses entry date to limit' '
test_cmp expect actual test_cmp expect actual
' '


test_expect_success 'walk prefers reflog to ref tip' ' # Create a situation where the reflog and ref database disagree about the latest
# state of HEAD.
test_expect_success REFFILES 'walk prefers reflog to ref tip' '
head=$(git rev-parse HEAD) && head=$(git rev-parse HEAD) &&
one=$(git rev-parse one) && one=$(git rev-parse one) &&
ident="$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE" && ident="$GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE" &&

View File

@ -16,7 +16,10 @@ test_expect_success 'setup' '
git -C wt2 update-ref refs/worktree/foo HEAD git -C wt2 update-ref refs/worktree/foo HEAD
' '


test_expect_success 'refs/worktree must not be packed' ' # The 'packed-refs' file is stored directly in .git/. This means it is global
# to the repository, and can only contain refs that are shared across all
# worktrees.
test_expect_success REFFILES 'refs/worktree must not be packed' '
git pack-refs --all && git pack-refs --all &&
test_path_is_missing .git/refs/tags/wt1 && test_path_is_missing .git/refs/tags/wt1 &&
test_path_is_file .git/refs/worktree/foo && test_path_is_file .git/refs/worktree/foo &&

View File

@ -76,7 +76,7 @@ test_expect_success '--orphan makes reflog by default' '
git rev-parse --verify delta@{0} git rev-parse --verify delta@{0}
' '


test_expect_success '--orphan does not make reflog when core.logAllRefUpdates = false' ' test_expect_success REFFILES '--orphan does not make reflog when core.logAllRefUpdates = false' '
git checkout main && git checkout main &&
git config core.logAllRefUpdates false && git config core.logAllRefUpdates false &&
git checkout --orphan epsilon && git checkout --orphan epsilon &&

View File

@ -1834,14 +1834,24 @@ test_expect_success 'log --graph --no-walk is forbidden' '
test_must_fail git log --graph --no-walk test_must_fail git log --graph --no-walk
' '


test_expect_success 'log diagnoses bogus HEAD' ' test_expect_success 'log on empty repo fails' '
git init empty && git init empty &&
test_when_finished "rm -rf empty" &&
test_must_fail git -C empty log 2>stderr && test_must_fail git -C empty log 2>stderr &&
test_i18ngrep does.not.have.any.commits stderr && test_i18ngrep does.not.have.any.commits stderr
'

test_expect_success REFFILES 'log diagnoses bogus HEAD hash' '
git init empty &&
test_when_finished "rm -rf empty" &&
echo 1234abcd >empty/.git/refs/heads/main && echo 1234abcd >empty/.git/refs/heads/main &&
test_must_fail git -C empty log 2>stderr && test_must_fail git -C empty log 2>stderr &&
test_i18ngrep broken stderr && test_i18ngrep broken stderr
echo "ref: refs/heads/invalid.lock" >empty/.git/HEAD && '

test_expect_success 'log diagnoses bogus HEAD symref' '
git init empty &&
git --git-dir empty/.git symbolic-ref HEAD refs/heads/invalid.lock &&
test_must_fail git -C empty log 2>stderr && test_must_fail git -C empty log 2>stderr &&
test_i18ngrep broken stderr && test_i18ngrep broken stderr &&
test_must_fail git -C empty log --default totally-bogus 2>stderr && test_must_fail git -C empty log --default totally-bogus 2>stderr &&

View File

@ -111,25 +111,34 @@ test_expect_success 'setup' '
EOF EOF
' '


test_expect_success \ test_expect_success 'populate workdir' '
'populate workdir' \ mkdir a &&
'mkdir a && echo simple textfile >a/a &&
echo simple textfile >a/a && ten=0123456789 &&
ten=0123456789 && hundred=$ten$ten$ten$ten$ten$ten$ten$ten$ten$ten && hundred="$ten$ten$ten$ten$ten$ten$ten$ten$ten$ten" &&
echo long filename >a/four$hundred && echo long filename >"a/four$hundred" &&
mkdir a/bin && mkdir a/bin &&
test-tool genrandom "frotz" 500000 >a/bin/sh && test-tool genrandom "frotz" 500000 >a/bin/sh &&
printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 && printf "A\$Format:%s\$O" "$SUBSTFORMAT" >a/substfile1 &&
printf "A not substituted O" >a/substfile2 && printf "A not substituted O" >a/substfile2 &&
if test_have_prereq SYMLINKS; then if test_have_prereq SYMLINKS
ln -s a a/l1 then
else ln -s a a/l1
printf %s a > a/l1 else
fi && printf %s a >a/l1
(p=long_path_to_a_file && cd a && fi &&
for depth in 1 2 3 4 5; do mkdir $p && cd $p; done && (
echo text >file_with_long_path) && p=long_path_to_a_file &&
(cd a && find .) | sort >a.lst' cd a &&
for depth in 1 2 3 4 5
do
mkdir $p &&
cd $p
done &&
echo text >file_with_long_path
) &&
(cd a && find .) | sort >a.lst
'


test_expect_success \ test_expect_success \
'add ignored file' \ 'add ignored file' \
@ -147,18 +156,18 @@ test_expect_success 'setup export-subst' '
>a/substfile1 >a/substfile1
' '


test_expect_success \ test_expect_success 'create bare clone' '
'create bare clone' \ git clone --bare . bare.git &&
'git clone --bare . bare.git && cp .git/info/attributes bare.git/info/attributes
cp .git/info/attributes bare.git/info/attributes' '


test_expect_success \ test_expect_success 'remove ignored file' '
'remove ignored file' \ rm a/ignored
'rm a/ignored' '


test_expect_success \ test_expect_success 'git archive' '
'git archive' \ git archive HEAD >b.tar
'git archive HEAD >b.tar' '


check_tar b check_tar b


@ -194,26 +203,28 @@ check_added with_untracked2 untracked one/untracked
check_added with_untracked2 untracked two/untracked check_added with_untracked2 untracked two/untracked


test_expect_success 'git archive on large files' ' test_expect_success 'git archive on large files' '
test_config core.bigfilethreshold 1 && test_config core.bigfilethreshold 1 &&
git archive HEAD >b3.tar && git archive HEAD >b3.tar &&
test_cmp_bin b.tar b3.tar test_cmp_bin b.tar b3.tar
' '


test_expect_success \ test_expect_success 'git archive in a bare repo' '
'git archive in a bare repo' \ git --git-dir bare.git archive HEAD >b3.tar
'(cd bare.git && git archive HEAD) >b3.tar' '


test_expect_success \ test_expect_success 'git archive vs. the same in a bare repo' '
'git archive vs. the same in a bare repo' \ test_cmp_bin b.tar b3.tar
'test_cmp_bin b.tar b3.tar' '


test_expect_success 'git archive with --output' \ test_expect_success 'git archive with --output' '
'git archive --output=b4.tar HEAD && git archive --output=b4.tar HEAD &&
test_cmp_bin b.tar b4.tar' test_cmp_bin b.tar b4.tar
'


test_expect_success 'git archive --remote' \ test_expect_success 'git archive --remote' '
'git archive --remote=. HEAD >b5.tar && git archive --remote=. HEAD >b5.tar &&
test_cmp_bin b.tar b5.tar' test_cmp_bin b.tar b5.tar
'


test_expect_success 'git archive --remote with configured remote' ' test_expect_success 'git archive --remote with configured remote' '
git config remote.foo.url . && git config remote.foo.url . &&
@ -224,18 +235,19 @@ test_expect_success 'git archive --remote with configured remote' '
test_cmp_bin b.tar b5-nick.tar test_cmp_bin b.tar b5-nick.tar
' '


test_expect_success \ test_expect_success 'validate file modification time' '
'validate file modification time' \ mkdir extract &&
'mkdir extract && "$TAR" xf b.tar -C extract a/a &&
"$TAR" xf b.tar -C extract a/a && test-tool chmtime --get extract/a/a >b.mtime &&
test-tool chmtime --get extract/a/a >b.mtime && echo "1117231200" >expected.mtime &&
echo "1117231200" >expected.mtime && test_cmp expected.mtime b.mtime
test_cmp expected.mtime b.mtime' '


test_expect_success \ test_expect_success 'git get-tar-commit-id' '
'git get-tar-commit-id' \ git get-tar-commit-id <b.tar >actual &&
'git get-tar-commit-id <b.tar >b.commitid && git rev-parse HEAD >expect &&
test_cmp .git/$(git symbolic-ref HEAD) b.commitid' test_cmp expect actual
'


test_expect_success 'git archive with --output, override inferred format' ' test_expect_success 'git archive with --output, override inferred format' '
git archive --format=tar --output=d4.zip HEAD && git archive --format=tar --output=d4.zip HEAD &&

View File

@ -22,30 +22,25 @@ add_blob() {
} }


test_expect_success setup ' test_expect_success setup '

>file &&
: > file &&
git add file && git add file &&
test_tick && test_tick &&
git commit -m initial && git commit -m initial &&
git gc git gc

' '


test_expect_success 'prune stale packs' ' test_expect_success 'prune stale packs' '

orig_pack=$(echo .git/objects/pack/*.pack) && orig_pack=$(echo .git/objects/pack/*.pack) &&
: > .git/objects/tmp_1.pack && >.git/objects/tmp_1.pack &&
: > .git/objects/tmp_2.pack && >.git/objects/tmp_2.pack &&
test-tool chmtime =-86501 .git/objects/tmp_1.pack && test-tool chmtime =-86501 .git/objects/tmp_1.pack &&
git prune --expire 1.day && git prune --expire 1.day &&
test_path_is_file $orig_pack && test_path_is_file $orig_pack &&
test_path_is_file .git/objects/tmp_2.pack && test_path_is_file .git/objects/tmp_2.pack &&
test_path_is_missing .git/objects/tmp_1.pack test_path_is_missing .git/objects/tmp_1.pack

' '


test_expect_success 'prune --expire' ' test_expect_success 'prune --expire' '

add_blob && add_blob &&
git prune --expire=1.hour.ago && git prune --expire=1.hour.ago &&
verbose test $((1 + $before)) = $(git count-objects | sed "s/ .*//") && verbose test $((1 + $before)) = $(git count-objects | sed "s/ .*//") &&
@ -54,11 +49,9 @@ test_expect_success 'prune --expire' '
git prune --expire 1.day && git prune --expire 1.day &&
verbose test $before = $(git count-objects | sed "s/ .*//") && verbose test $before = $(git count-objects | sed "s/ .*//") &&
test_path_is_missing $BLOB_FILE test_path_is_missing $BLOB_FILE

' '


test_expect_success 'gc: implicit prune --expire' ' test_expect_success 'gc: implicit prune --expire' '

add_blob && add_blob &&
test-tool chmtime =-$((2*$week-30)) $BLOB_FILE && test-tool chmtime =-$((2*$week-30)) $BLOB_FILE &&
git gc && git gc &&
@ -68,123 +61,98 @@ test_expect_success 'gc: implicit prune --expire' '
git gc && git gc &&
verbose test $before = $(git count-objects | sed "s/ .*//") && verbose test $before = $(git count-objects | sed "s/ .*//") &&
test_path_is_missing $BLOB_FILE test_path_is_missing $BLOB_FILE

' '


test_expect_success 'gc: refuse to start with invalid gc.pruneExpire' ' test_expect_success 'gc: refuse to start with invalid gc.pruneExpire' '

git config gc.pruneExpire invalid && git config gc.pruneExpire invalid &&
test_must_fail git gc test_must_fail git gc

' '


test_expect_success 'gc: start with ok gc.pruneExpire' ' test_expect_success 'gc: start with ok gc.pruneExpire' '

git config gc.pruneExpire 2.days.ago && git config gc.pruneExpire 2.days.ago &&
git gc git gc

' '


test_expect_success 'prune: prune nonsense parameters' ' test_expect_success 'prune: prune nonsense parameters' '

test_must_fail git prune garbage && test_must_fail git prune garbage &&
test_must_fail git prune --- && test_must_fail git prune --- &&
test_must_fail git prune --no-such-option test_must_fail git prune --no-such-option

' '


test_expect_success 'prune: prune unreachable heads' ' test_expect_success 'prune: prune unreachable heads' '

git config core.logAllRefUpdates false && git config core.logAllRefUpdates false &&
mv .git/logs .git/logs.old && >file2 &&
: > file2 &&
git add file2 && git add file2 &&
git commit -m temporary && git commit -m temporary &&
tmp_head=$(git rev-list -1 HEAD) && tmp_head=$(git rev-list -1 HEAD) &&
git reset HEAD^ && git reset HEAD^ &&
git reflog expire --all &&
git prune && git prune &&
test_must_fail git reset $tmp_head -- test_must_fail git reset $tmp_head --

' '


test_expect_success 'prune: do not prune detached HEAD with no reflog' ' test_expect_success 'prune: do not prune detached HEAD with no reflog' '

git checkout --detach --quiet && git checkout --detach --quiet &&
git commit --allow-empty -m "detached commit" && git commit --allow-empty -m "detached commit" &&
# verify that there is no reflogs git reflog expire --all &&
# (should be removed and disabled by previous test)
test_path_is_missing .git/logs &&
git prune -n >prune_actual && git prune -n >prune_actual &&
test_must_be_empty prune_actual test_must_be_empty prune_actual

' '


test_expect_success 'prune: prune former HEAD after checking out branch' ' test_expect_success 'prune: prune former HEAD after checking out branch' '

head_oid=$(git rev-parse HEAD) && head_oid=$(git rev-parse HEAD) &&
git checkout --quiet main && git checkout --quiet main &&
git reflog expire --all &&
git prune -v >prune_actual && git prune -v >prune_actual &&
grep "$head_oid" prune_actual grep "$head_oid" prune_actual

' '


test_expect_success 'prune: do not prune heads listed as an argument' ' test_expect_success 'prune: do not prune heads listed as an argument' '

>file2 &&
: > file2 &&
git add file2 && git add file2 &&
git commit -m temporary && git commit -m temporary &&
tmp_head=$(git rev-list -1 HEAD) && tmp_head=$(git rev-list -1 HEAD) &&
git reset HEAD^ && git reset HEAD^ &&
git prune -- $tmp_head && git prune -- $tmp_head &&
git reset $tmp_head -- git reset $tmp_head --

' '


test_expect_success 'gc --no-prune' ' test_expect_success 'gc --no-prune' '

add_blob && add_blob &&
test-tool chmtime =-$((5001*$day)) $BLOB_FILE && test-tool chmtime =-$((5001*$day)) $BLOB_FILE &&
git config gc.pruneExpire 2.days.ago && git config gc.pruneExpire 2.days.ago &&
git gc --no-prune && git gc --no-prune &&
verbose test 1 = $(git count-objects | sed "s/ .*//") && verbose test 1 = $(git count-objects | sed "s/ .*//") &&
test_path_is_file $BLOB_FILE test_path_is_file $BLOB_FILE

' '


test_expect_success 'gc respects gc.pruneExpire' ' test_expect_success 'gc respects gc.pruneExpire' '

git config gc.pruneExpire 5002.days.ago && git config gc.pruneExpire 5002.days.ago &&
git gc && git gc &&
test_path_is_file $BLOB_FILE && test_path_is_file $BLOB_FILE &&
git config gc.pruneExpire 5000.days.ago && git config gc.pruneExpire 5000.days.ago &&
git gc && git gc &&
test_path_is_missing $BLOB_FILE test_path_is_missing $BLOB_FILE

' '


test_expect_success 'gc --prune=<date>' ' test_expect_success 'gc --prune=<date>' '

add_blob && add_blob &&
test-tool chmtime =-$((5001*$day)) $BLOB_FILE && test-tool chmtime =-$((5001*$day)) $BLOB_FILE &&
git gc --prune=5002.days.ago && git gc --prune=5002.days.ago &&
test_path_is_file $BLOB_FILE && test_path_is_file $BLOB_FILE &&
git gc --prune=5000.days.ago && git gc --prune=5000.days.ago &&
test_path_is_missing $BLOB_FILE test_path_is_missing $BLOB_FILE

' '


test_expect_success 'gc --prune=never' ' test_expect_success 'gc --prune=never' '

add_blob && add_blob &&
git gc --prune=never && git gc --prune=never &&
test_path_is_file $BLOB_FILE && test_path_is_file $BLOB_FILE &&
git gc --prune=now && git gc --prune=now &&
test_path_is_missing $BLOB_FILE test_path_is_missing $BLOB_FILE

' '


test_expect_success 'gc respects gc.pruneExpire=never' ' test_expect_success 'gc respects gc.pruneExpire=never' '

git config gc.pruneExpire never && git config gc.pruneExpire never &&
add_blob && add_blob &&
git gc && git gc &&
@ -192,17 +160,14 @@ test_expect_success 'gc respects gc.pruneExpire=never' '
git config gc.pruneExpire now && git config gc.pruneExpire now &&
git gc && git gc &&
test_path_is_missing $BLOB_FILE test_path_is_missing $BLOB_FILE

' '


test_expect_success 'prune --expire=never' ' test_expect_success 'prune --expire=never' '

add_blob && add_blob &&
git prune --expire=never && git prune --expire=never &&
test_path_is_file $BLOB_FILE && test_path_is_file $BLOB_FILE &&
git prune && git prune &&
test_path_is_missing $BLOB_FILE test_path_is_missing $BLOB_FILE

' '


test_expect_success 'gc: prune old objects after local clone' ' test_expect_success 'gc: prune old objects after local clone' '
@ -222,16 +187,16 @@ test_expect_success 'gc: prune old objects after local clone' '
test_expect_success 'garbage report in count-objects -v' ' test_expect_success 'garbage report in count-objects -v' '
test_when_finished "rm -f .git/objects/pack/fake*" && test_when_finished "rm -f .git/objects/pack/fake*" &&
test_when_finished "rm -f .git/objects/pack/foo*" && test_when_finished "rm -f .git/objects/pack/foo*" &&
: >.git/objects/pack/foo && >.git/objects/pack/foo &&
: >.git/objects/pack/foo.bar && >.git/objects/pack/foo.bar &&
: >.git/objects/pack/foo.keep && >.git/objects/pack/foo.keep &&
: >.git/objects/pack/foo.pack && >.git/objects/pack/foo.pack &&
: >.git/objects/pack/fake.bar && >.git/objects/pack/fake.bar &&
: >.git/objects/pack/fake.keep && >.git/objects/pack/fake.keep &&
: >.git/objects/pack/fake.pack && >.git/objects/pack/fake.pack &&
: >.git/objects/pack/fake.idx && >.git/objects/pack/fake.idx &&
: >.git/objects/pack/fake2.keep && >.git/objects/pack/fake2.keep &&
: >.git/objects/pack/fake3.idx && >.git/objects/pack/fake3.idx &&
git count-objects -v 2>stderr && git count-objects -v 2>stderr &&
grep "index file .git/objects/pack/fake.idx is too small" stderr && grep "index file .git/objects/pack/fake.idx is too small" stderr &&
grep "^warning:" stderr | sort >actual && grep "^warning:" stderr | sort >actual &&
@ -250,12 +215,12 @@ EOF
test_expect_success 'clean pack garbage with gc' ' test_expect_success 'clean pack garbage with gc' '
test_when_finished "rm -f .git/objects/pack/fake*" && test_when_finished "rm -f .git/objects/pack/fake*" &&
test_when_finished "rm -f .git/objects/pack/foo*" && test_when_finished "rm -f .git/objects/pack/foo*" &&
: >.git/objects/pack/foo.keep && >.git/objects/pack/foo.keep &&
: >.git/objects/pack/foo.pack && >.git/objects/pack/foo.pack &&
: >.git/objects/pack/fake.idx && >.git/objects/pack/fake.idx &&
: >.git/objects/pack/fake2.keep && >.git/objects/pack/fake2.keep &&
: >.git/objects/pack/fake2.idx && >.git/objects/pack/fake2.idx &&
: >.git/objects/pack/fake3.keep && >.git/objects/pack/fake3.keep &&
git gc && git gc &&
git count-objects -v 2>stderr && git count-objects -v 2>stderr &&
grep "^warning:" stderr | sort >actual && grep "^warning:" stderr | sort >actual &&

View File

@ -305,7 +305,8 @@ test_expect_success 'clone from original with relative alternate' '
test_expect_success 'clone checking out a tag' ' test_expect_success 'clone checking out a tag' '
git clone --branch=some-tag src dst.tag && git clone --branch=some-tag src dst.tag &&
GIT_DIR=src/.git git rev-parse some-tag >expected && GIT_DIR=src/.git git rev-parse some-tag >expected &&
test_cmp expected dst.tag/.git/HEAD && GIT_DIR=dst.tag/.git git rev-parse HEAD >actual &&
test_cmp expected actual &&
GIT_DIR=dst.tag/.git git config remote.origin.fetch >fetch.actual && GIT_DIR=dst.tag/.git git config remote.origin.fetch >fetch.actual &&
echo "+refs/heads/*:refs/remotes/origin/*" >fetch.expected && echo "+refs/heads/*:refs/remotes/origin/*" >fetch.expected &&
test_cmp fetch.expected fetch.actual test_cmp fetch.expected fetch.actual

View File

@ -395,8 +395,11 @@ test_expect_success '--prune-empty is able to prune root commit' '
test_expect_success '--prune-empty is able to prune entire branch' ' test_expect_success '--prune-empty is able to prune entire branch' '
git branch prune-entire B && git branch prune-entire B &&
git filter-branch -f --prune-empty --index-filter "git update-index --remove A.t B.t" prune-entire && git filter-branch -f --prune-empty --index-filter "git update-index --remove A.t B.t" prune-entire &&
test_path_is_missing .git/refs/heads/prune-entire && test_must_fail git rev-parse refs/heads/prune-entire &&
test_must_fail git reflog exists refs/heads/prune-entire if test_have_prereq REFFILES
then
test_must_fail git reflog exists refs/heads/prune-entire
fi
' '


test_expect_success '--remap-to-ancestor with filename filters' ' test_expect_success '--remap-to-ancestor with filename filters' '

View File

@ -356,8 +356,6 @@ test_expect_success 'pack-refs task' '
done && done &&
GIT_TRACE2_EVENT="$(pwd)/pack-refs.txt" \ GIT_TRACE2_EVENT="$(pwd)/pack-refs.txt" \
git maintenance run --task=pack-refs && git maintenance run --task=pack-refs &&
ls .git/refs/heads/ >after &&
test_must_be_empty after &&
test_subcommand git pack-refs --all --prune <pack-refs.txt test_subcommand git pack-refs --all --prune <pack-refs.txt
' '



View File

@ -392,7 +392,7 @@ test_expect_success 'B: accept branch name "TEMP_TAG"' '
git gc git gc
git prune" && git prune" &&
git fast-import <input && git fast-import <input &&
test -f .git/TEMP_TAG && test $(test-tool ref-store main resolve-ref TEMP_TAG 0 | cut -f1 -d " " ) != "$ZERO_OID" &&
test $(git rev-parse main) = $(git rev-parse TEMP_TAG^) test $(git rev-parse main) = $(git rev-parse TEMP_TAG^)
' '



View File

@ -1509,6 +1509,8 @@ parisc* | hppa*)
;; ;;
esac esac


test_set_prereq REFFILES

( COLUMNS=1 && test $COLUMNS = 1 ) && test_set_prereq COLUMNS_CAN_BE_1 ( COLUMNS=1 && test $COLUMNS = 1 ) && test_set_prereq COLUMNS_CAN_BE_1
test -z "$NO_PERL" && test_set_prereq PERL test -z "$NO_PERL" && test_set_prereq PERL
test -z "$NO_PTHREADS" && test_set_prereq PTHREADS test -z "$NO_PTHREADS" && test_set_prereq PTHREADS