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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: execute files command within configured root #607

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Loading