Skip to content

Instantly share code, notes, and snippets.

@VonC
Created May 15, 2023 12:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VonC/a802b9668d6b94dfb2573b0a78911bce to your computer and use it in GitHub Desktop.
Save VonC/a802b9668d6b94dfb2573b0a78911bce to your computer and use it in GitHub Desktop.
How can WinMerge give me notification if there are still conflicts when I close it?

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:

  1. 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
  1. Make this script executable with the command:
chmod +x winmerge-with-conflict-check.sh
  1. 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
  1. 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.

@asmwarrior
Copy link

asmwarrior commented May 15, 2023

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment