mirror of
https://github.com/dolthub/dolt.git
synced 2026-02-04 18:49:00 -06:00
Consistently implement which commands require a repo and which do not. Add a test file to ensure behavior
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -40,10 +40,6 @@ func (cmd ArchiveInspectCmd) Description() string {
|
||||
return "Inspect a Dolt archive (.darc) file and display basic information about it."
|
||||
}
|
||||
|
||||
func (cmd ArchiveInspectCmd) RequiresRepo() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (cmd ArchiveInspectCmd) Docs() *cli.CommandDocumentation {
|
||||
return &cli.CommandDocumentation{
|
||||
ShortDesc: "Inspect a Dolt archive (.darc) file and display information about it",
|
||||
|
||||
@@ -39,10 +39,6 @@ func (cmd JournalInspectCmd) Description() string {
|
||||
return "Inspect a Dolt journal file and display information about it."
|
||||
}
|
||||
|
||||
func (cmd JournalInspectCmd) RequiresRepo() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (cmd JournalInspectCmd) Docs() *cli.CommandDocumentation {
|
||||
return &cli.CommandDocumentation{
|
||||
ShortDesc: "Inspect a Dolt journal file and display information about it",
|
||||
|
||||
@@ -37,10 +37,6 @@ func (cmd ZstdCmd) Description() string {
|
||||
return "A temporary admin command for taking a dependency on gozstd and working out tooling dependencies."
|
||||
}
|
||||
|
||||
func (cmd ZstdCmd) RequiresRepo() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (cmd ZstdCmd) Docs() *cli.CommandDocumentation {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -89,10 +89,6 @@ func (cmd BackupCmd) Description() string {
|
||||
return "Manage a set of server backups."
|
||||
}
|
||||
|
||||
func (cmd BackupCmd) RequiresRepo() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (cmd BackupCmd) Docs() *cli.CommandDocumentation {
|
||||
ap := cmd.ArgParser()
|
||||
return cli.NewCommandDocumentation(backupDocs, ap)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -91,12 +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
|
||||
}
|
||||
|
||||
func (cmd ConfigCmd) Docs() *cli.CommandDocumentation {
|
||||
ap := cmd.ArgParser()
|
||||
return cli.NewCommandDocumentation(cfgDocs, ap)
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -66,12 +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
|
||||
}
|
||||
|
||||
func (cmd ReadTablesCmd) ArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParserWithVariableArgs(cmd.Name())
|
||||
ap.ArgListHelp = [][2]string{
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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."
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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."
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -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
|
||||
|
||||
188
integration-tests/bats/requires-repo.bats
Normal file
188
integration-tests/bats/requires-repo.bats
Normal file
@@ -0,0 +1,188 @@
|
||||
#!/usr/bin/env bats
|
||||
# Tests for CLI behavior when running commands from a parent directory
|
||||
# that contains a child dolt database directory.
|
||||
# See https://github.com/dolthub/dolt/issues/10230
|
||||
|
||||
load $BATS_TEST_DIRNAME/helper/common.bash
|
||||
load $BATS_TEST_DIRNAME/helper/query-server-common.bash
|
||||
|
||||
setup() {
|
||||
skiponwindows "tests are flaky on Windows"
|
||||
if [ "$SQL_ENGINE" = "remote-engine" ]; then
|
||||
skip "This test tests local CLI behavior, SQL_ENGINE is not needed."
|
||||
fi
|
||||
setup_no_dolt_init
|
||||
# Create a child database directory
|
||||
mkdir child_db
|
||||
cd child_db
|
||||
dolt init
|
||||
dolt sql -q "CREATE TABLE test_table (pk INT PRIMARY KEY, value VARCHAR(100))"
|
||||
dolt add .
|
||||
dolt commit -m "Initial commit"
|
||||
cd ..
|
||||
# We are now in the parent directory with a child dolt database
|
||||
}
|
||||
|
||||
teardown() {
|
||||
stop_sql_server 1 && sleep 0.5
|
||||
teardown_common
|
||||
}
|
||||
|
||||
NOT_VALID_REPO_ERROR="The current directory is not a valid dolt repository."
|
||||
|
||||
# =============================================================================
|
||||
# Tests WITHOUT a running SQL server
|
||||
# All commands that require a repo should fail consistently from parent directory
|
||||
# =============================================================================
|
||||
|
||||
@test "parent-directory: dolt status from parent dir without server fails" {
|
||||
run dolt status
|
||||
[ "$status" -ne 0 ]
|
||||
[ "${lines[0]}" = "$NOT_VALID_REPO_ERROR" ]
|
||||
}
|
||||
|
||||
@test "parent-directory: dolt checkout from parent dir without server fails" {
|
||||
run dolt checkout -b new_branch
|
||||
[ "$status" -ne 0 ]
|
||||
[ "${lines[0]}" = "$NOT_VALID_REPO_ERROR" ]
|
||||
}
|
||||
|
||||
@test "parent-directory: dolt branch from parent dir without server fails" {
|
||||
run dolt branch
|
||||
[ "$status" -ne 0 ]
|
||||
[ "${lines[0]}" = "$NOT_VALID_REPO_ERROR" ]
|
||||
}
|
||||
|
||||
@test "parent-directory: dolt log from parent dir without server fails" {
|
||||
run dolt log
|
||||
[ "$status" -ne 0 ]
|
||||
[ "${lines[0]}" = "$NOT_VALID_REPO_ERROR" ]
|
||||
}
|
||||
|
||||
@test "parent-directory: dolt diff from parent dir without server fails" {
|
||||
run dolt diff
|
||||
[ "$status" -ne 0 ]
|
||||
[ "${lines[0]}" = "$NOT_VALID_REPO_ERROR" ]
|
||||
}
|
||||
|
||||
@test "parent-directory: dolt add from parent dir without server fails" {
|
||||
run dolt add .
|
||||
[ "$status" -ne 0 ]
|
||||
[ "${lines[0]}" = "$NOT_VALID_REPO_ERROR" ]
|
||||
}
|
||||
|
||||
@test "parent-directory: dolt commit from parent dir without server fails" {
|
||||
run dolt commit -m "test"
|
||||
[ "$status" -ne 0 ]
|
||||
[ "${lines[0]}" = "$NOT_VALID_REPO_ERROR" ]
|
||||
}
|
||||
|
||||
# =============================================================================
|
||||
# Tests WITH a running SQL server
|
||||
# Commands should still fail from parent directory - they require a local repo
|
||||
# =============================================================================
|
||||
|
||||
@test "parent-directory: dolt status from parent dir with running server fails" {
|
||||
start_multi_db_server child_db
|
||||
|
||||
# Status should fail - it requires being in a dolt repo directory
|
||||
run dolt status
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" =~ "$NOT_VALID_REPO_ERROR" ]] || false
|
||||
}
|
||||
|
||||
@test "parent-directory: dolt checkout from parent dir with running server fails" {
|
||||
start_multi_db_server child_db
|
||||
|
||||
run dolt checkout -b new_branch
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" =~ "$NOT_VALID_REPO_ERROR" ]] || false
|
||||
}
|
||||
|
||||
@test "parent-directory: dolt branch from parent dir with running server fails" {
|
||||
start_multi_db_server child_db
|
||||
|
||||
run dolt branch
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" =~ "$NOT_VALID_REPO_ERROR" ]] || false
|
||||
}
|
||||
|
||||
@test "parent-directory: dolt log from parent dir with running server fails" {
|
||||
start_multi_db_server child_db
|
||||
|
||||
run dolt log
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" =~ "$NOT_VALID_REPO_ERROR" ]] || false
|
||||
}
|
||||
|
||||
@test "parent-directory: dolt diff from parent dir with running server fails" {
|
||||
start_multi_db_server child_db
|
||||
|
||||
run dolt diff
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "$output" =~ "$NOT_VALID_REPO_ERROR" ]] || false
|
||||
}
|
||||
|
||||
# =============================================================================
|
||||
# Commands that do NOT require a repo should work from parent directory
|
||||
# =============================================================================
|
||||
|
||||
@test "parent-directory: dolt sql from parent dir with running server succeeds" {
|
||||
start_multi_db_server child_db
|
||||
|
||||
# SQL commands should work by connecting to the running server
|
||||
run dolt sql -q "SELECT * FROM child_db.test_table"
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
@test "parent-directory: dolt version from parent dir succeeds" {
|
||||
run dolt version
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "dolt version" ]] || false
|
||||
}
|
||||
|
||||
@test "parent-directory: dolt init in parent dir succeeds" {
|
||||
run dolt init
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "Successfully initialized dolt data repository" ]] || false
|
||||
}
|
||||
|
||||
# =============================================================================
|
||||
# Commands should work correctly when run from within the child database directory
|
||||
# =============================================================================
|
||||
|
||||
@test "parent-directory: commands in child directory work normally" {
|
||||
cd child_db
|
||||
|
||||
run dolt status
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "On branch main" ]] || false
|
||||
|
||||
run dolt checkout -b new_branch
|
||||
[ "$status" -eq 0 ]
|
||||
|
||||
run dolt branch
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "new_branch" ]] || false
|
||||
[[ "$output" =~ "main" ]] || false
|
||||
|
||||
run dolt log
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "Initial commit" ]] || false
|
||||
|
||||
run dolt diff
|
||||
[ "$status" -eq 0 ]
|
||||
}
|
||||
|
||||
# =============================================================================
|
||||
# Test consistent behavior - all repo-requiring commands should fail the same way
|
||||
# =============================================================================
|
||||
|
||||
@test "parent-directory: all repo-requiring commands fail consistently" {
|
||||
# All these commands should fail with the same error
|
||||
for cmd in "status" "branch" "log" "diff" "add ." "commit -m test" "checkout -b test"; do
|
||||
run dolt $cmd
|
||||
[ "$status" -ne 0 ]
|
||||
[[ "${lines[0]}" = "$NOT_VALID_REPO_ERROR" ]] || false
|
||||
done
|
||||
}
|
||||
Reference in New Issue
Block a user