github.com/emmahsax/go-git-helper@v0.0.8-0.20240519163017-907b9de0fa52/cmd/forgetLocalCommits/forgetLocalCommits.go (about) 1 package forgetLocalCommits 2 3 import ( 4 "github.com/emmahsax/go-git-helper/internal/executor" 5 "github.com/emmahsax/go-git-helper/internal/git" 6 "github.com/spf13/cobra" 7 ) 8 9 type ForgetLocalCommits struct { 10 Debug bool 11 Executor executor.ExecutorInterface 12 } 13 14 func NewCommand() *cobra.Command { 15 var ( 16 debug bool 17 ) 18 19 cmd := &cobra.Command{ 20 Use: "forget-local-commits", 21 Short: "Forget all commits that aren't pushed to remote", 22 Args: cobra.ExactArgs(0), 23 DisableFlagsInUseLine: true, 24 RunE: func(cmd *cobra.Command, args []string) error { 25 newForgetLocalCommits(debug, executor.NewExecutor(debug)).execute() 26 return nil 27 }, 28 } 29 30 cmd.Flags().BoolVar(&debug, "debug", false, "enables debug mode") 31 32 return cmd 33 } 34 35 func newForgetLocalCommits(debug bool, executor executor.ExecutorInterface) *ForgetLocalCommits { 36 return &ForgetLocalCommits{ 37 Debug: debug, 38 Executor: executor, 39 } 40 } 41 42 func (flc *ForgetLocalCommits) execute() { 43 g := git.NewGit(flc.Debug, flc.Executor) 44 g.Pull() 45 g.Reset() 46 }