1#!/bin/sh
2#
3# Copyright (c) 2007 Johannes E. Schindelin
4#
5
6test_description='Test commit notes'
7
8. ./test-lib.sh
9
10cat > fake_editor.sh << \EOF
11echo "$MSG" > "$1"
12echo "$MSG" >& 2
13EOF
14chmod a+x fake_editor.sh
15VISUAL=./fake_editor.sh
16export VISUAL
17
18test_expect_success 'cannot annotate non-existing HEAD' '
19 ! MSG=3 git notes edit
20'
21
22test_expect_success setup '
23 : > a1 &&
24 git add a1 &&
25 test_tick &&
26 git commit -m 1st &&
27 : > a2 &&
28 git add a2 &&
29 test_tick &&
30 git commit -m 2nd
31'
32
33test_expect_success 'need valid notes ref' '
34 ! MSG=1 GIT_NOTES_REF='/' git notes edit &&
35 ! MSG=2 GIT_NOTES_REF='/' git notes show
36'
37
38test_expect_success 'create notes' '
39 git config core.notesRef refs/notes/commits &&
40 MSG=b1 git notes edit &&
41 test ! -f .git/new-notes &&
42 test 1 = $(git ls-tree refs/notes/commits | wc -l) &&
43 test b1 = $(git notes show) &&
44 git show HEAD^ &&
45 ! git notes show HEAD^
46'
47
48cat > expect << EOF
49commit 268048bfb8a1fb38e703baceb8ab235421bf80c5
50Author: A U Thor <author@example.com>
51Date: Thu Apr 7 15:14:13 2005 -0700
52
53 2nd
54
55Notes:
56 b1
57EOF
58
59test_expect_success 'show notes' '
60 ! (git cat-file commit HEAD | grep b1) &&
61 git log -1 > output &&
62 git diff expect output
63'
64
65test_done