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

Don't auto-install lefthook if not found #602

Merged
merged 1 commit into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
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
12 changes: 6 additions & 6 deletions internal/git/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,19 +108,19 @@ func NewRepository(fs afero.Fs, git *CommandExecutor) (*Repository, error) {
// StagedFiles returns a list of staged files
// or an error if git command fails.
func (r *Repository) StagedFiles() ([]string, error) {
return r.FilesByCommand(cmdStagedFiles)
return r.FilesByCommand(cmdStagedFiles, "")
}

// StagedFiles returns a list of all files in repository
// or an error if git command fails.
func (r *Repository) AllFiles() ([]string, error) {
return r.FilesByCommand(cmdAllFiles)
return r.FilesByCommand(cmdAllFiles, "")
}

// PushFiles returns a list of files that are ready to be pushed
// or an error if git command fails.
func (r *Repository) PushFiles() ([]string, error) {
res, err := r.FilesByCommand(cmdPushFilesBase)
res, err := r.FilesByCommand(cmdPushFilesBase, "")
if err == nil {
return res, nil
}
Expand All @@ -147,7 +147,7 @@ func (r *Repository) PushFiles() ([]string, error) {
r.headBranch = r.emptyTreeSHA
}

return r.FilesByCommand(append(cmdPushFilesHead, r.headBranch))
return r.FilesByCommand(append(cmdPushFilesHead, r.headBranch), "")
}

// PartiallyStagedFiles returns the list of files that have both staged and
Expand Down Expand Up @@ -316,8 +316,8 @@ func (r *Repository) AddFiles(files []string) error {
}

// FilesByCommand accepts git command and returns its result as a list of filepaths.
func (r *Repository) FilesByCommand(command []string) ([]string, error) {
lines, err := r.Git.CmdLines(command)
func (r *Repository) FilesByCommand(command []string, folder string) ([]string, error) {
lines, err := r.Git.CmdLinesWithinFolder(command, folder)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/lefthook/runner/prepare_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func (r *Runner) buildRun(command *config.Command) (*run, error) {
} else {
cmd = []string{"sh", "-c", filesCmd}
}
return r.Repo.FilesByCommand(cmd)
return r.Repo.FilesByCommand(cmd, command.Root)
}
}

Expand Down
3 changes: 0 additions & 3 deletions internal/templates/hook.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ call_lefthook()
elif command -v mint >/dev/null 2>&1
then
mint run csjones/lefthook-plugin "$@"
elif command -v npx >/dev/null 2>&1
then
npx lefthook "$@"
else
echo "Can't find lefthook in PATH"
{{- if .AssertLefthookInstalled}}
Expand Down
Loading