aboutsummaryrefslogtreecommitdiffstats
path: root/commands/wipe.go
blob: ce9da032ec4d050e1d9c6ad7a18249db03609dc7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package commands

import (
	"github.com/spf13/cobra"

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

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

	return cmd
}

func runWipe(env *execenv.Env) error {
	env.Out.Println("cleaning entities...")
	err := env.Backend.RemoveAll()
	if err != nil {
		_ = env.Backend.Close()
		return err
	}

	env.Out.Println("cleaning git config ...")
	err = env.Backend.ClearUserIdentity()
	if err != nil {
		_ = env.Backend.Close()
		return err
	}
	err = env.Backend.LocalConfig().RemoveAll("git-bug")
	if err != nil {
		_ = env.Backend.Close()
		return err
	}

	storage := env.Backend.LocalStorage()

	err = env.Backend.Close()
	if err != nil {
		return err
	}

	env.Out.Println("cleaning caches ...")
	err = storage.RemoveAll(".")
	if err != nil {
		return err
	}

	return nil
}