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

+19 -15
View File
@@ -73,8 +73,12 @@ describe('GitResetCommand', () => {
isFileReset: boolean;
};
it('should parse no arguments as file reset', () => {
const result = (command as unknown as { parseArgs: (args: string[]) => ParseArgsResult }).parseArgs([]);
const callParseArgs = (args: string[]): Promise<ParseArgsResult> => {
return (command as unknown as { parseArgs: (args: string[], cwd: string) => Promise<ParseArgsResult> }).parseArgs(args, '/test/repo');
};
it('should parse no arguments as file reset', async () => {
const result = await callParseArgs([]);
expect(result).toEqual({
mode: 'mixed',
target: 'HEAD',
@@ -83,8 +87,8 @@ describe('GitResetCommand', () => {
});
});
it('should parse HEAD as file reset', () => {
const result = (command as unknown as { parseArgs: (args: string[]) => ParseArgsResult }).parseArgs(['HEAD']);
it('should parse HEAD as file reset', async () => {
const result = await callParseArgs(['HEAD']);
expect(result).toEqual({
mode: 'mixed',
target: 'HEAD',
@@ -93,8 +97,8 @@ describe('GitResetCommand', () => {
});
});
it('should parse HEAD with files as file reset', () => {
const result = (command as unknown as { parseArgs: (args: string[]) => ParseArgsResult }).parseArgs(['HEAD', 'file1.txt', 'file2.txt']);
it('should parse HEAD with files as file reset', async () => {
const result = await callParseArgs(['HEAD', 'file1.txt', 'file2.txt']);
expect(result).toEqual({
mode: 'mixed',
target: 'HEAD',
@@ -103,8 +107,8 @@ describe('GitResetCommand', () => {
});
});
it('should parse commit hash as commit reset', () => {
const result = (command as unknown as { parseArgs: (args: string[]) => ParseArgsResult }).parseArgs(['abc123def']);
it('should parse commit hash as commit reset', async () => {
const result = await callParseArgs(['abc123def']);
expect(result).toEqual({
mode: 'mixed',
target: 'abc123def',
@@ -113,8 +117,8 @@ describe('GitResetCommand', () => {
});
});
it('should parse mode flags correctly', () => {
const result = (command as unknown as { parseArgs: (args: string[]) => ParseArgsResult }).parseArgs(['--hard', 'HEAD~1']);
it('should parse mode flags correctly', async () => {
const result = await callParseArgs(['--hard', 'HEAD~1']);
expect(result).toEqual({
mode: 'hard',
target: 'HEAD~1',
@@ -123,8 +127,8 @@ describe('GitResetCommand', () => {
});
});
it('should parse mixed mode with commit', () => {
const result = (command as unknown as { parseArgs: (args: string[]) => ParseArgsResult }).parseArgs(['--mixed', 'HEAD~1']);
it('should parse mixed mode with commit', async () => {
const result = await callParseArgs(['--mixed', 'HEAD~1']);
expect(result).toEqual({
mode: 'mixed',
target: 'HEAD~1',
@@ -233,11 +237,11 @@ describe('GitResetCommand', () => {
expect(result.stdout).toContain('HEAD is now at def456a');
});
it('should return error for soft reset (not implemented)', async () => {
it('should handle commit reset with soft mode', async () => {
const result = await command.execute(['--soft', 'HEAD~1'], '/test/repo');
expect(result.exitCode).toBe(1);
expect(result.stderr).toContain('--soft reset is not implemented');
expect(result.exitCode).toBe(0);
expect(result.stdout).toContain('HEAD is now at def456a');
});
it('should handle invalid commit reference', async () => {