PR comments

This commit is contained in:
Stephanie You
2023-12-04 10:00:58 -08:00
parent 90b62c8bd7
commit 4ec6d2b9fe
3 changed files with 42 additions and 11 deletions

View File

@@ -125,7 +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.")
ap.SupportsFlag(SingleBranchFlag, "", "Clone only the history leading to the tip of a single branch, either specified by --branch or the remote's HEAD (default).")
return ap
}

View File

@@ -214,27 +214,28 @@ func CloneRemote(ctx context.Context, srcDB *doltdb.DoltDB, remoteName, branch s
// every branch in the remote. We iterate through local branches and
// 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 {
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())
for _, br := range branches {
if !singleBranch || (singleBranch && br.GetPath() == branch) {
cs, _ := doltdb.NewCommitSpec(br.GetPath())
cm, err := dEnv.DoltDB.Resolve(ctx, cs, nil)
if err != nil {
return fmt.Errorf("%w: %s; %s", ErrFailedToResolveBranchRef, brnch.String(), err.Error())
return fmt.Errorf("%w: %s; %s", ErrFailedToResolveBranchRef, br.String(), err.Error())
}
remoteRef := ref.NewRemoteRef(remoteName, brnch.GetPath())
remoteRef := ref.NewRemoteRef(remoteName, br.GetPath())
err = dEnv.DoltDB.SetHeadToCommit(ctx, remoteRef, cm)
if err != nil {
return fmt.Errorf("%w: %s; %s", ErrFailedToCreateRemoteRef, remoteRef.String(), err.Error())
}
}
if br.GetPath() != branch {
err := dEnv.DoltDB.DeleteBranch(ctx, br, nil)
if err != nil {
return fmt.Errorf("%w: %s; %s", ErrFailedToDeleteBranch, br.String(), err.Error())
}
}
}
// TODO: make this interface take a DoltRef and marshal it automatically

View File

@@ -1023,6 +1023,36 @@ create_five_remote_branches_main_and_master() {
[[ ! "$output" =~ "remotes/origin/branch-two" ]] || false
}
@test "remotes: clone --branch specifies which branch to clone" {
create_three_remote_branches
cd dolt-repo-clones
dolt clone --branch branch-one http://localhost:50051/test-org/test-repo
cd test-repo
run dolt branch -a
[ "$status" -eq 0 ]
[[ "$output" =~ "* branch-one" ]] || false
[[ ! "$output" =~ " main" ]] || false
[[ ! "$output" =~ " branch-two" ]] || false
[[ "$output" =~ "remotes/origin/main" ]] || false
[[ "$output" =~ "remotes/origin/branch-one" ]] || false
[[ "$output" =~ "remotes/origin/branch-two" ]] || false
}
@test "remotes: clone --single-branch --branch does not create all remote refs" {
create_three_remote_branches
cd dolt-repo-clones
dolt clone --branch branch-one --single-branch http://localhost:50051/test-org/test-repo
cd test-repo
run dolt branch -a
[ "$status" -eq 0 ]
[[ "$output" =~ "* branch-one" ]] || false
[[ ! "$output" =~ " main" ]] || 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