Update to 0.4.5

This commit is contained in:
NuklearRabbit
2026-07-24 20:50:37 +02:00
parent b4f0be3d77
commit 602309b203
8 changed files with 90 additions and 23 deletions
+30 -11
View File
@@ -73,25 +73,44 @@ class GitService {
return result.stdout;
}
async expandSelectedPaths(root, files) {
selectedStatusFiles(status, files) {
const selected = assertRepositoryRelativePaths(files);
if (!selected.length) return [];
if (!selected.length) return { selected, matches: status.files };
const selectedSet = new Set(selected);
const matches = status.files.filter((file) => selectedSet.has(file.path) || (file.originalPath && selectedSet.has(file.originalPath)));
return { selected, matches };
}
async expandSelectedPaths(root, files, { unstagedOnly = false } = {}) {
const status = await this.status(root);
const expanded = new Set(selected);
for (const file of status.files) {
if (selected.includes(file.path) || (file.originalPath && selected.includes(file.originalPath))) {
expanded.add(file.path);
if (file.originalPath) expanded.add(file.originalPath);
}
const { selected, matches } = this.selectedStatusFiles(status, files);
if (!selected.length) return [];
const expanded = new Set();
for (const file of matches) {
if (unstagedOnly && !file.unstaged) continue;
expanded.add(file.path);
if (file.originalPath) expanded.add(file.originalPath);
}
return [...expanded];
}
async stage(repoPath, files) {
const root = await this.ensureRepository(repoPath);
const selected = await this.expandSelectedPaths(root, files);
// -A is required for deleted files and for the old side of renames.
await run('git', selected.length ? ['add', '-A', '--', ...selected] : ['add', '--all'], { cwd: root, timeout: 60_000 });
const requested = assertRepositoryRelativePaths(files);
if (!requested.length) {
await run('git', ['add', '--all'], { cwd: root, timeout: 60_000 });
return this.status(root);
}
// Only stage records that still have a worktree-side change. Re-running
// `git add -A -- deleted-file` after that deletion is already staged makes
// Git fail with "pathspec did not match any files" because the file no
// longer exists in either the worktree or HEAD. Staged-only deletions and
// renames are already ready for commit and must therefore be left alone.
const selected = await this.expandSelectedPaths(root, requested, { unstagedOnly: true });
if (selected.length) {
await run('git', ['add', '-A', '--', ...selected], { cwd: root, timeout: 60_000 });
}
return this.status(root);
}