go: env/actions/branch: When deleting a branch, also delete its working set ref.

This commit is contained in:
Aaron Son
2021-07-28 16:23:18 -07:00
parent fe231a0ad1
commit 5427c4e408
2 changed files with 16 additions and 1 deletions

View File

@@ -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)
}

View File

@@ -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())
}
}