From 4aeec493d7accbdb82779841949ce26e79b4e610 Mon Sep 17 00:00:00 2001 From: mitchell Date: Mon, 27 Nov 2023 12:48:06 -0500 Subject: [PATCH 1/2] Re-enable localcommits and buildscripts. --- cmd/state/internal/cmdtree/cmdtree.go | 2 +- internal/constraints/constraints.go | 1 - internal/runbits/checkout/checkout.go | 47 +++++++++---------- .../runbits/commitmediator/commitmediator.go | 34 +++++++------- internal/runbits/refresh.go | 10 ++-- internal/runbits/requirements/requirements.go | 19 ++++---- internal/runners/initialize/init.go | 25 +++++----- internal/runners/pull/pull.go | 24 ++++++---- internal/testhelpers/e2e/session.go | 7 +-- pkg/platform/runtime/runtime.go | 2 - pkg/platform/runtime/setup/setup.go | 8 ++-- pkg/project/project.go | 6 --- pkg/project/project_test.go | 1 - pkg/project/testdata/activestate.yaml | 2 +- pkg/projectfile/projectfield.go | 5 -- pkg/projectfile/projectfile.go | 45 ++++-------------- test/integration/checkout_int_test.go | 20 ++++---- test/integration/commit_int_test.go | 1 - test/integration/install_int_test.go | 10 ++-- .../integration/project_migration_int_test.go | 1 - test/integration/pull_int_test.go | 18 ++----- test/integration/push_int_test.go | 9 +--- 22 files changed, 118 insertions(+), 179 deletions(-) diff --git a/cmd/state/internal/cmdtree/cmdtree.go b/cmd/state/internal/cmdtree/cmdtree.go index f4f9167db9..0a4d2ab35a 100644 --- a/cmd/state/internal/cmdtree/cmdtree.go +++ b/cmd/state/internal/cmdtree/cmdtree.go @@ -205,7 +205,7 @@ func New(prime *primer.Values, args ...string) *CmdTree { refreshCmd, newSwitchCommand(prime), newTestCommand(prime), - //newCommitCommand(prime), // re-enable in DX-2307 + newCommitCommand(prime), ) return &CmdTree{ diff --git a/internal/constraints/constraints.go b/internal/constraints/constraints.go index 6eb19cf192..76b099557f 100644 --- a/internal/constraints/constraints.go +++ b/internal/constraints/constraints.go @@ -82,7 +82,6 @@ type projectable interface { Dir() string URL() string LegacyCommitID() string // for commitmediator.Get - LegacySetCommit(string) error // for commitmediator.Set; remove in DX-2307 } func NewPrimeConditional(auth *authentication.Auth, pj projectable, subshellName string) *Conditional { diff --git a/internal/runbits/checkout/checkout.go b/internal/runbits/checkout/checkout.go index 5692e31ef3..95c3110796 100644 --- a/internal/runbits/checkout/checkout.go +++ b/internal/runbits/checkout/checkout.go @@ -13,8 +13,10 @@ import ( "github.com/ActiveState/cli/internal/errs" "github.com/ActiveState/cli/internal/fileutils" "github.com/ActiveState/cli/internal/language" + "github.com/ActiveState/cli/internal/multilog" "github.com/ActiveState/cli/internal/output" "github.com/ActiveState/cli/internal/runbits/git" + "github.com/ActiveState/cli/pkg/localcommit" "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" "github.com/ActiveState/cli/pkg/project" @@ -57,11 +59,10 @@ func (r *Checkout) Run(ns *project.Namespaced, branchName, cachePath, targetPath return "", errs.Wrap(err, "Could not get absolute path") } - // Re-enable in DX-2307. - //emptyDir, err := fileutils.IsEmptyDir(path) - //if err != nil { - // multilog.Error("Unable to check if directory is empty: %v", err) - //} + emptyDir, err := fileutils.IsEmptyDir(path) + if err != nil { + multilog.Error("Unable to check if directory is empty: %v", err) + } // If project does not exist at path then we must checkout // the project and create the project file @@ -126,31 +127,29 @@ func (r *Checkout) Run(ns *project.Namespaced, branchName, cachePath, targetPath configFile := filepath.Join(path, constants.ConfigFileName) if !fileutils.FileExists(configFile) { _, err = projectfile.Create(&projectfile.CreateParams{ - Owner: owner, - Project: pj.Name, // match case on the Platform - BranchName: branchName, - Directory: path, - Language: language.String(), - Cache: cachePath, - LegacyCommitID: commitID.String(), // remove in DX-2307 + Owner: owner, + Project: pj.Name, // match case on the Platform + BranchName: branchName, + Directory: path, + Language: language.String(), + Cache: cachePath, }) if err != nil { return "", errs.Wrap(err, "Could not create projectfile") } } - // Re-enable in DX-2307. - //err = localcommit.Set(path, commitID.String()) - //if err != nil { - // return "", errs.Wrap(err, "Could not create local commit file") - //} - //if emptyDir || fileutils.DirExists(filepath.Join(path, ".git")) { - // err = localcommit.AddToGitIgnore(path) - // if err != nil { - // r.Outputer.Notice(locale.Tr("notice_commit_id_gitignore", constants.ProjectConfigDirName, constants.CommitIdFileName)) - // multilog.Error("Unable to add local commit file to .gitignore: %v", err) - // } - //} + err = localcommit.Set(path, commitID.String()) + if err != nil { + return "", errs.Wrap(err, "Could not create local commit file") + } + if emptyDir || fileutils.DirExists(filepath.Join(path, ".git")) { + err = localcommit.AddToGitIgnore(path) + if err != nil { + r.Outputer.Notice(locale.Tr("notice_commit_id_gitignore", constants.ProjectConfigDirName, constants.CommitIdFileName)) + multilog.Error("Unable to add local commit file to .gitignore: %v", err) + } + } return path, nil } diff --git a/internal/runbits/commitmediator/commitmediator.go b/internal/runbits/commitmediator/commitmediator.go index 37e5df525c..d4d8bd73da 100644 --- a/internal/runbits/commitmediator/commitmediator.go +++ b/internal/runbits/commitmediator/commitmediator.go @@ -2,6 +2,10 @@ package commitmediator import ( "github.com/go-openapi/strfmt" + + "github.com/ActiveState/cli/internal/errs" + "github.com/ActiveState/cli/internal/runbits/legacy/projectmigration" + "github.com/ActiveState/cli/pkg/localcommit" ) type projecter interface { @@ -9,30 +13,26 @@ type projecter interface { URL() string Path() string LegacyCommitID() string - LegacySetCommit(string) error // remove this in DX-2307 } // Get returns the given project's commit ID in either the new format (commit file), or the old // format (activestate.yaml). // If you require the commit file, use localcommit.Get(). func Get(proj projecter) (strfmt.UUID, error) { - // Re-enable the contents of this function in DX-2307 - //if commitID, err := localcommit.Get(proj.Dir()); err == nil { - // return commitID, nil - //} else if localcommit.IsFileDoesNotExistError(err) { - //if migrated, err := projectmigration.PromptAndMigrate(proj); err == nil && migrated { - // return localcommit.Get(proj.Dir()) - //} else if err != nil { - // return "", errs.Wrap(err, "Could not prompt and/or migrate project") - //} - return strfmt.UUID(proj.LegacyCommitID()), nil - //} else { - // return "", errs.Wrap(err, "Could not get local commit") - //} + if commitID, err := localcommit.Get(proj.Dir()); err == nil { + return commitID, nil + } else if localcommit.IsFileDoesNotExistError(err) { + if migrated, err := projectmigration.PromptAndMigrate(proj); err == nil && migrated { + return localcommit.Get(proj.Dir()) + } else if err != nil { + return "", errs.Wrap(err, "Could not prompt and/or migrate project") + } + return strfmt.UUID(proj.LegacyCommitID()), nil + } else { + return "", errs.Wrap(err, "Could not get local commit") + } } func Set(proj projecter, commitID string) error { - // Replace all calls to this function with localcommit.Set() in DX-2307. - // Also, consider changing localcommit.Set() to accept a projecter interface with Dir(). - return proj.LegacySetCommit(commitID) + return localcommit.Set(proj.Dir(), commitID) } diff --git a/internal/runbits/refresh.go b/internal/runbits/refresh.go index 0dd7d9341c..b7d569b4a4 100644 --- a/internal/runbits/refresh.go +++ b/internal/runbits/refresh.go @@ -5,6 +5,7 @@ import ( "github.com/ActiveState/cli/internal/locale" "github.com/ActiveState/cli/internal/output" "github.com/ActiveState/cli/internal/rtutils" + "github.com/ActiveState/cli/internal/runbits/buildscript" "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" "github.com/ActiveState/cli/pkg/platform/runtime" @@ -24,11 +25,10 @@ func RefreshRuntime( trigger target.Trigger, svcm *model.SvcModel, ) (rerr error) { - // Re-enable in DX-2307. - //_, err := buildscript.Sync(proj, &commitID, out, auth) - //if err != nil { - // return locale.WrapError(err, "err_update_build_script") - //} + _, err := buildscript.Sync(proj, &commitID, out, auth) + if err != nil { + return locale.WrapError(err, "err_update_build_script") + } target := target.NewProjectTarget(proj, nil, trigger) isCached := true rt, err := runtime.New(target, an, svcm, auth) diff --git a/internal/runbits/requirements/requirements.go b/internal/runbits/requirements/requirements.go index 4eff7aee3e..4cd26f6df3 100644 --- a/internal/runbits/requirements/requirements.go +++ b/internal/runbits/requirements/requirements.go @@ -25,6 +25,7 @@ import ( medmodel "github.com/ActiveState/cli/pkg/platform/api/mediator/model" "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" + "github.com/ActiveState/cli/pkg/platform/runtime/buildscript" "github.com/ActiveState/cli/pkg/platform/runtime/target" "github.com/ActiveState/cli/pkg/project" "github.com/thoas/go-funk" @@ -271,22 +272,20 @@ func (r *RequirementOperation) ExecuteRequirementOperation(requirementName, requ return errs.Wrap(err, "Unsupported namespace type: %s", ns.Type().String()) } - // Re-enable in DX-2307. - //expr, err := bp.GetBuildExpression(r.Project.Owner(), r.Project.Name(), commitID.String()) - //if err != nil { - // return errs.Wrap(err, "Could not get remote build expr") - //} + expr, err := bp.GetBuildExpression(r.Project.Owner(), r.Project.Name(), commitID.String()) + if err != nil { + return errs.Wrap(err, "Could not get remote build expr") + } if err := commitmediator.Set(r.Project, commitID.String()); err != nil { return locale.WrapError(err, "err_package_update_commit_id") } // Note: a commit ID file needs to exist at this point. - // Re-enable in DX-2307. - //err = buildscript.Update(r.Project, expr, r.Auth) - //if err != nil { - // return locale.WrapError(err, "err_update_build_script") - //} + err = buildscript.Update(r.Project, expr, r.Auth) + if err != nil { + return locale.WrapError(err, "err_update_build_script") + } // refresh or install runtime err = runbits.RefreshRuntime(r.Auth, r.Output, r.Analytics, r.Project, commitID, true, trigger, r.SvcModel) diff --git a/internal/runners/initialize/init.go b/internal/runners/initialize/init.go index 9703958965..37f075938c 100644 --- a/internal/runners/initialize/init.go +++ b/internal/runners/initialize/init.go @@ -20,6 +20,7 @@ import ( "github.com/ActiveState/cli/internal/primer" "github.com/ActiveState/cli/internal/runbits" "github.com/ActiveState/cli/internal/runbits/commitmediator" + "github.com/ActiveState/cli/pkg/localcommit" "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" "github.com/ActiveState/cli/pkg/platform/runtime/setup" @@ -156,11 +157,10 @@ func (r *Initialize) Run(params *RunParams) (rerr error) { } } - // Re-enable in DX-2307. - //emptyDir, err := fileutils.IsEmptyDir(path) - //if err != nil { - // multilog.Error("Unable to check if directory is empty: %v", err) - //} + emptyDir, err := fileutils.IsEmptyDir(path) + if err != nil { + multilog.Error("Unable to check if directory is empty: %v", err) + } // Match the case of the organization. // Otherwise the incorrect case will be written to the project file. @@ -250,14 +250,13 @@ func (r *Initialize) Run(params *RunParams) (rerr error) { if err := commitmediator.Set(proj, commitID.String()); err != nil { return errs.Wrap(err, "Unable to create local commit file") } - // Re-enable in DX-2307. - //if emptyDir || fileutils.DirExists(filepath.Join(path, ".git")) { - // err := localcommit.AddToGitIgnore(path) - // if err != nil { - // r.out.Notice(locale.Tr("notice_commit_id_gitignore", constants.ProjectConfigDirName, constants.CommitIdFileName)) - // multilog.Error("Unable to add local commit file to .gitignore: %v", err) - // } - //} + if emptyDir || fileutils.DirExists(filepath.Join(path, ".git")) { + err := localcommit.AddToGitIgnore(path) + if err != nil { + r.out.Notice(locale.Tr("notice_commit_id_gitignore", constants.ProjectConfigDirName, constants.CommitIdFileName)) + multilog.Error("Unable to add local commit file to .gitignore: %v", err) + } + } err = runbits.RefreshRuntime(r.auth, r.out, r.analytics, proj, commitID, true, target.TriggerInit, r.svcModel) if err != nil { diff --git a/internal/runners/pull/pull.go b/internal/runners/pull/pull.go index bbed2c59b2..2f7ddada89 100644 --- a/internal/runners/pull/pull.go +++ b/internal/runners/pull/pull.go @@ -1,6 +1,7 @@ package pull import ( + "errors" "path/filepath" "strings" @@ -18,7 +19,6 @@ import ( "github.com/ActiveState/cli/internal/runbits/commit" "github.com/ActiveState/cli/internal/runbits/commitmediator" bpModel "github.com/ActiveState/cli/pkg/platform/api/buildplanner/model" - "github.com/ActiveState/cli/pkg/platform/api/mono/mono_models" "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" "github.com/ActiveState/cli/pkg/platform/runtime/buildexpression/merge" @@ -194,11 +194,10 @@ func (p *Pull) Run(params *PullParams) (rerr error) { } func (p *Pull) performMerge(remoteCommit, localCommit strfmt.UUID, namespace *project.Namespaced, branchName string) (strfmt.UUID, error) { - // Re-enable in DX-2307. - //err := p.mergeBuildScript(strategies, remoteCommit) - //if err != nil { - // return "", errs.Wrap(err, "Could not merge local build script with remote changes") - //} + err := p.mergeBuildScript(remoteCommit, localCommit) + if err != nil { + return "", errs.Wrap(err, "Could not merge local build script with remote changes") + } p.out.Notice(output.Title(locale.Tl("pull_diverged", "Merging history"))) p.out.Notice(locale.Tr( @@ -232,9 +231,8 @@ func (p *Pull) performMerge(remoteCommit, localCommit strfmt.UUID, namespace *pr return resultCommit, nil } -// mergeBuildScript merges the local build script with the remote buildexpression (not script) for a -// given UUID, performing the given merge strategy (e.g. from model.MergeCommit). -func (p *Pull) mergeBuildScript(strategies *mono_models.MergeStrategies, remoteCommit strfmt.UUID) error { +// mergeBuildScript merges the local build script with the remote buildexpression (not script). +func (p *Pull) mergeBuildScript(remoteCommit, localCommit strfmt.UUID) error { // Get the build script to merge. script, err := buildscript.NewScriptFromProject(p.project, p.auth) if err != nil { @@ -249,6 +247,14 @@ func (p *Pull) mergeBuildScript(strategies *mono_models.MergeStrategies, remoteC return errs.Wrap(err, "Unable to get buildexpression for remote commit") } + // Compute the merge strategy. + strategies, err := model.MergeCommit(remoteCommit, localCommit) + if err != nil { + if !errors.Is(err, model.ErrMergeCommitInHistory) { + return locale.WrapError(err, "err_mergecommit", "Could not detect if merge is necessary.") + } + } + // Attempt the merge. mergedExpr, err := merge.Merge(exprA, exprB, strategies) if err != nil { diff --git a/internal/testhelpers/e2e/session.go b/internal/testhelpers/e2e/session.go index d80effa8eb..6858bc6631 100644 --- a/internal/testhelpers/e2e/session.go +++ b/internal/testhelpers/e2e/session.go @@ -43,7 +43,6 @@ import ( "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" "github.com/ActiveState/cli/pkg/project" - "github.com/ActiveState/cli/pkg/projectfile" // remove in DX-2307 ) // Session represents an end-to-end testing session during which several console process can be spawned and tested @@ -382,11 +381,7 @@ func (s *Session) PrepareActiveStateYAML(contents string) { } func (s *Session) PrepareCommitIdFile(commitID string) { - // Replace the contents of this function with the line below in DX-2307. - //require.NoError(s.t, fileutils.WriteFile(filepath.Join(s.Dirs.Work, constants.ProjectConfigDirName, constants.CommitIdFileName), []byte(commitID))) - pjfile, err := projectfile.Parse(filepath.Join(s.Dirs.Work, constants.ConfigFileName)) - require.NoError(s.t, err) - require.NoError(s.t, pjfile.LegacySetCommit(commitID)) + require.NoError(s.t, fileutils.WriteFile(filepath.Join(s.Dirs.Work, constants.ProjectConfigDirName, constants.CommitIdFileName), []byte(commitID))) } // PrepareProject creates a very simple activestate.yaml file for the given org/project and, if a diff --git a/pkg/platform/runtime/runtime.go b/pkg/platform/runtime/runtime.go index e3441f5b72..806ea0e22e 100644 --- a/pkg/platform/runtime/runtime.go +++ b/pkg/platform/runtime/runtime.go @@ -116,8 +116,6 @@ func (r *Runtime) validateCache() error { return nil } - return nil // remove in DX-2307 to re-enable buildscripts below - // Check if local build script has changes that should be committed. script, err := buildscript.NewScriptFromProject(r.target, r.auth) if err != nil { diff --git a/pkg/platform/runtime/setup/setup.go b/pkg/platform/runtime/setup/setup.go index 4f18b129ee..a8b2bd9efb 100644 --- a/pkg/platform/runtime/setup/setup.go +++ b/pkg/platform/runtime/setup/setup.go @@ -37,6 +37,7 @@ import ( "github.com/ActiveState/cli/pkg/platform/runtime/artifact" "github.com/ActiveState/cli/pkg/platform/runtime/artifactcache" "github.com/ActiveState/cli/pkg/platform/runtime/buildplan" + "github.com/ActiveState/cli/pkg/platform/runtime/buildscript" "github.com/ActiveState/cli/pkg/platform/runtime/envdef" "github.com/ActiveState/cli/pkg/platform/runtime/executors" "github.com/ActiveState/cli/pkg/platform/runtime/setup/buildlog" @@ -601,10 +602,9 @@ func (s *Setup) fetchAndInstallArtifactsFromBuildPlan(installFunc artifactInstal } if s.target.ProjectDir() != "" { - // Re-enable in DX-2307 - //if err := buildscript.Update(s.target, buildResult.BuildExpression, s.auth); err != nil { - // return nil, nil, errs.Wrap(err, "Could not save build script.") - //} + if err := buildscript.Update(s.target, buildResult.BuildExpression, s.auth); err != nil { + return nil, nil, errs.Wrap(err, "Could not save build script.") + } } artifacts := buildResult.OrderedArtifacts() diff --git a/pkg/project/project.go b/pkg/project/project.go index 448ffb6206..d1ffc0a559 100644 --- a/pkg/project/project.go +++ b/pkg/project/project.go @@ -219,12 +219,6 @@ func (p *Project) LegacyCommitID() string { return p.projectfile.LegacyCommitID() } -// LegacySetCommit is for use by commitmediator.Set() ONLY. -// Remove in DX-2307. -func (p *Project) LegacySetCommit(commitID string) error { - return p.projectfile.LegacySetCommit(commitID) -} - func (p *Project) IsHeadless() bool { match := projectfile.CommitURLRe.FindStringSubmatch(p.URL()) return len(match) > 1 diff --git a/pkg/project/project_test.go b/pkg/project/project_test.go index 57bd0a392d..8df0240434 100644 --- a/pkg/project/project_test.go +++ b/pkg/project/project_test.go @@ -62,7 +62,6 @@ func (suite *ProjectTestSuite) TestGetSafe() { func (suite *ProjectTestSuite) TestProject() { projectLine := "https://platform.activestate.com/ActiveState/project?branch=main" - projectLine += "&commitID=00010001-0001-0001-0001-000100010001" // remove in DX-2307 suite.Equal(projectLine, suite.project.URL(), "Values should match") suite.Equal("project", suite.project.Name(), "Values should match") commitID, err := commitmediator.Get(suite.project) diff --git a/pkg/project/testdata/activestate.yaml b/pkg/project/testdata/activestate.yaml index 80908d57b2..41f1f8d8ec 100644 --- a/pkg/project/testdata/activestate.yaml +++ b/pkg/project/testdata/activestate.yaml @@ -1,4 +1,4 @@ -project: https://platform.activestate.com/ActiveState/project?branch=main&commitID=00010001-0001-0001-0001-000100010001 +project: https://platform.activestate.com/ActiveState/project?branch=main environments: "something" lock: "master@1.0.0-SHA123" namespace: "my/name/space" diff --git a/pkg/projectfile/projectfield.go b/pkg/projectfile/projectfield.go index fbf3da6c5c..f53555edb1 100644 --- a/pkg/projectfile/projectfield.go +++ b/pkg/projectfile/projectfield.go @@ -48,11 +48,6 @@ func (p *projectField) StripCommitID() { p.unsetQuery("commitID") // legacy } -// Remove this in DX-2307. -func (p *projectField) LegacySetCommit(commitID string) { - p.setQuery("commitID", commitID) -} - func (p *projectField) setPath(path string) { p.url.Path = path p.url.RawPath = p.url.EscapedPath() diff --git a/pkg/projectfile/projectfile.go b/pkg/projectfile/projectfile.go index 664c7a72be..04b60f6ff1 100644 --- a/pkg/projectfile/projectfile.go +++ b/pkg/projectfile/projectfile.go @@ -564,25 +564,6 @@ func (p *Project) LegacyCommitID() string { return p.parsedURL.LegacyCommitID } -// LegacySetCommit is for use by commitmediator.Set() ONLY. -// It changes the legacy commit ID in activestate.yaml. -// Remove this in DX-2307. -func (p *Project) LegacySetCommit(commitID string) error { - pf := NewProjectField() - if err := pf.LoadProject(p.Project); err != nil { - return errs.Wrap(err, "Could not load activestate.yaml") - } - pf.LegacySetCommit(commitID) - if err := pf.Save(p.path); err != nil { - return errs.Wrap(err, "Could not save activestate.yaml") - } - - p.parsedURL.LegacyCommitID = commitID - p.Project = pf.String() - return nil -} - -// Remove this function in DX-2307. func (p *Project) Dir() string { return filepath.Dir(p.path) } @@ -922,17 +903,16 @@ func FromExactPath(path string) (*Project, error) { // CreateParams are parameters that we create a custom activestate.yaml file from type CreateParams struct { - Owner string - Project string - BranchName string - Directory string - Content string - Language string - Private bool - path string - ProjectURL string - Cache string - LegacyCommitID string // remove in DX-2307 + Owner string + Project string + BranchName string + Directory string + Content string + Language string + Private bool + path string + ProjectURL string + Cache string } // Create will create a new activestate.yaml with a projectURL for the given details @@ -963,11 +943,6 @@ func createCustom(params *CreateParams, lang language.Language) (*Project, error q.Set("branch", params.BranchName) } - // Remove this block in DX-2307. - if params.LegacyCommitID != "" { - q.Set("commitID", params.LegacyCommitID) - } - u.RawQuery = q.Encode() params.ProjectURL = u.String() } diff --git a/test/integration/checkout_int_test.go b/test/integration/checkout_int_test.go index e7a3a87ed6..893fe1973b 100644 --- a/test/integration/checkout_int_test.go +++ b/test/integration/checkout_int_test.go @@ -40,13 +40,12 @@ func (suite *CheckoutIntegrationTestSuite) TestCheckout() { suite.Require().True(fileutils.FileExists(filepath.Join(ts.Dirs.Work, constants.ConfigFileName)), "ActiveState-CLI/Python3 was not checked out properly") // Verify .activestate/commit and .gitignore were created. - // Re-enable the following lines in DX-2307. - //projectConfigDir := filepath.Join(ts.Dirs.Work, constants.ProjectConfigDirName) - //suite.Require().True(fileutils.DirExists(projectConfigDir), "state checkout should have created "+projectConfigDir) - //suite.Assert().True(fileutils.FileExists(filepath.Join(projectConfigDir, constants.CommitIdFileName)), "commit file not created") - //gitignoreFile := filepath.Join(ts.Dirs.Work, ".gitignore") - //suite.Assert().True(fileutils.FileExists(gitignoreFile), "fresh checkout did not create .gitignore") - //suite.Assert().Contains(string(fileutils.ReadFileUnsafe(gitignoreFile)), fmt.Sprintf("%s/%s", constants.ProjectConfigDirName, constants.CommitIdFileName), "commit file not added to .gitignore") + projectConfigDir := filepath.Join(ts.Dirs.Work, constants.ProjectConfigDirName) + suite.Require().True(fileutils.DirExists(projectConfigDir), "state checkout should have created "+projectConfigDir) + suite.Assert().True(fileutils.FileExists(filepath.Join(projectConfigDir, constants.CommitIdFileName)), "commit file not created") + gitignoreFile := filepath.Join(ts.Dirs.Work, ".gitignore") + suite.Assert().True(fileutils.FileExists(gitignoreFile), "fresh checkout did not create .gitignore") + suite.Assert().Contains(string(fileutils.ReadFileUnsafe(gitignoreFile)), fmt.Sprintf("%s/%s", constants.ProjectConfigDirName, constants.CommitIdFileName), "commit file not added to .gitignore") // Verify runtime was installed correctly and works. targetDir := target.ProjectDirToTargetDir(ts.Dirs.Work, ts.Dirs.Cache) @@ -155,10 +154,9 @@ func (suite *CheckoutIntegrationTestSuite) TestCheckoutWithFlags() { cp.ExpectExitCode(0) suite.Require().True(fileutils.DirExists(python3Dir), "state checkout should have created "+python3Dir) - // Re-enable the following lines in DX-2307. - //commitIdFile := filepath.Join(python3Dir, constants.ProjectConfigDirName, constants.CommitIdFileName) - //suite.Require().True(fileutils.FileExists(commitIdFile), "ActiveState-CLI/Python3 was not checked out properly") - //suite.Assert().Equal(string(fileutils.ReadFileUnsafe(commitIdFile)), "6d9280e7-75eb-401a-9e71-0d99759fbad3", "did not check out specific commit ID") + commitIdFile := filepath.Join(python3Dir, constants.ProjectConfigDirName, constants.CommitIdFileName) + suite.Require().True(fileutils.FileExists(commitIdFile), "ActiveState-CLI/Python3 was not checked out properly") + suite.Assert().Equal(string(fileutils.ReadFileUnsafe(commitIdFile)), "6d9280e7-75eb-401a-9e71-0d99759fbad3", "did not check out specific commit ID") // Test --branch mismatch in non-checked-out project. branchPath := filepath.Join(ts.Dirs.Base, "branch") diff --git a/test/integration/commit_int_test.go b/test/integration/commit_int_test.go index 57bf60d0fe..c58eba8230 100644 --- a/test/integration/commit_int_test.go +++ b/test/integration/commit_int_test.go @@ -20,7 +20,6 @@ type CommitIntegrationTestSuite struct { func (suite *CommitIntegrationTestSuite) TestCommitManualBuildScriptMod() { suite.OnlyRunForTags(tagsuite.Commit) - suite.T().Skip("Temporarily disable buildscripts until DX-2307") // remove in DX-2307 ts := e2e.New(suite.T(), false) defer ts.Close() diff --git a/test/integration/install_int_test.go b/test/integration/install_int_test.go index a2bfb29d7d..bf760a3e09 100644 --- a/test/integration/install_int_test.go +++ b/test/integration/install_int_test.go @@ -32,15 +32,13 @@ func (suite *InstallIntegrationTestSuite) TestInstall_InvalidCommit() { ts.PrepareProject("ActiveState-CLI/small-python", "malformed-commit-id") cp := ts.SpawnWithOpts(e2e.OptArgs("install", "trender")) - //cp.Expect("Could not find or read the commit file") // re-enable in DX-2307 - cp.Expect("Invalid commit ID") // remove in DX-2307 + cp.Expect("Could not find or read the commit file") cp.ExpectExitCode(1) ts.IgnoreLogErrors() - // Re-enable in DX-2307. - //if strings.Count(cp.Snapshot(), " x ") != 1 { - // suite.Fail("Expected exactly ONE error message, got: ", cp.Snapshot()) - //} + if strings.Count(cp.Snapshot(), " x ") != 1 { + suite.Fail("Expected exactly ONE error message, got: ", cp.Snapshot()) + } } func (suite *InstallIntegrationTestSuite) TestInstall_NoMatches_NoAlternatives() { diff --git a/test/integration/project_migration_int_test.go b/test/integration/project_migration_int_test.go index 494b081a42..a39c648f7a 100644 --- a/test/integration/project_migration_int_test.go +++ b/test/integration/project_migration_int_test.go @@ -18,7 +18,6 @@ type ProjectMigrationIntegrationTestSuite struct { func (suite *ProjectMigrationIntegrationTestSuite) TestPromptMigration() { suite.OnlyRunForTags(tagsuite.Critical) - suite.T().Skip("Temporarily disabling project migration until DX-2307") // remove in DX-2307 ts := e2e.New(suite.T(), false) defer ts.Close() diff --git a/test/integration/pull_int_test.go b/test/integration/pull_int_test.go index 004df9fb1a..93964cc04a 100644 --- a/test/integration/pull_int_test.go +++ b/test/integration/pull_int_test.go @@ -12,7 +12,6 @@ import ( "github.com/ActiveState/cli/internal/testhelpers/tagsuite" "github.com/ActiveState/cli/pkg/platform/runtime/buildscript" "github.com/ActiveState/cli/pkg/project" - "github.com/ActiveState/cli/pkg/projectfile" // remove in DX-2307 "github.com/stretchr/testify/suite" ) @@ -33,10 +32,9 @@ func (suite *PullIntegrationTestSuite) TestPull() { cp.Expect("activestate.yaml has been updated") cp.ExpectExitCode(0) - // Re-enable this block in DX-2307. - //projectConfigDir := filepath.Join(ts.Dirs.Work, constants.ProjectConfigDirName) - //suite.Require().True(fileutils.DirExists(projectConfigDir)) - //suite.Assert().True(fileutils.FileExists(filepath.Join(projectConfigDir, constants.CommitIdFileName))) + projectConfigDir := filepath.Join(ts.Dirs.Work, constants.ProjectConfigDirName) + suite.Require().True(fileutils.DirExists(projectConfigDir)) + suite.Assert().True(fileutils.FileExists(filepath.Join(projectConfigDir, constants.CommitIdFileName))) cp = ts.Spawn("pull") cp.Expect("already up to date") @@ -94,14 +92,9 @@ func (suite *PullIntegrationTestSuite) TestPull_Merge() { pjfilepath := filepath.Join(ts.Dirs.Work, "cli", constants.ConfigFileName) err := fileutils.WriteFile(pjfilepath, []byte(projectLine)) suite.Require().NoError(err) - // Remove the following lines in DX-2307. - pjfile, err := projectfile.Parse(pjfilepath) + commitIdFile := filepath.Join(ts.Dirs.Work, "cli", constants.ProjectConfigDirName, constants.CommitIdFileName) + err = fileutils.WriteFile(commitIdFile, []byte(unPulledCommit)) suite.Require().NoError(err) - suite.Require().NoError(pjfile.LegacySetCommit(unPulledCommit)) - // Re-enable the following lines in DX-2307. - //commitIdFile := filepath.Join(ts.Dirs.Work, "cli", constants.ProjectConfigDirName, constants.CommitIdFileName) - //err = fileutils.WriteFile(commitIdFile, []byte(unPulledCommit)) - //suite.Require().NoError(err) ts.LoginAsPersistentUser() @@ -145,7 +138,6 @@ func (suite *PullIntegrationTestSuite) TestPull_RestoreNamespace() { func (suite *PullIntegrationTestSuite) TestMergeBuildScript() { suite.OnlyRunForTags(tagsuite.Pull) - suite.T().Skip("Temporarily disable buildscripts until DX-2307") // remove in DX-2307 ts := e2e.New(suite.T(), false) defer ts.Close() diff --git a/test/integration/push_int_test.go b/test/integration/push_int_test.go index d7a18ca19c..44a4cdabc0 100644 --- a/test/integration/push_int_test.go +++ b/test/integration/push_int_test.go @@ -367,13 +367,8 @@ func (suite *PushIntegrationTestSuite) TestPush_Outdated() { wd := filepath.Join(ts.Dirs.Work, "cli") pjfilepath := filepath.Join(ts.Dirs.Work, "cli", constants.ConfigFileName) suite.Require().NoError(fileutils.WriteFile(pjfilepath, []byte(projectLine))) - // Remove the following lines in DX-2307. - pjfile, err := projectfile.Parse(pjfilepath) - suite.Require().NoError(err) - suite.Require().NoError(pjfile.LegacySetCommit(unPushedCommit)) - // Re-enable the following lines in DX-2307. - //commitIdFile := filepath.Join(ts.Dirs.Work, "cli", constants.ProjectConfigDirName, constants.CommitIdFileName) - //suite.Require().NoError(fileutils.WriteFile(commitIdFile, []byte(unPushedCommit))) + commitIdFile := filepath.Join(ts.Dirs.Work, "cli", constants.ProjectConfigDirName, constants.CommitIdFileName) + suite.Require().NoError(fileutils.WriteFile(commitIdFile, []byte(unPushedCommit))) ts.LoginAsPersistentUser() cp := ts.SpawnWithOpts(e2e.OptArgs("push"), e2e.OptWD(wd)) From 89371f54c2463d09c31bba0e18e918ff582f8a73 Mon Sep 17 00:00:00 2001 From: mitchell Date: Mon, 22 Jan 2024 13:45:18 -0500 Subject: [PATCH 2/2] Do not assume checkout path exists when checking for emptiness. --- internal/runbits/checkout/checkout.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/runbits/checkout/checkout.go b/internal/runbits/checkout/checkout.go index 3fd64aa9da..34124c7ef4 100644 --- a/internal/runbits/checkout/checkout.go +++ b/internal/runbits/checkout/checkout.go @@ -60,9 +60,12 @@ func (r *Checkout) Run(ns *project.Namespaced, branchName, cachePath, targetPath return "", errs.Wrap(err, "Could not get absolute path") } - emptyDir, err := fileutils.IsEmptyDir(path) - if err != nil { - multilog.Error("Unable to check if directory is empty: %v", err) + emptyDir := true + if fileutils.DirExists(path) { + emptyDir, err = fileutils.IsEmptyDir(path) + if err != nil { + multilog.Error("Unable to check if directory is empty: %v", err) + } } // If project does not exist at path then we must checkout