mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-19 19:39:45 -05:00
Merge pull request #9186 from dolthub/nathan/nathanglobaloptions
Fix --branch global option always flagging error "no valid repository", fix bad error when running status on invalid branches
This commit is contained in:
@@ -28,6 +28,7 @@ import (
|
||||
eventsapi "github.com/dolthub/dolt/go/gen/proto/dolt/services/eventsapi/v1alpha1"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/doltdb"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/env"
|
||||
"github.com/dolthub/dolt/go/libraries/doltcore/sqle/dsess"
|
||||
"github.com/dolthub/dolt/go/libraries/utils/argparser"
|
||||
)
|
||||
|
||||
@@ -119,7 +120,7 @@ func (cmd StatusCmd) Exec(ctx context.Context, commandStr string, args []string,
|
||||
}
|
||||
|
||||
// get status information from the database
|
||||
pd, err := createPrintData(err, queryist, sqlCtx, showIgnoredTables)
|
||||
pd, err := createPrintData(err, queryist, sqlCtx, showIgnoredTables, cliCtx)
|
||||
if err != nil {
|
||||
return handleStatusVErr(err)
|
||||
}
|
||||
@@ -132,10 +133,19 @@ func (cmd StatusCmd) Exec(ctx context.Context, commandStr string, args []string,
|
||||
return 0
|
||||
}
|
||||
|
||||
func createPrintData(err error, queryist cli.Queryist, sqlCtx *sql.Context, showIgnoredTables bool) (*printData, error) {
|
||||
branchName, err := getActiveBranchName(sqlCtx, queryist)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
func createPrintData(err error, queryist cli.Queryist, sqlCtx *sql.Context, showIgnoredTables bool, cliCtx cli.CliContext) (*printData, error) {
|
||||
var branchName string
|
||||
|
||||
if brName, hasBranch := cliCtx.GlobalArgs().GetValue(cli.BranchParam); hasBranch {
|
||||
branchName = brName
|
||||
} else if useDb, hasUseDb := cliCtx.GlobalArgs().GetValue(UseDbFlag); hasUseDb {
|
||||
_, branchName = dsess.SplitRevisionDbName(useDb)
|
||||
} else {
|
||||
var err error
|
||||
branchName, err = getActiveBranchName(sqlCtx, queryist)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
ignorePatterns, err := getIgnoredTablePatternsFromSql(queryist, sqlCtx)
|
||||
|
||||
+6
-3
@@ -630,14 +630,17 @@ If you're interested in running this command against a remote host, hit us up on
|
||||
}
|
||||
}
|
||||
|
||||
var dbName string
|
||||
|
||||
if hasUseDb {
|
||||
dbName, _ := dsess.SplitRevisionDbName(useDb)
|
||||
dbName, _ = dsess.SplitRevisionDbName(useDb)
|
||||
targetEnv = mrEnv.GetEnv(dbName)
|
||||
if targetEnv == nil {
|
||||
return nil, fmt.Errorf("The provided --use-db %s does not exist.", dbName)
|
||||
}
|
||||
} else {
|
||||
useDb = mrEnv.GetFirstDatabase()
|
||||
dbName = mrEnv.GetFirstDatabase()
|
||||
useDb = dbName
|
||||
if hasBranch {
|
||||
useDb += "/" + useBranch
|
||||
}
|
||||
@@ -646,7 +649,7 @@ If you're interested in running this command against a remote host, hit us up on
|
||||
// If our targetEnv is still |nil| and we don't have an environment
|
||||
// which we will be using based on |useDb|, then our initialization
|
||||
// here did not find a repository we will be operating against.
|
||||
noValidRepository := targetEnv == nil && (useDb == "" || mrEnv.GetEnv(useDb) == nil)
|
||||
noValidRepository := targetEnv == nil && (useDb == "" || mrEnv.GetEnv(dbName) == nil)
|
||||
|
||||
// Not having a valid repository as we start to execute a CLI command
|
||||
// implementation is allowed for a small number of commands. We don't
|
||||
|
||||
@@ -135,3 +135,18 @@ SQL
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "\"sqlserver.global.log_bin\":\"1\"" ]] || false
|
||||
}
|
||||
|
||||
@test "global-args: can use --branch on valid branch" {
|
||||
cd db1
|
||||
run dolt --branch b1 status
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "On branch b1" ]] || false
|
||||
[[ "$output" =~ "nothing to commit, working tree clean" ]] || false
|
||||
}
|
||||
|
||||
@test "global-args: cannot use --branch on invalid branch" {
|
||||
cd db1
|
||||
run dolt --branch invalidBr status
|
||||
[ "$status" -eq 1 ]
|
||||
[[ "$output" =~ "database not found: db1/invalidBr" ]] || false
|
||||
}
|
||||
Reference in New Issue
Block a user