aboutsummaryrefslogtreecommitdiffstats
path: root/entity/dag/entity_actions.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2021-02-10 18:22:21 +0100
committerMichael Muré <batolettre@gmail.com>2021-02-14 12:19:03 +0100
commitef05c15f87468e0f4f1c688b0b9359cee2181c68 (patch)
treefba60b3d288ae6f6c2b8d8c18006e222c71807f5 /entity/dag/entity_actions.go
parentf74166914c344329f08823770982f12966c79a77 (diff)
downloadgit-bug-ef05c15f87468e0f4f1c688b0b9359cee2181c68.tar.gz
entity: implement remove
Diffstat (limited to 'entity/dag/entity_actions.go')
-rw-r--r--entity/dag/entity_actions.go28
1 files changed, 26 insertions, 2 deletions
diff --git a/entity/dag/entity_actions.go b/entity/dag/entity_actions.go
index 6f6fe45c..fa50473c 100644
--- a/entity/dag/entity_actions.go
+++ b/entity/dag/entity_actions.go
@@ -228,6 +228,30 @@ func merge(def Definition, repo repository.ClockedRepo, remoteRef string, author
return entity.NewMergeUpdatedStatus(id, localEntity)
}
-func Remove() error {
- panic("")
+// Remove delete an Entity.
+// Remove is idempotent.
+func Remove(def Definition, repo repository.ClockedRepo, id entity.Id) error {
+ var matches []string
+
+ ref := fmt.Sprintf("refs/%s/%s", def.namespace, id.String())
+ matches = append(matches, ref)
+
+ remotes, err := repo.GetRemotes()
+ if err != nil {
+ return err
+ }
+
+ for remote := range remotes {
+ ref = fmt.Sprintf("refs/remotes/%s/%s/%s", remote, def.namespace, id.String())
+ matches = append(matches, ref)
+ }
+
+ for _, ref = range matches {
+ err = repo.RemoveRef(ref)
+ if err != nil {
+ return err
+ }
+ }
+
+ return nil
}