Yes, it's possible to configure WinMerge in a way that it will notify you if there are remaining conflicts when you close it, but it's not a built-in feature of WinMerge itself. The strategy here is to add some script in Git configuration that checks whether the merge made by WinMerge is indeed successful.
Here is a simple approach to achieve this:
- Use a custom script as your mergetool that calls WinMerge and then checks for remaining conflict markers (
<<<<<<<
,=======
,>>>>>>>
) in the file.
Create a file named winmerge-with-conflict-check.sh
with the following content:
#!/bin/sh
# Call WinMerge
"/path/to/WinMergeU.exe" -e -ub -dl "Base" -dr "Mine" "$1" "$2"
# Check for conflict markers
if grep -q '<<<<<<<\|=======\|>>>>>>>' "$2"; then
echo "Warning: unresolved merge conflicts in $2"
exit 1
else
echo "Merge appears to be successful."
fi
- Make this script executable with the command:
chmod +x winmerge-with-conflict-check.sh
- Now, configure Git to use this script as your mergetool:
git config --global mergetool.winmergeWithCheck.cmd "/path/to/winmerge-with-conflict-check.sh \"\$BASE\" \"\$LOCAL\""
git config --global mergetool.winmergeWithCheck.trustExitCode true
- Finally, you can use your new mergetool with:
git mergetool -t winmergeWithCheck
Please make sure to replace "/path/to/WinMergeU.exe"
and "/path/to/winmerge-with-conflict-check.sh"
with the actual paths where these files are located on your machine.
This script is simple and might not catch all possible issues, but it will at least warn you if the obvious conflict markers are still present in the file when you close WinMerge.
First, thanks for sharing the method.
I have one question, when I run the git merge tool, I normally have three files to be shown in winmerge.
$LOCAL $MERGED $REMOTE
But in your script, I don't see there are three files as input, so do you have two panels or three panels?