diff --git a/go/libraries/doltcore/env/actions/branch.go b/go/libraries/doltcore/env/actions/branch.go index 9c00b716f0..6fd509c1c8 100644 --- a/go/libraries/doltcore/env/actions/branch.go +++ b/go/libraries/doltcore/env/actions/branch.go @@ -149,6 +149,18 @@ func DeleteBranchOnDB(ctx context.Context, ddb *doltdb.DoltDB, dref ref.DoltRef, } } + wsRef, err := ref.WorkingSetRefForHead(dref) + if err != nil { + if !errors.Is(err, ref.ErrWorkingSetUnsupported) { + return err + } + } else { + err = ddb.DeleteWorkingSet(ctx, wsRef) + if err != nil { + return err + } + } + return ddb.DeleteBranch(ctx, dref) } diff --git a/go/libraries/doltcore/ref/workingset_ref.go b/go/libraries/doltcore/ref/workingset_ref.go index f49d899c78..dad01e5c17 100755 --- a/go/libraries/doltcore/ref/workingset_ref.go +++ b/go/libraries/doltcore/ref/workingset_ref.go @@ -15,6 +15,7 @@ package ref import ( + "errors" "fmt" "path" "strings" @@ -38,6 +39,8 @@ func NewWorkingSetRef(workingSetName string) WorkingSetRef { return WorkingSetRef{workingSetName} } +var ErrWorkingSetUnsupported = errors.New("unsupported type of ref for a working set") + // WorkingSetRefForHead returns a new WorkingSetRef for the head ref given, or an error if the ref given doesn't // represent a head. func WorkingSetRefForHead(ref DoltRef) (WorkingSetRef, error) { @@ -45,7 +48,7 @@ func WorkingSetRefForHead(ref DoltRef) (WorkingSetRef, error) { case BranchRefType, WorkspaceRefType: return NewWorkingSetRef(path.Join(string(ref.GetType()), ref.GetPath())), nil default: - return WorkingSetRef{}, fmt.Errorf("unsupported type of ref for a working set: %s", ref.GetType()) + return WorkingSetRef{}, fmt.Errorf("%w: %s", ErrWorkingSetUnsupported, ref.GetType()) } }