1

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.

enter image description here

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

enter image description here

Pipeline:

branches:
    master:
      - step:
          name: Branch Trigger to Master
          script:
            - echo "Checking Merge Commit"
            - chmod +x MergeCommitCheck.sh && ./MergeCommitCheck.sh
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Karim Ali
  • 11
  • 4
  • What pipeline? The only pipeline in your code is the line where you calculate the value of `parent_commit_count`, and I don't quite understand what part of that pipeline is supposed to fail. – user1934428 May 30 '22 at 06:23
  • Updated it. My bad, new to DevOps. My apologies :) The pipeline is to maintain a clean git history of the graph, so that when merge is done, the pipeline will check if rebase is required and if it is rebased and merged onto master. The pipeline should fail if the merge is not good (in this case if no rebase is required or the commit that has been merged into master is not rebased) – Karim Ali May 30 '22 at 06:38

0 Answers0