mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
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.
83 lines
2.9 KiB
TypeScript
83 lines
2.9 KiB
TypeScript
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
import { GitLsFilesCommand } from './ls-files';
|
|
import type { Git } from '../../git';
|
|
import type { JSRuntimeFS } from '../../JSRuntime';
|
|
|
|
const mockFS = {
|
|
stat: async (path: string) => {
|
|
if (path.endsWith('/.git')) {
|
|
return { isDirectory: () => true };
|
|
}
|
|
throw new Error('File not found');
|
|
},
|
|
} as unknown as JSRuntimeFS;
|
|
|
|
describe('GitLsFilesCommand', () => {
|
|
let lsFilesCommand: GitLsFilesCommand;
|
|
let mockGit: Git;
|
|
|
|
beforeEach(() => {
|
|
mockGit = {
|
|
statusMatrix: vi.fn().mockResolvedValue([
|
|
// [filepath, headStatus, workdirStatus, stageStatus]
|
|
['file1.txt', 1, 1, 1], // Tracked, unchanged
|
|
['file2.txt', 1, 1, 1], // Tracked, unchanged
|
|
]),
|
|
resolveRef: vi.fn().mockResolvedValue('abc123'),
|
|
readBlob: vi.fn().mockResolvedValue({ oid: 'blob1', blob: new Uint8Array() }),
|
|
} as unknown as Git;
|
|
|
|
lsFilesCommand = new GitLsFilesCommand({ git: mockGit, fs: mockFS });
|
|
});
|
|
|
|
it('should list tracked files', async () => {
|
|
const result = await lsFilesCommand.execute([], '/test-repo');
|
|
expect(result.exitCode).toBe(0);
|
|
expect(result.stdout).toContain('file1.txt');
|
|
expect(result.stdout).toContain('file2.txt');
|
|
});
|
|
|
|
it('should list modified files with -m', async () => {
|
|
mockGit.statusMatrix = vi.fn().mockResolvedValue([
|
|
['file1.txt', 1, 2, 1], // Modified
|
|
['file2.txt', 1, 1, 1], // Unchanged
|
|
]);
|
|
const result = await lsFilesCommand.execute(['-m'], '/test-repo');
|
|
expect(result.exitCode).toBe(0);
|
|
expect(result.stdout).toContain('file1.txt');
|
|
expect(result.stdout).not.toContain('file2.txt');
|
|
});
|
|
|
|
it('should list untracked files with -o', async () => {
|
|
mockGit.statusMatrix = vi.fn().mockResolvedValue([
|
|
['file1.txt', 1, 1, 1], // Tracked
|
|
['untracked.txt', 0, 2, 0], // Untracked
|
|
]);
|
|
const result = await lsFilesCommand.execute(['-o'], '/test-repo');
|
|
expect(result.exitCode).toBe(0);
|
|
expect(result.stdout).toContain('untracked.txt');
|
|
expect(result.stdout).not.toContain('file1.txt');
|
|
});
|
|
|
|
it('should list deleted files with -d', async () => {
|
|
mockGit.statusMatrix = vi.fn().mockResolvedValue([
|
|
['deleted.txt', 1, 0, 1], // Deleted
|
|
['file.txt', 1, 1, 1], // Unchanged
|
|
]);
|
|
const result = await lsFilesCommand.execute(['-d'], '/test-repo');
|
|
expect(result.exitCode).toBe(0);
|
|
expect(result.stdout).toContain('deleted.txt');
|
|
expect(result.stdout).not.toContain('file.txt');
|
|
});
|
|
|
|
it('should fail when not in a git repo', async () => {
|
|
const mockFSNoGit = {
|
|
stat: async () => { throw new Error('ENOENT'); },
|
|
} as unknown as JSRuntimeFS;
|
|
const cmd = new GitLsFilesCommand({ git: mockGit, fs: mockFSNoGit });
|
|
const result = await cmd.execute([], '/not-a-repo');
|
|
expect(result.exitCode).toBe(1);
|
|
expect(result.stderr).toContain('not a git repository');
|
|
});
|
|
});
|