git merge programmatically detect conflict
Solution 1:
git merge
already has an exit code which indicates success or failure.
Either use git merge auto
directly in your if
:
if git merge auto; then
echo "sucess !"
else
exitcode=$?
echo "failure"
exit $exitcode
fi
or store the exit code right after executing git merge auto
for later comparison :
git merge auto
exitcode=$?
... # do something else
if [ $exitcode -eq 0 ]; then
echo "success"
else
echo "failure"
fi
Your current script is roughly equivalent to :
if git merge auto > /dev/null; then
exit 0;
else
exit 1;
fi