Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not init git config on help and version cmds #209

Merged
merged 1 commit into from
Jun 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const (
configExtensionPattern string = ".*"
defaultFilePermission os.FileMode = 0755
defaultDirPermission os.FileMode = 0666
gitInitMessage string = `This command must be executed within git repository.
Change working directory or initialize new repository with 'git init'.`
)

var (
Expand All @@ -49,14 +51,13 @@ lefthook install`,
return
}

initGitConfig()

if gitInitialized, _ := afero.Exists(appFs, filepath.Join(getRootPath(), ".git")); gitInitialized {
return
}

message := `This command must be executed within git repository.
Change working directory or initialize new repository with 'git init'.`

log.Fatal(au.Brown(message))
log.Fatal(au.Brown(gitInitMessage))
},
}

Expand Down Expand Up @@ -90,9 +91,6 @@ func initAurora() {
func initConfig() {
log.SetFlags(0)

setRootPath()
setGitHooksPath(getHooksPathFromGitConfig())

// store original config before merge
originConfig = viper.New()
originConfig.SetConfigName(configFileName)
Expand Down Expand Up @@ -123,6 +121,11 @@ func initConfig() {
viper.AutomaticEnv()
}

func initGitConfig() {
setRootPath()
setGitHooksPath(getHooksPathFromGitConfig())
}

func getRootPath() string {
return rootPath
}
Expand All @@ -131,7 +134,12 @@ func getRootPath() string {
func setRootPath() {
cmd := exec.Command("git", "rev-parse", "--show-toplevel")

outputBytes, _ := cmd.CombinedOutput()
outputBytes, err := cmd.CombinedOutput()

if err != nil {
log.Fatal(au.Brown(gitInitMessage))
}

rootPath = strings.TrimSpace(string(outputBytes))
}

Expand Down