git-lfs/commands/command_uninstall.go

45 lines
1.6 KiB
Go
Raw Normal View History

2015-11-16 20:37:08 +00:00
package commands
import (
"github.com/git-lfs/git-lfs/v3/git"
"github.com/spf13/cobra"
2015-11-16 20:37:08 +00:00
)
// uninstallCmd removes any configuration and hooks set by Git LFS.
2015-11-16 20:37:08 +00:00
func uninstallCommand(cmd *cobra.Command, args []string) {
2017-10-18 21:19:21 +00:00
if err := cmdInstallOptions().Uninstall(); err != nil {
command/uninstall: report errors and correct usage When uninstalling, if any "git config --remove-section" commands failed, we would previously ignore the error and proceed without reporting it. We now at least report the errors in a warning message printed to standard output, akin to the handling introduced to the "git lfs install" command in PR #2673. However, we likely can not alter the uninstall behaviour further and actually exit with an error code in these cases (skipping any attemp to uninstall our hooks) because users may depend on the existing willingness of "git lfs uninstall" to try to uninstall as much as possible, and may have scripts which depend on this behaviour. Thus we don't call os.Exit(2) in the manner introduced to "git lfs install" in PR #3624. On the one hand, this change means users who run an uninstall command when no relevant Git LFS filter configurations exist will see a "WARNING" message which may look somewhat scary. On the other hand, we already report other errors such as "no such file or directory" when hooks do not exist, and by reporting these git-config(1) errors we will be able to better support new options such as --worktree, where git-config may report error conditions such as when the worktreeConfig extension is not properly defined yet. So on balance, we aim for more rather than less error reporting. And separately, although the usage text for all command options is unused (because we override Cobra's usage function in run.go to always show the man page text instead), we still correct it here before we add any new options.
2020-06-16 00:55:17 +00:00
Print("WARNING: %s", err.Error())
2015-11-16 20:37:08 +00:00
}
if !skipRepoInstall && (localInstall || worktreeInstall || cfg.InRepo()) {
2015-11-16 20:37:08 +00:00
uninstallHooksCommand(cmd, args)
}
if systemInstall {
Print("System Git LFS configuration has been removed.")
} else if !(localInstall || worktreeInstall) {
Print("Global Git LFS configuration has been removed.")
}
2015-11-16 20:37:08 +00:00
}
// uninstallHooksCmd removes any hooks created by Git LFS.
2015-11-16 20:37:08 +00:00
func uninstallHooksCommand(cmd *cobra.Command, args []string) {
if err := uninstallHooks(); err != nil {
2015-11-16 20:37:08 +00:00
Error(err.Error())
}
Print("Hooks for this repository have been removed.")
}
func init() {
RegisterCommand("uninstall", uninstallCommand, func(cmd *cobra.Command) {
command/uninstall: report errors and correct usage When uninstalling, if any "git config --remove-section" commands failed, we would previously ignore the error and proceed without reporting it. We now at least report the errors in a warning message printed to standard output, akin to the handling introduced to the "git lfs install" command in PR #2673. However, we likely can not alter the uninstall behaviour further and actually exit with an error code in these cases (skipping any attemp to uninstall our hooks) because users may depend on the existing willingness of "git lfs uninstall" to try to uninstall as much as possible, and may have scripts which depend on this behaviour. Thus we don't call os.Exit(2) in the manner introduced to "git lfs install" in PR #3624. On the one hand, this change means users who run an uninstall command when no relevant Git LFS filter configurations exist will see a "WARNING" message which may look somewhat scary. On the other hand, we already report other errors such as "no such file or directory" when hooks do not exist, and by reporting these git-config(1) errors we will be able to better support new options such as --worktree, where git-config may report error conditions such as when the worktreeConfig extension is not properly defined yet. So on balance, we aim for more rather than less error reporting. And separately, although the usage text for all command options is unused (because we override Cobra's usage function in run.go to always show the man page text instead), we still correct it here before we add any new options.
2020-06-16 00:55:17 +00:00
cmd.Flags().BoolVarP(&localInstall, "local", "l", false, "Remove the Git LFS config for the local Git repository only.")
if git.IsGitVersionAtLeast("2.20.0") {
cmd.Flags().BoolVarP(&worktreeInstall, "worktree", "w", false, "Remove the Git LFS config for the current Git working tree, if multiple working trees are configured; otherwise, the same as --local.")
}
command/uninstall: report errors and correct usage When uninstalling, if any "git config --remove-section" commands failed, we would previously ignore the error and proceed without reporting it. We now at least report the errors in a warning message printed to standard output, akin to the handling introduced to the "git lfs install" command in PR #2673. However, we likely can not alter the uninstall behaviour further and actually exit with an error code in these cases (skipping any attemp to uninstall our hooks) because users may depend on the existing willingness of "git lfs uninstall" to try to uninstall as much as possible, and may have scripts which depend on this behaviour. Thus we don't call os.Exit(2) in the manner introduced to "git lfs install" in PR #3624. On the one hand, this change means users who run an uninstall command when no relevant Git LFS filter configurations exist will see a "WARNING" message which may look somewhat scary. On the other hand, we already report other errors such as "no such file or directory" when hooks do not exist, and by reporting these git-config(1) errors we will be able to better support new options such as --worktree, where git-config may report error conditions such as when the worktreeConfig extension is not properly defined yet. So on balance, we aim for more rather than less error reporting. And separately, although the usage text for all command options is unused (because we override Cobra's usage function in run.go to always show the man page text instead), we still correct it here before we add any new options.
2020-06-16 00:55:17 +00:00
cmd.Flags().BoolVarP(&systemInstall, "system", "", false, "Remove the Git LFS config in system-wide scope.")
cmd.Flags().BoolVarP(&skipRepoInstall, "skip-repo", "", false, "Skip repo setup, just uninstall global filters.")
cmd.AddCommand(NewCommand("hooks", uninstallHooksCommand))
})
2015-11-16 20:37:08 +00:00
}