]>
Commit | Line | Data |
---|---|---|
cf1af1b1 JK |
1 | #!/bin/sh |
2 | ||
3 | test_description='basic git merge-index / git-merge-one-file tests' | |
4 | . ./test-lib.sh | |
5 | ||
6 | test_expect_success 'setup diverging branches' ' | |
08495412 | 7 | test_write_lines 1 2 3 4 5 6 7 8 9 10 >file && |
cf1af1b1 JK |
8 | git add file && |
9 | git commit -m base && | |
10 | git tag base && | |
11 | sed s/2/two/ <file >tmp && | |
12 | mv tmp file && | |
13 | git commit -a -m two && | |
14 | git tag two && | |
15 | git checkout -b other HEAD^ && | |
16 | sed s/10/ten/ <file >tmp && | |
17 | mv tmp file && | |
18 | git commit -a -m ten && | |
19 | git tag ten | |
20 | ' | |
21 | ||
22 | cat >expect-merged <<'EOF' | |
23 | 1 | |
24 | two | |
25 | 3 | |
26 | 4 | |
27 | 5 | |
28 | 6 | |
29 | 7 | |
30 | 8 | |
31 | 9 | |
32 | ten | |
33 | EOF | |
34 | ||
35 | test_expect_success 'read-tree does not resolve content merge' ' | |
36 | git read-tree -i -m base ten two && | |
37 | echo file >expect && | |
38 | git diff-files --name-only --diff-filter=U >unmerged && | |
39 | test_cmp expect unmerged | |
40 | ' | |
41 | ||
42 | test_expect_success 'git merge-index git-merge-one-file resolves' ' | |
43 | git merge-index git-merge-one-file -a && | |
44 | git diff-files --name-only --diff-filter=U >unmerged && | |
d3c6751b | 45 | test_must_be_empty unmerged && |
cf1af1b1 JK |
46 | test_cmp expect-merged file && |
47 | git cat-file blob :file >file-index && | |
48 | test_cmp expect-merged file-index | |
49 | ' | |
50 | ||
51 | test_expect_success 'setup bare merge' ' | |
52 | git clone --bare . bare.git && | |
53 | (cd bare.git && | |
54 | GIT_INDEX_FILE=$PWD/merge.index && | |
55 | export GIT_INDEX_FILE && | |
56 | git read-tree -i -m base ten two | |
57 | ) | |
58 | ' | |
59 | ||
60 | test_expect_success 'merge-one-file fails without a work tree' ' | |
61 | (cd bare.git && | |
62 | GIT_INDEX_FILE=$PWD/merge.index && | |
63 | export GIT_INDEX_FILE && | |
64 | test_must_fail git merge-index git-merge-one-file -a | |
65 | ) | |
66 | ' | |
67 | ||
6aaeca90 | 68 | test_expect_success 'merge-one-file respects GIT_WORK_TREE' ' |
cf1af1b1 JK |
69 | (cd bare.git && |
70 | mkdir work && | |
71 | GIT_WORK_TREE=$PWD/work && | |
72 | export GIT_WORK_TREE && | |
73 | GIT_INDEX_FILE=$PWD/merge.index && | |
74 | export GIT_INDEX_FILE && | |
75 | git merge-index git-merge-one-file -a && | |
76 | git cat-file blob :file >work/file-index | |
77 | ) && | |
78 | test_cmp expect-merged bare.git/work/file && | |
79 | test_cmp expect-merged bare.git/work/file-index | |
80 | ' | |
81 | ||
6aaeca90 | 82 | test_expect_success 'merge-one-file respects core.worktree' ' |
cf1af1b1 JK |
83 | mkdir subdir && |
84 | git clone . subdir/child && | |
85 | (cd subdir && | |
86 | GIT_DIR=$PWD/child/.git && | |
87 | export GIT_DIR && | |
88 | git config core.worktree "$PWD/child" && | |
89 | git read-tree -i -m base ten two && | |
90 | git merge-index git-merge-one-file -a && | |
91 | git cat-file blob :file >file-index | |
92 | ) && | |
93 | test_cmp expect-merged subdir/child/file && | |
94 | test_cmp expect-merged subdir/file-index | |
95 | ' | |
96 | ||
97 | test_done |