Skip to content

Commit

Permalink
Merge pull request #2938 from ActiveState/mitchell/dx-1558
Browse files Browse the repository at this point in the history
Remove `state pull --set-project`.
  • Loading branch information
mitchell-as authored Dec 7, 2023
2 parents 197e9e9 + c7342f2 commit b51523c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 113 deletions.
9 changes: 1 addition & 8 deletions cmd/state/internal/cmdtree/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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: &params.SetProject,
},
},
[]*captain.Flag{},
[]*captain.Argument{},
func(cmd *captain.Command, args []string) error {
params.Force = globals.NonInteractive
Expand Down
54 changes: 7 additions & 47 deletions internal/runners/pull/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ type Pull struct {
}

type PullParams struct {
Force bool
SetProject string
Force bool
}

type primeable interface {
Expand Down Expand Up @@ -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")
}
Expand All @@ -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

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
58 changes: 0 additions & 58 deletions test/integration/pull_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b51523c

Please sign in to comment.