如果以前的提交被重新纠正,管道将失败

发布于 2025-02-02 23:10:27 字数 1285 浏览 4 评论 0原文

当将提交合并到主人身上时,我能够运行管道以检查是否需要重新重新进行,但是一旦将提交重新构成并与主分支同步,它将通过管道。我的脚本是比较合并完成后的两个父母所做的。如果将提交重新列入并将其合并到Bitbucket Master分支,则搜索使管道失败的方法。

我的脚本如下:

#!/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

branches:
    master:
      - step:
          name: Branch Trigger to Master
          script:
            - echo "Checking Merge Commit"
            - chmod +x MergeCommitCheck.sh && ./MergeCommitCheck.sh

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文