mirror of
https://github.com/dolthub/dolt.git
synced 2026-02-09 03:09:12 -06:00
/{go,integration-tests}: address pr feedback
This commit is contained in:
@@ -313,7 +313,7 @@ func cloneRemote(ctx context.Context, srcDB *doltdb.DoltDB, remoteName, branch s
|
||||
}
|
||||
|
||||
if branch == "" {
|
||||
branch = getDefaultMainOrMaster(dEnv, branches[:])
|
||||
branch = GetDefaultBranch(dEnv, branches)
|
||||
}
|
||||
|
||||
// If we couldn't find a branch but the repo cloned successfully, it's empty. Initialize it instead of pulling from
|
||||
@@ -399,6 +399,7 @@ func cloneRemote(ctx context.Context, srcDB *doltdb.DoltDB, remoteName, branch s
|
||||
func initEmptyClonedRepo(ctx context.Context, dEnv *env.DoltEnv) error {
|
||||
name := dEnv.Config.GetStringOrDefault(env.UserNameKey, "")
|
||||
email := dEnv.Config.GetStringOrDefault(env.UserEmailKey, "")
|
||||
initBranch := env.GetDefaultInitBranch(dEnv.Config)
|
||||
|
||||
if *name == "" {
|
||||
return errhand.BuildDError(fmt.Sprintf("error: could not determine user name. run dolt config --global --add %[1]s", env.UserNameKey)).Build()
|
||||
@@ -406,7 +407,7 @@ func initEmptyClonedRepo(ctx context.Context, dEnv *env.DoltEnv) error {
|
||||
return errhand.BuildDError("error: could not determine email. run dolt config --global --add %[1]s", env.UserEmailKey).Build()
|
||||
}
|
||||
|
||||
err := dEnv.InitDBWithTime(ctx, types.Format_Default, *name, *email, "", doltdb.CommitNowFunc())
|
||||
err := dEnv.InitDBWithTime(ctx, types.Format_Default, *name, *email, initBranch, doltdb.CommitNowFunc())
|
||||
if err != nil {
|
||||
return errhand.BuildDError("error: could not initialize repository").AddCause(err).Build()
|
||||
}
|
||||
@@ -414,10 +415,10 @@ func initEmptyClonedRepo(ctx context.Context, dEnv *env.DoltEnv) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// getDefaultMainOrMaster prioritizes the branches checked out during clone, returning
|
||||
// GetDefaultBranch returns the default branch from among the branches given, returning
|
||||
// the configs default config branch first, then init branch main, then the old init branch master,
|
||||
// and finally the first lexicographical branch if non of the others are found
|
||||
func getDefaultMainOrMaster(dEnv *env.DoltEnv, branches []ref.DoltRef) string {
|
||||
// and finally the first lexicographical branch if none of the others are found
|
||||
func GetDefaultBranch(dEnv *env.DoltEnv, branches []ref.DoltRef) string {
|
||||
if len(branches) == 0 {
|
||||
return env.DefaultInitBranch
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ import (
|
||||
const (
|
||||
emailParamName = "email"
|
||||
usernameParamName = "name"
|
||||
initBranchParamName = "branch"
|
||||
initBranchParamName = "initial-branch"
|
||||
)
|
||||
|
||||
var initDocs = cli.CommandDocumentationContent{
|
||||
@@ -76,7 +76,7 @@ func (cmd InitCmd) createArgParser() *argparser.ArgParser {
|
||||
ap.SupportsString(usernameParamName, "", "name", fmt.Sprintf("The name used in commits to this repo. If not provided will be taken from {{.EmphasisLeft}}%s{{.EmphasisRight}} in the global config.", env.UserNameKey))
|
||||
ap.SupportsString(emailParamName, "", "email", fmt.Sprintf("The email address used. If not provided will be taken from {{.EmphasisLeft}}%s{{.EmphasisRight}} in the global config.", env.UserEmailKey))
|
||||
ap.SupportsString(cli.DateParam, "", "date", "Specify the date used in the initial commit. If not specified the current system time is used.")
|
||||
ap.SupportsString(initBranchParamName, "", "branch", fmt.Sprintf("The branch name used to initialize this database. If not provided will be taken from {{.EmphasisLeft}}%s{{.EmphasisRight}} in the global config. If unset, the default initialized branch will be named '%s'.", env.InitBranchName, env.DefaultInitBranch))
|
||||
ap.SupportsString(initBranchParamName, "b", "branch", fmt.Sprintf("The branch name used to initialize this database. If not provided will be taken from {{.EmphasisLeft}}%s{{.EmphasisRight}} in the global config. If unset, the default initialized branch will be named '%s'.", env.InitBranchName, env.DefaultInitBranch))
|
||||
return ap
|
||||
}
|
||||
|
||||
@@ -93,10 +93,12 @@ func (cmd InitCmd) Exec(ctx context.Context, commandStr string, args []string, d
|
||||
|
||||
name, _ := apr.GetValue(usernameParamName)
|
||||
email, _ := apr.GetValue(emailParamName)
|
||||
initBranch, _ := apr.GetValue(initBranchParamName)
|
||||
name = dEnv.Config.IfEmptyUseConfig(name, env.UserNameKey)
|
||||
email = dEnv.Config.IfEmptyUseConfig(email, env.UserEmailKey)
|
||||
|
||||
initBranch, _ := apr.GetValue(initBranchParamName)
|
||||
if initBranch == "" {
|
||||
initBranch = env.GetDefaultInitBranch(dEnv.Config)
|
||||
}
|
||||
|
||||
if name == "" {
|
||||
cli.PrintErrln(
|
||||
|
||||
@@ -120,7 +120,12 @@ func (cmd ReadTablesCmd) Exec(ctx context.Context, commandStr string, args []str
|
||||
return HandleVErrAndExitCode(verr, usage)
|
||||
}
|
||||
|
||||
dEnv, verr = initializeShallowCloneRepo(ctx, dEnv, srcDB.Format(), dir)
|
||||
branches, err := srcDB.GetBranches(ctx)
|
||||
if verr != nil {
|
||||
BuildVerrAndExit("Failed to get remote branches", err)
|
||||
}
|
||||
|
||||
dEnv, verr = initializeShallowCloneRepo(ctx, dEnv, srcDB.Format(), dir, GetDefaultBranch(dEnv, branches))
|
||||
if verr != nil {
|
||||
return HandleVErrAndExitCode(verr, usage)
|
||||
}
|
||||
@@ -217,7 +222,7 @@ func getRemoteDBAtCommit(ctx context.Context, remoteUrl string, remoteUrlParams
|
||||
return srcDB, srcRoot, nil
|
||||
}
|
||||
|
||||
func initializeShallowCloneRepo(ctx context.Context, dEnv *env.DoltEnv, nbf *types.NomsBinFormat, dir string) (*env.DoltEnv, errhand.VerboseError) {
|
||||
func initializeShallowCloneRepo(ctx context.Context, dEnv *env.DoltEnv, nbf *types.NomsBinFormat, dir, branchName string) (*env.DoltEnv, errhand.VerboseError) {
|
||||
var verr errhand.VerboseError
|
||||
dEnv, verr = envForClone(ctx, nbf, env.NoRemote, dir, dEnv.FS, dEnv.Version)
|
||||
|
||||
@@ -230,7 +235,7 @@ func initializeShallowCloneRepo(ctx context.Context, dEnv *env.DoltEnv, nbf *typ
|
||||
return nil, errhand.BuildDError("Unable to initialize repo.").AddCause(err).Build()
|
||||
}
|
||||
|
||||
err = dEnv.InitializeRepoState(ctx, "")
|
||||
err = dEnv.InitializeRepoState(ctx, branchName)
|
||||
|
||||
if err != nil {
|
||||
return nil, errhand.BuildDError("Unable to initialize repo.").AddCause(err).Build()
|
||||
|
||||
@@ -51,7 +51,7 @@ func CreateTestEnv() *env.DoltEnv {
|
||||
env.UserNameKey: name,
|
||||
env.UserEmailKey: email,
|
||||
})
|
||||
err := dEnv.InitRepo(context.Background(), types.Format_Default, name, email, "")
|
||||
err := dEnv.InitRepo(context.Background(), types.Format_Default, name, email, "main")
|
||||
|
||||
if err != nil {
|
||||
panic("Failed to initialize environment:" + err.Error())
|
||||
|
||||
2
go/libraries/doltcore/env/actions/branch.go
vendored
2
go/libraries/doltcore/env/actions/branch.go
vendored
@@ -28,7 +28,7 @@ import (
|
||||
|
||||
var ErrAlreadyExists = errors.New("already exists")
|
||||
var ErrCOBranchDelete = errors.New("attempted to delete checked out branch")
|
||||
var ErrUnmergedBranchDelete = errors.New("attempted to delete a branch that is not fully merged into main; use `-f` to force")
|
||||
var ErrUnmergedBranchDelete = errors.New("attempted to delete a branch that is not fully merged into its parent; use `-f` to force")
|
||||
|
||||
func RenameBranch(ctx context.Context, dEnv *env.DoltEnv, oldBranch, newBranch string, force bool) error {
|
||||
oldRef := ref.NewBranchRef(oldBranch)
|
||||
|
||||
@@ -48,7 +48,7 @@ func createUninitializedEnv() *env.DoltEnv {
|
||||
|
||||
func TestGetDotDotRevisions(t *testing.T) {
|
||||
env := createUninitializedEnv()
|
||||
err := env.InitRepo(context.Background(), types.Format_LD_1, "Bill Billerson", "bill@billerson.com", "")
|
||||
err := env.InitRepo(context.Background(), types.Format_LD_1, "Bill Billerson", "bill@billerson.com", "main")
|
||||
require.NoError(t, err)
|
||||
|
||||
cs, err := doltdb.NewCommitSpec("main")
|
||||
@@ -218,7 +218,7 @@ func mustForkDB(t *testing.T, fromDB *doltdb.DoltDB, bn string, cm *doltdb.Commi
|
||||
stref, err := cm.GetStRef()
|
||||
require.NoError(t, err)
|
||||
forkEnv := createUninitializedEnv()
|
||||
err = forkEnv.InitRepo(context.Background(), types.Format_LD_1, "Bill Billerson", "bill@billerson.com", "")
|
||||
err = forkEnv.InitRepo(context.Background(), types.Format_LD_1, "Bill Billerson", "bill@billerson.com", "main")
|
||||
require.NoError(t, err)
|
||||
p1 := make(chan datas.PullProgress)
|
||||
p2 := make(chan datas.PullerEvent)
|
||||
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/ref"
|
||||
)
|
||||
|
||||
var ErrUnmergedWorkspaceDelete = errors.New("attempted to delete a workspace that is not fully merged into main; use `-f` to force")
|
||||
var ErrUnmergedWorkspaceDelete = errors.New("attempted to delete a workspace that is not fully merged into its parent; use `-f` to force")
|
||||
var ErrCOWorkspaceDelete = errors.New("attempted to delete checked out workspace")
|
||||
var ErrBranchNameExists = errors.New("workspace name must not be existing branch name")
|
||||
|
||||
|
||||
16
go/libraries/doltcore/env/environment.go
vendored
16
go/libraries/doltcore/env/environment.go
vendored
@@ -451,12 +451,7 @@ func (dEnv *DoltEnv) InitDBWithTime(ctx context.Context, nbf *types.NomsBinForma
|
||||
return err
|
||||
}
|
||||
|
||||
initBranch := GetDefaultInitBranch(dEnv.Config)
|
||||
if branchName != "" {
|
||||
initBranch = branchName
|
||||
}
|
||||
|
||||
err = dEnv.DoltDB.WriteEmptyRepoWithCommitTime(ctx, initBranch, name, email, t)
|
||||
err = dEnv.DoltDB.WriteEmptyRepoWithCommitTime(ctx, branchName, name, email, t)
|
||||
if err != nil {
|
||||
return doltdb.ErrNomsIO
|
||||
}
|
||||
@@ -466,12 +461,7 @@ func (dEnv *DoltEnv) InitDBWithTime(ctx context.Context, nbf *types.NomsBinForma
|
||||
|
||||
// InitializeRepoState writes a default repo state to disk, consisting of a main branch and current root hash value.
|
||||
func (dEnv *DoltEnv) InitializeRepoState(ctx context.Context, branchName string) error {
|
||||
initBranch := GetDefaultInitBranch(dEnv.Config)
|
||||
if branchName != "" {
|
||||
initBranch = branchName
|
||||
}
|
||||
|
||||
commit, err := dEnv.DoltDB.ResolveCommitRef(ctx, ref.NewBranchRef(initBranch))
|
||||
commit, err := dEnv.DoltDB.ResolveCommitRef(ctx, ref.NewBranchRef(branchName))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -481,7 +471,7 @@ func (dEnv *DoltEnv) InitializeRepoState(ctx context.Context, branchName string)
|
||||
return err
|
||||
}
|
||||
|
||||
dEnv.RepoState, err = CreateRepoState(dEnv.FS, initBranch)
|
||||
dEnv.RepoState, err = CreateRepoState(dEnv.FS, branchName)
|
||||
if err != nil {
|
||||
return ErrStateUpdate
|
||||
}
|
||||
|
||||
@@ -122,12 +122,12 @@ func (h *DoltHarness) ExecuteQuery(statement string) (schema string, results []s
|
||||
|
||||
func innerInit(h *DoltHarness, dEnv *env.DoltEnv) error {
|
||||
if !dEnv.HasDoltDir() {
|
||||
err := dEnv.InitRepoWithTime(context.Background(), types.Format_Default, name, email, "", time.Now())
|
||||
err := dEnv.InitRepoWithTime(context.Background(), types.Format_Default, name, email, "main", time.Now())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
err := dEnv.InitDBAndRepoState(context.Background(), types.Format_Default, name, email, "", time.Now())
|
||||
err := dEnv.InitDBAndRepoState(context.Background(), types.Format_Default, name, email, "main", time.Now())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ func createTestEnvWithFS(fs filesys.Filesys, workingDir string) *env.DoltEnv {
|
||||
const name = "test mcgibbins"
|
||||
const email = "bigfakeytester@fake.horse"
|
||||
dEnv := env.Load(context.Background(), testHomeDirFunc, fs, doltdb.InMemDoltDB, "test")
|
||||
err := dEnv.InitRepo(context.Background(), types.Format_Default, name, email, "")
|
||||
err := dEnv.InitRepo(context.Background(), types.Format_Default, name, email, "main")
|
||||
if err != nil {
|
||||
panic("Failed to initialize environment")
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ func WriteValueFile(ctx context.Context, filepath string, store *FileValueStore,
|
||||
// WriteToWriter writes the values out to the provided writer in the value file format
|
||||
func WriteToWriter(ctx context.Context, wr io.Writer, store *FileValueStore, values ...types.Value) error {
|
||||
db := datas.NewDatabase(store)
|
||||
ds, err := db.GetDataset(ctx, env.DefaultInitBranch) // TODO: DUSTIN
|
||||
ds, err := db.GetDataset(ctx, env.DefaultInitBranch)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -192,19 +192,19 @@ teardown() {
|
||||
dolt config --global --add user.name "bats tester"
|
||||
dolt config --global --add user.email "joshn@doe.com"
|
||||
|
||||
dolt config --global --add init.defaultBranch "main"
|
||||
dolt config --global --add init.defaultBranch "master"
|
||||
dolt config --list
|
||||
run dolt config --list
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "init.defaultbranch = main" ]]
|
||||
[[ "$output" =~ "init.defaultbranch = master" ]]
|
||||
|
||||
dolt init
|
||||
run dolt status
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "On branch main" ]]
|
||||
[[ "$output" =~ "On branch master" ]]
|
||||
run dolt branch
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "* main" ]]
|
||||
[[ "$output" =~ "* master" ]]
|
||||
|
||||
# cleanup
|
||||
dolt config --global --unset init.defaultBranch
|
||||
@@ -227,7 +227,7 @@ teardown() {
|
||||
dolt config --global --add user.name "bats tester"
|
||||
dolt config --global --add user.email "joshn@doe.com"
|
||||
|
||||
dolt init --branch=vegan-btw
|
||||
dolt init -b=vegan-btw
|
||||
run dolt status
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "On branch vegan-btw" ]]
|
||||
|
||||
Reference in New Issue
Block a user