Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion go/cmd/dolt/cli/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ func hasHelpFlag(args []string) bool {
return false
}

// globalArgsSpecifyDB checks if the global arguments contain --use-db or --host flags,
// which indicate that the user is manually specifying a database connection
// rather than relying on the current directory being a dolt repository.
func globalArgsSpecifyDB(cliCtx CliContext) bool {
if cliCtx == nil {
return false
}
globalArgs := cliCtx.GlobalArgs()
if globalArgs == nil {
return false
}
_, hasUseDb := globalArgs.GetValue("use-db")
_, hasHost := globalArgs.GetValue(HostFlag)
return hasUseDb || hasHost
}

// Command is the interface which defines a Dolt cli command
type Command interface {
// Name returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
Expand Down Expand Up @@ -220,7 +236,9 @@ func (hc SubCommandHandler) handleCommand(ctx context.Context, commandStr string
cmdRequiresRepo = rnrCmd.RequiresRepo()
}

if cmdRequiresRepo && !hasHelpFlag(args) {
// If --use-db or --host is specified, the user is manually specifying a database/server
// connection, so we don't require the current directory to be a valid dolt repository.
if cmdRequiresRepo && !hasHelpFlag(args) && !globalArgsSpecifyDB(cliCtx) {
isValid := CheckEnvIsValid(dEnv)
if !isValid {
return 2
Expand Down
6 changes: 0 additions & 6 deletions go/cmd/dolt/commands/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,6 @@ The dolt status command can be used to obtain a summary of which tables have cha

type AddCmd struct{}

var _ cli.RepoNotRequiredCommand = AddCmd{}

func (cmd AddCmd) RequiresRepo() bool {
return false
}

// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
func (cmd AddCmd) Name() string {
return "add"
Expand Down
6 changes: 0 additions & 6 deletions go/cmd/dolt/commands/blame.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,6 @@ func (cmd BlameCmd) ArgParser() *argparser.ArgParser {
return ap
}

func (cmd BlameCmd) RequiresRepo() bool {
return false
}

var _ cli.RepoNotRequiredCommand = BlameCmd{}

// EventType returns the type of the event to log
func (cmd BlameCmd) EventType() eventsapi.ClientEventType {
return eventsapi.ClientEventType_BLAME
Expand Down
4 changes: 0 additions & 4 deletions go/cmd/dolt/commands/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,6 @@ func (cmd CleanCmd) ArgParser() *argparser.ArgParser {
return cli.CreateCleanArgParser()
}

func (cmd CleanCmd) RequiresRepo() bool {
return false
}

// Exec executes the command
func (cmd CleanCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv, cliCtx cli.CliContext) int {
ap := cli.CreateCleanArgParser()
Expand Down
4 changes: 0 additions & 4 deletions go/cmd/dolt/commands/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ func (cmd CommitCmd) ArgParser() *argparser.ArgParser {
return cli.CreateCommitArgParser(false)
}

func (cmd CommitCmd) RequiresRepo() bool {
return false
}

// Exec executes the command
func (cmd CommitCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv, cliCtx cli.CliContext) int {
res, skipped := performCommit(ctx, commandStr, args, cliCtx, dEnv)
Expand Down
2 changes: 0 additions & 2 deletions go/cmd/dolt/commands/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@ func (cmd ConfigCmd) Description() string {
return "Dolt configuration."
}

// RequiresRepo should return false if this interface is implemented, and the command does not have the requirement
// that it be run from within a data repository directory
func (cmd ConfigCmd) RequiresRepo() bool {
return false
}
Expand Down
8 changes: 0 additions & 8 deletions go/cmd/dolt/commands/debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,6 @@ func (cmd DebugCmd) EventType() eventsapi.ClientEventType {
return eventsapi.ClientEventType_SQL
}

// RequiresRepo indicates that this command does not have to be run from within a dolt data repository directory.
// In this case it is because this command supports the DataDirFlag which can pass in a directory. In the event that
// that parameter is not provided there is additional error handling within this command to make sure that this was in
// fact run from within a dolt data repository directory.
func (cmd DebugCmd) RequiresRepo() bool {
return false
}

// Exec executes the command
// Unlike other commands, sql doesn't set a new working root directly, as the SQL layer updates the working set as
// necessary when committing work.
Expand Down
4 changes: 0 additions & 4 deletions go/cmd/dolt/commands/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,6 @@ func (cmd DiffCmd) ArgParser() *argparser.ArgParser {
return cli.CreateDiffArgParser(false)
}

func (cmd DiffCmd) RequiresRepo() bool {
return false
}

// Exec executes the command
func (cmd DiffCmd) Exec(ctx context.Context, commandStr string, args []string, _ *env.DoltEnv, cliCtx cli.CliContext) int {
ap := cmd.ArgParser()
Expand Down
4 changes: 0 additions & 4 deletions go/cmd/dolt/commands/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ func (cmd FetchCmd) ArgParser() *argparser.ArgParser {
return cli.CreateFetchArgParser()
}

func (cmd FetchCmd) RequiresRepo() bool {
return false
}

// Exec executes the command
func (cmd FetchCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv, cliCtx cli.CliContext) int {
ap := cli.CreateFetchArgParser()
Expand Down
4 changes: 0 additions & 4 deletions go/cmd/dolt/commands/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@ func (cmd LogCmd) ArgParser() *argparser.ArgParser {
return cli.CreateLogArgParser(false)
}

func (cmd LogCmd) RequiresRepo() bool {
return false
}

// Exec executes the command
func (cmd LogCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv, cliCtx cli.CliContext) int {
return cmd.logWithLoggerFunc(ctx, commandStr, args, dEnv, cliCtx)
Expand Down
4 changes: 0 additions & 4 deletions go/cmd/dolt/commands/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,6 @@ func (cmd MergeCmd) EventType() eventsapi.ClientEventType {
return eventsapi.ClientEventType_MERGE
}

func (cmd MergeCmd) RequiresRepo() bool {
return false
}

// Exec executes the command
func (cmd MergeCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv, cliCtx cli.CliContext) int {
ap := cli.CreateMergeArgParser()
Expand Down
2 changes: 0 additions & 2 deletions go/cmd/dolt/commands/read_tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ func (cmd ReadTablesCmd) Docs() *cli.CommandDocumentation {
return cli.NewCommandDocumentation(readTablesDocs, ap)
}

// RequiresRepo should return false if this interface is implemented, and the command does not have the requirement
// that it be run from within a data repository directory
func (cmd ReadTablesCmd) RequiresRepo() bool {
return false
}
Expand Down
4 changes: 0 additions & 4 deletions go/cmd/dolt/commands/reflog.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ func (cmd ReflogCmd) ArgParser() *argparser.ArgParser {
return cli.CreateReflogArgParser()
}

func (cmd ReflogCmd) RequiresRepo() bool {
return false
}

// Exec executes the command
func (cmd ReflogCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv, cliCtx cli.CliContext) int {
ap := cmd.ArgParser()
Expand Down
4 changes: 0 additions & 4 deletions go/cmd/dolt/commands/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ func (cmd ResetCmd) ArgParser() *argparser.ArgParser {
return cli.CreateResetArgParser()
}

func (cmd ResetCmd) RequiresRepo() bool {
return false
}

// Exec executes the command
func (cmd ResetCmd) Exec(ctx context.Context, commandStr string, args []string, _ *env.DoltEnv, cliCtx cli.CliContext) int {
ap := cli.CreateResetArgParser()
Expand Down
4 changes: 0 additions & 4 deletions go/cmd/dolt/commands/revert.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ func (cmd RevertCmd) Name() string {
return "revert"
}

func (cmd RevertCmd) RequiresRepo() bool {
return false
}

// Description implements the interface cli.Command.
func (cmd RevertCmd) Description() string {
return "Undo the changes introduced in a commit."
Expand Down
4 changes: 0 additions & 4 deletions go/cmd/dolt/commands/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ The dolt status command can be used to obtain a summary of which tables have cha

type RmCmd struct{}

func (cmd RmCmd) RequiresRepo() bool {
return false
}

// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
func (cmd RmCmd) Name() string {
return "rm"
Expand Down
6 changes: 0 additions & 6 deletions go/cmd/dolt/commands/roots.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ func (cmd RootsCmd) Hidden() bool {
return true
}

// RequiresRepo should return false if this interface is implemented, and the command does not have the requirement
// that it be run from within a data repository directory
func (cmd RootsCmd) RequiresRepo() bool {
return false
}

// Description returns a description of the command
func (cmd RootsCmd) Description() string {
return "Displays store root values (or potential store root values) that we find in the current database."
Expand Down
6 changes: 0 additions & 6 deletions go/cmd/dolt/commands/send_metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ func (cmd SendMetricsCmd) Description() string {
return "Send events logs to server."
}

// RequiresRepo should return false if this interface is implemented, and the command does not have the requirement
// that it be run from within a data repository directory
func (cmd SendMetricsCmd) RequiresRepo() bool {
return false
}

// Hidden should return true if this command should be hidden from the help text
func (cmd SendMetricsCmd) Hidden() bool {
return true
Expand Down
4 changes: 0 additions & 4 deletions go/cmd/dolt/commands/show.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ func (cmd ShowCmd) ArgParser() *argparser.ArgParser {
return ap
}

func (cmd ShowCmd) RequiresRepo() bool {
return false
}

// Exec executes the command
func (cmd ShowCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv, cliCtx cli.CliContext) int {
ap := cmd.ArgParser()
Expand Down
5 changes: 0 additions & 5 deletions go/cmd/dolt/commands/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,6 @@ var statusDocs = cli.CommandDocumentationContent{

type StatusCmd struct{}

func (cmd StatusCmd) RequiresRepo() bool {
return false
}

var _ cli.RepoNotRequiredCommand = StatusCmd{}
var _ cli.EventMonitoredCommand = StatusCmd{}

// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
Expand Down
1 change: 1 addition & 0 deletions integration-tests/bats/helper/local-remote.bash
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ SKIP_SERVER_TESTS=$(cat <<-EOM
~nonlocal.bats~
~branch-activity.bats~
~mutual-tls-auth.bats~
~requires-repo.bats~
EOM
)

Expand Down
2 changes: 1 addition & 1 deletion integration-tests/bats/init.bats
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ teardown() {

# Assert that the current directory has NOT been initialized
run dolt status
[ $status -eq 1 ]
[ $status -eq 2 ]
[[ $output =~ "The current directory is not a valid dolt repository" ]] || false
[ ! -d "$baseDir/not_a_repo/.dolt" ]

Expand Down
Loading
Loading