simpler error message in SQL context, fuller one on CLI

This commit is contained in:
Zach Musgrave
2023-01-20 17:14:19 -08:00
parent 12c9e77b00
commit c35c7f6546
3 changed files with 10 additions and 6 deletions

View File

@@ -72,6 +72,8 @@ const (
showCurrentFlag = "show-current"
)
var ErrUnmergedBranchDelete = errors.New("The branch '%s' is not fully merged.\nIf you are sure you want to delete it, run 'dolt branch -D %s'.")
type BranchCmd struct{}
// Name is returns the name of the Dolt cli command. This is what is used on the command line to invoke the command
@@ -328,6 +330,8 @@ func deleteBranches(ctx context.Context, dEnv *env.DoltEnv, apr *argparser.ArgPa
var verr errhand.VerboseError
if err == doltdb.ErrBranchNotFound {
verr = errhand.BuildDError("fatal: branch '%s' not found", brName).Build()
} else if err == actions.ErrUnmergedBranch {
verr = errhand.BuildDError(ErrUnmergedBranchDelete.Error(), brName, brName).Build()
} else if err == actions.ErrCOBranchDelete {
verr = errhand.BuildDError("error: Cannot delete checked out branch '%s'", brName).Build()
} else {

View File

@@ -29,7 +29,7 @@ import (
var ErrAlreadyExists = errors.New("already exists")
var ErrCOBranchDelete = errors.New("attempted to delete checked out branch")
var ErrUnmergedBranchDelete = errors.New("The branch '%s' is not fully merged.\nIf you are sure you want to delete it, run 'dolt branch -D %s'.")
var ErrUnmergedBranch = errors.New("branch is not fully merged")
var ErrWorkingSetsOnBothBranches = errors.New("checkout would overwrite uncommitted changes on target branch")
func RenameBranch(ctx context.Context, dbData env.DbData, oldBranch, newBranch string, remoteDbPro env.RemoteDbProvider, force bool) error {
@@ -205,7 +205,7 @@ func validateBranchMergedIntoCurrentWorkingBranch(ctx context.Context, dbdata en
return nil
}
if errors.Is(err, doltdb.ErrIsAhead) {
return fmt.Errorf(ErrUnmergedBranchDelete.Error(), branch.GetPath(), branch.GetPath())
return ErrUnmergedBranch
}
// TODO: no common ancestor is not an error
@@ -213,7 +213,7 @@ func validateBranchMergedIntoCurrentWorkingBranch(ctx context.Context, dbdata en
}
if !isMerged {
return fmt.Errorf(ErrUnmergedBranchDelete.Error(), branch.GetPath(), branch.GetPath())
return ErrUnmergedBranch
}
return nil
@@ -257,14 +257,14 @@ func validateBranchMergedIntoUpstream(ctx context.Context, dbdata env.DbData, br
return nil
}
if errors.Is(err, doltdb.ErrIsAhead) {
return fmt.Errorf(ErrUnmergedBranchDelete.Error(), branch.GetPath(), branch.GetPath())
return ErrUnmergedBranch
}
// TODO: no common ancestor is not an error
return err
}
if !canFF {
return fmt.Errorf(ErrUnmergedBranchDelete.Error(), branch.GetPath(), branch.GetPath())
return ErrUnmergedBranch
}
return nil

View File

@@ -1713,7 +1713,7 @@ var DoltBranchScripts = []queries.ScriptTest{
{
// Trying to delete a branch with unpushed changes fails without force option
Query: "CALL DOLT_BRANCH('-d', 'myNewBranchWithCommit')",
ExpectedErrStr: "attempted to delete a branch that is not fully merged into its parent; use `-f` to force",
ExpectedErrStr: "branch is not fully merged",
},
{
Query: "CALL DOLT_BRANCH('-df', 'myNewBranchWithCommit')",