From 7b98e27de3230438f294aa9587f91279bccbf1be Mon Sep 17 00:00:00 2001 From: wilso199 Date: Sun, 2 Aug 2020 21:36:56 -0400 Subject: [PATCH] Adding logic and documentation for a recurse submodules flag --- command/pr.go | 2 ++ command/pr_checkout.go | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/command/pr.go b/command/pr.go index 3f8e53481..70594b8d0 100644 --- a/command/pr.go +++ b/command/pr.go @@ -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) diff --git a/command/pr_checkout.go b/command/pr_checkout.go index 256a3dfe8..0ce94cc55 100644 --- a/command/pr_checkout.go +++ b/command/pr_checkout.go @@ -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 { | | }", 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")