Merge branch 'dl/test-cleanup'

Test cleanup.

* dl/test-cleanup: (26 commits)
  t7700: stop losing return codes of git commands
  t7700: make references to SHA-1 generic
  t7700: replace egrep with grep
  t7700: consolidate code into test_has_duplicate_object()
  t7700: consolidate code into test_no_missing_in_packs()
  t7700: s/test -f/test_path_is_file/
  t7700: move keywords onto their own line
  t7700: remove spaces after redirect operators
  t7700: drop redirections to /dev/null
  t7501: stop losing return codes of git commands
  t7501: remove spaces after redirect operators
  t5703: stop losing return codes of git commands
  t5703: simplify one-time-sed generation logic
  t5317: use ! grep to check for no matching lines
  t5317: stop losing return codes of git commands
  t4138: stop losing return codes of git commands
  t4015: use test_write_lines()
  t4015: stop losing return codes of git commands
  t3600: comment on inducing SIGPIPE in `git rm`
  t3600: stop losing return codes of git commands
  ...
This commit is contained in:
Junio C Hamano
2019-12-16 13:08:32 -08:00
12 changed files with 425 additions and 323 deletions

View File

@ -2,10 +2,12 @@
# to run under Bash; primarily intended for tests of the completion # to run under Bash; primarily intended for tests of the completion
# script. # script.
if test -n "$BASH" && test -z "$POSIXLY_CORRECT"; then if test -n "$BASH" && test -z "$POSIXLY_CORRECT"
then
# we are in full-on bash mode # we are in full-on bash mode
true true
elif type bash >/dev/null 2>&1; then elif type bash >/dev/null 2>&1
then
# execute in full-on bash mode # execute in full-on bash mode
unset POSIXLY_CORRECT unset POSIXLY_CORRECT
exec bash "$0" "$@" exec bash "$0" "$@"

View File

@ -7,11 +7,13 @@
# #
# This can be used to simulate the effects of the repository changing in # This can be used to simulate the effects of the repository changing in
# between HTTP request-response pairs. # between HTTP request-response pairs.
if [ -e one-time-sed ]; then if test -f one-time-sed
then
"$GIT_EXEC_PATH/git-http-backend" >out "$GIT_EXEC_PATH/git-http-backend" >out
sed "$(cat one-time-sed)" <out >out_modified sed "$(cat one-time-sed)" out >out_modified
if diff out out_modified >/dev/null; then if cmp -s out out_modified
then
cat out cat out
else else
cat out_modified cat out_modified

View File

@ -38,8 +38,8 @@ test_expect_success 'looping aliases - internal execution' '
#' #'
test_expect_success 'run-command formats empty args properly' ' test_expect_success 'run-command formats empty args properly' '
GIT_TRACE=1 git frotz a "" b " " c 2>&1 | test_must_fail env GIT_TRACE=1 git frotz a "" b " " c 2>actual.raw &&
sed -ne "/run_command:/s/.*trace: run_command: //p" >actual && sed -ne "/run_command:/s/.*trace: run_command: //p" actual.raw >actual &&
echo "git-frotz a '\'''\'' b '\'' '\'' c" >expect && echo "git-frotz a '\'''\'' b '\'' '\'' c" >expect &&
test_cmp expect actual test_cmp expect actual
' '

View File

@ -21,9 +21,10 @@ generate_expected_cache_tree_rec () {
parent="$2" && parent="$2" &&
# ls-files might have foo/bar, foo/bar/baz, and foo/bar/quux # ls-files might have foo/bar, foo/bar/baz, and foo/bar/quux
# We want to count only foo because it's the only direct child # We want to count only foo because it's the only direct child
subtrees=$(git ls-files|grep /|cut -d / -f 1|uniq) && git ls-files >files &&
subtrees=$(grep / files|cut -d / -f 1|uniq) &&
subtree_count=$(echo "$subtrees"|awk -v c=0 '$1 != "" {++c} END {print c}') && subtree_count=$(echo "$subtrees"|awk -v c=0 '$1 != "" {++c} END {print c}') &&
entries=$(git ls-files|wc -l) && entries=$(wc -l <files) &&
printf "SHA $dir (%d entries, %d subtrees)\n" "$entries" "$subtree_count" && printf "SHA $dir (%d entries, %d subtrees)\n" "$entries" "$subtree_count" &&
for subtree in $subtrees for subtree in $subtrees
do do

View File

@ -54,7 +54,9 @@ test_expect_success 'create notes' '
test_path_is_missing .git/NOTES_EDITMSG && test_path_is_missing .git/NOTES_EDITMSG &&
git ls-tree -r refs/notes/commits >actual && git ls-tree -r refs/notes/commits >actual &&
test_line_count = 1 actual && test_line_count = 1 actual &&
test "b4" = "$(git notes show)" && echo b4 >expect &&
git notes show >actual &&
test_cmp expect actual &&
git show HEAD^ && git show HEAD^ &&
test_must_fail git notes show HEAD^ test_must_fail git notes show HEAD^
' '
@ -79,14 +81,21 @@ test_expect_success 'edit existing notes' '
test_path_is_missing .git/NOTES_EDITMSG && test_path_is_missing .git/NOTES_EDITMSG &&
git ls-tree -r refs/notes/commits >actual && git ls-tree -r refs/notes/commits >actual &&
test_line_count = 1 actual && test_line_count = 1 actual &&
test "b3" = "$(git notes show)" && echo b3 >expect &&
git notes show >actual &&
test_cmp expect actual &&
git show HEAD^ && git show HEAD^ &&
test_must_fail git notes show HEAD^ test_must_fail git notes show HEAD^
' '
test_expect_success 'show notes from treeish' ' test_expect_success 'show notes from treeish' '
test "b3" = "$(git notes --ref commits^{tree} show)" && echo b3 >expect &&
test "b4" = "$(git notes --ref commits@{1} show)" git notes --ref commits^{tree} show >actual &&
test_cmp expect actual &&
echo b4 >expect &&
git notes --ref commits@{1} show >actual &&
test_cmp expect actual
' '
test_expect_success 'cannot edit notes from non-ref' ' test_expect_success 'cannot edit notes from non-ref' '
@ -99,7 +108,9 @@ test_expect_success 'cannot "git notes add -m" where notes already exists' '
test_path_is_missing .git/NOTES_EDITMSG && test_path_is_missing .git/NOTES_EDITMSG &&
git ls-tree -r refs/notes/commits >actual && git ls-tree -r refs/notes/commits >actual &&
test_line_count = 1 actual && test_line_count = 1 actual &&
test "b3" = "$(git notes show)" && echo b3 >expect &&
git notes show >actual &&
test_cmp expect actual &&
git show HEAD^ && git show HEAD^ &&
test_must_fail git notes show HEAD^ test_must_fail git notes show HEAD^
' '
@ -109,7 +120,9 @@ test_expect_success 'can overwrite existing note with "git notes add -f -m"' '
test_path_is_missing .git/NOTES_EDITMSG && test_path_is_missing .git/NOTES_EDITMSG &&
git ls-tree -r refs/notes/commits >actual && git ls-tree -r refs/notes/commits >actual &&
test_line_count = 1 actual && test_line_count = 1 actual &&
test "b1" = "$(git notes show)" && echo b1 >expect &&
git notes show >actual &&
test_cmp expect actual &&
git show HEAD^ && git show HEAD^ &&
test_must_fail git notes show HEAD^ test_must_fail git notes show HEAD^
' '
@ -119,7 +132,9 @@ test_expect_success 'add w/no options on existing note morphs into edit' '
test_path_is_missing .git/NOTES_EDITMSG && test_path_is_missing .git/NOTES_EDITMSG &&
git ls-tree -r refs/notes/commits >actual && git ls-tree -r refs/notes/commits >actual &&
test_line_count = 1 actual && test_line_count = 1 actual &&
test "b2" = "$(git notes show)" && echo b2 >expect &&
git notes show >actual &&
test_cmp expect actual &&
git show HEAD^ && git show HEAD^ &&
test_must_fail git notes show HEAD^ test_must_fail git notes show HEAD^
' '
@ -129,7 +144,9 @@ test_expect_success 'can overwrite existing note with "git notes add -f"' '
test_path_is_missing .git/NOTES_EDITMSG && test_path_is_missing .git/NOTES_EDITMSG &&
git ls-tree -r refs/notes/commits >actual && git ls-tree -r refs/notes/commits >actual &&
test_line_count = 1 actual && test_line_count = 1 actual &&
test "b1" = "$(git notes show)" && echo b1 >expect &&
git notes show >actual &&
test_cmp expect actual &&
git show HEAD^ && git show HEAD^ &&
test_must_fail git notes show HEAD^ test_must_fail git notes show HEAD^
' '
@ -146,7 +163,8 @@ test_expect_success 'show notes' '
Notes: Notes:
${indent}b1 ${indent}b1
EOF EOF
! (git cat-file commit HEAD | grep b1) && git cat-file commit HEAD >commits &&
! grep b1 commits &&
git log -1 >actual && git log -1 >actual &&
test_cmp expect actual test_cmp expect actual
' '
@ -472,9 +490,11 @@ test_expect_success 'removing with --stdin --ignore-missing' '
test_expect_success 'list notes with "git notes list"' ' test_expect_success 'list notes with "git notes list"' '
commit_2=$(git rev-parse 2nd) && commit_2=$(git rev-parse 2nd) &&
commit_3=$(git rev-parse 3rd) && commit_3=$(git rev-parse 3rd) &&
note_2=$(git rev-parse refs/notes/commits:$commit_2) &&
note_3=$(git rev-parse refs/notes/commits:$commit_3) &&
sort -t" " -k2 >expect <<-EOF && sort -t" " -k2 >expect <<-EOF &&
$(git rev-parse refs/notes/commits:$commit_2) $commit_2 $note_2 $commit_2
$(git rev-parse refs/notes/commits:$commit_3) $commit_3 $note_3 $commit_3
EOF EOF
git notes list >actual && git notes list >actual &&
test_cmp expect actual test_cmp expect actual
@ -486,9 +506,7 @@ test_expect_success 'list notes with "git notes"' '
' '
test_expect_success 'list specific note with "git notes list <object>"' ' test_expect_success 'list specific note with "git notes list <object>"' '
cat >expect <<-EOF && git rev-parse refs/notes/commits:$commit_3 >expect &&
$(git rev-parse refs/notes/commits:$commit_3)
EOF
git notes list HEAD^^ >actual && git notes list HEAD^^ >actual &&
test_cmp expect actual test_cmp expect actual
' '
@ -512,10 +530,11 @@ test_expect_success 'append to existing note with "git notes append"' '
test_expect_success '"git notes list" does not expand to "git notes list HEAD"' ' test_expect_success '"git notes list" does not expand to "git notes list HEAD"' '
commit_5=$(git rev-parse 5th) && commit_5=$(git rev-parse 5th) &&
note_5=$(git rev-parse refs/notes/commits:$commit_5) &&
sort -t" " -k2 >expect_list <<-EOF && sort -t" " -k2 >expect_list <<-EOF &&
$(git rev-parse refs/notes/commits:$commit_2) $commit_2 $note_2 $commit_2
$(git rev-parse refs/notes/commits:$commit_3) $commit_3 $note_3 $commit_3
$(git rev-parse refs/notes/commits:$commit_5) $commit_5 $note_5 $commit_5
EOF EOF
git notes list >actual && git notes list >actual &&
test_cmp expect_list actual test_cmp expect_list actual
@ -721,7 +740,8 @@ test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' '
git notes show HEAD: >actual && git notes show HEAD: >actual &&
test_cmp expect actual && test_cmp expect actual &&
echo "Note on a blob" >expect && echo "Note on a blob" >expect &&
filename=$(git ls-tree --name-only HEAD | head -n1) && git ls-tree --name-only HEAD >files &&
filename=$(head -n1 files) &&
git notes add -m "Note on a blob" HEAD:$filename && git notes add -m "Note on a blob" HEAD:$filename &&
git notes show HEAD:$filename >actual && git notes show HEAD:$filename >actual &&
test_cmp expect actual && test_cmp expect actual &&
@ -745,10 +765,13 @@ test_expect_success 'create note from other note with "git notes add -C"' '
Notes: Notes:
${indent}order test ${indent}order test
EOF EOF
git notes add -C $(git notes list HEAD^) && note=$(git notes list HEAD^) &&
git notes add -C $note &&
git log -1 >actual && git log -1 >actual &&
test_cmp expect actual && test_cmp expect actual &&
test "$(git notes list HEAD)" = "$(git notes list HEAD^)" git notes list HEAD^ >expect &&
git notes list HEAD >actual &&
test_cmp expect actual
' '
test_expect_success 'create note from non-existing note with "git notes add -C" fails' ' test_expect_success 'create note from non-existing note with "git notes add -C" fails' '
@ -777,11 +800,12 @@ test_expect_success 'create note from blob with "git notes add -C" reuses blob i
Notes: Notes:
${indent}This is a blob object ${indent}This is a blob object
EOF EOF
blob=$(echo "This is a blob object" | git hash-object -w --stdin) && echo "This is a blob object" | git hash-object -w --stdin >blob &&
git notes add -C $blob && git notes add -C $(cat blob) &&
git log -1 >actual && git log -1 >actual &&
test_cmp expect actual && test_cmp expect actual &&
test "$(git notes list HEAD)" = "$blob" git notes list HEAD >actual &&
test_cmp blob actual
' '
test_expect_success 'create note from other note with "git notes add -c"' ' test_expect_success 'create note from other note with "git notes add -c"' '
@ -797,7 +821,8 @@ test_expect_success 'create note from other note with "git notes add -c"' '
Notes: Notes:
${indent}yet another note ${indent}yet another note
EOF EOF
MSG="yet another note" git notes add -c $(git notes list HEAD^^) && note=$(git notes list HEAD^^) &&
MSG="yet another note" git notes add -c $note &&
git log -1 >actual && git log -1 >actual &&
test_cmp expect actual test_cmp expect actual
' '
@ -822,7 +847,8 @@ test_expect_success 'append to note from other note with "git notes append -C"'
${indent} ${indent}
${indent}yet another note ${indent}yet another note
EOF EOF
git notes append -C $(git notes list HEAD^) HEAD^ && note=$(git notes list HEAD^) &&
git notes append -C $note HEAD^ &&
git log -1 HEAD^ >actual && git log -1 HEAD^ >actual &&
test_cmp expect actual test_cmp expect actual
' '
@ -839,7 +865,8 @@ test_expect_success 'create note from other note with "git notes append -c"' '
Notes: Notes:
${indent}other note ${indent}other note
EOF EOF
MSG="other note" git notes append -c $(git notes list HEAD^) && note=$(git notes list HEAD^) &&
MSG="other note" git notes append -c $note &&
git log -1 >actual && git log -1 >actual &&
test_cmp expect actual test_cmp expect actual
' '
@ -858,7 +885,8 @@ test_expect_success 'append to note from other note with "git notes append -c"'
${indent} ${indent}
${indent}yet another note ${indent}yet another note
EOF EOF
MSG="yet another note" git notes append -c $(git notes list HEAD) && note=$(git notes list HEAD) &&
MSG="yet another note" git notes append -c $note &&
git log -1 >actual && git log -1 >actual &&
test_cmp expect actual test_cmp expect actual
' '
@ -878,7 +906,9 @@ test_expect_success 'copy note with "git notes copy"' '
git notes copy 8th 4th && git notes copy 8th 4th &&
git log 3rd..4th >actual && git log 3rd..4th >actual &&
test_cmp expect actual && test_cmp expect actual &&
test "$(git note list 4th)" = "$(git note list 8th)" git notes list 4th >expect &&
git notes list 8th >actual &&
test_cmp expect actual
' '
test_expect_success 'copy note with "git notes copy" with default' ' test_expect_success 'copy note with "git notes copy" with default' '
@ -899,14 +929,30 @@ test_expect_success 'copy note with "git notes copy" with default' '
git notes copy HEAD^ && git notes copy HEAD^ &&
git log -1 >actual && git log -1 >actual &&
test_cmp expect actual && test_cmp expect actual &&
test "$(git notes list HEAD)" = "$(git notes list HEAD^)" git notes list HEAD^ >expect &&
git notes list HEAD >actual &&
test_cmp expect actual
' '
test_expect_success 'prevent overwrite with "git notes copy"' ' test_expect_success 'prevent overwrite with "git notes copy"' '
test_must_fail git notes copy HEAD~2 HEAD && test_must_fail git notes copy HEAD~2 HEAD &&
cat >expect <<-EOF &&
commit $commit
Author: A U Thor <author@example.com>
Date: Thu Apr 7 15:23:13 2005 -0700
${indent}11th
Notes:
${indent}other note
${indent}
${indent}yet another note
EOF
git log -1 >actual && git log -1 >actual &&
test_cmp expect actual && test_cmp expect actual &&
test "$(git notes list HEAD)" = "$(git notes list HEAD^)" git notes list HEAD^ >expect &&
git notes list HEAD >actual &&
test_cmp expect actual
' '
test_expect_success 'allow overwrite with "git notes copy -f"' ' test_expect_success 'allow overwrite with "git notes copy -f"' '
@ -924,7 +970,9 @@ test_expect_success 'allow overwrite with "git notes copy -f"' '
git notes copy -f HEAD~3 HEAD && git notes copy -f HEAD~3 HEAD &&
git log -1 >actual && git log -1 >actual &&
test_cmp expect actual && test_cmp expect actual &&
test "$(git notes list HEAD)" = "$(git notes list HEAD~3)" git notes list HEAD~3 >expect &&
git notes list HEAD >actual &&
test_cmp expect actual
' '
test_expect_success 'allow overwrite with "git notes copy -f" with default' ' test_expect_success 'allow overwrite with "git notes copy -f" with default' '
@ -944,7 +992,9 @@ test_expect_success 'allow overwrite with "git notes copy -f" with default' '
git notes copy -f HEAD~2 && git notes copy -f HEAD~2 &&
git log -1 >actual && git log -1 >actual &&
test_cmp expect actual && test_cmp expect actual &&
test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" git notes list HEAD~2 >expect &&
git notes list HEAD >actual &&
test_cmp expect actual
' '
test_expect_success 'cannot copy note from object without notes' ' test_expect_success 'cannot copy note from object without notes' '
@ -979,13 +1029,21 @@ test_expect_success 'git notes copy --stdin' '
${indent} ${indent}
${indent}yet another note ${indent}yet another note
EOF EOF
(echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) && from=$(git rev-parse HEAD~3) &&
echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) | to=$(git rev-parse HEAD^) &&
git notes copy --stdin && echo "$from" "$to" >copy &&
from=$(git rev-parse HEAD~2) &&
to=$(git rev-parse HEAD) &&
echo "$from" "$to" >>copy &&
git notes copy --stdin <copy &&
git log -2 >actual && git log -2 >actual &&
test_cmp expect actual && test_cmp expect actual &&
test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" && git notes list HEAD~2 >expect &&
test "$(git notes list HEAD^)" = "$(git notes list HEAD~3)" git notes list HEAD >actual &&
test_cmp expect actual &&
git notes list HEAD~3 >expect &&
git notes list HEAD^ >actual &&
test_cmp expect actual
' '
test_expect_success 'git notes copy --for-rewrite (unconfigured)' ' test_expect_success 'git notes copy --for-rewrite (unconfigured)' '
@ -1006,9 +1064,13 @@ test_expect_success 'git notes copy --for-rewrite (unconfigured)' '
${indent}14th ${indent}14th
EOF EOF
(echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) && from=$(git rev-parse HEAD~3) &&
echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) | to=$(git rev-parse HEAD^) &&
git notes copy --for-rewrite=foo && echo "$from" "$to" >copy &&
from=$(git rev-parse HEAD~2) &&
to=$(git rev-parse HEAD) &&
echo "$from" "$to" >>copy &&
git notes copy --for-rewrite=foo <copy &&
git log -2 >actual && git log -2 >actual &&
test_cmp expect actual test_cmp expect actual
' '
@ -1041,17 +1103,23 @@ test_expect_success 'git notes copy --for-rewrite (enabled)' '
EOF EOF
test_config notes.rewriteMode overwrite && test_config notes.rewriteMode overwrite &&
test_config notes.rewriteRef "refs/notes/*" && test_config notes.rewriteRef "refs/notes/*" &&
(echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) && from=$(git rev-parse HEAD~3) &&
echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) | to=$(git rev-parse HEAD^) &&
git notes copy --for-rewrite=foo && echo "$from" "$to" >copy &&
from=$(git rev-parse HEAD~2) &&
to=$(git rev-parse HEAD) &&
echo "$from" "$to" >>copy &&
git notes copy --for-rewrite=foo <copy &&
git log -2 >actual && git log -2 >actual &&
test_cmp expect actual test_cmp expect actual
' '
test_expect_success 'git notes copy --for-rewrite (disabled)' ' test_expect_success 'git notes copy --for-rewrite (disabled)' '
test_config notes.rewrite.bar false && test_config notes.rewrite.bar false &&
echo $(git rev-parse HEAD~3) $(git rev-parse HEAD) | from=$(git rev-parse HEAD~3) &&
git notes copy --for-rewrite=bar && to=$(git rev-parse HEAD) &&
echo "$from" "$to" >copy &&
git notes copy --for-rewrite=bar <copy &&
git log -2 >actual && git log -2 >actual &&
test_cmp expect actual test_cmp expect actual
' '
@ -1071,8 +1139,10 @@ test_expect_success 'git notes copy --for-rewrite (overwrite)' '
git notes add -f -m"a fresh note" HEAD^ && git notes add -f -m"a fresh note" HEAD^ &&
test_config notes.rewriteMode overwrite && test_config notes.rewriteMode overwrite &&
test_config notes.rewriteRef "refs/notes/*" && test_config notes.rewriteRef "refs/notes/*" &&
echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | from=$(git rev-parse HEAD^) &&
git notes copy --for-rewrite=foo && to=$(git rev-parse HEAD) &&
echo "$from" "$to" >copy &&
git notes copy --for-rewrite=foo <copy &&
git log -1 >actual && git log -1 >actual &&
test_cmp expect actual test_cmp expect actual
' '
@ -1080,8 +1150,10 @@ test_expect_success 'git notes copy --for-rewrite (overwrite)' '
test_expect_success 'git notes copy --for-rewrite (ignore)' ' test_expect_success 'git notes copy --for-rewrite (ignore)' '
test_config notes.rewriteMode ignore && test_config notes.rewriteMode ignore &&
test_config notes.rewriteRef "refs/notes/*" && test_config notes.rewriteRef "refs/notes/*" &&
echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | from=$(git rev-parse HEAD^) &&
git notes copy --for-rewrite=foo && to=$(git rev-parse HEAD) &&
echo "$from" "$to" >copy &&
git notes copy --for-rewrite=foo <copy &&
git log -1 >actual && git log -1 >actual &&
test_cmp expect actual test_cmp expect actual
' '
@ -1103,8 +1175,10 @@ test_expect_success 'git notes copy --for-rewrite (append)' '
git notes add -f -m"another fresh note" HEAD^ && git notes add -f -m"another fresh note" HEAD^ &&
test_config notes.rewriteMode concatenate && test_config notes.rewriteMode concatenate &&
test_config notes.rewriteRef "refs/notes/*" && test_config notes.rewriteRef "refs/notes/*" &&
echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | from=$(git rev-parse HEAD^) &&
git notes copy --for-rewrite=foo && to=$(git rev-parse HEAD) &&
echo "$from" "$to" >copy &&
git notes copy --for-rewrite=foo <copy &&
git log -1 >actual && git log -1 >actual &&
test_cmp expect actual test_cmp expect actual
' '
@ -1131,9 +1205,13 @@ test_expect_success 'git notes copy --for-rewrite (append two to one)' '
git notes add -f -m"append 2" HEAD^^ && git notes add -f -m"append 2" HEAD^^ &&
test_config notes.rewriteMode concatenate && test_config notes.rewriteMode concatenate &&
test_config notes.rewriteRef "refs/notes/*" && test_config notes.rewriteRef "refs/notes/*" &&
(echo $(git rev-parse HEAD^) $(git rev-parse HEAD) && from=$(git rev-parse HEAD^) &&
echo $(git rev-parse HEAD^^) $(git rev-parse HEAD)) | to=$(git rev-parse HEAD) &&
git notes copy --for-rewrite=foo && echo "$from" "$to" >copy &&
from=$(git rev-parse HEAD^^) &&
to=$(git rev-parse HEAD) &&
echo "$from" "$to" >>copy &&
git notes copy --for-rewrite=foo <copy &&
git log -1 >actual && git log -1 >actual &&
test_cmp expect actual test_cmp expect actual
' '
@ -1142,8 +1220,10 @@ test_expect_success 'git notes copy --for-rewrite (append empty)' '
git notes remove HEAD^ && git notes remove HEAD^ &&
test_config notes.rewriteMode concatenate && test_config notes.rewriteMode concatenate &&
test_config notes.rewriteRef "refs/notes/*" && test_config notes.rewriteRef "refs/notes/*" &&
echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | from=$(git rev-parse HEAD^) &&
git notes copy --for-rewrite=foo && to=$(git rev-parse HEAD) &&
echo "$from" "$to" >copy &&
git notes copy --for-rewrite=foo <copy &&
git log -1 >actual && git log -1 >actual &&
test_cmp expect actual test_cmp expect actual
' '
@ -1163,8 +1243,10 @@ test_expect_success 'GIT_NOTES_REWRITE_MODE works' '
test_config notes.rewriteMode concatenate && test_config notes.rewriteMode concatenate &&
test_config notes.rewriteRef "refs/notes/*" && test_config notes.rewriteRef "refs/notes/*" &&
git notes add -f -m"replacement note 1" HEAD^ && git notes add -f -m"replacement note 1" HEAD^ &&
echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | from=$(git rev-parse HEAD^) &&
GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo && to=$(git rev-parse HEAD) &&
echo "$from" "$to" >copy &&
GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo <copy &&
git log -1 >actual && git log -1 >actual &&
test_cmp expect actual test_cmp expect actual
' '
@ -1184,9 +1266,11 @@ test_expect_success 'GIT_NOTES_REWRITE_REF works' '
git notes add -f -m"replacement note 2" HEAD^ && git notes add -f -m"replacement note 2" HEAD^ &&
test_config notes.rewriteMode overwrite && test_config notes.rewriteMode overwrite &&
test_unconfig notes.rewriteRef && test_unconfig notes.rewriteRef &&
echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | from=$(git rev-parse HEAD^) &&
to=$(git rev-parse HEAD) &&
echo "$from" "$to" >copy &&
GIT_NOTES_REWRITE_REF=refs/notes/commits:refs/notes/other \ GIT_NOTES_REWRITE_REF=refs/notes/commits:refs/notes/other \
git notes copy --for-rewrite=foo && git notes copy --for-rewrite=foo <copy &&
git log -1 >actual && git log -1 >actual &&
test_cmp expect actual test_cmp expect actual
' '
@ -1195,9 +1279,11 @@ test_expect_success 'GIT_NOTES_REWRITE_REF overrides config' '
git notes add -f -m"replacement note 3" HEAD^ && git notes add -f -m"replacement note 3" HEAD^ &&
test_config notes.rewriteMode overwrite && test_config notes.rewriteMode overwrite &&
test_config notes.rewriteRef refs/notes/other && test_config notes.rewriteRef refs/notes/other &&
echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | from=$(git rev-parse HEAD^) &&
to=$(git rev-parse HEAD) &&
echo "$from" "$to" >copy &&
GIT_NOTES_REWRITE_REF=refs/notes/commits \ GIT_NOTES_REWRITE_REF=refs/notes/commits \
git notes copy --for-rewrite=foo && git notes copy --for-rewrite=foo <copy &&
git log -1 >actual && git log -1 >actual &&
grep "replacement note 3" actual grep "replacement note 3" actual
' '
@ -1212,26 +1298,36 @@ test_expect_success 'git notes copy diagnoses too many or too few parameters' '
test_expect_success 'git notes get-ref expands refs/heads/master to refs/notes/refs/heads/master' ' test_expect_success 'git notes get-ref expands refs/heads/master to refs/notes/refs/heads/master' '
test_unconfig core.notesRef && test_unconfig core.notesRef &&
sane_unset GIT_NOTES_REF && sane_unset GIT_NOTES_REF &&
test "$(git notes --ref=refs/heads/master get-ref)" = "refs/notes/refs/heads/master" echo refs/notes/refs/heads/master >expect &&
git notes --ref=refs/heads/master get-ref >actual &&
test_cmp expect actual
' '
test_expect_success 'git notes get-ref (no overrides)' ' test_expect_success 'git notes get-ref (no overrides)' '
test_unconfig core.notesRef && test_unconfig core.notesRef &&
sane_unset GIT_NOTES_REF && sane_unset GIT_NOTES_REF &&
test "$(git notes get-ref)" = "refs/notes/commits" echo refs/notes/commits >expect &&
git notes get-ref >actual &&
test_cmp expect actual
' '
test_expect_success 'git notes get-ref (core.notesRef)' ' test_expect_success 'git notes get-ref (core.notesRef)' '
test_config core.notesRef refs/notes/foo && test_config core.notesRef refs/notes/foo &&
test "$(git notes get-ref)" = "refs/notes/foo" echo refs/notes/foo >expect &&
git notes get-ref >actual &&
test_cmp expect actual
' '
test_expect_success 'git notes get-ref (GIT_NOTES_REF)' ' test_expect_success 'git notes get-ref (GIT_NOTES_REF)' '
test "$(GIT_NOTES_REF=refs/notes/bar git notes get-ref)" = "refs/notes/bar" echo refs/notes/bar >expect &&
GIT_NOTES_REF=refs/notes/bar git notes get-ref >actual &&
test_cmp expect actual
' '
test_expect_success 'git notes get-ref (--ref)' ' test_expect_success 'git notes get-ref (--ref)' '
test "$(GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref)" = "refs/notes/baz" echo refs/notes/baz >expect &&
GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref >actual &&
test_cmp expect actual
' '
test_expect_success 'setup testing of empty notes' ' test_expect_success 'setup testing of empty notes' '

View File

@ -113,9 +113,10 @@ test_expect_success '"rm" command printed' '
echo frotz >test-file && echo frotz >test-file &&
git add test-file && git add test-file &&
git commit -m "add file for rm test" && git commit -m "add file for rm test" &&
git rm test-file >rm-output && git rm test-file >rm-output.raw &&
test $(grep "^rm " rm-output | wc -l) = 1 && grep "^rm " rm-output.raw >rm-output &&
rm -f test-file rm-output && test_line_count = 1 rm-output &&
rm -f test-file rm-output.raw rm-output &&
git commit -m "remove file from rm test" git commit -m "remove file from rm test"
' '
@ -250,6 +251,7 @@ test_expect_success 'choking "git rm" should not let it die with cruft' '
echo "100644 $hash 0 some-file-$i" echo "100644 $hash 0 some-file-$i"
i=$(( $i + 1 )) i=$(( $i + 1 ))
done | git update-index --index-info && done | git update-index --index-info &&
# git command is intentionally placed upstream of pipe to induce SIGPIPE
git rm -n "some-file-*" | : && git rm -n "some-file-*" | : &&
test_path_is_missing .git/index.lock test_path_is_missing .git/index.lock
' '
@ -303,7 +305,8 @@ EOF
test_expect_success 'rm removes empty submodules from work tree' ' test_expect_success 'rm removes empty submodules from work tree' '
mkdir submod && mkdir submod &&
git update-index --add --cacheinfo 160000 $(git rev-parse HEAD) submod && hash=$(git rev-parse HEAD) &&
git update-index --add --cacheinfo 160000 "$hash" submod &&
git config -f .gitmodules submodule.sub.url ./. && git config -f .gitmodules submodule.sub.url ./. &&
git config -f .gitmodules submodule.sub.path submod && git config -f .gitmodules submodule.sub.path submod &&
git submodule init && git submodule init &&
@ -622,7 +625,8 @@ test_expect_success 'setup subsubmodule' '
git submodule update && git submodule update &&
( (
cd submod && cd submod &&
git update-index --add --cacheinfo 160000 $(git rev-parse HEAD) subsubmod && hash=$(git rev-parse HEAD) &&
git update-index --add --cacheinfo 160000 "$hash" subsubmod &&
git config -f .gitmodules submodule.sub.url ../. && git config -f .gitmodules submodule.sub.url ../. &&
git config -f .gitmodules submodule.sub.path subsubmod && git config -f .gitmodules submodule.sub.path subsubmod &&
git submodule init && git submodule init &&

View File

@ -16,7 +16,8 @@ test_expect_success "Ray Lehtiniemi's example" '
} while (0); } while (0);
EOF EOF
git update-index --add x && git update-index --add x &&
before=$(git rev-parse --short $(git hash-object x)) && old_hash_x=$(git hash-object x) &&
before=$(git rev-parse --short "$old_hash_x") &&
cat <<-\EOF >x && cat <<-\EOF >x &&
do do
@ -25,7 +26,8 @@ test_expect_success "Ray Lehtiniemi's example" '
} }
while (0); while (0);
EOF EOF
after=$(git rev-parse --short $(git hash-object x)) && new_hash_x=$(git hash-object x) &&
after=$(git rev-parse --short "$new_hash_x") &&
cat <<-EOF >expect && cat <<-EOF >expect &&
diff --git a/x b/x diff --git a/x b/x
@ -63,7 +65,8 @@ test_expect_success 'another test, without options' '
EOF EOF
git update-index x && git update-index x &&
before=$(git rev-parse --short $(git hash-object x)) && old_hash_x=$(git hash-object x) &&
before=$(git rev-parse --short "$old_hash_x") &&
tr "_" " " <<-\EOF >x && tr "_" " " <<-\EOF >x &&
_ whitespace at beginning _ whitespace at beginning
@ -73,7 +76,8 @@ test_expect_success 'another test, without options' '
unchanged line unchanged line
CR at end CR at end
EOF EOF
after=$(git rev-parse --short $(git hash-object x)) && new_hash_x=$(git hash-object x) &&
after=$(git rev-parse --short "$new_hash_x") &&
tr "Q_" "\015 " <<-EOF >expect && tr "Q_" "\015 " <<-EOF >expect &&
diff --git a/x b/x diff --git a/x b/x
@ -526,13 +530,15 @@ test_expect_success 'ignore-blank-lines: mix changes and blank lines' '
test_expect_success 'check mixed spaces and tabs in indent' ' test_expect_success 'check mixed spaces and tabs in indent' '
# This is indented with SP HT SP. # This is indented with SP HT SP.
echo " foo();" >x && echo " foo();" >x &&
git diff --check | grep "space before tab in indent" test_must_fail git diff --check >check &&
grep "space before tab in indent" check
' '
test_expect_success 'check mixed tabs and spaces in indent' ' test_expect_success 'check mixed tabs and spaces in indent' '
# This is indented with HT SP HT. # This is indented with HT SP HT.
echo " foo();" >x && echo " foo();" >x &&
git diff --check | grep "space before tab in indent" test_must_fail git diff --check >check &&
grep "space before tab in indent" check
' '
test_expect_success 'check with no whitespace errors' ' test_expect_success 'check with no whitespace errors' '
@ -753,20 +759,23 @@ test_expect_success 'check tab-in-indent excluded from wildcard whitespace attri
test_expect_success 'line numbers in --check output are correct' ' test_expect_success 'line numbers in --check output are correct' '
echo "" >x && echo "" >x &&
echo "foo(); " >>x && echo "foo(); " >>x &&
git diff --check | grep "x:2:" test_must_fail git diff --check >check &&
grep "x:2:" check
' '
test_expect_success 'checkdiff detects new trailing blank lines (1)' ' test_expect_success 'checkdiff detects new trailing blank lines (1)' '
echo "foo();" >x && echo "foo();" >x &&
echo "" >>x && echo "" >>x &&
git diff --check | grep "new blank line" test_must_fail git diff --check >check &&
grep "new blank line" check
' '
test_expect_success 'checkdiff detects new trailing blank lines (2)' ' test_expect_success 'checkdiff detects new trailing blank lines (2)' '
{ echo a; echo b; echo; echo; } >x && test_write_lines a b "" "" >x &&
git add x && git add x &&
{ echo a; echo; echo; echo; echo; } >x && test_write_lines a "" "" "" "" >x &&
git diff --check | grep "new blank line" test_must_fail git diff --check >check &&
grep "new blank line" check
' '
test_expect_success 'checkdiff allows new blank lines' ' test_expect_success 'checkdiff allows new blank lines' '
@ -794,14 +803,16 @@ test_expect_success 'whitespace-only changes reported across renames' '
git reset --hard && git reset --hard &&
for i in 1 2 3 4 5 6 7 8 9; do echo "$i$i$i$i$i$i"; done >x && for i in 1 2 3 4 5 6 7 8 9; do echo "$i$i$i$i$i$i"; done >x &&
git add x && git add x &&
before=$(git rev-parse --short $(git hash-object x)) && hash_x=$(git hash-object x) &&
before=$(git rev-parse --short "$hash_x") &&
git commit -m "base" && git commit -m "base" &&
sed -e "5s/^/ /" x >z && sed -e "5s/^/ /" x >z &&
git rm x && git rm x &&
git add z && git add z &&
after=$(git rev-parse --short $(git hash-object z)) && hash_z=$(git hash-object z) &&
git diff -w -M --cached | after=$(git rev-parse --short "$hash_z") &&
sed -e "/^similarity index /s/[0-9][0-9]*/NUM/" >actual && git diff -w -M --cached >actual.raw &&
sed -e "/^similarity index /s/[0-9][0-9]*/NUM/" actual.raw >actual &&
cat <<-EOF >expect && cat <<-EOF >expect &&
diff --git a/x b/z diff --git a/x b/z
similarity index NUM% similarity index NUM%
@ -840,7 +851,8 @@ test_expect_success 'combined diff with autocrlf conversion' '
git config core.autocrlf true && git config core.autocrlf true &&
test_must_fail git merge master && test_must_fail git merge master &&
git diff | sed -e "1,/^@@@/d" >actual && git diff >actual.raw &&
sed -e "1,/^@@@/d" actual.raw >actual &&
! grep "^-" actual ! grep "^-" actual
' '
@ -864,11 +876,14 @@ test_expect_success 'diff that introduces a line with only tabs' '
git config core.whitespace blank-at-eol && git config core.whitespace blank-at-eol &&
git reset --hard && git reset --hard &&
echo "test" >x && echo "test" >x &&
before=$(git rev-parse --short $(git hash-object x)) && old_hash_x=$(git hash-object x) &&
before=$(git rev-parse --short "$old_hash_x") &&
git commit -m "initial" x && git commit -m "initial" x &&
echo "{NTN}" | tr "NT" "\n\t" >>x && echo "{NTN}" | tr "NT" "\n\t" >>x &&
after=$(git rev-parse --short $(git hash-object x)) && new_hash_x=$(git hash-object x) &&
git diff --color | test_decode_color >current && after=$(git rev-parse --short "$new_hash_x") &&
git diff --color >current.raw &&
test_decode_color <current.raw >current &&
cat >expected <<-EOF && cat >expected <<-EOF &&
<BOLD>diff --git a/x b/x<RESET> <BOLD>diff --git a/x b/x<RESET>
@ -891,17 +906,19 @@ test_expect_success 'diff that introduces and removes ws breakages' '
echo "0. blank-at-eol " && echo "0. blank-at-eol " &&
echo "1. blank-at-eol " echo "1. blank-at-eol "
} >x && } >x &&
before=$(git rev-parse --short $(git hash-object x)) && old_hash_x=$(git hash-object x) &&
before=$(git rev-parse --short "$old_hash_x") &&
git commit -a --allow-empty -m preimage && git commit -a --allow-empty -m preimage &&
{ {
echo "0. blank-at-eol " && echo "0. blank-at-eol " &&
echo "1. still-blank-at-eol " && echo "1. still-blank-at-eol " &&
echo "2. and a new line " echo "2. and a new line "
} >x && } >x &&
after=$(git rev-parse --short $(git hash-object x)) && new_hash_x=$(git hash-object x) &&
after=$(git rev-parse --short "$new_hash_x") &&
git diff --color | git diff --color >current.raw &&
test_decode_color >current && test_decode_color <current.raw >current &&
cat >expected <<-EOF && cat >expected <<-EOF &&
<BOLD>diff --git a/x b/x<RESET> <BOLD>diff --git a/x b/x<RESET>
@ -925,14 +942,16 @@ test_expect_success 'ws-error-highlight test setup' '
echo "0. blank-at-eol " && echo "0. blank-at-eol " &&
echo "1. blank-at-eol " echo "1. blank-at-eol "
} >x && } >x &&
before=$(git rev-parse --short $(git hash-object x)) && old_hash_x=$(git hash-object x) &&
before=$(git rev-parse --short "$old_hash_x") &&
git commit -a --allow-empty -m preimage && git commit -a --allow-empty -m preimage &&
{ {
echo "0. blank-at-eol " && echo "0. blank-at-eol " &&
echo "1. still-blank-at-eol " && echo "1. still-blank-at-eol " &&
echo "2. and a new line " echo "2. and a new line "
} >x && } >x &&
after=$(git rev-parse --short $(git hash-object x)) && new_hash_x=$(git hash-object x) &&
after=$(git rev-parse --short "$new_hash_x") &&
cat >expect.default-old <<-EOF && cat >expect.default-old <<-EOF &&
<BOLD>diff --git a/x b/x<RESET> <BOLD>diff --git a/x b/x<RESET>
@ -974,32 +993,32 @@ test_expect_success 'ws-error-highlight test setup' '
test_expect_success 'test --ws-error-highlight option' ' test_expect_success 'test --ws-error-highlight option' '
git diff --color --ws-error-highlight=default,old | git diff --color --ws-error-highlight=default,old >current.raw &&
test_decode_color >current && test_decode_color <current.raw >current &&
test_cmp expect.default-old current && test_cmp expect.default-old current &&
git diff --color --ws-error-highlight=all | git diff --color --ws-error-highlight=all >current.raw &&
test_decode_color >current && test_decode_color <current.raw >current &&
test_cmp expect.all current && test_cmp expect.all current &&
git diff --color --ws-error-highlight=none | git diff --color --ws-error-highlight=none >current.raw &&
test_decode_color >current && test_decode_color <current.raw >current &&
test_cmp expect.none current test_cmp expect.none current
' '
test_expect_success 'test diff.wsErrorHighlight config' ' test_expect_success 'test diff.wsErrorHighlight config' '
git -c diff.wsErrorHighlight=default,old diff --color | git -c diff.wsErrorHighlight=default,old diff --color >current.raw &&
test_decode_color >current && test_decode_color <current.raw >current &&
test_cmp expect.default-old current && test_cmp expect.default-old current &&
git -c diff.wsErrorHighlight=all diff --color | git -c diff.wsErrorHighlight=all diff --color >current.raw &&
test_decode_color >current && test_decode_color <current.raw >current &&
test_cmp expect.all current && test_cmp expect.all current &&
git -c diff.wsErrorHighlight=none diff --color | git -c diff.wsErrorHighlight=none diff --color >current.raw &&
test_decode_color >current && test_decode_color <current.raw >current &&
test_cmp expect.none current test_cmp expect.none current
' '
@ -1007,18 +1026,18 @@ test_expect_success 'test diff.wsErrorHighlight config' '
test_expect_success 'option overrides diff.wsErrorHighlight' ' test_expect_success 'option overrides diff.wsErrorHighlight' '
git -c diff.wsErrorHighlight=none \ git -c diff.wsErrorHighlight=none \
diff --color --ws-error-highlight=default,old | diff --color --ws-error-highlight=default,old >current.raw &&
test_decode_color >current && test_decode_color <current.raw >current &&
test_cmp expect.default-old current && test_cmp expect.default-old current &&
git -c diff.wsErrorHighlight=default \ git -c diff.wsErrorHighlight=default \
diff --color --ws-error-highlight=all | diff --color --ws-error-highlight=all >current.raw &&
test_decode_color >current && test_decode_color <current.raw >current &&
test_cmp expect.all current && test_cmp expect.all current &&
git -c diff.wsErrorHighlight=all \ git -c diff.wsErrorHighlight=all \
diff --color --ws-error-highlight=none | diff --color --ws-error-highlight=none >current.raw &&
test_decode_color >current && test_decode_color <current.raw >current &&
test_cmp expect.none current test_cmp expect.none current
' '
@ -1038,7 +1057,8 @@ test_expect_success 'detect moved code, complete file' '
git mv test.c main.c && git mv test.c main.c &&
test_config color.diff.oldMoved "normal red" && test_config color.diff.oldMoved "normal red" &&
test_config color.diff.newMoved "normal green" && test_config color.diff.newMoved "normal green" &&
git diff HEAD --color-moved=zebra --color --no-renames | test_decode_color >actual && git diff HEAD --color-moved=zebra --color --no-renames >actual.raw &&
test_decode_color <actual.raw >actual &&
cat >expected <<-EOF && cat >expected <<-EOF &&
<BOLD>diff --git a/main.c b/main.c<RESET> <BOLD>diff --git a/main.c b/main.c<RESET>
<BOLD>new file mode 100644<RESET> <BOLD>new file mode 100644<RESET>
@ -1141,9 +1161,12 @@ test_expect_success 'detect malicious moved code, inside file' '
bar(); bar();
} }
EOF EOF
after_main=$(git rev-parse --short $(git hash-object main.c)) && hash_main=$(git hash-object main.c) &&
after_test=$(git rev-parse --short $(git hash-object test.c)) && after_main=$(git rev-parse --short "$hash_main") &&
git diff HEAD --no-renames --color-moved=zebra --color | test_decode_color >actual && hash_test=$(git hash-object test.c) &&
after_test=$(git rev-parse --short "$hash_test") &&
git diff HEAD --no-renames --color-moved=zebra --color >actual.raw &&
test_decode_color <actual.raw >actual &&
cat <<-EOF >expected && cat <<-EOF >expected &&
<BOLD>diff --git a/main.c b/main.c<RESET> <BOLD>diff --git a/main.c b/main.c<RESET>
<BOLD>index $before_main..$after_main 100644<RESET> <BOLD>index $before_main..$after_main 100644<RESET>
@ -1192,7 +1215,8 @@ test_expect_success 'plain moved code, inside file' '
test_config color.diff.oldMovedAlternative "blue" && test_config color.diff.oldMovedAlternative "blue" &&
test_config color.diff.newMovedAlternative "yellow" && test_config color.diff.newMovedAlternative "yellow" &&
# needs previous test as setup # needs previous test as setup
git diff HEAD --no-renames --color-moved=plain --color | test_decode_color >actual && git diff HEAD --no-renames --color-moved=plain --color >actual.raw &&
test_decode_color <actual.raw >actual &&
cat <<-EOF >expected && cat <<-EOF >expected &&
<BOLD>diff --git a/main.c b/main.c<RESET> <BOLD>diff --git a/main.c b/main.c<RESET>
<BOLD>index $before_main..$after_main 100644<RESET> <BOLD>index $before_main..$after_main 100644<RESET>
@ -1771,7 +1795,8 @@ test_expect_success 'move detection with submodules' '
! grep BRED decoded_actual && ! grep BRED decoded_actual &&
# nor did we mess with it another way # nor did we mess with it another way
git diff --submodule=diff --color | test_decode_color >expect && git diff --submodule=diff --color >expect.raw &&
test_decode_color <expect.raw >expect &&
test_cmp expect decoded_actual && test_cmp expect decoded_actual &&
rm -rf bananas && rm -rf bananas &&
git submodule deinit bananas git submodule deinit bananas

View File

@ -17,8 +17,8 @@ test_expect_success setup '
printf "\t%s\n" 1 2 3 >after && printf "\t%s\n" 1 2 3 >after &&
printf "%64s\n" a b c >>after && printf "%64s\n" a b c >>after &&
printf "\t%s\n" 4 5 6 >>after && printf "\t%s\n" 4 5 6 >>after &&
git diff --no-index before after | test_expect_code 1 git diff --no-index before after >patch1.patch.raw &&
sed -e "s/before/test-1/" -e "s/after/test-1/" >patch1.patch && sed -e "s/before/test-1/" -e "s/after/test-1/" patch1.patch.raw >patch1.patch &&
printf "%64s\n" 1 2 3 4 5 6 >test-1 && printf "%64s\n" 1 2 3 4 5 6 >test-1 &&
printf "%64s\n" 1 2 3 a b c 4 5 6 >expect-1 && printf "%64s\n" 1 2 3 a b c 4 5 6 >expect-1 &&
@ -33,8 +33,8 @@ test_expect_success setup '
x=$(( $x + 1 )) x=$(( $x + 1 ))
done && done &&
printf "\t%s\n" d e f >>after && printf "\t%s\n" d e f >>after &&
git diff --no-index before after | test_expect_code 1 git diff --no-index before after >patch2.patch.raw &&
sed -e "s/before/test-2/" -e "s/after/test-2/" >patch2.patch && sed -e "s/before/test-2/" -e "s/after/test-2/" patch2.patch.raw >patch2.patch &&
printf "%64s\n" a b c d e f >test-2 && printf "%64s\n" a b c d e f >test-2 &&
printf "%64s\n" a b c >expect-2 && printf "%64s\n" a b c >expect-2 &&
x=1 && x=1 &&
@ -56,8 +56,8 @@ test_expect_success setup '
x=$(( $x + 1 )) x=$(( $x + 1 ))
done && done &&
printf "\t%s\n" d e f >>after && printf "\t%s\n" d e f >>after &&
git diff --no-index before after | test_expect_code 1 git diff --no-index before after >patch3.patch.raw &&
sed -e "s/before/test-3/" -e "s/after/test-3/" >patch3.patch && sed -e "s/before/test-3/" -e "s/after/test-3/" patch3.patch.raw >patch3.patch &&
printf "%64s\n" a b c d e f >test-3 && printf "%64s\n" a b c d e f >test-3 &&
printf "%64s\n" a b c >expect-3 && printf "%64s\n" a b c >expect-3 &&
x=0 && x=0 &&
@ -84,8 +84,8 @@ test_expect_success setup '
printf "\t%02d\n" $x >>after printf "\t%02d\n" $x >>after
x=$(( $x + 1 )) x=$(( $x + 1 ))
done && done &&
git diff --no-index before after | test_expect_code 1 git diff --no-index before after >patch4.patch.raw &&
sed -e "s/before/test-4/" -e "s/after/test-4/" >patch4.patch && sed -e "s/before/test-4/" -e "s/after/test-4/" patch4.patch.raw >patch4.patch &&
>test-4 && >test-4 &&
x=0 && x=0 &&
while test $x -lt 50 while test $x -lt 50

View File

@ -45,12 +45,7 @@ test_expect_success 'verify blob:none packfile has no blobs' '
git -C r1 index-pack ../filter.pack && git -C r1 index-pack ../filter.pack &&
git -C r1 verify-pack -v ../filter.pack >verify_result && git -C r1 verify-pack -v ../filter.pack >verify_result &&
grep blob verify_result | ! grep blob verify_result
awk -f print_1.awk |
sort >observed &&
nr=$(wc -l <observed) &&
test 0 -eq $nr
' '
test_expect_success 'verify normal and blob:none packfiles have same commits/trees' ' test_expect_success 'verify normal and blob:none packfiles have same commits/trees' '
@ -72,7 +67,8 @@ test_expect_success 'get an error for missing tree object' '
echo foo >r5/foo && echo foo >r5/foo &&
git -C r5 add foo && git -C r5 add foo &&
git -C r5 commit -m "foo" && git -C r5 commit -m "foo" &&
del=$(git -C r5 rev-parse HEAD^{tree} | sed "s|..|&/|") && git -C r5 rev-parse HEAD^{tree} >tree &&
del=$(sed "s|..|&/|" tree) &&
rm r5/.git/objects/$del && rm r5/.git/objects/$del &&
test_must_fail git -C r5 pack-objects --revs --stdout 2>bad_tree <<-EOF && test_must_fail git -C r5 pack-objects --revs --stdout 2>bad_tree <<-EOF &&
HEAD HEAD
@ -148,12 +144,7 @@ test_expect_success 'verify blob:limit=500 omits all blobs' '
git -C r2 index-pack ../filter.pack && git -C r2 index-pack ../filter.pack &&
git -C r2 verify-pack -v ../filter.pack >verify_result && git -C r2 verify-pack -v ../filter.pack >verify_result &&
grep blob verify_result | ! grep blob verify_result
awk -f print_1.awk |
sort >observed &&
nr=$(wc -l <observed) &&
test 0 -eq $nr
' '
test_expect_success 'verify blob:limit=1000' ' test_expect_success 'verify blob:limit=1000' '
@ -163,12 +154,7 @@ test_expect_success 'verify blob:limit=1000' '
git -C r2 index-pack ../filter.pack && git -C r2 index-pack ../filter.pack &&
git -C r2 verify-pack -v ../filter.pack >verify_result && git -C r2 verify-pack -v ../filter.pack >verify_result &&
grep blob verify_result | ! grep blob verify_result
awk -f print_1.awk |
sort >observed &&
nr=$(wc -l <observed) &&
test 0 -eq $nr
' '
test_expect_success 'verify blob:limit=1001' ' test_expect_success 'verify blob:limit=1001' '
@ -230,10 +216,9 @@ test_expect_success 'verify explicitly specifying oversized blob in input' '
awk -f print_2.awk ls_files_result | awk -f print_2.awk ls_files_result |
sort >expected && sort >expected &&
git -C r2 pack-objects --revs --stdout --filter=blob:limit=1k >filter.pack <<-EOF && echo HEAD >objects &&
HEAD git -C r2 rev-parse HEAD:large.10000 >>objects &&
$(git -C r2 rev-parse HEAD:large.10000) git -C r2 pack-objects --revs --stdout --filter=blob:limit=1k <objects >filter.pack &&
EOF
git -C r2 index-pack ../filter.pack && git -C r2 index-pack ../filter.pack &&
git -C r2 verify-pack -v ../filter.pack >verify_result && git -C r2 verify-pack -v ../filter.pack >verify_result &&
@ -377,7 +362,8 @@ test_expect_success 'verify sparse:oid=OID' '
awk -f print_2.awk ls_files_result | awk -f print_2.awk ls_files_result |
sort >expected && sort >expected &&
oid=$(git -C r4 ls-files -s pattern | awk -f print_2.awk) && git -C r4 ls-files -s pattern >staged &&
oid=$(awk -f print_2.awk staged) &&
git -C r4 pack-objects --revs --stdout --filter=sparse:oid=$oid >filter.pack <<-EOF && git -C r4 pack-objects --revs --stdout --filter=sparse:oid=$oid >filter.pack <<-EOF &&
HEAD HEAD
EOF EOF

View File

@ -18,14 +18,16 @@ get_actual_commits () {
p p
}' <out | test-tool pkt-line unpack-sideband >o.pack && }' <out | test-tool pkt-line unpack-sideband >o.pack &&
git index-pack o.pack && git index-pack o.pack &&
git verify-pack -v o.idx | grep commit | cut -c-40 | sort >actual_commits git verify-pack -v o.idx >objs &&
grep commit objs | cut -c-40 | sort >actual_commits
} }
check_output () { check_output () {
get_actual_refs && get_actual_refs &&
test_cmp expected_refs actual_refs && test_cmp expected_refs actual_refs &&
get_actual_commits && get_actual_commits &&
test_cmp expected_commits actual_commits sort expected_commits >sorted_commits &&
test_cmp sorted_commits actual_commits
} }
# c(o/foo) d(o/bar) # c(o/foo) d(o/bar)
@ -75,17 +77,19 @@ test_expect_success 'invalid want-ref line' '
' '
test_expect_success 'basic want-ref' ' test_expect_success 'basic want-ref' '
oid=$(git rev-parse f) &&
cat >expected_refs <<-EOF && cat >expected_refs <<-EOF &&
$(git rev-parse f) refs/heads/master $oid refs/heads/master
EOF EOF
git rev-parse f | sort >expected_commits && git rev-parse f >expected_commits &&
oid=$(git rev-parse a) &&
test-tool pkt-line pack >in <<-EOF && test-tool pkt-line pack >in <<-EOF &&
command=fetch command=fetch
0001 0001
no-progress no-progress
want-ref refs/heads/master want-ref refs/heads/master
have $(git rev-parse a) have $oid
done done
0000 0000
EOF EOF
@ -95,19 +99,22 @@ test_expect_success 'basic want-ref' '
' '
test_expect_success 'multiple want-ref lines' ' test_expect_success 'multiple want-ref lines' '
oid_c=$(git rev-parse c) &&
oid_d=$(git rev-parse d) &&
cat >expected_refs <<-EOF && cat >expected_refs <<-EOF &&
$(git rev-parse c) refs/heads/o/foo $oid_c refs/heads/o/foo
$(git rev-parse d) refs/heads/o/bar $oid_d refs/heads/o/bar
EOF EOF
git rev-parse c d | sort >expected_commits && git rev-parse c d >expected_commits &&
oid=$(git rev-parse b) &&
test-tool pkt-line pack >in <<-EOF && test-tool pkt-line pack >in <<-EOF &&
command=fetch command=fetch
0001 0001
no-progress no-progress
want-ref refs/heads/o/foo want-ref refs/heads/o/foo
want-ref refs/heads/o/bar want-ref refs/heads/o/bar
have $(git rev-parse b) have $oid
done done
0000 0000
EOF EOF
@ -117,10 +124,11 @@ test_expect_success 'multiple want-ref lines' '
' '
test_expect_success 'mix want and want-ref' ' test_expect_success 'mix want and want-ref' '
oid=$(git rev-parse f) &&
cat >expected_refs <<-EOF && cat >expected_refs <<-EOF &&
$(git rev-parse f) refs/heads/master $oid refs/heads/master
EOF EOF
git rev-parse e f | sort >expected_commits && git rev-parse e f >expected_commits &&
test-tool pkt-line pack >in <<-EOF && test-tool pkt-line pack >in <<-EOF &&
command=fetch command=fetch
@ -138,17 +146,19 @@ test_expect_success 'mix want and want-ref' '
' '
test_expect_success 'want-ref with ref we already have commit for' ' test_expect_success 'want-ref with ref we already have commit for' '
oid=$(git rev-parse c) &&
cat >expected_refs <<-EOF && cat >expected_refs <<-EOF &&
$(git rev-parse c) refs/heads/o/foo $oid refs/heads/o/foo
EOF EOF
>expected_commits && >expected_commits &&
oid=$(git rev-parse c) &&
test-tool pkt-line pack >in <<-EOF && test-tool pkt-line pack >in <<-EOF &&
command=fetch command=fetch
0001 0001
no-progress no-progress
want-ref refs/heads/o/foo want-ref refs/heads/o/foo
have $(git rev-parse c) have $oid
done done
0000 0000
EOF EOF
@ -211,13 +221,14 @@ test_expect_success 'fetching with exact OID' '
rm -rf local && rm -rf local &&
cp -r "$LOCAL_PRISTINE" local && cp -r "$LOCAL_PRISTINE" local &&
oid=$(git -C "$REPO" rev-parse d) &&
GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin \ GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin \
$(git -C "$REPO" rev-parse d):refs/heads/actual && "$oid":refs/heads/actual &&
git -C "$REPO" rev-parse "d" >expected && git -C "$REPO" rev-parse "d" >expected &&
git -C local rev-parse refs/heads/actual >actual && git -C local rev-parse refs/heads/actual >actual &&
test_cmp expected actual && test_cmp expected actual &&
grep "want $(git -C "$REPO" rev-parse d)" log grep "want $oid" log
' '
test_expect_success 'fetching multiple refs' ' test_expect_success 'fetching multiple refs' '
@ -239,13 +250,14 @@ test_expect_success 'fetching ref and exact OID' '
rm -rf local && rm -rf local &&
cp -r "$LOCAL_PRISTINE" local && cp -r "$LOCAL_PRISTINE" local &&
oid=$(git -C "$REPO" rev-parse b) &&
GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin \ GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin \
master $(git -C "$REPO" rev-parse b):refs/heads/actual && master "$oid":refs/heads/actual &&
git -C "$REPO" rev-parse "master" "b" >expected && git -C "$REPO" rev-parse "master" "b" >expected &&
git -C local rev-parse refs/remotes/origin/master refs/heads/actual >actual && git -C local rev-parse refs/remotes/origin/master refs/heads/actual >actual &&
test_cmp expected actual && test_cmp expected actual &&
grep "want $(git -C "$REPO" rev-parse b)" log && grep "want $oid" log &&
grep "want-ref refs/heads/master" log grep "want-ref refs/heads/master" log
' '
@ -312,10 +324,9 @@ inconsistency () {
# repository appears to change during negotiation, for example, when # repository appears to change during negotiation, for example, when
# different servers in a load-balancing arrangement serve (stateless) # different servers in a load-balancing arrangement serve (stateless)
# RPCs during a single negotiation. # RPCs during a single negotiation.
printf "s/%s/%s/" \ oid1=$(git -C "$REPO" rev-parse $1) &&
$(git -C "$REPO" rev-parse $1 | tr -d "\n") \ oid2=$(git -C "$REPO" rev-parse $2) &&
$(git -C "$REPO" rev-parse $2 | tr -d "\n") \ echo "s/$oid1/$oid2/" >"$HTTPD_ROOT_PATH/one-time-sed"
>"$HTTPD_ROOT_PATH/one-time-sed"
} }
test_expect_success 'server is initially ahead - no ref in want' ' test_expect_success 'server is initially ahead - no ref in want' '

View File

@ -150,7 +150,7 @@ test_expect_success 'setup: commit message from file' '
test_expect_success 'amend commit' ' test_expect_success 'amend commit' '
cat >editor <<-\EOF && cat >editor <<-\EOF &&
#!/bin/sh #!/bin/sh
sed -e "s/a file/an amend commit/g" < "$1" > "$1-" sed -e "s/a file/an amend commit/g" <"$1" >"$1-"
mv "$1-" "$1" mv "$1-" "$1"
EOF EOF
chmod 755 editor && chmod 755 editor &&
@ -263,7 +263,7 @@ test_expect_success 'using message from other commit' '
test_expect_success 'editing message from other commit' ' test_expect_success 'editing message from other commit' '
cat >editor <<-\EOF && cat >editor <<-\EOF &&
#!/bin/sh #!/bin/sh
sed -e "s/amend/older/g" < "$1" > "$1-" sed -e "s/amend/older/g" <"$1" >"$1-"
mv "$1-" "$1" mv "$1-" "$1"
EOF EOF
chmod 755 editor && chmod 755 editor &&
@ -285,9 +285,8 @@ test_expect_success 'overriding author from command line' '
' '
test_expect_success PERL 'interactive add' ' test_expect_success PERL 'interactive add' '
echo 7 | echo 7 | test_must_fail git commit --interactive >out &&
git commit --interactive | grep "What now" out
grep "What now"
' '
test_expect_success PERL "commit --interactive doesn't change index if editor aborts" ' test_expect_success PERL "commit --interactive doesn't change index if editor aborts" '
@ -362,12 +361,12 @@ test_expect_success 'amend commit to fix author' '
oldtick=$GIT_AUTHOR_DATE && oldtick=$GIT_AUTHOR_DATE &&
test_tick && test_tick &&
git reset --hard && git reset --hard &&
git cat-file -p HEAD | git cat-file -p HEAD >commit &&
sed -e "s/author.*/author $author $oldtick/" \ sed -e "s/author.*/author $author $oldtick/" \
-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \ -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" \
expected && commit >expected &&
git commit --amend --author="$author" && git commit --amend --author="$author" &&
git cat-file -p HEAD > current && git cat-file -p HEAD >current &&
test_cmp expected current test_cmp expected current
' '
@ -377,12 +376,12 @@ test_expect_success 'amend commit to fix date' '
test_tick && test_tick &&
newtick=$GIT_AUTHOR_DATE && newtick=$GIT_AUTHOR_DATE &&
git reset --hard && git reset --hard &&
git cat-file -p HEAD | git cat-file -p HEAD >commit &&
sed -e "s/author.*/author $author $newtick/" \ sed -e "s/author.*/author $author $newtick/" \
-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \ -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" \
expected && commit >expected &&
git commit --amend --date="$newtick" && git commit --amend --date="$newtick" &&
git cat-file -p HEAD > current && git cat-file -p HEAD >current &&
test_cmp expected current test_cmp expected current
' '
@ -409,12 +408,13 @@ test_expect_success 'sign off (1)' '
echo 1 >positive && echo 1 >positive &&
git add positive && git add positive &&
git commit -s -m "thank you" && git commit -s -m "thank you" &&
git cat-file commit HEAD | sed -e "1,/^\$/d" >actual && git cat-file commit HEAD >commit &&
sed -e "1,/^\$/d" commit >actual &&
( (
echo thank you && echo thank you &&
echo && echo &&
git var GIT_COMMITTER_IDENT | git var GIT_COMMITTER_IDENT >ident &&
sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident
) >expected && ) >expected &&
test_cmp expected actual test_cmp expected actual
@ -428,13 +428,14 @@ test_expect_success 'sign off (2)' '
git commit -s -m "thank you git commit -s -m "thank you
$existing" && $existing" &&
git cat-file commit HEAD | sed -e "1,/^\$/d" >actual && git cat-file commit HEAD >commit &&
sed -e "1,/^\$/d" commit >actual &&
( (
echo thank you && echo thank you &&
echo && echo &&
echo $existing && echo $existing &&
git var GIT_COMMITTER_IDENT | git var GIT_COMMITTER_IDENT >ident &&
sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident
) >expected && ) >expected &&
test_cmp expected actual test_cmp expected actual
@ -448,13 +449,14 @@ test_expect_success 'signoff gap' '
git commit -s -m "welcome git commit -s -m "welcome
$alt" && $alt" &&
git cat-file commit HEAD | sed -e "1,/^\$/d" > actual && git cat-file commit HEAD >commit &&
sed -e "1,/^\$/d" commit >actual &&
( (
echo welcome && echo welcome &&
echo && echo &&
echo $alt && echo $alt &&
git var GIT_COMMITTER_IDENT | git var GIT_COMMITTER_IDENT >ident &&
sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident
) >expected && ) >expected &&
test_cmp expected actual test_cmp expected actual
' '
@ -468,15 +470,16 @@ test_expect_success 'signoff gap 2' '
We have now We have now
$alt" && $alt" &&
git cat-file commit HEAD | sed -e "1,/^\$/d" > actual && git cat-file commit HEAD >commit &&
sed -e "1,/^\$/d" commit >actual &&
( (
echo welcome && echo welcome &&
echo && echo &&
echo We have now && echo We have now &&
echo $alt && echo $alt &&
echo && echo &&
git var GIT_COMMITTER_IDENT | git var GIT_COMMITTER_IDENT >ident &&
sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident
) >expected && ) >expected &&
test_cmp expected actual test_cmp expected actual
' '
@ -489,7 +492,8 @@ test_expect_success 'signoff respects trailer config' '
non-trailer line non-trailer line
Myfooter: x" && Myfooter: x" &&
git cat-file commit HEAD | sed -e "1,/^\$/d" > actual && git cat-file commit HEAD >commit &&
sed -e "1,/^\$/d" commit >actual &&
( (
echo subject && echo subject &&
echo && echo &&
@ -506,7 +510,8 @@ Myfooter: x" &&
non-trailer line non-trailer line
Myfooter: x" && Myfooter: x" &&
git cat-file commit HEAD | sed -e "1,/^\$/d" > actual && git cat-file commit HEAD >commit &&
sed -e "1,/^\$/d" commit >actual &&
( (
echo subject && echo subject &&
echo && echo &&
@ -538,7 +543,8 @@ test_expect_success 'multiple -m' '
>negative && >negative &&
git add negative && git add negative &&
git commit -m "one" -m "two" -m "three" && git commit -m "one" -m "two" -m "three" &&
git cat-file commit HEAD | sed -e "1,/^\$/d" >actual && git cat-file commit HEAD >commit &&
sed -e "1,/^\$/d" commit >actual &&
( (
echo one && echo one &&
echo && echo &&
@ -555,23 +561,25 @@ test_expect_success 'amend commit to fix author' '
oldtick=$GIT_AUTHOR_DATE && oldtick=$GIT_AUTHOR_DATE &&
test_tick && test_tick &&
git reset --hard && git reset --hard &&
git cat-file -p HEAD | git cat-file -p HEAD >commit &&
sed -e "s/author.*/author $author $oldtick/" \ sed -e "s/author.*/author $author $oldtick/" \
-e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \ -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" \
expected && commit >expected &&
git commit --amend --author="$author" && git commit --amend --author="$author" &&
git cat-file -p HEAD > current && git cat-file -p HEAD >current &&
test_cmp expected current test_cmp expected current
' '
test_expect_success 'git commit <file> with dirty index' ' test_expect_success 'git commit <file> with dirty index' '
echo tacocat > elif && echo tacocat >elif &&
echo tehlulz > chz && echo tehlulz >chz &&
git add chz && git add chz &&
git commit elif -m "tacocat is a palindrome" && git commit elif -m "tacocat is a palindrome" &&
git show --stat | grep elif && git show --stat >stat &&
git diff --cached | grep chz grep elif stat &&
git diff --cached >diff &&
grep chz diff
' '
test_expect_success 'same tree (single parent)' ' test_expect_success 'same tree (single parent)' '
@ -584,7 +592,8 @@ test_expect_success 'same tree (single parent)' '
test_expect_success 'same tree (single parent) --allow-empty' ' test_expect_success 'same tree (single parent) --allow-empty' '
git commit --allow-empty -m "forced empty" && git commit --allow-empty -m "forced empty" &&
git cat-file commit HEAD | grep forced git cat-file commit HEAD >commit &&
grep forced commit
' '

View File

@ -4,129 +4,104 @@ test_description='git repack works correctly'
. ./test-lib.sh . ./test-lib.sh
commit_and_pack() { commit_and_pack () {
test_commit "$@" >/dev/null && test_commit "$@" 1>&2 &&
SHA1=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) && incrpackid=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) &&
echo pack-${SHA1}.pack echo pack-${incrpackid}.pack
}
test_no_missing_in_packs () {
myidx=$(ls -1 .git/objects/pack/*.idx) &&
test_path_is_file "$myidx" &&
git verify-pack -v alt_objects/pack/*.idx >orig.raw &&
sed -n -e "s/^\($OID_REGEX\).*/\1/p" orig.raw | sort >orig &&
git verify-pack -v $myidx >dest.raw &&
cut -d" " -f1 dest.raw | sort >dest &&
comm -23 orig dest >missing &&
test_must_be_empty missing
}
# we expect $packid and $oid to be defined
test_has_duplicate_object () {
want_duplicate_object="$1"
found_duplicate_object=false
for p in .git/objects/pack/*.idx
do
idx=$(basename $p)
test "pack-$packid.idx" = "$idx" && continue
git verify-pack -v $p >packlist || return $?
if grep "^$oid" packlist
then
found_duplicate_object=true
echo "DUPLICATE OBJECT FOUND"
break
fi
done &&
test "$want_duplicate_object" = "$found_duplicate_object"
} }
test_expect_success 'objects in packs marked .keep are not repacked' ' test_expect_success 'objects in packs marked .keep are not repacked' '
echo content1 > file1 && echo content1 >file1 &&
echo content2 > file2 && echo content2 >file2 &&
git add . && git add . &&
test_tick && test_tick &&
git commit -m initial_commit && git commit -m initial_commit &&
# Create two packs # Create two packs
# The first pack will contain all of the objects except one # The first pack will contain all of the objects except one
git rev-list --objects --all | grep -v file2 | git rev-list --objects --all >objs &&
git pack-objects pack > /dev/null && grep -v file2 objs | git pack-objects pack &&
# The second pack will contain the excluded object # The second pack will contain the excluded object
packsha1=$(git rev-list --objects --all | grep file2 | packid=$(grep file2 objs | git pack-objects pack) &&
git pack-objects pack) && >pack-$packid.keep &&
>pack-$packsha1.keep && git verify-pack -v pack-$packid.idx >packlist &&
objsha1=$(git verify-pack -v pack-$packsha1.idx | head -n 1 | oid=$(head -n 1 packlist | sed -e "s/^\($OID_REGEX\).*/\1/") &&
sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") &&
mv pack-* .git/objects/pack/ && mv pack-* .git/objects/pack/ &&
git repack -A -d -l && git repack -A -d -l &&
git prune-packed && git prune-packed &&
for p in .git/objects/pack/*.idx; do test_has_duplicate_object false
idx=$(basename $p)
test "pack-$packsha1.idx" = "$idx" && continue
if git verify-pack -v $p | egrep "^$objsha1"; then
found_duplicate_object=1
echo "DUPLICATE OBJECT FOUND"
break
fi
done &&
test -z "$found_duplicate_object"
' '
test_expect_success 'writing bitmaps via command-line can duplicate .keep objects' ' test_expect_success 'writing bitmaps via command-line can duplicate .keep objects' '
# build on $objsha1, $packsha1, and .keep state from previous # build on $oid, $packid, and .keep state from previous
git repack -Adbl && git repack -Adbl &&
test_when_finished "found_duplicate_object=" && test_has_duplicate_object true
for p in .git/objects/pack/*.idx; do
idx=$(basename $p)
test "pack-$packsha1.idx" = "$idx" && continue
if git verify-pack -v $p | egrep "^$objsha1"; then
found_duplicate_object=1
echo "DUPLICATE OBJECT FOUND"
break
fi
done &&
test "$found_duplicate_object" = 1
' '
test_expect_success 'writing bitmaps via config can duplicate .keep objects' ' test_expect_success 'writing bitmaps via config can duplicate .keep objects' '
# build on $objsha1, $packsha1, and .keep state from previous # build on $oid, $packid, and .keep state from previous
git -c repack.writebitmaps=true repack -Adl && git -c repack.writebitmaps=true repack -Adl &&
test_when_finished "found_duplicate_object=" && test_has_duplicate_object true
for p in .git/objects/pack/*.idx; do
idx=$(basename $p)
test "pack-$packsha1.idx" = "$idx" && continue
if git verify-pack -v $p | egrep "^$objsha1"; then
found_duplicate_object=1
echo "DUPLICATE OBJECT FOUND"
break
fi
done &&
test "$found_duplicate_object" = 1
' '
test_expect_success 'loose objects in alternate ODB are not repacked' ' test_expect_success 'loose objects in alternate ODB are not repacked' '
mkdir alt_objects && mkdir alt_objects &&
echo $(pwd)/alt_objects > .git/objects/info/alternates && echo $(pwd)/alt_objects >.git/objects/info/alternates &&
echo content3 > file3 && echo content3 >file3 &&
objsha1=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) && oid=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) &&
git add file3 && git add file3 &&
test_tick && test_tick &&
git commit -m commit_file3 && git commit -m commit_file3 &&
git repack -a -d -l && git repack -a -d -l &&
git prune-packed && git prune-packed &&
for p in .git/objects/pack/*.idx; do test_has_duplicate_object false
if git verify-pack -v $p | egrep "^$objsha1"; then
found_duplicate_object=1
echo "DUPLICATE OBJECT FOUND"
break
fi
done &&
test -z "$found_duplicate_object"
' '
test_expect_success 'packed obs in alt ODB are repacked even when local repo is packless' ' test_expect_success 'packed obs in alt ODB are repacked even when local repo is packless' '
mkdir alt_objects/pack && mkdir alt_objects/pack &&
mv .git/objects/pack/* alt_objects/pack && mv .git/objects/pack/* alt_objects/pack &&
git repack -a && git repack -a &&
myidx=$(ls -1 .git/objects/pack/*.idx) && test_no_missing_in_packs
test -f "$myidx" &&
for p in alt_objects/pack/*.idx; do
git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
done | while read sha1 rest; do
if ! ( git verify-pack -v $myidx | grep "^$sha1" ); then
echo "Missing object in local pack: $sha1"
return 1
fi
done
' '
test_expect_success 'packed obs in alt ODB are repacked when local repo has packs' ' test_expect_success 'packed obs in alt ODB are repacked when local repo has packs' '
rm -f .git/objects/pack/* && rm -f .git/objects/pack/* &&
echo new_content >> file1 && echo new_content >>file1 &&
git add file1 && git add file1 &&
test_tick && test_tick &&
git commit -m more_content && git commit -m more_content &&
git repack && git repack &&
git repack -a -d && git repack -a -d &&
myidx=$(ls -1 .git/objects/pack/*.idx) && test_no_missing_in_packs
test -f "$myidx" &&
for p in alt_objects/pack/*.idx; do
git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
done | while read sha1 rest; do
if ! ( git verify-pack -v $myidx | grep "^$sha1" ); then
echo "Missing object in local pack: $sha1"
return 1
fi
done
' '
test_expect_success 'packed obs in alternate ODB kept pack are repacked' ' test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
@ -134,7 +109,7 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
for p in alt_objects/pack/*.pack for p in alt_objects/pack/*.pack
do do
base_name=$(basename $p .pack) && base_name=$(basename $p .pack) &&
if test -f alt_objects/pack/$base_name.keep if test_path_is_file alt_objects/pack/$base_name.keep
then then
rm alt_objects/pack/$base_name.keep rm alt_objects/pack/$base_name.keep
else else
@ -142,22 +117,13 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
fi fi
done && done &&
git repack -a -d && git repack -a -d &&
myidx=$(ls -1 .git/objects/pack/*.idx) && test_no_missing_in_packs
test -f "$myidx" &&
for p in alt_objects/pack/*.idx; do
git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
done | while read sha1 rest; do
if ! ( git verify-pack -v $myidx | grep "^$sha1" ); then
echo "Missing object in local pack: $sha1"
return 1
fi
done
' '
test_expect_success 'packed unreachable obs in alternate ODB are not loosened' ' test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
rm -f alt_objects/pack/*.keep && rm -f alt_objects/pack/*.keep &&
mv .git/objects/pack/* alt_objects/pack/ && mv .git/objects/pack/* alt_objects/pack/ &&
csha1=$(git rev-parse HEAD^{commit}) && coid=$(git rev-parse HEAD^{commit}) &&
git reset --hard HEAD^ && git reset --hard HEAD^ &&
test_tick && test_tick &&
git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all && git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
@ -167,15 +133,15 @@ test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
--unpack-unreachable </dev/null pack && --unpack-unreachable </dev/null pack &&
rm -f .git/objects/pack/* && rm -f .git/objects/pack/* &&
mv pack-* .git/objects/pack/ && mv pack-* .git/objects/pack/ &&
test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | git verify-pack -v -- .git/objects/pack/*.idx >packlist &&
egrep "^$csha1 " | sort | uniq | wc -l) && ! grep "^$coid " packlist &&
echo > .git/objects/info/alternates && echo >.git/objects/info/alternates &&
test_must_fail git show $csha1 test_must_fail git show $coid
' '
test_expect_success 'local packed unreachable obs that exist in alternate ODB are not loosened' ' test_expect_success 'local packed unreachable obs that exist in alternate ODB are not loosened' '
echo $(pwd)/alt_objects > .git/objects/info/alternates && echo $(pwd)/alt_objects >.git/objects/info/alternates &&
echo "$csha1" | git pack-objects --non-empty --all --reflog pack && echo "$coid" | git pack-objects --non-empty --all --reflog pack &&
rm -f .git/objects/pack/* && rm -f .git/objects/pack/* &&
mv pack-* .git/objects/pack/ && mv pack-* .git/objects/pack/ &&
# The pack-objects call on the next line is equivalent to # The pack-objects call on the next line is equivalent to
@ -184,10 +150,10 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar
--unpack-unreachable </dev/null pack && --unpack-unreachable </dev/null pack &&
rm -f .git/objects/pack/* && rm -f .git/objects/pack/* &&
mv pack-* .git/objects/pack/ && mv pack-* .git/objects/pack/ &&
test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | git verify-pack -v -- .git/objects/pack/*.idx >packlist &&
egrep "^$csha1 " | sort | uniq | wc -l) && ! grep "^$coid " &&
echo > .git/objects/info/alternates && echo >.git/objects/info/alternates &&
test_must_fail git show $csha1 test_must_fail git show $coid
' '
test_expect_success 'objects made unreachable by grafts only are kept' ' test_expect_success 'objects made unreachable by grafts only are kept' '
@ -196,7 +162,7 @@ test_expect_success 'objects made unreachable by grafts only are kept' '
H0=$(git rev-parse HEAD) && H0=$(git rev-parse HEAD) &&
H1=$(git rev-parse HEAD^) && H1=$(git rev-parse HEAD^) &&
H2=$(git rev-parse HEAD^^) && H2=$(git rev-parse HEAD^^) &&
echo "$H0 $H2" > .git/info/grafts && echo "$H0 $H2" >.git/info/grafts &&
git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all && git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
git repack -a -d && git repack -a -d &&
git cat-file -t $H1 git cat-file -t $H1
@ -235,7 +201,7 @@ test_expect_success 'incremental repack does not complain' '
test_expect_success 'bitmaps can be disabled on bare repos' ' test_expect_success 'bitmaps can be disabled on bare repos' '
git -c repack.writeBitmaps=false -C bare.git repack -ad && git -c repack.writeBitmaps=false -C bare.git repack -ad &&
bitmap=$(ls bare.git/objects/pack/*.bitmap 2>/dev/null || :) && bitmap=$(ls bare.git/objects/pack/*.bitmap || :) &&
test -z "$bitmap" test -z "$bitmap"
' '