Skip to content

Commit

Permalink
Temporarily disable localcommit files.
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchell-as committed Oct 30, 2023
1 parent fb9374a commit 9ceab6e
Show file tree
Hide file tree
Showing 24 changed files with 211 additions and 122 deletions.
3 changes: 2 additions & 1 deletion internal/constraints/constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
39 changes: 24 additions & 15 deletions internal/runbits/commitmediator/commitmediator.go
Original file line number Diff line number Diff line change
@@ -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"
)

Expand All @@ -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)
}
9 changes: 5 additions & 4 deletions internal/runbits/requirements/requirements.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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")
}

Expand Down
5 changes: 3 additions & 2 deletions internal/runners/branch/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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")
}
Expand Down
28 changes: 15 additions & 13 deletions internal/runners/initialize/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
7 changes: 4 additions & 3 deletions internal/runners/packages/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
}
Expand All @@ -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
Expand Down
11 changes: 6 additions & 5 deletions internal/runners/pull/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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")
}
Expand Down
11 changes: 6 additions & 5 deletions internal/runners/push/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
}

Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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")
}
Expand Down
9 changes: 5 additions & 4 deletions internal/runners/reset/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
}
Expand All @@ -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")
}
Expand All @@ -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")
}
Expand Down
7 changes: 4 additions & 3 deletions internal/runners/revert/revert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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")
}
Expand Down
5 changes: 3 additions & 2 deletions internal/runners/swtch/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
}
Expand Down
Loading

0 comments on commit 9ceab6e

Please sign in to comment.