t / t3308-notes-merge.shon commit Merge branch 'master' of https://github.com/vnwildman/git (26a567e)
   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        # Copy notes to remote-notes
  23        git fetch . refs/notes/*:refs/remote-notes/origin/*
  24'
  25
  26commit_sha1=$(git rev-parse 1st^{commit})
  27commit_sha2=$(git rev-parse 2nd^{commit})
  28commit_sha3=$(git rev-parse 3rd^{commit})
  29commit_sha4=$(git rev-parse 4th^{commit})
  30commit_sha5=$(git rev-parse 5th^{commit})
  31
  32verify_notes () {
  33        notes_ref="$1"
  34        git -c core.notesRef="refs/notes/$notes_ref" notes |
  35                sort >"output_notes_$notes_ref" &&
  36        test_cmp "expect_notes_$notes_ref" "output_notes_$notes_ref" &&
  37        git -c core.notesRef="refs/notes/$notes_ref" log --format="%H %s%n%N" \
  38                >"output_log_$notes_ref" &&
  39        test_cmp "expect_log_$notes_ref" "output_log_$notes_ref"
  40}
  41
  42cat <<EOF | sort >expect_notes_x
  435e93d24084d32e1cb61f7070505b9d2530cca987 $commit_sha4
  448366731eeee53787d2bdf8fc1eff7d94757e8da0 $commit_sha3
  45eede89064cd42441590d6afec6c37b321ada3389 $commit_sha2
  46daa55ffad6cb99bf64226532147ffcaf5ce8bdd1 $commit_sha1
  47EOF
  48
  49cat >expect_log_x <<EOF
  50$commit_sha5 5th
  51
  52$commit_sha4 4th
  53Notes on 4th commit
  54
  55$commit_sha3 3rd
  56Notes on 3rd commit
  57
  58$commit_sha2 2nd
  59Notes on 2nd commit
  60
  61$commit_sha1 1st
  62Notes on 1st commit
  63
  64EOF
  65
  66test_expect_success 'verify initial notes (x)' '
  67        verify_notes x
  68'
  69
  70cp expect_notes_x expect_notes_y
  71cp expect_notes_x expect_notes_v
  72cp expect_log_x expect_log_y
  73cp expect_log_x expect_log_v
  74
  75test_expect_success 'fail to merge empty notes ref into empty notes ref (z => y)' '
  76        test_must_fail git -c "core.notesRef=refs/notes/y" notes merge z
  77'
  78
  79test_expect_success 'fail to merge into various non-notes refs' '
  80        test_must_fail git -c "core.notesRef=refs/notes" notes merge x &&
  81        test_must_fail git -c "core.notesRef=refs/notes/" notes merge x &&
  82        git update-ref refs/notes/dir/foo HEAD &&
  83        test_must_fail git -c "core.notesRef=refs/notes/dir" notes merge x &&
  84        test_must_fail git -c "core.notesRef=refs/notes/dir/" notes merge x &&
  85        test_must_fail git -c "core.notesRef=refs/heads/master" notes merge x &&
  86        test_must_fail git -c "core.notesRef=refs/notes/y:" notes merge x &&
  87        test_must_fail git -c "core.notesRef=refs/notes/y:foo" notes merge x &&
  88        test_must_fail git -c "core.notesRef=refs/notes/foo^{bar" notes merge x
  89'
  90
  91test_expect_success 'merge non-notes ref into empty notes ref (remote-notes/origin/x => v)' '
  92        git config core.notesRef refs/notes/v &&
  93        git notes merge refs/remote-notes/origin/x &&
  94        verify_notes v &&
  95        # refs/remote-notes/origin/x and v should point to the same notes commit
  96        test "$(git rev-parse refs/remote-notes/origin/x)" = "$(git rev-parse refs/notes/v)"
  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_expect_success 'merge empty notes ref (z => y)' '
 181        # Prepare empty (but valid) notes ref (z)
 182        git config core.notesRef refs/notes/z &&
 183        git notes add -m "foo" &&
 184        git notes remove &&
 185        git notes >output_notes_z &&
 186        test_must_be_empty output_notes_z &&
 187        # Do the merge (z => y)
 188        git config core.notesRef refs/notes/y &&
 189        git notes merge z &&
 190        verify_notes y &&
 191        # y should no longer point to the same notes commit as x
 192        test "$(git rev-parse refs/notes/x)" != "$(git rev-parse refs/notes/y)"
 193'
 194
 195cat <<EOF | sort >expect_notes_y
 1960f2efbd00262f2fd41dfae33df8765618eeacd99 $commit_sha5
 197dec2502dac3ea161543f71930044deff93fa945c $commit_sha4
 1984069cdb399fd45463ec6eef8e051a16a03592d91 $commit_sha3
 199d000d30e6ddcfce3a8122c403226a2ce2fd04d9d $commit_sha2
 20043add6bd0c8c0bc871ac7991e0f5573cfba27804 $commit_sha1
 201EOF
 202
 203cat >expect_log_y <<EOF
 204$commit_sha5 5th
 205Notes on 5th commit
 206
 207$commit_sha4 4th
 208New notes on 4th commit
 209
 210$commit_sha3 3rd
 211Notes on 3rd commit
 212
 213More notes on 3rd commit
 214
 215$commit_sha2 2nd
 216New notes on 2nd commit
 217
 218$commit_sha1 1st
 219Notes on 1st commit
 220
 221More notes on 1st commit
 222
 223EOF
 224
 225test_expect_success 'change notes on other notes ref (y)' '
 226        # Append to 1st commit notes
 227        git notes append -m "More notes on 1st commit" 1st &&
 228        # Add new notes to 2nd commit
 229        git notes add -m "New notes on 2nd commit" 2nd &&
 230        verify_notes y
 231'
 232
 233cat <<EOF | sort >expect_notes_x
 2340f2efbd00262f2fd41dfae33df8765618eeacd99 $commit_sha5
 2351f257a3a90328557c452f0817d6cc50c89d315d4 $commit_sha4
 236daa55ffad6cb99bf64226532147ffcaf5ce8bdd1 $commit_sha1
 237EOF
 238
 239cat >expect_log_x <<EOF
 240$commit_sha5 5th
 241Notes on 5th commit
 242
 243$commit_sha4 4th
 244New notes on 4th commit
 245
 246More notes on 4th commit
 247
 248$commit_sha3 3rd
 249
 250$commit_sha2 2nd
 251
 252$commit_sha1 1st
 253Notes on 1st commit
 254
 255EOF
 256
 257test_expect_success 'change notes on notes ref (x)' '
 258        git config core.notesRef refs/notes/x &&
 259        git notes remove 3rd &&
 260        git notes append -m "More notes on 4th commit" 4th &&
 261        verify_notes x
 262'
 263
 264cat <<EOF | sort >expect_notes_x
 2650f2efbd00262f2fd41dfae33df8765618eeacd99 $commit_sha5
 2661f257a3a90328557c452f0817d6cc50c89d315d4 $commit_sha4
 267d000d30e6ddcfce3a8122c403226a2ce2fd04d9d $commit_sha2
 26843add6bd0c8c0bc871ac7991e0f5573cfba27804 $commit_sha1
 269EOF
 270
 271cat >expect_log_x <<EOF
 272$commit_sha5 5th
 273Notes on 5th commit
 274
 275$commit_sha4 4th
 276New notes on 4th commit
 277
 278More notes on 4th commit
 279
 280$commit_sha3 3rd
 281
 282$commit_sha2 2nd
 283New notes on 2nd commit
 284
 285$commit_sha1 1st
 286Notes on 1st commit
 287
 288More notes on 1st commit
 289
 290EOF
 291
 292test_expect_success 'merge y into x => Non-conflicting 3-way merge' '
 293        git notes merge y &&
 294        verify_notes x &&
 295        verify_notes y
 296'
 297
 298cat <<EOF | sort >expect_notes_w
 29905a4927951bcef347f51486575b878b2b60137f2 $commit_sha3
 300d000d30e6ddcfce3a8122c403226a2ce2fd04d9d $commit_sha2
 301EOF
 302
 303cat >expect_log_w <<EOF
 304$commit_sha5 5th
 305
 306$commit_sha4 4th
 307
 308$commit_sha3 3rd
 309New notes on 3rd commit
 310
 311$commit_sha2 2nd
 312New notes on 2nd commit
 313
 314$commit_sha1 1st
 315
 316EOF
 317
 318test_expect_success 'create notes on new, separate notes ref (w)' '
 319        git config core.notesRef refs/notes/w &&
 320        # Add same note as refs/notes/y on 2nd commit
 321        git notes add -m "New notes on 2nd commit" 2nd &&
 322        # Add new note on 3rd commit (non-conflicting)
 323        git notes add -m "New notes on 3rd commit" 3rd &&
 324        # Verify state of notes on new, separate notes ref (w)
 325        verify_notes w
 326'
 327
 328cat <<EOF | sort >expect_notes_x
 3290f2efbd00262f2fd41dfae33df8765618eeacd99 $commit_sha5
 3301f257a3a90328557c452f0817d6cc50c89d315d4 $commit_sha4
 33105a4927951bcef347f51486575b878b2b60137f2 $commit_sha3
 332d000d30e6ddcfce3a8122c403226a2ce2fd04d9d $commit_sha2
 33343add6bd0c8c0bc871ac7991e0f5573cfba27804 $commit_sha1
 334EOF
 335
 336cat >expect_log_x <<EOF
 337$commit_sha5 5th
 338Notes on 5th commit
 339
 340$commit_sha4 4th
 341New notes on 4th commit
 342
 343More notes on 4th commit
 344
 345$commit_sha3 3rd
 346New notes on 3rd commit
 347
 348$commit_sha2 2nd
 349New notes on 2nd commit
 350
 351$commit_sha1 1st
 352Notes on 1st commit
 353
 354More notes on 1st commit
 355
 356EOF
 357
 358test_expect_success 'merge w into x => Non-conflicting history-less merge' '
 359        git config core.notesRef refs/notes/x &&
 360        git notes merge w &&
 361        # Verify new state of notes on other notes ref (x)
 362        verify_notes x &&
 363        # Also verify that nothing changed on other notes refs (y and w)
 364        verify_notes y &&
 365        verify_notes w
 366'
 367
 368test_done