From b1c60863e9a7d3fff7e3c91e20d53104d34f7a50 Mon Sep 17 00:00:00 2001 From: mitchell Date: Thu, 7 Nov 2024 17:37:54 -0500 Subject: [PATCH] `state commit`, `state push`, and `state reset` should not fail if there is no work to be don --- internal/runners/commit/commit.go | 11 ++--------- internal/runners/push/push.go | 12 +++++++++--- internal/runners/push/rationalize.go | 15 --------------- internal/runners/reset/reset.go | 3 ++- test/integration/commit_int_test.go | 2 +- test/integration/push_int_test.go | 7 +------ test/integration/reset_int_test.go | 2 +- 7 files changed, 16 insertions(+), 36 deletions(-) diff --git a/internal/runners/commit/commit.go b/internal/runners/commit/commit.go index 4b7b208ccc..08a7f2f12b 100644 --- a/internal/runners/commit/commit.go +++ b/internal/runners/commit/commit.go @@ -35,8 +35,6 @@ func New(p primeable) *Commit { return &Commit{p} } -var ErrNoChanges = errors.New("buildscript has no changes") - func rationalizeError(err *error) { var buildPlannerErr *bpResp.BuildPlannerError @@ -44,12 +42,6 @@ func rationalizeError(err *error) { case err == nil: return - case errors.Is(*err, ErrNoChanges): - *err = errs.WrapUserFacing(*err, locale.Tl( - "commit_notice_no_change", - "Your buildscript contains no new changes. No commit necessary.", - ), errs.SetInput()) - case errors.Is(*err, buildscript_runbit.ErrBuildscriptNotExist): *err = errs.WrapUserFacing(*err, locale.T("err_buildscript_not_exist")) @@ -109,7 +101,8 @@ func (c *Commit) Run() (rerr error) { // Check if there is anything to commit if equals { - return ErrNoChanges + out.Notice(locale.Tl("commit_notice_no_change", "Your buildscript contains no new changes. No commit necessary.")) + return nil } pg := output.StartSpinner(out, locale.T("progress_commit"), constants.TerminalAnimationInterval) diff --git a/internal/runners/push/push.go b/internal/runners/push/push.go index df61f99e2f..ca1c774161 100644 --- a/internal/runners/push/push.go +++ b/internal/runners/push/push.go @@ -13,6 +13,7 @@ import ( "github.com/ActiveState/cli/internal/rtutils/ptr" "github.com/ActiveState/cli/internal/runbits/rationalize" "github.com/ActiveState/cli/pkg/localcommit" + bpResp "github.com/ActiveState/cli/pkg/platform/api/buildplanner/response" "github.com/ActiveState/cli/pkg/platform/api/buildplanner/types" "github.com/ActiveState/cli/pkg/platform/api/mono/mono_models" "github.com/ActiveState/cli/pkg/platform/authentication" @@ -65,8 +66,7 @@ const ( ) var ( - errNoChanges = errors.New("no changes") - errNoCommit = errors.New("no commit") + errNoCommit = errors.New("no commit") ) type errProjectNameInUse struct { @@ -234,7 +234,8 @@ func (r *Push) Run(params PushParams) (rerr error) { // Check if branch is already up to date if branch.CommitID != nil && branch.CommitID.String() == commitID.String() { - return errNoChanges + r.out.Notice(locale.T("push_no_changes")) + return nil } // Perform the (fast-forward) push. @@ -246,6 +247,11 @@ func (r *Push) Run(params PushParams) (rerr error) { Strategy: types.MergeCommitStrategyFastForward, }) if err != nil { + var mergeCommitErr *bpResp.MergedCommitError + if errors.As(err, &mergeCommitErr) && mergeCommitErr.Type == types.NoChangeSinceLastCommitErrorType { + r.out.Notice(locale.T("push_no_changes")) + return nil + } return errs.Wrap(err, "Could not push") } } diff --git a/internal/runners/push/rationalize.go b/internal/runners/push/rationalize.go index 90af8e6774..762ed5c55a 100644 --- a/internal/runners/push/rationalize.go +++ b/internal/runners/push/rationalize.go @@ -52,13 +52,6 @@ func rationalizeError(err *error) { errs.SetInput(), ) - // No changes made - case errors.Is(*err, errNoChanges): - *err = errs.WrapUserFacing(*err, - locale.T("push_no_changes"), - errs.SetInput(), - ) - // Project name is already in use case errors.As(*err, &projectNameInUseErr): *err = errs.WrapUserFacing(*err, @@ -86,14 +79,6 @@ func rationalizeError(err *error) { *err = errs.WrapUserFacing(*err, locale.T("err_push_target_invalid_history"), errs.SetInput()) - - // No changes made - case types.NoChangeSinceLastCommitErrorType: - *err = errs.WrapUserFacing(*err, - locale.T("push_no_changes"), - errs.SetInput(), - ) - } } } diff --git a/internal/runners/reset/reset.go b/internal/runners/reset/reset.go index c046635e63..45e042e725 100644 --- a/internal/runners/reset/reset.go +++ b/internal/runners/reset/reset.go @@ -86,7 +86,8 @@ func (r *Reset) Run(params *Params) error { return errs.Wrap(err, "Unable to get local commit") } if *latestCommit == localCommitID { - return locale.NewInputError("err_reset_latest", "You are already on the latest commit") + r.out.Notice(locale.Tl("err_reset_latest", "You are already on the latest commit")) + return nil } commitID = *latestCommit diff --git a/test/integration/commit_int_test.go b/test/integration/commit_int_test.go index 9dbe1c22b4..77e549d7ea 100644 --- a/test/integration/commit_int_test.go +++ b/test/integration/commit_int_test.go @@ -35,7 +35,7 @@ func (suite *CommitIntegrationTestSuite) TestCommitManualBuildScriptMod() { cp := ts.Spawn("commit") cp.Expect("no new changes") - cp.ExpectExitCode(1) + cp.ExpectExitCode(0) _, err = buildscript_runbit.ScriptFromProject(proj) suite.Require().NoError(err) // verify validity diff --git a/test/integration/push_int_test.go b/test/integration/push_int_test.go index a19dd5323b..6a6e03514f 100644 --- a/test/integration/push_int_test.go +++ b/test/integration/push_int_test.go @@ -259,12 +259,7 @@ func (suite *PushIntegrationTestSuite) TestPush_NoChanges() { ts.LoginAsPersistentUser() cp := ts.Spawn("push") cp.Expect("no local changes to push") - cp.ExpectExitCode(1) - ts.IgnoreLogErrors() - - if strings.Count(cp.Snapshot(), " x ") != 1 { - suite.Fail("Expected exactly ONE error message, got: ", cp.Snapshot()) - } + cp.ExpectExitCode(0) } func (suite *PushIntegrationTestSuite) TestPush_NameInUse() { diff --git a/test/integration/reset_int_test.go b/test/integration/reset_int_test.go index e7cc862ea9..9b3199ee60 100644 --- a/test/integration/reset_int_test.go +++ b/test/integration/reset_int_test.go @@ -51,7 +51,7 @@ func (suite *ResetIntegrationTestSuite) TestReset() { cp = ts.Spawn("reset") cp.Expect("You are already on the latest commit") - cp.ExpectNotExitCode(0) + cp.ExpectExitCode(0) cp = ts.Spawn("reset", "00000000-0000-0000-0000-000000000000") cp.Expect("The given commit ID does not exist")