auto-git:
[change] main.js
This commit is contained in:
82
main.js
82
main.js
@@ -287,42 +287,62 @@ function parseLLMCommitMessages(rawOutput) {
|
|||||||
throw new Error('Could not parse LLM output:\n' + rawOutput);
|
throw new Error('Could not parse LLM output:\n' + rawOutput);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 5. Rewrite-Logik (mit simple-git, wie oben!)
|
|
||||||
async function rewriteCommitMessages(repoPath, message) {
|
|
||||||
const git = simpleGit(repoPath);
|
|
||||||
await git.raw(['commit', '--amend', '-m', message, '--no-edit', '--allow-empty']);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
const { spawn } = require('child_process');
|
||||||
|
|
||||||
/*async function rewriteCommitMessages(repoPath, messageMap, hashesToRewrite) {
|
async function squashCommitMessages(repoPath, commitMessage, hashes) {
|
||||||
const git = simpleGit(repoPath);
|
const git = simpleGit(repoPath);
|
||||||
|
|
||||||
let branchesWithHashes = new Set();
|
// 1. Find the oldest commit in the sequence
|
||||||
for (let hash of hashesToRewrite) {
|
const allCommits = (await git.log()).all;
|
||||||
const branches = await git.branch(['--contains', hash]);
|
const hashIdxs = hashes.map(h => allCommits.findIndex(c => c.hash.startsWith(h)));
|
||||||
Object.keys(branches.branches).forEach(branch => {
|
if (hashIdxs.includes(-1)) throw new Error('Some commit(s) not found.');
|
||||||
branchesWithHashes.add(branch);
|
const oldestIdx = Math.min(...hashIdxs);
|
||||||
|
|
||||||
|
// The commit *before* the oldest in the list is the "upstream" for rebase
|
||||||
|
const rebaseFrom = oldestIdx + 1 < allCommits.length ? allCommits[oldestIdx + 1].hash : '--root';
|
||||||
|
|
||||||
|
// 2. Create rebase-todo: all commits → squash into first
|
||||||
|
// Pick the oldest, squash the rest
|
||||||
|
const toSquash = allCommits.slice(0, oldestIdx + 1).reverse();
|
||||||
|
const first = toSquash[0];
|
||||||
|
const rest = toSquash.slice(1);
|
||||||
|
|
||||||
|
const todoLines = [
|
||||||
|
`pick ${first.hash} ${first.message.split('\n')[0]}`,
|
||||||
|
...rest.map(c => `squash ${c.hash} ${c.message.split('\n')[0]}`)
|
||||||
|
];
|
||||||
|
|
||||||
|
// Write the todo file
|
||||||
|
const tmpdir = require('os').tmpdir();
|
||||||
|
const todoPath = require('path').join(tmpdir, `git-rebase-todo-${Date.now()}.txt`);
|
||||||
|
fs.writeFileSync(todoPath, todoLines.join('\n'));
|
||||||
|
|
||||||
|
// Create a temporary file for the commit message
|
||||||
|
const msgPath = require('path').join(tmpdir, `llm-squash-msg-${Date.now()}.txt`);
|
||||||
|
fs.writeFileSync(msgPath, commitMessage);
|
||||||
|
|
||||||
|
// Use GIT_SEQUENCE_EDITOR to inject the todo file, and GIT_EDITOR to inject the commit message
|
||||||
|
await new Promise((resolve, reject) => {
|
||||||
|
const proc = spawn('git', ['rebase', '-i', rebaseFrom], {
|
||||||
|
cwd: repoPath,
|
||||||
|
env: {
|
||||||
|
...process.env,
|
||||||
|
GIT_SEQUENCE_EDITOR: `cat "${todoPath}" >`,
|
||||||
|
GIT_EDITOR: `cat "${msgPath}" >`
|
||||||
|
},
|
||||||
|
stdio: 'inherit'
|
||||||
});
|
});
|
||||||
}
|
proc.on('exit', code => {
|
||||||
|
try {
|
||||||
for (let branch of branchesWithHashes) {
|
fs.unlinkSync(todoPath);
|
||||||
await git.checkout(branch);
|
fs.unlinkSync(msgPath);
|
||||||
|
} catch {}
|
||||||
const log = await git.log();
|
if (code === 0) resolve();
|
||||||
const commitsInBranch = log.all.map(c => c.hash);
|
else reject(new Error('git rebase failed with exit code ' + code));
|
||||||
const targetHashes = commitsInBranch.filter(hash => hashesToRewrite.includes(hash));
|
});
|
||||||
if (targetHashes.length === 0) continue;
|
});
|
||||||
// Von ältestem zum neuesten
|
}
|
||||||
for (let i = log.all.length - 1; i >= 0; i--) {
|
|
||||||
const c = log.all[i];
|
|
||||||
if (hashesToRewrite.includes(c.hash)) {
|
|
||||||
const newMsg = messageMap[c.hash] || c.message;
|
|
||||||
await git.raw(['commit', '--amend', '-m', newMsg, '--no-edit', '--allow-empty']);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Kein Push!
|
|
||||||
}
|
|
||||||
} */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Komplett-Workflow: Von Kandidaten bis Rewrite
|
* Komplett-Workflow: Von Kandidaten bis Rewrite
|
||||||
|
|||||||
Reference in New Issue
Block a user