Here's an extended example.
mkdir -p ~/tmp/xml-merge-example
cd !$
git init .
cat > example.xml <<EOF
<?xml version='1.0'?>
<hurr durr='hello'/>
<durr hurr='world'/>
EOF
git add .
git commit -m "Initial commit."
git checkout -b alternate-reality
cat > example.xml <<EOF
<?xml version='1.0'?>
<durr hurr='world'/>
<hurr durr='hello'/>
<foo reality='alternate'/>
EOF
git add .
git commit -m "Alternate reality."
git checkout master
sed -i '' -e 's/hello/foo/' -e 's/world/bar/' example.xml
git add .
git commit -m "Hello foo to the world bar."
git merge alternate-reality
The attempted merge will result in the following: Auto-merging example.xml
CONFLICT (content): Merge conflict in example.xml
Automatic merge failed; fix conflicts and then commit the result.
For a quick PoC, let's create a little script that will echo the arguments that was passed to it and then exit with failure. The real script would work as outlined in the parent comment and would exit with success at the end as long as the merge worked out.The t argument to mergetool works a bit different than I thought, but not by much -- the tool must be referenced by name and the corresponding mergetool.<tool>.cmd must have been set. In the command you use the variables $BASE, $LOCAL, $REMOTE and $MERGED as explained in https://git-scm.com/docs/git-mergetool#git-mergetool--tlttoo... . This allows tools with different argument ordering, flags and such to be used.
Let's write the PoC script
mkdir -p ~/bin
cat >~/bin/mergepoc.bash <<'EOF'
#!/usr/bin/env bash
echo "$0: WARN: Proof-of-Concept" 1>&2
echo "$0: INFO: Arguments: $@" 1>&2
exit 1
EOF
chmod 755 ~/bin/mergepoc.bash
and define the mergetool cmd git config mergetool.mergepoc.cmd '~/bin/mergepoc.bash --base "$BASE" "$LOCAL" "$REMOTE" -o "$MERGED"'
and tell git to trust the exit status of this tool git config mergetool.mergepoc.trustExitCode true
Then we run it. git mergetool -t mergepoc example.xml
Result (with an additional line-break inserted in order for to avoid having the contents shown here scroll sideways): Merging:
example.xml
Normal merge conflict for 'example.xml':
{local}: modified file
{remote}: modified file
/home/erikn/bin/mergepoc.bash: WARN: Proof-of-Concept
/home/erikn/bin/mergepoc.bash: INFO: Arguments: --base ./example_BASE_4020.xml
./example_LOCAL_4020.xml ./example_REMOTE_4020.xml -o example.xml
merge of example.xml failed
Continue merging other unresolved paths [y/n]? n