]> git.ipfire.org Git - thirdparty/git.git/blame - t/t2023-checkout-m.sh
The third batch
[thirdparty/git.git] / t / t2023-checkout-m.sh
CommitLineData
3d0b0517
PH
1#!/bin/sh
2
3test_description='checkout -m -- <conflicted path>
4
5Ensures that checkout -m on a resolved file restores the conflicted file'
6
883b98ef 7GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
8export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9
3e3b9321 10TEST_PASSES_SANITIZE_LEAK=true
3d0b0517
PH
11. ./test-lib.sh
12
13test_expect_success setup '
14 test_tick &&
15 test_commit both.txt both.txt initial &&
16 git branch topic &&
883b98ef
JS
17 test_commit modified_in_main both.txt in_main &&
18 test_commit added_in_main each.txt in_main &&
3d0b0517
PH
19 git checkout topic &&
20 test_commit modified_in_topic both.txt in_topic &&
21 test_commit added_in_topic each.txt in_topic
22'
23
883b98ef
JS
24test_expect_success 'git merge main' '
25 test_must_fail git merge main
5cd7fadc 26'
3d0b0517
PH
27
28clean_branchnames () {
29 # Remove branch names after conflict lines
30 sed 's/^\([<>]\{5,\}\) .*$/\1/'
31}
32
33test_expect_success '-m restores 2-way conflicted+resolved file' '
34 cp each.txt each.txt.conflicted &&
35 echo resolved >each.txt &&
36 git add each.txt &&
37 git checkout -m -- each.txt &&
38 clean_branchnames <each.txt >each.txt.cleaned &&
39 clean_branchnames <each.txt.conflicted >each.txt.conflicted.cleaned &&
40 test_cmp each.txt.conflicted.cleaned each.txt.cleaned
41'
42
43test_expect_success '-m restores 3-way conflicted+resolved file' '
44 cp both.txt both.txt.conflicted &&
45 echo resolved >both.txt &&
46 git add both.txt &&
47 git checkout -m -- both.txt &&
48 clean_branchnames <both.txt >both.txt.cleaned &&
49 clean_branchnames <both.txt.conflicted >both.txt.conflicted.cleaned &&
50 test_cmp both.txt.conflicted.cleaned both.txt.cleaned
51'
52
ab5af825
NTND
53test_expect_success 'force checkout a conflict file creates stage zero entry' '
54 git init co-force &&
55 (
56 cd co-force &&
57 echo a >a &&
58 git add a &&
59 git commit -ama &&
60 A_OBJ=$(git rev-parse :a) &&
61 git branch topic &&
62 echo b >a &&
63 git commit -amb &&
64 B_OBJ=$(git rev-parse :a) &&
65 git checkout topic &&
66 echo c >a &&
67 C_OBJ=$(git hash-object a) &&
883b98ef 68 git checkout -m main &&
ab5af825
NTND
69 test_cmp_rev :1:a $A_OBJ &&
70 test_cmp_rev :2:a $B_OBJ &&
71 test_cmp_rev :3:a $C_OBJ &&
72 git checkout -f topic &&
73 test_cmp_rev :0:a $A_OBJ
74 )
75'
76
3d0b0517 77test_done