Skip to content

fix: preserve json output for empty results - #248

Merged
andrew merged 2 commits into
git-pkgs:mainfrom
sanmaxdev:fix/json-empty-results
Jun 29, 2026
Merged

andrew merged 2 commits into
git-pkgs:mainfrom
sanmaxdev:fix/json-empty-results

Conversation

@sanmaxdev

Copy link
Copy Markdown
Contributor

Summary

  • keep --format=json responses as JSON arrays when result sets are empty
  • preserve the existing empty-result messages for text output
  • add regression coverage for empty search, log, and notes JSON output

Testing

  • go test ./cmd
  • go test ./...
  • go build ./...
  • go tool golangci-lint run ./...
  • manual reproduction with git-pkgs search definitely-not-present --format=json

Closes #233

@andrew andrew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pattern is right (move the empty check into the text branch, nonNilSlice so the encoder emits [] not null) and the test is good, but coverage is incomplete for a PR that closes #233.

The issue explicitly names six files; this fixes three (search.go, log.go, notes.go) plus vulns log, but skips:

  • cmd/blame.go:53
  • cmd/tree.go:66
  • cmd/outdated.go:82,163

The issue also says there may be more. The same if len(x) == 0 { print text; return nil } before the format switch appears in:

  • cmd/diff.go:127
  • cmd/show.go:59
  • cmd/stale.go:49
  • cmd/where.go:148
  • cmd/history.go:85
  • cmd/licenses.go:130
  • cmd/integrity.go:100,266
  • cmd/vulns.go:417,461,1251,1620,1732,1989

Since nonNilSlice is already in place and the change is mechanical, please cover at least the three files named in the issue, and ideally the rest so #233 can actually close.

Heads up: cmd/helpers.go will conflict with #251 (both insert at the same spot) — whichever lands second will need a rebase.

@sanmaxdev

Copy link
Copy Markdown
Contributor Author

Updated the empty JSON fix to cover the remaining commands called out in the review: blame, tree, outdated, diff, show, stale, and where.

Verified with:

  • go test ./cmd -run TestEmptyResultsRespectJSONFormat -count=1
  • go test ./cmd -count=1
  • go test ./... -count=1
  • git diff --check

@andrew andrew left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the follow-up — all six files named in #233 are now covered plus diff/show/stale/where, and the table-driven test is a nice guard.

history.go, licenses.go, integrity.go, and the remaining vulns.go sites still have the same pattern; I'll open a follow-up issue for those rather than block this further.

Heads up #251 is still open, so whichever lands second will need a small rebase around cmd/helpers.go.

@andrew
andrew merged commit cd00b9a into git-pkgs:main Jun 29, 2026
4 checks passed
@sanmaxdev
sanmaxdev deleted the fix/json-empty-results branch June 29, 2026 10:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JSON output is invalid for empty result sets

3 participants