Skip to content

Commit

Permalink
state commit, state push, and state reset should not fail if th…
Browse files Browse the repository at this point in the history
…ere is no work to be don
  • Loading branch information
mitchell-as committed Nov 7, 2024
1 parent 747e0c9 commit b1c6086
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 36 deletions.
11 changes: 2 additions & 9 deletions internal/runners/commit/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,13 @@ func New(p primeable) *Commit {
return &Commit{p}
}

var ErrNoChanges = errors.New("buildscript has no changes")

func rationalizeError(err *error) {
var buildPlannerErr *bpResp.BuildPlannerError

switch {
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"))

Expand Down Expand Up @@ -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)
Expand Down
12 changes: 9 additions & 3 deletions internal/runners/push/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -65,8 +66,7 @@ const (
)

var (
errNoChanges = errors.New("no changes")
errNoCommit = errors.New("no commit")
errNoCommit = errors.New("no commit")
)

type errProjectNameInUse struct {
Expand Down Expand Up @@ -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.
Expand All @@ -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")
}
}
Expand Down
15 changes: 0 additions & 15 deletions internal/runners/push/rationalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
)

}
}
}
3 changes: 2 additions & 1 deletion internal/runners/reset/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion test/integration/commit_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 1 addition & 6 deletions test/integration/push_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/reset_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit b1c6086

Please sign in to comment.