checkout a remote only branch

This commit is contained in:
Brian Hendriks
2019-11-07 12:25:26 -08:00
committed by GitHub
parent acbe3e7b30
commit c8215b4446
2 changed files with 25 additions and 1 deletions

View File

@@ -17,6 +17,8 @@ package commands
import (
"context"
"github.com/liquidata-inc/dolt/go/libraries/doltcore/ref"
"github.com/liquidata-inc/dolt/go/cmd/dolt/cli"
"github.com/liquidata-inc/dolt/go/cmd/dolt/errhand"
"github.com/liquidata-inc/dolt/go/libraries/doltcore/doltdb"
@@ -76,7 +78,24 @@ func Checkout(ctx context.Context, commandStr string, args []string, dEnv *env.D
} else if isBranch {
verr = checkoutBranch(ctx, dEnv, name)
} else {
verr = errhand.BuildDError("error: could not find %s", name).Build()
refs, err := dEnv.DoltDB.GetRefs(ctx)
if err != nil {
verr = errhand.BuildDError("fatal: unable to read from data repository.").AddCause(err).Build()
}
found := false
for _, rf := range refs {
if remRef, ok := rf.(ref.RemoteRef); ok && remRef.GetBranch() == name {
verr = checkoutNewBranch(ctx, dEnv, name, rf.String())
found = true
break
}
}
if !found {
verr = errhand.BuildDError("error: could not find %s", name).Build()
}
}
}

View File

@@ -47,6 +47,11 @@ func (rr RemoteRef) GetRemote() string {
return rr.remote
}
// GetBranch returns the name of a remote branch
func (rr RemoteRef) GetBranch() string {
return rr.branch
}
// NewRemoteRef creates a remote ref from an origin name and a path
func NewRemoteRef(remote, branch string) RemoteRef {
return RemoteRef{remote, branch}