-
-
Notifications
You must be signed in to change notification settings - Fork 107
/
save.go
50 lines (44 loc) · 1.17 KB
/
save.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
package cmd
import (
"fmt"
"github.com/spf13/cobra"
"strings"
)
// saveCmd represents the save command
var saveCmd = &cobra.Command{
Use: "save",
Short: "Save your changes to your current branch",
Long: `E.g. bit save; bit save "commit message"`,
Run: func(cmd *cobra.Command, args []string) {
msg := ""
if len(args) > 0 {
msg = strings.Join(args, " ")
}
save(msg)
},
//Args: cobra.MaximumNArgs(1),
}
// add comment
func init() {
ShellCmd.AddCommand(saveCmd)
// saveCmd.PersistentFlags().String("foo", "", "A help for foo")
// saveCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
func save(msg string) {
if NothingToCommit() {
fmt.Println("nothing to save or commit")
return
}
if msg == "" {
//if ahead of master
if IsAheadOfCurrent() || !CloudBranchExists() {
Runwithcolor("git", []string{"commit", "-a", "--amend", "--no-edit"}) // amend if already ahead
} else {
Runwithcolor("git", []string{"status", "-sb"})
resp := PromptUser("Please provide a description of your changes")
Runwithcolor("git", []string{"commit", "-a", "-m " + resp})
}
} else {
Runwithcolor("git", []string{"commit", "-a", "-m " + msg})
}
}