feat(git): Git-Brew löschen entfernt die Datei per Commit (F9, #20)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bbf838c5d6
commit
69cfb364ae
7 files changed
+265
-30
No files matched your search
@@ -153,6 +153,15 @@ export const createGitClient = (cfg, { lookup, gitBinary = 'git' } = {})=>{
|
||||
return buf.toString('utf8');
|
||||
};
|
||||
|
||||
const commitTree = async (repo, { parent, tree, author, message, committer })=>repo.str(['commit-tree', tree, ...(parent ? ['-p', parent] : []), '-m', message], {
|
||||
extraEnv : {
|
||||
GIT_AUTHOR_NAME : clean(author.name) || 'Homebrewery',
|
||||
GIT_AUTHOR_EMAIL : clean(author.email) || committer.email,
|
||||
GIT_COMMITTER_NAME : committer.name,
|
||||
GIT_COMMITTER_EMAIL : committer.email
|
||||
}
|
||||
});
|
||||
|
||||
// Baut einen Commit ohne Arbeitskopie. parent === null → Root-Commit.
|
||||
const buildCommit = async (repo, { parent, filePath, content, author, message, committer })=>{
|
||||
const blob = await repo.str(['hash-object', '-w', '--stdin'], { input: content });
|
||||
@@ -160,17 +169,20 @@ export const createGitClient = (cfg, { lookup, gitBinary = 'git' } = {})=>{
|
||||
if(parent) await repo.run(['read-tree', parent], { extraEnv });
|
||||
await repo.run(['update-index', '--add', '--cacheinfo', `100644,${blob},${filePath}`], { extraEnv });
|
||||
const tree = await repo.str(['write-tree'], { extraEnv });
|
||||
const commit = await repo.str(['commit-tree', tree, ...(parent ? ['-p', parent] : []), '-m', message], {
|
||||
extraEnv : {
|
||||
GIT_AUTHOR_NAME : clean(author.name) || 'Homebrewery',
|
||||
GIT_AUTHOR_EMAIL : clean(author.email) || committer.email,
|
||||
GIT_COMMITTER_NAME : committer.name,
|
||||
GIT_COMMITTER_EMAIL : committer.email
|
||||
}
|
||||
});
|
||||
const commit = await commitTree(repo, { parent, tree, author, message, committer });
|
||||
return { commit, blob };
|
||||
};
|
||||
|
||||
// Commit, der die Datei entfernt (ADR 0003 §5, Löschen). parent muss gesetzt sein.
|
||||
const buildDeleteCommit = async (repo, { parent, filePath, author, message, committer })=>{
|
||||
const extraEnv = { GIT_INDEX_FILE: repo.idx };
|
||||
await repo.run(['read-tree', parent], { extraEnv });
|
||||
// Modus 0 entfernt den Eintrag (--force-remove bräuchte eine Arbeitskopie)
|
||||
await repo.run(['update-index', '--index-info'], { extraEnv, input: `0 ${'0'.repeat(40)}\t${filePath}\n` });
|
||||
const tree = await repo.str(['write-tree'], { extraEnv });
|
||||
return commitTree(repo, { parent, tree, author, message, committer });
|
||||
};
|
||||
|
||||
// Push ohne --force. Wirft e.kind === 'rejected' bei Non-Fast-Forward.
|
||||
const push = async (repo, commit, branch)=>{
|
||||
await repo.run(['push', '-q', repo.url, `${commit}:refs/heads/${branch}`]);
|
||||
@@ -197,7 +209,7 @@ export const createGitClient = (cfg, { lookup, gitBinary = 'git' } = {})=>{
|
||||
return out.split('\n').filter((f)=>f.endsWith('.md')).map((f)=>dir ? `${dir}/${f}` : f);
|
||||
};
|
||||
|
||||
return { withRepo, fetchHead, isEmptyRemote, blobAt, readBlob, buildCommit, push, lsRemote, listFiles };
|
||||
return { withRepo, fetchHead, isEmptyRemote, blobAt, readBlob, buildCommit, buildDeleteCommit, push, lsRemote, listFiles };
|
||||
};
|
||||
|
||||
export const randomId = ()=>crypto.randomBytes(8).toString('hex');
|
||||
Reference in new issue
Block a user