Skip to content

Commit 137b15b

Browse files
committed
Update to remote commit if there is a build script merge conflict.
Do not stay on the local commit.
1 parent b00cfa9 commit 137b15b

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

internal/runners/pull/pull.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package pull
22

33
import (
44
"errors"
5-
"path/filepath"
65
"strings"
76
"time"
87

@@ -82,6 +81,14 @@ func (o *pullOutput) MarshalStructured(format output.Format) interface{} {
8281
return o
8382
}
8483

84+
type ErrBuildScriptMergeConflict struct {
85+
ProjectDir string
86+
}
87+
88+
func (e *ErrBuildScriptMergeConflict) Error() string {
89+
return "build script merge conflict"
90+
}
91+
8592
func (p *Pull) Run(params *PullParams) (rerr error) {
8693
defer rationalizeError(&rerr)
8794

@@ -160,6 +167,12 @@ func (p *Pull) Run(params *PullParams) (rerr error) {
160167
if p.cfg.GetBool(constants.OptinBuildscriptsConfig) {
161168
err := p.mergeBuildScript(*remoteCommit, *localCommit)
162169
if err != nil {
170+
if errs.Matches(err, &ErrBuildScriptMergeConflict{}) {
171+
err2 := localcommit.Set(p.project.Dir(), remoteCommit.String())
172+
if err2 != nil {
173+
err = errs.Pack(err, errs.Wrap(err2, "Could not set local commit to remote commit after build script merge conflict"))
174+
}
175+
}
163176
return errs.Wrap(err, "Could not merge local build script with remote changes")
164177
}
165178
}
@@ -260,10 +273,7 @@ func (p *Pull) mergeBuildScript(remoteCommit, localCommit strfmt.UUID) error {
260273
if err != nil {
261274
return locale.WrapError(err, "err_diff_build_script", "Unable to generate differences between local and remote build script")
262275
}
263-
return locale.NewInputError(
264-
"err_build_script_merge",
265-
"Unable to automatically merge build scripts. Please resolve conflicts manually in '{{.V0}}' and then run '[ACTIONABLE]state commit[/RESET]'",
266-
filepath.Join(p.project.Dir(), constants.BuildScriptFileName))
276+
return &ErrBuildScriptMergeConflict{p.project.Dir()}
267277
}
268278

269279
// For now, pick the later of the script AtTimes.

internal/runners/pull/rationalize.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ package pull
22

33
import (
44
"errors"
5+
"path/filepath"
56

7+
"github.com/ActiveState/cli/internal/constants"
68
"github.com/ActiveState/cli/internal/errs"
79
"github.com/ActiveState/cli/internal/locale"
810
"github.com/ActiveState/cli/pkg/platform/api/buildplanner/model"
@@ -14,6 +16,7 @@ func rationalizeError(err *error) {
1416
}
1517

1618
var mergeCommitErr *model.MergedCommitError
19+
var buildscriptMergeCommitErr *ErrBuildScriptMergeConflict
1720

1821
switch {
1922
case errors.As(*err, &mergeCommitErr):
@@ -44,5 +47,12 @@ func rationalizeError(err *error) {
4447
),
4548
)
4649
}
50+
51+
case errors.As(*err, &buildscriptMergeCommitErr):
52+
*err = errs.WrapUserFacing(*err,
53+
locale.Tl("err_build_script_merge",
54+
"Unable to automatically merge build scripts. Please resolve conflicts manually in '{{.V0}}' and then run '[ACTIONABLE]state commit[/RESET]'",
55+
filepath.Join(buildscriptMergeCommitErr.ProjectDir, constants.BuildScriptFileName)),
56+
errs.SetInput())
4757
}
4858
}

test/integration/pull_int_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,6 @@ func (suite *PullIntegrationTestSuite) TestMergeBuildScript() {
9494
cp.Expect("Package added", e2e.RuntimeSourcingTimeoutOpt)
9595
cp.ExpectExitCode(0)
9696

97-
commit, err := localcommit.Get(ts.Dirs.Work)
98-
suite.Require().NoError(err)
99-
10097
proj, err := project.FromPath(ts.Dirs.Work)
10198
suite.NoError(err, "Error loading project")
10299

@@ -117,12 +114,14 @@ func (suite *PullIntegrationTestSuite) TestMergeBuildScript() {
117114
suite.Assert().Contains(string(bytes), "=======", "No merge conflict markers are in build script")
118115
suite.Assert().Contains(string(bytes), ">>>>>>>", "No merge conflict markers are in build script")
119116

120-
// Verify the local commit was not updated to the merge commit.
121-
// Note: even though the buildscript merge failed, a merge commit was still created. After resolving
122-
// buildscript conflicts, `state commit` should always have something new to commit.
123-
commit2, err := localcommit.Get(ts.Dirs.Work)
117+
// Verify the local commit was updated to the remote commit, not the merge commit.
118+
// Note: even though the buildscript merge failed, a merge commit was still created (we just
119+
// ignore it). After resolving buildscript conflicts, `state commit` should always have something
120+
// new to commit.
121+
remoteHeadCommit := "d908a758-6a81-40d4-b0eb-87069cd7f07d"
122+
commit, err := localcommit.Get(ts.Dirs.Work)
124123
suite.Require().NoError(err)
125-
suite.Assert().Equal(commit.String(), commit2.String(), "localcommit should not have been updated to merged commit")
124+
suite.Assert().Equal(remoteHeadCommit, commit.String(), "localcommit should have been updated to remote commit")
126125
}
127126

128127
func (suite *PullIntegrationTestSuite) assertMergeStrategyNotification(ts *e2e.Session, strategy string) {

0 commit comments

Comments
 (0)