/
run.go
76 lines (70 loc) · 2.06 KB
/
run.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package steps
import (
"fmt"
"os"
"github.com/Originate/exit"
"github.com/Originate/git-town/src/git"
"github.com/Originate/git-town/src/util"
"github.com/fatih/color"
)
// Run runs the Git Town command described by the given state
// nolint: gocyclo
func Run(runState *RunState) {
for {
step := runState.RunStepList.Pop()
if step == nil {
runState.MarkAsFinished()
if runState.IsAbort || runState.isUndo {
DeletePreviousRunState()
} else {
SaveRunState(runState)
}
fmt.Println()
return
}
if getTypeName(step) == "*SkipCurrentBranchSteps" {
runState.SkipCurrentBranchSteps()
continue
}
if getTypeName(step) == "*PushBranchAfterCurrentBranchSteps" {
runState.AddPushBranchStepAfterCurrentBranchSteps()
continue
}
undoStepBeforeRun := step.CreateUndoStepBeforeRun()
err := step.Run()
if err != nil {
runState.AbortStepList.Append(step.CreateAbortStep())
if step.ShouldAutomaticallyAbortOnError() {
abortRunState := runState.CreateAbortRunState()
Run(&abortRunState)
util.ExitWithErrorMessage(step.GetAutomaticAbortErrorMessage())
} else {
runState.RunStepList.Prepend(step.CreateContinueStep())
runState.MarkAsUnfinished()
if runState.Command == "sync" && !(git.IsRebaseInProgress() && git.Config().IsMainBranch(git.GetCurrentBranchName())) {
runState.UnfinishedDetails.CanSkip = true
}
SaveRunState(runState)
exitWithMessages(runState.UnfinishedDetails.CanSkip)
}
}
undoStepAfterRun := step.CreateUndoStepAfterRun()
runState.UndoStepList.Prepend(undoStepBeforeRun)
runState.UndoStepList.Prepend(undoStepAfterRun)
}
}
// Helpers
func exitWithMessages(canSkip bool) {
messageFmt := color.New(color.FgRed)
fmt.Println()
_, err := messageFmt.Printf("To abort, run \"git-town abort\".\n")
exit.If(err)
_, err = messageFmt.Printf("To continue after having resolved conflicts, run \"git-town continue\".\n")
exit.If(err)
if canSkip {
_, err = messageFmt.Printf("To continue by skipping the current branch, run \"git-town skip\".\n")
exit.If(err)
}
fmt.Println()
os.Exit(1)
}