Adding logic and documentation for a recurse submodules flag

This commit is contained in:
wilso199 2020-08-02 21:36:56 -04:00
parent bb6851c88b
commit 7b98e27de3
2 changed files with 17 additions and 0 deletions

View file

@ -28,6 +28,8 @@ func init() {
RootCmd.AddCommand(prCmd)
prCmd.AddCommand(prCheckoutCmd)
prCheckoutCmd.Flags().BoolP("recurse-submodules", "", false, "Update all active submodules (recursively)")
prCmd.AddCommand(prCreateCmd)
prCmd.AddCommand(prStatusCmd)
prCmd.AddCommand(prCloseCmd)

View file

@ -7,6 +7,7 @@ import (
"os/exec"
"strings"
"github.com/MakeNowJust/heredoc"
"github.com/spf13/cobra"
"github.com/cli/cli/api"
@ -104,6 +105,16 @@ func prCheckout(cmd *cobra.Command, args []string) error {
}
}
recurseSubmodules, err := cmd.Flags().GetBool("recurse-submodules")
if err != nil {
return err
}
if recurseSubmodules {
cmdQueue = append(cmdQueue, []string{"git", "submodule", "sync", "--recursive"})
cmdQueue = append(cmdQueue, []string{"git", "submodule", "update", "--init", "--recursive"})
}
for _, args := range cmdQueue {
cmd := exec.Command(args[0], args[1:]...)
cmd.Stdout = os.Stdout
@ -119,6 +130,10 @@ func prCheckout(cmd *cobra.Command, args []string) error {
var prCheckoutCmd = &cobra.Command{
Use: "checkout {<number> | <url> | <branch>}",
Short: "Check out a pull request in Git",
Example: heredoc.Doc(`
$ gh pr checkout 353
$ gh pr checkout 353 --recurse-submodules
`),
Args: func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
return errors.New("requires a pull request number as an argument")