-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Provide manual install mode (#124)
- Now you can use `--use-manual` for the installer and Githooks will not set `init.templateDir` nor `core.hooksPath` and the user is responsible to install hooks into repositories by `git hooks install` which use Githooks.
- Loading branch information
Showing
53 changed files
with
494 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package install | ||
|
||
import ( | ||
"github.com/gabyx/githooks/githooks/git" | ||
"github.com/gabyx/githooks/githooks/hooks" | ||
) | ||
|
||
type InstallModeType int | ||
type installModeType struct { | ||
None InstallModeType | ||
TemplateDir InstallModeType | ||
CoreHooksPath InstallModeType | ||
Manual InstallModeType | ||
} | ||
|
||
// InstallModeTypeV enumerates all types of install modes. | ||
var InstallModeTypeV = &installModeType{TemplateDir: 0, CoreHooksPath: 1, Manual: 2, None: 3} // nolint:gomnd | ||
|
||
// GetInstallMode returns the current set install mode of Githooks. | ||
func GetInstallMode(gitx *git.Context) InstallModeType { | ||
useManual := gitx.GetConfig(hooks.GitCKUseManual, git.GlobalScope) == git.GitCVTrue | ||
useCoreHooksPathValue := gitx.GetConfig(hooks.GitCKUseCoreHooksPath, git.GlobalScope) | ||
|
||
switch { | ||
case useManual: | ||
return InstallModeTypeV.Manual | ||
case useCoreHooksPathValue == git.GitCVTrue: | ||
return InstallModeTypeV.CoreHooksPath | ||
case useCoreHooksPathValue == git.GitCVFalse: | ||
return InstallModeTypeV.TemplateDir | ||
default: | ||
return InstallModeTypeV.None | ||
} | ||
|
||
} | ||
|
||
// GetInstallModeName returns a string for the install mode. | ||
func GetInstallModeName(installMode InstallModeType) string { | ||
switch installMode { | ||
case InstallModeTypeV.Manual: | ||
return "manual" | ||
case InstallModeTypeV.TemplateDir: | ||
return "template-dir" | ||
case InstallModeTypeV.CoreHooksPath: | ||
return "core-hooks-path" | ||
default: | ||
return "none" | ||
} | ||
} | ||
|
||
// MapInstallerArgsToInstallMode maps installer arguments to install modes. | ||
func MapInstallerArgsToInstallMode( | ||
useCoreHooksPath bool, | ||
useManual bool) InstallModeType { | ||
|
||
switch { | ||
case useManual: | ||
return InstallModeTypeV.Manual | ||
case useCoreHooksPath: | ||
return InstallModeTypeV.CoreHooksPath | ||
default: | ||
return InstallModeTypeV.TemplateDir | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.