]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3308-notes-merge.sh
builtin/notes.c: Refactor creation of notes commits.
[thirdparty/git.git] / t / t3308-notes-merge.sh
CommitLineData
75ef3f4a
JH
1#!/bin/sh
2#
3# Copyright (c) 2010 Johan Herland
4#
5
6test_description='Test merging of notes trees'
7
8. ./test-lib.sh
9
10test_expect_success setup '
11 test_commit 1st &&
12 test_commit 2nd &&
13 test_commit 3rd &&
14 test_commit 4th &&
15 test_commit 5th &&
16 # Create notes on 4 first commits
17 git config core.notesRef refs/notes/x &&
18 git notes add -m "Notes on 1st commit" 1st &&
19 git notes add -m "Notes on 2nd commit" 2nd &&
20 git notes add -m "Notes on 3rd commit" 3rd &&
21 git notes add -m "Notes on 4th commit" 4th
22'
23
24commit_sha1=$(git rev-parse 1st^{commit})
25commit_sha2=$(git rev-parse 2nd^{commit})
26commit_sha3=$(git rev-parse 3rd^{commit})
27commit_sha4=$(git rev-parse 4th^{commit})
28commit_sha5=$(git rev-parse 5th^{commit})
29
30verify_notes () {
31 notes_ref="$1"
32 git -c core.notesRef="refs/notes/$notes_ref" notes |
33 sort >"output_notes_$notes_ref" &&
34 test_cmp "expect_notes_$notes_ref" "output_notes_$notes_ref" &&
35 git -c core.notesRef="refs/notes/$notes_ref" log --format="%H %s%n%N" \
36 >"output_log_$notes_ref" &&
37 test_cmp "expect_log_$notes_ref" "output_log_$notes_ref"
38}
39
40cat <<EOF | sort >expect_notes_x
415e93d24084d32e1cb61f7070505b9d2530cca987 $commit_sha4
428366731eeee53787d2bdf8fc1eff7d94757e8da0 $commit_sha3
43eede89064cd42441590d6afec6c37b321ada3389 $commit_sha2
44daa55ffad6cb99bf64226532147ffcaf5ce8bdd1 $commit_sha1
45EOF
46
47cat >expect_log_x <<EOF
48$commit_sha5 5th
49
50$commit_sha4 4th
51Notes on 4th commit
52
53$commit_sha3 3rd
54Notes on 3rd commit
55
56$commit_sha2 2nd
57Notes on 2nd commit
58
59$commit_sha1 1st
60Notes on 1st commit
61
62EOF
63
64test_expect_success 'verify initial notes (x)' '
65 verify_notes x
66'
67
68cp expect_notes_x expect_notes_y
69cp expect_log_x expect_log_y
70
71test_expect_success 'fail to merge empty notes ref into empty notes ref (z => y)' '
72 test_must_fail git -c "core.notesRef=refs/notes/y" notes merge z
73'
74
75test_expect_success 'fail to merge into various non-notes refs' '
76 test_must_fail git -c "core.notesRef=refs/notes" notes merge x &&
77 test_must_fail git -c "core.notesRef=refs/notes/" notes merge x &&
78 mkdir -p .git/refs/notes/dir &&
79 test_must_fail git -c "core.notesRef=refs/notes/dir" notes merge x &&
80 test_must_fail git -c "core.notesRef=refs/notes/dir/" notes merge x &&
81 test_must_fail git -c "core.notesRef=refs/heads/master" notes merge x &&
82 test_must_fail git -c "core.notesRef=refs/notes/y:" notes merge x &&
83 test_must_fail git -c "core.notesRef=refs/notes/y:foo" notes merge x &&
84 test_must_fail git -c "core.notesRef=refs/notes/foo^{bar" notes merge x
85'
86
87test_expect_success 'fail to merge various non-note-trees' '
88 git config core.notesRef refs/notes/y &&
89 test_must_fail git notes merge refs/notes &&
90 test_must_fail git notes merge refs/notes/ &&
91 test_must_fail git notes merge refs/notes/dir &&
92 test_must_fail git notes merge refs/notes/dir/ &&
93 test_must_fail git notes merge refs/heads/master &&
94 test_must_fail git notes merge x: &&
95 test_must_fail git notes merge x:foo &&
96 test_must_fail git notes merge foo^{bar
97'
98
99test_expect_success 'merge notes into empty notes ref (x => y)' '
100 git config core.notesRef refs/notes/y &&
101 git notes merge x &&
102 verify_notes y &&
103 # x and y should point to the same notes commit
104 test "$(git rev-parse refs/notes/x)" = "$(git rev-parse refs/notes/y)"
105'
106
107test_expect_success 'merge empty notes ref (z => y)' '
108 git notes merge z &&
109 # y should not change (still == x)
110 test "$(git rev-parse refs/notes/x)" = "$(git rev-parse refs/notes/y)"
111'
112
113test_expect_success 'change notes on other notes ref (y)' '
114 # Not touching notes to 1st commit
115 git notes remove 2nd &&
116 git notes append -m "More notes on 3rd commit" 3rd &&
117 git notes add -f -m "New notes on 4th commit" 4th &&
118 git notes add -m "Notes on 5th commit" 5th
119'
120
121test_expect_success 'merge previous notes commit (y^ => y) => No-op' '
122 pre_state="$(git rev-parse refs/notes/y)" &&
123 git notes merge y^ &&
124 # y should not move
125 test "$pre_state" = "$(git rev-parse refs/notes/y)"
126'
127
128cat <<EOF | sort >expect_notes_y
1290f2efbd00262f2fd41dfae33df8765618eeacd99 $commit_sha5
130dec2502dac3ea161543f71930044deff93fa945c $commit_sha4
1314069cdb399fd45463ec6eef8e051a16a03592d91 $commit_sha3
132daa55ffad6cb99bf64226532147ffcaf5ce8bdd1 $commit_sha1
133EOF
134
135cat >expect_log_y <<EOF
136$commit_sha5 5th
137Notes on 5th commit
138
139$commit_sha4 4th
140New notes on 4th commit
141
142$commit_sha3 3rd
143Notes on 3rd commit
144
145More notes on 3rd commit
146
147$commit_sha2 2nd
148
149$commit_sha1 1st
150Notes on 1st commit
151
152EOF
153
154test_expect_success 'verify changed notes on other notes ref (y)' '
155 verify_notes y
156'
157
158test_expect_success 'verify unchanged notes on original notes ref (x)' '
159 verify_notes x
160'
161
162test_expect_success 'merge original notes (x) into changed notes (y) => No-op' '
163 git notes merge -vvv x &&
164 verify_notes y &&
165 verify_notes x
166'
167
168cp expect_notes_y expect_notes_x
169cp expect_log_y expect_log_x
170
171test_expect_success 'merge changed (y) into original (x) => Fast-forward' '
172 git config core.notesRef refs/notes/x &&
173 git notes merge y &&
174 verify_notes x &&
175 verify_notes y &&
176 # x and y should point to same the notes commit
177 test "$(git rev-parse refs/notes/x)" = "$(git rev-parse refs/notes/y)"
178'
179
180test_done