git-lfs/commands/command_uninit.go
Taylor Blau c7cb8e0303 lfs: promote Hooks and Filters to types
This commit introduces two new types into the API: Hook, and Filter.

Both `Hook` and `Filter` are abstractions built on Git hooks and filters
respectively. Each type knows how to install and uninstall itself. These
processes are utilized by the setup method in the `lfs` package, and the
appropriate calls have been updated in the init and uninit commands.

These abstractions were introduced to make adding/removing required filters and
hooks easier for future projects, including the migration away from the smudge
filter.

Eventually it seems appropriate to move both new types into the `git` package,
as opposed to the `lfs` package. At the time of writing this commit, there is
some coupling against state defined in the `lfs` package (i.e., whether or not
we're currently in a git repo, the local working directory, etc). At somepoint
it would be nice to remove that coupling and move these new types into the
`git` package.
2015-09-01 18:19:34 -04:00

48 lines
1.0 KiB
Go

package commands
import (
"github.com/github/git-lfs/lfs"
"github.com/github/git-lfs/vendor/_nuts/github.com/spf13/cobra"
)
var (
// uninitCmd removes any configuration and hooks set by Git LFS.
uninitCmd = &cobra.Command{
Use: "uninit",
Short: "Clear the Git LFS configuration",
Run: uninitCommand,
}
// uninitHooksCmd removes any hooks created by Git LFS.
uninitHooksCmd = &cobra.Command{
Use: "hooks",
Short: "Clear only the Git hooks for the current repository",
Run: uninitHooksCommand,
}
)
func uninitCommand(cmd *cobra.Command, args []string) {
if err := lfs.TeardownFilters(); err != nil {
Error(err.Error())
}
Print("Global Git LFS configuration has been removed.")
if lfs.InRepo() {
uninitHooksCommand(cmd, args)
}
}
func uninitHooksCommand(cmd *cobra.Command, args []string) {
if err := lfs.UninstallHooks(); err != nil {
Error(err.Error())
}
Print("Hooks for this repository have been removed.")
}
func init() {
uninitCmd.AddCommand(uninitHooksCmd)
RootCmd.AddCommand(uninitCmd)
}