Skip to content

Commit

Permalink
fix!: execute files command within configured root (evilmartians#607)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexox committed Oct 22, 2024
1 parent 5517878 commit baefefc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
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

0 comments on commit baefefc

Please sign in to comment.