mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-20 03:00:43 -05:00
Separate ignored tables into their own section on dolt status
This commit is contained in:
@@ -118,6 +118,7 @@ const (
|
||||
UserParam = "user"
|
||||
NoPrettyFlag = "no-pretty"
|
||||
AddIgnoredFlag = "add-ignored"
|
||||
ShowIgnoredFlag = "show-ignored"
|
||||
)
|
||||
|
||||
const (
|
||||
|
||||
@@ -276,7 +276,11 @@ func handleCommitErr(ctx context.Context, dEnv *env.DoltEnv, err error, usage cl
|
||||
|
||||
if actions.IsNothingStaged(err) {
|
||||
notStagedTbls := actions.NothingStagedTblDiffs(err)
|
||||
n := PrintDiffsNotStaged(ctx, dEnv, cli.CliOut, notStagedTbls, false, 0, merge.ArtifactStatus{})
|
||||
n, newErr := PrintDiffsNotStaged(ctx, dEnv, cli.CliOut, notStagedTbls, false, false, 0, merge.ArtifactStatus{})
|
||||
if newErr != nil {
|
||||
bdr := errhand.BuildDError(`no changes added to commit (use "dolt add")\n%w`, newErr)
|
||||
return HandleVErrAndExitCode(bdr.Build(), usage)
|
||||
}
|
||||
|
||||
if n == 0 {
|
||||
bdr := errhand.BuildDError(`no changes added to commit (use "dolt add")`)
|
||||
@@ -370,7 +374,10 @@ func buildInitalCommitMsg(ctx context.Context, dEnv *env.DoltEnv, suggestedMsg s
|
||||
|
||||
buf := bytes.NewBuffer([]byte{})
|
||||
n := printStagedDiffs(buf, stagedTblDiffs, true)
|
||||
n = PrintDiffsNotStaged(ctx, dEnv, buf, notStagedTblDiffs, true, n, as)
|
||||
n, err = PrintDiffsNotStaged(ctx, dEnv, buf, notStagedTblDiffs, true, false, n, as)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
currBranch := dEnv.RepoStateReader().CWBHeadRef()
|
||||
initialCommitMessage := fmt.Sprintf("%s\n# Please enter the commit message for your changes. Lines starting"+
|
||||
@@ -405,9 +412,15 @@ func PrintDiffsNotStaged(
|
||||
wr io.Writer,
|
||||
notStagedTbls []diff.TableDelta,
|
||||
printHelp bool,
|
||||
printIgnored bool,
|
||||
linesPrinted int,
|
||||
as merge.ArtifactStatus,
|
||||
) int {
|
||||
) (int, error) {
|
||||
roots, err := dEnv.Roots(ctx)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
inCnfSet := set.NewStrSet(as.DataConflictTables)
|
||||
inCnfSet.Add(as.SchemaConflictsTables...)
|
||||
violationSet := set.NewStrSet(as.ConstraintViolationsTables)
|
||||
@@ -487,13 +500,39 @@ func PrintDiffsNotStaged(
|
||||
iohelp.WriteLine(wr, untrackedHeaderHelp)
|
||||
}
|
||||
|
||||
lines := getAddedNotStaged(notStagedTbls)
|
||||
addedNotStagedTables := getAddedNotStagedTables(notStagedTbls)
|
||||
addedNotStagedNotIgnoredTables, ignoredTables, err := doltdb.FilterIgnoredTables(ctx, addedNotStagedTables, roots)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
lines := make([]string, len(addedNotStagedNotIgnoredTables))
|
||||
for i, tableName := range addedNotStagedNotIgnoredTables {
|
||||
lines[i] = fmt.Sprintf(statusFmt, tblDiffTypeToLabel[diff.AddedTable], tableName)
|
||||
}
|
||||
|
||||
iohelp.WriteLine(wr, color.RedString(strings.Join(lines, "\n")))
|
||||
linesPrinted += len(lines)
|
||||
|
||||
if printIgnored && len(ignoredTables) > 0 {
|
||||
if linesPrinted > 0 {
|
||||
cli.Println()
|
||||
}
|
||||
|
||||
iohelp.WriteLine(wr, ignoredHeader)
|
||||
|
||||
if printHelp {
|
||||
iohelp.WriteLine(wr, ignoredHeaderHelp)
|
||||
}
|
||||
|
||||
for i, tableName := range ignoredTables {
|
||||
lines[i] = fmt.Sprintf(statusFmt, tblDiffTypeToLabel[diff.AddedTable], tableName)
|
||||
}
|
||||
linesPrinted += len(lines)
|
||||
}
|
||||
}
|
||||
|
||||
return linesPrinted
|
||||
return linesPrinted, nil
|
||||
}
|
||||
|
||||
func getModifiedAndRemovedNotStaged(notStagedTbls []diff.TableDelta, inCnfSet, violationSet *set.StrSet) (lines []string) {
|
||||
@@ -514,15 +553,14 @@ func getModifiedAndRemovedNotStaged(notStagedTbls []diff.TableDelta, inCnfSet, v
|
||||
return lines
|
||||
}
|
||||
|
||||
func getAddedNotStaged(notStagedTbls []diff.TableDelta) (lines []string) {
|
||||
lines = make([]string, 0, len(notStagedTbls))
|
||||
func getAddedNotStagedTables(notStagedTbls []diff.TableDelta) (tables []string) {
|
||||
tables = make([]string, 0, len(notStagedTbls))
|
||||
for _, td := range notStagedTbls {
|
||||
if td.IsAdd() || td.IsRename() {
|
||||
// per Git, unstaged renames are shown as drop + add
|
||||
lines = append(lines, fmt.Sprintf(statusFmt, tblDiffTypeToLabel[diff.AddedTable], td.CurName()))
|
||||
tables = append(tables, td.CurName())
|
||||
}
|
||||
}
|
||||
return lines
|
||||
return tables
|
||||
}
|
||||
|
||||
const (
|
||||
@@ -548,6 +586,9 @@ const (
|
||||
untrackedHeader = `Untracked files:`
|
||||
untrackedHeaderHelp = ` (use "dolt add <table>" to include in what will be committed)`
|
||||
|
||||
ignoredHeader = `Ignored files:`
|
||||
ignoredHeaderHelp = ` (use "dolt add -f <table>" to include in what will be committed)`
|
||||
|
||||
statusFmt = "\t%-18s%s"
|
||||
statusRenameFmt = "\t%-18s%s -> %s"
|
||||
schemaConflictLabel = "schema conflict:"
|
||||
|
||||
@@ -57,6 +57,7 @@ func (cmd StatusCmd) Docs() *cli.CommandDocumentation {
|
||||
|
||||
func (cmd StatusCmd) ArgParser() *argparser.ArgParser {
|
||||
ap := argparser.NewArgParserWithMaxArgs(cmd.Name(), 0)
|
||||
ap.SupportsFlag(cli.ShowIgnoredFlag, "i", "Show tables that are ignored (according to dolt_ignore)")
|
||||
return ap
|
||||
}
|
||||
|
||||
@@ -64,7 +65,7 @@ func (cmd StatusCmd) ArgParser() *argparser.ArgParser {
|
||||
func (cmd StatusCmd) Exec(ctx context.Context, commandStr string, args []string, dEnv *env.DoltEnv, cliCtx cli.CliContext) int {
|
||||
ap := cmd.ArgParser()
|
||||
help, _ := cli.HelpAndUsagePrinters(cli.CommandDocsForCommandString(commandStr, statusDocs, ap))
|
||||
cli.ParseArgsOrDie(ap, args, help)
|
||||
apr := cli.ParseArgsOrDie(ap, args, help)
|
||||
|
||||
roots, err := dEnv.Roots(ctx)
|
||||
if err != nil {
|
||||
@@ -86,7 +87,7 @@ func (cmd StatusCmd) Exec(ctx context.Context, commandStr string, args []string,
|
||||
handleStatusVErr(err)
|
||||
}
|
||||
|
||||
err = PrintStatus(ctx, dEnv, staged, notStaged, as)
|
||||
err = PrintStatus(ctx, dEnv, staged, notStaged, apr.Contains(cli.ShowIgnoredFlag), as)
|
||||
if err != nil {
|
||||
return handleStatusVErr(err)
|
||||
}
|
||||
@@ -94,7 +95,7 @@ func (cmd StatusCmd) Exec(ctx context.Context, commandStr string, args []string,
|
||||
}
|
||||
|
||||
// TODO: working docs in conflict param not used here
|
||||
func PrintStatus(ctx context.Context, dEnv *env.DoltEnv, stagedTbls, notStagedTbls []diff.TableDelta, as merge.ArtifactStatus) error {
|
||||
func PrintStatus(ctx context.Context, dEnv *env.DoltEnv, stagedTbls, notStagedTbls []diff.TableDelta, showIgnoredTables bool, as merge.ArtifactStatus) error {
|
||||
cli.Printf(branchHeader, dEnv.RepoStateReader().CWBHeadRef().GetPath())
|
||||
|
||||
err := printRemoteRefTrackingInfo(ctx, dEnv)
|
||||
@@ -120,7 +121,10 @@ func PrintStatus(ctx context.Context, dEnv *env.DoltEnv, stagedTbls, notStagedTb
|
||||
}
|
||||
|
||||
n := printStagedDiffs(cli.CliOut, stagedTbls, true)
|
||||
n = PrintDiffsNotStaged(ctx, dEnv, cli.CliOut, notStagedTbls, true, n, as)
|
||||
n, err = PrintDiffsNotStaged(ctx, dEnv, cli.CliOut, notStagedTbls, true, showIgnoredTables, n, as)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if !mergeActive && n == 0 {
|
||||
cli.Println("nothing to commit, working tree clean")
|
||||
|
||||
@@ -1055,24 +1055,27 @@ func UnionTableNames(ctx context.Context, roots ...*RootValue) ([]string, error)
|
||||
return tblNames, nil
|
||||
}
|
||||
|
||||
// FilterIgnoredTables takes a slice of table names and returns a new slice that omits any table names that are specified by dolt_ignore.
|
||||
func FilterIgnoredTables(ctx context.Context, tables []string, roots Roots) ([]string, error) {
|
||||
// FilterIgnoredTables takes a slice of table names and returns two new slices: one with any table names that are specified by dolt_ignore, and the other with only those tables.
|
||||
func FilterIgnoredTables(ctx context.Context, tables []string, roots Roots) ([]string, []string, error) {
|
||||
filteredTables := []string{}
|
||||
ignoredTables := []string{}
|
||||
ignorePatterns, err := GetIgnoredTablePatterns(ctx, roots)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
for _, tableName := range tables {
|
||||
ignored, err := ignorePatterns.IsTableNameIgnored(tableName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
if !ignored {
|
||||
filteredTables = append(filteredTables, tableName)
|
||||
} else {
|
||||
ignoredTables = append(ignoredTables, tableName)
|
||||
}
|
||||
}
|
||||
|
||||
return filteredTables, nil
|
||||
return filteredTables, ignoredTables, nil
|
||||
}
|
||||
|
||||
// validateTagUniqueness checks for tag collisions between the given table and the set of tables in then given root.
|
||||
|
||||
+2
-2
@@ -24,7 +24,7 @@ import (
|
||||
func StageTables(ctx context.Context, roots doltdb.Roots, tbls []string, filterIgnoredTables bool) (doltdb.Roots, error) {
|
||||
if filterIgnoredTables {
|
||||
var err error
|
||||
tbls, err = doltdb.FilterIgnoredTables(ctx, tbls, roots)
|
||||
tbls, _, err = doltdb.FilterIgnoredTables(ctx, tbls, roots)
|
||||
if err != nil {
|
||||
return doltdb.Roots{}, err
|
||||
}
|
||||
@@ -48,7 +48,7 @@ func StageModifiedAndDeletedTables(ctx context.Context, roots doltdb.Roots) (dol
|
||||
return doltdb.Roots{}, err
|
||||
}
|
||||
|
||||
tbls := []string{}
|
||||
var tbls []string
|
||||
for _, tableDelta := range unstaged {
|
||||
if !tableDelta.IsAdd() {
|
||||
tbls = append(tbls, tableDelta.FromName)
|
||||
|
||||
Reference in New Issue
Block a user