diff --git a/go/cmd/dolt/commands/log.go b/go/cmd/dolt/commands/log.go index 9bf6c839a3..1489ce1001 100644 --- a/go/cmd/dolt/commands/log.go +++ b/go/cmd/dolt/commands/log.go @@ -141,9 +141,26 @@ func constructInterpolatedDoltLogQuery(apr *argparser.ArgParseResults) (string, first = false } - for _, args := range apr.Args { - writeToBuffer("?", true) - params = append(params, args) + if apr.PositionalArgsSeparatorIndex >= 0 { + for i := 0; i < apr.PositionalArgsSeparatorIndex; i++ { + writeToBuffer("?", true) + params = append(params, apr.Arg(i)) + } + tableNames := "" + for i := apr.PositionalArgsSeparatorIndex; i < apr.NArg(); i++ { + tableNames = tableNames + "?," + params = append(params, apr.Arg(i)) + } + if tableNames != "" { + tableNames = strings.TrimSuffix(tableNames, ",") + writeToBuffer("--tables", false) + writeToBuffer(tableNames, true) + } + } else { + for _, arg := range apr.Args { + writeToBuffer("?", true) + params = append(params, arg) + } } if minParents, hasMinParents := apr.GetValue(cli.MinParentsFlag); hasMinParents { diff --git a/go/libraries/utils/argparser/args_test.go b/go/libraries/utils/argparser/args_test.go index bbbb86a0bd..aa1c0742f1 100644 --- a/go/libraries/utils/argparser/args_test.go +++ b/go/libraries/utils/argparser/args_test.go @@ -201,7 +201,7 @@ func TestParsing(t *testing.T) { parser.SupportOption(opt) } - exp := &ArgParseResults{test.expectedOpts, test.expectedArgs, parser} + exp := &ArgParseResults{test.expectedOpts, test.expectedArgs, parser, -1} res, err := parser.Parse(test.args) if test.expectedErr != "" { diff --git a/go/libraries/utils/argparser/parser.go b/go/libraries/utils/argparser/parser.go index 05d91f2735..5c68eefba2 100644 --- a/go/libraries/utils/argparser/parser.go +++ b/go/libraries/utils/argparser/parser.go @@ -285,7 +285,7 @@ func (ap *ArgParser) ParseGlobalArgs(args []string) (apr *ArgParseResults, remai if arg[0] != '-' { // This isn't a flag; assume it's the subcommand. Don't parse the remaining args. - return &ArgParseResults{results, nil, ap}, args[i:], nil + return &ArgParseResults{results, nil, ap, -1}, args[i:], nil } var err error @@ -304,6 +304,7 @@ func (ap *ArgParser) ParseGlobalArgs(args []string) (apr *ArgParseResults, remai // universal --help or -h flag is found, an ErrHelp error is returned. func (ap *ArgParser) Parse(args []string) (*ArgParseResults, error) { positionalArgs := make([]string, 0, 16) + positionalArgsSeparatorIndex := -1 namedArgs := make(map[string]string) onlyPositionalArgsLeft := false @@ -319,6 +320,7 @@ func (ap *ArgParser) Parse(args []string) (*ArgParseResults, error) { if arg == "--" { onlyPositionalArgsLeft = true + positionalArgsSeparatorIndex = len(positionalArgs) continue } @@ -338,7 +340,7 @@ func (ap *ArgParser) Parse(args []string) (*ArgParseResults, error) { return nil, ap.TooManyArgsErrorFunc(positionalArgs) } - return &ArgParseResults{namedArgs, positionalArgs, ap}, nil + return &ArgParseResults{namedArgs, positionalArgs, ap, positionalArgsSeparatorIndex}, nil } func (ap *ArgParser) parseToken(args []string, index int, positionalArgs []string, namedArgs map[string]string) (newIndex int, newPositionalArgs []string, newNamedArgs map[string]string, err error) { diff --git a/go/libraries/utils/argparser/results.go b/go/libraries/utils/argparser/results.go index d914c965ed..c021ff5815 100644 --- a/go/libraries/utils/argparser/results.go +++ b/go/libraries/utils/argparser/results.go @@ -26,6 +26,8 @@ type ArgParseResults struct { options map[string]string Args []string parser *ArgParser + + PositionalArgsSeparatorIndex int } // Equals res and other are only considered equal if the order and contents of their arguments @@ -135,7 +137,7 @@ func (res *ArgParseResults) DropValue(name string) *ArgParseResults { } } - return &ArgParseResults{newNamedArgs, res.Args, res.parser} + return &ArgParseResults{newNamedArgs, res.Args, res.parser, -1} } func (res *ArgParseResults) MustGetValue(name string) string { diff --git a/integration-tests/bats/log.bats b/integration-tests/bats/log.bats index 277e236dbe..4ff339828f 100755 --- a/integration-tests/bats/log.bats +++ b/integration-tests/bats/log.bats @@ -147,7 +147,6 @@ teardown() { [[ "$output" =~ "BRANCHA" ]] || false run dolt log main branchA --not $(dolt merge-base main branchA) [ $status -eq 0 ] - echo $output [[ ! "$output" =~ "MAIN" ]] || false [[ "$output" =~ "AFTER" ]] || false [[ "$output" =~ "BRANCHA" ]] || false @@ -239,8 +238,6 @@ teardown() { [ $status -eq 1 ] run dolt log testtable ^main [ $status -eq 1 ] - run dolt log ^branchA --not main - [ $status -eq 1 ] run dolt log main..branchA --not main [ $status -eq 1 ] run dolt log main..branchA --not ^main @@ -268,15 +265,14 @@ teardown() { [[ "$output" =~ "BRANCH1" ]] || false # Should default to first argument as branch name, second argument as table name (if table exists) if two arguments provided - run dolt log myname myname + run dolt log myname -- myname [ $status -eq 0 ] - echo $output [[ ! "$output" =~ "MAIN" ]] || false [[ "$output" =~ "BRANCH1" ]] || false # Table main does not exist - run dolt log main main - [ $status -eq 1 ] + run dolt log main -- main + [ $status -eq 0 ] } @test "log: with -n specified" { @@ -356,9 +352,8 @@ teardown() { @test "log: Properly throws an error when neither a valid commit hash nor a valid table are passed" { run dolt log notvalid - echo $output [ "$status" -eq 1 ] - [[ "$output" =~ "error: table notvalid does not exist" ]] || false + [[ "$output" =~ "branch not found: notvalid" ]] || false } @test "log: Log on a table has basic functionality" { @@ -366,8 +361,7 @@ teardown() { dolt add . dolt commit -am "first commit" - run dolt log test - echo $output + run dolt log -- test [ $status -eq 0 ] [[ "$output" =~ "first commit" ]] || false [[ ! "$output" =~ "Initialize data repository" ]] || false @@ -375,7 +369,7 @@ teardown() { dolt sql -q "INSERT INTO test VALUES (1)" dolt commit -am "second commit" - run dolt log test + run dolt log -- test [ $status -eq 0 ] [[ "$output" =~ "second commit" ]] || false [[ "$output" =~ "first commit" ]] || false @@ -386,7 +380,7 @@ teardown() { dolt commit -am "third commit" # Validate we only look at the right commits - run dolt log test + run dolt log -- test [ $status -eq 0 ] [[ "$output" =~ "second commit" ]] || false [[ "$output" =~ "first commit" ]] || false @@ -399,15 +393,14 @@ teardown() { dolt add . dolt commit -am "first commit" - run dolt log -n 1 test + run dolt log -n 1 -- test [ $status -eq 0 ] - echo $output [[ "$output" =~ "first commit" ]] || false dolt sql -q "INSERT INTO test VALUES (1)" dolt commit -am "second commit" - run dolt log -n 2 test + run dolt log -n 2 -- test [ $status -eq 0 ] [[ "$output" =~ "second commit" ]] || false [[ "$output" =~ "first commit" ]] || false @@ -420,7 +413,7 @@ teardown() { dolt commit -am "fourth commit" # Validate we only look at the right commits - run dolt log test -n 1 + run dolt log -n 1 -- test [ $status -eq 0 ] [[ "$output" =~ "second commit" ]] || false [[ ! "$output" =~ "first commit" ]] || false @@ -428,7 +421,7 @@ teardown() { [[ ! "$output" =~ "third commit" ]] || false [[ ! "$output" =~ "fourth commit" ]] || false - run dolt log test -n 100 + run dolt log -n 100 -- test [ $status -eq 0 ] [[ "$output" =~ "second commit" ]] || false [[ "$output" =~ "first commit" ]] || false @@ -451,8 +444,7 @@ teardown() { dolt commit -m "Commit3" dolt merge test-branch --no-commit - run dolt log test - echo $output + run dolt log -- test [ $status -eq 0 ] [[ "$output" =~ "Commit1" ]] || false [[ "$output" =~ "Commit3" ]] || false @@ -463,7 +455,7 @@ teardown() { dolt add test dolt commit -m "MergeCommit" - run dolt log test + run dolt log -- test [ $status -eq 0 ] [[ "$output" =~ "MergeCommit" ]] || false [[ "$output" =~ "Merge:" ]] || false @@ -483,8 +475,7 @@ teardown() { dolt commit -m "Commit2" dolt checkout main - run dolt log test-branch test - echo $output + run dolt log test-branch -- test [ $status -eq 0 ] [[ "$output" =~ "Commit2" ]] || false [[ "$output" =~ "Commit1" ]] || false @@ -499,16 +490,14 @@ teardown() { dolt add test dolt commit -m "Commit 2" - run dolt log test - echo $output - [ $status -eq 1 ] - [[ "$output" =~ "error: table test does not exist" ]] || false + run dolt log -- test + [ $status -eq 0 ] dolt sql -q "create table test (pk int, c1 int, primary key(pk))" dolt add test dolt commit -m "Commit3" - run dolt log test + run dolt log -- test [[ "$output" =~ "Commit3" ]] || false [[ "$output" =~ "Commit1" ]] || false ! [[ "$output" =~ "Commit2" ]] || false @@ -588,7 +577,6 @@ teardown() { @test "log: --decorate=full shows full branches and tags" { dolt tag tag_v0 run dolt log --decorate=full - echo $output [[ "$output" =~ "commit" ]] || false [[ "$output" =~ "Author" ]] || false [[ "$output" =~ "Date" ]] || false