Skip to content

Commit 082da09

Browse files
fullstackjamclaude
andauthored
Fix dotfiles branch resolution and disk space calculation (#25)
* fix(ci): resolve dotfiles default branch via remote and silence Linux gosec resolveBranch fell back to "main" whenever local origin/HEAD wasn't a symbolic ref (e.g. cloned from an empty bare), causing TestClone_DetachedHeadFallback and any user with a master-default repo to fail with "ambiguous argument 'origin/main'". Add a final fallback that consults the remote via `git ls-remote --symref origin HEAD`. Also annotate the syscall.Statfs block-size conversion in brew.CheckDiskSpace so `golangci-lint run` is clean on Linux too (stat.Bsize is int64 on linux, uint32 on darwin — value is always non-negative). * ci: bump golangci-lint-action to v7 and migrate labeler config to v5 - golangci/golangci-lint-action@v6 only supports golangci-lint v1; with the recent bump to v2.11.4 it errors out at startup. Bump the action to v7, which is the v2-compatible release. - actions/labeler@v5 requires the new `changed-files` schema. The current config uses the v4 flat-glob form, so every PR fails labeling with "found unexpected type for label 'catalog'". Convert each entry to the v5 `changed-files: any-glob-to-any-file` form. * ci(lint): move dir exclusions out of run.exclude-dirs (rejected by v2.11.4) golangci-lint v2.11.4 enforces a stricter schema than 2.5 and rejects the deprecated `run.exclude-dirs` key with "additional properties 'exclude-dirs' not allowed". Move the directory list to `linters.exclusions.paths` (the v2 location) and drop the now-redundant per-path testutil rule. * fix(snapshot): CaptureNpm returns []string{} instead of nil when no globals When npm is installed but `npm list -g --depth=0 --parseable` returns only the prefix line (or only npm/corepack), the loop never appends and `var packages []string` stays nil. TestCaptureNpm_NoPanic asserts the returned slice is not nil, so the test fails on macOS-CI runners where npm is present but has no user-installed globals. Initialise as an empty slice to match the early-return contract. --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 5716c32 commit 082da09

File tree

6 files changed

+46
-20
lines changed

6 files changed

+46
-20
lines changed

.github/labeler.yml

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,40 @@
11
catalog:
2-
- internal/config/data/packages.yaml
2+
- changed-files:
3+
- any-glob-to-any-file:
4+
- internal/config/data/packages.yaml
35

46
brew:
5-
- internal/brew/**
7+
- changed-files:
8+
- any-glob-to-any-file:
9+
- internal/brew/**
610

711
installer:
8-
- internal/installer/**
12+
- changed-files:
13+
- any-glob-to-any-file:
14+
- internal/installer/**
915

1016
ci:
11-
- .github/workflows/**
17+
- changed-files:
18+
- any-glob-to-any-file:
19+
- .github/workflows/**
1220

1321
docs:
14-
- "*.md"
15-
- docs/**
22+
- changed-files:
23+
- any-glob-to-any-file:
24+
- "*.md"
25+
- docs/**
1626

1727
tests:
18-
- "**/*_test.go"
28+
- changed-files:
29+
- any-glob-to-any-file:
30+
- "**/*_test.go"
1931

2032
snapshot:
21-
- internal/snapshot/**
33+
- changed-files:
34+
- any-glob-to-any-file:
35+
- internal/snapshot/**
2236

2337
ui:
24-
- internal/ui/**
38+
- changed-files:
39+
- any-glob-to-any-file:
40+
- internal/ui/**

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
with:
3030
go-version-file: "go.mod"
3131
- name: golangci-lint
32-
uses: golangci/golangci-lint-action@v6
32+
uses: golangci/golangci-lint-action@v7
3333
with:
3434
version: v2.11.4
3535

.golangci.yml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ version: "2"
22

33
run:
44
timeout: 5m
5-
exclude-dirs:
6-
- vendor
7-
- testutil
85

96
formatters:
107
enable:
@@ -46,13 +43,11 @@ linters:
4643
excludes:
4744
- G304 # File path provided as taint input — acceptable for CLI tools
4845
exclusions:
46+
paths:
47+
- vendor
48+
- testutil
4949
rules:
5050
- path: "_test\\.go"
5151
linters:
5252
- errcheck
5353
- gosec
54-
- path: "testutil/"
55-
linters:
56-
- gosec
57-
- errcheck
58-
- unused

internal/brew/brew.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,9 @@ func CheckDiskSpace() (float64, error) {
289289
if err := syscall.Statfs(home, &stat); err != nil {
290290
return 0, err
291291
}
292-
availableGB := float64(stat.Bavail*uint64(stat.Bsize)) / (1024 * 1024 * 1024)
292+
// stat.Bsize is uint32 on darwin and int64 on linux; the kernel always
293+
// reports a non-negative block size so the conversion is safe.
294+
availableGB := float64(stat.Bavail*uint64(stat.Bsize)) / (1024 * 1024 * 1024) //nolint:gosec // see comment above
293295
return availableGB, nil
294296
}
295297

internal/dotfiles/dotfiles.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,19 @@ func resolveBranch(dotfilesPath string) string {
159159
branch = strings.TrimPrefix(ref, "refs/remotes/origin/")
160160
}
161161
}
162+
// origin/HEAD may not be configured locally — ask the remote what its default branch is.
163+
if branch == "" || branch == "HEAD" {
164+
if out, err := gitOutputFunc([]string{"-C", dotfilesPath, "ls-remote", "--symref", "origin", "HEAD"}); err == nil {
165+
for _, line := range strings.Split(string(out), "\n") {
166+
if rest, ok := strings.CutPrefix(line, "ref: "); ok {
167+
if fields := strings.Fields(rest); len(fields) >= 1 {
168+
branch = strings.TrimPrefix(fields[0], "refs/heads/")
169+
break
170+
}
171+
}
172+
}
173+
}
174+
}
162175
if branch == "" || branch == "HEAD" {
163176
return "main"
164177
}

internal/snapshot/capture.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ func CaptureNpm() ([]string, error) {
183183
if len(lines) <= 1 {
184184
return []string{}, nil
185185
}
186-
var packages []string
186+
packages := []string{}
187187
for _, line := range lines[1:] {
188188
line = strings.TrimSpace(line)
189189
if line == "" {

0 commit comments

Comments
 (0)