Skip to content

Commit

Permalink
state commit should error if there is nothing new to commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchell-as committed Dec 4, 2024
1 parent e554f37 commit 71ce6c7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
8 changes: 6 additions & 2 deletions internal/runners/commit/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ func New(p primeable) *Commit {
return &Commit{p}
}

var errNoNewChanges = errs.New("no new changes")

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

Expand All @@ -57,6 +59,9 @@ func rationalizeError(err *error) {
case errors.As(*err, &invalidDepValueType{}):
*err = errs.WrapUserFacing(*err, locale.T("err_commit_invalid_dep_value_type"), errs.SetInput())

case errors.Is(*err, errNoNewChanges):
*err = errs.WrapUserFacing(*err, locale.Tl("commit_notice_no_change", "Your buildscript contains no new changes. No commit necessary."), errs.SetInput())

}
}

Expand Down Expand Up @@ -101,8 +106,7 @@ func (c *Commit) Run() (rerr error) {

// Check if there is anything to commit
if equals {
out.Notice(locale.Tl("commit_notice_no_change", "Your buildscript contains no new changes. No commit necessary."))
return nil
return errNoNewChanges
}

pg := output.StartSpinner(out, locale.T("progress_commit"), constants.TerminalAnimationInterval)
Expand Down
4 changes: 2 additions & 2 deletions test/integration/buildscript_int_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ Project: %s
Time: "2024-10-30T21:31:33.000Z"
%s
wheel = make_wheel(
at_time = at_time,
at_time = TIME,
src = tag(
plan = ingredient(
build_deps = [
Expand Down Expand Up @@ -111,7 +111,7 @@ main = wheel
// already exists with the given hash.
cp = ts.Spawn("commit")
cp.Expect("no new changes")
cp.ExpectExit()
cp.ExpectNotExitCode(0)

// Commit should've given us the hash
suite.Contains(string(fileutils.ReadFileUnsafe(filepath.Join(ts.Dirs.Work, constants.BuildScriptFileName))), "hash_readonly")
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(0)
cp.ExpectNotExitCode(0)

_, err = buildscript_runbit.ScriptFromProject(proj)
suite.Require().NoError(err) // verify validity
Expand Down

0 comments on commit 71ce6c7

Please sign in to comment.