Re: [bug?] checkout -m doesn't work without a base version
- From
- Pete Harlan <pgit@pcharlan.com>
- Date
- Dec 7, 2011, 07:30 UTC
- Message-ID
- <4EDF1631.5090906@pcharlan.com>
- In-Reply-To
- <7vbormn8vk.fsf@alter.siamese.dyndns.org>
On 12/05/2011 10:58 AM, Junio C Hamano wrote:
Show 18 quoted lines
> Pete Harlan <pgit@pcharlan.com> writes: > >> But this only works if there's a base version; if foo.c was added in >> each branch, we get: >> >> error: path 'foo.c' does not have all three versions >> >> Git didn't need all three versions to create the original conflicted >> file, so why would it need them to recreate it? > > Because the original "merge" was a bit more carefully written but > "checkout -m" was written without worrying too much about "both sides > added differently" corner case and still being defensive about not doing > random thing upon getting an unexpected input state. > > IOW, being lazy ;-) > > How does this look?
Wow, thanks for the quick response! That does indeed let me checkout the file as expected.
I wrote a test (below) to be folded in with your patch, but the test fails because it expects the restored file to be the same as the originally-conflicted file, but the conflict-line labels change from "HEAD" and "master":
<<<<<<< HEAD in_topic ======= in_master >>>>>>> master
to "ours" and "theirs". (The same thing happens in the 3-way merge case.)
If the label change is expected then I can rewrite the test to ignore labels, or to expect "ours" and "theirs", whichever you think is best. If the label change is unexpected, then I guess the test is good :)
--Pete
-- >8 -- Test 'checkout -m -- path' when path is a 2-way merge
Signed-off-by: Pete Harlan <pgit@pcharlan.com> --- t/t2023-checkout-m-twoway.sh | 29 +++++++++++++++++++++++++++++ 1 files changed, 29 insertions(+), 0 deletions(-) create mode 100755 t/t2023-checkout-m-twoway.sh
diff --git a/t/t2023-checkout-m-twoway.sh b/t/t2023-checkout-m-twoway.sh new file mode 100755 index 0000000..5b50360 --- /dev/null +++ b/t/t2023-checkout-m-twoway.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +test_description='checkout -m -- conflicted/path/with/2-way/merge + +Ensures that checkout -m on a resolved file restores the conflicted file +when it conflicted with a 2-way merge.' + +. ./test-lib.sh + +test_expect_success setup ' + test_tick && + test_commit initial_commit && + git branch topic && + test_commit added_in_master file.txt in_master && + git checkout topic && + test_commit added_in_topic file.txt in_topic +' + +test_must_fail git merge master + +test_expect_success '-m restores 2-way conflicted+resolved file' ' + cp file.txt file.txt.conflicted && + echo resolved >file.txt && + git add file.txt && + git checkout -m -- file.txt && + test_cmp file.txt.conflicted file.txt +' + +test_done