Skip to content

Commit

Permalink
fix(cmd): fixed pull cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
Raj Nandan Sharma authored and Raj Nandan Sharma committed Apr 18, 2024
1 parent 10c7da8 commit 24f2b42
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
6 changes: 1 addition & 5 deletions cmd/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")

},
}
Expand Down
3 changes: 3 additions & 0 deletions cmd/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
21 changes: 15 additions & 6 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")
Expand All @@ -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, "")

},
}

Expand Down

0 comments on commit 24f2b42

Please sign in to comment.