Skip to content

Commit

Permalink
Merge pull request #2672 from ActiveState/mitchell/dx-1967
Browse files Browse the repository at this point in the history
Added `state checkout --no-clone` option for not cloning a project's associated git repo.
  • Loading branch information
mitchell-as authored Aug 1, 2023
2 parents a0205a9 + 0e326d1 commit 3970281
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
5 changes: 5 additions & 0 deletions cmd/state/internal/cmdtree/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: &params.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: &params.NoClone,
},
},
[]*captain.Argument{
{
Expand Down
2 changes: 1 addition & 1 deletion internal/runners/activate/activate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
Expand Down
3 changes: 2 additions & 1 deletion internal/runners/checkout/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type Params struct {
PreferredPath string
Branch string
RuntimePath string
NoClone bool
}

type primeable interface {
Expand Down Expand Up @@ -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())
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmdlets/checkout/checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 3970281

Please sign in to comment.