Skip to content

Commit

Permalink
add wipe sub-command that remove local bugs and identities
Browse files Browse the repository at this point in the history
  • Loading branch information
zinderic committed Nov 28, 2022
1 parent 70bd737 commit 512e68b
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 16 deletions.
5 changes: 3 additions & 2 deletions commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (

"github.com/spf13/cobra"

"github.com/MichaelMure/git-bug/commands/bridge"
bridgecmd "github.com/MichaelMure/git-bug/commands/bridge"
usercmd "github.com/MichaelMure/git-bug/commands/user"

"github.com/MichaelMure/git-bug/commands/bug"
bugcmd "github.com/MichaelMure/git-bug/commands/bug"
"github.com/MichaelMure/git-bug/commands/execenv"
)

Expand Down Expand Up @@ -82,6 +82,7 @@ the same git remote you are already using to collaborate with other people.

cmd.AddCommand(newCommandsCommand())
cmd.AddCommand(newVersionCommand())
cmd.AddCommand(newWipeCommand())

return cmd
}
Expand Down
42 changes: 42 additions & 0 deletions commands/wipe.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package commands

import (
"github.com/MichaelMure/git-bug/entities/bug"
"github.com/MichaelMure/git-bug/entities/identity"

"github.com/spf13/cobra"

"github.com/MichaelMure/git-bug/commands/execenv"
)

func newWipeCommand() *cobra.Command {
env := execenv.NewEnv()

cmd := &cobra.Command{
Use: "wipe",
Short: "Wipe git-bug from git repository",
Long: "Wipe git-bug from git repository",
PreRunE: execenv.LoadRepo(env),
RunE: execenv.CloseBackend(env, func(cmd *cobra.Command, args []string) error {
return runWipe(env)
}),
}

return cmd
}

func runWipe(env *execenv.Env) error {

env.Out.Println("cleaning bugs..")
err := bug.RemoveAll(env.Repo)
if err != nil {
return err
}
env.Out.Println("cleaning identities..")
err = identity.RemoveAll(env.Repo)
if err != nil {
return err
}

return nil
}
27 changes: 27 additions & 0 deletions doc/man/git-bug-wipe.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.nh
.TH "GIT-BUG" "1" "Apr 2019" "Generated from git-bug's source code" ""

.SH NAME
.PP
git-bug-wipe - Wipe git-bug from git repository


.SH SYNOPSIS
.PP
\fBgit-bug wipe [flags]\fP


.SH DESCRIPTION
.PP
Wipe git-bug from git repository


.SH OPTIONS
.PP
\fB-h\fP, \fB--help\fP[=false]
help for wipe


.SH SEE ALSO
.PP
\fBgit-bug(1)\fP
2 changes: 1 addition & 1 deletion doc/man/git-bug.1
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ the same git remote you are already using to collaborate with other people.

.SH SEE ALSO
.PP
\fBgit-bug-bridge(1)\fP, \fBgit-bug-bug(1)\fP, \fBgit-bug-commands(1)\fP, \fBgit-bug-label(1)\fP, \fBgit-bug-pull(1)\fP, \fBgit-bug-push(1)\fP, \fBgit-bug-termui(1)\fP, \fBgit-bug-user(1)\fP, \fBgit-bug-version(1)\fP, \fBgit-bug-webui(1)\fP
\fBgit-bug-bridge(1)\fP, \fBgit-bug-bug(1)\fP, \fBgit-bug-commands(1)\fP, \fBgit-bug-label(1)\fP, \fBgit-bug-pull(1)\fP, \fBgit-bug-push(1)\fP, \fBgit-bug-termui(1)\fP, \fBgit-bug-user(1)\fP, \fBgit-bug-version(1)\fP, \fBgit-bug-webui(1)\fP, \fBgit-bug-wipe(1)\fP
1 change: 1 addition & 0 deletions doc/md/git-bug.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ git-bug [flags]
* [git-bug user](git-bug_user.md) - List identities
* [git-bug version](git-bug_version.md) - Show git-bug version information
* [git-bug webui](git-bug_webui.md) - Launch the web UI
* [git-bug wipe](git-bug_wipe.md) - Wipe git-bug from git repository

22 changes: 22 additions & 0 deletions doc/md/git-bug_wipe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## git-bug wipe

Wipe git-bug from git repository

### Synopsis

Wipe git-bug from git repository

```
git-bug wipe [flags]
```

### Options

```
-h, --help help for wipe
```

### SEE ALSO

* [git-bug](git-bug.md) - A bug tracker embedded in Git

4 changes: 4 additions & 0 deletions entities/bug/bug_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,7 @@ func MergeAll(repo repository.ClockedRepo, resolvers entity.Resolvers, remote st
func Remove(repo repository.ClockedRepo, id entity.Id) error {
return dag.Remove(def, repo, id)
}

func RemoveAll(repo repository.ClockedRepo) error {
return dag.RemoveAll(def, repo)
}
15 changes: 15 additions & 0 deletions entities/identity/identity_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,18 @@ func MergeAll(repo repository.ClockedRepo, remote string) <-chan entity.MergeRes

return out
}

func RemoveAll(repo repository.ClockedRepo) error {
localIds, err := ListLocalIds(repo)
if err != nil {
return err
}
for _, id := range localIds {
fmt.Println("removing", id.Human())
err = RemoveIdentity(repo, id)
if err != nil {
return err
}
}
return nil
}
44 changes: 31 additions & 13 deletions entity/dag/entity_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package dag

import (
"fmt"

"github.com/pkg/errors"

"github.com/MichaelMure/git-bug/entities/identity"
Expand Down Expand Up @@ -53,18 +52,18 @@ func Pull(def Definition, repo repository.ClockedRepo, resolvers entity.Resolver
// MergeAll will merge all the available remote Entity:
//
// Multiple scenario exist:
// 1. if the remote Entity doesn't exist locally, it's created
// --> emit entity.MergeStatusNew
// 2. if the remote and local Entity have the same state, nothing is changed
// --> emit entity.MergeStatusNothing
// 3. if the local Entity has new commits but the remote don't, nothing is changed
// --> emit entity.MergeStatusNothing
// 4. if the remote has new commit, the local bug is updated to match the same history
// (fast-forward update)
// --> emit entity.MergeStatusUpdated
// 5. if both local and remote Entity have new commits (that is, we have a concurrent edition),
// a merge commit with an empty operationPack is created to join both branch and form a DAG.
// --> emit entity.MergeStatusUpdated
// 1. if the remote Entity doesn't exist locally, it's created
// --> emit entity.MergeStatusNew
// 2. if the remote and local Entity have the same state, nothing is changed
// --> emit entity.MergeStatusNothing
// 3. if the local Entity has new commits but the remote don't, nothing is changed
// --> emit entity.MergeStatusNothing
// 4. if the remote has new commit, the local bug is updated to match the same history
// (fast-forward update)
// --> emit entity.MergeStatusUpdated
// 5. if both local and remote Entity have new commits (that is, we have a concurrent edition),
// a merge commit with an empty operationPack is created to join both branch and form a DAG.
// --> emit entity.MergeStatusUpdated
//
// Note: an author is necessary for the case where a merge commit is created, as this commit will
// have an author and may be signed if a signing key is available.
Expand Down Expand Up @@ -258,3 +257,22 @@ func Remove(def Definition, repo repository.ClockedRepo, id entity.Id) error {

return nil
}

// RemoveAll delete all Entity items for all identities
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
}
}
err = repo.ClearBleveIndex(def.Typename)
if err != nil {
return err
}
return nil
}
34 changes: 34 additions & 0 deletions entity/dag/entity_actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,3 +406,37 @@ func TestRemove(t *testing.T) {
err = Remove(def, repoA, e.Id())
require.NoError(t, err)
}

func TestRemoveAll(t *testing.T) {

repo, id1, id2, _, def := makeTestContext()
e := New(def)
e.Append(newOp1(id1, "bug1"))
e.Append(newOp1(id2, "bug2"))

type args struct {
def Definition
repo repository.ClockedRepo
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "wipe",
args: args{
def,
repo,
},
wantErr: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := RemoveAll(tt.args.def, tt.args.repo); (err != nil) != tt.wantErr {
t.Errorf("RemoveAll() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}

0 comments on commit 512e68b

Please sign in to comment.