diff --git a/internal/constraints/constraints.go b/internal/constraints/constraints.go index fc454f90ee..6eb19cf192 100644 --- a/internal/constraints/constraints.go +++ b/internal/constraints/constraints.go @@ -81,7 +81,8 @@ type projectable interface { Path() string Dir() string URL() string - LegacyCommitID() string // for commitmediator.Get + 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/commitmediator/commitmediator.go b/internal/runbits/commitmediator/commitmediator.go index 64bb3d2709..2998072013 100644 --- a/internal/runbits/commitmediator/commitmediator.go +++ b/internal/runbits/commitmediator/commitmediator.go @@ -1,9 +1,10 @@ package commitmediator import ( - "github.com/ActiveState/cli/internal/errs" - "github.com/ActiveState/cli/internal/runbits/legacy/projectmigration" - "github.com/ActiveState/cli/pkg/localcommit" + // Re-enable in DX-2307. + //"github.com/ActiveState/cli/internal/errs" + //"github.com/ActiveState/cli/internal/runbits/legacy/projectmigration" + //"github.com/ActiveState/cli/pkg/localcommit" "github.com/go-openapi/strfmt" ) @@ -12,22 +13,30 @@ 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) { - 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") - } + // 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") + //} +} + +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) } diff --git a/internal/runbits/requirements/requirements.go b/internal/runbits/requirements/requirements.go index 03c8515564..8f90d429c4 100644 --- a/internal/runbits/requirements/requirements.go +++ b/internal/runbits/requirements/requirements.go @@ -19,8 +19,9 @@ import ( "github.com/ActiveState/cli/internal/prompt" "github.com/ActiveState/cli/internal/rtutils/ptr" "github.com/ActiveState/cli/internal/runbits" + "github.com/ActiveState/cli/internal/runbits/commitmediator" "github.com/ActiveState/cli/internal/runbits/rationalize" - "github.com/ActiveState/cli/pkg/localcommit" + //"github.com/ActiveState/cli/pkg/localcommit" // re-enable in DX-2307 bpModel "github.com/ActiveState/cli/pkg/platform/api/buildplanner/model" medmodel "github.com/ActiveState/cli/pkg/platform/api/mediator/model" "github.com/ActiveState/cli/pkg/platform/authentication" @@ -108,7 +109,7 @@ func (r *RequirementOperation) ExecuteRequirementOperation(requirementName, requ switch nsType { case model.NamespacePackage, model.NamespaceBundle: - commitID, err := localcommit.Get(r.Project.Dir()) + commitID, err := commitmediator.Get(r.Project) if err != nil { return errs.Wrap(err, "Unable to get local commit") } @@ -190,7 +191,7 @@ func (r *RequirementOperation) ExecuteRequirementOperation(requirementName, requ pg = nil } - parentCommitID, err := localcommit.Get(r.Project.Dir()) + parentCommitID, err := commitmediator.Get(r.Project) if err != nil { return errs.Wrap(err, "Unable to get local commit") } @@ -274,7 +275,7 @@ func (r *RequirementOperation) ExecuteRequirementOperation(requirementName, requ return errs.Wrap(err, "Could not get remote build expr") } - if err := localcommit.Set(r.Project.Dir(), commitID.String()); err != nil { + if err := commitmediator.Set(r.Project, commitID.String()); err != nil { return locale.WrapError(err, "err_package_update_commit_id") } diff --git a/internal/runners/branch/add.go b/internal/runners/branch/add.go index 800bb57140..8782994d67 100644 --- a/internal/runners/branch/add.go +++ b/internal/runners/branch/add.go @@ -5,7 +5,8 @@ import ( "github.com/ActiveState/cli/internal/locale" "github.com/ActiveState/cli/internal/logging" "github.com/ActiveState/cli/internal/output" - "github.com/ActiveState/cli/pkg/localcommit" + "github.com/ActiveState/cli/internal/runbits/commitmediator" + //"github.com/ActiveState/cli/pkg/localcommit" // re-enable in DX-2307 "github.com/ActiveState/cli/pkg/platform/model" "github.com/ActiveState/cli/pkg/project" ) @@ -49,7 +50,7 @@ func (a *Add) Run(params AddParams) error { return locale.WrapError(err, "err_fetch_branch", "", localBranch) } - commitID, err := localcommit.Get(a.project.Dir()) + commitID, err := commitmediator.Get(a.project) if err != nil { return errs.Wrap(err, "Unable to get local commit") } diff --git a/internal/runners/initialize/init.go b/internal/runners/initialize/init.go index 7a61f94818..fd78ed49b3 100644 --- a/internal/runners/initialize/init.go +++ b/internal/runners/initialize/init.go @@ -20,7 +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/localcommit" // re-enable in DX-2307 "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" "github.com/ActiveState/cli/pkg/platform/runtime/setup" @@ -157,10 +157,11 @@ func (r *Initialize) Run(params *RunParams) (rerr error) { } } - emptyDir, err := fileutils.IsEmptyDir(path) - if err != nil { - multilog.Error("Unable to check if directory is empty: %v", err) - } + // Re-enable in DX-2307. + //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. @@ -247,16 +248,17 @@ func (r *Initialize) Run(params *RunParams) (rerr error) { return locale.WrapError(err, "err_init_commit", "Could not create initial commit") } - if err := localcommit.Set(proj.Dir(), commitID.String()); err != nil { + if err := commitmediator.Set(proj, commitID.String()); err != nil { return errs.Wrap(err, "Unable to create local commit file") } - 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) - } - } + // Re-enable in DX-2307. + //if emptyDir || fileutils.DirExists(filepath.Join(path, ".git")) {B + // 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/packages/import.go b/internal/runners/packages/import.go index 943d39f105..a4e30333ce 100644 --- a/internal/runners/packages/import.go +++ b/internal/runners/packages/import.go @@ -12,7 +12,8 @@ import ( "github.com/ActiveState/cli/internal/primer" "github.com/ActiveState/cli/internal/prompt" "github.com/ActiveState/cli/internal/runbits" - "github.com/ActiveState/cli/pkg/localcommit" + "github.com/ActiveState/cli/internal/runbits/commitmediator" + //"github.com/ActiveState/cli/pkg/localcommit" // re-enable in DX-2307 "github.com/ActiveState/cli/pkg/platform/api" gqlModel "github.com/ActiveState/cli/pkg/platform/api/graphql/model" "github.com/ActiveState/cli/pkg/platform/api/reqsimport" @@ -177,7 +178,7 @@ func fetchImportChangeset(cp ChangesetProvider, file string, lang string) (model } func commitChangeset(project *project.Project, msg string, changeset model.Changeset) (strfmt.UUID, error) { - localCommitID, err := localcommit.Get(project.Dir()) + localCommitID, err := commitmediator.Get(project) if err != nil { return "", errs.Wrap(err, "Unable to get local commit") } @@ -188,7 +189,7 @@ func commitChangeset(project *project.Project, msg string, changeset model.Chang locale.T("commit_failed_pull_tip")) } - if err := localcommit.Set(project.Dir(), commitID.String()); err != nil { + if err := commitmediator.Set(project, commitID.String()); err != nil { return "", locale.WrapError(err, "err_package_update_commit_id") } return commitID, nil diff --git a/internal/runners/pull/pull.go b/internal/runners/pull/pull.go index 586f3569d9..4bd6903f19 100644 --- a/internal/runners/pull/pull.go +++ b/internal/runners/pull/pull.go @@ -15,8 +15,9 @@ import ( "github.com/ActiveState/cli/internal/prompt" "github.com/ActiveState/cli/internal/runbits" buildscriptRunbits "github.com/ActiveState/cli/internal/runbits/buildscript" + "github.com/ActiveState/cli/internal/runbits/commitmediator" "github.com/ActiveState/cli/pkg/cmdlets/commit" - "github.com/ActiveState/cli/pkg/localcommit" + //"github.com/ActiveState/cli/pkg/localcommit" // re-enable in DX-2307 "github.com/ActiveState/cli/pkg/platform/api/mono/mono_models" "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" @@ -98,7 +99,7 @@ func (p *Pull) Run(params *PullParams) error { } var localCommit *strfmt.UUID - localCommitID, err := localcommit.Get(p.project.Dir()) + localCommitID, err := commitmediator.Get(p.project) if err != nil { return errs.Wrap(err, "Unable to get local commit") } @@ -150,13 +151,13 @@ func (p *Pull) Run(params *PullParams) error { } } - commitID, err := localcommit.Get(p.project.Dir()) + commitID, err := commitmediator.Get(p.project) if err != nil { return errs.Wrap(err, "Unable to get local commit") } if commitID != *resultingCommit { - err := localcommit.Set(p.project.Dir(), resultingCommit.String()) + err := commitmediator.Set(p.project, resultingCommit.String()) if err != nil { return errs.Wrap(err, "Unable to set local commit") } @@ -191,7 +192,7 @@ func (p *Pull) performMerge(strategies *mono_models.MergeStrategies, remoteCommi "pull_diverged_message", namespace.String(), branchName, localCommit.String(), remoteCommit.String())) - commitID, err := localcommit.Get(p.project.Dir()) + commitID, err := commitmediator.Get(p.project) if err != nil { return "", errs.Wrap(err, "Unable to get local commit") } diff --git a/internal/runners/push/push.go b/internal/runners/push/push.go index 20367586ec..4bb4c71949 100644 --- a/internal/runners/push/push.go +++ b/internal/runners/push/push.go @@ -12,8 +12,9 @@ import ( "github.com/ActiveState/cli/internal/primer" "github.com/ActiveState/cli/internal/prompt" "github.com/ActiveState/cli/internal/rtutils/ptr" + "github.com/ActiveState/cli/internal/runbits/commitmediator" "github.com/ActiveState/cli/internal/runbits/rationalize" - "github.com/ActiveState/cli/pkg/localcommit" + //"github.com/ActiveState/cli/pkg/localcommit" // re-enable in DX-2307 "github.com/ActiveState/cli/pkg/platform/api/mono/mono_models" "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" @@ -87,7 +88,7 @@ func (r *Push) Run(params PushParams) (rerr error) { } r.out.Notice(locale.Tl("operating_message", "", r.project.NamespaceString(), r.project.Dir())) - commitID, err := localcommit.Get(r.project.Dir()) // The commit we want to push + commitID, err := commitmediator.Get(r.project) // The commit we want to push if err != nil { // Note: should not get here, as verifyInput() ensures there is a local commit return errs.Wrap(err, "Unable to get local commit") @@ -191,7 +192,7 @@ func (r *Push) Run(params PushParams) (rerr error) { } // Update the project's commitID with the create project or push result. - if err := localcommit.Set(r.project.Dir(), commitID.String()); err != nil { + if err := commitmediator.Set(r.project, commitID.String()); err != nil { return errs.Wrap(err, "Unable to create local commit file") } @@ -297,7 +298,7 @@ func (r *Push) verifyInput() error { return rationalize.ErrNoProject } - commitID, err := localcommit.Get(r.project.Dir()) + commitID, err := commitmediator.Get(r.project) if err != nil { return errs.Wrap(err, "Unable to get local commit") } @@ -335,7 +336,7 @@ func (r *Push) promptNamespace() (*project.Namespaced, error) { } var name string - commitID, err := localcommit.Get(r.project.Dir()) + commitID, err := commitmediator.Get(r.project) if err != nil { return nil, errs.Wrap(err, "Unable to get local commit") } diff --git a/internal/runners/reset/reset.go b/internal/runners/reset/reset.go index f64ac2cd6d..09777c94f3 100644 --- a/internal/runners/reset/reset.go +++ b/internal/runners/reset/reset.go @@ -8,7 +8,8 @@ import ( "github.com/ActiveState/cli/internal/primer" "github.com/ActiveState/cli/internal/prompt" "github.com/ActiveState/cli/internal/runbits" - "github.com/ActiveState/cli/pkg/localcommit" + "github.com/ActiveState/cli/internal/runbits/commitmediator" + //"github.com/ActiveState/cli/pkg/localcommit" // re-enable in DX-2307 "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" "github.com/ActiveState/cli/pkg/platform/runtime/target" @@ -63,7 +64,7 @@ func (r *Reset) Run(params *Params) error { if err != nil { return locale.WrapError(err, "err_reset_latest_commit", "Could not get latest commit ID") } - localCommitID, err := localcommit.Get(r.project.Dir()) + localCommitID, err := commitmediator.Get(r.project) if err != nil { return errs.Wrap(err, "Unable to get local commit") } @@ -76,7 +77,7 @@ func (r *Reset) Run(params *Params) error { return locale.NewInputError("Invalid commit ID") } commitID = strfmt.UUID(params.CommitID) - localCommitID, err := localcommit.Get(r.project.Dir()) + localCommitID, err := commitmediator.Get(r.project) if err != nil { return errs.Wrap(err, "Unable to get local commit") } @@ -100,7 +101,7 @@ func (r *Reset) Run(params *Params) error { return locale.NewInputError("err_reset_aborted", "Reset aborted by user") } - err = localcommit.Set(r.project.Dir(), commitID.String()) + err = commitmediator.Set(r.project, commitID.String()) if err != nil { return errs.Wrap(err, "Unable to set local commit") } diff --git a/internal/runners/revert/revert.go b/internal/runners/revert/revert.go index f2e345a29a..46343352fa 100644 --- a/internal/runners/revert/revert.go +++ b/internal/runners/revert/revert.go @@ -8,8 +8,9 @@ import ( "github.com/ActiveState/cli/internal/primer" "github.com/ActiveState/cli/internal/prompt" "github.com/ActiveState/cli/internal/runbits" + "github.com/ActiveState/cli/internal/runbits/commitmediator" "github.com/ActiveState/cli/pkg/cmdlets/commit" - "github.com/ActiveState/cli/pkg/localcommit" + //"github.com/ActiveState/cli/pkg/localcommit" // re-enable in DX-2307 gqlmodel "github.com/ActiveState/cli/pkg/platform/api/graphql/model" "github.com/ActiveState/cli/pkg/platform/api/mono/mono_models" "github.com/ActiveState/cli/pkg/platform/authentication" @@ -61,7 +62,7 @@ func (r *Revert) Run(params *Params) error { if !strfmt.IsUUID(params.CommitID) { return locale.NewInputError("err_invalid_commit_id", "Invalid commit ID") } - latestCommit, err := localcommit.Get(r.project.Dir()) + latestCommit, err := commitmediator.Get(r.project) if err != nil { return errs.Wrap(err, "Unable to get local commit") } @@ -139,7 +140,7 @@ func (r *Revert) Run(params *Params) error { return locale.WrapError(err, "err_refresh_runtime") } - err = localcommit.Set(r.project.Dir(), revertCommit.CommitID.String()) + err = commitmediator.Set(r.project, revertCommit.CommitID.String()) if err != nil { return errs.Wrap(err, "Unable to set local commit") } diff --git a/internal/runners/swtch/switch.go b/internal/runners/swtch/switch.go index 1f63120613..52f334c2ac 100644 --- a/internal/runners/swtch/switch.go +++ b/internal/runners/swtch/switch.go @@ -8,7 +8,8 @@ import ( "github.com/ActiveState/cli/internal/output" "github.com/ActiveState/cli/internal/primer" "github.com/ActiveState/cli/internal/runbits" - "github.com/ActiveState/cli/pkg/localcommit" + "github.com/ActiveState/cli/internal/runbits/commitmediator" + //"github.com/ActiveState/cli/pkg/localcommit" // re-enable in DX-2307 "github.com/ActiveState/cli/pkg/platform/api/mono/mono_models" "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" @@ -110,7 +111,7 @@ func (s *Switch) Run(params SwitchParams) error { return locale.NewInputError("err_identifier_branch_not_on_branch", "Commit does not belong to history for branch [ACTIONABLE]{{.V0}}[/RESET]", s.project.BranchName()) } - err = localcommit.Set(s.project.Dir(), identifier.CommitID().String()) + err = commitmediator.Set(s.project, identifier.CommitID().String()) if err != nil { return errs.Wrap(err, "Unable to set local commit") } diff --git a/internal/testhelpers/e2e/session.go b/internal/testhelpers/e2e/session.go index 2f25d5fd4f..93d22c0723 100644 --- a/internal/testhelpers/e2e/session.go +++ b/internal/testhelpers/e2e/session.go @@ -43,6 +43,7 @@ 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 @@ -380,7 +381,11 @@ func (s *Session) PrepareActiveStateYAML(contents string) { } func (s *Session) PrepareCommitIdFile(commitID string) { - require.NoError(s.t, fileutils.WriteFile(filepath.Join(s.Dirs.Work, constants.ProjectConfigDirName, constants.CommitIdFileName), []byte(commitID))) + // 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)) } // PrepareProject creates a very simple activestate.yaml file for the given org/project and, if a diff --git a/pkg/cmdlets/checkout/checkout.go b/pkg/cmdlets/checkout/checkout.go index 3a3e5235c9..af4ff463de 100644 --- a/pkg/cmdlets/checkout/checkout.go +++ b/pkg/cmdlets/checkout/checkout.go @@ -13,10 +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/multilog" // re-enable in DX-2307 "github.com/ActiveState/cli/internal/output" "github.com/ActiveState/cli/pkg/cmdlets/git" - "github.com/ActiveState/cli/pkg/localcommit" + //"github.com/ActiveState/cli/pkg/localcommit" // re-enable in DX-2307 "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" "github.com/ActiveState/cli/pkg/project" @@ -59,10 +59,11 @@ 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) - } + // Re-enable in DX-2307. + //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 @@ -127,29 +128,31 @@ 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, + 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 }) if err != nil { return "", errs.Wrap(err, "Could not create projectfile") } } - 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) - } - } + // 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) + // } + //} return path, nil } diff --git a/pkg/project/project.go b/pkg/project/project.go index d1ffc0a559..448ffb6206 100644 --- a/pkg/project/project.go +++ b/pkg/project/project.go @@ -219,6 +219,12 @@ 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 b8c3ae4b63..ad57a276c3 100644 --- a/pkg/project/project_test.go +++ b/pkg/project/project_test.go @@ -11,8 +11,9 @@ import ( "github.com/ActiveState/cli/internal/environment" "github.com/ActiveState/cli/internal/errs" "github.com/ActiveState/cli/internal/language" + "github.com/ActiveState/cli/internal/runbits/commitmediator" "github.com/ActiveState/cli/internal/subshell" - "github.com/ActiveState/cli/pkg/localcommit" + //"github.com/ActiveState/cli/pkg/localcommit" // re-enable in DX-2307 "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/project" "github.com/ActiveState/cli/pkg/projectfile" @@ -61,9 +62,11 @@ func (suite *ProjectTestSuite) TestGetSafe() { } func (suite *ProjectTestSuite) TestProject() { - suite.Equal("https://platform.activestate.com/ActiveState/project?branch=main", suite.project.URL(), "Values should match") + 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 := localcommit.Get(suite.project.Dir()) + commitID, err := commitmediator.Get(suite.project) suite.NoError(err) suite.Equal("00010001-0001-0001-0001-000100010001", commitID.String(), "Values should match") suite.Equal("ActiveState", suite.project.Owner(), "Values should match") diff --git a/pkg/project/testdata/activestate.yaml b/pkg/project/testdata/activestate.yaml index 41f1f8d8ec..80908d57b2 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 +project: https://platform.activestate.com/ActiveState/project?branch=main&commitID=00010001-0001-0001-0001-000100010001 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 f53555edb1..fbf3da6c5c 100644 --- a/pkg/projectfile/projectfield.go +++ b/pkg/projectfile/projectfield.go @@ -48,6 +48,11 @@ 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 ffab8e795d..664c7a72be 100644 --- a/pkg/projectfile/projectfile.go +++ b/pkg/projectfile/projectfile.go @@ -564,6 +564,29 @@ 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) +} + // SetPath sets the path of the project file and should generally only be used by tests func (p *Project) SetPath(path string) { p.path = path @@ -899,16 +922,17 @@ 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 + 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 } // Create will create a new activestate.yaml with a projectURL for the given details @@ -939,6 +963,11 @@ 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 e016dc1d0f..ad12549a75 100644 --- a/test/integration/checkout_int_test.go +++ b/test/integration/checkout_int_test.go @@ -40,12 +40,13 @@ 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. - 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") + // 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") // Verify runtime was installed correctly and works. targetDir := target.ProjectDirToTargetDir(ts.Dirs.Work, ts.Dirs.Cache) @@ -152,10 +153,11 @@ func (suite *CheckoutIntegrationTestSuite) TestCheckoutWithFlags() { cp.Expect("Checked out") cp.ExpectExitCode(0) - suite.Require().True(fileutils.DirExists(python3Dir), "state checkout should have created "+python3Dir) - 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") + // Re-enable the following lines in DX-2307. + //suite.Require().True(fileutils.DirExists(python3Dir), "state checkout should have created "+python3Dir) + //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/install_int_test.go b/test/integration/install_int_test.go index 0851c5bfd4..3217240f3b 100644 --- a/test/integration/install_int_test.go +++ b/test/integration/install_int_test.go @@ -32,7 +32,8 @@ 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") + //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.ExpectExitCode(1) if strings.Count(cp.Snapshot(), " x ") != 1 { diff --git a/test/integration/project_migration_int_test.go b/test/integration/project_migration_int_test.go index a39c648f7a..494b081a42 100644 --- a/test/integration/project_migration_int_test.go +++ b/test/integration/project_migration_int_test.go @@ -18,6 +18,7 @@ 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 d16923cbee..0f024b620a 100644 --- a/test/integration/pull_int_test.go +++ b/test/integration/pull_int_test.go @@ -12,6 +12,7 @@ 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" ) @@ -32,9 +33,10 @@ func (suite *PullIntegrationTestSuite) TestPull() { cp.Expect("activestate.yaml has been updated") cp.ExpectExitCode(0) - projectConfigDir := filepath.Join(ts.Dirs.Work, constants.ProjectConfigDirName) - suite.Require().True(fileutils.DirExists(projectConfigDir)) - suite.Assert().True(fileutils.FileExists(filepath.Join(projectConfigDir, constants.CommitIdFileName))) + // 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))) cp = ts.Spawn("pull") cp.Expect("already up to date") @@ -90,9 +92,14 @@ func (suite *PullIntegrationTestSuite) TestPull_Merge() { pjfilepath := filepath.Join(ts.Dirs.Work, "cli", constants.ConfigFileName) err := fileutils.WriteFile(pjfilepath, []byte(projectLine)) suite.Require().NoError(err) - commitIdFile := filepath.Join(ts.Dirs.Work, "cli", constants.ProjectConfigDirName, constants.CommitIdFileName) - err = fileutils.WriteFile(commitIdFile, []byte(unPulledCommit)) + // Remove the following lines in DX-2307. + pjfile, err := projectfile.Parse(pjfilepath) 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() diff --git a/test/integration/push_int_test.go b/test/integration/push_int_test.go index f12b75524f..90ec0ce493 100644 --- a/test/integration/push_int_test.go +++ b/test/integration/push_int_test.go @@ -13,10 +13,11 @@ import ( "github.com/ActiveState/cli/internal/constants" "github.com/ActiveState/cli/internal/fileutils" + "github.com/ActiveState/cli/internal/runbits/commitmediator" "github.com/ActiveState/cli/internal/strutils" "github.com/ActiveState/cli/internal/testhelpers/e2e" "github.com/ActiveState/cli/internal/testhelpers/tagsuite" - "github.com/ActiveState/cli/pkg/localcommit" + //"github.com/ActiveState/cli/pkg/localcommit" // re-enable in DX-2307 "github.com/ActiveState/cli/pkg/project" "github.com/ActiveState/cli/pkg/projectfile" ) @@ -73,7 +74,7 @@ func (suite *PushIntegrationTestSuite) TestInitAndPush() { // Check that languages were reset pjfile, err := projectfile.Parse(pjfilepath) suite.Require().NoError(err) - commitID, err := localcommit.Get(filepath.Join(ts.Dirs.Work, namespace)) + commitID, err := commitmediator.Get(pjfile) suite.Require().NoError(err) suite.Require().NotEmpty(commitID.String(), "commitID was not set after running push for project creation") suite.Require().NotEmpty(pjfile.BranchName(), "branch was not set after running push for project creation") @@ -359,8 +360,13 @@ 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))) - commitIdFile := filepath.Join(ts.Dirs.Work, "cli", constants.ProjectConfigDirName, constants.CommitIdFileName) - suite.Require().NoError(fileutils.WriteFile(commitIdFile, []byte(unPushedCommit))) + // 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))) ts.LoginAsPersistentUser() cp := ts.SpawnWithOpts(e2e.OptArgs("push"), e2e.OptWD(wd)) diff --git a/test/integration/switch_int_test.go b/test/integration/switch_int_test.go index 7508c78de8..f87255c21b 100644 --- a/test/integration/switch_int_test.go +++ b/test/integration/switch_int_test.go @@ -6,9 +6,10 @@ import ( "testing" "github.com/ActiveState/cli/internal/constants" + "github.com/ActiveState/cli/internal/runbits/commitmediator" "github.com/ActiveState/cli/internal/testhelpers/e2e" "github.com/ActiveState/cli/internal/testhelpers/tagsuite" - "github.com/ActiveState/cli/pkg/localcommit" + //"github.com/ActiveState/cli/pkg/localcommit" // re-enable in DX-2307 "github.com/ActiveState/cli/pkg/projectfile" "github.com/stretchr/testify/suite" ) @@ -31,7 +32,7 @@ func (suite *SwitchIntegrationTestSuite) TestSwitch_Branch() { pjfile, err := projectfile.Parse(pjfilepath) suite.Require().NoError(err) suite.Require().Equal("main", pjfile.BranchName(), "branch was not set to 'main' after pull") - mainBranchCommitID, err := localcommit.Get(ts.Dirs.Work) + mainBranchCommitID, err := commitmediator.Get(pjfile) suite.Require().NoError(err) cp := ts.SpawnWithOpts(e2e.OptArgs("switch", "secondbranch")) @@ -45,7 +46,7 @@ func (suite *SwitchIntegrationTestSuite) TestSwitch_Branch() { // Check that branch and commitID were updated pjfile, err = projectfile.Parse(pjfilepath) suite.Require().NoError(err) - commitID, err := localcommit.Get(ts.Dirs.Work) + commitID, err := commitmediator.Get(pjfile) suite.Require().NoError(err) suite.Require().NotEqual(mainBranchCommitID, commitID, "commitID was not updated after switching branches") suite.Require().Equal("secondbranch", pjfile.BranchName(), "branch was not updated after switching branches") @@ -65,7 +66,7 @@ func (suite *SwitchIntegrationTestSuite) TestSwitch_CommitID() { pjfile, err := projectfile.Parse(pjfilepath) suite.Require().NoError(err) suite.Require().Equal("main", pjfile.BranchName(), "branch was not set to 'main' after pull") - originalCommitID, err := localcommit.Get(ts.Dirs.Work) + originalCommitID, err := commitmediator.Get(pjfile) suite.Require().NoError(err) cp := ts.SpawnWithOpts(e2e.OptArgs("switch", "efce7c7a-c61a-4b04-bb00-f8e7edfd247f")) @@ -77,7 +78,7 @@ func (suite *SwitchIntegrationTestSuite) TestSwitch_CommitID() { // Check that branch and commitID were updated pjfile, err = projectfile.Parse(pjfilepath) suite.Require().NoError(err) - commitID, err := localcommit.Get(ts.Dirs.Work) + commitID, err := commitmediator.Get(pjfile) suite.Require().NotEqual(originalCommitID, commitID, "commitID was not updated after switching branches") } @@ -95,7 +96,7 @@ func (suite *SwitchIntegrationTestSuite) TestSwitch_CommitID_NotInHistory() { pjfile, err := projectfile.Parse(pjfilepath) suite.Require().NoError(err) suite.Require().Equal("main", pjfile.BranchName(), "branch was not set to 'main' after pull") - originalCommitID, err := localcommit.Get(ts.Dirs.Work) + originalCommitID, err := commitmediator.Get(pjfile) suite.Require().NoError(err) cp := ts.SpawnWithOpts(e2e.OptArgs("switch", "76dff77a-66b9-43e3-90be-dc75917dd661")) @@ -107,7 +108,7 @@ func (suite *SwitchIntegrationTestSuite) TestSwitch_CommitID_NotInHistory() { // Check that branch and commitID were not updated pjfile, err = projectfile.Parse(pjfilepath) suite.Require().NoError(err) - commitID, err := localcommit.Get(ts.Dirs.Work) + commitID, err := commitmediator.Get(pjfile) suite.Require().NoError(err) suite.Equal(originalCommitID, commitID, "commitID was updated after switching branches") }