2009-10-09 12:21:58 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2007 Johannes E. Schindelin
|
|
|
|
#
|
|
|
|
|
|
|
|
test_description='Test commit notes'
|
|
|
|
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
write_script fake_editor <<\EOF
|
|
|
|
echo "$MSG" >"$1"
|
|
|
|
echo "$MSG" >&2
|
2009-10-09 12:21:58 +02:00
|
|
|
EOF
|
2014-11-12 01:40:16 +01:00
|
|
|
GIT_EDITOR=./fake_editor
|
2010-02-13 22:28:20 +01:00
|
|
|
export GIT_EDITOR
|
2009-10-09 12:21:58 +02:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
indent=" "
|
|
|
|
|
2009-10-09 12:21:58 +02:00
|
|
|
test_expect_success 'cannot annotate non-existing HEAD' '
|
2014-03-18 19:54:05 +01:00
|
|
|
test_must_fail env MSG=3 git notes add
|
2009-10-09 12:21:58 +02:00
|
|
|
'
|
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
test_expect_success 'setup' '
|
|
|
|
test_commit 1st &&
|
|
|
|
test_commit 2nd
|
2009-10-09 12:21:58 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'need valid notes ref' '
|
2014-03-18 19:54:05 +01:00
|
|
|
test_must_fail env MSG=1 GIT_NOTES_REF=/ git notes show &&
|
|
|
|
test_must_fail env MSG=2 GIT_NOTES_REF=/ git notes show
|
2009-10-09 12:21:58 +02:00
|
|
|
'
|
|
|
|
|
2010-02-13 22:28:32 +01:00
|
|
|
test_expect_success 'refusing to add notes in refs/heads/' '
|
2014-03-18 19:54:05 +01:00
|
|
|
test_must_fail env MSG=1 GIT_NOTES_REF=refs/heads/bogus git notes add
|
2009-10-09 12:21:58 +02:00
|
|
|
'
|
|
|
|
|
2010-02-13 22:28:32 +01:00
|
|
|
test_expect_success 'refusing to edit notes in refs/remotes/' '
|
2014-03-18 19:54:05 +01:00
|
|
|
test_must_fail env MSG=1 GIT_NOTES_REF=refs/heads/bogus git notes edit
|
2009-10-09 12:21:58 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
# 1 indicates caught gracefully by die, 128 means git-show barked
|
|
|
|
test_expect_success 'handle empty notes gracefully' '
|
2010-10-31 08:36:57 +01:00
|
|
|
test_expect_code 1 git notes show
|
2009-10-09 12:21:58 +02:00
|
|
|
'
|
|
|
|
|
2010-04-18 20:19:39 +02:00
|
|
|
test_expect_success 'show non-existent notes entry with %N' '
|
2014-11-12 01:40:16 +01:00
|
|
|
test_write_lines A B >expect &&
|
|
|
|
git show -s --format="A%n%NB" >actual &&
|
|
|
|
test_cmp expect actual
|
2010-04-18 20:19:39 +02:00
|
|
|
'
|
|
|
|
|
2009-10-09 12:21:58 +02:00
|
|
|
test_expect_success 'create notes' '
|
2010-02-13 22:28:32 +01:00
|
|
|
MSG=b4 git notes add &&
|
2014-11-12 01:40:16 +01:00
|
|
|
test_path_is_missing .git/NOTES_EDITMSG &&
|
|
|
|
git ls-tree -r refs/notes/commits >actual &&
|
|
|
|
test_line_count = 1 actual &&
|
2019-11-27 20:53:13 +01:00
|
|
|
echo b4 >expect &&
|
|
|
|
git notes show >actual &&
|
|
|
|
test_cmp expect actual &&
|
2010-02-13 22:28:20 +01:00
|
|
|
git show HEAD^ &&
|
|
|
|
test_must_fail git notes show HEAD^
|
|
|
|
'
|
|
|
|
|
2010-04-18 20:19:39 +02:00
|
|
|
test_expect_success 'show notes entry with %N' '
|
2014-11-12 01:40:16 +01:00
|
|
|
test_write_lines A b4 B >expect &&
|
|
|
|
git show -s --format="A%n%NB" >actual &&
|
|
|
|
test_cmp expect actual
|
2010-04-18 20:19:39 +02:00
|
|
|
'
|
|
|
|
|
2010-03-29 15:05:58 +02:00
|
|
|
test_expect_success 'create reflog entry' '
|
2019-08-18 21:16:35 +02:00
|
|
|
ref=$(git rev-parse --short refs/notes/commits) &&
|
2014-11-12 01:40:16 +01:00
|
|
|
cat <<-EOF >expect &&
|
2019-08-18 21:16:35 +02:00
|
|
|
$ref refs/notes/commits@{0}: notes: Notes added by '\''git notes add'\''
|
2014-11-12 01:40:16 +01:00
|
|
|
EOF
|
|
|
|
git reflog show refs/notes/commits >actual &&
|
|
|
|
test_cmp expect actual
|
2010-03-29 15:05:57 +02:00
|
|
|
'
|
|
|
|
|
2010-02-13 22:28:20 +01:00
|
|
|
test_expect_success 'edit existing notes' '
|
2010-02-13 22:28:32 +01:00
|
|
|
MSG=b3 git notes edit &&
|
2014-11-12 01:40:16 +01:00
|
|
|
test_path_is_missing .git/NOTES_EDITMSG &&
|
|
|
|
git ls-tree -r refs/notes/commits >actual &&
|
|
|
|
test_line_count = 1 actual &&
|
2019-11-27 20:53:13 +01:00
|
|
|
echo b3 >expect &&
|
|
|
|
git notes show >actual &&
|
|
|
|
test_cmp expect actual &&
|
2010-02-13 22:28:32 +01:00
|
|
|
git show HEAD^ &&
|
|
|
|
test_must_fail git notes show HEAD^
|
|
|
|
'
|
|
|
|
|
2015-10-08 04:54:43 +02:00
|
|
|
test_expect_success 'show notes from treeish' '
|
2019-11-27 20:53:13 +01:00
|
|
|
echo b3 >expect &&
|
|
|
|
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
|
2015-10-08 04:54:43 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'cannot edit notes from non-ref' '
|
|
|
|
test_must_fail git notes --ref commits^{tree} edit &&
|
|
|
|
test_must_fail git notes --ref commits@{1} edit
|
|
|
|
'
|
|
|
|
|
2011-03-30 02:02:55 +02:00
|
|
|
test_expect_success 'cannot "git notes add -m" where notes already exists' '
|
|
|
|
test_must_fail git notes add -m "b2" &&
|
2014-11-12 01:40:16 +01:00
|
|
|
test_path_is_missing .git/NOTES_EDITMSG &&
|
|
|
|
git ls-tree -r refs/notes/commits >actual &&
|
|
|
|
test_line_count = 1 actual &&
|
2019-11-27 20:53:13 +01:00
|
|
|
echo b3 >expect &&
|
|
|
|
git notes show >actual &&
|
|
|
|
test_cmp expect actual &&
|
2010-02-13 22:28:32 +01:00
|
|
|
git show HEAD^ &&
|
|
|
|
test_must_fail git notes show HEAD^
|
|
|
|
'
|
|
|
|
|
2011-03-30 02:02:55 +02:00
|
|
|
test_expect_success 'can overwrite existing note with "git notes add -f -m"' '
|
|
|
|
git notes add -f -m "b1" &&
|
2014-11-12 01:40:16 +01:00
|
|
|
test_path_is_missing .git/NOTES_EDITMSG &&
|
|
|
|
git ls-tree -r refs/notes/commits >actual &&
|
|
|
|
test_line_count = 1 actual &&
|
2019-11-27 20:53:13 +01:00
|
|
|
echo b1 >expect &&
|
|
|
|
git notes show >actual &&
|
|
|
|
test_cmp expect actual &&
|
2011-03-30 02:02:55 +02:00
|
|
|
git show HEAD^ &&
|
|
|
|
test_must_fail git notes show HEAD^
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'add w/no options on existing note morphs into edit' '
|
|
|
|
MSG=b2 git notes add &&
|
2014-11-12 01:40:16 +01:00
|
|
|
test_path_is_missing .git/NOTES_EDITMSG &&
|
|
|
|
git ls-tree -r refs/notes/commits >actual &&
|
|
|
|
test_line_count = 1 actual &&
|
2019-11-27 20:53:13 +01:00
|
|
|
echo b2 >expect &&
|
|
|
|
git notes show >actual &&
|
|
|
|
test_cmp expect actual &&
|
2011-03-30 02:02:55 +02:00
|
|
|
git show HEAD^ &&
|
|
|
|
test_must_fail git notes show HEAD^
|
|
|
|
'
|
|
|
|
|
2010-02-13 22:28:32 +01:00
|
|
|
test_expect_success 'can overwrite existing note with "git notes add -f"' '
|
|
|
|
MSG=b1 git notes add -f &&
|
2014-11-12 01:40:16 +01:00
|
|
|
test_path_is_missing .git/NOTES_EDITMSG &&
|
|
|
|
git ls-tree -r refs/notes/commits >actual &&
|
|
|
|
test_line_count = 1 actual &&
|
2019-11-27 20:53:13 +01:00
|
|
|
echo b1 >expect &&
|
|
|
|
git notes show >actual &&
|
|
|
|
test_cmp expect actual &&
|
2009-10-09 12:21:58 +02:00
|
|
|
git show HEAD^ &&
|
|
|
|
test_must_fail git notes show HEAD^
|
|
|
|
'
|
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
test_expect_success 'show notes' '
|
2019-08-18 21:16:35 +02:00
|
|
|
commit=$(git rev-parse HEAD) &&
|
2014-11-12 01:40:16 +01:00
|
|
|
cat >expect <<-EOF &&
|
2019-08-18 21:16:35 +02:00
|
|
|
commit $commit
|
2014-11-12 01:40:16 +01:00
|
|
|
Author: A U Thor <author@example.com>
|
|
|
|
Date: Thu Apr 7 15:14:13 2005 -0700
|
2009-10-09 12:21:58 +02:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
${indent}2nd
|
2009-10-09 12:21:58 +02:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
Notes:
|
|
|
|
${indent}b1
|
|
|
|
EOF
|
2019-11-27 20:53:13 +01:00
|
|
|
git cat-file commit HEAD >commits &&
|
|
|
|
! grep b1 commits &&
|
2014-11-12 01:40:16 +01:00
|
|
|
git log -1 >actual &&
|
|
|
|
test_cmp expect actual
|
2009-10-09 12:21:58 +02:00
|
|
|
'
|
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
test_expect_success 'show multi-line notes' '
|
|
|
|
test_commit 3rd &&
|
|
|
|
MSG="b3${LF}c3c3c3c3${LF}d3d3d3" git notes add &&
|
2019-08-18 21:16:35 +02:00
|
|
|
commit=$(git rev-parse HEAD) &&
|
2014-11-12 01:40:16 +01:00
|
|
|
cat >expect-multiline <<-EOF &&
|
2019-08-18 21:16:35 +02:00
|
|
|
commit $commit
|
2014-11-12 01:40:16 +01:00
|
|
|
Author: A U Thor <author@example.com>
|
|
|
|
Date: Thu Apr 7 15:15:13 2005 -0700
|
2009-10-09 12:21:58 +02:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
${indent}3rd
|
2009-10-09 12:21:58 +02:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
Notes:
|
|
|
|
${indent}b3
|
|
|
|
${indent}c3c3c3c3
|
|
|
|
${indent}d3d3d3
|
2009-10-09 12:21:58 +02:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
EOF
|
|
|
|
cat expect >>expect-multiline &&
|
|
|
|
git log -2 >actual &&
|
|
|
|
test_cmp expect-multiline actual
|
2009-10-09 12:21:58 +02:00
|
|
|
'
|
2009-10-09 12:22:01 +02:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
test_expect_success 'show -F notes' '
|
|
|
|
test_commit 4th &&
|
|
|
|
echo "xyzzy" >note5 &&
|
|
|
|
git notes add -F note5 &&
|
2019-08-18 21:16:35 +02:00
|
|
|
commit=$(git rev-parse HEAD) &&
|
2014-11-12 01:40:16 +01:00
|
|
|
cat >expect-F <<-EOF &&
|
2019-08-18 21:16:35 +02:00
|
|
|
commit $commit
|
2014-11-12 01:40:16 +01:00
|
|
|
Author: A U Thor <author@example.com>
|
|
|
|
Date: Thu Apr 7 15:16:13 2005 -0700
|
2009-10-09 12:22:01 +02:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
${indent}4th
|
2009-10-09 12:22:01 +02:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
Notes:
|
|
|
|
${indent}xyzzy
|
2009-10-09 12:22:01 +02:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
EOF
|
|
|
|
cat expect-multiline >>expect-F &&
|
|
|
|
git log -3 >actual &&
|
|
|
|
test_cmp expect-F actual
|
2009-10-09 12:22:01 +02:00
|
|
|
'
|
2009-10-09 12:21:58 +02:00
|
|
|
|
2011-03-30 02:02:55 +02:00
|
|
|
test_expect_success 'Re-adding -F notes without -f fails' '
|
2014-11-12 01:40:16 +01:00
|
|
|
echo "zyxxy" >note5 &&
|
2011-03-30 02:02:55 +02:00
|
|
|
test_must_fail git notes add -F note5 &&
|
2014-11-12 01:40:16 +01:00
|
|
|
git log -3 >actual &&
|
|
|
|
test_cmp expect-F actual
|
2011-03-30 02:02:55 +02:00
|
|
|
'
|
|
|
|
|
2010-01-20 22:59:36 +01:00
|
|
|
test_expect_success 'git log --pretty=raw does not show notes' '
|
2019-08-18 21:16:35 +02:00
|
|
|
commit=$(git rev-parse HEAD) &&
|
|
|
|
tree=$(git rev-parse HEAD^{tree}) &&
|
|
|
|
parent=$(git rev-parse HEAD^) &&
|
2014-11-12 01:40:16 +01:00
|
|
|
cat >expect <<-EOF &&
|
2019-08-18 21:16:35 +02:00
|
|
|
commit $commit
|
|
|
|
tree $tree
|
|
|
|
parent $parent
|
2014-11-12 01:40:16 +01:00
|
|
|
author A U Thor <author@example.com> 1112912173 -0700
|
|
|
|
committer C O Mitter <committer@example.com> 1112912173 -0700
|
|
|
|
|
|
|
|
${indent}4th
|
|
|
|
EOF
|
|
|
|
git log -1 --pretty=raw >actual &&
|
|
|
|
test_cmp expect actual
|
2010-01-20 22:59:36 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'git log --show-notes' '
|
2014-11-12 01:40:16 +01:00
|
|
|
cat >>expect <<-EOF &&
|
|
|
|
|
|
|
|
Notes:
|
|
|
|
${indent}xyzzy
|
|
|
|
EOF
|
|
|
|
git log -1 --pretty=raw --show-notes >actual &&
|
|
|
|
test_cmp expect actual
|
2010-01-20 22:59:36 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'git log --no-notes' '
|
2014-11-12 01:40:16 +01:00
|
|
|
git log -1 --no-notes >actual &&
|
|
|
|
! grep xyzzy actual
|
2010-01-20 22:59:36 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'git format-patch does not show notes' '
|
2014-11-12 01:40:16 +01:00
|
|
|
git format-patch -1 --stdout >actual &&
|
|
|
|
! grep xyzzy actual
|
2010-01-20 22:59:36 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'git format-patch --show-notes does show notes' '
|
2014-11-12 01:40:16 +01:00
|
|
|
git format-patch --show-notes -1 --stdout >actual &&
|
|
|
|
grep xyzzy actual
|
2010-01-20 22:59:36 +01:00
|
|
|
'
|
|
|
|
|
2010-01-21 23:57:41 +01:00
|
|
|
for pretty in \
|
|
|
|
"" --pretty --pretty=raw --pretty=short --pretty=medium \
|
|
|
|
--pretty=full --pretty=fuller --pretty=format:%s --oneline
|
2010-01-20 22:59:36 +01:00
|
|
|
do
|
|
|
|
case "$pretty" in
|
|
|
|
"") p= not= negate="" ;;
|
2010-01-21 23:57:41 +01:00
|
|
|
?*) p="$pretty" not=" not" negate="!" ;;
|
2010-01-20 22:59:36 +01:00
|
|
|
esac
|
|
|
|
test_expect_success "git show $pretty does$not show notes" '
|
2014-11-12 01:40:16 +01:00
|
|
|
git show $p >actual &&
|
|
|
|
eval "$negate grep xyzzy actual"
|
2010-01-20 22:59:36 +01:00
|
|
|
'
|
|
|
|
done
|
|
|
|
|
2011-03-29 22:57:47 +02:00
|
|
|
test_expect_success 'setup alternate notes ref' '
|
|
|
|
git notes --ref=alternate add -m alternate
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'git log --notes shows default notes' '
|
2014-11-12 01:40:16 +01:00
|
|
|
git log -1 --notes >actual &&
|
|
|
|
grep xyzzy actual &&
|
|
|
|
! grep alternate actual
|
2011-03-29 22:57:47 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'git log --notes=X shows only X' '
|
2014-11-12 01:40:16 +01:00
|
|
|
git log -1 --notes=alternate >actual &&
|
|
|
|
! grep xyzzy actual &&
|
|
|
|
grep alternate actual
|
2011-03-29 22:57:47 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'git log --notes --notes=X shows both' '
|
2014-11-12 01:40:16 +01:00
|
|
|
git log -1 --notes --notes=alternate >actual &&
|
|
|
|
grep xyzzy actual &&
|
|
|
|
grep alternate actual
|
2011-03-29 22:57:47 +02:00
|
|
|
'
|
|
|
|
|
2011-03-29 22:59:42 +02:00
|
|
|
test_expect_success 'git log --no-notes resets default state' '
|
|
|
|
git log -1 --notes --notes=alternate \
|
|
|
|
--no-notes --notes=alternate \
|
2014-11-12 01:40:16 +01:00
|
|
|
>actual &&
|
|
|
|
! grep xyzzy actual &&
|
|
|
|
grep alternate actual
|
2011-03-29 22:59:42 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'git log --no-notes resets ref list' '
|
|
|
|
git log -1 --notes --notes=alternate \
|
|
|
|
--no-notes --notes \
|
2014-11-12 01:40:16 +01:00
|
|
|
>actual &&
|
|
|
|
grep xyzzy actual &&
|
|
|
|
! grep alternate actual
|
2010-02-13 22:28:20 +01:00
|
|
|
'
|
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
test_expect_success 'show -m notes' '
|
|
|
|
test_commit 5th &&
|
|
|
|
git notes add -m spam -m "foo${LF}bar${LF}baz" &&
|
2019-08-18 21:16:35 +02:00
|
|
|
commit=$(git rev-parse HEAD) &&
|
2014-11-12 01:40:16 +01:00
|
|
|
cat >expect-m <<-EOF &&
|
2019-08-18 21:16:35 +02:00
|
|
|
commit $commit
|
2014-11-12 01:40:16 +01:00
|
|
|
Author: A U Thor <author@example.com>
|
|
|
|
Date: Thu Apr 7 15:17:13 2005 -0700
|
|
|
|
|
|
|
|
${indent}5th
|
|
|
|
|
|
|
|
Notes:
|
|
|
|
${indent}spam
|
|
|
|
${indent}
|
|
|
|
${indent}foo
|
|
|
|
${indent}bar
|
|
|
|
${indent}baz
|
|
|
|
|
|
|
|
EOF
|
|
|
|
cat expect-F >>expect-m &&
|
|
|
|
git log -4 >actual &&
|
|
|
|
test_cmp expect-m actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'remove note with add -f -F /dev/null' '
|
|
|
|
git notes add -f -F /dev/null &&
|
2019-08-18 21:16:35 +02:00
|
|
|
commit=$(git rev-parse HEAD) &&
|
2014-11-12 01:40:16 +01:00
|
|
|
cat >expect-rm-F <<-EOF &&
|
2019-08-18 21:16:35 +02:00
|
|
|
commit $commit
|
2014-11-12 01:40:16 +01:00
|
|
|
Author: A U Thor <author@example.com>
|
|
|
|
Date: Thu Apr 7 15:17:13 2005 -0700
|
|
|
|
|
|
|
|
${indent}5th
|
|
|
|
|
|
|
|
EOF
|
|
|
|
cat expect-F >>expect-rm-F &&
|
|
|
|
git log -4 >actual &&
|
|
|
|
test_cmp expect-rm-F actual &&
|
2010-07-21 01:18:34 +02:00
|
|
|
test_must_fail git notes show
|
2010-02-13 22:28:24 +01:00
|
|
|
'
|
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
test_expect_success 'do not create empty note with -m ""' '
|
|
|
|
git notes add -m "" &&
|
|
|
|
git log -4 >actual &&
|
|
|
|
test_cmp expect-rm-F actual &&
|
2010-07-21 01:18:34 +02:00
|
|
|
test_must_fail git notes show
|
2010-02-13 22:28:24 +01:00
|
|
|
'
|
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
test_expect_success 'create note with combination of -m and -F' '
|
|
|
|
cat >expect-combine_m_and_F <<-EOF &&
|
|
|
|
foo
|
2010-02-13 22:28:35 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
xyzzy
|
2010-02-13 22:28:35 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
bar
|
2010-02-13 22:28:35 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
zyxxy
|
2010-02-13 22:28:35 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
baz
|
|
|
|
EOF
|
|
|
|
echo "xyzzy" >note_a &&
|
|
|
|
echo "zyxxy" >note_b &&
|
2010-02-13 22:28:35 +01:00
|
|
|
git notes add -m "foo" -F note_a -m "bar" -F note_b -m "baz" &&
|
2014-11-12 01:40:16 +01:00
|
|
|
git notes show >actual &&
|
|
|
|
test_cmp expect-combine_m_and_F actual
|
2010-02-13 22:28:35 +01:00
|
|
|
'
|
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
test_expect_success 'remove note with "git notes remove"' '
|
2010-02-13 22:28:35 +01:00
|
|
|
git notes remove HEAD^ &&
|
2014-11-12 01:40:16 +01:00
|
|
|
git notes remove &&
|
2019-08-18 21:16:35 +02:00
|
|
|
commit=$(git rev-parse HEAD) &&
|
|
|
|
parent=$(git rev-parse HEAD^) &&
|
2014-11-12 01:40:16 +01:00
|
|
|
cat >expect-rm-remove <<-EOF &&
|
2019-08-18 21:16:35 +02:00
|
|
|
commit $commit
|
2014-11-12 01:40:16 +01:00
|
|
|
Author: A U Thor <author@example.com>
|
|
|
|
Date: Thu Apr 7 15:17:13 2005 -0700
|
2010-02-13 22:28:25 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
${indent}5th
|
2010-02-13 22:28:25 +01:00
|
|
|
|
2019-08-18 21:16:35 +02:00
|
|
|
commit $parent
|
2014-11-12 01:40:16 +01:00
|
|
|
Author: A U Thor <author@example.com>
|
|
|
|
Date: Thu Apr 7 15:16:13 2005 -0700
|
2010-02-13 22:28:25 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
${indent}4th
|
2010-02-13 22:28:25 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
EOF
|
|
|
|
cat expect-multiline >>expect-rm-remove &&
|
|
|
|
git log -4 >actual &&
|
|
|
|
test_cmp expect-rm-remove actual &&
|
2010-07-21 01:18:34 +02:00
|
|
|
test_must_fail git notes show HEAD^
|
2010-02-13 22:28:25 +01:00
|
|
|
'
|
|
|
|
|
2010-08-31 17:56:50 +02:00
|
|
|
test_expect_success 'removing non-existing note should not create new commit' '
|
2014-11-12 01:40:16 +01:00
|
|
|
git rev-parse --verify refs/notes/commits >before_commit &&
|
2010-08-31 17:56:50 +02:00
|
|
|
test_must_fail git notes remove HEAD^ &&
|
2014-11-12 01:40:16 +01:00
|
|
|
git rev-parse --verify refs/notes/commits >after_commit &&
|
2010-08-31 17:56:50 +02:00
|
|
|
test_cmp before_commit after_commit
|
|
|
|
'
|
|
|
|
|
2011-05-19 00:44:37 +02:00
|
|
|
test_expect_success 'removing more than one' '
|
|
|
|
before=$(git rev-parse --verify refs/notes/commits) &&
|
|
|
|
test_when_finished "git update-ref refs/notes/commits $before" &&
|
|
|
|
|
|
|
|
# We have only two -- add another and make sure it stays
|
|
|
|
git notes add -m "extra" &&
|
|
|
|
git notes list HEAD >after-removal-expect &&
|
|
|
|
git notes remove HEAD^^ HEAD^^^ &&
|
|
|
|
git notes list | sed -e "s/ .*//" >actual &&
|
|
|
|
test_cmp after-removal-expect actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'removing is atomic' '
|
|
|
|
before=$(git rev-parse --verify refs/notes/commits) &&
|
|
|
|
test_when_finished "git update-ref refs/notes/commits $before" &&
|
|
|
|
test_must_fail git notes remove HEAD^^ HEAD^^^ HEAD^ &&
|
|
|
|
after=$(git rev-parse --verify refs/notes/commits) &&
|
|
|
|
test "$before" = "$after"
|
|
|
|
'
|
|
|
|
|
2011-05-19 01:02:58 +02:00
|
|
|
test_expect_success 'removing with --ignore-missing' '
|
|
|
|
before=$(git rev-parse --verify refs/notes/commits) &&
|
|
|
|
test_when_finished "git update-ref refs/notes/commits $before" &&
|
|
|
|
|
|
|
|
# We have only two -- add another and make sure it stays
|
|
|
|
git notes add -m "extra" &&
|
|
|
|
git notes list HEAD >after-removal-expect &&
|
|
|
|
git notes remove --ignore-missing HEAD^^ HEAD^^^ HEAD^ &&
|
|
|
|
git notes list | sed -e "s/ .*//" >actual &&
|
|
|
|
test_cmp after-removal-expect actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'removing with --ignore-missing but bogus ref' '
|
|
|
|
before=$(git rev-parse --verify refs/notes/commits) &&
|
|
|
|
test_when_finished "git update-ref refs/notes/commits $before" &&
|
|
|
|
test_must_fail git notes remove --ignore-missing HEAD^^ HEAD^^^ NO-SUCH-COMMIT &&
|
|
|
|
after=$(git rev-parse --verify refs/notes/commits) &&
|
|
|
|
test "$before" = "$after"
|
|
|
|
'
|
|
|
|
|
2011-05-19 01:44:30 +02:00
|
|
|
test_expect_success 'remove reads from --stdin' '
|
|
|
|
before=$(git rev-parse --verify refs/notes/commits) &&
|
|
|
|
test_when_finished "git update-ref refs/notes/commits $before" &&
|
|
|
|
|
|
|
|
# We have only two -- add another and make sure it stays
|
|
|
|
git notes add -m "extra" &&
|
|
|
|
git notes list HEAD >after-removal-expect &&
|
|
|
|
git rev-parse HEAD^^ HEAD^^^ >input &&
|
|
|
|
git notes remove --stdin <input &&
|
|
|
|
git notes list | sed -e "s/ .*//" >actual &&
|
|
|
|
test_cmp after-removal-expect actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'remove --stdin is also atomic' '
|
|
|
|
before=$(git rev-parse --verify refs/notes/commits) &&
|
|
|
|
test_when_finished "git update-ref refs/notes/commits $before" &&
|
|
|
|
git rev-parse HEAD^^ HEAD^^^ HEAD^ >input &&
|
|
|
|
test_must_fail git notes remove --stdin <input &&
|
|
|
|
after=$(git rev-parse --verify refs/notes/commits) &&
|
|
|
|
test "$before" = "$after"
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'removing with --stdin --ignore-missing' '
|
|
|
|
before=$(git rev-parse --verify refs/notes/commits) &&
|
|
|
|
test_when_finished "git update-ref refs/notes/commits $before" &&
|
|
|
|
|
|
|
|
# We have only two -- add another and make sure it stays
|
|
|
|
git notes add -m "extra" &&
|
|
|
|
git notes list HEAD >after-removal-expect &&
|
|
|
|
git rev-parse HEAD^^ HEAD^^^ HEAD^ >input &&
|
|
|
|
git notes remove --ignore-missing --stdin <input &&
|
|
|
|
git notes list | sed -e "s/ .*//" >actual &&
|
|
|
|
test_cmp after-removal-expect actual
|
|
|
|
'
|
|
|
|
|
2010-02-13 22:28:30 +01:00
|
|
|
test_expect_success 'list notes with "git notes list"' '
|
2019-08-18 21:16:35 +02:00
|
|
|
commit_2=$(git rev-parse 2nd) &&
|
|
|
|
commit_3=$(git rev-parse 3rd) &&
|
2019-11-27 20:53:13 +01:00
|
|
|
note_2=$(git rev-parse refs/notes/commits:$commit_2) &&
|
|
|
|
note_3=$(git rev-parse refs/notes/commits:$commit_3) &&
|
2019-08-18 21:16:35 +02:00
|
|
|
sort -t" " -k2 >expect <<-EOF &&
|
2019-11-27 20:53:13 +01:00
|
|
|
$note_2 $commit_2
|
|
|
|
$note_3 $commit_3
|
2014-11-12 01:40:16 +01:00
|
|
|
EOF
|
|
|
|
git notes list >actual &&
|
|
|
|
test_cmp expect actual
|
2010-02-13 22:28:30 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'list notes with "git notes"' '
|
2014-11-12 01:40:16 +01:00
|
|
|
git notes >actual &&
|
|
|
|
test_cmp expect actual
|
2010-02-13 22:28:30 +01:00
|
|
|
'
|
|
|
|
|
2022-08-19 18:03:53 +02:00
|
|
|
test_expect_success '"git notes" without subcommand does not take arguments' '
|
|
|
|
test_expect_code 129 git notes HEAD^^ 2>err &&
|
|
|
|
grep "^error: unknown subcommand" err
|
|
|
|
'
|
|
|
|
|
2010-02-13 22:28:30 +01:00
|
|
|
test_expect_success 'list specific note with "git notes list <object>"' '
|
2019-11-27 20:53:13 +01:00
|
|
|
git rev-parse refs/notes/commits:$commit_3 >expect &&
|
2014-11-12 01:40:16 +01:00
|
|
|
git notes list HEAD^^ >actual &&
|
|
|
|
test_cmp expect actual
|
2010-02-13 22:28:30 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'listing non-existing notes fails' '
|
2014-11-12 01:40:16 +01:00
|
|
|
test_must_fail git notes list HEAD >actual &&
|
tests: use 'test_must_be_empty' instead of 'test_cmp <empty> <out>'
Using 'test_must_be_empty' is shorter and more idiomatic than
>empty &&
test_cmp empty out
as it saves the creation of an empty file. Furthermore, sometimes the
expected empty file doesn't have such a descriptive name like 'empty',
and its creation is far away from the place where it's finally used
for comparison (e.g. in 't7600-merge.sh', where two expected empty
files are created in the 'setup' test, but are used only about 500
lines later).
These cases were found by instrumenting 'test_cmp' to error out the
test script when it's used to compare empty files, and then converted
manually.
Note that even after this patch there still remain a lot of cases
where we use 'test_cmp' to check empty files:
- Sometimes the expected output is not hard-coded in the test, but
'test_cmp' is used to ensure that two similar git commands produce
the same output, and that output happens to be empty, e.g. the
test 'submodule update --merge - ignores --merge for new
submodules' in 't7406-submodule-update.sh'.
- Repetitive common tasks, including preparing the expected results
and running 'test_cmp', are often extracted into a helper
function, and some of this helper's callsites expect no output.
- For the same reason as above, the whole 'test_expect_success'
block is within a helper function, e.g. in 't3070-wildmatch.sh'.
- Or 'test_cmp' is invoked in a loop, e.g. the test 'cvs update
(-p)' in 't9400-git-cvsserver-server.sh'.
Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2018-08-19 23:57:25 +02:00
|
|
|
test_must_be_empty actual
|
2010-02-13 22:28:30 +01:00
|
|
|
'
|
|
|
|
|
2010-02-13 22:28:33 +01:00
|
|
|
test_expect_success 'append to existing note with "git notes append"' '
|
2014-11-12 01:40:16 +01:00
|
|
|
cat >expect <<-EOF &&
|
|
|
|
Initial set of notes
|
|
|
|
|
|
|
|
More notes appended with git notes append
|
|
|
|
EOF
|
2010-02-13 22:28:33 +01:00
|
|
|
git notes add -m "Initial set of notes" &&
|
|
|
|
git notes append -m "More notes appended with git notes append" &&
|
2014-11-12 01:40:16 +01:00
|
|
|
git notes show >actual &&
|
|
|
|
test_cmp expect actual
|
2010-02-13 22:28:33 +01:00
|
|
|
'
|
|
|
|
|
2010-02-27 09:59:22 +01:00
|
|
|
test_expect_success '"git notes list" does not expand to "git notes list HEAD"' '
|
2019-08-18 21:16:35 +02:00
|
|
|
commit_5=$(git rev-parse 5th) &&
|
2019-11-27 20:53:13 +01:00
|
|
|
note_5=$(git rev-parse refs/notes/commits:$commit_5) &&
|
2019-08-18 21:16:35 +02:00
|
|
|
sort -t" " -k2 >expect_list <<-EOF &&
|
2019-11-27 20:53:13 +01:00
|
|
|
$note_2 $commit_2
|
|
|
|
$note_3 $commit_3
|
|
|
|
$note_5 $commit_5
|
2014-11-12 01:40:16 +01:00
|
|
|
EOF
|
|
|
|
git notes list >actual &&
|
|
|
|
test_cmp expect_list actual
|
2010-02-27 09:59:22 +01:00
|
|
|
'
|
|
|
|
|
2010-02-13 22:28:33 +01:00
|
|
|
test_expect_success 'appending empty string does not change existing note' '
|
|
|
|
git notes append -m "" &&
|
2014-11-12 01:40:16 +01:00
|
|
|
git notes show >actual &&
|
|
|
|
test_cmp expect actual
|
2010-02-13 22:28:33 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'git notes append == add when there is no existing note' '
|
|
|
|
git notes remove HEAD &&
|
|
|
|
test_must_fail git notes list HEAD &&
|
2014-11-12 01:40:16 +01:00
|
|
|
git notes append -m "Initial set of notes${LF}${LF}More notes appended with git notes append" &&
|
|
|
|
git notes show >actual &&
|
|
|
|
test_cmp expect actual
|
2010-02-13 22:28:33 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'appending empty string to non-existing note does not create note' '
|
|
|
|
git notes remove HEAD &&
|
|
|
|
test_must_fail git notes list HEAD &&
|
|
|
|
git notes append -m "" &&
|
|
|
|
test_must_fail git notes list HEAD
|
|
|
|
'
|
|
|
|
|
2010-02-13 22:28:20 +01:00
|
|
|
test_expect_success 'create other note on a different notes ref (setup)' '
|
2014-11-12 01:40:16 +01:00
|
|
|
test_commit 6th &&
|
|
|
|
GIT_NOTES_REF="refs/notes/other" git notes add -m "other note" &&
|
2019-08-18 21:16:35 +02:00
|
|
|
commit=$(git rev-parse HEAD) &&
|
2014-11-12 01:40:16 +01:00
|
|
|
cat >expect-not-other <<-EOF &&
|
2019-08-18 21:16:35 +02:00
|
|
|
commit $commit
|
2014-11-12 01:40:16 +01:00
|
|
|
Author: A U Thor <author@example.com>
|
|
|
|
Date: Thu Apr 7 15:18:13 2005 -0700
|
2010-02-13 22:28:20 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
${indent}6th
|
|
|
|
EOF
|
|
|
|
cp expect-not-other expect-other &&
|
|
|
|
cat >>expect-other <<-EOF
|
2010-02-13 22:28:20 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
Notes (other):
|
|
|
|
${indent}other note
|
|
|
|
EOF
|
|
|
|
'
|
2010-02-13 22:28:11 +01:00
|
|
|
|
|
|
|
test_expect_success 'Do not show note on other ref by default' '
|
2014-11-12 01:40:16 +01:00
|
|
|
git log -1 >actual &&
|
|
|
|
test_cmp expect-not-other actual
|
2010-02-13 22:28:11 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'Do show note when ref is given in GIT_NOTES_REF' '
|
2014-11-12 01:40:16 +01:00
|
|
|
GIT_NOTES_REF="refs/notes/other" git log -1 >actual &&
|
|
|
|
test_cmp expect-other actual
|
2010-02-13 22:28:11 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'Do show note when ref is given in core.notesRef config' '
|
2014-11-12 01:40:16 +01:00
|
|
|
test_config core.notesRef "refs/notes/other" &&
|
|
|
|
git log -1 >actual &&
|
|
|
|
test_cmp expect-other actual
|
2010-02-13 22:28:11 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'Do not show note when core.notesRef is overridden' '
|
2014-11-12 01:40:16 +01:00
|
|
|
test_config core.notesRef "refs/notes/other" &&
|
|
|
|
GIT_NOTES_REF="refs/notes/wrong" git log -1 >actual &&
|
|
|
|
test_cmp expect-not-other actual
|
2010-02-13 22:28:11 +01:00
|
|
|
'
|
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
test_expect_success 'Show all notes when notes.displayRef=refs/notes/*' '
|
2019-08-18 21:16:35 +02:00
|
|
|
commit=$(git rev-parse HEAD) &&
|
|
|
|
parent=$(git rev-parse HEAD^) &&
|
2014-11-12 01:40:16 +01:00
|
|
|
cat >expect-both <<-EOF &&
|
2019-08-18 21:16:35 +02:00
|
|
|
commit $commit
|
2014-11-12 01:40:16 +01:00
|
|
|
Author: A U Thor <author@example.com>
|
|
|
|
Date: Thu Apr 7 15:18:13 2005 -0700
|
2010-03-12 18:04:26 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
${indent}6th
|
2010-03-12 18:04:26 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
Notes:
|
|
|
|
${indent}order test
|
2010-03-12 18:04:26 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
Notes (other):
|
|
|
|
${indent}other note
|
2010-03-12 18:04:26 +01:00
|
|
|
|
2019-08-18 21:16:35 +02:00
|
|
|
commit $parent
|
2014-11-12 01:40:16 +01:00
|
|
|
Author: A U Thor <author@example.com>
|
|
|
|
Date: Thu Apr 7 15:17:13 2005 -0700
|
2010-03-12 18:04:26 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
${indent}5th
|
2010-03-12 18:04:26 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
Notes:
|
|
|
|
${indent}replacement for deleted note
|
|
|
|
EOF
|
2010-03-12 18:04:26 +01:00
|
|
|
GIT_NOTES_REF=refs/notes/commits git notes add \
|
|
|
|
-m"replacement for deleted note" HEAD^ &&
|
|
|
|
GIT_NOTES_REF=refs/notes/commits git notes add -m"order test" &&
|
2014-11-12 01:40:16 +01:00
|
|
|
test_unconfig core.notesRef &&
|
|
|
|
test_config notes.displayRef "refs/notes/*" &&
|
|
|
|
git log -2 >actual &&
|
|
|
|
test_cmp expect-both actual
|
2010-03-12 18:04:26 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'core.notesRef is implicitly in notes.displayRef' '
|
2014-11-12 01:40:16 +01:00
|
|
|
test_config core.notesRef refs/notes/commits &&
|
|
|
|
test_config notes.displayRef refs/notes/other &&
|
|
|
|
git log -2 >actual &&
|
|
|
|
test_cmp expect-both actual
|
2010-03-12 18:04:26 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'notes.displayRef can be given more than once' '
|
2014-11-12 01:40:16 +01:00
|
|
|
test_unconfig core.notesRef &&
|
|
|
|
test_config notes.displayRef refs/notes/commits &&
|
2010-03-12 18:04:26 +01:00
|
|
|
git config --add notes.displayRef refs/notes/other &&
|
2014-11-12 01:40:16 +01:00
|
|
|
git log -2 >actual &&
|
|
|
|
test_cmp expect-both actual
|
2010-03-12 18:04:26 +01:00
|
|
|
'
|
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
test_expect_success 'notes.displayRef respects order' '
|
2019-08-18 21:16:35 +02:00
|
|
|
commit=$(git rev-parse HEAD) &&
|
2014-11-12 01:40:16 +01:00
|
|
|
cat >expect-both-reversed <<-EOF &&
|
2019-08-18 21:16:35 +02:00
|
|
|
commit $commit
|
2014-11-12 01:40:16 +01:00
|
|
|
Author: A U Thor <author@example.com>
|
|
|
|
Date: Thu Apr 7 15:18:13 2005 -0700
|
2010-03-12 18:04:26 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
${indent}6th
|
2010-03-12 18:04:26 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
Notes (other):
|
|
|
|
${indent}other note
|
2010-03-12 18:04:26 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
Notes:
|
|
|
|
${indent}order test
|
|
|
|
EOF
|
|
|
|
test_config core.notesRef refs/notes/other &&
|
|
|
|
test_config notes.displayRef refs/notes/commits &&
|
|
|
|
git log -1 >actual &&
|
|
|
|
test_cmp expect-both-reversed actual
|
2010-03-12 18:04:26 +01:00
|
|
|
'
|
|
|
|
|
2020-11-23 04:23:42 +01:00
|
|
|
test_expect_success 'notes.displayRef with no value handled gracefully' '
|
|
|
|
test_must_fail git -c notes.displayRef log -0 --notes &&
|
|
|
|
test_must_fail git -c notes.displayRef diff-tree --notes HEAD
|
|
|
|
'
|
|
|
|
|
2010-03-12 18:04:26 +01:00
|
|
|
test_expect_success 'GIT_NOTES_DISPLAY_REF works' '
|
|
|
|
GIT_NOTES_DISPLAY_REF=refs/notes/commits:refs/notes/other \
|
2014-11-12 01:40:16 +01:00
|
|
|
git log -2 >actual &&
|
|
|
|
test_cmp expect-both actual
|
2010-03-12 18:04:26 +01:00
|
|
|
'
|
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
test_expect_success 'GIT_NOTES_DISPLAY_REF overrides config' '
|
2019-08-18 21:16:35 +02:00
|
|
|
commit=$(git rev-parse HEAD) &&
|
|
|
|
parent=$(git rev-parse HEAD^) &&
|
2014-11-12 01:40:16 +01:00
|
|
|
cat >expect-none <<-EOF &&
|
2019-08-18 21:16:35 +02:00
|
|
|
commit $commit
|
2014-11-12 01:40:16 +01:00
|
|
|
Author: A U Thor <author@example.com>
|
|
|
|
Date: Thu Apr 7 15:18:13 2005 -0700
|
2010-03-12 18:04:26 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
${indent}6th
|
2010-03-12 18:04:26 +01:00
|
|
|
|
2019-08-18 21:16:35 +02:00
|
|
|
commit $parent
|
2014-11-12 01:40:16 +01:00
|
|
|
Author: A U Thor <author@example.com>
|
|
|
|
Date: Thu Apr 7 15:17:13 2005 -0700
|
2010-03-12 18:04:26 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
${indent}5th
|
|
|
|
EOF
|
|
|
|
test_config notes.displayRef "refs/notes/*" &&
|
|
|
|
GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log -2 >actual &&
|
|
|
|
test_cmp expect-none actual
|
2010-03-12 18:04:26 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '--show-notes=* adds to GIT_NOTES_DISPLAY_REF' '
|
2014-11-12 01:40:16 +01:00
|
|
|
GIT_NOTES_REF= GIT_NOTES_DISPLAY_REF= git log --show-notes=* -2 >actual &&
|
|
|
|
test_cmp expect-both actual
|
2010-03-12 18:04:26 +01:00
|
|
|
'
|
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
test_expect_success '--no-standard-notes' '
|
2019-08-18 21:16:35 +02:00
|
|
|
commit=$(git rev-parse HEAD) &&
|
2015-01-22 12:59:36 +01:00
|
|
|
cat >expect-commits <<-EOF &&
|
2019-08-18 21:16:35 +02:00
|
|
|
commit $commit
|
2014-11-12 01:40:16 +01:00
|
|
|
Author: A U Thor <author@example.com>
|
|
|
|
Date: Thu Apr 7 15:18:13 2005 -0700
|
2010-03-12 18:04:26 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
${indent}6th
|
2010-03-12 18:04:26 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
Notes:
|
|
|
|
${indent}order test
|
|
|
|
EOF
|
|
|
|
git log --no-standard-notes --show-notes=commits -1 >actual &&
|
|
|
|
test_cmp expect-commits actual
|
2010-03-12 18:04:26 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '--standard-notes' '
|
2014-11-12 01:40:16 +01:00
|
|
|
test_config notes.displayRef "refs/notes/*" &&
|
2010-03-12 18:04:26 +01:00
|
|
|
git log --no-standard-notes --show-notes=commits \
|
2014-11-12 01:40:16 +01:00
|
|
|
--standard-notes -2 >actual &&
|
|
|
|
test_cmp expect-both actual
|
2010-03-12 18:04:26 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '--show-notes=ref accumulates' '
|
|
|
|
git log --show-notes=other --show-notes=commits \
|
2014-11-12 01:40:16 +01:00
|
|
|
--no-standard-notes -1 >actual &&
|
|
|
|
test_cmp expect-both-reversed actual
|
2010-03-12 18:04:26 +01:00
|
|
|
'
|
|
|
|
|
2010-02-13 22:28:21 +01:00
|
|
|
test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' '
|
2014-11-12 01:40:16 +01:00
|
|
|
test_config core.notesRef refs/notes/other &&
|
|
|
|
echo "Note on a tree" >expect &&
|
2010-02-13 22:28:32 +01:00
|
|
|
git notes add -m "Note on a tree" HEAD: &&
|
2014-11-12 01:40:16 +01:00
|
|
|
git notes show HEAD: >actual &&
|
2010-02-13 22:28:21 +01:00
|
|
|
test_cmp expect actual &&
|
2014-11-12 01:40:16 +01:00
|
|
|
echo "Note on a blob" >expect &&
|
2019-11-27 20:53:13 +01:00
|
|
|
git ls-tree --name-only HEAD >files &&
|
|
|
|
filename=$(head -n1 files) &&
|
2010-02-13 22:28:32 +01:00
|
|
|
git notes add -m "Note on a blob" HEAD:$filename &&
|
2014-11-12 01:40:16 +01:00
|
|
|
git notes show HEAD:$filename >actual &&
|
2010-02-13 22:28:21 +01:00
|
|
|
test_cmp expect actual &&
|
2014-11-12 01:40:16 +01:00
|
|
|
echo "Note on a tag" >expect &&
|
2010-02-13 22:28:21 +01:00
|
|
|
git tag -a -m "This is an annotated tag" foobar HEAD^ &&
|
2010-02-13 22:28:32 +01:00
|
|
|
git notes add -m "Note on a tag" foobar &&
|
2014-11-12 01:40:16 +01:00
|
|
|
git notes show foobar >actual &&
|
2010-02-13 22:28:21 +01:00
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
test_expect_success 'create note from other note with "git notes add -C"' '
|
2019-08-18 21:16:35 +02:00
|
|
|
test_commit 7th &&
|
|
|
|
commit=$(git rev-parse HEAD) &&
|
2014-11-12 01:40:16 +01:00
|
|
|
cat >expect <<-EOF &&
|
2019-08-18 21:16:35 +02:00
|
|
|
commit $commit
|
2014-11-12 01:40:16 +01:00
|
|
|
Author: A U Thor <author@example.com>
|
|
|
|
Date: Thu Apr 7 15:19:13 2005 -0700
|
2010-02-13 22:28:36 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
${indent}7th
|
2010-02-13 22:28:36 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
Notes:
|
|
|
|
${indent}order test
|
|
|
|
EOF
|
2019-11-27 20:53:13 +01:00
|
|
|
note=$(git notes list HEAD^) &&
|
|
|
|
git notes add -C $note &&
|
2014-11-12 01:40:16 +01:00
|
|
|
git log -1 >actual &&
|
2010-02-13 22:28:36 +01:00
|
|
|
test_cmp expect actual &&
|
2019-11-27 20:53:13 +01:00
|
|
|
git notes list HEAD^ >expect &&
|
|
|
|
git notes list HEAD >actual &&
|
|
|
|
test_cmp expect actual
|
2010-02-13 22:28:36 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'create note from non-existing note with "git notes add -C" fails' '
|
2014-11-12 01:40:16 +01:00
|
|
|
test_commit 8th &&
|
2010-02-13 22:28:36 +01:00
|
|
|
test_must_fail git notes add -C deadbeef &&
|
|
|
|
test_must_fail git notes list HEAD
|
|
|
|
'
|
|
|
|
|
2014-02-12 10:54:16 +01:00
|
|
|
test_expect_success 'create note from non-blob with "git notes add -C" fails' '
|
|
|
|
commit=$(git rev-parse --verify HEAD) &&
|
|
|
|
tree=$(git rev-parse --verify HEAD:) &&
|
|
|
|
test_must_fail git notes add -C $commit &&
|
|
|
|
test_must_fail git notes add -C $tree &&
|
|
|
|
test_must_fail git notes list HEAD
|
|
|
|
'
|
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
test_expect_success 'create note from blob with "git notes add -C" reuses blob id' '
|
2019-08-18 21:16:35 +02:00
|
|
|
commit=$(git rev-parse HEAD) &&
|
2014-11-12 01:40:16 +01:00
|
|
|
cat >expect <<-EOF &&
|
2019-08-18 21:16:35 +02:00
|
|
|
commit $commit
|
2014-11-12 01:40:16 +01:00
|
|
|
Author: A U Thor <author@example.com>
|
|
|
|
Date: Thu Apr 7 15:20:13 2005 -0700
|
2014-02-12 10:54:16 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
${indent}8th
|
2014-02-12 10:54:16 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
Notes:
|
|
|
|
${indent}This is a blob object
|
|
|
|
EOF
|
2019-11-27 20:53:13 +01:00
|
|
|
echo "This is a blob object" | git hash-object -w --stdin >blob &&
|
|
|
|
git notes add -C $(cat blob) &&
|
2014-11-12 01:40:16 +01:00
|
|
|
git log -1 >actual &&
|
2014-02-12 10:54:16 +01:00
|
|
|
test_cmp expect actual &&
|
2019-11-27 20:53:13 +01:00
|
|
|
git notes list HEAD >actual &&
|
|
|
|
test_cmp blob actual
|
2014-02-12 10:54:16 +01:00
|
|
|
'
|
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
test_expect_success 'create note from other note with "git notes add -c"' '
|
2019-08-18 21:16:35 +02:00
|
|
|
test_commit 9th &&
|
|
|
|
commit=$(git rev-parse HEAD) &&
|
2014-11-12 01:40:16 +01:00
|
|
|
cat >expect <<-EOF &&
|
2019-08-18 21:16:35 +02:00
|
|
|
commit $commit
|
2014-11-12 01:40:16 +01:00
|
|
|
Author: A U Thor <author@example.com>
|
|
|
|
Date: Thu Apr 7 15:21:13 2005 -0700
|
2010-02-13 22:28:36 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
${indent}9th
|
2010-02-13 22:28:36 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
Notes:
|
|
|
|
${indent}yet another note
|
|
|
|
EOF
|
2019-11-27 20:53:13 +01:00
|
|
|
note=$(git notes list HEAD^^) &&
|
|
|
|
MSG="yet another note" git notes add -c $note &&
|
2014-11-12 01:40:16 +01:00
|
|
|
git log -1 >actual &&
|
2010-02-13 22:28:36 +01:00
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'create note from non-existing note with "git notes add -c" fails' '
|
2014-11-12 01:40:16 +01:00
|
|
|
test_commit 10th &&
|
2014-03-18 19:54:05 +01:00
|
|
|
test_must_fail env MSG="yet another note" git notes add -c deadbeef &&
|
2010-02-13 22:28:36 +01:00
|
|
|
test_must_fail git notes list HEAD
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'append to note from other note with "git notes append -C"' '
|
2019-08-18 21:16:35 +02:00
|
|
|
commit=$(git rev-parse HEAD^) &&
|
2014-11-12 01:40:16 +01:00
|
|
|
cat >expect <<-EOF &&
|
2019-08-18 21:16:35 +02:00
|
|
|
commit $commit
|
2014-11-12 01:40:16 +01:00
|
|
|
Author: A U Thor <author@example.com>
|
|
|
|
Date: Thu Apr 7 15:21:13 2005 -0700
|
|
|
|
|
|
|
|
${indent}9th
|
|
|
|
|
|
|
|
Notes:
|
|
|
|
${indent}yet another note
|
|
|
|
${indent}
|
|
|
|
${indent}yet another note
|
|
|
|
EOF
|
2019-11-27 20:53:13 +01:00
|
|
|
note=$(git notes list HEAD^) &&
|
|
|
|
git notes append -C $note HEAD^ &&
|
2014-11-12 01:40:16 +01:00
|
|
|
git log -1 HEAD^ >actual &&
|
2010-02-13 22:28:36 +01:00
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
test_expect_success 'create note from other note with "git notes append -c"' '
|
2019-08-18 21:16:35 +02:00
|
|
|
commit=$(git rev-parse HEAD) &&
|
2014-11-12 01:40:16 +01:00
|
|
|
cat >expect <<-EOF &&
|
2019-08-18 21:16:35 +02:00
|
|
|
commit $commit
|
2014-11-12 01:40:16 +01:00
|
|
|
Author: A U Thor <author@example.com>
|
|
|
|
Date: Thu Apr 7 15:22:13 2005 -0700
|
2010-02-13 22:28:36 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
${indent}10th
|
2010-02-13 22:28:36 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
Notes:
|
|
|
|
${indent}other note
|
|
|
|
EOF
|
2019-11-27 20:53:13 +01:00
|
|
|
note=$(git notes list HEAD^) &&
|
|
|
|
MSG="other note" git notes append -c $note &&
|
2014-11-12 01:40:16 +01:00
|
|
|
git log -1 >actual &&
|
2010-02-13 22:28:36 +01:00
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'append to note from other note with "git notes append -c"' '
|
2019-08-18 21:16:35 +02:00
|
|
|
commit=$(git rev-parse HEAD) &&
|
2014-11-12 01:40:16 +01:00
|
|
|
cat >expect <<-EOF &&
|
2019-08-18 21:16:35 +02:00
|
|
|
commit $commit
|
2014-11-12 01:40:16 +01:00
|
|
|
Author: A U Thor <author@example.com>
|
|
|
|
Date: Thu Apr 7 15:22:13 2005 -0700
|
|
|
|
|
|
|
|
${indent}10th
|
|
|
|
|
|
|
|
Notes:
|
|
|
|
${indent}other note
|
|
|
|
${indent}
|
|
|
|
${indent}yet another note
|
|
|
|
EOF
|
2019-11-27 20:53:13 +01:00
|
|
|
note=$(git notes list HEAD) &&
|
|
|
|
MSG="yet another note" git notes append -c $note &&
|
2014-11-12 01:40:16 +01:00
|
|
|
git log -1 >actual &&
|
2010-02-13 22:28:36 +01:00
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2010-02-13 22:28:38 +01:00
|
|
|
test_expect_success 'copy note with "git notes copy"' '
|
2019-10-16 07:18:41 +02:00
|
|
|
commit=$(git rev-parse 4th) &&
|
|
|
|
cat >expect <<-EOF &&
|
|
|
|
commit $commit
|
|
|
|
Author: A U Thor <author@example.com>
|
|
|
|
Date: Thu Apr 7 15:16:13 2005 -0700
|
|
|
|
|
|
|
|
${indent}4th
|
|
|
|
|
|
|
|
Notes:
|
|
|
|
${indent}This is a blob object
|
|
|
|
EOF
|
|
|
|
git notes copy 8th 4th &&
|
|
|
|
git log 3rd..4th >actual &&
|
|
|
|
test_cmp expect actual &&
|
2019-11-27 20:53:13 +01:00
|
|
|
git notes list 4th >expect &&
|
|
|
|
git notes list 8th >actual &&
|
|
|
|
test_cmp expect actual
|
2019-10-16 07:18:41 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'copy note with "git notes copy" with default' '
|
2019-08-18 21:16:35 +02:00
|
|
|
test_commit 11th &&
|
|
|
|
commit=$(git rev-parse HEAD) &&
|
2014-11-12 01:40:16 +01:00
|
|
|
cat >expect <<-EOF &&
|
2019-08-18 21:16:35 +02:00
|
|
|
commit $commit
|
2014-11-12 01:40:16 +01:00
|
|
|
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
|
2019-10-16 07:18:41 +02:00
|
|
|
git notes copy HEAD^ &&
|
2014-11-12 01:40:16 +01:00
|
|
|
git log -1 >actual &&
|
2010-02-13 22:28:38 +01:00
|
|
|
test_cmp expect actual &&
|
2019-11-27 20:53:13 +01:00
|
|
|
git notes list HEAD^ >expect &&
|
|
|
|
git notes list HEAD >actual &&
|
|
|
|
test_cmp expect actual
|
2010-02-13 22:28:38 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'prevent overwrite with "git notes copy"' '
|
|
|
|
test_must_fail git notes copy HEAD~2 HEAD &&
|
2019-11-27 20:53:13 +01:00
|
|
|
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
|
2014-11-12 01:40:16 +01:00
|
|
|
git log -1 >actual &&
|
2010-02-13 22:28:38 +01:00
|
|
|
test_cmp expect actual &&
|
2019-11-27 20:53:13 +01:00
|
|
|
git notes list HEAD^ >expect &&
|
|
|
|
git notes list HEAD >actual &&
|
|
|
|
test_cmp expect actual
|
2010-02-13 22:28:38 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'allow overwrite with "git notes copy -f"' '
|
2019-10-16 07:18:41 +02:00
|
|
|
commit=$(git rev-parse 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}This is a blob object
|
|
|
|
EOF
|
|
|
|
git notes copy -f HEAD~3 HEAD &&
|
|
|
|
git log -1 >actual &&
|
|
|
|
test_cmp expect actual &&
|
2019-11-27 20:53:13 +01:00
|
|
|
git notes list HEAD~3 >expect &&
|
|
|
|
git notes list HEAD >actual &&
|
|
|
|
test_cmp expect actual
|
2019-10-16 07:18:41 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'allow overwrite with "git notes copy -f" with default' '
|
2019-08-18 21:16:35 +02:00
|
|
|
commit=$(git rev-parse HEAD) &&
|
2014-11-12 01:40:16 +01:00
|
|
|
cat >expect <<-EOF &&
|
2019-08-18 21:16:35 +02:00
|
|
|
commit $commit
|
2014-11-12 01:40:16 +01:00
|
|
|
Author: A U Thor <author@example.com>
|
|
|
|
Date: Thu Apr 7 15:23:13 2005 -0700
|
|
|
|
|
|
|
|
${indent}11th
|
|
|
|
|
|
|
|
Notes:
|
|
|
|
${indent}yet another note
|
|
|
|
${indent}
|
|
|
|
${indent}yet another note
|
|
|
|
EOF
|
2019-10-16 07:18:41 +02:00
|
|
|
git notes copy -f HEAD~2 &&
|
2014-11-12 01:40:16 +01:00
|
|
|
git log -1 >actual &&
|
2010-02-13 22:28:38 +01:00
|
|
|
test_cmp expect actual &&
|
2019-11-27 20:53:13 +01:00
|
|
|
git notes list HEAD~2 >expect &&
|
|
|
|
git notes list HEAD >actual &&
|
|
|
|
test_cmp expect actual
|
2010-02-13 22:28:38 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'cannot copy note from object without notes' '
|
2014-11-12 01:40:16 +01:00
|
|
|
test_commit 12th &&
|
|
|
|
test_commit 13th &&
|
2010-02-13 22:28:38 +01:00
|
|
|
test_must_fail git notes copy HEAD^ HEAD
|
|
|
|
'
|
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
test_expect_success 'git notes copy --stdin' '
|
2019-08-18 21:16:35 +02:00
|
|
|
commit=$(git rev-parse HEAD) &&
|
|
|
|
parent=$(git rev-parse HEAD^) &&
|
2014-11-12 01:40:16 +01:00
|
|
|
cat >expect <<-EOF &&
|
2019-08-18 21:16:35 +02:00
|
|
|
commit $commit
|
2014-11-12 01:40:16 +01:00
|
|
|
Author: A U Thor <author@example.com>
|
|
|
|
Date: Thu Apr 7 15:25:13 2005 -0700
|
2010-03-12 18:04:31 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
${indent}13th
|
2010-03-12 18:04:31 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
Notes:
|
|
|
|
${indent}yet another note
|
|
|
|
${indent}
|
|
|
|
${indent}yet another note
|
2010-03-12 18:04:31 +01:00
|
|
|
|
2019-08-18 21:16:35 +02:00
|
|
|
commit $parent
|
2014-11-12 01:40:16 +01:00
|
|
|
Author: A U Thor <author@example.com>
|
|
|
|
Date: Thu Apr 7 15:24:13 2005 -0700
|
2010-03-12 18:04:31 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
${indent}12th
|
2010-03-12 18:04:31 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
Notes:
|
|
|
|
${indent}other note
|
|
|
|
${indent}
|
|
|
|
${indent}yet another note
|
|
|
|
EOF
|
2019-11-27 20:53:13 +01:00
|
|
|
from=$(git rev-parse HEAD~3) &&
|
|
|
|
to=$(git rev-parse HEAD^) &&
|
|
|
|
echo "$from" "$to" >copy &&
|
|
|
|
from=$(git rev-parse HEAD~2) &&
|
|
|
|
to=$(git rev-parse HEAD) &&
|
|
|
|
echo "$from" "$to" >>copy &&
|
|
|
|
git notes copy --stdin <copy &&
|
2014-11-12 01:40:16 +01:00
|
|
|
git log -2 >actual &&
|
|
|
|
test_cmp expect actual &&
|
2019-11-27 20:53:13 +01:00
|
|
|
git notes list HEAD~2 >expect &&
|
|
|
|
git notes list HEAD >actual &&
|
|
|
|
test_cmp expect actual &&
|
|
|
|
git notes list HEAD~3 >expect &&
|
|
|
|
git notes list HEAD^ >actual &&
|
|
|
|
test_cmp expect actual
|
2010-03-12 18:04:31 +01:00
|
|
|
'
|
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
test_expect_success 'git notes copy --for-rewrite (unconfigured)' '
|
2019-08-18 21:16:35 +02:00
|
|
|
test_commit 14th &&
|
|
|
|
test_commit 15th &&
|
|
|
|
commit=$(git rev-parse HEAD) &&
|
|
|
|
parent=$(git rev-parse HEAD^) &&
|
2014-11-12 01:40:16 +01:00
|
|
|
cat >expect <<-EOF &&
|
2019-08-18 21:16:35 +02:00
|
|
|
commit $commit
|
2014-11-12 01:40:16 +01:00
|
|
|
Author: A U Thor <author@example.com>
|
|
|
|
Date: Thu Apr 7 15:27:13 2005 -0700
|
2010-03-12 18:04:32 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
${indent}15th
|
2010-03-12 18:04:32 +01:00
|
|
|
|
2019-08-18 21:16:35 +02:00
|
|
|
commit $parent
|
2014-11-12 01:40:16 +01:00
|
|
|
Author: A U Thor <author@example.com>
|
|
|
|
Date: Thu Apr 7 15:26:13 2005 -0700
|
2010-03-12 18:04:32 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
${indent}14th
|
|
|
|
EOF
|
2019-11-27 20:53:13 +01:00
|
|
|
from=$(git rev-parse HEAD~3) &&
|
|
|
|
to=$(git rev-parse HEAD^) &&
|
|
|
|
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 &&
|
2014-11-12 01:40:16 +01:00
|
|
|
git log -2 >actual &&
|
|
|
|
test_cmp expect actual
|
2010-03-12 18:04:32 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'git notes copy --for-rewrite (enabled)' '
|
2019-08-18 21:16:35 +02:00
|
|
|
commit=$(git rev-parse HEAD) &&
|
|
|
|
parent=$(git rev-parse HEAD^) &&
|
2014-11-12 01:40:16 +01:00
|
|
|
cat >expect <<-EOF &&
|
2019-08-18 21:16:35 +02:00
|
|
|
commit $commit
|
2014-11-12 01:40:16 +01:00
|
|
|
Author: A U Thor <author@example.com>
|
|
|
|
Date: Thu Apr 7 15:27:13 2005 -0700
|
|
|
|
|
|
|
|
${indent}15th
|
|
|
|
|
|
|
|
Notes:
|
|
|
|
${indent}yet another note
|
|
|
|
${indent}
|
|
|
|
${indent}yet another note
|
|
|
|
|
2019-08-18 21:16:35 +02:00
|
|
|
commit $parent
|
2014-11-12 01:40:16 +01:00
|
|
|
Author: A U Thor <author@example.com>
|
|
|
|
Date: Thu Apr 7 15:26:13 2005 -0700
|
|
|
|
|
|
|
|
${indent}14th
|
|
|
|
|
|
|
|
Notes:
|
|
|
|
${indent}other note
|
|
|
|
${indent}
|
|
|
|
${indent}yet another note
|
|
|
|
EOF
|
|
|
|
test_config notes.rewriteMode overwrite &&
|
|
|
|
test_config notes.rewriteRef "refs/notes/*" &&
|
2019-11-27 20:53:13 +01:00
|
|
|
from=$(git rev-parse HEAD~3) &&
|
|
|
|
to=$(git rev-parse HEAD^) &&
|
|
|
|
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 &&
|
2014-11-12 01:40:16 +01:00
|
|
|
git log -2 >actual &&
|
|
|
|
test_cmp expect actual
|
2010-03-12 18:04:32 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'git notes copy --for-rewrite (disabled)' '
|
2014-11-12 01:40:16 +01:00
|
|
|
test_config notes.rewrite.bar false &&
|
2019-11-27 20:53:13 +01:00
|
|
|
from=$(git rev-parse HEAD~3) &&
|
|
|
|
to=$(git rev-parse HEAD) &&
|
|
|
|
echo "$from" "$to" >copy &&
|
|
|
|
git notes copy --for-rewrite=bar <copy &&
|
2014-11-12 01:40:16 +01:00
|
|
|
git log -2 >actual &&
|
|
|
|
test_cmp expect actual
|
2010-03-12 18:04:32 +01:00
|
|
|
'
|
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
test_expect_success 'git notes copy --for-rewrite (overwrite)' '
|
2019-08-18 21:16:35 +02:00
|
|
|
commit=$(git rev-parse HEAD) &&
|
2014-11-12 01:40:16 +01:00
|
|
|
cat >expect <<-EOF &&
|
2019-08-18 21:16:35 +02:00
|
|
|
commit $commit
|
2014-11-12 01:40:16 +01:00
|
|
|
Author: A U Thor <author@example.com>
|
|
|
|
Date: Thu Apr 7 15:27:13 2005 -0700
|
2010-03-12 18:04:32 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
${indent}15th
|
2010-03-12 18:04:32 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
Notes:
|
|
|
|
${indent}a fresh note
|
|
|
|
EOF
|
2010-03-12 18:04:32 +01:00
|
|
|
git notes add -f -m"a fresh note" HEAD^ &&
|
2014-11-12 01:40:16 +01:00
|
|
|
test_config notes.rewriteMode overwrite &&
|
|
|
|
test_config notes.rewriteRef "refs/notes/*" &&
|
2019-11-27 20:53:13 +01:00
|
|
|
from=$(git rev-parse HEAD^) &&
|
|
|
|
to=$(git rev-parse HEAD) &&
|
|
|
|
echo "$from" "$to" >copy &&
|
|
|
|
git notes copy --for-rewrite=foo <copy &&
|
2014-11-12 01:40:16 +01:00
|
|
|
git log -1 >actual &&
|
|
|
|
test_cmp expect actual
|
2010-03-12 18:04:32 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'git notes copy --for-rewrite (ignore)' '
|
2014-11-12 01:40:16 +01:00
|
|
|
test_config notes.rewriteMode ignore &&
|
|
|
|
test_config notes.rewriteRef "refs/notes/*" &&
|
2019-11-27 20:53:13 +01:00
|
|
|
from=$(git rev-parse HEAD^) &&
|
|
|
|
to=$(git rev-parse HEAD) &&
|
|
|
|
echo "$from" "$to" >copy &&
|
|
|
|
git notes copy --for-rewrite=foo <copy &&
|
2014-11-12 01:40:16 +01:00
|
|
|
git log -1 >actual &&
|
|
|
|
test_cmp expect actual
|
2010-03-12 18:04:32 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'git notes copy --for-rewrite (append)' '
|
2019-08-18 21:16:35 +02:00
|
|
|
commit=$(git rev-parse HEAD) &&
|
2014-11-12 01:40:16 +01:00
|
|
|
cat >expect <<-EOF &&
|
2019-08-18 21:16:35 +02:00
|
|
|
commit $commit
|
2014-11-12 01:40:16 +01:00
|
|
|
Author: A U Thor <author@example.com>
|
|
|
|
Date: Thu Apr 7 15:27:13 2005 -0700
|
|
|
|
|
|
|
|
${indent}15th
|
|
|
|
|
|
|
|
Notes:
|
|
|
|
${indent}a fresh note
|
|
|
|
${indent}
|
|
|
|
${indent}another fresh note
|
|
|
|
EOF
|
2010-03-12 18:04:32 +01:00
|
|
|
git notes add -f -m"another fresh note" HEAD^ &&
|
2014-11-12 01:40:16 +01:00
|
|
|
test_config notes.rewriteMode concatenate &&
|
|
|
|
test_config notes.rewriteRef "refs/notes/*" &&
|
2019-11-27 20:53:13 +01:00
|
|
|
from=$(git rev-parse HEAD^) &&
|
|
|
|
to=$(git rev-parse HEAD) &&
|
|
|
|
echo "$from" "$to" >copy &&
|
|
|
|
git notes copy --for-rewrite=foo <copy &&
|
2014-11-12 01:40:16 +01:00
|
|
|
git log -1 >actual &&
|
|
|
|
test_cmp expect actual
|
2010-03-12 18:04:32 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'git notes copy --for-rewrite (append two to one)' '
|
2019-08-18 21:16:35 +02:00
|
|
|
commit=$(git rev-parse HEAD) &&
|
2014-11-12 01:40:16 +01:00
|
|
|
cat >expect <<-EOF &&
|
2019-08-18 21:16:35 +02:00
|
|
|
commit $commit
|
2014-11-12 01:40:16 +01:00
|
|
|
Author: A U Thor <author@example.com>
|
|
|
|
Date: Thu Apr 7 15:27:13 2005 -0700
|
|
|
|
|
|
|
|
${indent}15th
|
|
|
|
|
|
|
|
Notes:
|
|
|
|
${indent}a fresh note
|
|
|
|
${indent}
|
|
|
|
${indent}another fresh note
|
|
|
|
${indent}
|
|
|
|
${indent}append 1
|
|
|
|
${indent}
|
|
|
|
${indent}append 2
|
|
|
|
EOF
|
2010-03-12 18:04:32 +01:00
|
|
|
git notes add -f -m"append 1" HEAD^ &&
|
|
|
|
git notes add -f -m"append 2" HEAD^^ &&
|
2014-11-12 01:40:16 +01:00
|
|
|
test_config notes.rewriteMode concatenate &&
|
|
|
|
test_config notes.rewriteRef "refs/notes/*" &&
|
2019-11-27 20:53:13 +01:00
|
|
|
from=$(git rev-parse HEAD^) &&
|
|
|
|
to=$(git rev-parse HEAD) &&
|
|
|
|
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 &&
|
2014-11-12 01:40:16 +01:00
|
|
|
git log -1 >actual &&
|
|
|
|
test_cmp expect actual
|
2010-03-12 18:04:32 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'git notes copy --for-rewrite (append empty)' '
|
|
|
|
git notes remove HEAD^ &&
|
2014-11-12 01:40:16 +01:00
|
|
|
test_config notes.rewriteMode concatenate &&
|
|
|
|
test_config notes.rewriteRef "refs/notes/*" &&
|
2019-11-27 20:53:13 +01:00
|
|
|
from=$(git rev-parse HEAD^) &&
|
|
|
|
to=$(git rev-parse HEAD) &&
|
|
|
|
echo "$from" "$to" >copy &&
|
|
|
|
git notes copy --for-rewrite=foo <copy &&
|
2014-11-12 01:40:16 +01:00
|
|
|
git log -1 >actual &&
|
|
|
|
test_cmp expect actual
|
2010-03-12 18:04:32 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'GIT_NOTES_REWRITE_MODE works' '
|
2019-08-18 21:16:35 +02:00
|
|
|
commit=$(git rev-parse HEAD) &&
|
2014-11-12 01:40:16 +01:00
|
|
|
cat >expect <<-EOF &&
|
2019-08-18 21:16:35 +02:00
|
|
|
commit $commit
|
2014-11-12 01:40:16 +01:00
|
|
|
Author: A U Thor <author@example.com>
|
|
|
|
Date: Thu Apr 7 15:27:13 2005 -0700
|
|
|
|
|
|
|
|
${indent}15th
|
|
|
|
|
|
|
|
Notes:
|
|
|
|
${indent}replacement note 1
|
|
|
|
EOF
|
|
|
|
test_config notes.rewriteMode concatenate &&
|
|
|
|
test_config notes.rewriteRef "refs/notes/*" &&
|
2010-03-12 18:04:32 +01:00
|
|
|
git notes add -f -m"replacement note 1" HEAD^ &&
|
2019-11-27 20:53:13 +01:00
|
|
|
from=$(git rev-parse HEAD^) &&
|
|
|
|
to=$(git rev-parse HEAD) &&
|
|
|
|
echo "$from" "$to" >copy &&
|
|
|
|
GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo <copy &&
|
2014-11-12 01:40:16 +01:00
|
|
|
git log -1 >actual &&
|
|
|
|
test_cmp expect actual
|
2010-03-12 18:04:32 +01:00
|
|
|
'
|
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
test_expect_success 'GIT_NOTES_REWRITE_REF works' '
|
2019-08-18 21:16:35 +02:00
|
|
|
commit=$(git rev-parse HEAD) &&
|
2014-11-12 01:40:16 +01:00
|
|
|
cat >expect <<-EOF &&
|
2019-08-18 21:16:35 +02:00
|
|
|
commit $commit
|
2014-11-12 01:40:16 +01:00
|
|
|
Author: A U Thor <author@example.com>
|
|
|
|
Date: Thu Apr 7 15:27:13 2005 -0700
|
2010-03-12 18:04:32 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
${indent}15th
|
2010-03-12 18:04:32 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
Notes:
|
|
|
|
${indent}replacement note 2
|
|
|
|
EOF
|
2010-03-12 18:04:32 +01:00
|
|
|
git notes add -f -m"replacement note 2" HEAD^ &&
|
2014-11-12 01:40:16 +01:00
|
|
|
test_config notes.rewriteMode overwrite &&
|
|
|
|
test_unconfig notes.rewriteRef &&
|
2019-11-27 20:53:13 +01:00
|
|
|
from=$(git rev-parse HEAD^) &&
|
|
|
|
to=$(git rev-parse HEAD) &&
|
|
|
|
echo "$from" "$to" >copy &&
|
2010-03-12 18:04:32 +01:00
|
|
|
GIT_NOTES_REWRITE_REF=refs/notes/commits:refs/notes/other \
|
2019-11-27 20:53:13 +01:00
|
|
|
git notes copy --for-rewrite=foo <copy &&
|
2014-11-12 01:40:16 +01:00
|
|
|
git log -1 >actual &&
|
|
|
|
test_cmp expect actual
|
2010-03-12 18:04:32 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'GIT_NOTES_REWRITE_REF overrides config' '
|
|
|
|
git notes add -f -m"replacement note 3" HEAD^ &&
|
2014-11-12 01:40:16 +01:00
|
|
|
test_config notes.rewriteMode overwrite &&
|
|
|
|
test_config notes.rewriteRef refs/notes/other &&
|
2019-11-27 20:53:13 +01:00
|
|
|
from=$(git rev-parse HEAD^) &&
|
|
|
|
to=$(git rev-parse HEAD) &&
|
|
|
|
echo "$from" "$to" >copy &&
|
t3301: fix false negative
In 6956f858f6 (notes: implement helpers needed for note copying during
rewrite, 2010-03-12), we introduced a test case that verifies that the
config setting `notes.rewriteRef` can be overridden via the environment
variable `GIT_NOTES_REWRITE_REF`.
Back when it was introduced, it relied on a side effect of an earlier
test case that configured `core.noteRef` to point to `refs/notes/other`.
In 908a320363 (t3301: modernize style, 2014-11-12), this side effect was
removed.
The test case *still* passed, but for the wrong reason: we no longer
overrode the rewrite ref, but there simply was nothing to rewrite
anymore, as the overridden notes ref was "modernized" away.
Let's let that test case pass for the correct reason again.
To make sure of that, let's change the idea of the original test case:
it configured `notes.rewriteRef` to point to the actual notes ref,
forced that to be ignored and then verified that the notes were *not*
rewritten.
By turning that idea upside down (configure the `notes.rewriteRef` to
another notes ref, override it via the environment variable to force the
notes to be copied, and then verify that the notes *were* rewritten), we
make it much harder for that test case to pass for the wrong reason.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-04-09 12:41:23 +02:00
|
|
|
GIT_NOTES_REWRITE_REF=refs/notes/commits \
|
2019-11-27 20:53:13 +01:00
|
|
|
git notes copy --for-rewrite=foo <copy &&
|
2014-11-12 01:40:16 +01:00
|
|
|
git log -1 >actual &&
|
t3301: fix false negative
In 6956f858f6 (notes: implement helpers needed for note copying during
rewrite, 2010-03-12), we introduced a test case that verifies that the
config setting `notes.rewriteRef` can be overridden via the environment
variable `GIT_NOTES_REWRITE_REF`.
Back when it was introduced, it relied on a side effect of an earlier
test case that configured `core.noteRef` to point to `refs/notes/other`.
In 908a320363 (t3301: modernize style, 2014-11-12), this side effect was
removed.
The test case *still* passed, but for the wrong reason: we no longer
overrode the rewrite ref, but there simply was nothing to rewrite
anymore, as the overridden notes ref was "modernized" away.
Let's let that test case pass for the correct reason again.
To make sure of that, let's change the idea of the original test case:
it configured `notes.rewriteRef` to point to the actual notes ref,
forced that to be ignored and then verified that the notes were *not*
rewritten.
By turning that idea upside down (configure the `notes.rewriteRef` to
another notes ref, override it via the environment variable to force the
notes to be copied, and then verify that the notes *were* rewritten), we
make it much harder for that test case to pass for the wrong reason.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-04-09 12:41:23 +02:00
|
|
|
grep "replacement note 3" actual
|
2010-03-12 18:04:32 +01:00
|
|
|
'
|
2010-06-28 10:59:07 +02:00
|
|
|
|
2021-02-23 22:11:32 +01:00
|
|
|
test_expect_success 'git notes copy diagnoses too many or too few arguments' '
|
2019-10-16 07:18:40 +02:00
|
|
|
test_must_fail git notes copy 2>error &&
|
2021-02-23 22:11:32 +01:00
|
|
|
test_i18ngrep "too few arguments" error &&
|
2019-10-16 07:18:40 +02:00
|
|
|
test_must_fail git notes copy one two three 2>error &&
|
2021-02-23 22:11:32 +01:00
|
|
|
test_i18ngrep "too many arguments" error
|
2010-06-28 10:59:07 +02:00
|
|
|
'
|
|
|
|
|
2020-11-19 00:44:23 +01:00
|
|
|
test_expect_success 'git notes get-ref expands refs/heads/main to refs/notes/refs/heads/main' '
|
2015-09-23 00:15:03 +02:00
|
|
|
test_unconfig core.notesRef &&
|
|
|
|
sane_unset GIT_NOTES_REF &&
|
2020-11-19 00:44:23 +01:00
|
|
|
echo refs/notes/refs/heads/main >expect &&
|
|
|
|
git notes --ref=refs/heads/main get-ref >actual &&
|
2019-11-27 20:53:13 +01:00
|
|
|
test_cmp expect actual
|
2015-09-23 00:15:03 +02:00
|
|
|
'
|
|
|
|
|
2010-11-09 22:49:57 +01:00
|
|
|
test_expect_success 'git notes get-ref (no overrides)' '
|
2014-11-12 01:40:16 +01:00
|
|
|
test_unconfig core.notesRef &&
|
2011-01-06 01:30:02 +01:00
|
|
|
sane_unset GIT_NOTES_REF &&
|
2019-11-27 20:53:13 +01:00
|
|
|
echo refs/notes/commits >expect &&
|
|
|
|
git notes get-ref >actual &&
|
|
|
|
test_cmp expect actual
|
2010-11-09 22:49:57 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'git notes get-ref (core.notesRef)' '
|
2014-11-12 01:40:16 +01:00
|
|
|
test_config core.notesRef refs/notes/foo &&
|
2019-11-27 20:53:13 +01:00
|
|
|
echo refs/notes/foo >expect &&
|
|
|
|
git notes get-ref >actual &&
|
|
|
|
test_cmp expect actual
|
2010-11-09 22:49:57 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'git notes get-ref (GIT_NOTES_REF)' '
|
2019-11-27 20:53:13 +01:00
|
|
|
echo refs/notes/bar >expect &&
|
|
|
|
GIT_NOTES_REF=refs/notes/bar git notes get-ref >actual &&
|
|
|
|
test_cmp expect actual
|
2010-11-09 22:49:57 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'git notes get-ref (--ref)' '
|
2019-11-27 20:53:13 +01:00
|
|
|
echo refs/notes/baz >expect &&
|
|
|
|
GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref >actual &&
|
|
|
|
test_cmp expect actual
|
2010-11-09 22:49:57 +01:00
|
|
|
'
|
|
|
|
|
2014-11-09 13:30:48 +01:00
|
|
|
test_expect_success 'setup testing of empty notes' '
|
|
|
|
test_unconfig core.notesRef &&
|
|
|
|
test_commit 16th &&
|
2014-11-12 01:40:14 +01:00
|
|
|
empty_blob=$(git hash-object -w /dev/null) &&
|
|
|
|
echo "$empty_blob" >expect_empty
|
2014-11-09 13:30:48 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
while read cmd
|
|
|
|
do
|
|
|
|
test_expect_success "'git notes $cmd' removes empty note" "
|
|
|
|
test_might_fail git notes remove HEAD &&
|
|
|
|
MSG= git notes $cmd &&
|
|
|
|
test_must_fail git notes list HEAD
|
|
|
|
"
|
2014-11-12 01:40:14 +01:00
|
|
|
|
|
|
|
test_expect_success "'git notes $cmd --allow-empty' stores empty note" "
|
|
|
|
test_might_fail git notes remove HEAD &&
|
|
|
|
MSG= git notes $cmd --allow-empty &&
|
|
|
|
git notes list HEAD >actual &&
|
|
|
|
test_cmp expect_empty actual
|
|
|
|
"
|
2014-11-09 13:30:48 +01:00
|
|
|
done <<\EOF
|
|
|
|
add
|
|
|
|
add -F /dev/null
|
|
|
|
add -m ""
|
|
|
|
add -c "$empty_blob"
|
|
|
|
add -C "$empty_blob"
|
|
|
|
append
|
|
|
|
append -F /dev/null
|
|
|
|
append -m ""
|
|
|
|
append -c "$empty_blob"
|
|
|
|
append -C "$empty_blob"
|
|
|
|
edit
|
|
|
|
EOF
|
|
|
|
|
2014-11-12 01:40:15 +01:00
|
|
|
test_expect_success 'empty notes are displayed by git log' '
|
|
|
|
test_commit 17th &&
|
|
|
|
git log -1 >expect &&
|
2014-11-12 01:40:16 +01:00
|
|
|
cat >>expect <<-EOF &&
|
2014-11-12 01:40:15 +01:00
|
|
|
|
2014-11-12 01:40:16 +01:00
|
|
|
Notes:
|
|
|
|
EOF
|
2014-11-12 01:40:15 +01:00
|
|
|
git notes add -C "$empty_blob" --allow-empty &&
|
|
|
|
git log -1 >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2009-10-09 12:21:58 +02:00
|
|
|
test_done
|