From c7342f2caf22b540b1097d4c11c96dfae346a69a Mon Sep 17 00:00:00 2001 From: mitchell Date: Thu, 7 Dec 2023 17:49:30 -0500 Subject: [PATCH] Remove `state pull --set-project`. Headless commits are no longer a thing. --- cmd/state/internal/cmdtree/pull.go | 9 +---- internal/runners/pull/pull.go | 54 ++++------------------------ test/integration/pull_int_test.go | 58 ------------------------------ 3 files changed, 8 insertions(+), 113 deletions(-) diff --git a/cmd/state/internal/cmdtree/pull.go b/cmd/state/internal/cmdtree/pull.go index d673c00a2a..0ca845556f 100644 --- a/cmd/state/internal/cmdtree/pull.go +++ b/cmd/state/internal/cmdtree/pull.go @@ -17,14 +17,7 @@ func newPullCommand(prime *primer.Values, globals *globalOptions) *captain.Comma locale.Tl("pull_title", "Pulling Remote Project"), locale.Tl("pull_description", "Pull in the latest version of your project from the ActiveState Platform"), prime, - []*captain.Flag{ - { - Name: "set-project", - Shorthand: "", - Description: locale.Tl("flag_state_pull_set_project_description", "Pull from the specified project instead of the checked out one. That project and the current one must share a common commit in their histories"), - Value: ¶ms.SetProject, - }, - }, + []*captain.Flag{}, []*captain.Argument{}, func(cmd *captain.Command, args []string) error { params.Force = globals.NonInteractive diff --git a/internal/runners/pull/pull.go b/internal/runners/pull/pull.go index 421f4d9046..7fe032b8c5 100644 --- a/internal/runners/pull/pull.go +++ b/internal/runners/pull/pull.go @@ -39,8 +39,7 @@ type Pull struct { } type PullParams struct { - Force bool - SetProject string + Force bool } type primeable interface { @@ -95,7 +94,7 @@ func (p *Pull) Run(params *PullParams) (rerr error) { } // Determine the project to pull from - remoteProject, err := resolveRemoteProject(p.project, params.SetProject) + remoteProject, err := resolveRemoteProject(p.project) if err != nil { return errs.Wrap(err, "Unable to determine target project") } @@ -109,21 +108,6 @@ func (p *Pull) Run(params *PullParams) (rerr error) { localCommit = &localCommitID } - if params.SetProject != "" { - defaultChoice := params.Force - confirmed, err := p.prompt.Confirm( - locale.T("confirm"), - locale.Tl("confirm_unrelated_pull_set_project", - "If you switch to {{.V0}}, you may lose changes to your project. Are you sure you want to do this?", remoteProject.String()), - &defaultChoice) - if err != nil { - return locale.WrapError(err, "err_pull_confirm", "Failed to get user confirmation to update project") - } - if !confirmed { - return locale.NewInputError("err_pull_aborted", "Pull aborted by user") - } - } - remoteCommit := remoteProject.CommitID resultingCommit := remoteCommit // resultingCommit is the commit we want to update the local project file with @@ -156,13 +140,6 @@ func (p *Pull) Run(params *PullParams) (rerr error) { } } - if params.SetProject != "" { - err = p.project.Source().SetNamespace(remoteProject.Owner, remoteProject.Project) - if err != nil { - return locale.WrapError(err, "err_pull_update_namespace", "Cannot update the namespace in your project file.") - } - } - commitID, err := commitmediator.Get(p.project) if err != nil { return errs.Wrap(err, "Unable to get local commit") @@ -266,29 +243,12 @@ func (p *Pull) mergeBuildScript(strategies *mono_models.MergeStrategies, remoteC return buildscript.Update(p.project, mergedExpr, p.auth) } -func resolveRemoteProject(prj *project.Project, overwrite string) (*project.Namespaced, error) { +func resolveRemoteProject(prj *project.Project) (*project.Namespaced, error) { ns := prj.Namespace() - if overwrite != "" { - var err error - ns, err = project.ParseNamespace(overwrite) - if err != nil { - return nil, locale.WrapInputError(err, "pull_set_project_parse_err", "Failed to parse namespace {{.V0}}", overwrite) - } - } - - // Retrieve commit ID to set the project to (if unset) - if overwrite != "" { - branch, err := model.DefaultBranchForProjectName(ns.Owner, ns.Project) - if err != nil { - return nil, locale.WrapError(err, "err_pull_commit", "Could not retrieve the latest commit for your project.") - } - ns.CommitID = branch.CommitID - } else { - var err error - ns.CommitID, err = model.BranchCommitID(ns.Owner, ns.Project, prj.BranchName()) - if err != nil { - return nil, locale.WrapError(err, "err_pull_commit_branch", "Could not retrieve the latest commit for your project and branch.") - } + var err error + ns.CommitID, err = model.BranchCommitID(ns.Owner, ns.Project, prj.BranchName()) + if err != nil { + return nil, locale.WrapError(err, "err_pull_commit_branch", "Could not retrieve the latest commit for your project and branch.") } return ns, nil diff --git a/test/integration/pull_int_test.go b/test/integration/pull_int_test.go index 004df9fb1a..05947aca57 100644 --- a/test/integration/pull_int_test.go +++ b/test/integration/pull_int_test.go @@ -43,45 +43,6 @@ func (suite *PullIntegrationTestSuite) TestPull() { cp.ExpectExitCode(0) } -func (suite *PullIntegrationTestSuite) TestPullSetProject() { - suite.OnlyRunForTags(tagsuite.Pull) - ts := e2e.New(suite.T(), false) - defer ts.Close() - - ts.PrepareProject("ActiveState-CLI/small-python", "9733d11a-dfb3-41de-a37a-843b7c421db4") - - // update to related project - cp := ts.Spawn("pull", "--set-project", "ActiveState-CLI/small-python-fork") - cp.Expect("Are you sure you want to do this? (y/N)") - cp.SendLine("n") - cp.Expect("Pull aborted by user") - cp.ExpectNotExitCode(0) - ts.IgnoreLogErrors() - - cp = ts.Spawn("pull", "--non-interactive", "--set-project", "ActiveState-CLI/small-python-fork") - cp.Expect("activestate.yaml has been updated") - cp.ExpectExitCode(0) -} - -func (suite *PullIntegrationTestSuite) TestPullSetProjectUnrelated() { - suite.OnlyRunForTags(tagsuite.Pull) - ts := e2e.New(suite.T(), false) - defer ts.Close() - - ts.PrepareProject("ActiveState-CLI/small-python", "9733d11a-dfb3-41de-a37a-843b7c421db4") - - cp := ts.Spawn("pull", "--set-project", "ActiveState-CLI/Python3") - cp.Expect("Are you sure you want to do this? (y/N)") - cp.SendLine("n") - cp.Expect("Pull aborted by user") - cp.ExpectNotExitCode(0) - ts.IgnoreLogErrors() - - cp = ts.Spawn("pull", "--non-interactive", "--set-project", "ActiveState-CLI/Python3") - cp.Expect("no common base") - cp.ExpectExitCode(1) -} - func (suite *PullIntegrationTestSuite) TestPull_Merge() { suite.OnlyRunForTags(tagsuite.Pull) projectLine := "project: https://platform.activestate.com/ActiveState-CLI/cli" @@ -124,25 +85,6 @@ func (suite *PullIntegrationTestSuite) TestPull_Merge() { cp.ExpectExitCode(0) } -func (suite *PullIntegrationTestSuite) TestPull_RestoreNamespace() { - suite.OnlyRunForTags(tagsuite.Pull) - ts := e2e.New(suite.T(), false) - defer ts.Close() - - ts.PrepareProject("ActiveState-CLI/small-python", "9733d11a-dfb3-41de-a37a-843b7c421db4") - - // Attempt to update to unrelated project. - cp := ts.Spawn("pull", "--non-interactive", "--set-project", "ActiveState-CLI/Python3") - cp.Expect("no common base") - cp.ExpectNotExitCode(0) - ts.IgnoreLogErrors() - - // Verify namespace is unchanged. - cp = ts.Spawn("show") - cp.Expect("ActiveState-CLI/small-python") - cp.ExpectExitCode(0) -} - func (suite *PullIntegrationTestSuite) TestMergeBuildScript() { suite.OnlyRunForTags(tagsuite.Pull) suite.T().Skip("Temporarily disable buildscripts until DX-2307") // remove in DX-2307