Skip to content
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Code Ownership & Review Assignment Tool - GitHub CODEOWNERS but better

[![Go Report Card](https://goreportcard.com/badge/github.com/multimediallc/codeowners-plus)](https://goreportcard.com/report/github.com/multimediallc/codeowners-plus?kill_cache=1)
[![Tests](https://github.com/multimediallc/codeowners-plus/actions/workflows/go.yml/badge.svg)](https://github.com/multimediallc/codeowners-plus/actions/workflows/go.yml)
![Coverage](https://img.shields.io/badge/Coverage-83.6%25-brightgreen)
![Coverage](https://img.shields.io/badge/Coverage-83.7%25-brightgreen)
[![License](https://img.shields.io/badge/License-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](CODE_OF_CONDUCT.md)

Expand Down
17 changes: 14 additions & 3 deletions internal/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,11 +158,22 @@ func resolveHookPath(path, workspace string) (string, error) {
return resolved, nil
}

// resolveSymlinks resolves symlinks in the longest existing prefix of path,
// so a path that does not exist yet still gets the same canonical prefix as
// its existing parents (e.g. /var -> /private/var on macOS).
func resolveSymlinks(path string) string {
if real, err := filepath.EvalSymlinks(path); err == nil {
return real
path = filepath.Clean(path)
rest := ""
for dir := path; ; dir = filepath.Dir(dir) {
if real, err := filepath.EvalSymlinks(dir); err == nil {
return filepath.Join(real, rest)
}
parent := filepath.Dir(dir)
if parent == dir {
return path
}
rest = filepath.Join(filepath.Base(dir), rest)
}
return filepath.Clean(path)
}

func toHookHunks(bodies []string) []hook.Hunk {
Expand Down
12 changes: 9 additions & 3 deletions internal/app/hunk_filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,18 @@ func TestResolveHookPathFollowsASymlinkIntoTheCheckout(t *testing.T) {

// Local runs have no GITHUB_WORKSPACE, so an absolute path stands on its own.
func TestResolveHookPathWithoutAWorkspace(t *testing.T) {
path := filepath.Join(t.TempDir(), "filter")
dir := t.TempDir()
path := filepath.Join(dir, "filter")
got, err := resolveHookPath(path, "")
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if got != filepath.Clean(path) {
t.Errorf("expected %q, got %q", path, got)
// The temp dir may sit behind a symlink (/var -> /private/var on macOS).
realDir, err := filepath.EvalSymlinks(dir)
if err != nil {
t.Fatal(err)
}
if want := filepath.Join(realDir, "filter"); got != want {
t.Errorf("expected %q, got %q", want, got)
}
}
Loading