generated from permafrost-dev/go-project-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge main into sweep/add-sweep-config
- Loading branch information
Showing
9 changed files
with
189 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package utils | ||
|
||
import ( | ||
"os/exec" | ||
"strings" | ||
) | ||
|
||
func RunCommand(command string, args ...string) (string, error) { | ||
cmd := exec.Command(command, args...) | ||
result, err := cmd.Output() | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return strings.TrimSpace(string(result)), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/permafrost-dev/git-ninja/app/helpers" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
pushFlag := false | ||
pullFlag := false | ||
|
||
cmd := &cobra.Command{ | ||
Use: "branch:current", | ||
Short: "Work with the current branch or return the current branch name", | ||
Args: cobra.NoArgs, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
branchName, _ := helpers.GetCurrentBranchName() | ||
|
||
if pushFlag { | ||
helpers.RunCommandOnStdout("git", "push", "origin", branchName) | ||
return | ||
} | ||
|
||
if pullFlag { | ||
helpers.RunCommandOnStdout("git", "pull", "origin", branchName, "--rebase") | ||
return | ||
} | ||
|
||
fmt.Println(branchName) | ||
}, | ||
} | ||
|
||
cmd.Flags().BoolVarP(&pushFlag, "push", "p", false, "push the current branch to origin") | ||
cmd.Flags().BoolVarP(&pullFlag, "pull", "u", false, "pull the current branch from origin and rebase") | ||
|
||
rootCmd.AddCommand(cmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/permafrost-dev/git-ninja/app/helpers" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(&cobra.Command{ | ||
Use: "branch:exists [name]", | ||
Short: "Check if the given branch name exists", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if len(args) < 1 { | ||
fmt.Println("error: branch name required") | ||
return | ||
} | ||
|
||
if exists, _ := helpers.BranchExists(args[0]); !exists { | ||
os.Exit(1) | ||
} | ||
|
||
os.Exit(0) | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/permafrost-dev/git-ninja/app/helpers" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(&cobra.Command{ | ||
Use: "branch:last", | ||
Short: "Show the last checked out branch name", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
branchName, _ := helpers.GetLastCheckedoutBranchName() | ||
fmt.Println(branchName) | ||
}, | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
|
||
"github.com/permafrost-dev/git-ninja/app/helpers" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(&cobra.Command{ | ||
Use: "branch:current:push", | ||
Short: "Push the current branch to origin", | ||
Run: func(c *cobra.Command, args []string) { | ||
branch, err := helpers.GetCurrentBranchName() | ||
|
||
if err != nil { | ||
fmt.Println(err) | ||
return | ||
} | ||
|
||
exec.Command("git", "push", "origin", branch).Run() | ||
}, | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
module github.com/vendor-name/git-ninja | ||
module github.com/permafrost-dev/git-ninja | ||
|
||
go 1.19 | ||
|
||
require github.com/blang/semver v3.5.1+incompatible | ||
require ( | ||
github.com/blang/semver v3.5.1+incompatible | ||
github.com/spf13/cobra v1.8.0 | ||
) | ||
|
||
require ( | ||
github.com/inconshreveable/mousetrap v1.1.0 // indirect | ||
github.com/spf13/cobra v1.8.0 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters