Skip to content

Commit

Permalink
Create .git/hooks directory when it does not exist (evilmartians#169)
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryTsepelev committed Apr 27, 2021
1 parent ac5aaa7 commit 503c78d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

## master (unreleased)

-[PR](https://github.com/evilmartians/lefthook/pull/169) Create .git/hooks directory when it does not exist @DmitryTsepelev
- [PR](https://github.com/evilmartians/lefthook/pull/171) Improve check for installed git @DmitryTsepelev
- [PR](https://github.com/evilmartians/lefthook/pull/169) Create .git/hooks directory when it does not exist @DmitryTsepelev

# 0.7.3 (2021-04-23)

-[PR](https://github.com/evilmartians/lefthook/pull/168) Package versions for all architectures (x86_64, ARM64, x86) into Ruby gem and NPM package @Envek
-[PR](https://github.com/evilmartians/lefthook/pull/167) Fix golang 15+ build @skryukov
- [PR](https://github.com/evilmartians/lefthook/pull/168) Package versions for all architectures (x86_64, ARM64, x86) into Ruby gem and NPM package @Envek
- [PR](https://github.com/evilmartians/lefthook/pull/167) Fix golang 15+ build @skryukov

# 0.7.2 (2020-02-02)

Expand Down
19 changes: 17 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"

"github.com/logrusorgru/aurora"
"github.com/spf13/afero"
"github.com/mattn/go-isatty"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -43,6 +44,21 @@ var rootCmd = &cobra.Command{
Long: `After installation go to your project directory
and execute the following command:
lefthook install`,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
if cmd.Name() == "help" || cmd.Name() == "version" {
return
}

var fs = afero.NewOsFs()
if gitInitialized, _ := afero.DirExists(fs, 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))
},
}

func Execute() {
Expand Down Expand Up @@ -115,8 +131,7 @@ func setRootPath(path string) {
// get absolute path to .git dir (project root)
cmd := exec.Command("git", "rev-parse", "--show-toplevel")

outputBytes, err := cmd.CombinedOutput()
check(err)
outputBytes, _ := cmd.CombinedOutput()
rootPath = strings.TrimSpace(string(outputBytes))
}

Expand Down

0 comments on commit 503c78d

Please sign in to comment.