diff options
Diffstat (limited to 't/t6500-gc.sh')
-rwxr-xr-x | t/t6500-gc.sh | 188 |
1 files changed, 122 insertions, 66 deletions
diff --git a/t/t6500-gc.sh b/t/t6500-gc.sh index d9acb63951..18fe1c25e6 100755 --- a/t/t6500-gc.sh +++ b/t/t6500-gc.sh @@ -41,7 +41,7 @@ test_expect_success 'gc does not leave behind pid file' ' test_expect_success 'gc --gobbledegook' ' test_expect_code 129 git gc --nonsense 2>err && - test_i18ngrep "[Uu]sage: git gc" err + test_grep "[Uu]sage: git gc" err ' test_expect_success 'gc -h with invalid configuration' ' @@ -52,7 +52,7 @@ test_expect_success 'gc -h with invalid configuration' ' echo "[gc] pruneexpire = CORRUPT" >>.git/config && test_expect_code 129 git gc -h >usage 2>&1 ) && - test_i18ngrep "[Uu]sage" broken/usage + test_grep "[Uu]sage" broken/usage ' test_expect_success 'gc is not aborted due to a stale symref' ' @@ -155,7 +155,7 @@ test_expect_success 'auto gc with too many loose objects does not attempt to cre test_commit "$(test_oid obj4)" && git gc --auto 2>err && - test_i18ngrep ! "^warning:" err && + test_grep ! "^warning:" err && ls .git/objects/pack/pack-*.pack | sort >post_packs && comm -1 -3 existing_packs post_packs >new && comm -2 -3 existing_packs post_packs >del && @@ -166,15 +166,15 @@ test_expect_success 'auto gc with too many loose objects does not attempt to cre test_expect_success 'gc --no-quiet' ' GIT_PROGRESS_DELAY=0 git -c gc.writeCommitGraph=true gc --no-quiet >stdout 2>stderr && test_must_be_empty stdout && - test_i18ngrep "Computing commit graph generation numbers" stderr + test_grep "Computing commit graph generation numbers" stderr ' test_expect_success TTY 'with TTY: gc --no-quiet' ' test_terminal env GIT_PROGRESS_DELAY=0 \ git -c gc.writeCommitGraph=true gc --no-quiet >stdout 2>stderr && test_must_be_empty stdout && - test_i18ngrep "Enumerating objects" stderr && - test_i18ngrep "Computing commit graph generation numbers" stderr + test_grep "Enumerating objects" stderr && + test_grep "Computing commit graph generation numbers" stderr ' test_expect_success 'gc --quiet' ' @@ -202,6 +202,30 @@ test_expect_success 'one of gc.reflogExpire{Unreachable,}=never does not skip "e grep -E "^trace: (built-in|exec|run_command): git reflog expire --" trace.out ' +test_expect_success 'gc.repackFilter launches repack with a filter' ' + git clone --no-local --bare . bare.git && + + git -C bare.git -c gc.cruftPacks=false gc && + test_stdout_line_count = 1 ls bare.git/objects/pack/*.pack && + + GIT_TRACE=$(pwd)/trace.out git -C bare.git -c gc.repackFilter=blob:none \ + -c repack.writeBitmaps=false -c gc.cruftPacks=false gc && + test_stdout_line_count = 2 ls bare.git/objects/pack/*.pack && + grep -E "^trace: (built-in|exec|run_command): git repack .* --filter=blob:none ?.*" trace.out +' + +test_expect_success 'gc.repackFilterTo store filtered out objects' ' + test_when_finished "rm -rf bare.git filtered.git" && + + git init --bare filtered.git && + git -C bare.git -c gc.repackFilter=blob:none \ + -c gc.repackFilterTo=../filtered.git/objects/pack/pack \ + -c repack.writeBitmaps=false -c gc.cruftPacks=false gc && + + test_stdout_line_count = 1 ls bare.git/objects/pack/*.pack && + test_stdout_line_count = 1 ls filtered.git/objects/pack/*.pack +' + prepare_cruft_history () { test_commit base && @@ -210,92 +234,124 @@ prepare_cruft_history () { git reset HEAD^^ } -assert_cruft_packs () { - find .git/objects/pack -name "*.mtimes" >mtimes && - sed -e 's/\.mtimes$/\.pack/g' mtimes >packs && - - test_file_not_empty packs && - while read pack - do - test_path_is_file "$pack" || return 1 - done <packs -} - assert_no_cruft_packs () { find .git/objects/pack -name "*.mtimes" >mtimes && test_must_be_empty mtimes } -test_expect_success 'gc --cruft generates a cruft pack' ' - test_when_finished "rm -fr crufts" && - git init crufts && +for argv in \ + "gc" \ + "-c gc.cruftPacks=true gc" \ + "-c gc.cruftPacks=false gc --cruft" +do + test_expect_success "git $argv generates a cruft pack" ' + test_when_finished "rm -fr repo" && + git init repo && + ( + cd repo && + + prepare_cruft_history && + git $argv && + + find .git/objects/pack -name "*.mtimes" >mtimes && + sed -e 's/\.mtimes$/\.pack/g' mtimes >packs && + + test_file_not_empty packs && + while read pack + do + test_path_is_file "$pack" || return 1 + done <packs + ) + ' +done + +for argv in \ + "gc --no-cruft" \ + "-c gc.cruftPacks=false gc" \ + "-c gc.cruftPacks=true gc --no-cruft" +do + test_expect_success "git $argv does not generate a cruft pack" ' + test_when_finished "rm -fr repo" && + git init repo && + ( + cd repo && + + prepare_cruft_history && + git $argv && + + assert_no_cruft_packs + ) + ' +done + +test_expect_success '--keep-largest-pack ignores cruft packs' ' + test_when_finished "rm -fr repo" && + git init repo && ( - cd crufts && + cd repo && + # Generate a pack for reachable objects (of which there + # are 3), and one for unreachable objects (of which + # there are 6). prepare_cruft_history && git gc --cruft && - assert_cruft_packs - ) -' -test_expect_success 'gc.cruftPacks=true generates a cruft pack' ' - test_when_finished "rm -fr crufts" && - git init crufts && - ( - cd crufts && + mtimes="$(find .git/objects/pack -type f -name "pack-*.mtimes")" && + sz="$(test_file_size "${mtimes%.mtimes}.pack")" && - prepare_cruft_history && - git -c gc.cruftPacks=true gc && - assert_cruft_packs + # Ensure that the cruft pack gets removed (due to + # `--prune=now`) despite it being the largest pack. + git -c gc.bigPackThreshold=$sz gc --cruft --prune=now && + + assert_no_cruft_packs ) ' -test_expect_success 'feature.experimental=true generates a cruft pack' ' - git init crufts && - test_when_finished "rm -fr crufts" && +test_expect_success 'gc.bigPackThreshold ignores cruft packs' ' + test_when_finished "rm -fr repo" && + git init repo && ( - cd crufts && + cd repo && + # Generate a pack for reachable objects (of which there + # are 3), and one for unreachable objects (of which + # there are 6). prepare_cruft_history && - git -c feature.experimental=true gc && - assert_cruft_packs - ) -' + git gc --cruft && -test_expect_success 'feature.experimental=false allows explicit cruft packs' ' - git init crufts && - test_when_finished "rm -fr crufts" && - ( - cd crufts && + # Ensure that the cruft pack gets removed (due to + # `--prune=now`) despite it being the largest pack. + git gc --cruft --prune=now --keep-largest-pack && - prepare_cruft_history && - git -c gc.cruftPacks=true -c feature.experimental=false gc && - assert_cruft_packs + assert_no_cruft_packs ) ' -test_expect_success 'feature.experimental=true can be overridden' ' - git init crufts && - test_when_finished "rm -fr crufts" && - ( - cd crufts && +cruft_max_size_opts="git repack -d -l --cruft --cruft-expiration=2.weeks.ago" - prepare_cruft_history && - git -c feature.expiremental=true -c gc.cruftPacks=false gc && - assert_no_cruft_packs +test_expect_success 'setup for --max-cruft-size tests' ' + git init cruft--max-size && + ( + cd cruft--max-size && + prepare_cruft_history ) ' -test_expect_success 'feature.experimental=false avoids cruft packs by default' ' - git init crufts && - test_when_finished "rm -fr crufts" && - ( - cd crufts && +test_expect_success '--max-cruft-size sets appropriate repack options' ' + GIT_TRACE2_EVENT=$(pwd)/trace2.txt git -C cruft--max-size \ + gc --cruft --max-cruft-size=1M && + test_subcommand $cruft_max_size_opts --max-cruft-size=1048576 <trace2.txt +' - prepare_cruft_history && - git -c feature.experimental=false gc && - assert_no_cruft_packs - ) +test_expect_success 'gc.maxCruftSize sets appropriate repack options' ' + GIT_TRACE2_EVENT=$(pwd)/trace2.txt \ + git -C cruft--max-size -c gc.maxCruftSize=2M gc --cruft && + test_subcommand $cruft_max_size_opts --max-cruft-size=2097152 <trace2.txt && + + GIT_TRACE2_EVENT=$(pwd)/trace2.txt \ + git -C cruft--max-size -c gc.maxCruftSize=2M gc --cruft \ + --max-cruft-size=3M && + test_subcommand $cruft_max_size_opts --max-cruft-size=3145728 <trace2.txt ' run_and_wait_for_auto_gc () { @@ -316,7 +372,7 @@ test_expect_success 'background auto gc does not run if gc.log is present and re test_config gc.autodetach true && echo fleem >.git/gc.log && git gc --auto 2>err && - test_i18ngrep "^warning:" err && + test_grep "^warning:" err && test_config gc.logexpiry 5.days && test-tool chmtime =-345600 .git/gc.log && git gc --auto && |