mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 00:27:24 +00:00
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:
41 files changed
+4384
-796
No files matched your search
@@ -7,7 +7,7 @@ import type { Git } from "../../git";
|
||||
export class GitInitCommand implements GitSubcommand {
|
||||
name = 'init';
|
||||
description = 'Create an empty Git repository or reinitialize an existing one';
|
||||
usage = 'git init [--bare] [<directory>]';
|
||||
usage = 'git init [--bare] [-b | --initial-branch <name>] [<directory>]';
|
||||
|
||||
private git: Git;
|
||||
private fs: JSRuntimeFS;
|
||||
@@ -21,7 +21,9 @@ export class GitInitCommand implements GitSubcommand {
|
||||
try {
|
||||
// Parse arguments
|
||||
const { options, directory } = this.parseArgs(args);
|
||||
const targetDir = directory || cwd;
|
||||
const targetDir = directory
|
||||
? (directory.startsWith('/') ? directory : `${cwd}/${directory}`)
|
||||
: cwd;
|
||||
|
||||
// Check if directory exists, create if needed
|
||||
if (directory) {
|
||||
@@ -45,21 +47,25 @@ export class GitInitCommand implements GitSubcommand {
|
||||
await this.git.init({
|
||||
dir: targetDir,
|
||||
bare: options.bare,
|
||||
defaultBranch: 'main'
|
||||
defaultBranch: options.initialBranch || 'main',
|
||||
});
|
||||
|
||||
// Set up basic configuration
|
||||
await this.git.setConfig({
|
||||
dir: targetDir,
|
||||
path: 'user.name',
|
||||
value: 'shakespeare.diy'
|
||||
});
|
||||
try {
|
||||
await this.git.setConfig({
|
||||
dir: targetDir,
|
||||
path: 'user.name',
|
||||
value: 'shakespeare.diy',
|
||||
});
|
||||
|
||||
await this.git.setConfig({
|
||||
dir: targetDir,
|
||||
path: 'user.email',
|
||||
value: '[email protected]'
|
||||
});
|
||||
await this.git.setConfig({
|
||||
dir: targetDir,
|
||||
path: 'user.email',
|
||||
value: '[email protected]',
|
||||
});
|
||||
} catch {
|
||||
// Non-fatal
|
||||
}
|
||||
|
||||
const message = options.bare
|
||||
? `Initialized empty Git repository in ${targetDir}/\n`
|
||||
@@ -72,13 +78,25 @@ export class GitInitCommand implements GitSubcommand {
|
||||
}
|
||||
}
|
||||
|
||||
private parseArgs(args: string[]): { options: { bare: boolean }; directory?: string } {
|
||||
const options = { bare: false };
|
||||
private parseArgs(args: string[]): {
|
||||
options: { bare: boolean; initialBranch?: string };
|
||||
directory?: string;
|
||||
} {
|
||||
const options: { bare: boolean; initialBranch?: string } = { bare: false };
|
||||
let directory: string | undefined;
|
||||
|
||||
for (const arg of args) {
|
||||
for (let i = 0; i < args.length; i++) {
|
||||
const arg = args[i];
|
||||
|
||||
if (arg === '--bare') {
|
||||
options.bare = true;
|
||||
} else if (arg === '-b' || arg === '--initial-branch') {
|
||||
if (i + 1 < args.length) {
|
||||
options.initialBranch = args[i + 1];
|
||||
i++;
|
||||
}
|
||||
} else if (arg.startsWith('--initial-branch=')) {
|
||||
options.initialBranch = arg.substring(17);
|
||||
} else if (!arg.startsWith('-')) {
|
||||
directory = arg;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user