diff --git a/go/cmd/dolt/commands/clone.go b/go/cmd/dolt/commands/clone.go index 112ba2a579..c5e39deaca 100644 --- a/go/cmd/dolt/commands/clone.go +++ b/go/cmd/dolt/commands/clone.go @@ -26,10 +26,18 @@ const ( branchParam = "branch" ) -var cloneShortDesc = "" -var cloneLongDesc = "" +var cloneShortDesc = "Clone a data repository into a new directory" +var cloneLongDesc = "Clones a repository into a newly created directory, creates remote-tracking branches for each " + + "branch in the cloned repository (visible using git branch -a), and creates and checks out an initial branch that " + + "is forked from the cloned repository's currently active branch.\n" + + "\n" + + "After the clone, a plain dolt fetch without arguments will update all the remote-tracking branches, and a dolt " + + "pull without arguments will in addition merge the remote branch into the current branch\n" + + "\n" + + "This default configuration is achieved by creating references to the remote branch heads under refs/remotes/origin " + + "and by creating a remote named 'origin'." var cloneSynopsis = []string{ - "[-remote ] [-branch ] ", + "[-remote ] [-branch ] [--aws-region ] [--aws-creds-type ] [--aws-creds-file ] [--aws-creds-profile ] ", } func Clone(commandStr string, args []string, dEnv *env.DoltEnv) int { diff --git a/go/cmd/dolt/commands/remote.go b/go/cmd/dolt/commands/remote.go index aad1664165..297e69346c 100644 --- a/go/cmd/dolt/commands/remote.go +++ b/go/cmd/dolt/commands/remote.go @@ -56,7 +56,7 @@ var remoteLongDesc = "With no arguments, shows a list of existing remotes. Sever var remoteSynopsis = []string{ "[-v | --verbose]", - "add [--aws-region ] [--aws-creds-type ] [--aws-creds-file ] ", + "add [--aws-region ] [--aws-creds-type ] [--aws-creds-file ] [--aws-creds-profile ] ", "rename ", "remove ", } @@ -76,6 +76,7 @@ func Remote(commandStr string, args []string, dEnv *env.DoltEnv) int { ap := argparser.NewArgParser() ap.ArgListHelp["region"] = "cloud provider region associated with this remote." ap.ArgListHelp["creds-type"] = "credential type. Valid options are role, env, and file. See the help section for additional details." + ap.ArgListHelp["profile"] = "AWS profile to use." ap.SupportsFlag(verboseFlag, "v", "When printing the list of remotes adds additional details.") ap.SupportsString(dbfactory.AWSRegionParam, "", "region", "") ap.SupportsValidatedString(dbfactory.AWSCredsTypeParam, "", "creds-type", "", argparser.ValidatorFromStrList(dbfactory.AWSCredsTypeParam, credTypes)) diff --git a/go/libraries/doltcore/dbfactory/aws.go b/go/libraries/doltcore/dbfactory/aws.go index 30ba6431d2..38d51535b7 100644 --- a/go/libraries/doltcore/dbfactory/aws.go +++ b/go/libraries/doltcore/dbfactory/aws.go @@ -141,7 +141,9 @@ func validatePath(path string) (string, error) { pathLen-- } - if strings.Index(path, "/") != -1 { + // Should probably have regex validation of a valid database name here once we decide what valid database names look + // like. + if len(path) == 0 || strings.Index(path, "/") != -1 { return "", errors.New("invalid database name") } diff --git a/go/libraries/doltcore/dbfactory/aws_test.go b/go/libraries/doltcore/dbfactory/aws_test.go new file mode 100644 index 0000000000..0f6ac64568 --- /dev/null +++ b/go/libraries/doltcore/dbfactory/aws_test.go @@ -0,0 +1,66 @@ +package dbfactory + +import ( + "github.com/stretchr/testify/assert" + "testing" +) + +func TestAWSPathValidation(t *testing.T) { + tests := []struct { + name string + path string + expectedPath string + expectErr bool + }{ + { + "empty path", + "", + "", + true, + }, + { + "basic", + "database", + "database", + false, + }, + { + "slash prefix", + "/database", + "database", + false, + }, + { + "slash suffix", + "database/", + "database", + false, + }, + { + "slash prefix and suffix", + "/database/", + "database", + false, + }, + { + "slash in the middle", + "/data/base/", + "", + true, + }, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + actualPath, actualErr := validatePath(test.path) + + assert.Equal(t, actualPath, test.expectedPath) + + if test.expectErr { + assert.Error(t, actualErr, "Did not expect an error") + } else { + assert.NoError(t, actualErr, "Expected an error") + } + }) + } +} diff --git a/go/libraries/doltcore/dbfactory/factory_test.go b/go/libraries/doltcore/dbfactory/factory_test.go new file mode 100644 index 0000000000..12aebee84f --- /dev/null +++ b/go/libraries/doltcore/dbfactory/factory_test.go @@ -0,0 +1,43 @@ +package dbfactory + +import ( + "context" + "github.com/attic-labs/noms/go/types" + "github.com/stretchr/testify/assert" + "testing" +) + +func TestCreateFileDB(t *testing.T) { + ctx := context.Background() + + db, err := CreateDB(ctx, "file://testdata/", nil) + + assert.NoError(t, err) + + datasets := db.Datasets(ctx) + + assert.Equal(t, int(datasets.Len()), 2) + + master, masterOK := datasets.MaybeGet(ctx, types.String("refs/heads/master")) + assert.True(t, masterOK) + + masterVal := master.(types.Ref).TargetValue(ctx, db) + assert.NotNil(t, masterVal) + + create, createOK := datasets.MaybeGet(ctx, types.String("refs/internal/create")) + assert.True(t, createOK) + + createVal := create.(types.Ref).TargetValue(ctx, db) + assert.NotNil(t, createVal) + + _, fakeOK := datasets.MaybeGet(ctx, types.String("refs/heads/fake")) + assert.False(t, fakeOK) +} + +func TestCreateMemDB(t *testing.T) { + ctx := context.Background() + db, err := CreateDB(ctx, "mem://", nil) + + assert.NoError(t, err) + assert.NotNil(t, db) +} diff --git a/go/libraries/doltcore/dbfactory/testdata/.dolt/config.json b/go/libraries/doltcore/dbfactory/testdata/.dolt/config.json new file mode 100755 index 0000000000..9e26dfeeb6 --- /dev/null +++ b/go/libraries/doltcore/dbfactory/testdata/.dolt/config.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/3qr85kk4r4tobjvh80dujletthct2cr3 b/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/3qr85kk4r4tobjvh80dujletthct2cr3 new file mode 100644 index 0000000000..fe640c579f Binary files /dev/null and b/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/3qr85kk4r4tobjvh80dujletthct2cr3 differ diff --git a/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/4bujnjuatdli0klda7ucot0tl836jujt b/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/4bujnjuatdli0klda7ucot0tl836jujt new file mode 100644 index 0000000000..c41b419f7c Binary files /dev/null and b/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/4bujnjuatdli0klda7ucot0tl836jujt differ diff --git a/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/5cikgaumcp6n04u1hq2memjmfq7a95fm b/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/5cikgaumcp6n04u1hq2memjmfq7a95fm new file mode 100644 index 0000000000..3b5b7a20b7 Binary files /dev/null and b/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/5cikgaumcp6n04u1hq2memjmfq7a95fm differ diff --git a/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/6n6j25hjb3akcri05fkbtaj24mtpcemi b/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/6n6j25hjb3akcri05fkbtaj24mtpcemi new file mode 100644 index 0000000000..129a66afb1 Binary files /dev/null and b/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/6n6j25hjb3akcri05fkbtaj24mtpcemi differ diff --git a/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/LOCK b/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/LOCK new file mode 100644 index 0000000000..e69de29bb2 diff --git a/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/aejlvev89jfts7q5s7ti6koo1gacrsts b/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/aejlvev89jfts7q5s7ti6koo1gacrsts new file mode 100644 index 0000000000..2e72188895 Binary files /dev/null and b/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/aejlvev89jfts7q5s7ti6koo1gacrsts differ diff --git a/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/e1odhsfrvvklnuh2n5cggo44fmvndr8q b/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/e1odhsfrvvklnuh2n5cggo44fmvndr8q new file mode 100644 index 0000000000..6d8ed13464 Binary files /dev/null and b/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/e1odhsfrvvklnuh2n5cggo44fmvndr8q differ diff --git a/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/i80ob4hj9d797nqvpn2190q52pistj5v b/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/i80ob4hj9d797nqvpn2190q52pistj5v new file mode 100644 index 0000000000..8e211ed117 Binary files /dev/null and b/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/i80ob4hj9d797nqvpn2190q52pistj5v differ diff --git a/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/llm37m4bvu362vnkkbfi7r37d58ijigq b/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/llm37m4bvu362vnkkbfi7r37d58ijigq new file mode 100644 index 0000000000..95ba0a3fd7 Binary files /dev/null and b/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/llm37m4bvu362vnkkbfi7r37d58ijigq differ diff --git a/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/manifest b/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/manifest new file mode 100644 index 0000000000..c57721e5d7 --- /dev/null +++ b/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/manifest @@ -0,0 +1 @@ +4:7.18:eqacm9kvt0cjrrg3pp4epa8bqeo0u582:6l57vgii8u337ahfcpe8r0sku8agdpg7:um7eif38t3jh0i0hutoelu1ded8qbqhr:2:aejlvev89jfts7q5s7ti6koo1gacrsts:1:llm37m4bvu362vnkkbfi7r37d58ijigq:1:e1odhsfrvvklnuh2n5cggo44fmvndr8q:1:i80ob4hj9d797nqvpn2190q52pistj5v:5:5cikgaumcp6n04u1hq2memjmfq7a95fm:1:3qr85kk4r4tobjvh80dujletthct2cr3:2:4bujnjuatdli0klda7ucot0tl836jujt:1:6n6j25hjb3akcri05fkbtaj24mtpcemi:4 \ No newline at end of file diff --git a/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/um7eif38t3jh0i0hutoelu1ded8qbqhr b/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/um7eif38t3jh0i0hutoelu1ded8qbqhr new file mode 100644 index 0000000000..8906c68952 Binary files /dev/null and b/go/libraries/doltcore/dbfactory/testdata/.dolt/noms/um7eif38t3jh0i0hutoelu1ded8qbqhr differ diff --git a/go/libraries/doltcore/dbfactory/testdata/.dolt/repo_state.json b/go/libraries/doltcore/dbfactory/testdata/.dolt/repo_state.json new file mode 100755 index 0000000000..54f95d34ff --- /dev/null +++ b/go/libraries/doltcore/dbfactory/testdata/.dolt/repo_state.json @@ -0,0 +1,8 @@ +{ + "head": "refs/heads/master", + "staged": "1dpev4iss2fv0cbe6261lsfd6kcs24br", + "working": "1dpev4iss2fv0cbe6261lsfd6kcs24br", + "merge": null, + "remotes": null, + "branches": null +} \ No newline at end of file