1package cmd
2
3import (
4	"fmt"
5
6	"github.com/git-town/git-town/src/cli"
7	"github.com/git-town/git-town/src/drivers"
8	"github.com/git-town/git-town/src/steps"
9
10	"github.com/spf13/cobra"
11)
12
13var continueCmd = &cobra.Command{
14	Use:   "continue",
15	Short: "Restarts the last run git-town command after having resolved conflicts",
16	Run: func(cmd *cobra.Command, args []string) {
17		runState, err := steps.LoadPreviousRunState(prodRepo)
18		if err != nil {
19			cli.Exit(fmt.Errorf("cannot load previous run state: %v", err))
20		}
21		if runState == nil || !runState.IsUnfinished() {
22			cli.Exit(fmt.Errorf("nothing to continue"))
23		}
24		hasConflicts, err := prodRepo.Silent.HasConflicts()
25		if err != nil {
26			cli.Exit(err)
27		}
28		if hasConflicts {
29			cli.Exit(fmt.Errorf("you must resolve the conflicts before continuing"))
30		}
31		err = steps.Run(runState, prodRepo, drivers.Load(prodRepo.Config, &prodRepo.Silent, cli.PrintDriverAction))
32		if err != nil {
33			cli.Exit(err)
34		}
35	},
36	Args: cobra.NoArgs,
37	PreRunE: func(cmd *cobra.Command, args []string) error {
38		if err := ValidateIsRepository(prodRepo); err != nil {
39			return err
40		}
41		return validateIsConfigured(prodRepo)
42	},
43}
44
45func init() {
46	RootCmd.AddCommand(continueCmd)
47}
48