/
pull_branch_strategy.go
47 lines (40 loc) · 1.19 KB
/
pull_branch_strategy.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
package cmd
import (
"fmt"
"github.com/Originate/git-town/src/cfmt"
"github.com/Originate/git-town/src/git"
"github.com/spf13/cobra"
)
var pullBranchStrategyCommand = &cobra.Command{
Use: "pull-branch-strategy [(rebase | merge)]",
Short: "Displays or sets your pull branch strategy",
Long: `Displays or sets your pull branch strategy
The pull branch strategy specifies what strategy to use
when merging remote tracking branches into local branches
for the main branch and perennial branches.`,
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
printPullBranchStrategy()
} else {
setPullBranchStrategy(args[0])
}
},
Args: func(cmd *cobra.Command, args []string) error {
if len(args) == 1 && args[0] != "rebase" && args[0] != "merge" {
return fmt.Errorf("invalid value: %q", args[0])
}
return cobra.MaximumNArgs(1)(cmd, args)
},
PreRunE: func(cmd *cobra.Command, args []string) error {
return git.ValidateIsRepository()
},
}
func printPullBranchStrategy() {
cfmt.Println(git.Config().GetPullBranchStrategy())
}
func setPullBranchStrategy(value string) {
git.Config().SetPullBranchStrategy(value)
}
func init() {
RootCmd.AddCommand(pullBranchStrategyCommand)
}