Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support dolt diff --staged #8353

Merged
merged 1 commit into from
Sep 13, 2024
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
1 change: 1 addition & 0 deletions go/cmd/dolt/cli/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const (
SkipEmptyFlag = "skip-empty"
SoftResetParam = "soft"
SquashParam = "squash"
StagedFlag = "staged"
StatFlag = "stat"
SystemFlag = "system"
TablesFlag = "tables"
Expand Down
7 changes: 5 additions & 2 deletions go/cmd/dolt/commands/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ func (cmd DiffCmd) ArgParser() *argparser.ArgParser {
ap.SupportsString(FormatFlag, "r", "result output format", "How to format diff output. Valid values are tabular, sql, json. Defaults to tabular.")
ap.SupportsString(whereParam, "", "column", "filters columns based on values in the diff. See {{.EmphasisLeft}}dolt diff --help{{.EmphasisRight}} for details.")
ap.SupportsInt(limitParam, "", "record_count", "limits to the first N diffs.")
ap.SupportsFlag(cli.CachedFlag, "c", "Show only the staged data changes.")
ap.SupportsFlag(cli.StagedFlag, "", "Show only the staged data changes.")
ap.SupportsFlag(cli.CachedFlag, "c", "Synonym for --staged")
ap.SupportsFlag(SkinnyFlag, "sk", "Shows only primary key columns and any columns with data changes.")
ap.SupportsFlag(MergeBase, "", "Uses merge base of the first commit and second commit (or HEAD if not supplied) as the first commit")
ap.SupportsString(DiffMode, "", "diff mode", "Determines how to display modified rows with tabular output. Valid values are row, line, in-place, context. Defaults to context.")
Expand Down Expand Up @@ -286,7 +287,9 @@ func parseDiffArgs(queryist cli.Queryist, sqlCtx *sql.Context, apr *argparser.Ar
diffDisplaySettings: parseDiffDisplaySettings(apr),
}

tableNames, err := dArgs.applyDiffRoots(queryist, sqlCtx, apr.Args, apr.Contains(cli.CachedFlag), apr.Contains(MergeBase))
staged := apr.Contains(cli.StagedFlag) || apr.Contains(cli.CachedFlag)

tableNames, err := dArgs.applyDiffRoots(queryist, sqlCtx, apr.Args, staged, apr.Contains(MergeBase))
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions integration-tests/bats/diff.bats
Original file line number Diff line number Diff line change
Expand Up @@ -1021,8 +1021,8 @@ SQL
[[ "$output" =~ "where poop = 0" ]] || false
}

@test "diff: --cached" {
run dolt diff --cached
@test "diff: --cached/--staged" {
run dolt diff --staged
[ $status -eq 0 ]
[ "$output" = "" ]

Expand All @@ -1038,7 +1038,7 @@ SQL

CORRECT_DIFF=$output
dolt add test
run dolt diff --cached
run dolt diff --staged
[ $status -eq 0 ]
[ "$output" = "$CORRECT_DIFF" ]

Expand Down
Loading