diff --git a/cmd/pull.go b/cmd/pull.go index 3066a96..c6cf582 100644 --- a/cmd/pull.go +++ b/cmd/pull.go @@ -41,11 +41,7 @@ var pullCmd = &cobra.Command{ gitPull := models.AllCommands["gitPull"] gitPull.Arguments = append(gitPull.Arguments, string(branch)) - cmdOut, cmdErr = utils.RunCommand(gitPull.Name, gitPull.Arguments, "") - if cmdErr != nil { - utils.LogFatal(cmdErr) - } - utils.LogOutput(cmdOut) + utils.RunCommand(gitPull.Name, gitPull.Arguments, "") }, } diff --git a/cmd/push.go b/cmd/push.go index de54596..5f3783d 100644 --- a/cmd/push.go +++ b/cmd/push.go @@ -12,6 +12,9 @@ var pushCmd = &cobra.Command{ Long: "Push local branch changes to remote. Similar to `git push`. Example usage: okgit ps", Run: func(cmd *cobra.Command, args []string) { + // do a git pull first + pullCmd.Run(cmd, args) + gitPush := models.AllCommands["gitPush"] cmdOut, cmdErr := utils.RunCommand(gitPush.Name, gitPush.Arguments, "") if cmdErr != nil { diff --git a/cmd/root.go b/cmd/root.go index 1995918..0853f70 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -17,7 +17,7 @@ var rootCmd = &cobra.Command{ // Uncomment the following line if your bare application // has an action associated with it: // Run: func(cmd *cobra.Command, args []string) { }, - Version: "1.0.8", + Version: "1.0.9", } // Execute adds all child commands to the root command and sets flags appropriately. diff --git a/cmd/start.go b/cmd/start.go index f355796..d9dfa2f 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -26,7 +26,19 @@ var startCmd = &cobra.Command{ if err != nil { utils.LogFatal(err) } - if len(res) == 0 { + + splitRes := strings.Split(res, "\n") + branchPresent := false + for _, line := range splitRes { + trimmed := strings.TrimSpace(line) + trimmed = strings.TrimPrefix(trimmed, "* ") + if trimmed == branch { + branchPresent = true + break + } + } + + if !branchPresent { createBranch := models.AllCommands["createBranch"] createBranch.Arguments = append(createBranch.Arguments, branch) cmdOut, cmdErr := utils.RunCommand(createBranch.Name, createBranch.Arguments, "") @@ -41,11 +53,8 @@ var startCmd = &cobra.Command{ gitPull := models.AllCommands["gitPull"] gitPull.Arguments = append(gitPull.Arguments, branch) - msg, err1 := utils.RunCommand(gitPull.Name, gitPull.Arguments, "") - if err1 != nil { - utils.LogFatal(err1) - } - utils.LogOutput(msg) + utils.RunCommand(gitPull.Name, gitPull.Arguments, "") + }, }