Skip to content

feat(git): git.file.text() and git.file.json()#577

Merged
tugrulates merged 3 commits intomainfrom
feat/git/file
Mar 22, 2026
Merged

feat(git): git.file.text() and git.file.json()#577
tugrulates merged 3 commits intomainfrom
feat/git/file

Conversation

@tugrulates
Copy link
Member

@tugrulates tugrulates commented Mar 22, 2026

Summary: git().file provides text() and json() methods for reading file contents from the working tree or from a specific revision. When a source option is provided (commit, branch, tag, or hash), the file is read via git show <ref>:<path>. When omitted, the file is read directly from the working tree.

Implementation: FileOperations and FileOptions are added to the Git interface between ignore and commit. text() delegates to git show when source is set, otherwise calls Deno.readTextFile. json() delegates to text() and parses with JSON.parse. Working tree reads let Deno.errors.NotFound propagate; revision reads rethrows GitError via run() as Deno.errors.NotFound.

Tests: Covers reading text and JSON from both working tree and committed revisions, verifying that revision reads return the committed content (not the current working tree), missing file error (NotFound) for both working tree and revision, and invalid JSON errors (SyntaxError) for both sources.

Copilot AI review requested due to automatic review settings March 22, 2026 08:54
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds git().file helpers to read file contents either from the working tree or from a specific Git revision, with accompanying tests to validate behavior across both sources.

Changes:

  • Introduces Git.file with text() and json() methods plus FileOptions { source?: Commitish }.
  • Implements revision reads via git show <ref>:<path> and working-tree reads via Deno.readTextFile.
  • Adds tests for reading text/JSON, missing files, and invalid JSON for both working tree and revision sources.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
core/git/git.ts Adds file operations to the Git API and implements text()/json() with optional revision source.
core/git/git.test.ts Adds coverage for the new file operations for both working tree and revision reads.

tugrulates and others added 3 commits March 22, 2026 10:44
Summary**: `git().file` provides `text()` and `json()` methods for
reading file contents from the working tree or from a specific revision.
When a `source` option is provided (commit, branch, tag, or hash), the
file is read via `git show <ref>:<path>`. When omitted, the file is read
directly from the working tree.

**Implementation**: `FileOperations` and `FileOptions` are added to the
`Git` interface between `ignore` and `commit`. `text()` delegates to
`git show` when `source` is set, otherwise calls `Deno.readTextFile`.
`json()` delegates to `text()` and parses with `JSON.parse`. Working
tree reads let `Deno.errors.NotFound` propagate; revision reads throw
`GitError` via `run()`.

**Tests**: Covers reading text and JSON from both working tree and
committed revisions, verifying that revision reads return the committed
content (not the current working tree), missing file errors for both
working tree (`NotFound`) and revision (`GitError`), and invalid JSON
errors (`SyntaxError`) for both sources.

Co-authored-by: Claude <noreply@anthropic.com>
@tugrulates tugrulates merged commit bc0e69a into main Mar 22, 2026
9 checks passed
@tugrulates tugrulates deleted the feat/git/file branch March 22, 2026 11:40
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.

2 participants