mirror of
https://github.com/dolthub/dolt.git
synced 2026-03-01 10:09:41 -06:00
adds --single-branch for dolt clone
This commit is contained in:
@@ -125,6 +125,7 @@ func CreateCloneArgParser() *argparser.ArgParser {
|
||||
ap.SupportsString(dbfactory.OSSCredsFileParam, "", "file", "OSS credentials file.")
|
||||
ap.SupportsString(dbfactory.OSSCredsProfile, "", "profile", "OSS profile to use.")
|
||||
ap.SupportsString(UserFlag, "u", "user", "User name to use when authenticating with the remote. Gets password from the environment variable {{.EmphasisLeft}}DOLT_REMOTE_PASSWORD{{.EmphasisRight}}.")
|
||||
ap.SupportsFlag(SingleBranchFlag, "", "Clone only the history leading to the tip of a single branch, either specified by --branch or the primary branch remote's HEAD points at.")
|
||||
return ap
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,7 @@ const (
|
||||
ShallowFlag = "shallow"
|
||||
ShowIgnoredFlag = "ignored"
|
||||
SilentFlag = "silent"
|
||||
SingleBranchFlag = "single-branch"
|
||||
SkipEmptyFlag = "skip-empty"
|
||||
SoftResetParam = "soft"
|
||||
SquashParam = "squash"
|
||||
|
||||
@@ -98,6 +98,7 @@ func (cmd CloneCmd) Exec(ctx context.Context, commandStr string, args []string,
|
||||
func clone(ctx context.Context, apr *argparser.ArgParseResults, dEnv *env.DoltEnv) errhand.VerboseError {
|
||||
remoteName := apr.GetValueOrDefault(cli.RemoteParam, "origin")
|
||||
branch := apr.GetValueOrDefault(cli.BranchParam, "")
|
||||
singleBranch := apr.Contains(cli.SingleBranchFlag)
|
||||
dir, urlStr, verr := parseArgs(apr)
|
||||
if verr != nil {
|
||||
return verr
|
||||
@@ -143,7 +144,7 @@ func clone(ctx context.Context, apr *argparser.ArgParseResults, dEnv *env.DoltEn
|
||||
// Nil out the old Dolt env so we don't accidentally operate on the wrong database
|
||||
dEnv = nil
|
||||
|
||||
err = actions.CloneRemote(ctx, srcDB, remoteName, branch, clonedEnv)
|
||||
err = actions.CloneRemote(ctx, srcDB, remoteName, branch, singleBranch, clonedEnv)
|
||||
if err != nil {
|
||||
// If we're cloning into a directory that already exists do not erase it. Otherwise
|
||||
// make best effort to delete the directory we created.
|
||||
|
||||
30
go/libraries/doltcore/env/actions/clone.go
vendored
30
go/libraries/doltcore/env/actions/clone.go
vendored
@@ -156,7 +156,7 @@ func sortedKeys(m map[string]iohelp.ReadStats) []string {
|
||||
return keys
|
||||
}
|
||||
|
||||
func CloneRemote(ctx context.Context, srcDB *doltdb.DoltDB, remoteName, branch string, dEnv *env.DoltEnv) error {
|
||||
func CloneRemote(ctx context.Context, srcDB *doltdb.DoltDB, remoteName, branch string, singleBranch bool, dEnv *env.DoltEnv) error {
|
||||
eventCh := make(chan pull.TableFileEvent, 128)
|
||||
|
||||
wg := &sync.WaitGroup{}
|
||||
@@ -215,25 +215,25 @@ func CloneRemote(ctx context.Context, srcDB *doltdb.DoltDB, remoteName, branch s
|
||||
// create remote refs corresponding to each of them. We delete all of
|
||||
// the local branches except for the one corresponding to |branch|.
|
||||
for _, brnch := range branches {
|
||||
cs, _ := doltdb.NewCommitSpec(brnch.GetPath())
|
||||
cm, err := dEnv.DoltDB.Resolve(ctx, cs, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: %s; %s", ErrFailedToResolveBranchRef, brnch.String(), err.Error())
|
||||
|
||||
}
|
||||
|
||||
remoteRef := ref.NewRemoteRef(remoteName, brnch.GetPath())
|
||||
err = dEnv.DoltDB.SetHeadToCommit(ctx, remoteRef, cm)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: %s; %s", ErrFailedToCreateRemoteRef, remoteRef.String(), err.Error())
|
||||
|
||||
}
|
||||
|
||||
if brnch.GetPath() != branch {
|
||||
err := dEnv.DoltDB.DeleteBranch(ctx, brnch, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: %s; %s", ErrFailedToDeleteBranch, brnch.String(), err.Error())
|
||||
}
|
||||
} else if !singleBranch || brnch.GetPath() == branch {
|
||||
cs, _ := doltdb.NewCommitSpec(brnch.GetPath())
|
||||
cm, err := dEnv.DoltDB.Resolve(ctx, cs, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: %s; %s", ErrFailedToResolveBranchRef, brnch.String(), err.Error())
|
||||
|
||||
}
|
||||
|
||||
remoteRef := ref.NewRemoteRef(remoteName, brnch.GetPath())
|
||||
err = dEnv.DoltDB.SetHeadToCommit(ctx, remoteRef, cm)
|
||||
if err != nil {
|
||||
return fmt.Errorf("%w: %s; %s", ErrFailedToCreateRemoteRef, remoteRef.String(), err.Error())
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -527,7 +527,7 @@ func (p *DoltDatabaseProvider) cloneDatabaseFromRemote(
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = actions.CloneRemote(ctx, srcDB, remoteName, branch, dEnv)
|
||||
err = actions.CloneRemote(ctx, srcDB, remoteName, branch, false, dEnv)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -1008,6 +1008,21 @@ create_five_remote_branches_main_and_master() {
|
||||
[[ "$output" =~ "remotes/origin/branch-two" ]] || false
|
||||
}
|
||||
|
||||
@test "remotes: clone --single-branch does not create remote refs for all remote branches" {
|
||||
create_three_remote_branches
|
||||
cd dolt-repo-clones
|
||||
dolt clone --single-branch http://localhost:50051/test-org/test-repo
|
||||
cd test-repo
|
||||
run dolt branch -a
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "* main" ]] || false
|
||||
[[ ! "$output" =~ " branch-one" ]] || false
|
||||
[[ ! "$output" =~ " branch-two" ]] || false
|
||||
[[ "$output" =~ "remotes/origin/main" ]] || false
|
||||
[[ ! "$output" =~ "remotes/origin/branch-one" ]] || false
|
||||
[[ ! "$output" =~ "remotes/origin/branch-two" ]] || false
|
||||
}
|
||||
|
||||
@test "remotes: fetch creates new remote refs for new remote branches" {
|
||||
create_main_remote_branch
|
||||
|
||||
|
||||
Reference in New Issue
Block a user