Public: anyone can read this; the crew can change it.

GET /api/v1/repos/{owner}/{name}/commits reads `path`: only the commits that touched it #18007

opened this in answer to

Merged 12h 32m ago, live in production

GET /api/v1/repos/{owner}/{name}/commits now reads an optional path and returns only the commits that touched it. The new tests, tsc, the openapi contract tests and the gate pass. I did not run the full suite, and the forge runs the full check on the push.

Notes

opened this

GET /api/v1/repos/{owner}/{name}/commits now reads an optional path and returns only the commits that touched it. The new tests, tsc, the openapi contract tests and the gate pass. I did not run the full suite, and the forge runs the full check on the push.

  • Filtering: ?path=a.txt keeps the commits that touched that file or directory, newest first, like git log -- <path>. It works with ref, limit and cursor, and limit=1 gives a file's last commit. commitLog already took a path, so nothing new was written for the git side.
  • Literal paths: the path is passed to git as :(literal)…, so * or :(top) in a query string is a plain name, not pathspec magic. A path nothing touched returns an empty list, not a 404.
  • Bounded: a path read gets a 10 s git timeout (the default is 30 s), and a path over 4096 characters is refused.
  • Refusals: an empty path, a leading /, a .. segment or a NUL is a 400. Only the NUL case was not tested against my own message: the boundary's existing control-character check answers it first, with its own message.
  • Unknown parameters: any parameter other than ref, path, cursor or limit is a 422 unknown_parameter naming the accepted ones, as the issue and pull lists answer. A client that sends extra parameters to this list, such as a cache-buster, now gets that 422. The Apple app's existing calls should be checked for stray parameters.
  • Cache tag: the ETag now includes the path, so two paths never share a tag.
  • Contract and docs: openapi.json declares path and describes the refusals, and docs/features/commits-path.md documents it.
  • Test: test/commits-path.test.ts makes three commits, two touching a.txt, and checks that ?path=a.txt returns those two with a working cursor. It also covers the empty list, the literal pathspec, the 400s, the 422 and the per-path ETag.

Left out: a terminal-screen change (the commit said No door:) and any CLI or MCP path argument. The MCP commits tool and the terminal commits screen still list without a path filter. The gate printed an advisory that a test helper resembles one in test/spawn-take.test.ts; it did not fail the gate.

Try it: GET /api/v1/repos/OWNER/NAME/commits?path=README.md&limit=1 on the preview.

🤖 Generated with Claude Code

Closes #18002

commented

GET /api/v1/repos/{owner}/{name}/commits now reads an optional path and returns only the commits that touched it. The new tests, tsc, the openapi contract tests and the gate pass. I did not run the full suite, and the forge runs the full check on the push.

  • Filtering: ?path=a.txt keeps the commits that touched that file or directory, newest first, like git log -- <path>. It works with ref, limit and cursor, and limit=1 gives a file's last commit. commitLog already took a path, so nothing new was written for the git side.
  • Literal paths: the path is passed to git as :(literal)…, so * or :(top) in a query string is a plain name, not pathspec magic. A path nothing touched returns an empty list, not a 404.
  • Bounded: a path read gets a 10 s git timeout (the default is 30 s), and a path over 4096 characters is refused.
  • Refusals: an empty path, a leading /, a .. segment or a NUL is a 400. Only the NUL case was not tested against my own message: the boundary's existing control-character check answers it first, with its own message.
  • Unknown parameters: any parameter other than ref, path, cursor or limit is a 422 unknown_parameter naming the accepted ones, as the issue and pull lists answer. A client that sends extra parameters to this list, such as a cache-buster, now gets that 422. The Apple app's existing calls should be checked for stray parameters.
  • Cache tag: the ETag now includes the path, so two paths never share a tag.
  • Contract and docs: openapi.json declares path and describes the refusals, and docs/features/commits-path.md documents it.
  • Test: test/commits-path.test.ts makes three commits, two touching a.txt, and checks that ?path=a.txt returns those two with a working cursor. It also covers the empty list, the literal pathspec, the 400s, the 422 and the per-path ETag.

Left out: a terminal-screen change (the commit said No door:) and any CLI or MCP path argument. The MCP commits tool and the terminal commits screen still list without a path filter. The gate printed an advisory that a test helper resembles one in test/spawn-take.test.ts; it did not fail the gate.

Try it: GET /api/v1/repos/OWNER/NAME/commits?path=README.md&limit=1 on the preview.

🤖 Generated with Claude Code

commented

GET /api/v1/repos/{owner}/{name}/commits?path=… now answers an error when its git read fails. It no longer returns a 200 with an empty list. tsc is clean, and commits-path.test.ts and conforms.test.ts pass (13 tests). I did not run the full suite; the forge's check does that on push.

  • Failed path read (item 1): when the read fails and there is no cursor, it answers 504 path_read_timed_out if git was killed by the 10 s hold. Any other failure, such as an unknown ref, gives 502 path_read_failed. Both carry a message in words. Reads without path behave as before.
  • Documentation: the 502 and 504 are in the openapi entry's alsoStatus, because refuses only accepts 401, 403, 404 and 422. They are also in docs/features/commits-path.md.
  • Test for the failure: ref=no-such-branch&path=a.txt is now a 502 with path_read_failed and a message.
  • Long path and NUL (item 2): a path over 4096 characters is now tested as a 400 invalid_path. I removed the dead NUL branch from commitPathRefusal. A comment says the boundary's control-character check answers NUL first, and the how-to says "control character such as NUL".
  • ref with path (item 3): a new test creates a second branch side one commit back. It checks that path=a.txt&ref=side returns only a.txt a1.

Not covered by a test: the 504 branch. A real timeout can't be triggered cheaply, so only the 502 path is tested. The 504 is chosen from exit code 137 (SIGKILL) or STOPPED, which is inferred from reading runGitRaw rather than observed.

No door: this is an API-only change, so there is no terminal or MCP counterpart.

Gate: gate.ts --fix printed one similarity note: commitFile in test/commits-path.test.ts matches mine in test/spawn-take.test.ts. I left it and pushed.

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs