/
squash_merge_branch_step.go
51 lines (44 loc) · 1.58 KB
/
squash_merge_branch_step.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package steps
import (
"github.com/Originate/git-town/src/git"
"github.com/Originate/git-town/src/prompt"
"github.com/Originate/git-town/src/script"
)
// SquashMergeBranchStep squash merges the branch with the given name into the current branch
type SquashMergeBranchStep struct {
NoOpStep
BranchName string
CommitMessage string
}
// CreateAbortStep returns the abort step for this step.
func (step *SquashMergeBranchStep) CreateAbortStep() Step {
return &DiscardOpenChangesStep{}
}
// CreateUndoStepAfterRun returns the undo step for this step after it is run.
func (step *SquashMergeBranchStep) CreateUndoStepAfterRun() Step {
return &RevertCommitStep{Sha: git.GetCurrentSha()}
}
// GetAutomaticAbortErrorMessage returns the error message to display when this step
// cause the command to automatically abort.
func (step *SquashMergeBranchStep) GetAutomaticAbortErrorMessage() string {
return "Aborted because commit exited with error"
}
// Run executes this step.
func (step *SquashMergeBranchStep) Run() error {
script.SquashMerge(step.BranchName)
args := []string{"commit"}
if step.CommitMessage != "" {
args = append(args, "-m", step.CommitMessage)
}
author := prompt.GetSquashCommitAuthor(step.BranchName)
if author != git.GetLocalAuthor() {
args = append(args, "--author", author)
}
git.CommentOutSquashCommitMessage("")
return script.RunCommand("git", args...)
}
// ShouldAutomaticallyAbortOnError returns whether this step should cause the command to
// automatically abort if it errors.
func (step *SquashMergeBranchStep) ShouldAutomaticallyAbortOnError() bool {
return true
}