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

+53 -12
View File
@@ -8,7 +8,7 @@ import type { Git } from "../../git";
export class GitCloneCommand implements GitSubcommand {
name = 'clone';
description = 'Clone a repository into a new directory';
usage = 'git clone [--depth <depth>] [--single-branch] <repository> [<directory>]';
usage = 'git clone [--depth <depth>] [--single-branch] [--branch | -b <name>] [--origin | -o <name>] [--bare] <repository> [<directory>]';
private git: Git;
private fs: JSRuntimeFS;
@@ -35,7 +35,7 @@ export class GitCloneCommand implements GitSubcommand {
targetDir = repoName.replace(/\.git$/, ''); // Remove .git suffix if present
}
const targetPath = `${cwd}/${targetDir}`;
const targetPath = targetDir.startsWith('/') ? targetDir : `${cwd}/${targetDir}`;
// Check if target directory already exists
try {
@@ -45,11 +45,13 @@ export class GitCloneCommand implements GitSubcommand {
// Directory doesn't exist, which is what we want
}
// Validate URL format
try {
new URL(repository);
} catch {
return createErrorResult(`fatal: repository '${repository}' does not appear to be a git repository`);
// Validate URL format (accept nostr:// as well)
if (!repository.startsWith('nostr://')) {
try {
new URL(repository);
} catch {
return createErrorResult(`fatal: repository '${repository}' does not appear to be a git repository`);
}
}
// Clone the repository
@@ -58,7 +60,10 @@ export class GitCloneCommand implements GitSubcommand {
url: repository,
singleBranch: options.singleBranch,
depth: options.depth,
});
ref: options.branch,
remote: options.origin,
noCheckout: options.bare,
} as Parameters<typeof this.git.clone>[0]);
return createSuccessResult(`Cloning into '${targetDir}'...\ndone.\n`);
@@ -78,11 +83,27 @@ export class GitCloneCommand implements GitSubcommand {
}
private parseArgs(args: string[]): {
options: { depth?: number; singleBranch: boolean };
options: {
depth?: number;
singleBranch: boolean;
branch?: string;
origin: string;
bare: boolean;
};
repository?: string;
directory?: string
directory?: string;
} {
const options: { depth?: number; singleBranch: boolean } = { singleBranch: false };
const options: {
depth?: number;
singleBranch: boolean;
branch?: string;
origin: string;
bare: boolean;
} = {
singleBranch: false,
origin: 'origin',
bare: false,
};
let repository: string | undefined;
let directory: string | undefined;
@@ -95,7 +116,7 @@ export class GitCloneCommand implements GitSubcommand {
if (!isNaN(depth) && depth > 0) {
options.depth = depth;
}
i++; // Skip next argument
i++;
}
} else if (arg.startsWith('--depth=')) {
const depth = parseInt(arg.substring(8), 10);
@@ -104,6 +125,26 @@ export class GitCloneCommand implements GitSubcommand {
}
} else if (arg === '--single-branch') {
options.singleBranch = true;
} else if (arg === '--no-single-branch') {
options.singleBranch = false;
} else if (arg === '--branch' || arg === '-b') {
if (i + 1 < args.length) {
options.branch = args[i + 1];
options.singleBranch = true;
i++;
}
} else if (arg.startsWith('--branch=')) {
options.branch = arg.substring(9);
options.singleBranch = true;
} else if (arg === '--origin' || arg === '-o') {
if (i + 1 < args.length) {
options.origin = args[i + 1];
i++;
}
} else if (arg.startsWith('--origin=')) {
options.origin = arg.substring(9);
} else if (arg === '--bare' || arg === '--mirror') {
options.bare = true;
} else if (!arg.startsWith('-')) {
if (!repository) {
repository = arg;