From 4ec6d2b9fe8352ecdabdc3697177a04f1fde4df0 Mon Sep 17 00:00:00 2001 From: Stephanie You Date: Mon, 4 Dec 2023 10:00:58 -0800 Subject: [PATCH] PR comments --- go/cmd/dolt/cli/arg_parser_helpers.go | 2 +- go/libraries/doltcore/env/actions/clone.go | 21 +++++++-------- integration-tests/bats/remotes.bats | 30 ++++++++++++++++++++++ 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/go/cmd/dolt/cli/arg_parser_helpers.go b/go/cmd/dolt/cli/arg_parser_helpers.go index eb8cd1ae06..0a04e0f20b 100644 --- a/go/cmd/dolt/cli/arg_parser_helpers.go +++ b/go/cmd/dolt/cli/arg_parser_helpers.go @@ -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 } diff --git a/go/libraries/doltcore/env/actions/clone.go b/go/libraries/doltcore/env/actions/clone.go index 82d5de273a..e0cac4b902 100644 --- a/go/libraries/doltcore/env/actions/clone.go +++ b/go/libraries/doltcore/env/actions/clone.go @@ -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 diff --git a/integration-tests/bats/remotes.bats b/integration-tests/bats/remotes.bats index 0dd65d7d5e..26dbfffb9b 100644 --- a/integration-tests/bats/remotes.bats +++ b/integration-tests/bats/remotes.bats @@ -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