Skip to content

Commit 71ce6c7

Browse files
committed
state commit should error if there is nothing new to commit.
1 parent e554f37 commit 71ce6c7

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

internal/runners/commit/commit.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ func New(p primeable) *Commit {
3535
return &Commit{p}
3636
}
3737

38+
var errNoNewChanges = errs.New("no new changes")
39+
3840
func rationalizeError(err *error) {
3941
var buildPlannerErr *bpResp.BuildPlannerError
4042

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

62+
case errors.Is(*err, errNoNewChanges):
63+
*err = errs.WrapUserFacing(*err, locale.Tl("commit_notice_no_change", "Your buildscript contains no new changes. No commit necessary."), errs.SetInput())
64+
6065
}
6166
}
6267

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

102107
// Check if there is anything to commit
103108
if equals {
104-
out.Notice(locale.Tl("commit_notice_no_change", "Your buildscript contains no new changes. No commit necessary."))
105-
return nil
109+
return errNoNewChanges
106110
}
107111

108112
pg := output.StartSpinner(out, locale.T("progress_commit"), constants.TerminalAnimationInterval)

test/integration/buildscript_int_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ Project: %s
7575
Time: "2024-10-30T21:31:33.000Z"
7676
%s
7777
wheel = make_wheel(
78-
at_time = at_time,
78+
at_time = TIME,
7979
src = tag(
8080
plan = ingredient(
8181
build_deps = [
@@ -111,7 +111,7 @@ main = wheel
111111
// already exists with the given hash.
112112
cp = ts.Spawn("commit")
113113
cp.Expect("no new changes")
114-
cp.ExpectExit()
114+
cp.ExpectNotExitCode(0)
115115

116116
// Commit should've given us the hash
117117
suite.Contains(string(fileutils.ReadFileUnsafe(filepath.Join(ts.Dirs.Work, constants.BuildScriptFileName))), "hash_readonly")

test/integration/commit_int_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (suite *CommitIntegrationTestSuite) TestCommitManualBuildScriptMod() {
3535

3636
cp := ts.Spawn("commit")
3737
cp.Expect("no new changes")
38-
cp.ExpectExitCode(0)
38+
cp.ExpectNotExitCode(0)
3939

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

0 commit comments

Comments
 (0)