Reputation: 686
Is there any way to know if the current branch is in merging status?
It means, is there any way to know if MERGE_HEAD exists?
I'm developing a script that will traverse several projects and I want to automatize some steps.
My idea is something like
# for each project
git checkout dev
git pull
git checkout $myBranch
git merge dev
if [[THERE_ARE_CONFLICTS]]
echo "Some warning"
else
git push origin $myBranch
fi;
Upvotes: 0
Views: 593
Reputation: 464
There is no specific Git command for that. You can check the existence of the .git/MERGE* file.
git merge dev
if [ ! -z "$( ls .git/MERGE* 2>/dev/null )" ]; then
echo "Merge is on-going"
else
echo "All fine."
fi
Upvotes: 1
Reputation: 13678
git merge
has a non-zero exit status if there are merge conflicts. That is, you can simply use
git merge dev
if [ "$?" -eq 0 ]; then
echo "All fine."
else
echo "There were merge conflicts."
fi
If you don't have access to the exit status, then checking for existence of .git/MERGE_HEAD
, as kfb suggested in the comments, is a reliable way to detect that git is currently in merging status, as is documented briefly in the git-merge man page:
[..] record $GIT_DIR/MERGE_HEAD (to cause the next git commit command to create a merge commit) [..]
Upvotes: 1