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
;;