eadb6b7df61331d80549c02f5648cab1eb229a96
   1#!/bin/sh
   2#
   3# Copyright (c) 2010 Johan Herland
   4#
   5
   6test_description='Test notes merging with manual conflict resolution'
   7
   8. ./test-lib.sh
   9
  10# Set up a notes merge scenario with different kinds of conflicts
  11test_expect_success 'setup commits' '
  12        test_commit 1st &&
  13        test_commit 2nd &&
  14        test_commit 3rd &&
  15        test_commit 4th &&
  16        test_commit 5th
  17'
  18
  19commit_sha1=$(git rev-parse 1st^{commit})
  20commit_sha2=$(git rev-parse 2nd^{commit})
  21commit_sha3=$(git rev-parse 3rd^{commit})
  22commit_sha4=$(git rev-parse 4th^{commit})
  23commit_sha5=$(git rev-parse 5th^{commit})
  24
  25verify_notes () {
  26        notes_ref="$1"
  27        git -c core.notesRef="refs/notes/$notes_ref" notes |
  28                sort >"output_notes_$notes_ref" &&
  29        test_cmp "expect_notes_$notes_ref" "output_notes_$notes_ref" &&
  30        git -c core.notesRef="refs/notes/$notes_ref" log --format="%H %s%n%N" \
  31                >"output_log_$notes_ref" &&
  32        test_cmp "expect_log_$notes_ref" "output_log_$notes_ref"
  33}
  34
  35cat <<EOF | sort >expect_notes_x
  366e8e3febca3c2bb896704335cc4d0c34cb2f8715 $commit_sha4
  37e5388c10860456ee60673025345fe2e153eb8cf8 $commit_sha3
  38ceefa674873670e7ecd131814d909723cce2b669 $commit_sha2
  39EOF
  40
  41cat >expect_log_x <<EOF
  42$commit_sha5 5th
  43
  44$commit_sha4 4th
  45x notes on 4th commit
  46
  47$commit_sha3 3rd
  48x notes on 3rd commit
  49
  50$commit_sha2 2nd
  51x notes on 2nd commit
  52
  53$commit_sha1 1st
  54
  55EOF
  56
  57test_expect_success 'setup merge base (x)' '
  58        git config core.notesRef refs/notes/x &&
  59        git notes add -m "x notes on 2nd commit" 2nd &&
  60        git notes add -m "x notes on 3rd commit" 3rd &&
  61        git notes add -m "x notes on 4th commit" 4th &&
  62        verify_notes x
  63'
  64
  65cat <<EOF | sort >expect_notes_y
  66e2bfd06a37dd2031684a59a6e2b033e212239c78 $commit_sha4
  675772f42408c0dd6f097a7ca2d24de0e78d1c46b1 $commit_sha3
  68b0a6021ec006d07e80e9b20ec9b444cbd9d560d3 $commit_sha1
  69EOF
  70
  71cat >expect_log_y <<EOF
  72$commit_sha5 5th
  73
  74$commit_sha4 4th
  75y notes on 4th commit
  76
  77$commit_sha3 3rd
  78y notes on 3rd commit
  79
  80$commit_sha2 2nd
  81
  82$commit_sha1 1st
  83y notes on 1st commit
  84
  85EOF
  86
  87test_expect_success 'setup local branch (y)' '
  88        git update-ref refs/notes/y refs/notes/x &&
  89        git config core.notesRef refs/notes/y &&
  90        git notes add -f -m "y notes on 1st commit" 1st &&
  91        git notes remove 2nd &&
  92        git notes add -f -m "y notes on 3rd commit" 3rd &&
  93        git notes add -f -m "y notes on 4th commit" 4th &&
  94        verify_notes y
  95'
  96
  97cat <<EOF | sort >expect_notes_z
  98cff59c793c20bb49a4e01bc06fb06bad642e0d54 $commit_sha4
  99283b48219aee9a4105f6cab337e789065c82c2b9 $commit_sha2
 1000a81da8956346e19bcb27a906f04af327e03e31b $commit_sha1
 101EOF
 102
 103cat >expect_log_z <<EOF
 104$commit_sha5 5th
 105
 106$commit_sha4 4th
 107z notes on 4th commit
 108
 109$commit_sha3 3rd
 110
 111$commit_sha2 2nd
 112z notes on 2nd commit
 113
 114$commit_sha1 1st
 115z notes on 1st commit
 116
 117EOF
 118
 119test_expect_success 'setup remote branch (z)' '
 120        git update-ref refs/notes/z refs/notes/x &&
 121        git config core.notesRef refs/notes/z &&
 122        git notes add -f -m "z notes on 1st commit" 1st &&
 123        git notes add -f -m "z notes on 2nd commit" 2nd &&
 124        git notes remove 3rd &&
 125        git notes add -f -m "z notes on 4th commit" 4th &&
 126        verify_notes z
 127'
 128
 129# At this point, before merging z into y, we have the following status:
 130#
 131# commit | base/x  | local/y | remote/z | diff from x to y/z
 132# -------|---------|---------|----------|---------------------------
 133# 1st    | [none]  | b0a6021 | 0a81da8  | added     / added (diff)
 134# 2nd    | ceefa67 | [none]  | 283b482  | removed   / changed
 135# 3rd    | e5388c1 | 5772f42 | [none]   | changed   / removed
 136# 4th    | 6e8e3fe | e2bfd06 | cff59c7  | changed   / changed (diff)
 137# 5th    | [none]  | [none]  | [none]   | [none]
 138
 139cat <<EOF | sort >expect_conflicts
 140$commit_sha1
 141$commit_sha2
 142$commit_sha3
 143$commit_sha4
 144EOF
 145
 146cat >expect_conflict_$commit_sha1 <<EOF
 147<<<<<<< refs/notes/m
 148y notes on 1st commit
 149=======
 150z notes on 1st commit
 151>>>>>>> refs/notes/z
 152EOF
 153
 154cat >expect_conflict_$commit_sha2 <<EOF
 155z notes on 2nd commit
 156EOF
 157
 158cat >expect_conflict_$commit_sha3 <<EOF
 159y notes on 3rd commit
 160EOF
 161
 162cat >expect_conflict_$commit_sha4 <<EOF
 163<<<<<<< refs/notes/m
 164y notes on 4th commit
 165=======
 166z notes on 4th commit
 167>>>>>>> refs/notes/z
 168EOF
 169
 170cp expect_notes_y expect_notes_m
 171cp expect_log_y expect_log_m
 172
 173git rev-parse refs/notes/y > pre_merge_y
 174
 175test_expect_success 'merge z into m (== y) with default ("manual") resolver => Conflicting 3-way merge' '
 176        git update-ref refs/notes/m refs/notes/y &&
 177        git config core.notesRef refs/notes/m &&
 178        test_must_fail git notes merge z >output &&
 179        # Output should point to where to resolve conflicts
 180        grep -q "\\.git/NOTES_MERGE_WORKTREE" output &&
 181        # Inspect merge conflicts
 182        ls .git/NOTES_MERGE_WORKTREE >output_conflicts &&
 183        test_cmp expect_conflicts output_conflicts &&
 184        ( for f in $(cat expect_conflicts); do
 185                test_cmp "expect_conflict_$f" ".git/NOTES_MERGE_WORKTREE/$f" ||
 186                exit 1
 187        done ) &&
 188        # Verify that current notes tree (pre-merge) has not changed (m == y)
 189        verify_notes y &&
 190        verify_notes m &&
 191        test "$(git rev-parse refs/notes/m)" = "$(cat pre_merge_y)"
 192'
 193
 194cat <<EOF | sort >expect_notes_z
 19500494adecf2d9635a02fa431308d67993f853968 $commit_sha4
 196283b48219aee9a4105f6cab337e789065c82c2b9 $commit_sha2
 1970a81da8956346e19bcb27a906f04af327e03e31b $commit_sha1
 198EOF
 199
 200cat >expect_log_z <<EOF
 201$commit_sha5 5th
 202
 203$commit_sha4 4th
 204z notes on 4th commit
 205
 206More z notes on 4th commit
 207
 208$commit_sha3 3rd
 209
 210$commit_sha2 2nd
 211z notes on 2nd commit
 212
 213$commit_sha1 1st
 214z notes on 1st commit
 215
 216EOF
 217
 218test_expect_success 'change notes in z' '
 219        git notes --ref z append -m "More z notes on 4th commit" 4th &&
 220        verify_notes z
 221'
 222
 223test_expect_success 'cannot do merge w/conflicts when previous merge is unfinished' '
 224        test -d .git/NOTES_MERGE_WORKTREE &&
 225        test_must_fail git notes merge z >output 2>&1 &&
 226        # Output should indicate what is wrong
 227        grep -q "\\.git/NOTES_MERGE_\\* exists" output
 228'
 229
 230# Setup non-conflicting merge between x and new notes ref w
 231
 232cat <<EOF | sort >expect_notes_w
 233ceefa674873670e7ecd131814d909723cce2b669 $commit_sha2
 234f75d1df88cbfe4258d49852f26cfc83f2ad4494b $commit_sha1
 235EOF
 236
 237cat >expect_log_w <<EOF
 238$commit_sha5 5th
 239
 240$commit_sha4 4th
 241
 242$commit_sha3 3rd
 243
 244$commit_sha2 2nd
 245x notes on 2nd commit
 246
 247$commit_sha1 1st
 248w notes on 1st commit
 249
 250EOF
 251
 252test_expect_success 'setup unrelated notes ref (w)' '
 253        git config core.notesRef refs/notes/w &&
 254        git notes add -m "w notes on 1st commit" 1st &&
 255        git notes add -m "x notes on 2nd commit" 2nd &&
 256        verify_notes w
 257'
 258
 259cat <<EOF | sort >expect_notes_w
 2606e8e3febca3c2bb896704335cc4d0c34cb2f8715 $commit_sha4
 261e5388c10860456ee60673025345fe2e153eb8cf8 $commit_sha3
 262ceefa674873670e7ecd131814d909723cce2b669 $commit_sha2
 263f75d1df88cbfe4258d49852f26cfc83f2ad4494b $commit_sha1
 264EOF
 265
 266cat >expect_log_w <<EOF
 267$commit_sha5 5th
 268
 269$commit_sha4 4th
 270x notes on 4th commit
 271
 272$commit_sha3 3rd
 273x notes on 3rd commit
 274
 275$commit_sha2 2nd
 276x notes on 2nd commit
 277
 278$commit_sha1 1st
 279w notes on 1st commit
 280
 281EOF
 282
 283test_expect_success 'can do merge without conflicts even if previous merge is unfinished (x => w)' '
 284        test -d .git/NOTES_MERGE_WORKTREE &&
 285        git notes merge x &&
 286        verify_notes w &&
 287        # Verify that other notes refs has not changed (x and y)
 288        verify_notes x &&
 289        verify_notes y
 290'
 291
 292test_done