Audit and overhaul virtual shell's git command

Fix critical bugs, add extensive missing flags, and add 8 new subcommands
to bring the browser-side git command closer to parity with real git.

Critical bug fixes:
- git commit: file-count classification used impossible stageStatus=1
  comparisons, always reporting 0 files changed
- git status --porcelain: untracked files could clobber staged indicators
- git add: directory walker skipped all dotfiles (including .gitignore
  itself), ignoring real git's .gitignore-based filtering
- git pull: untracked files incorrectly blocked pulls
- git reset: target regex rejected valid refs like branch names
- git diff: path filter used substring matching; --cached read working
  directory instead of index; <commit> and <commit>..<commit> forms were
  stubbed/unimplemented; used fake JS hashes instead of git.hashBlob

Implemented git reset --soft (was returning "not implemented").

New flags added across existing subcommands:
- commit: --signoff, --no-verify, -F/--file, --author, -C/--reuse-message,
  multiple -m support
- add: -u/--update, -f/--force, -n/--dry-run, absolute paths inside repo
- log: --stat, -p/--patch, --name-only, --name-status, --author, --grep,
  --since, --until, --no-merges, --reverse, --follow, custom
  --pretty=format:, proper timezone in output
- push: -u/--set-upstream (now wired to config), --tags, --delete,
  --dry-run, refspec (local:remote)
- fetch: --all, --tags, --prune now actually passed through
- branch: -a/--all, -r/--remotes, -m/-M (rename), --show-current, -v
- checkout: -B, -f/--force, commit-hash support (detached HEAD)
- config: --unset, --get-all, --add, --local, proper --list that reads
  the whole config file
- tag: real annotated tags via git.annotatedTag, -m, -f, -n, glob patterns
- clone: -b/--branch, -o/--origin, --bare
- init: -b/--initial-branch
- show: --stat, --name-only, --name-status
- diff: --stat, --name-only, --name-status
- remote: set-url, get-url, rename, show subcommands

New subcommands:
- git rm: remove files from index (and optionally worktree)
- git mv: rename/move files with index updates
- git restore: modern replacement for checkout of files
- git switch: modern replacement for branch checkout
- git merge: wrapper over git.merge (including --abort, --ff-only)
- git revert: create an inverse commit
- git rev-parse: resolve refs, --short, --abbrev-ref, --show-toplevel,
  --git-dir, HEAD~N / HEAD^N
- git ls-files: list tracked/modified/deleted/untracked files

All existing tests updated where behavior intentionally changed; new
subcommands have dedicated test suites. Final suite: 1392 passing.
This commit is contained in:
Alex Gleason committed 2026-04-27 00:42:10 -05:00
1 parent 376a982449
commit b3fddf6cb3
41 files changed
+4384 -796

No files matched your search

+29 -4
View File
@@ -63,7 +63,7 @@ describe('GitDiffCommand', () => {
type ParseArgsResult = {
commits: string[];
paths: string[];
options: { cached: boolean; staged: boolean };
options: { cached: boolean; nameOnly: boolean; nameStatus: boolean; stat: boolean };
};
it('should parse no arguments correctly', () => {
@@ -71,7 +71,7 @@ describe('GitDiffCommand', () => {
expect(result).toEqual({
commits: [],
paths: [],
options: { cached: false, staged: false },
options: { cached: false, nameOnly: false, nameStatus: false, stat: false },
});
});
@@ -80,18 +80,43 @@ describe('GitDiffCommand', () => {
expect(result).toEqual({
commits: [],
paths: [],
options: { cached: true, staged: true },
options: { cached: true, nameOnly: false, nameStatus: false, stat: false },
});
});
it('should parse --staged option as alias for --cached', () => {
const result = (command as unknown as { parseArgs: (args: string[]) => ParseArgsResult }).parseArgs(['--staged']);
expect(result.options.cached).toBe(true);
});
it('should parse --name-only option', () => {
const result = (command as unknown as { parseArgs: (args: string[]) => ParseArgsResult }).parseArgs(['--name-only']);
expect(result.options.nameOnly).toBe(true);
});
it('should parse --name-status option', () => {
const result = (command as unknown as { parseArgs: (args: string[]) => ParseArgsResult }).parseArgs(['--name-status']);
expect(result.options.nameStatus).toBe(true);
});
it('should parse --stat option', () => {
const result = (command as unknown as { parseArgs: (args: string[]) => ParseArgsResult }).parseArgs(['--stat']);
expect(result.options.stat).toBe(true);
});
it('should parse commits and paths', () => {
const result = (command as unknown as { parseArgs: (args: string[]) => ParseArgsResult }).parseArgs(['HEAD~1', 'HEAD', '--', 'file.txt']);
expect(result).toEqual({
commits: ['HEAD~1', 'HEAD'],
paths: ['file.txt'],
options: { cached: false, staged: false },
options: { cached: false, nameOnly: false, nameStatus: false, stat: false },
});
});
it('should parse range syntax commit1..commit2', () => {
const result = (command as unknown as { parseArgs: (args: string[]) => ParseArgsResult }).parseArgs(['HEAD~2..HEAD']);
expect(result.commits).toEqual(['HEAD~2', 'HEAD']);
});
});
describe('execute', () => {