1package commands
2
3import (
4 "github.com/spf13/cobra"
5
6 "github.com/git-bug/git-bug/commands/execenv"
7)
8
9func newWipeCommand(env *execenv.Env) *cobra.Command {
10 cmd := &cobra.Command{
11 Use: "wipe",
12 Short: "Wipe git-bug from the git repository",
13 PreRunE: execenv.LoadBackend(env),
14 RunE: func(cmd *cobra.Command, args []string) error {
15 return runWipe(env)
16 },
17 }
18
19 return cmd
20}
21
22func runWipe(env *execenv.Env) error {
23 env.Out.Println("cleaning entities...")
24 err := env.Backend.RemoveAll()
25 if err != nil {
26 _ = env.Backend.Close()
27 return err
28 }
29
30 env.Out.Println("cleaning git config ...")
31 err = env.Backend.ClearUserIdentity()
32 if err != nil {
33 _ = env.Backend.Close()
34 return err
35 }
36
37 err = env.Backend.LocalConfig().RemoveAll("git-bug")
38 if err != nil {
39 _ = env.Backend.Close()
40 return err
41 }
42
43 storage := env.Backend.LocalStorage()
44
45 err = env.Backend.Close()
46 if err != nil {
47 return err
48 }
49
50 env.Out.Println("cleaning caches ...")
51 err = storage.RemoveAll(".")
52 if err != nil {
53 return err
54 }
55
56 return nil
57}