diff --git a/go/cmd/dolt/commands/branch.go b/go/cmd/dolt/commands/branch.go index a7e34bde78..0546539a9b 100644 --- a/go/cmd/dolt/commands/branch.go +++ b/go/cmd/dolt/commands/branch.go @@ -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 { diff --git a/go/libraries/doltcore/env/actions/branch.go b/go/libraries/doltcore/env/actions/branch.go index 9e99b0e122..a7660decdc 100644 --- a/go/libraries/doltcore/env/actions/branch.go +++ b/go/libraries/doltcore/env/actions/branch.go @@ -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 diff --git a/go/libraries/doltcore/sqle/enginetest/dolt_queries.go b/go/libraries/doltcore/sqle/enginetest/dolt_queries.go index e768641aa9..bae3f80f74 100644 --- a/go/libraries/doltcore/sqle/enginetest/dolt_queries.go +++ b/go/libraries/doltcore/sqle/enginetest/dolt_queries.go @@ -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')",