You can now vote for scripts to help people know if they're useful or not. Login or create an account to vote!

1

Enforce Squashed Commits

Overview

Force all commits present on a branch to be squashed into a single commit before merging.

Example

You want to stop your team merging branches with multiple commits. Use this script to enforce squashing all commits before a branch can be merged.

Good to Know

  • This script only checks commits created after the branch was created.

Requirements

  • Bitbucket Bitbucket (6.3 - 7.12)
  • ScriptRunner for Bitbucket ScriptRunner for Bitbucket (6.11.0)
    
import com.atlassian.bitbucket.pull.PullRequestService import com.atlassian.sal.api.component.ComponentLocator def pullRequestService = ComponentLocator.getComponent(PullRequestService) def pullRequest = mergeRequest.pullRequest if (pullRequestService.countCommits(pullRequest.fromRef.repository.id, pullRequest.id) > 1) { mergeRequest.veto("Commits have not been squashed", "You should squash your commits into one before merging.") }
Discovered an issue? Report it here

Suggested for you