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 2acb6c6
Show file tree
Hide file tree
Showing 3 changed files with 17 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
14 changes: 12 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,16 @@ 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) {
var fs = afero.NewOsFs()
gitInitialized, _ := afero.DirExists(fs, filepath.Join(getRootPath(), ".git"))
if !gitInitialized {
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 +126,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
1 change: 1 addition & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var versionCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
log.Println(version)
},
PersistentPreRun: func(cmd *cobra.Command, args []string) {},
}

func init() {
Expand Down

0 comments on commit 2acb6c6

Please sign in to comment.