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