Refactor commit message handling and add short hash support
This commit is contained in:
24
main.js
24
main.js
@@ -214,9 +214,10 @@ async function getCommitsForLLM(folderPath, hashes) {
|
|||||||
const git = simpleGit(folderPath);
|
const git = simpleGit(folderPath);
|
||||||
const commits = [];
|
const commits = [];
|
||||||
for (const hash of hashes) {
|
for (const hash of hashes) {
|
||||||
|
const shortHash = hash.substring(0, 7);
|
||||||
const diff = await git.diff([`${hash}^!`]);
|
const diff = await git.diff([`${hash}^!`]);
|
||||||
const msg = (await git.show(['-s', '--format=%B', hash])).trim();
|
const msg = (await git.show(['-s', '--format=%B', hash])).trim();
|
||||||
commits.push({ hash, message: msg, diff });
|
commits.push({ hash: shortHash, message: msg, diff });
|
||||||
}
|
}
|
||||||
return commits;
|
return commits;
|
||||||
}
|
}
|
||||||
@@ -329,7 +330,7 @@ function parseLLMCommitMessages(rawOutput) {
|
|||||||
async function rewordCommitsSequentially(repoPath, commitMessageMap, hashes) {
|
async function rewordCommitsSequentially(repoPath, commitMessageMap, hashes) {
|
||||||
const git = simpleGit(repoPath);
|
const git = simpleGit(repoPath);
|
||||||
|
|
||||||
// Sanity: Sort hashes chronologically by git log order (oldest first)
|
// Sort hashes...
|
||||||
const allCommits = (await git.log()).all;
|
const allCommits = (await git.log()).all;
|
||||||
const hashesOrdered = hashes
|
const hashesOrdered = hashes
|
||||||
.map(h => allCommits.find(c => c.hash.startsWith(h)))
|
.map(h => allCommits.find(c => c.hash.startsWith(h)))
|
||||||
@@ -339,15 +340,20 @@ async function rewordCommitsSequentially(repoPath, commitMessageMap, hashes) {
|
|||||||
)
|
)
|
||||||
.map(c => c.hash);
|
.map(c => c.hash);
|
||||||
|
|
||||||
// Loop over all hashes
|
// EIN Loop!
|
||||||
for (const hash of hashesOrdered) {
|
for (const hash of hashesOrdered) {
|
||||||
// Compose the rebase command: only one commit at a time!
|
// --- Lookup: full hash oder short hash
|
||||||
await new Promise((resolve, reject) => {
|
let msg = commitMessageMap[hash];
|
||||||
// macOS: sed -i '' ... Linux: sed -i ...
|
if (!msg) msg = commitMessageMap[hash.substring(0, 7)];
|
||||||
// Try macOS style, change '' to '' or nothing if you get errors.
|
if (!msg) {
|
||||||
const sequenceEditor = `sed -i '' '1s/pick/reword/'`;
|
console.warn('No commit message found for hash', hash, 'or', hash.substring(0, 7));
|
||||||
const commitMsg = commitMessageMap[hash].replace(/(["$`\\])/g, '\\$1'); // Escape quotes etc
|
continue;
|
||||||
|
}
|
||||||
|
const commitMsg = msg.replace(/(["$`\\])/g, '\\$1');
|
||||||
|
const sequenceEditor = `sed -i '' '1s/pick/reword/'`;
|
||||||
|
|
||||||
|
// await auf Promise – aber OHNE zweiten for!
|
||||||
|
await new Promise((resolve, reject) => {
|
||||||
const proc = spawn('git', [
|
const proc = spawn('git', [
|
||||||
'rebase', '-i', `${hash}^`
|
'rebase', '-i', `${hash}^`
|
||||||
], {
|
], {
|
||||||
|
|||||||
Reference in New Issue
Block a user