From 7f3d3f0be4bb74e9a7a657e0f61b57a8a747d16f Mon Sep 17 00:00:00 2001 From: BakerNet Date: Thu, 1 Oct 2026 14:06:52 -0700 Subject: [PATCH] Fix hunk filtering on MacOS and update covbadge --- README.md | 2 +- internal/app/app.go | 17 ++++++++++++++--- internal/app/hunk_filter_test.go | 12 +++++++++--- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 75a8930..2bb4db8 100644 --- a/README.md +++ b/README.md @@ -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) diff --git a/internal/app/app.go b/internal/app/app.go index 23589a6..bbb09f0 100644 --- a/internal/app/app.go +++ b/internal/app/app.go @@ -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 { diff --git a/internal/app/hunk_filter_test.go b/internal/app/hunk_filter_test.go index c3c9c51..1cc6780 100644 --- a/internal/app/hunk_filter_test.go +++ b/internal/app/hunk_filter_test.go @@ -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) } }