mirror of
https://github.com/dolthub/dolt.git
synced 2026-03-14 11:10:40 -05:00
go: env/actions/branch: When deleting a branch, also delete its working set ref.
This commit is contained in:
12
go/libraries/doltcore/env/actions/branch.go
vendored
12
go/libraries/doltcore/env/actions/branch.go
vendored
@@ -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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user