feat(git): git.file.text() and git.file.json()#577
Merged
tugrulates merged 3 commits intomainfrom Mar 22, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
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.filewithtext()andjson()methods plusFileOptions { source?: Commitish }. - Implements revision reads via
git show <ref>:<path>and working-tree reads viaDeno.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. |
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>
c1748be to
c00f3f1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
git().fileprovidestext()andjson()methods for reading file contents from the working tree or from a specific revision. When asourceoption is provided (commit, branch, tag, or hash), the file is read viagit show <ref>:<path>. When omitted, the file is read directly from the working tree.Implementation:
FileOperationsandFileOptionsare added to theGitinterface betweenignoreandcommit.text()delegates togit showwhensourceis set, otherwise callsDeno.readTextFile.json()delegates totext()and parses withJSON.parse. Working tree reads letDeno.errors.NotFoundpropagate; revision reads rethrowsGitErrorviarun()asDeno.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.