Skip to main content
Example scripts
arrow icon
To homepage
Bitbucket
Data centre icon
Data Center

Rebase branch

Tags
Created 1 year ago, Updated 5 month(s) ago
App in script
ScriptRunner For Bitbucket
ScriptRunner For Bitbucket
by Adaptavist
Compatibility
compatibility bullet
Bitbucket (6.0 - 7.17)
compatibility bullet
ScriptRunner For Bitbucket (7.10.0)
Language |
groovy
import com.atlassian.bitbucket.scm.git.command.GitExtendedCommandFactory
import com.atlassian.bitbucket.scm.git.command.GitRebaseCommandParameters
import com.atlassian.bitbucket.user.ApplicationUser
import com.atlassian.sal.api.component.ComponentLocator
import com.onresolve.scriptrunner.bitbucket.branch.BranchWithRepository
import com.onresolve.scriptrunner.parameters.annotation.BranchPicker
import com.onresolve.scriptrunner.parameters.annotation.UserPicker

@BranchPicker(label = "Upstream branch to rebase from", description = "Enter the name of the upstream branch")
BranchWithRepository upstreamBranch

@BranchPicker(label = "Branch to rebase", description = "Enter the name of the branch to rebase")
BranchWithRepository branchToRebase

@UserPicker(label = "Rebasing user", description = "User the rebase will be performed as")
ApplicationUser rebasingUser

def gitExtendedCommandFactory = ComponentLocator.getComponent(GitExtendedCommandFactory)

def rebaseCommand = gitExtendedCommandFactory.rebase(branchToRebase.repository,
    new GitRebaseCommandParameters.Builder(branchToRebase, upstreamBranch.latestCommit)
        .committer(rebasingUser)
        .commitRequired(false)
        .upstreamRepository(upstreamBranch.repository)
        .build())

rebaseCommand.call()
Having an issue with this script?
Report it here