mirror of
https://github.com/daveberrys/guh.git
synced 2026-11-29 00:46:45 +08:00
improve commiting and pushing
This commit is contained in:
1 parent
99e2b8d92f
commit
5c7575a889
2 files changed
+74
-6
No files matched your search
+54
-3
@@ -3,6 +3,7 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/daveberrys/guh/src/utils"
|
"github.com/daveberrys/guh/src/utils"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@@ -13,7 +14,7 @@ func init() { rootCmd.AddCommand(commitCmd) }
|
|||||||
var commitCmd = &cobra.Command{
|
var commitCmd = &cobra.Command{
|
||||||
Use: "commit [files] [message] [description]",
|
Use: "commit [files] [message] [description]",
|
||||||
Short: "Add specified files and commit",
|
Short: "Add specified files and commit",
|
||||||
Args: cobra.RangeArgs(0, 3),
|
Args: cobra.RangeArgs(0, 5),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
return utils.RunGitSequence(false, []string{"status", "--short"})
|
return utils.RunGitSequence(false, []string{"status", "--short"})
|
||||||
@@ -35,16 +36,66 @@ var commitCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Edited files:")
|
fmt.Println("Edited files:")
|
||||||
if err := utils.RunGitSequence(false, []string{"status", "--short"}); err != nil { return err }
|
if err := utils.RunGitSequence(false, []string{"status", "--short"}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
|
|
||||||
utils.RunGitSequence(false, addArgs)
|
utils.RunGitSequence(false, addArgs)
|
||||||
|
|
||||||
commitArgs := []string{"commit", "-m", args[1]}
|
commitArgs := []string{"commit", "-m", args[1]}
|
||||||
if len(args) == 3 {
|
afterPush, remoteName := false, "origin"
|
||||||
|
|
||||||
|
// case 1 -> guh commit [files] [message] [desc] push[:optional] [remote_name:optional(origin)]
|
||||||
|
// case 2 -> guh commit [files] [message] push[:optional] [remote_name:optional(origin)]
|
||||||
|
// case 3 -> guh commit [files] [message] [desc]
|
||||||
|
// case 4 -> guh commit [files] [message]
|
||||||
|
switch len(args) {
|
||||||
|
case 5:
|
||||||
|
// [files] [message] [desc] push [remote] (case 1)
|
||||||
commitArgs = append(commitArgs, "-m", args[2])
|
commitArgs = append(commitArgs, "-m", args[2])
|
||||||
|
afterPush = true
|
||||||
|
if args[4] != "" {
|
||||||
|
remoteName = args[4]
|
||||||
|
}
|
||||||
|
case 4:
|
||||||
|
if args[2] == "push" {
|
||||||
|
// [files] [message] push [remote] (case 2)
|
||||||
|
afterPush = true
|
||||||
|
if args[3] != "" {
|
||||||
|
remoteName = args[3]
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// [files] [message] [desc] push (case 1)
|
||||||
|
commitArgs = append(commitArgs, "-m", args[2])
|
||||||
|
afterPush = true
|
||||||
|
}
|
||||||
|
case 3:
|
||||||
|
if args[2] == "push" {
|
||||||
|
// [files] [message] push (case 2)
|
||||||
|
afterPush = true
|
||||||
|
} else {
|
||||||
|
// [files] [message] [desc] (case 3)
|
||||||
|
commitArgs = append(commitArgs, "-m", args[2])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
utils.RunGitSequence(false, commitArgs)
|
utils.RunGitSequence(false, commitArgs)
|
||||||
|
if afterPush {
|
||||||
|
if remoteName == "all" {
|
||||||
|
remotes, err := utils.RunGit(true, "remote")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, r := range strings.Fields(remotes) {
|
||||||
|
if err := utils.RunGitSequence(false, []string{"push", r}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
utils.RunGitSequence(false, []string{"push", remoteName})
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
+20
-3
@@ -1,6 +1,8 @@
|
|||||||
package cmd
|
package cmd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/daveberrys/guh/src/utils"
|
"github.com/daveberrys/guh/src/utils"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
@@ -8,10 +10,25 @@ import (
|
|||||||
func init() { rootCmd.AddCommand(pushCmd) }
|
func init() { rootCmd.AddCommand(pushCmd) }
|
||||||
|
|
||||||
var pushCmd = &cobra.Command{
|
var pushCmd = &cobra.Command{
|
||||||
Use: "push",
|
Use: "push [remote]",
|
||||||
Short: "Add current changes and push",
|
Short: "Add current changes and push",
|
||||||
Args: cobra.NoArgs,
|
Args: cobra.MaximumNArgs(1),
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
return utils.RunGitSequence(false, []string{"push"})
|
if len(args) == 0 {
|
||||||
|
return utils.RunGitSequence(false, []string{"push"})
|
||||||
|
}
|
||||||
|
if args[0] == "all" {
|
||||||
|
remotes, err := utils.RunGit(true, "remote")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, r := range strings.Fields(remotes) {
|
||||||
|
if err := utils.RunGitSequence(false, []string{"push", r}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return utils.RunGitSequence(false, []string{"push", args[0]})
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user