#!/bin/sh # Based on a test case submitted by Björn Steinbrink. global test_description := ''git blame on conflicted files'' source ./test-lib.sh test_expect_success 'setup first case' ' # Create the old file echo "Old line" > file1 && git add file1 && git commit --author "Old Line " -m file1.a && # Branch git checkout -b foo && # Do an ugly move and change git rm file1 && echo "New line ..." > file2 && echo "... and more" >> file2 && git add file2 && git commit --author "U Gly " -m ugly && # Back to master and change something git checkout master && echo " bla" >> file1 && git commit --author "Old Line " -a -m file1.b && # Back to foo and merge master git checkout foo && if git merge master; then echo needed conflict here exit 1 else echo merge failed - resolving automatically fi && echo "New line ... ... and more bla Even more" > file2 && git rm file1 && git commit --author "M Result " -a -m merged && # Back to master and change file1 again git checkout master && sed s/bla/foo/ X && rm file1 && mv X file1 && git commit --author "No Bla " -a -m replace && # Try to merge into foo again git checkout foo && if git merge master; then echo needed conflict here exit 1 else echo merge failed - test is setup fi ' test_expect_success \ 'blame runs on unconflicted file while other file has conflicts' ' git blame file2 ' test_expect_success 'blame does not crash with conflicted file in stages 1,3' ' git blame file1 ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"git blame on conflicted files">)} spids: [8] ) ] spids: [8] ) (C {(.)} {(./test-lib.sh)}) (C {(test_expect_success)} {(SQ <"setup first case">)} { (SQ <"\n"> <"\t# Create the old file\n"> <"\techo \"Old line\" > file1 &&\n"> <"\tgit add file1 &&\n"> <"\tgit commit --author \"Old Line \" -m file1.a &&\n"> <"\n"> <"\t# Branch\n"> <"\tgit checkout -b foo &&\n"> <"\n"> <"\t# Do an ugly move and change\n"> <"\tgit rm file1 &&\n"> <"\techo \"New line ...\" > file2 &&\n"> <"\techo \"... and more\" >> file2 &&\n"> <"\tgit add file2 &&\n"> <"\tgit commit --author \"U Gly \" -m ugly &&\n"> <"\n"> <"\t# Back to master and change something\n"> <"\tgit checkout master &&\n"> <"\techo \"\n"> <"\n"> <"bla\" >> file1 &&\n"> <"\tgit commit --author \"Old Line \" -a -m file1.b &&\n"> <"\n"> <"\t# Back to foo and merge master\n"> <"\tgit checkout foo &&\n"> <"\tif git merge master; then\n"> <"\t\techo needed conflict here\n"> <"\t\texit 1\n"> <"\telse\n"> <"\t\techo merge failed - resolving automatically\n"> <"\tfi &&\n"> <"\techo \"New line ...\n"> <"... and more\n"> <"\n"> <"bla\n"> <"Even more\" > file2 &&\n"> <"\tgit rm file1 &&\n"> <"\tgit commit --author \"M Result \" -a -m merged &&\n"> <"\n"> <"\t# Back to master and change file1 again\n"> <"\tgit checkout master &&\n"> <"\tsed s/bla/foo/ X &&\n"> <"\trm file1 &&\n"> <"\tmv X file1 &&\n"> <"\tgit commit --author \"No Bla \" -a -m replace &&\n"> <"\n"> <"\t# Try to merge into foo again\n"> <"\tgit checkout foo &&\n"> <"\tif git merge master; then\n"> <"\t\techo needed conflict here\n"> <"\t\texit 1\n"> <"\telse\n"> <"\t\techo merge failed - test is setup\n"> <"\tfi\n"> ) } ) (C {(test_expect_success)} {(SQ <"blame runs on unconflicted file while other file has conflicts">)} {(SQ <"\n"> <"\tgit blame file2\n">)} ) (C {(test_expect_success)} {(SQ <"blame does not crash with conflicted file in stages 1,3">)} {(SQ <"\n"> <"\tgit blame file1\n">)} ) (C {(test_done)}) ] )