Reputation: 1928
I'm trying to write a merge driver for git that used the kdiff3 for merge and conflict resolution.
I need a way to know if kdiff3 was successful in the merge or not.
So far I've got this:
#!/bin/bash
Kdiff3 "${1}" "${2}" "${3}" -o "${1}" --L1 "Working Copy" --L2 "Nearest Common ancestor" --L3 "Version from Other Branch"
exit 1
Since the exit 1 tells git whether or not the merge succeed or not, I'd like to set it based on the success of kdiff3.
Is there a way to do this that I am completely missing?
Upvotes: 1
Views: 935
Reputation: 1328992
You can tell if the auto-merge worked by checking if the output has been written by kdiff3, as mentioned in this thread
If you don't specify an output file explicitly (via
-o
) then the third (last) file will be the destination.The exit status is 0 when after a merge the output file was saved successfully.
And 1 if you exit without saving.
That is what this script is testing (here as an example), but using diff3
:
(With kdiff3 command-line options, you should need to add the -auto
option to your command-line)
echo "Attempting to auto-merge ${baseFileName}" 1>&2
diff3 -L $labelMine -L $labelOlder -L $labelTheirs -Em $mine $older $theirs > $output
if [ $? = 1 ]; then
#Can't auto merge
rm -f $output
$VDIFF3 $older $mine $theirs --L1 $labelOlder --L2 $labelMine --L3 $labelTheirs -o $output --auto 1>&2
bLoop=1
if [ -f $output ]; then
if [ -s $output ]; then
#output succesfully written
bLoop=0
fi
fi
if [ $bLoop = 0 ]; then
cat $output
rm -f $output
exit 0
else
echo "Merge failed, try again" 1>&2
fi
else
#We can automerge, and we already did it
cat $output
rm -f $output
exit 0
fi
;;
Upvotes: 1