diff options
author | Kalin Staykov <k.t.staykov@gmail.com> | 2022-11-26 15:49:59 +0200 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2023-01-11 14:58:58 +0100 |
commit | fc266b733cf0ea794209031e3500ab3f86db6cee (patch) | |
tree | bae1996ec19fb74446429200e52cdb942f60ac54 /entity | |
parent | 9c50a359704f4edd2f33df6d256e032feae3a576 (diff) | |
download | git-bug-fc266b733cf0ea794209031e3500ab3f86db6cee.tar.gz |
add wipe sub-command that remove local bugs and identities
Diffstat (limited to 'entity')
-rw-r--r-- | entity/dag/entity_actions.go | 16 | ||||
-rw-r--r-- | entity/dag/entity_actions_test.go | 31 |
2 files changed, 47 insertions, 0 deletions
diff --git a/entity/dag/entity_actions.go b/entity/dag/entity_actions.go index 97a68c36..5f0abec3 100644 --- a/entity/dag/entity_actions.go +++ b/entity/dag/entity_actions.go @@ -258,3 +258,19 @@ func Remove(def Definition, repo repository.ClockedRepo, id entity.Id) error { return nil } + +// RemoveAll delete all Entity matching the Definition. +// RemoveAll is idempotent. +func RemoveAll(def Definition, repo repository.ClockedRepo) error { + localIds, err := ListLocalIds(def, repo) + if err != nil { + return err + } + for _, id := range localIds { + err = Remove(def, repo, id) + if err != nil { + return err + } + } + return nil +} diff --git a/entity/dag/entity_actions_test.go b/entity/dag/entity_actions_test.go index fd219644..6181614b 100644 --- a/entity/dag/entity_actions_test.go +++ b/entity/dag/entity_actions_test.go @@ -406,3 +406,34 @@ func TestRemove(t *testing.T) { err = Remove(def, repoA, e.Id()) require.NoError(t, err) } + +func TestRemoveAll(t *testing.T) { + repoA, _, _, id1, _, resolvers, def := makeTestContextRemote(t) + + var ids []entity.Id + + for i := 0; i < 10; i++ { + e := New(def) + e.Append(newOp1(id1, "foo")) + require.NoError(t, e.Commit(repoA)) + ids = append(ids, e.Id()) + } + + _, err := Push(def, repoA, "remote") + require.NoError(t, err) + + err = RemoveAll(def, repoA) + require.NoError(t, err) + + for _, id := range ids { + _, err = Read(def, wrapper, repoA, resolvers, id) + require.Error(t, err) + + _, err = readRemote(def, wrapper, repoA, resolvers, "remote", id) + require.Error(t, err) + } + + // Remove is idempotent + err = RemoveAll(def, repoA) + require.NoError(t, err) +} |