I was able to run a pipeline to check if rebased was required or not when a commit is merged onto master, but once the commit is rebased and synced with master branch, it passes the pipeline. My script is comparing the 2 parents commits when the merge is done. Searching for ways to make the pipeline fail if commit was rebased and merged onto bitbucket master branch.
My script is as follows:
#!/bin/bash
trg=$1
itg=$2
parent_commit_count=$(git cat-file -p $BITBUCKET_COMMIT | grep -o -i parent | wc -l)
echo "Number of parent commits:"$parent_commit_count
if [ "${parent_commit_count}" = "2" ]
then
echo "Validating master branch graph shape"
fi
if [[ -z $trg ]]; then
trg=HEAD
fi
if [[ -z $itg ]]; then
itg=master
fi
ret=$(git rev-list $trg..$itg)
if [[ -z $ret ]]; then
echo "No rebase required, sexy graph is maintained."
else
echo "Commit $BITBUCKET_COMMIT needs to be rebased to absorb the following changes:"
for r in $ret
do
echo $r
done
exit 1
fi
Pipeline:
branches:
master:
- step:
name: Branch Trigger to Master
script:
- echo "Checking Merge Commit"
- chmod +x MergeCommitCheck.sh && ./MergeCommitCheck.sh