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

Create .git/hooks directory when it does not exist #169

Merged
merged 3 commits into from
Apr 26, 2021

Conversation

DmitryTsepelev
Copy link
Contributor

@DmitryTsepelev DmitryTsepelev commented Apr 26, 2021

Sometimes .git/hooks directory does not exist and lefthook fails to init hooks. The solution is to create the directory when it does not exist.

Closes #158.

Copy link
Member

@Envek Envek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You added check for git hooks uninstall. But what about installing?

lefthook/cmd/add.go

Lines 97 to 111 in 04f9b56

pathToFile := filepath.Join(getGitHooksDir(), hookName)
if yes, _ := afero.Exists(fs, pathToFile); yes {
if isLefthookFile(pathToFile) {
e := fs.Remove(pathToFile)
check(e)
} else {
if yes, _ := afero.Exists(fs, pathToFile+".old"); yes {
panic("Can`t rename " + hookName + " to " + hookName + ".old File already exists")
}
e := fs.Rename(pathToFile, pathToFile+".old")
log.Println("Existed " + hookName + " hook renamed to " + hookName + ".old")
check(e)
}
}

@DmitryTsepelev
Copy link
Contributor Author

DmitryTsepelev commented Apr 26, 2021

When lefthook is initialized, it calls DeleteGitHooks, so it guarantees that there was .git/hooks initially. Deleting the folder manually after the init sounds like sam sebe zlobny buratino.

Copy link
Member

@Envek Envek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is so counter-intuitive!

@Envek
Copy link
Member

Envek commented Apr 26, 2021

Btw, Travis is failing.

@DmitryTsepelev
Copy link
Contributor Author

fixed

if (err != nil) {
log.Println("⚠️ ", au.Bold(".git/hooks"), "directory does not exist, creating")

if err := os.MkdirAll(hooksPath, os.ModePerm); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope we will change it back to os.Mkdir while fixing #90

@Envek Envek merged commit ac5aaa7 into evilmartians:master Apr 26, 2021
DmitryTsepelev added a commit to DmitryTsepelev/lefthook that referenced this pull request Apr 27, 2021
DmitryTsepelev added a commit to DmitryTsepelev/lefthook that referenced this pull request Apr 27, 2021
DmitryTsepelev added a commit to DmitryTsepelev/lefthook that referenced this pull request Apr 27, 2021
DmitryTsepelev added a commit to DmitryTsepelev/lefthook that referenced this pull request Apr 27, 2021
Envek pushed a commit that referenced this pull request Apr 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

No pre-commit file?
3 participants