2015-11-16 20:37:08 +00:00
package commands
import (
2020-06-15 22:10:28 +00:00
"github.com/git-lfs/git-lfs/git"
2016-05-23 18:02:27 +00:00
"github.com/spf13/cobra"
2015-11-16 20:37:08 +00:00
)
2016-08-10 15:33:25 +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
}
2020-06-15 22:10:28 +00:00
if ! skipRepoInstall && ( localInstall || worktreeInstall || cfg . InRepo ( ) ) {
2015-11-16 20:37:08 +00:00
uninstallHooksCommand ( cmd , args )
}
2017-01-24 23:33:29 +00:00
2018-10-17 18:27:03 +00:00
if systemInstall {
Print ( "System Git LFS configuration has been removed." )
2020-06-15 22:10:28 +00:00
} else if ! ( localInstall || worktreeInstall ) {
2018-04-18 22:21:59 +00:00
Print ( "Global Git LFS configuration has been removed." )
}
2015-11-16 20:37:08 +00:00
}
2016-08-10 15:33:25 +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 ) {
2017-10-18 21:42:00 +00:00
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 ( ) {
2016-09-01 16:09:38 +00:00
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." )
2020-06-15 22:10:28 +00:00
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." )
2018-10-17 18:53:04 +00:00
cmd . Flags ( ) . BoolVarP ( & skipRepoInstall , "skip-repo" , "" , false , "Skip repo setup, just uninstall global filters." )
2016-09-01 14:46:26 +00:00
cmd . AddCommand ( NewCommand ( "hooks" , uninstallHooksCommand ) )
2016-08-10 15:33:25 +00:00
} )
2015-11-16 20:37:08 +00:00
}