diff --git a/internal/captain/rationalize.go b/internal/captain/rationalize.go index c44d7dbfdf..11a079e1e0 100644 --- a/internal/captain/rationalize.go +++ b/internal/captain/rationalize.go @@ -7,11 +7,11 @@ import ( "github.com/ActiveState/cli/internal/locale" "github.com/ActiveState/cli/internal/runbits/rationalize" "github.com/ActiveState/cli/pkg/buildscript" - "github.com/ActiveState/cli/pkg/localcommit" + "github.com/ActiveState/cli/pkg/checkoutinfo" ) func rationalizeError(err *error) { - var errInvalidCommitID *localcommit.ErrInvalidCommitID + var errInvalidCommitID *checkoutinfo.ErrInvalidCommitID switch { case err == nil: diff --git a/internal/events/cmdcall/cmdcall.go b/internal/events/cmdcall/cmdcall.go index 7e8d068016..2e2e56e27f 100644 --- a/internal/events/cmdcall/cmdcall.go +++ b/internal/events/cmdcall/cmdcall.go @@ -21,6 +21,7 @@ type primeable interface { primer.Configurer primer.Analyticer primer.SvcModeler + primer.CheckoutInfoer } // CmdCall manages dependencies for the handling of events triggered by command diff --git a/internal/migrator/migrator.go b/internal/migrator/migrator.go index 23c7b7fa1f..5dd5be424f 100644 --- a/internal/migrator/migrator.go +++ b/internal/migrator/migrator.go @@ -9,6 +9,7 @@ import ( "github.com/ActiveState/cli/internal/locale" "github.com/ActiveState/cli/internal/logging" "github.com/ActiveState/cli/internal/runbits/buildscript" + "github.com/ActiveState/cli/pkg/checkoutinfo" "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" "github.com/ActiveState/cli/pkg/projectfile" @@ -29,7 +30,8 @@ func NewMigrator(auth *authentication.Auth, cfg *config.Instance, svcm *model.Sv case 0: if cfg.GetBool(constants.OptinBuildscriptsConfig) { logging.Debug("Creating buildscript") - if err := buildscript_runbit.Initialize(filepath.Dir(project.Path()), auth, svcm); err != nil { + info := checkoutinfo.New(project) + if err := buildscript_runbit.Initialize(filepath.Dir(project.Path()), auth, svcm, info); err != nil { return v, errs.Wrap(err, "Failed to initialize buildscript") } } diff --git a/internal/primer/primer.go b/internal/primer/primer.go index 8ad3854415..af9bfa6c07 100644 --- a/internal/primer/primer.go +++ b/internal/primer/primer.go @@ -12,6 +12,7 @@ import ( "github.com/ActiveState/cli/internal/prompt" "github.com/ActiveState/cli/internal/subshell" "github.com/ActiveState/cli/internal/svcctl" + "github.com/ActiveState/cli/pkg/checkoutinfo" "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" "github.com/ActiveState/cli/pkg/project" @@ -19,17 +20,18 @@ import ( ) type Values struct { - project *project.Project - projectfile *projectfile.Project - output output.Outputer - auth *authentication.Auth - prompt prompt.Prompter - subshell subshell.SubShell - conditional *constraints.Conditional - config *config.Instance - ipComm svcctl.IPCommunicator - svcModel *model.SvcModel - analytics analytics.Dispatcher + project *project.Project + projectfile *projectfile.Project + output output.Outputer + auth *authentication.Auth + prompt prompt.Prompter + subshell subshell.SubShell + conditional *constraints.Conditional + config *config.Instance + ipComm svcctl.IPCommunicator + svcModel *model.SvcModel + analytics analytics.Dispatcher + checkoutinfo *checkoutinfo.CheckoutInfo } func New(values ...any) *Values { @@ -65,12 +67,14 @@ func New(values ...any) *Values { } } } + result.checkoutinfo = checkoutinfo.New(result.projectfile) return result } func (v *Values) SetProject(p *project.Project) { v.project = p v.projectfile = p.Source() + v.checkoutinfo = checkoutinfo.New(v.projectfile) } type Projecter interface { @@ -118,6 +122,10 @@ type Conditioner interface { Conditional() *constraints.Conditional } +type CheckoutInfoer interface { + CheckoutInfo() *checkoutinfo.CheckoutInfo +} + func (v *Values) Project() *project.Project { return v.project } @@ -161,3 +169,7 @@ func (v *Values) Config() *config.Instance { func (v *Values) Analytics() analytics.Dispatcher { return v.analytics } + +func (v *Values) CheckoutInfo() *checkoutinfo.CheckoutInfo { + return v.checkoutinfo +} diff --git a/internal/runbits/buildplanner/buildplanner.go b/internal/runbits/buildplanner/buildplanner.go index 85db3935c2..00d34b0485 100644 --- a/internal/runbits/buildplanner/buildplanner.go +++ b/internal/runbits/buildplanner/buildplanner.go @@ -9,7 +9,6 @@ import ( "github.com/ActiveState/cli/internal/rtutils/ptr" "github.com/ActiveState/cli/internal/runbits/rationalize" "github.com/ActiveState/cli/pkg/buildplan" - "github.com/ActiveState/cli/pkg/localcommit" "github.com/ActiveState/cli/pkg/platform/api/buildplanner/request" "github.com/ActiveState/cli/pkg/platform/model" bpModel "github.com/ActiveState/cli/pkg/platform/model/buildplanner" @@ -39,6 +38,7 @@ type primeable interface { primer.Auther primer.Outputer primer.SvcModeler + primer.CheckoutInfoer } // GetCommit returns a commit from the given arguments. By default, the local commit for the @@ -54,6 +54,7 @@ func GetCommit( out := prime.Output() auth := prime.Auth() svcm := prime.SvcModel() + info := prime.CheckoutInfo() if pj == nil && !namespace.IsValid() { return nil, rationalize.ErrNoProject @@ -87,9 +88,9 @@ func GetCommit( switch { // Return the buildplan from this runtime. case !namespaceProvided && !commitIdProvided: - localCommitID, err := localcommit.Get(pj.Path()) + localCommitID, err := info.CommitID() if err != nil { - return nil, errs.Wrap(err, "Could not get local commit") + return nil, errs.Wrap(err, "Could not get commit ID") } bp := bpModel.NewBuildPlannerModel(auth, svcm) @@ -154,9 +155,9 @@ func GetCommit( owner = pj.Owner() name = pj.Name() nsString = pj.NamespaceString() - commitID, err := localcommit.Get(pj.Path()) + commitID, err := info.CommitID() if err != nil { - return nil, errs.Wrap(err, "Could not get local commit") + return nil, errs.Wrap(err, "Could not get commit ID") } localCommitID = &commitID } diff --git a/internal/runbits/buildscript/file.go b/internal/runbits/buildscript/file.go index 72e66d5ff6..657e5637b8 100644 --- a/internal/runbits/buildscript/file.go +++ b/internal/runbits/buildscript/file.go @@ -9,9 +9,8 @@ import ( "github.com/ActiveState/cli/internal/errs" "github.com/ActiveState/cli/internal/fileutils" "github.com/ActiveState/cli/internal/logging" - "github.com/ActiveState/cli/internal/primer" "github.com/ActiveState/cli/pkg/buildscript" - "github.com/ActiveState/cli/pkg/localcommit" + "github.com/ActiveState/cli/pkg/checkoutinfo" "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" "github.com/ActiveState/cli/pkg/platform/model/buildplanner" @@ -42,12 +41,7 @@ func ScriptFromFile(path string) (*buildscript.BuildScript, error) { return buildscript.Unmarshal(data) } -type primeable interface { - primer.Auther - primer.SvcModeler -} - -func Initialize(path string, auth *authentication.Auth, svcm *model.SvcModel) error { +func Initialize(path string, auth *authentication.Auth, svcm *model.SvcModel, info *checkoutinfo.CheckoutInfo) error { scriptPath := filepath.Join(path, constants.BuildScriptFileName) script, err := ScriptFromFile(scriptPath) if err == nil { @@ -58,7 +52,7 @@ func Initialize(path string, auth *authentication.Auth, svcm *model.SvcModel) er } logging.Debug("Build script does not exist. Creating one.") - commitId, err := localcommit.Get(path) + commitId, err := info.CommitID() if err != nil { return errs.Wrap(err, "Unable to get the local commit ID") } diff --git a/internal/runbits/checker/checker.go b/internal/runbits/checker/checker.go index 482acc9f0e..433680dbba 100644 --- a/internal/runbits/checker/checker.go +++ b/internal/runbits/checker/checker.go @@ -8,7 +8,7 @@ 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/pkg/checkoutinfo" "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" "github.com/ActiveState/cli/pkg/project" @@ -16,8 +16,8 @@ import ( // RunCommitsBehindNotifier checks for the commits behind count based on the // provided project and displays the results to the user in a helpful manner. -func RunCommitsBehindNotifier(p *project.Project, out output.Outputer, auth *authentication.Auth) { - count, err := CommitsBehind(p, auth) +func RunCommitsBehindNotifier(p *project.Project, out output.Outputer, auth *authentication.Auth, info *checkoutinfo.CheckoutInfo) { + count, err := CommitsBehind(p, auth, info) if err != nil { if errors.Is(err, model.ErrCommitCountUnknowable) { out.Notice(output.Title(locale.Tr("runtime_update_notice_unknown_count"))) @@ -35,7 +35,7 @@ func RunCommitsBehindNotifier(p *project.Project, out output.Outputer, auth *aut } } -func CommitsBehind(p *project.Project, auth *authentication.Auth) (int, error) { +func CommitsBehind(p *project.Project, auth *authentication.Auth, info *checkoutinfo.CheckoutInfo) (int, error) { if p.IsHeadless() { return 0, nil } @@ -49,9 +49,9 @@ func CommitsBehind(p *project.Project, auth *authentication.Auth) (int, error) { return 0, locale.NewError("err_latest_commit", "Latest commit ID is nil") } - commitID, err := localcommit.Get(p.Dir()) + commitID, err := info.CommitID() if err != nil { - return 0, errs.Wrap(err, "Unable to get local commit") + return 0, errs.Wrap(err, "Unable to get commit ID") } return model.CommitsBehind(*latestCommitID, commitID, auth) diff --git a/internal/runbits/checkout/checkout.go b/internal/runbits/checkout/checkout.go index 5c505f4cc4..f6c1fe41aa 100644 --- a/internal/runbits/checkout/checkout.go +++ b/internal/runbits/checkout/checkout.go @@ -14,7 +14,6 @@ import ( "github.com/ActiveState/cli/internal/language" "github.com/ActiveState/cli/internal/osutils" "github.com/ActiveState/cli/internal/runbits/git" - "github.com/ActiveState/cli/pkg/localcommit" "github.com/ActiveState/cli/pkg/platform/api/mono/mono_models" "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" @@ -28,6 +27,7 @@ type primeable interface { primer.Configurer primer.Auther primer.SvcModeler + primer.CheckoutInfoer } // Checkout will checkout the given platform project at the given path @@ -99,7 +99,7 @@ func (r *Checkout) Run(ns *project.Namespaced, branchName, cachePath, targetPath } if r.prime.Config().GetBool(constants.OptinBuildscriptsConfig) { - if err := buildscript_runbit.Initialize(path, r.prime.Auth(), r.prime.SvcModel()); err != nil { + if err := buildscript_runbit.Initialize(path, r.prime.Auth(), r.prime.SvcModel(), r.prime.CheckoutInfo()); err != nil { return "", errs.Wrap(err, "Unable to initialize buildscript") } } @@ -184,6 +184,7 @@ func CreateProjectFiles(checkoutPath, cachePath, owner, name, branch, commitID, Owner: owner, Project: name, // match case on the Platform BranchName: branch, + CommitID: commitID, Directory: checkoutPath, Language: language, Cache: cachePath, @@ -196,10 +197,6 @@ func CreateProjectFiles(checkoutPath, cachePath, owner, name, branch, commitID, } } - if err := localcommit.Set(checkoutPath, commitID); err != nil { - return errs.Wrap(err, "Could not create local commit file") - } - return nil } diff --git a/internal/runbits/commits_runbit/time.go b/internal/runbits/commits_runbit/time.go index 2c2ec60d59..b719617d05 100644 --- a/internal/runbits/commits_runbit/time.go +++ b/internal/runbits/commits_runbit/time.go @@ -6,7 +6,7 @@ import ( "github.com/ActiveState/cli/internal/captain" "github.com/ActiveState/cli/internal/errs" "github.com/ActiveState/cli/pkg/buildscript" - "github.com/ActiveState/cli/pkg/localcommit" + "github.com/ActiveState/cli/pkg/checkoutinfo" "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" "github.com/ActiveState/cli/pkg/project" @@ -40,14 +40,14 @@ func ExpandTime(ts *captain.TimeValue, auth *authentication.Auth) (time.Time, er // ExpandTimeForProject is the same as ExpandTime except that it ensures the returned time is either the same or // later than that of the most recent commit. -func ExpandTimeForProject(ts *captain.TimeValue, auth *authentication.Auth, proj *project.Project) (time.Time, error) { +func ExpandTimeForProject(ts *captain.TimeValue, auth *authentication.Auth, proj *project.Project, info *checkoutinfo.CheckoutInfo) (time.Time, error) { timestamp, err := ExpandTime(ts, auth) if err != nil { return time.Time{}, errs.Wrap(err, "Unable to expand time") } if proj != nil { - commitID, err := localcommit.Get(proj.Dir()) + commitID, err := info.CommitID() if err != nil { return time.Time{}, errs.Wrap(err, "Unable to get commit ID") } diff --git a/internal/runbits/reqop_runbit/update.go b/internal/runbits/reqop_runbit/update.go index 395f4797c7..295e6a4911 100644 --- a/internal/runbits/reqop_runbit/update.go +++ b/internal/runbits/reqop_runbit/update.go @@ -33,6 +33,7 @@ type primeable interface { primer.Configurer primer.Analyticer primer.SvcModeler + primer.CheckoutInfoer } type requirements []*Requirement diff --git a/internal/runbits/runtime/runtime.go b/internal/runbits/runtime/runtime.go index 8a1256ed99..b28ba2d89c 100644 --- a/internal/runbits/runtime/runtime.go +++ b/internal/runbits/runtime/runtime.go @@ -23,7 +23,6 @@ import ( "github.com/ActiveState/cli/internal/runbits/runtime/progress" "github.com/ActiveState/cli/internal/runbits/runtime/trigger" "github.com/ActiveState/cli/pkg/buildplan" - "github.com/ActiveState/cli/pkg/localcommit" "github.com/ActiveState/cli/pkg/platform/model" bpModel "github.com/ActiveState/cli/pkg/platform/model/buildplanner" "github.com/ActiveState/cli/pkg/project" @@ -105,6 +104,7 @@ type primeable interface { primer.Configurer primer.SvcModeler primer.Analyticer + primer.CheckoutInfoer } func Update( @@ -147,7 +147,7 @@ func Update( commitID = opts.Commit.CommitID } if commitID == "" { - commitID, err = localcommit.Get(proj.Dir()) + commitID, err = prime.CheckoutInfo().CommitID() if err != nil { return nil, errs.Wrap(err, "Failed to get local commit") } @@ -169,7 +169,7 @@ func Update( } }() - rtHash, err := runtime_helpers.Hash(proj, &commitID) + rtHash, err := runtime_helpers.Hash(prime, &commitID) if err != nil { ah.fire(anaConsts.CatRuntimeDebug, anaConsts.ActRuntimeCache, nil) return nil, errs.Wrap(err, "Failed to get runtime hash") diff --git a/internal/runners/activate/activate.go b/internal/runners/activate/activate.go index 1cf3c2f389..d96c121b51 100644 --- a/internal/runners/activate/activate.go +++ b/internal/runners/activate/activate.go @@ -28,7 +28,6 @@ import ( "github.com/ActiveState/cli/internal/runbits/runtime/trigger" "github.com/ActiveState/cli/internal/subshell" "github.com/ActiveState/cli/internal/virtualenvironment" - "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" @@ -66,6 +65,7 @@ type primeable interface { primer.Configurer primer.SvcModeler primer.Analyticer + primer.CheckoutInfoer } func NewActivate(prime primeable) *Activate { @@ -146,9 +146,9 @@ func (r *Activate) Run(params *ActivateParams) (rerr error) { } if proj != nil { - commitID, err := localcommit.Get(proj.Dir()) + commitID, err := r.prime.CheckoutInfo().CommitID() if err != nil { - return errs.Wrap(err, "Unable to get local commit") + return errs.Wrap(err, "Unable to get commit ID") } if cid := params.Namespace.CommitID; cid != nil && *cid != commitID { return locale.NewInputError("err_activate_commit_id_mismatch") @@ -196,9 +196,9 @@ func (r *Activate) Run(params *ActivateParams) (rerr error) { } } - commitID, err := localcommit.Get(proj.Dir()) + commitID, err := r.prime.CheckoutInfo().CommitID() if err != nil { - return errs.Wrap(err, "Unable to get local commit") + return errs.Wrap(err, "Unable to get commit ID") } if commitID == "" { err := locale.NewInputError("err_project_no_commit", "Your project does not have a commit ID. Please run [ACTIONIABLE]'state push'[/RESET] first.", model.ProjectURL(proj.Owner(), proj.Name(), "")) diff --git a/internal/runners/artifacts/artifacts.go b/internal/runners/artifacts/artifacts.go index 078d2668a1..57d1d08ed8 100644 --- a/internal/runners/artifacts/artifacts.go +++ b/internal/runners/artifacts/artifacts.go @@ -31,6 +31,7 @@ type primeable interface { primer.SvcModeler primer.Configurer primer.Analyticer + primer.CheckoutInfoer } type Params struct { diff --git a/internal/runners/branch/add.go b/internal/runners/branch/add.go index a7af6e3c74..3d2801b177 100644 --- a/internal/runners/branch/add.go +++ b/internal/runners/branch/add.go @@ -6,13 +6,13 @@ import ( "github.com/ActiveState/cli/internal/logging" "github.com/ActiveState/cli/internal/output" "github.com/ActiveState/cli/internal/runbits/rationalize" - "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" ) type Add struct { + prime primeable out output.Outputer project *project.Project auth *authentication.Auth @@ -24,6 +24,7 @@ type AddParams struct { func NewAdd(prime primeable) *Add { return &Add{ + prime: prime, out: prime.Output(), project: prime.Project(), auth: prime.Auth(), @@ -53,9 +54,9 @@ func (a *Add) Run(params AddParams) error { return locale.WrapError(err, "err_fetch_branch", "", localBranch) } - commitID, err := localcommit.Get(a.project.Dir()) + commitID, err := a.prime.CheckoutInfo().CommitID() if err != nil { - return errs.Wrap(err, "Unable to get local commit") + return errs.Wrap(err, "Unable to get commit ID") } err = model.UpdateBranchTracking(branchID, commitID, branch.BranchID, model.TrackingIgnore, a.auth) diff --git a/internal/runners/branch/list.go b/internal/runners/branch/list.go index e60fdad106..b02cb00b3f 100644 --- a/internal/runners/branch/list.go +++ b/internal/runners/branch/list.go @@ -17,6 +17,7 @@ type primeable interface { primer.Configurer primer.Analyticer primer.SvcModeler + primer.CheckoutInfoer } type List struct { diff --git a/internal/runners/checkout/checkout.go b/internal/runners/checkout/checkout.go index 576dcbd453..f7988b622b 100644 --- a/internal/runners/checkout/checkout.go +++ b/internal/runners/checkout/checkout.go @@ -23,7 +23,6 @@ import ( "github.com/ActiveState/cli/internal/runbits/runtime/trigger" "github.com/ActiveState/cli/internal/subshell" "github.com/ActiveState/cli/pkg/buildplan" - "github.com/ActiveState/cli/pkg/localcommit" "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" bpModel "github.com/ActiveState/cli/pkg/platform/model/buildplanner" @@ -48,6 +47,7 @@ type primeable interface { primer.SvcModeler primer.Analyticer primer.Projecter + primer.CheckoutInfoer } type Checkout struct { @@ -142,7 +142,7 @@ func (u *Checkout) Run(params *Params) (rerr error) { var buildPlan *buildplan.BuildPlan rtOpts := []runtime_runbit.SetOpt{} if archive == nil { - commitID, err := localcommit.Get(proj.Path()) + commitID, err := u.prime.CheckoutInfo().CommitID() if err != nil { return errs.Wrap(err, "Could not get local commit") } diff --git a/internal/runners/commit/commit.go b/internal/runners/commit/commit.go index d0edf547d6..8999c9c61b 100644 --- a/internal/runners/commit/commit.go +++ b/internal/runners/commit/commit.go @@ -12,7 +12,6 @@ import ( "github.com/ActiveState/cli/internal/runbits/cves" "github.com/ActiveState/cli/internal/runbits/dependencies" "github.com/ActiveState/cli/internal/runbits/rationalize" - "github.com/ActiveState/cli/pkg/localcommit" bpResp "github.com/ActiveState/cli/pkg/platform/api/buildplanner/response" "github.com/ActiveState/cli/pkg/platform/model/buildplanner" ) @@ -25,6 +24,7 @@ type primeable interface { primer.SvcModeler primer.Configurer primer.Prompter + primer.CheckoutInfoer } type Commit struct { @@ -79,9 +79,9 @@ func (c *Commit) Run() (rerr error) { } // Get equivalent build script for current state of the project - localCommitID, err := localcommit.Get(proj.Dir()) + localCommitID, err := c.prime.CheckoutInfo().CommitID() if err != nil { - return errs.Wrap(err, "Unable to get local commit ID") + return errs.Wrap(err, "Unable to get commit ID") } bp := buildplanner.NewBuildPlannerModel(c.prime.Auth(), c.prime.SvcModel()) remoteScript, err := bp.GetBuildScript(localCommitID.String()) @@ -117,8 +117,8 @@ func (c *Commit) Run() (rerr error) { } // Update local commit ID - if err := localcommit.Set(proj.Dir(), stagedCommit.CommitID.String()); err != nil { - return errs.Wrap(err, "Could not set local commit ID") + if err := c.prime.CheckoutInfo().SetCommitID(stagedCommit.CommitID); err != nil { + return errs.Wrap(err, "Could not set commit ID") } // Update our local build expression to match the committed one. This allows our API a way to ensure forward compatibility. diff --git a/internal/runners/cve/cve.go b/internal/runners/cve/cve.go index 20f6e51116..fcc550fcf8 100644 --- a/internal/runners/cve/cve.go +++ b/internal/runners/cve/cve.go @@ -12,7 +12,6 @@ import ( "github.com/ActiveState/cli/internal/output" "github.com/ActiveState/cli/internal/primer" "github.com/ActiveState/cli/internal/runbits/rationalize" - "github.com/ActiveState/cli/pkg/localcommit" medmodel "github.com/ActiveState/cli/pkg/platform/api/mediator/model" "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" @@ -23,12 +22,14 @@ type primeable interface { primer.Projecter primer.Auther primer.Outputer + primer.CheckoutInfoer } type Cve struct { - proj *project.Project - auth *authentication.Auth - out output.Outputer + prime primeable + proj *project.Project + auth *authentication.Auth + out output.Outputer } type CveInfo struct { @@ -38,7 +39,7 @@ type CveInfo struct { } func NewCve(prime primeable) *Cve { - return &Cve{prime.Project(), prime.Auth(), prime.Output()} + return &Cve{prime, prime.Project(), prime.Auth(), prime.Output()} } type Params struct { @@ -115,9 +116,9 @@ func (r *Cve) fetchVulnerabilities(namespaceOverride project.Namespaced) (*medmo commitID = namespaceOverride.CommitID.String() } else { var err error - commitUUID, err := localcommit.Get(r.proj.Dir()) + commitUUID, err := r.prime.CheckoutInfo().CommitID() if err != nil { - return nil, errs.Wrap(err, "Unable to get local commit") + return nil, errs.Wrap(err, "Unable to get commit ID") } commitID = commitUUID.String() } diff --git a/internal/runners/deploy/deploy.go b/internal/runners/deploy/deploy.go index b69ac6587b..3267c5fb98 100644 --- a/internal/runners/deploy/deploy.go +++ b/internal/runners/deploy/deploy.go @@ -71,6 +71,7 @@ type primeable interface { primer.Analyticer primer.SvcModeler primer.Projecter + primer.CheckoutInfoer } func NewDeploy(step Step, prime primeable) *Deploy { diff --git a/internal/runners/deploy/uninstall/uninstall.go b/internal/runners/deploy/uninstall/uninstall.go index fb158bb9cd..93993cdc34 100644 --- a/internal/runners/deploy/uninstall/uninstall.go +++ b/internal/runners/deploy/uninstall/uninstall.go @@ -20,7 +20,7 @@ import ( "github.com/ActiveState/cli/internal/runbits/runtime/trigger" "github.com/ActiveState/cli/internal/subshell" "github.com/ActiveState/cli/internal/subshell/sscommon" - "github.com/ActiveState/cli/pkg/localcommit" + "github.com/ActiveState/cli/pkg/checkoutinfo" "github.com/ActiveState/cli/pkg/project" "github.com/ActiveState/cli/pkg/projectfile" ) @@ -85,7 +85,7 @@ func (u *Uninstall) Run(params *Params) error { return locale.WrapError(err, "err_deploy_uninstall_cannot_read_project", "Cannot read project at '{{.V0}}'", path) } - commitID, err := localcommit.Get(path) + commitID, err := checkoutinfo.New(proj.Source()).CommitID() if err != nil { return locale.WrapError(err, "err_deploy_uninstall_cannot_read_commit", "Cannot read commit ID from project at '{{.V0}}'", path) } diff --git a/internal/runners/eval/eval.go b/internal/runners/eval/eval.go index d55d00b2c2..f7d5d64a46 100644 --- a/internal/runners/eval/eval.go +++ b/internal/runners/eval/eval.go @@ -7,7 +7,6 @@ import ( "github.com/ActiveState/cli/internal/output" "github.com/ActiveState/cli/internal/primer" "github.com/ActiveState/cli/internal/runbits/rationalize" - "github.com/ActiveState/cli/pkg/localcommit" "github.com/ActiveState/cli/pkg/platform/model/buildplanner" ) @@ -16,6 +15,7 @@ type primeable interface { primer.Auther primer.Projecter primer.SvcModeler + primer.CheckoutInfoer } type Params struct { @@ -49,7 +49,7 @@ func (e *Eval) Run(params *Params) (rerr error) { return rationalize.ErrNoProject } - commitID, err := localcommit.Get(proj.Dir()) + commitID, err := e.prime.CheckoutInfo().CommitID() if err != nil { return errs.Wrap(err, "Unable to get commit ID") } diff --git a/internal/runners/exec/exec.go b/internal/runners/exec/exec.go index 6ddca60d0a..932f54c9dd 100644 --- a/internal/runners/exec/exec.go +++ b/internal/runners/exec/exec.go @@ -62,6 +62,7 @@ type primeable interface { primer.Configurer primer.Analyticer primer.SvcModeler + primer.CheckoutInfoer } type Params struct { diff --git a/internal/runners/export/deptree/artifacts.go b/internal/runners/export/deptree/artifacts.go index f750bb4eb1..4f348bba4f 100644 --- a/internal/runners/export/deptree/artifacts.go +++ b/internal/runners/export/deptree/artifacts.go @@ -24,6 +24,7 @@ type primeable interface { primer.Projecter primer.Analyticer primer.SvcModeler + primer.CheckoutInfoer } type ArtifactParams struct { diff --git a/internal/runners/export/deptree/common.go b/internal/runners/export/deptree/common.go index 865bbef076..32d71e889e 100644 --- a/internal/runners/export/deptree/common.go +++ b/internal/runners/export/deptree/common.go @@ -5,7 +5,6 @@ import ( "github.com/ActiveState/cli/internal/errs" "github.com/ActiveState/cli/internal/locale" "github.com/ActiveState/cli/internal/runbits/rationalize" - "github.com/ActiveState/cli/pkg/localcommit" "github.com/ActiveState/cli/pkg/platform/model" "github.com/ActiveState/cli/pkg/project" "github.com/go-openapi/strfmt" @@ -42,9 +41,9 @@ func resolveNamespace(inputNs *project.Namespaced, inputCommitID string, prime p ns.CommitID = branch.CommitID } else { var err error - commitID, err = localcommit.Get(proj.Dir()) + commitID, err = prime.CheckoutInfo().CommitID() if err != nil { - return nil, errs.Wrap(err, "Unable to get local commit ID") + return nil, errs.Wrap(err, "Unable to get commit ID ID") } ns.CommitID = &commitID } diff --git a/internal/runners/export/export.go b/internal/runners/export/export.go index 34e425b46a..651383247e 100644 --- a/internal/runners/export/export.go +++ b/internal/runners/export/export.go @@ -13,6 +13,7 @@ type primeable interface { primer.Projecter primer.Analyticer primer.SvcModeler + primer.CheckoutInfoer } type Export struct{} diff --git a/internal/runners/hello/hello_example.go b/internal/runners/hello/hello_example.go index a13ee016c3..7e1d16ea0a 100644 --- a/internal/runners/hello/hello_example.go +++ b/internal/runners/hello/hello_example.go @@ -16,7 +16,6 @@ import ( "github.com/ActiveState/cli/internal/primer" "github.com/ActiveState/cli/internal/runbits/example" "github.com/ActiveState/cli/internal/runbits/rationalize" - "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" @@ -27,6 +26,7 @@ type primeable interface { primer.Outputer primer.Auther primer.Projecter + primer.CheckoutInfoer } // Params defines the parameters needed to execute a given runner. These @@ -48,6 +48,7 @@ func NewParams() *Params { // Hello defines the app-level dependencies that are accessible within the Run // function. type Hello struct { + prime primeable out output.Outputer project *project.Project auth *authentication.Auth @@ -57,6 +58,7 @@ type Hello struct { // implementation of primeable. func New(p primeable) *Hello { return &Hello{ + prime: p, out: p.Output(), project: p.Project(), auth: p.Auth(), @@ -121,7 +123,7 @@ func (h *Hello) Run(params *Params) (rerr error) { } // Grab data from the platform. - commitMsg, err := currentCommitMessage(h.project, h.auth) + commitMsg, err := currentCommitMessage(h.prime) if err != nil { err = errs.Wrap( err, "Cannot get commit message", @@ -145,12 +147,16 @@ func (h *Hello) Run(params *Params) (rerr error) { // is obtained. Since it is a sort of construction function that has some // complexity, it is helpful to provide localized error context. Secluding this // sort of logic is helpful to keep the subhandlers clean. -func currentCommitMessage(proj *project.Project, auth *authentication.Auth) (string, error) { +func currentCommitMessage(prime primeable) (string, error) { + proj := prime.Project() + auth := prime.Auth() + info := prime.CheckoutInfo() + if proj == nil { return "", errs.New("Cannot determine which project to use") } - commitId, err := localcommit.Get(proj.Dir()) + commitId, err := info.CommitID() if err != nil { return "", errs.Wrap(err, "Cannot determine which commit to use") } diff --git a/internal/runners/history/history.go b/internal/runners/history/history.go index 6d27e4f396..bf77a29023 100644 --- a/internal/runners/history/history.go +++ b/internal/runners/history/history.go @@ -8,7 +8,6 @@ import ( "github.com/ActiveState/cli/internal/output" "github.com/ActiveState/cli/internal/primer" "github.com/ActiveState/cli/internal/runbits/commit" - "github.com/ActiveState/cli/pkg/localcommit" "github.com/ActiveState/cli/pkg/platform/api/mono/mono_models" "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" @@ -19,9 +18,11 @@ type primeable interface { primer.Projecter primer.Outputer primer.Auther + primer.CheckoutInfoer } type History struct { + prime primeable project *project.Project out output.Outputer auth *authentication.Auth @@ -29,6 +30,7 @@ type History struct { func NewHistory(prime primeable) *History { return &History{ + prime, prime.Project(), prime.Output(), prime.Auth(), @@ -44,9 +46,9 @@ func (h *History) Run(params *HistoryParams) error { } h.out.Notice(locale.Tr("operating_message", h.project.NamespaceString(), h.project.Dir())) - localCommitID, err := localcommit.Get(h.project.Dir()) + localCommitID, err := h.prime.CheckoutInfo().CommitID() if err != nil { - return errs.Wrap(err, "Unable to get local commit") + return errs.Wrap(err, "Unable to get commit ID") } if h.project.IsHeadless() { diff --git a/internal/runners/initialize/init.go b/internal/runners/initialize/init.go index 85ecd17d1f..c8f397547f 100644 --- a/internal/runners/initialize/init.go +++ b/internal/runners/initialize/init.go @@ -25,7 +25,7 @@ import ( "github.com/ActiveState/cli/internal/runbits/rationalize" "github.com/ActiveState/cli/internal/runbits/runtime" "github.com/ActiveState/cli/internal/runbits/runtime/trigger" - "github.com/ActiveState/cli/pkg/localcommit" + "github.com/ActiveState/cli/pkg/checkoutinfo" "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" bpModel "github.com/ActiveState/cli/pkg/platform/model/buildplanner" @@ -70,6 +70,7 @@ type primeable interface { primer.Analyticer primer.SvcModeler primer.Projecter + primer.CheckoutInfoer } type errProjectExists struct { @@ -108,9 +109,9 @@ func inferLanguage(config projectfile.ConfigGetter, auth *authentication.Auth) ( if err != nil { return "", "", false } - commitID, err := localcommit.Get(defaultProj.Dir()) + commitID, err := checkoutinfo.New(defaultProj.Source()).CommitID() if err != nil { - multilog.Error("Unable to get local commit: %v", errs.JoinMessage(err)) + multilog.Error("Unable to get commit ID: %v", errs.JoinMessage(err)) return "", "", false } if commitID == "" { @@ -276,12 +277,12 @@ func (r *Initialize) Run(params *RunParams) (rerr error) { return errs.Wrap(err, "Could not create project") } - if err := localcommit.Set(proj.Dir(), commitID.String()); err != nil { + if err := r.prime.CheckoutInfo().SetCommitID(commitID); err != nil { return errs.Wrap(err, "Unable to create local commit file") } if r.config.GetBool(constants.OptinBuildscriptsConfig) { - if err := buildscript_runbit.Initialize(proj.Dir(), r.auth, r.svcModel); err != nil { + if err := buildscript_runbit.Initialize(proj.Dir(), r.auth, r.svcModel, r.prime.CheckoutInfo()); err != nil { return errs.Wrap(err, "Unable to initialize buildscript") } } diff --git a/internal/runners/install/install.go b/internal/runners/install/install.go index f0b4ce3b86..ba10b36b31 100644 --- a/internal/runners/install/install.go +++ b/internal/runners/install/install.go @@ -21,7 +21,6 @@ import ( "github.com/ActiveState/cli/internal/runbits/runtime/trigger" "github.com/ActiveState/cli/internal/sliceutils" "github.com/ActiveState/cli/pkg/buildscript" - "github.com/ActiveState/cli/pkg/localcommit" "github.com/ActiveState/cli/pkg/platform/api/buildplanner/types" "github.com/ActiveState/cli/pkg/platform/model" bpModel "github.com/ActiveState/cli/pkg/platform/model/buildplanner" @@ -35,6 +34,7 @@ type primeable interface { primer.Configurer primer.Analyticer primer.SvcModeler + primer.CheckoutInfoer } // Params tracks the info required for running Install. @@ -118,9 +118,9 @@ func (i *Install) Run(params Params) (rerr error) { pg = output.StartSpinner(out, locale.T("progress_search"), constants.TerminalAnimationInterval) // Grab local commit info - localCommitID, err := localcommit.Get(i.prime.Project().Dir()) + localCommitID, err := i.prime.CheckoutInfo().CommitID() if err != nil { - return errs.Wrap(err, "Unable to get local commit") + return errs.Wrap(err, "Unable to get commit ID") } oldCommit, err = bp.FetchCommit(localCommitID, pj.Owner(), pj.Name(), nil) if err != nil { diff --git a/internal/runners/languages/languages.go b/internal/runners/languages/languages.go index 5e9658f04f..07a06a2ae4 100644 --- a/internal/runners/languages/languages.go +++ b/internal/runners/languages/languages.go @@ -10,7 +10,6 @@ import ( "github.com/ActiveState/cli/internal/primer" "github.com/ActiveState/cli/internal/runbits/rationalize" "github.com/ActiveState/cli/pkg/buildplan" - "github.com/ActiveState/cli/pkg/localcommit" "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" bpModel "github.com/ActiveState/cli/pkg/platform/model/buildplanner" @@ -25,10 +24,12 @@ type primeable interface { primer.Configurer primer.Analyticer primer.SvcModeler + primer.CheckoutInfoer } // Languages manages the listing execution context. type Languages struct { + prime primeable out output.Outputer project *project.Project analytics analytics.Dispatcher @@ -40,6 +41,7 @@ type Languages struct { // NewLanguages prepares a list execution context for use. func NewLanguages(prime primeable) *Languages { return &Languages{ + prime, prime.Output(), prime.Project(), prime.Analytics(), @@ -68,7 +70,7 @@ func (l *Languages) Run() error { return rationalize.ErrNoProject } - commitID, err := localcommit.Get(l.project.Dir()) + commitID, err := l.prime.CheckoutInfo().CommitID() if err != nil { return errs.AddTips( locale.WrapError( diff --git a/internal/runners/manifest/manifest.go b/internal/runners/manifest/manifest.go index 19765d7257..5c7cc84409 100644 --- a/internal/runners/manifest/manifest.go +++ b/internal/runners/manifest/manifest.go @@ -12,7 +12,6 @@ import ( "github.com/ActiveState/cli/internal/runbits/rationalize" "github.com/ActiveState/cli/pkg/buildplan" "github.com/ActiveState/cli/pkg/buildscript" - "github.com/ActiveState/cli/pkg/localcommit" "github.com/ActiveState/cli/pkg/platform/api/vulnerabilities/request" "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" @@ -27,6 +26,7 @@ type primeable interface { primer.Analyticer primer.SvcModeler primer.Configurer + primer.CheckoutInfoer } type Params struct { @@ -105,7 +105,7 @@ func (m *Manifest) fetchRequirements() ([]buildscript.Requirement, error) { return nil, errs.Wrap(err, "Could not get buildscript") } } else { - commitID, err := localcommit.Get(m.project.Dir()) + commitID, err := m.prime.CheckoutInfo().CommitID() if err != nil { return nil, errs.Wrap(err, "Could not get commit ID") } @@ -126,7 +126,7 @@ func (m *Manifest) fetchRequirements() ([]buildscript.Requirement, error) { } func (m *Manifest) fetchBuildplanRequirements() (buildplan.Ingredients, error) { - commitID, err := localcommit.Get(m.project.Dir()) + commitID, err := m.prime.CheckoutInfo().CommitID() if err != nil { return nil, errs.Wrap(err, "Failed to get local commit") } diff --git a/internal/runners/packages/import.go b/internal/runners/packages/import.go index ef7f4436ea..637eb02593 100644 --- a/internal/runners/packages/import.go +++ b/internal/runners/packages/import.go @@ -17,7 +17,6 @@ import ( runtime_runbit "github.com/ActiveState/cli/internal/runbits/runtime" "github.com/ActiveState/cli/internal/runbits/runtime/trigger" "github.com/ActiveState/cli/pkg/buildscript" - "github.com/ActiveState/cli/pkg/localcommit" "github.com/ActiveState/cli/pkg/platform/api" "github.com/ActiveState/cli/pkg/platform/api/buildplanner/types" "github.com/ActiveState/cli/pkg/platform/api/reqsimport" @@ -68,6 +67,7 @@ type primeable interface { primer.Configurer primer.Analyticer primer.SvcModeler + primer.CheckoutInfoer } // NewImport prepares an importation execution context for use. @@ -92,7 +92,7 @@ func (i *Import) Run(params *ImportRunParams) (rerr error) { params.FileName = defaultImportFile } - localCommitId, err := localcommit.Get(proj.Dir()) + localCommitId, err := i.prime.CheckoutInfo().CommitID() if err != nil { return locale.WrapError(err, "package_err_cannot_obtain_commit") } @@ -135,7 +135,7 @@ func (i *Import) Run(params *ImportRunParams) (rerr error) { }) // Always update the local commit ID even if the commit fails to build if stagedCommit != nil && stagedCommit.Commit != nil && stagedCommit.Commit.CommitID != "" { - if err := localcommit.Set(proj.Dir(), stagedCommit.CommitID.String()); err != nil { + if err := i.prime.CheckoutInfo().SetCommitID(stagedCommit.CommitID); err != nil { return locale.WrapError(err, "err_package_update_commit_id") } } diff --git a/internal/runners/packages/info.go b/internal/runners/packages/info.go index 2366cae3ff..d1b5527dbd 100644 --- a/internal/runners/packages/info.go +++ b/internal/runners/packages/info.go @@ -30,17 +30,19 @@ type InfoRunParams struct { // Info manages the information execution context. type Info struct { - out output.Outputer - proj *project.Project - auth *authentication.Auth + prime primeable + out output.Outputer + proj *project.Project + auth *authentication.Auth } // NewInfo prepares an information execution context for use. func NewInfo(prime primeable) *Info { return &Info{ - out: prime.Output(), - proj: prime.Project(), - auth: prime.Auth(), + prime: prime, + out: prime.Output(), + proj: prime.Project(), + auth: prime.Auth(), } } @@ -58,7 +60,7 @@ func (i *Info) Run(params InfoRunParams, nstype model.NamespaceType) error { } if nsTypeV != nil { - language, err := targetedLanguage(params.Language, i.proj, i.auth) + language, err := targetedLanguage(params.Language, i.prime) if err != nil { return locale.WrapError(err, fmt.Sprintf("%s_err_cannot_obtain_language", *nsTypeV)) } @@ -71,7 +73,7 @@ func (i *Info) Run(params InfoRunParams, nstype model.NamespaceType) error { normalized = params.Package.Name } - ts, err := commits_runbit.ExpandTimeForProject(¶ms.Timestamp, i.auth, i.proj) + ts, err := commits_runbit.ExpandTimeForProject(¶ms.Timestamp, i.auth, i.proj, i.prime.CheckoutInfo()) if err != nil { return errs.Wrap(err, "Unable to get timestamp from params") } diff --git a/internal/runners/packages/list.go b/internal/runners/packages/list.go index 4c39904eb9..f0538c97af 100644 --- a/internal/runners/packages/list.go +++ b/internal/runners/packages/list.go @@ -18,7 +18,6 @@ import ( "github.com/ActiveState/cli/internal/output" "github.com/ActiveState/cli/internal/rtutils/ptr" "github.com/ActiveState/cli/internal/runbits/rationalize" - "github.com/ActiveState/cli/pkg/localcommit" gqlModel "github.com/ActiveState/cli/pkg/platform/api/graphql/model" "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" @@ -34,6 +33,7 @@ type ListRunParams struct { // List manages the listing execution context. type List struct { + prime primeable out output.Outputer project *project.Project analytics analytics.Dispatcher @@ -45,6 +45,7 @@ type List struct { // NewList prepares a list execution context for use. func NewList(prime primeable) *List { return &List{ + prime: prime, out: prime.Output(), project: prime.Project(), analytics: prime.Analytics(), @@ -89,7 +90,7 @@ func (l *List) Run(params ListRunParams, nstype model.NamespaceType) error { return locale.WrapError(err, fmt.Sprintf("%s_err_cannot_obtain_commit", nstype)) } default: - commitID, err = targetFromProjectFile(l.project) + commitID, err = targetFromProjectFile(l.prime) if err != nil { return locale.WrapError(err, fmt.Sprintf("%s_err_cannot_obtain_commit", nstype)) } @@ -205,14 +206,17 @@ func targetFromProject(projectString string) (*strfmt.UUID, error) { return branch.CommitID, nil } -func targetFromProjectFile(proj *project.Project) (*strfmt.UUID, error) { +func targetFromProjectFile(prime primeable) (*strfmt.UUID, error) { + proj := prime.Project() + info := prime.CheckoutInfo() + logging.Debug("commit from project file") if proj == nil { return nil, rationalize.ErrNoProject } - commit, err := localcommit.Get(proj.Dir()) + commit, err := info.CommitID() if err != nil { - return nil, errs.Wrap(err, "Unable to get local commit") + return nil, errs.Wrap(err, "Unable to get commit ID") } if commit == "" { logging.Debug("latest commit used as fallback selection") diff --git a/internal/runners/packages/search.go b/internal/runners/packages/search.go index 6af93400cf..475d41ba4e 100644 --- a/internal/runners/packages/search.go +++ b/internal/runners/packages/search.go @@ -9,7 +9,6 @@ import ( "github.com/ActiveState/cli/internal/logging" "github.com/ActiveState/cli/internal/output" "github.com/ActiveState/cli/internal/runbits/commits_runbit" - "github.com/ActiveState/cli/pkg/localcommit" "github.com/ActiveState/cli/pkg/platform/api/vulnerabilities/request" "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" @@ -27,17 +26,19 @@ type SearchRunParams struct { // Search manages the searching execution context. type Search struct { - out output.Outputer - proj *project.Project - auth *authentication.Auth + prime primeable + out output.Outputer + proj *project.Project + auth *authentication.Auth } // NewSearch prepares a searching execution context for use. func NewSearch(prime primeable) *Search { return &Search{ - out: prime.Output(), - proj: prime.Project(), - auth: prime.Auth(), + prime: prime, + out: prime.Output(), + proj: prime.Project(), + auth: prime.Auth(), } } @@ -49,7 +50,7 @@ func (s *Search) Run(params SearchRunParams, nstype model.NamespaceType) error { var ns model.Namespace if params.Ingredient.Namespace == "" { - language, err := targetedLanguage(params.Language, s.proj, s.auth) + language, err := targetedLanguage(params.Language, s.prime) if err != nil { return locale.WrapError(err, fmt.Sprintf("%s_err_cannot_obtain_language", nstype)) } @@ -59,7 +60,7 @@ func (s *Search) Run(params SearchRunParams, nstype model.NamespaceType) error { ns = model.NewNamespaceRaw(params.Ingredient.Namespace) } - ts, err := commits_runbit.ExpandTimeForProject(¶ms.Timestamp, s.auth, s.proj) + ts, err := commits_runbit.ExpandTimeForProject(¶ms.Timestamp, s.auth, s.proj, s.prime.CheckoutInfo()) if err != nil { return errs.Wrap(err, "Unable to get timestamp from params") } @@ -113,7 +114,11 @@ func (s *Search) Run(params SearchRunParams, nstype model.NamespaceType) error { return nil } -func targetedLanguage(languageOpt string, proj *project.Project, auth *authentication.Auth) (string, error) { +func targetedLanguage(languageOpt string, prime primeable) (string, error) { + proj := prime.Project() + auth := prime.Auth() + info := prime.CheckoutInfo() + if languageOpt != "" { return languageOpt, nil } @@ -124,9 +129,9 @@ func targetedLanguage(languageOpt string, proj *project.Project, auth *authentic ) } - commitID, err := localcommit.Get(proj.Dir()) + commitID, err := info.CommitID() if err != nil { - return "", errs.Wrap(err, "Unable to get local commit") + return "", errs.Wrap(err, "Unable to get commit ID") } lang, err := model.LanguageByCommit(commitID, auth) if err != nil { diff --git a/internal/runners/platforms/add.go b/internal/runners/platforms/add.go index b4d8d5c253..5720aae78e 100644 --- a/internal/runners/platforms/add.go +++ b/internal/runners/platforms/add.go @@ -15,7 +15,6 @@ import ( "github.com/ActiveState/cli/internal/runbits/rationalizers" "github.com/ActiveState/cli/internal/runbits/reqop_runbit" "github.com/ActiveState/cli/internal/runbits/runtime/trigger" - "github.com/ActiveState/cli/pkg/localcommit" bpResp "github.com/ActiveState/cli/pkg/platform/api/buildplanner/response" "github.com/ActiveState/cli/pkg/platform/model" bpModel "github.com/ActiveState/cli/pkg/platform/model/buildplanner" @@ -39,6 +38,7 @@ type primeable interface { primer.Configurer primer.Analyticer primer.SvcModeler + primer.CheckoutInfoer } // NewAdd prepares an add execution context for use. @@ -72,9 +72,9 @@ func (a *Add) Run(params AddRunParams) (rerr error) { pg = output.StartSpinner(out, locale.T("progress_platform_search"), constants.TerminalAnimationInterval) // Grab local commit info - localCommitID, err := localcommit.Get(pj.Dir()) + localCommitID, err := a.prime.CheckoutInfo().CommitID() if err != nil { - return errs.Wrap(err, "Unable to get local commit") + return errs.Wrap(err, "Unable to get commit ID") } oldCommit, err := bp.FetchCommit(localCommitID, pj.Owner(), pj.Name(), nil) if err != nil { @@ -91,7 +91,7 @@ func (a *Add) Run(params AddRunParams) (rerr error) { pg = nil // Resolve timestamp, commit and languages used for current project. - ts, err := commits_runbit.ExpandTimeForProject(nil, a.prime.Auth(), pj) + ts, err := commits_runbit.ExpandTimeForProject(nil, a.prime.Auth(), pj, a.prime.CheckoutInfo()) if err != nil { return errs.Wrap(err, "Unable to get timestamp from params") } diff --git a/internal/runners/platforms/list.go b/internal/runners/platforms/list.go index 87027c2704..d8925aa15b 100644 --- a/internal/runners/platforms/list.go +++ b/internal/runners/platforms/list.go @@ -6,7 +6,6 @@ import ( "github.com/ActiveState/cli/internal/logging" "github.com/ActiveState/cli/internal/output" "github.com/ActiveState/cli/internal/runbits/rationalize" - "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" @@ -15,17 +14,19 @@ import ( // List manages the listing execution context. type List struct { - out output.Outputer - proj *project.Project - auth *authentication.Auth + prime primeable + out output.Outputer + proj *project.Project + auth *authentication.Auth } // NewList prepares a list execution context for use. func NewList(prime primeable) *List { return &List{ - out: prime.Output(), - proj: prime.Project(), - auth: prime.Auth(), + prime: prime, + out: prime.Output(), + proj: prime.Project(), + auth: prime.Auth(), } } @@ -37,9 +38,9 @@ func (l *List) Run() error { return rationalize.ErrNoProject } - commitID, err := localcommit.Get(l.proj.Dir()) + commitID, err := l.prime.CheckoutInfo().CommitID() if err != nil { - return errs.Wrap(err, "Unable to get local commit") + return errs.Wrap(err, "Unable to get commit ID") } targetCommitID, err := targetedCommitID(commitID.String(), l.proj.Name(), l.proj.Owner(), l.proj.BranchName()) diff --git a/internal/runners/platforms/remove.go b/internal/runners/platforms/remove.go index 85a56d33db..69f1b1a40d 100644 --- a/internal/runners/platforms/remove.go +++ b/internal/runners/platforms/remove.go @@ -13,7 +13,6 @@ import ( "github.com/ActiveState/cli/internal/runbits/rationalizers" "github.com/ActiveState/cli/internal/runbits/reqop_runbit" "github.com/ActiveState/cli/internal/runbits/runtime/trigger" - "github.com/ActiveState/cli/pkg/localcommit" bpResp "github.com/ActiveState/cli/pkg/platform/api/buildplanner/response" "github.com/ActiveState/cli/pkg/platform/model" bpModel "github.com/ActiveState/cli/pkg/platform/model/buildplanner" @@ -59,9 +58,9 @@ func (a *Remove) Run(params RemoveRunParams) (rerr error) { pg = output.StartSpinner(out, locale.T("progress_platforms"), constants.TerminalAnimationInterval) // Grab local commit info - localCommitID, err := localcommit.Get(pj.Dir()) + localCommitID, err := a.prime.CheckoutInfo().CommitID() if err != nil { - return errs.Wrap(err, "Unable to get local commit") + return errs.Wrap(err, "Unable to get commit ID") } oldCommit, err := bp.FetchCommit(localCommitID, pj.Owner(), pj.Name(), nil) if err != nil { diff --git a/internal/runners/prepare/prepare.go b/internal/runners/prepare/prepare.go index 4c097fba10..eeadd6b70c 100644 --- a/internal/runners/prepare/prepare.go +++ b/internal/runners/prepare/prepare.go @@ -37,10 +37,13 @@ type primeable interface { primer.Configurer primer.Analyticer primer.SvcModeler + primer.Projecter + primer.CheckoutInfoer } // Prepare manages the prepare execution context. type Prepare struct { + prime primeable out output.Outputer subshell subshell.SubShell cfg *config.Instance @@ -51,6 +54,7 @@ type Prepare struct { // New prepares a prepare execution context for use. func New(prime primeable) *Prepare { return &Prepare{ + prime: prime, out: prime.Output(), subshell: prime.Subshell(), cfg: prime.Config(), @@ -71,13 +75,14 @@ func (r *Prepare) resetExecutors() error { if err != nil { return errs.Wrap(err, "Could not get project from its directory") } + r.prime.SetProject(proj) rt, err := runtime_helpers.FromProject(proj) if err != nil { return errs.Wrap(err, "Could not initialize runtime for project.") } - rtHash, err := runtime_helpers.Hash(proj, nil) + rtHash, err := runtime_helpers.Hash(r.prime, nil) if err != nil { return errs.Wrap(err, "Could not get runtime hash") } diff --git a/internal/runners/pull/pull.go b/internal/runners/pull/pull.go index 0e9ea15c92..0b3b7c4313 100644 --- a/internal/runners/pull/pull.go +++ b/internal/runners/pull/pull.go @@ -21,7 +21,6 @@ import ( "github.com/ActiveState/cli/internal/runbits/rationalize" "github.com/ActiveState/cli/internal/runbits/runtime" "github.com/ActiveState/cli/internal/runbits/runtime/trigger" - "github.com/ActiveState/cli/pkg/localcommit" "github.com/ActiveState/cli/pkg/platform/api/buildplanner/types" "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" @@ -65,6 +64,7 @@ type primeable interface { primer.Analyticer primer.Configurer primer.SvcModeler + primer.CheckoutInfoer } func New(prime primeable) *Pull { @@ -124,9 +124,9 @@ func (p *Pull) Run(params *PullParams) (rerr error) { } var localCommit *strfmt.UUID - localCommitID, err := localcommit.Get(p.project.Dir()) + localCommitID, err := p.prime.CheckoutInfo().CommitID() if err != nil { - return errs.Wrap(err, "Unable to get local commit") + return errs.Wrap(err, "Unable to get commit ID") } if localCommitID != "" { localCommit = &localCommitID @@ -182,9 +182,9 @@ func (p *Pull) Run(params *PullParams) (rerr error) { p.notifyMergeStrategy(string(strategy), *localCommit, remoteProject) } - commitID, err := localcommit.Get(p.project.Dir()) + commitID, err := p.prime.CheckoutInfo().CommitID() if err != nil { - return errs.Wrap(err, "Unable to get local commit") + return errs.Wrap(err, "Unable to get commit ID") } if commitID != *resultingCommit { @@ -193,7 +193,7 @@ func (p *Pull) Run(params *PullParams) (rerr error) { if err != nil { var errBuildScriptMergeConflict *ErrBuildScriptMergeConflict if errors.As(err, &errBuildScriptMergeConflict) { - err2 := localcommit.Set(p.project.Dir(), remoteCommit.String()) + err2 := p.prime.CheckoutInfo().SetCommitID(*remoteCommit) if err2 != nil { err = errs.Pack(err, errs.Wrap(err2, "Could not set local commit to remote commit after build script merge conflict")) } @@ -202,7 +202,7 @@ func (p *Pull) Run(params *PullParams) (rerr error) { } } - err := localcommit.Set(p.project.Dir(), resultingCommit.String()) + err := p.prime.CheckoutInfo().SetCommitID(*resultingCommit) if err != nil { return errs.Wrap(err, "Unable to set local commit") } diff --git a/internal/runners/push/push.go b/internal/runners/push/push.go index df61f99e2f..92a0450b63 100644 --- a/internal/runners/push/push.go +++ b/internal/runners/push/push.go @@ -12,7 +12,6 @@ import ( "github.com/ActiveState/cli/internal/prompt" "github.com/ActiveState/cli/internal/rtutils/ptr" "github.com/ActiveState/cli/internal/runbits/rationalize" - "github.com/ActiveState/cli/pkg/localcommit" "github.com/ActiveState/cli/pkg/platform/api/buildplanner/types" "github.com/ActiveState/cli/pkg/platform/api/mono/mono_models" "github.com/ActiveState/cli/pkg/platform/authentication" @@ -48,6 +47,7 @@ type primeable interface { primer.Prompter primer.Auther primer.SvcModeler + primer.CheckoutInfoer } func NewPush(prime primeable) *Push { @@ -93,10 +93,10 @@ func (r *Push) Run(params PushParams) (rerr error) { } r.out.Notice(locale.Tr("operating_message", r.project.NamespaceString(), r.project.Dir())) - commitID, err := localcommit.Get(r.project.Dir()) // The commit we want to push + commitID, err := r.prime.CheckoutInfo().CommitID() // 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") + return errs.Wrap(err, "Unable to get commit ID") } // Detect target namespace if possible @@ -198,7 +198,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 := r.prime.CheckoutInfo().SetCommitID(commitID); err != nil { return errs.Wrap(err, "Unable to create local commit file") } @@ -285,9 +285,9 @@ func (r *Push) verifyInput() error { return rationalize.ErrNoProject } - commitID, err := localcommit.Get(r.project.Dir()) + commitID, err := r.prime.CheckoutInfo().CommitID() if err != nil { - return errs.Wrap(err, "Unable to get local commit") + return errs.Wrap(err, "Unable to get commit ID") } if commitID == "" { return errNoCommit @@ -323,9 +323,9 @@ func (r *Push) promptNamespace() (*project.Namespaced, error) { } var name string - commitID, err := localcommit.Get(r.project.Dir()) + commitID, err := r.prime.CheckoutInfo().CommitID() if err != nil { - return nil, errs.Wrap(err, "Unable to get local commit") + return nil, errs.Wrap(err, "Unable to get commit ID") } if lang, err := model.FetchLanguageForCommit(commitID, r.auth); err == nil { name = lang.Name diff --git a/internal/runners/refresh/refresh.go b/internal/runners/refresh/refresh.go index 1a25a6b594..bee1c0bec0 100644 --- a/internal/runners/refresh/refresh.go +++ b/internal/runners/refresh/refresh.go @@ -36,6 +36,7 @@ type primeable interface { primer.SvcModeler primer.Analyticer primer.Projecter + primer.CheckoutInfoer } type Refresh struct { @@ -79,7 +80,7 @@ func (r *Refresh) Run(params *Params) error { r.out.Notice(locale.Tr("operating_message", proj.NamespaceString(), proj.Dir())) - needsUpdate, err := runtime_helpers.NeedsUpdate(proj, nil) + needsUpdate, err := runtime_helpers.NeedsUpdate(r.prime, nil) if err != nil { return errs.Wrap(err, "could not determine if runtime needs update") } diff --git a/internal/runners/reset/reset.go b/internal/runners/reset/reset.go index 0e2b5c89fb..c68dc6ecfc 100644 --- a/internal/runners/reset/reset.go +++ b/internal/runners/reset/reset.go @@ -16,7 +16,7 @@ import ( "github.com/ActiveState/cli/internal/runbits/rationalize" "github.com/ActiveState/cli/internal/runbits/runtime" "github.com/ActiveState/cli/internal/runbits/runtime/trigger" - "github.com/ActiveState/cli/pkg/localcommit" + "github.com/ActiveState/cli/pkg/checkoutinfo" "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" "github.com/ActiveState/cli/pkg/project" @@ -52,6 +52,7 @@ type primeable interface { primer.Configurer primer.Analyticer primer.SvcModeler + primer.CheckoutInfoer } func New(prime primeable) *Reset { @@ -80,10 +81,10 @@ 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()) - var errInvalidCommitID *localcommit.ErrInvalidCommitID + localCommitID, err := r.prime.CheckoutInfo().CommitID() + var errInvalidCommitID *checkoutinfo.ErrInvalidCommitID if err != nil && !errors.As(err, &errInvalidCommitID) { - return errs.Wrap(err, "Unable to get local commit") + return errs.Wrap(err, "Unable to get commit ID") } if *latestCommit == localCommitID { return locale.NewInputError("err_reset_latest", "You are already on the latest commit") @@ -91,9 +92,9 @@ func (r *Reset) Run(params *Params) error { commitID = *latestCommit case strings.EqualFold(params.CommitID, local): - localCommitID, err := localcommit.Get(r.project.Dir()) + localCommitID, err := r.prime.CheckoutInfo().CommitID() if err != nil { - return errs.Wrap(err, "Unable to get local commit") + return errs.Wrap(err, "Unable to get commit ID") } commitID = localCommitID @@ -109,10 +110,10 @@ func (r *Reset) Run(params *Params) error { } } - localCommitID, err := localcommit.Get(r.project.Dir()) - var errInvalidCommitID *localcommit.ErrInvalidCommitID + localCommitID, err := r.prime.CheckoutInfo().CommitID() + var errInvalidCommitID *checkoutinfo.ErrInvalidCommitID if err != nil && !errors.As(err, &errInvalidCommitID) { - return errs.Wrap(err, "Unable to get local commit") + return errs.Wrap(err, "Unable to get commit ID") } r.out.Notice(locale.Tl("reset_commit", "Your project will be reset to [ACTIONABLE]{{.V0}}[/RESET]\n", commitID.String())) if commitID != localCommitID { @@ -126,7 +127,7 @@ func (r *Reset) Run(params *Params) error { } } - err = localcommit.Set(r.project.Dir(), commitID.String()) + err = r.prime.CheckoutInfo().SetCommitID(commitID) if err != nil { return errs.Wrap(err, "Unable to set local commit") } @@ -134,7 +135,7 @@ func (r *Reset) Run(params *Params) error { // Ensure the buildscript exists. Normally we should never do this, but reset is used for resetting from a corrupted // state, so it is appropriate. if r.cfg.GetBool(constants.OptinBuildscriptsConfig) { - if err := buildscript_runbit.Initialize(r.project.Dir(), r.auth, r.svcModel); err != nil { + if err := buildscript_runbit.Initialize(r.project.Dir(), r.auth, r.svcModel, r.prime.CheckoutInfo()); err != nil { return errs.Wrap(err, "Unable to initialize buildscript") } } diff --git a/internal/runners/revert/revert.go b/internal/runners/revert/revert.go index 60da9a2441..e237e52a25 100644 --- a/internal/runners/revert/revert.go +++ b/internal/runners/revert/revert.go @@ -14,7 +14,6 @@ import ( "github.com/ActiveState/cli/internal/runbits/rationalize" runtime_runbit "github.com/ActiveState/cli/internal/runbits/runtime" "github.com/ActiveState/cli/internal/runbits/runtime/trigger" - "github.com/ActiveState/cli/pkg/localcommit" gqlmodel "github.com/ActiveState/cli/pkg/platform/api/graphql/model" "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" @@ -51,6 +50,7 @@ type primeable interface { primer.Analyticer primer.SvcModeler primer.Configurer + primer.CheckoutInfoer } func New(prime primeable) *Revert { @@ -84,9 +84,9 @@ func (r *Revert) Run(params *Params) (rerr error) { if !strfmt.IsUUID(commitID) && !strings.EqualFold(commitID, remoteCommitID) { return locale.NewInputError("err_revert_invalid_commit_id", "Invalid commit ID") } - latestCommit, err := localcommit.Get(r.project.Dir()) + latestCommit, err := r.prime.CheckoutInfo().CommitID() if err != nil { - return errs.Wrap(err, "Unable to get local commit") + return errs.Wrap(err, "Unable to get commit ID") } if strings.EqualFold(commitID, remoteCommitID) { commitID = latestCommit.String() @@ -156,7 +156,7 @@ func (r *Revert) Run(params *Params) (rerr error) { locale.T("tip_private_project_auth")) } - err = localcommit.Set(r.project.Dir(), revertCommit.String()) + err = r.prime.CheckoutInfo().SetCommitID(revertCommit) if err != nil { return errs.Wrap(err, "Unable to set local commit") } diff --git a/internal/runners/run/run.go b/internal/runners/run/run.go index 4b3908b999..de37f90ef1 100644 --- a/internal/runners/run/run.go +++ b/internal/runners/run/run.go @@ -43,6 +43,7 @@ type primeable interface { primer.Configurer primer.SvcModeler primer.Analyticer + primer.CheckoutInfoer } // New constructs a new instance of Run. @@ -76,7 +77,7 @@ func (r *Run) Run(name string, args []string) error { r.out.Notice(output.Title(locale.Tl("run_script_title", "Running Script: [ACTIONABLE]{{.V0}}[/RESET]", name))) if r.auth.Authenticated() { - checker.RunCommitsBehindNotifier(r.proj, r.out, r.auth) + checker.RunCommitsBehindNotifier(r.proj, r.out, r.auth, r.prime.CheckoutInfo()) } script, err := r.proj.ScriptByName(name) diff --git a/internal/runners/shell/shell.go b/internal/runners/shell/shell.go index 43cc179806..90c50a5203 100644 --- a/internal/runners/shell/shell.go +++ b/internal/runners/shell/shell.go @@ -20,7 +20,6 @@ import ( "github.com/ActiveState/cli/internal/runbits/runtime/trigger" "github.com/ActiveState/cli/internal/subshell" "github.com/ActiveState/cli/internal/virtualenvironment" - "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" @@ -41,6 +40,7 @@ type primeable interface { primer.SvcModeler primer.Analyticer primer.Projecter + primer.CheckoutInfoer } type Shell struct { @@ -84,9 +84,9 @@ func (u *Shell) Run(params *Params) error { u.prime.SetProject(proj) - commitID, err := localcommit.Get(proj.Dir()) + commitID, err := u.prime.CheckoutInfo().CommitID() if err != nil { - return errs.Wrap(err, "Unable to get local commit") + return errs.Wrap(err, "Unable to get commit ID") } if cid := params.Namespace.CommitID; cid != nil && *cid != commitID { diff --git a/internal/runners/show/show.go b/internal/runners/show/show.go index 2c5387d561..6e61e18b2d 100644 --- a/internal/runners/show/show.go +++ b/internal/runners/show/show.go @@ -18,7 +18,6 @@ import ( "github.com/ActiveState/cli/internal/primer" "github.com/ActiveState/cli/internal/runbits/rationalize" "github.com/ActiveState/cli/internal/secrets" - "github.com/ActiveState/cli/pkg/localcommit" "github.com/ActiveState/cli/pkg/platform/api/mono/mono_models" secretsapi "github.com/ActiveState/cli/pkg/platform/api/secrets" "github.com/ActiveState/cli/pkg/platform/authentication" @@ -34,6 +33,7 @@ type Params struct { // Show manages the show run execution context. type Show struct { + prime primeable project *project.Project out output.Outputer conditional *constraints.Conditional @@ -45,6 +45,7 @@ type primeable interface { primer.Outputer primer.Conditioner primer.Auther + primer.CheckoutInfoer } type RuntimeDetails struct { @@ -124,6 +125,7 @@ type secretOutput struct { // New returns a pointer to an instance of Show. func New(prime primeable) *Show { return &Show{ + prime, prime.Project(), prime.Output(), prime.Conditional(), @@ -189,9 +191,9 @@ func (s *Show) Run(params Params) error { return locale.WrapError(err, "err_show_scripts", "Could not parse scripts") } - commitID, err = localcommit.Get(s.project.Dir()) + commitID, err = s.prime.CheckoutInfo().CommitID() if err != nil { - return errs.Wrap(err, "Unable to get local commit") + return errs.Wrap(err, "Unable to get commit ID") } projectDir = filepath.Dir(s.project.Path()) @@ -225,7 +227,7 @@ func (s *Show) Run(params Params) error { return locale.WrapError(err, "err_show_langauges", "Could not retrieve language information") } - commit, err := commitsData(owner, projectName, branchName, commitID, s.project, s.auth) + commit, err := commitsData(owner, projectName, branchName, commitID, s.prime) if err != nil { return locale.WrapError(err, "err_show_commit", "Could not get commit information") } @@ -356,7 +358,11 @@ func visibilityData(owner, project string, remoteProject *mono_models.Project) s return locale.T("public") } -func commitsData(owner, project, branchName string, commitID strfmt.UUID, localProject *project.Project, auth *authentication.Auth) (string, error) { +func commitsData(owner, project, branchName string, commitID strfmt.UUID, prime primeable) (string, error) { + auth := prime.Auth() + localProject := prime.Project() + info := prime.CheckoutInfo() + latestCommit, err := model.BranchCommitID(owner, project, branchName) if err != nil { return "", locale.WrapError(err, "err_show_get_latest_commit", "Could not get latest commit ID") @@ -380,9 +386,9 @@ func commitsData(owner, project, branchName string, commitID strfmt.UUID, localP if err != nil { return "", locale.WrapError(err, "err_show_commits_behind", "Could not determine number of commits behind latest") } - localCommitID, err := localcommit.Get(localProject.Dir()) + localCommitID, err := info.CommitID() if err != nil { - return "", errs.Wrap(err, "Unable to get local commit") + return "", errs.Wrap(err, "Unable to get commit ID") } if behind > 0 { return fmt.Sprintf("%s (%d %s)", localCommitID.String(), behind, locale.Tl("show_commits_behind_latest", "behind latest")), nil diff --git a/internal/runners/swtch/switch.go b/internal/runners/swtch/switch.go index b0ee096628..4b9ee5246b 100644 --- a/internal/runners/swtch/switch.go +++ b/internal/runners/swtch/switch.go @@ -11,7 +11,6 @@ import ( "github.com/ActiveState/cli/internal/runbits/rationalize" "github.com/ActiveState/cli/internal/runbits/runtime" "github.com/ActiveState/cli/internal/runbits/runtime/trigger" - "github.com/ActiveState/cli/pkg/localcommit" "github.com/ActiveState/cli/pkg/platform/api/mono/mono_models" "github.com/ActiveState/cli/pkg/platform/authentication" "github.com/ActiveState/cli/pkg/platform/model" @@ -43,6 +42,7 @@ type primeable interface { primer.Configurer primer.Analyticer primer.SvcModeler + primer.CheckoutInfoer } type identifier interface { @@ -119,7 +119,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 = s.prime.CheckoutInfo().SetCommitID(identifier.CommitID()) if err != nil { return errs.Wrap(err, "Unable to set local commit") } diff --git a/internal/runners/uninstall/uninstall.go b/internal/runners/uninstall/uninstall.go index be85debf5e..ef2d98b97f 100644 --- a/internal/runners/uninstall/uninstall.go +++ b/internal/runners/uninstall/uninstall.go @@ -16,7 +16,6 @@ import ( "github.com/ActiveState/cli/internal/runbits/runtime/trigger" "github.com/ActiveState/cli/internal/sliceutils" "github.com/ActiveState/cli/pkg/buildscript" - "github.com/ActiveState/cli/pkg/localcommit" "github.com/ActiveState/cli/pkg/platform/api/buildplanner/types" "github.com/ActiveState/cli/pkg/platform/model" bpModel "github.com/ActiveState/cli/pkg/platform/model/buildplanner" @@ -30,6 +29,7 @@ type primeable interface { primer.Configurer primer.Analyticer primer.SvcModeler + primer.CheckoutInfoer } // Params tracks the info required for running Uninstall. @@ -111,9 +111,9 @@ func (u *Uninstall) Run(params Params) (rerr error) { pg = output.StartSpinner(out, locale.T("progress_requirements"), constants.TerminalAnimationInterval) // Grab local commit info - localCommitID, err := localcommit.Get(u.prime.Project().Dir()) + localCommitID, err := u.prime.CheckoutInfo().CommitID() if err != nil { - return errs.Wrap(err, "Unable to get local commit") + return errs.Wrap(err, "Unable to get commit ID") } oldCommit, err := bp.FetchCommit(localCommitID, pj.Owner(), pj.Name(), nil) if err != nil { diff --git a/internal/runners/upgrade/upgrade.go b/internal/runners/upgrade/upgrade.go index 953b20098c..c59be30794 100644 --- a/internal/runners/upgrade/upgrade.go +++ b/internal/runners/upgrade/upgrade.go @@ -18,7 +18,6 @@ import ( "github.com/ActiveState/cli/internal/sliceutils" "github.com/ActiveState/cli/internal/table" "github.com/ActiveState/cli/pkg/buildplan" - "github.com/ActiveState/cli/pkg/localcommit" "github.com/ActiveState/cli/pkg/platform/api/buildplanner/response" "github.com/ActiveState/cli/pkg/platform/api/buildplanner/types" "github.com/ActiveState/cli/pkg/platform/model" @@ -32,6 +31,7 @@ type primeable interface { primer.Projecter primer.Prompter primer.SvcModeler + primer.CheckoutInfoer } type Params struct { @@ -91,7 +91,7 @@ func (u *Upgrade) Run(params *Params) (rerr error) { }() // Collect "before" buildplan - localCommitID, err := localcommit.Get(proj.Dir()) + localCommitID, err := u.prime.CheckoutInfo().CommitID() if err != nil { return errs.Wrap(err, "Failed to get local commit") } @@ -157,7 +157,7 @@ func (u *Upgrade) Run(params *Params) (rerr error) { } } - if err := localcommit.Set(u.prime.Project().Dir(), bumpedCommit.CommitID.String()); err != nil { + if err := u.prime.CheckoutInfo().SetCommitID(bumpedCommit.CommitID); err != nil { return errs.Wrap(err, "Failed to set local commit") } diff --git a/internal/runners/use/use.go b/internal/runners/use/use.go index 1169a16deb..2039e4fa8d 100644 --- a/internal/runners/use/use.go +++ b/internal/runners/use/use.go @@ -18,7 +18,6 @@ import ( "github.com/ActiveState/cli/internal/runbits/runtime" "github.com/ActiveState/cli/internal/runbits/runtime/trigger" "github.com/ActiveState/cli/internal/subshell" - "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" @@ -37,6 +36,7 @@ type primeable interface { primer.SvcModeler primer.Analyticer primer.Projecter + primer.CheckoutInfoer } type Use struct { @@ -81,9 +81,9 @@ func (u *Use) Run(params *Params) error { u.prime.SetProject(proj) - commitID, err := localcommit.Get(proj.Dir()) + commitID, err := u.prime.CheckoutInfo().CommitID() if err != nil { - return errs.Wrap(err, "Unable to get local commit") + return errs.Wrap(err, "Unable to get commit ID") } if cid := params.Namespace.CommitID; cid != nil && *cid != commitID { diff --git a/internal/scriptrun/scriptrun.go b/internal/scriptrun/scriptrun.go index 12f94c17c9..29776e3c7a 100644 --- a/internal/scriptrun/scriptrun.go +++ b/internal/scriptrun/scriptrun.go @@ -33,6 +33,7 @@ type primeable interface { primer.Configurer primer.Analyticer primer.SvcModeler + primer.CheckoutInfoer } // ScriptRun manages the context required to run a script. diff --git a/pkg/checkoutinfo/checkoutinfo.go b/pkg/checkoutinfo/checkoutinfo.go new file mode 100644 index 0000000000..83ccfe4273 --- /dev/null +++ b/pkg/checkoutinfo/checkoutinfo.go @@ -0,0 +1,38 @@ +package checkoutinfo + +import ( + "github.com/go-openapi/strfmt" +) + +type ErrInvalidCommitID struct { + CommitID string +} + +func (e ErrInvalidCommitID) Error() string { + return "invalid commit ID" +} + +type projectfiler interface { + LegacyCommitID() string + SetLegacyCommit(string) error +} + +type CheckoutInfo struct { + project projectfiler +} + +func New(project projectfiler) *CheckoutInfo { + return &CheckoutInfo{project} +} + +func (c *CheckoutInfo) CommitID() (strfmt.UUID, error) { + commitID := c.project.LegacyCommitID() + if !strfmt.IsUUID(commitID) { + return "", &ErrInvalidCommitID{commitID} + } + return strfmt.UUID(commitID), nil +} + +func (c *CheckoutInfo) SetCommitID(commitID strfmt.UUID) error { + return c.project.SetLegacyCommit(commitID.String()) +} diff --git a/pkg/projectfile/projectfile.go b/pkg/projectfile/projectfile.go index 9761cbb17b..110ae6b912 100644 --- a/pkg/projectfile/projectfile.go +++ b/pkg/projectfile/projectfile.go @@ -913,6 +913,7 @@ type CreateParams struct { Owner string Project string BranchName string + CommitID string Directory string Content string Language string @@ -955,6 +956,10 @@ func createCustom(params *CreateParams, lang language.Language) (*Project, error q.Set("branch", params.BranchName) } + if params.CommitID != "" { + q.Set("commitID", params.CommitID) + } + u.RawQuery = q.Encode() params.ProjectURL = u.String() } diff --git a/pkg/runtime_helpers/helpers.go b/pkg/runtime_helpers/helpers.go index 3ecad8c694..05a16667d1 100644 --- a/pkg/runtime_helpers/helpers.go +++ b/pkg/runtime_helpers/helpers.go @@ -10,7 +10,7 @@ import ( "github.com/ActiveState/cli/internal/hash" "github.com/ActiveState/cli/internal/installation/storage" "github.com/ActiveState/cli/internal/multilog" - "github.com/ActiveState/cli/pkg/localcommit" + "github.com/ActiveState/cli/internal/primer" "github.com/ActiveState/cli/pkg/project" "github.com/ActiveState/cli/pkg/runtime" "github.com/go-openapi/strfmt" @@ -22,6 +22,11 @@ with certain concepts, like projects, we still want convenience layers for inter of projects. */ +type primeable interface { + primer.Projecter + primer.CheckoutInfoer +} + func FromProject(proj *project.Project) (*runtime.Runtime, error) { targetDir := TargetDirFromProject(proj) rt, err := runtime.New(targetDir) @@ -31,13 +36,13 @@ func FromProject(proj *project.Project) (*runtime.Runtime, error) { return rt, nil } -func NeedsUpdate(proj *project.Project, overrideCommitID *strfmt.UUID) (bool, error) { - rt, err := FromProject(proj) +func NeedsUpdate(prime primeable, overrideCommitID *strfmt.UUID) (bool, error) { + rt, err := FromProject(prime.Project()) if err != nil { return false, errs.Wrap(err, "Could not obtain runtime") } - hash, err := Hash(proj, overrideCommitID) + hash, err := Hash(prime, overrideCommitID) if err != nil { return false, errs.Wrap(err, "Could not get hash") } @@ -45,11 +50,14 @@ func NeedsUpdate(proj *project.Project, overrideCommitID *strfmt.UUID) (bool, er return hash != rt.Hash(), nil } -func Hash(proj *project.Project, overrideCommitID *strfmt.UUID) (string, error) { +func Hash(prime primeable, overrideCommitID *strfmt.UUID) (string, error) { + proj := prime.Project() + info := prime.CheckoutInfo() + var err error var commitID strfmt.UUID if overrideCommitID == nil { - commitID, err = localcommit.Get(proj.Dir()) + commitID, err = info.CommitID() if err != nil { return "", errs.Wrap(err, "Failed to get local commit") } diff --git a/test/integration/pull_int_test.go b/test/integration/pull_int_test.go index e2a7eea4a8..152e5e87ea 100644 --- a/test/integration/pull_int_test.go +++ b/test/integration/pull_int_test.go @@ -14,7 +14,6 @@ import ( "github.com/ActiveState/cli/internal/testhelpers/e2e" "github.com/ActiveState/cli/internal/testhelpers/suite" "github.com/ActiveState/cli/internal/testhelpers/tagsuite" - "github.com/ActiveState/cli/pkg/localcommit" "github.com/ActiveState/cli/pkg/platform/api/buildplanner/types" "github.com/ActiveState/cli/pkg/project" ) @@ -118,9 +117,8 @@ func (suite *PullIntegrationTestSuite) TestMergeBuildScript() { // ignore it). After resolving buildscript conflicts, `state commit` should always have something // new to commit. remoteHeadCommit := "2c461e7c-43d2-4e43-b169-a255c305becd" - commit, err := localcommit.Get(ts.Dirs.Work) - suite.Require().NoError(err) - suite.Assert().Equal(remoteHeadCommit, commit.String(), "localcommit should have been updated to remote commit") + commit := ts.CommitID() + suite.Assert().Equal(remoteHeadCommit, commit, "commitID should have been updated to remote commit") } func (suite *PullIntegrationTestSuite) assertMergeStrategyNotification(ts *e2e.Session, strategy string) { diff --git a/test/integration/reset_int_test.go b/test/integration/reset_int_test.go index e7cc862ea9..4346867e81 100644 --- a/test/integration/reset_int_test.go +++ b/test/integration/reset_int_test.go @@ -10,7 +10,6 @@ import ( "github.com/ActiveState/cli/internal/testhelpers/e2e" "github.com/ActiveState/cli/internal/testhelpers/suite" "github.com/ActiveState/cli/internal/testhelpers/tagsuite" - "github.com/ActiveState/cli/pkg/localcommit" ) type ResetIntegrationTestSuite struct { @@ -23,8 +22,7 @@ func (suite *ResetIntegrationTestSuite) TestReset() { defer ts.Close() ts.PrepareEmptyProject() - commitID, err := localcommit.Get(ts.Dirs.Work) - suite.Require().NoError(err) + commitID := ts.CommitID() cp := ts.Spawn("config", "set", constants.AsyncRuntimeConfig, "true") cp.ExpectExitCode(0) @@ -38,11 +36,11 @@ func (suite *ResetIntegrationTestSuite) TestReset() { cp.ExpectExitCode(0) cp = ts.Spawn("reset") - cp.Expect("Your project will be reset to " + commitID.String()) + cp.Expect("Your project will be reset to " + commitID) cp.Expect("Are you sure") cp.Expect("(y/N)") cp.SendLine("y") - cp.Expect("Successfully reset to commit: " + commitID.String()) + cp.Expect("Successfully reset to commit: " + commitID) cp.ExpectExitCode(0) cp = ts.Spawn("history") @@ -76,12 +74,11 @@ func (suite *ResetIntegrationTestSuite) TestRevertInvalidURL() { defer ts.Close() ts.PrepareEmptyProject() - commitID, err := localcommit.Get(ts.Dirs.Work) - suite.Require().NoError(err) + commitID := ts.CommitID() contents := fileutils.ReadFileUnsafe(filepath.Join(ts.Dirs.Work, constants.ConfigFileName)) - contents = bytes.Replace(contents, []byte(commitID.String()), []byte(""), 1) - err = fileutils.WriteFile(filepath.Join(ts.Dirs.Work, constants.ConfigFileName), contents) + contents = bytes.Replace(contents, []byte(commitID), []byte(""), 1) + err := fileutils.WriteFile(filepath.Join(ts.Dirs.Work, constants.ConfigFileName), contents) suite.Require().NoError(err) cp := ts.Spawn("install", "language/python/requests") @@ -90,7 +87,7 @@ func (suite *ResetIntegrationTestSuite) TestRevertInvalidURL() { cp.ExpectNotExitCode(0) cp = ts.Spawn("reset", "-n") - cp.Expect("Successfully reset to commit: " + commitID.String()) + cp.Expect("Successfully reset to commit: " + commitID) cp.ExpectExitCode(0) }