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