Merge branch 'kg/packed-ref-cache-fix'
[git] / t / t3320-notes-merge-worktrees.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2015 Twitter, Inc
4 #
5
6 test_description='Test merging of notes trees in multiple worktrees'
7
8 . ./test-lib.sh
9
10 test_expect_success 'setup commit' '
11         test_commit tantrum
12 '
13
14 commit_tantrum=$(git rev-parse tantrum^{commit})
15
16 test_expect_success 'setup notes ref (x)' '
17         git config core.notesRef refs/notes/x &&
18         git notes add -m "x notes on tantrum" tantrum
19 '
20
21 test_expect_success 'setup local branch (y)' '
22         git update-ref refs/notes/y refs/notes/x &&
23         git config core.notesRef refs/notes/y &&
24         git notes remove tantrum
25 '
26
27 test_expect_success 'setup remote branch (z)' '
28         git update-ref refs/notes/z refs/notes/x &&
29         git config core.notesRef refs/notes/z &&
30         git notes add -f -m "conflicting notes on tantrum" tantrum
31 '
32
33 test_expect_success 'modify notes ref ourselves (x)' '
34         git config core.notesRef refs/notes/x &&
35         git notes add -f -m "more conflicting notes on tantrum" tantrum
36 '
37
38 test_expect_success 'create some new worktrees' '
39         git worktree add -b newbranch worktree master &&
40         git worktree add -b newbranch2 worktree2 master
41 '
42
43 test_expect_success 'merge z into y fails and sets NOTES_MERGE_REF' '
44         git config core.notesRef refs/notes/y &&
45         test_must_fail git notes merge z &&
46         echo "ref: refs/notes/y" >expect &&
47         test_cmp .git/NOTES_MERGE_REF expect
48 '
49
50 test_expect_success 'merge z into y while mid-merge in another workdir fails' '
51         (
52                 cd worktree &&
53                 git config core.notesRef refs/notes/y &&
54                 test_must_fail git notes merge z 2>err &&
55                 test_i18ngrep "a notes merge into refs/notes/y is already in-progress at" err
56         ) &&
57         test_path_is_missing .git/worktrees/worktree/NOTES_MERGE_REF
58 '
59
60 test_expect_success 'merge z into x while mid-merge on y succeeds' '
61         (
62                 cd worktree2 &&
63                 git config core.notesRef refs/notes/x &&
64                 test_must_fail git notes merge z >out 2>&1 &&
65                 test_i18ngrep "Automatic notes merge failed" out &&
66                 grep -v "A notes merge into refs/notes/x is already in-progress in" out
67         ) &&
68         echo "ref: refs/notes/x" >expect &&
69         test_cmp .git/worktrees/worktree2/NOTES_MERGE_REF expect
70 '
71
72 test_done