From 0e326d12c7bc13c9053e93492be8e1715b81bbe2 Mon Sep 17 00:00:00 2001 From: mitchell Date: Mon, 31 Jul 2023 11:58:21 -0400 Subject: [PATCH] Added `state checkout --no-clone` option for not cloning a project's associated git repo. --- cmd/state/internal/cmdtree/checkout.go | 5 +++++ internal/runners/activate/activate.go | 2 +- internal/runners/checkout/checkout.go | 3 ++- pkg/cmdlets/checkout/checkout.go | 4 ++-- 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/cmd/state/internal/cmdtree/checkout.go b/cmd/state/internal/cmdtree/checkout.go index e70befdaf3..f8f03613a5 100644 --- a/cmd/state/internal/cmdtree/checkout.go +++ b/cmd/state/internal/cmdtree/checkout.go @@ -29,6 +29,11 @@ func newCheckoutCommand(prime *primer.Values) *captain.Command { Description: locale.Tl("flag_state_checkout_runtime-path_description", "Path to store the runtime files"), Value: ¶ms.RuntimePath, }, + { + Name: "no-clone", + Description: locale.Tl("flag_state_checkout_no_clone_description", "Do not clone the github repository associated with this project (if any)"), + Value: ¶ms.NoClone, + }, }, []*captain.Argument{ { diff --git a/internal/runners/activate/activate.go b/internal/runners/activate/activate.go index 2145d42c28..14fd6ba218 100644 --- a/internal/runners/activate/activate.go +++ b/internal/runners/activate/activate.go @@ -94,7 +94,7 @@ func (r *Activate) Run(params *ActivateParams) error { } // Perform fresh checkout - pathToUse, err := r.activateCheckout.Run(params.Namespace, params.Branch, "", params.PreferredPath) + pathToUse, err := r.activateCheckout.Run(params.Namespace, params.Branch, "", params.PreferredPath, false) if err != nil { return locale.WrapError(err, "err_activate_pathtouse", "Could not figure out what path to use.") } diff --git a/internal/runners/checkout/checkout.go b/internal/runners/checkout/checkout.go index 3aa8c6f1a1..678fb6663f 100644 --- a/internal/runners/checkout/checkout.go +++ b/internal/runners/checkout/checkout.go @@ -25,6 +25,7 @@ type Params struct { PreferredPath string Branch string RuntimePath string + NoClone bool } type primeable interface { @@ -66,7 +67,7 @@ func (u *Checkout) Run(params *Params) error { logging.Debug("Checking out %s to %s", params.Namespace.String(), params.PreferredPath) var err error - projectDir, err := u.checkout.Run(params.Namespace, params.Branch, params.RuntimePath, params.PreferredPath) + projectDir, err := u.checkout.Run(params.Namespace, params.Branch, params.RuntimePath, params.PreferredPath, params.NoClone) if err != nil { return locale.WrapError(err, "err_checkout_project", "", params.Namespace.String()) } diff --git a/pkg/cmdlets/checkout/checkout.go b/pkg/cmdlets/checkout/checkout.go index 0bb472fc88..2ee2f493db 100644 --- a/pkg/cmdlets/checkout/checkout.go +++ b/pkg/cmdlets/checkout/checkout.go @@ -44,7 +44,7 @@ func New(repo git.Repository, prime primeable) *Checkout { return &Checkout{repo, prime.Output(), prime.Config(), prime.Analytics(), "", prime.Auth()} } -func (r *Checkout) Run(ns *project.Namespaced, branchName, cachePath, targetPath string) (string, error) { +func (r *Checkout) Run(ns *project.Namespaced, branchName, cachePath, targetPath string, noClone bool) (string, error) { path, err := r.pathToUse(ns, targetPath) if err != nil { return "", errs.Wrap(err, "Could not get path to use") @@ -84,7 +84,7 @@ func (r *Checkout) Run(ns *project.Namespaced, branchName, cachePath, targetPath } // Clone the related repo, if it is defined - if pj.RepoURL != nil && *pj.RepoURL != "" { + if !noClone && pj.RepoURL != nil && *pj.RepoURL != "" { err := r.repo.CloneProject(ns.Owner, ns.Project, path, r.Outputer, r.analytics) if err != nil { return "", locale.WrapError(err, "err_clone_project", "Could not clone associated git repository")