mirror of
https://github.com/dolthub/dolt.git
synced 2026-03-13 01:54:38 -05:00
Refactor RepoStateReader's CWBHeadRef and CWBHeadSpec to return errors.
This commit is contained in:
@@ -138,7 +138,10 @@ func printBranches(ctx context.Context, dEnv *env.DoltEnv, apr *argparser.ArgPar
|
||||
return HandleVErrAndExitCode(errhand.BuildDError("error: failed to read refs from db").AddCause(err).Build(), nil)
|
||||
}
|
||||
|
||||
currentBranch := dEnv.RepoStateReader().CWBHeadRef()
|
||||
currentBranch, err := dEnv.RepoStateReader().CWBHeadRef()
|
||||
if err != nil {
|
||||
return HandleVErrAndExitCode(errhand.BuildDError("error: failed to read refs from db").AddCause(err).Build(), nil)
|
||||
}
|
||||
sort.Slice(branches, func(i, j int) bool {
|
||||
return branches[i].String() < branches[j].String()
|
||||
})
|
||||
@@ -172,7 +175,11 @@ func printBranches(ctx context.Context, dEnv *env.DoltEnv, apr *argparser.ArgPar
|
||||
}
|
||||
|
||||
if verbose {
|
||||
cm, err := dEnv.DoltDB.Resolve(ctx, cs, dEnv.RepoStateReader().CWBHeadRef())
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef()
|
||||
if err != nil {
|
||||
return HandleVErrAndExitCode(errhand.BuildDError(err.Error()).Build(), nil)
|
||||
}
|
||||
cm, err := dEnv.DoltDB.Resolve(ctx, cs, headRef)
|
||||
|
||||
if err == nil {
|
||||
h, err := cm.HashOf()
|
||||
@@ -195,7 +202,11 @@ func printBranches(ctx context.Context, dEnv *env.DoltEnv, apr *argparser.ArgPar
|
||||
}
|
||||
|
||||
func printCurrentBranch(dEnv *env.DoltEnv) int {
|
||||
cli.Println(dEnv.RepoStateReader().CWBHeadRef().GetPath())
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef()
|
||||
if err != nil {
|
||||
return HandleVErrAndExitCode(errhand.BuildDError(err.Error()).Build(), nil)
|
||||
}
|
||||
cli.Println(headRef.GetPath())
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
@@ -119,7 +119,10 @@ func (cmd CheckoutCmd) Exec(ctx context.Context, commandStr string, args []strin
|
||||
if err != nil {
|
||||
return HandleVErrAndExitCode(errhand.BuildDError(err.Error()).Build(), usagePrt)
|
||||
}
|
||||
headRef := dEnv.RepoStateReader().CWBHeadRef()
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef()
|
||||
if err != nil {
|
||||
return HandleVErrAndExitCode(errhand.BuildDError(err.Error()).Build(), nil)
|
||||
}
|
||||
ws, err := dEnv.WorkingSet(ctx)
|
||||
if err != nil {
|
||||
HandleVErrAndExitCode(errhand.BuildDError(err.Error()).Build(), usagePrt)
|
||||
@@ -179,7 +182,11 @@ func checkoutNewBranch(ctx context.Context, dEnv *env.DoltEnv, apr *argparser.Ar
|
||||
|
||||
// the new branch is checked out at this point
|
||||
if setTrackUpstream {
|
||||
verr = SetRemoteUpstreamForBranchRef(dEnv, remoteName, remoteBranchName, dEnv.RepoStateReader().CWBHeadRef())
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef()
|
||||
if err != nil {
|
||||
return errhand.BuildDError(err.Error()).Build()
|
||||
}
|
||||
verr = SetRemoteUpstreamForBranchRef(dEnv, remoteName, remoteBranchName, headRef)
|
||||
if verr != nil {
|
||||
return verr
|
||||
}
|
||||
@@ -195,7 +202,11 @@ func checkoutNewBranch(ctx context.Context, dEnv *env.DoltEnv, apr *argparser.Ar
|
||||
if !remoteOk {
|
||||
return nil
|
||||
}
|
||||
verr = SetRemoteUpstreamForBranchRef(dEnv, remoteName, remoteBranchName, dEnv.RepoStateReader().CWBHeadRef())
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef()
|
||||
if err != nil {
|
||||
return errhand.BuildDError(err.Error()).Build()
|
||||
}
|
||||
verr = SetRemoteUpstreamForBranchRef(dEnv, remoteName, remoteBranchName, headRef)
|
||||
if verr != nil {
|
||||
return verr
|
||||
}
|
||||
@@ -230,7 +241,11 @@ func checkoutRemoteBranchOrSuggestNew(ctx context.Context, dEnv *env.DoltEnv, na
|
||||
if verr != nil {
|
||||
return verr
|
||||
}
|
||||
return SetRemoteUpstreamForBranchRef(dEnv, remoteRefs[0].GetRemote(), remoteRefs[0].GetBranch(), dEnv.RepoStateReader().CWBHeadRef())
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef()
|
||||
if err != nil {
|
||||
return errhand.BuildDError(err.Error()).Build()
|
||||
}
|
||||
return SetRemoteUpstreamForBranchRef(dEnv, remoteRefs[0].GetRemote(), remoteRefs[0].GetBranch(), headRef)
|
||||
} else {
|
||||
// TODO : add hint of using `dolt checkout --track <remote>/<branch>` when --track flag is supported
|
||||
return errhand.BuildDError("'%s' matched multiple (%v) remote tracking branches", name, len(remoteRefs)).Build()
|
||||
|
||||
@@ -221,9 +221,13 @@ func performCommit(ctx context.Context, commandStr string, args []string, dEnv *
|
||||
return handleCommitErr(ctx, dEnv, err, usage)
|
||||
}
|
||||
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef()
|
||||
if err != nil {
|
||||
return handleCommitErr(ctx, dEnv, err, usage)
|
||||
}
|
||||
_, err = dEnv.DoltDB.CommitWithWorkingSet(
|
||||
ctx,
|
||||
dEnv.RepoStateReader().CWBHeadRef(),
|
||||
headRef,
|
||||
ws.Ref(),
|
||||
pendingCommit,
|
||||
ws.WithStagedRoot(pendingCommit.Roots.Staged).WithWorkingRoot(pendingCommit.Roots.Working).ClearMerge(),
|
||||
@@ -380,7 +384,10 @@ func buildInitalCommitMsg(ctx context.Context, dEnv *env.DoltEnv, suggestedMsg s
|
||||
return "", err
|
||||
}
|
||||
|
||||
currBranch := dEnv.RepoStateReader().CWBHeadRef()
|
||||
currBranch, err := dEnv.RepoStateReader().CWBHeadRef()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
initialCommitMessage := fmt.Sprintf("%s\n# Please enter the commit message for your changes. Lines starting"+
|
||||
"\n# with '#' will be ignored, and an empty message aborts the commit."+
|
||||
"\n# On branch %s\n#\n", suggestedMsg, currBranch)
|
||||
|
||||
@@ -123,7 +123,11 @@ func (cmd LogCmd) logWithLoggerFunc(ctx context.Context, commandStr string, args
|
||||
return HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage)
|
||||
}
|
||||
if len(opts.commitSpecs) == 0 {
|
||||
opts.commitSpecs = append(opts.commitSpecs, dEnv.RepoStateReader().CWBHeadSpec())
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadSpec()
|
||||
if err != nil {
|
||||
return HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage)
|
||||
}
|
||||
opts.commitSpecs = append(opts.commitSpecs, headRef)
|
||||
}
|
||||
if len(opts.tableName) > 0 {
|
||||
return handleErrAndExit(logTableCommits(ctx, dEnv, opts))
|
||||
@@ -327,8 +331,12 @@ func getHashToRefs(ctx context.Context, dEnv *env.DoltEnv, decorationLevel strin
|
||||
func logCommits(ctx context.Context, dEnv *env.DoltEnv, opts *logOpts) int {
|
||||
hashes := make([]hash.Hash, len(opts.commitSpecs))
|
||||
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef()
|
||||
if err != nil {
|
||||
return handleErrAndExit(err)
|
||||
}
|
||||
for i, cs := range opts.commitSpecs {
|
||||
commit, err := dEnv.DoltDB.Resolve(ctx, cs, dEnv.RepoStateReader().CWBHeadRef())
|
||||
commit, err := dEnv.DoltDB.Resolve(ctx, cs, headRef)
|
||||
if err != nil {
|
||||
cli.PrintErrln(color.HiRedString("Fatal error: cannot get HEAD commit for current branch."))
|
||||
return 1
|
||||
@@ -360,7 +368,7 @@ func logCommits(ctx context.Context, dEnv *env.DoltEnv, opts *logOpts) int {
|
||||
excludingHashes := make([]hash.Hash, len(opts.excludingCommitSpecs))
|
||||
|
||||
for i, excludingSpec := range opts.excludingCommitSpecs {
|
||||
excludingCommit, err := dEnv.DoltDB.Resolve(ctx, excludingSpec, dEnv.RepoStateReader().CWBHeadRef())
|
||||
excludingCommit, err := dEnv.DoltDB.Resolve(ctx, excludingSpec, headRef)
|
||||
if err != nil {
|
||||
cli.PrintErrln(color.HiRedString("Fatal error: cannot get excluding commit for current branch."))
|
||||
return 1
|
||||
@@ -383,7 +391,6 @@ func logCommits(ctx context.Context, dEnv *env.DoltEnv, opts *logOpts) int {
|
||||
return 1
|
||||
}
|
||||
|
||||
headRef := dEnv.RepoStateReader().CWBHeadRef()
|
||||
cwbHash, err := dEnv.DoltDB.GetHashForRefStr(ctx, headRef.String())
|
||||
|
||||
if err != nil {
|
||||
@@ -441,8 +448,13 @@ func tableExists(ctx context.Context, commit *doltdb.Commit, tableName string) (
|
||||
func logTableCommits(ctx context.Context, dEnv *env.DoltEnv, opts *logOpts) error {
|
||||
hashes := make([]hash.Hash, len(opts.commitSpecs))
|
||||
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for i, cs := range opts.commitSpecs {
|
||||
commit, err := dEnv.DoltDB.Resolve(ctx, cs, dEnv.RepoStateReader().CWBHeadRef())
|
||||
commit, err := dEnv.DoltDB.Resolve(ctx, cs, headRef)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -96,16 +96,20 @@ func (cmd PushCmd) Exec(ctx context.Context, commandStr string, args []string, d
|
||||
var verr errhand.VerboseError
|
||||
switch err {
|
||||
case env.ErrNoUpstreamForBranch:
|
||||
currentBranch := dEnv.RepoStateReader().CWBHeadRef()
|
||||
remoteName := "<remote>"
|
||||
if defRemote, verr := env.GetDefaultRemote(dEnv.RepoStateReader()); verr == nil {
|
||||
remoteName = defRemote.Name
|
||||
currentBranch, err := dEnv.RepoStateReader().CWBHeadRef()
|
||||
if err != nil {
|
||||
verr = errhand.BuildDError("fatal: The current branch could not be identified").Build()
|
||||
} else {
|
||||
remoteName := "<remote>"
|
||||
if defRemote, verr := env.GetDefaultRemote(dEnv.RepoStateReader()); verr == nil {
|
||||
remoteName = defRemote.Name
|
||||
}
|
||||
verr = errhand.BuildDError("fatal: The current branch " + currentBranch.GetPath() + " has no upstream branch.\n" +
|
||||
"To push the current branch and set the remote as upstream, use\n" +
|
||||
"\tdolt push --set-upstream " + remoteName + " " + currentBranch.GetPath() + "\n" +
|
||||
"To have this happen automatically for branches without a tracking\n" +
|
||||
"upstream, see 'push.autoSetupRemote' in 'dolt config --help'.").Build()
|
||||
}
|
||||
verr = errhand.BuildDError("fatal: The current branch " + currentBranch.GetPath() + " has no upstream branch.\n" +
|
||||
"To push the current branch and set the remote as upstream, use\n" +
|
||||
"\tdolt push --set-upstream " + remoteName + " " + currentBranch.GetPath() + "\n" +
|
||||
"To have this happen automatically for branches without a tracking\n" +
|
||||
"upstream, see 'push.autoSetupRemote' in 'dolt config --help'.").Build()
|
||||
|
||||
case env.ErrInvalidSetUpstreamArgs:
|
||||
verr = errhand.BuildDError("error: --set-upstream requires <remote> and <refspec> params.").SetPrintUsage().Build()
|
||||
|
||||
@@ -145,7 +145,10 @@ func handleResetHard(ctx context.Context, apr *argparser.ArgParseResults, usage
|
||||
arg = apr.Arg(0)
|
||||
}
|
||||
|
||||
headRef := dEnv.RepoStateReader().CWBHeadRef()
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef()
|
||||
if err != nil {
|
||||
return HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage)
|
||||
}
|
||||
ws, err := dEnv.WorkingSet(ctx)
|
||||
if err != nil {
|
||||
return HandleVErrAndExitCode(errhand.VerboseErrorFromError(err), usage)
|
||||
|
||||
@@ -159,7 +159,11 @@ func parseShowArgs(ctx context.Context, dEnv *env.DoltEnv, apr *argparser.ArgPar
|
||||
|
||||
func showObjects(ctx context.Context, dEnv *env.DoltEnv, opts *showOpts) error {
|
||||
if len(opts.specRefs) == 0 {
|
||||
return showCommitSpec(ctx, dEnv, opts, dEnv.RepoStateReader().CWBHeadSpec())
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadSpec()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return showCommitSpec(ctx, dEnv, opts, headRef)
|
||||
}
|
||||
|
||||
for _, specRef := range opts.specRefs {
|
||||
@@ -243,7 +247,12 @@ func showSpecRef(ctx context.Context, dEnv *env.DoltEnv, opts *showOpts, specRef
|
||||
|
||||
func showCommitSpec(ctx context.Context, dEnv *env.DoltEnv, opts *showOpts, commitSpec *doltdb.CommitSpec) error {
|
||||
|
||||
commit, err := dEnv.DoltDB.Resolve(ctx, commitSpec, dEnv.RepoStateReader().CWBHeadRef())
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
commit, err := dEnv.DoltDB.Resolve(ctx, commitSpec, headRef)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -283,7 +292,10 @@ func showCommit(ctx context.Context, dEnv *env.DoltEnv, opts *showOpts, comm *do
|
||||
return err
|
||||
}
|
||||
|
||||
headRef := dEnv.RepoStateReader().CWBHeadRef()
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
cwbHash, err := dEnv.DoltDB.GetHashForRefStr(ctx, headRef.String())
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -222,7 +222,10 @@ func stashChanges(ctx context.Context, dEnv *env.DoltEnv, apr *argparser.ArgPars
|
||||
}
|
||||
}
|
||||
|
||||
curHeadRef := dEnv.RepoStateReader().CWBHeadRef()
|
||||
curHeadRef, err := dEnv.RepoStateReader().CWBHeadRef()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
curBranchName := curHeadRef.String()
|
||||
commitSpec, err := doltdb.NewCommitSpec(curBranchName)
|
||||
if err != nil {
|
||||
|
||||
@@ -95,9 +95,14 @@ func (cmd StatusCmd) Exec(ctx context.Context, commandStr string, args []string,
|
||||
}
|
||||
|
||||
func PrintStatus(ctx context.Context, dEnv *env.DoltEnv, stagedTbls, notStagedTbls []diff.TableDelta, showIgnoredTables bool, as merge.ArtifactStatus) error {
|
||||
cli.Printf(branchHeader, dEnv.RepoStateReader().CWBHeadRef().GetPath())
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err := printRemoteRefTrackingInfo(ctx, dEnv)
|
||||
cli.Printf(branchHeader, headRef.GetPath())
|
||||
|
||||
err = printRemoteRefTrackingInfo(ctx, dEnv)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -141,7 +146,10 @@ func handleStatusVErr(err error) int {
|
||||
func printRemoteRefTrackingInfo(ctx context.Context, dEnv *env.DoltEnv) error {
|
||||
ddb := dEnv.DoltDB
|
||||
rsr := dEnv.RepoStateReader()
|
||||
headRef := rsr.CWBHeadRef()
|
||||
headRef, err := rsr.CWBHeadRef()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
branches, err := rsr.GetBranches()
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -148,4 +148,8 @@ require (
|
||||
|
||||
replace github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi => ./gen/proto/dolt/services/eventsapi
|
||||
|
||||
replace github.com/dolthub/vitess => ../../vitess
|
||||
|
||||
replace github.com/dolthub/go-mysql-server => ../../go-mysql-server
|
||||
|
||||
go 1.19
|
||||
|
||||
@@ -29,7 +29,6 @@ var ErrInvalidBranchOrHash = errors.New("string is not a valid branch or hash")
|
||||
var ErrInvalidHash = errors.New("string is not a valid hash")
|
||||
|
||||
var ErrFoundHashNotACommit = errors.New("the value retrieved for this hash is not a commit")
|
||||
|
||||
var ErrHashNotFound = errors.New("could not find a value for this hash")
|
||||
var ErrBranchNotFound = errors.New("branch not found")
|
||||
var ErrTagNotFound = errors.New("tag not found")
|
||||
@@ -49,6 +48,8 @@ var ErrIsBehind = errors.New("cannot reverse from b to a. b is a is behind a alr
|
||||
var ErrUnresolvedConflictsOrViolations = errors.New("merge has unresolved conflicts or constraint violations")
|
||||
var ErrMergeActive = errors.New("merging is not possible because you have not committed an active merge")
|
||||
|
||||
var ErrOperationNotSupportedInDetachedHead = errors.New("this operation is not supported while in a detached head state")
|
||||
|
||||
type ErrClientOutOfDate struct {
|
||||
RepoVer FeatureVersion
|
||||
ClientVer FeatureVersion
|
||||
|
||||
12
go/libraries/doltcore/env/actions/checkout.go
vendored
12
go/libraries/doltcore/env/actions/checkout.go
vendored
@@ -17,7 +17,6 @@ package actions
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/env"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/ref"
|
||||
@@ -159,7 +158,10 @@ func rootsForBranch(ctx context.Context, roots doltdb.Roots, branchRoot *doltdb.
|
||||
|
||||
func CheckoutBranch(ctx context.Context, dEnv *env.DoltEnv, brName string, force bool) error {
|
||||
branchRef := ref.NewBranchRef(brName)
|
||||
initialHeadRef := dEnv.RepoStateReader().CWBHeadRef()
|
||||
initialHeadRef, err := dEnv.RepoStateReader().CWBHeadRef()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
db := dEnv.DoltDB
|
||||
hasRef, err := db.HasRef(ctx, branchRef)
|
||||
@@ -170,7 +172,11 @@ func CheckoutBranch(ctx context.Context, dEnv *env.DoltEnv, brName string, force
|
||||
return doltdb.ErrBranchNotFound
|
||||
}
|
||||
|
||||
if ref.Equals(dEnv.RepoStateReader().CWBHeadRef(), branchRef) {
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if ref.Equals(headRef, branchRef) {
|
||||
return doltdb.ErrAlreadyOnBranch
|
||||
}
|
||||
|
||||
|
||||
19
go/libraries/doltcore/env/environment.go
vendored
19
go/libraries/doltcore/env/environment.go
vendored
@@ -206,7 +206,10 @@ func (dEnv *DoltEnv) Valid() bool {
|
||||
// initWorkingSetFromRepoState sets the working set for the env's head to mirror the contents of the repo state file.
|
||||
// This is only necessary to migrate repos written before this method was introduced, and can be removed after 1.0
|
||||
func (dEnv *DoltEnv) initWorkingSetFromRepoState(ctx context.Context) error {
|
||||
headRef := dEnv.RepoStateReader().CWBHeadRef()
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
wsRef, err := ref.WorkingSetRefForHead(headRef)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -591,7 +594,11 @@ func (dEnv *DoltEnv) WorkingSet(ctx context.Context) (*doltdb.WorkingSet, error)
|
||||
}
|
||||
|
||||
func WorkingSet(ctx context.Context, ddb *doltdb.DoltDB, rsr RepoStateReader) (*doltdb.WorkingSet, error) {
|
||||
workingSetRef, err := ref.WorkingSetRefForHead(rsr.CWBHeadRef())
|
||||
headRef, err := rsr.CWBHeadRef()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
workingSetRef, err := ref.WorkingSetRefForHead(headRef)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -655,12 +662,12 @@ type repoStateReader struct {
|
||||
*DoltEnv
|
||||
}
|
||||
|
||||
func (r *repoStateReader) CWBHeadRef() ref.DoltRef {
|
||||
return r.RepoState.CWBHeadRef()
|
||||
func (r *repoStateReader) CWBHeadRef() (ref.DoltRef, error) {
|
||||
return r.RepoState.CWBHeadRef(), nil
|
||||
}
|
||||
|
||||
func (r *repoStateReader) CWBHeadSpec() *doltdb.CommitSpec {
|
||||
return r.RepoState.CWBHeadSpec()
|
||||
func (r *repoStateReader) CWBHeadSpec() (*doltdb.CommitSpec, error) {
|
||||
return r.RepoState.CWBHeadSpec(), nil
|
||||
}
|
||||
|
||||
func (dEnv *DoltEnv) RepoStateReader() RepoStateReader {
|
||||
|
||||
34
go/libraries/doltcore/env/memory.go
vendored
34
go/libraries/doltcore/env/memory.go
vendored
@@ -101,16 +101,20 @@ type MemoryRepoState struct {
|
||||
var _ RepoStateReader = MemoryRepoState{}
|
||||
var _ RepoStateWriter = MemoryRepoState{}
|
||||
|
||||
func (m MemoryRepoState) CWBHeadRef() ref.DoltRef {
|
||||
return m.Head
|
||||
func (m MemoryRepoState) CWBHeadRef() (ref.DoltRef, error) {
|
||||
return m.Head, nil
|
||||
}
|
||||
|
||||
func (m MemoryRepoState) CWBHeadSpec() *doltdb.CommitSpec {
|
||||
spec, err := doltdb.NewCommitSpec(m.CWBHeadRef().GetPath())
|
||||
func (m MemoryRepoState) CWBHeadSpec() (*doltdb.CommitSpec, error) {
|
||||
headRef, err := m.CWBHeadRef()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return nil, err
|
||||
}
|
||||
return spec
|
||||
spec, err := doltdb.NewCommitSpec(headRef.GetPath())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return spec, nil
|
||||
}
|
||||
|
||||
func (m MemoryRepoState) UpdateStagedRoot(ctx context.Context, newRoot *doltdb.RootValue) error {
|
||||
@@ -120,7 +124,11 @@ func (m MemoryRepoState) UpdateStagedRoot(ctx context.Context, newRoot *doltdb.R
|
||||
ws, err := m.WorkingSet(ctx)
|
||||
if err == doltdb.ErrWorkingSetNotFound {
|
||||
// first time updating root
|
||||
wsRef, err = ref.WorkingSetRefForHead(m.CWBHeadRef())
|
||||
headRef, err := m.CWBHeadRef()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
wsRef, err = ref.WorkingSetRefForHead(headRef)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -146,7 +154,11 @@ func (m MemoryRepoState) UpdateWorkingRoot(ctx context.Context, newRoot *doltdb.
|
||||
ws, err := m.WorkingSet(ctx)
|
||||
if err == doltdb.ErrWorkingSetNotFound {
|
||||
// first time updating root
|
||||
wsRef, err = ref.WorkingSetRefForHead(m.CWBHeadRef())
|
||||
headRef, err := m.CWBHeadRef()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
wsRef, err = ref.WorkingSetRefForHead(headRef)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -166,7 +178,11 @@ func (m MemoryRepoState) UpdateWorkingRoot(ctx context.Context, newRoot *doltdb.
|
||||
}
|
||||
|
||||
func (m MemoryRepoState) WorkingSet(ctx context.Context) (*doltdb.WorkingSet, error) {
|
||||
workingSetRef, err := ref.WorkingSetRefForHead(m.CWBHeadRef())
|
||||
headRef, err := m.CWBHeadRef()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
workingSetRef, err := ref.WorkingSetRefForHead(headRef)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
10
go/libraries/doltcore/env/remotes.go
vendored
10
go/libraries/doltcore/env/remotes.go
vendored
@@ -141,7 +141,10 @@ func NewPushOpts(ctx context.Context, apr *argparser.ArgParseResults, rsr RepoSt
|
||||
}
|
||||
|
||||
remote, remoteOK := remotes[remoteName]
|
||||
currentBranch := rsr.CWBHeadRef()
|
||||
currentBranch, err := rsr.CWBHeadRef()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
branches, err := rsr.GetBranches()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -422,7 +425,10 @@ func NewPullSpec(_ context.Context, rsr RepoStateReader, remoteName, remoteRefNa
|
||||
|
||||
var remoteRef ref.DoltRef
|
||||
if remoteRefName == "" {
|
||||
branch := rsr.CWBHeadRef()
|
||||
branch, err := rsr.CWBHeadRef()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
trackedBranches, err := rsr.GetBranches()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
4
go/libraries/doltcore/env/repo_state.go
vendored
4
go/libraries/doltcore/env/repo_state.go
vendored
@@ -27,8 +27,8 @@ import (
|
||||
|
||||
// TODO: change name to ClientStateReader, move out of env package
|
||||
type RepoStateReader interface {
|
||||
CWBHeadRef() ref.DoltRef
|
||||
CWBHeadSpec() *doltdb.CommitSpec
|
||||
CWBHeadRef() (ref.DoltRef, error)
|
||||
CWBHeadSpec() (*doltdb.CommitSpec, error)
|
||||
GetRemotes() (map[string]Remote, error)
|
||||
GetBackups() (map[string]Remote, error)
|
||||
GetBranches() (map[string]BranchConfig, error)
|
||||
|
||||
@@ -417,14 +417,17 @@ func (db Database) getTableInsensitive(ctx *sql.Context, head *doltdb.Commit, ds
|
||||
|
||||
// resolveAsOf resolves given expression to a commit, if one exists.
|
||||
func resolveAsOf(ctx *sql.Context, db Database, asOf interface{}) (*doltdb.Commit, *doltdb.RootValue, error) {
|
||||
head := db.rsr.CWBHeadRef()
|
||||
head, err := db.rsr.CWBHeadRef()
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
switch x := asOf.(type) {
|
||||
case time.Time:
|
||||
return resolveAsOfTime(ctx, db.ddb, head, x)
|
||||
case string:
|
||||
return resolveAsOfCommitRef(ctx, db, head, x)
|
||||
default:
|
||||
panic(fmt.Sprintf("unsupported AS OF type %T", asOf))
|
||||
return nil, nil, fmt.Errorf("unsupported AS OF type %T", asOf)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -864,7 +864,11 @@ func initialDbState(ctx context.Context, db dsess.SqlDatabase, branch string) (d
|
||||
if len(branch) > 0 {
|
||||
r = ref.NewBranchRef(branch)
|
||||
} else {
|
||||
r = rsr.CWBHeadRef()
|
||||
var err error
|
||||
r, err = rsr.CWBHeadRef()
|
||||
if err != nil {
|
||||
return dsess.InitialDbState{}, err
|
||||
}
|
||||
}
|
||||
|
||||
var retainedErr error
|
||||
@@ -1418,7 +1422,11 @@ func initialStateForCommit(ctx context.Context, srcDb ReadOnlyDatabase) (dsess.I
|
||||
return dsess.InitialDbState{}, err
|
||||
}
|
||||
|
||||
cm, err := srcDb.DbData().Ddb.Resolve(ctx, spec, srcDb.DbData().Rsr.CWBHeadRef())
|
||||
headRef, err := srcDb.DbData().Rsr.CWBHeadRef()
|
||||
if err != nil {
|
||||
return dsess.InitialDbState{}, err
|
||||
}
|
||||
cm, err := srcDb.DbData().Ddb.Resolve(ctx, spec, headRef)
|
||||
if err != nil {
|
||||
return dsess.InitialDbState{}, err
|
||||
}
|
||||
@@ -1448,8 +1456,8 @@ type staticRepoState struct {
|
||||
env.RepoStateReader
|
||||
}
|
||||
|
||||
func (s staticRepoState) CWBHeadRef() ref.DoltRef {
|
||||
return s.branch
|
||||
func (s staticRepoState) CWBHeadRef() (ref.DoltRef, error) {
|
||||
return s.branch, nil
|
||||
}
|
||||
|
||||
// formatDbMapKeyName returns formatted string of database name and/or branch name. Database name is case-insensitive,
|
||||
|
||||
@@ -97,7 +97,10 @@ func doDoltTag(ctx *sql.Context, args []string) (int, error) {
|
||||
if len(apr.Args) > 1 {
|
||||
startPoint = apr.Arg(1)
|
||||
}
|
||||
headRef := dbData.Rsr.CWBHeadRef()
|
||||
headRef, err := dbData.Rsr.CWBHeadRef()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
err = actions.CreateTagOnDB(ctx, dbData.Ddb, tagName, startPoint, props, headRef)
|
||||
if err != nil {
|
||||
return 1, err
|
||||
|
||||
@@ -61,29 +61,30 @@ func (s SessionStateAdapter) GetRoots(ctx context.Context) (doltdb.Roots, error)
|
||||
return state.GetRoots(), nil
|
||||
}
|
||||
|
||||
func (s SessionStateAdapter) CWBHeadRef() ref.DoltRef {
|
||||
func (s SessionStateAdapter) CWBHeadRef() (ref.DoltRef, error) {
|
||||
workingSet, err := s.session.WorkingSet(sql.NewContext(context.Background()), s.dbName)
|
||||
if err != nil {
|
||||
// TODO: fix this interface
|
||||
panic(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
headRef, err := workingSet.Ref().ToHeadRef()
|
||||
// TODO: fix this interface
|
||||
if err != nil {
|
||||
panic(err)
|
||||
return nil, err
|
||||
}
|
||||
return headRef
|
||||
return headRef, nil
|
||||
}
|
||||
|
||||
func (s SessionStateAdapter) CWBHeadSpec() *doltdb.CommitSpec {
|
||||
func (s SessionStateAdapter) CWBHeadSpec() (*doltdb.CommitSpec, error) {
|
||||
// TODO: get rid of this
|
||||
ref := s.CWBHeadRef()
|
||||
ref, err := s.CWBHeadRef()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
spec, err := doltdb.NewCommitSpec(ref.GetPath())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return spec
|
||||
return spec, nil
|
||||
}
|
||||
|
||||
func (s SessionStateAdapter) GetRemotes() (map[string]env.Remote, error) {
|
||||
|
||||
@@ -169,11 +169,18 @@ func drainIter(ctx *sql.Context, iter sql.RowIter) error {
|
||||
return iter.Close(ctx)
|
||||
}
|
||||
|
||||
func getDbState(t *testing.T, db sql.Database, dEnv *env.DoltEnv) dsess.InitialDbState {
|
||||
func getDbState(t *testing.T, db sql.Database, dEnv *env.DoltEnv) (dsess.InitialDbState, error) {
|
||||
ctx := context.Background()
|
||||
|
||||
head := dEnv.RepoStateReader().CWBHeadSpec()
|
||||
headCommit, err := dEnv.DoltDB.Resolve(ctx, head, dEnv.RepoStateReader().CWBHeadRef())
|
||||
headSpec, err := dEnv.RepoStateReader().CWBHeadSpec()
|
||||
if err != nil {
|
||||
return dsess.InitialDbState{}, err
|
||||
}
|
||||
headRef, err := dEnv.RepoStateReader().CWBHeadRef()
|
||||
if err != nil {
|
||||
return dsess.InitialDbState{}, err
|
||||
}
|
||||
headCommit, err := dEnv.DoltDB.Resolve(ctx, headSpec, headRef)
|
||||
require.NoError(t, err)
|
||||
|
||||
ws, err := dEnv.WorkingSet(ctx)
|
||||
@@ -185,5 +192,5 @@ func getDbState(t *testing.T, db sql.Database, dEnv *env.DoltEnv) dsess.InitialD
|
||||
WorkingSet: ws,
|
||||
DbData: dEnv.DbData(),
|
||||
Remotes: dEnv.RepoState.Remotes,
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user