Merge https://github.com/prati0100/git-gui
[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 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10
11 . ./test-lib.sh
12
13 test_expect_success 'setup commit' '
14         test_commit tantrum
15 '
16
17 commit_tantrum=$(git rev-parse tantrum^{commit})
18
19 test_expect_success 'setup notes ref (x)' '
20         git config core.notesRef refs/notes/x &&
21         git notes add -m "x notes on tantrum" tantrum
22 '
23
24 test_expect_success 'setup local branch (y)' '
25         git update-ref refs/notes/y refs/notes/x &&
26         git config core.notesRef refs/notes/y &&
27         git notes remove tantrum
28 '
29
30 test_expect_success 'setup remote branch (z)' '
31         git update-ref refs/notes/z refs/notes/x &&
32         git config core.notesRef refs/notes/z &&
33         git notes add -f -m "conflicting notes on tantrum" tantrum
34 '
35
36 test_expect_success 'modify notes ref ourselves (x)' '
37         git config core.notesRef refs/notes/x &&
38         git notes add -f -m "more conflicting notes on tantrum" tantrum
39 '
40
41 test_expect_success 'create some new worktrees' '
42         git worktree add -b newbranch worktree main &&
43         git worktree add -b newbranch2 worktree2 main
44 '
45
46 test_expect_success 'merge z into y fails and sets NOTES_MERGE_REF' '
47         git config core.notesRef refs/notes/y &&
48         test_must_fail git notes merge z &&
49         echo "ref: refs/notes/y" >expect &&
50         test_cmp expect .git/NOTES_MERGE_REF
51 '
52
53 test_expect_success 'merge z into y while mid-merge in another workdir fails' '
54         (
55                 cd worktree &&
56                 git config core.notesRef refs/notes/y &&
57                 test_must_fail git notes merge z 2>err &&
58                 test_i18ngrep "a notes merge into refs/notes/y is already in-progress at" err
59         ) &&
60         test_path_is_missing .git/worktrees/worktree/NOTES_MERGE_REF
61 '
62
63 test_expect_success 'merge z into x while mid-merge on y succeeds' '
64         (
65                 cd worktree2 &&
66                 git config core.notesRef refs/notes/x &&
67                 test_must_fail git notes merge z >out 2>&1 &&
68                 test_i18ngrep "Automatic notes merge failed" out &&
69                 grep -v "A notes merge into refs/notes/x is already in-progress in" out
70         ) &&
71         echo "ref: refs/notes/x" >expect &&
72         test_cmp expect .git/worktrees/worktree2/NOTES_MERGE_REF
73 '
74
75 test_done