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 (5.6 - 5.16)

    
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