Skip to content

Commit 36fdeec

Browse files
committed
fix: check if editorScript for 1st (native) rebase succeeds, pipe stderr if not
Signed-off-by: Kipras Melnikovas <kipras@kipras.org>
1 parent 5006863 commit 36fdeec

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

git-stacked-rebase.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,11 +1413,17 @@ async function getWantedCommitsWithBranchBoundariesUsingNativeGitRebase({
14131413

14141414
const regularRebaseDirBackupPath: string = pathToRegularRebaseDirInsideDotGit + ".backup-from-1st";
14151415

1416+
const editorScriptSuccessIndicator: string = path.join(regularRebaseDirBackupPath, "success");
1417+
const checkIfSucceeded = (): boolean => fs.existsSync(editorScriptSuccessIndicator);
1418+
14161419
/** BEGIN COPY-PASTA */
14171420

14181421
const editorScript = `\
14191422
#!/usr/bin/env bash
14201423
1424+
# remove beforehand
1425+
rm -rf ${editorScriptSuccessIndicator}
1426+
14211427
printf "yes sir\n\n"
14221428
14231429
pushd "${dotGitDirPath}"
@@ -1430,7 +1436,13 @@ cat ${pathToRegularRebaseTodoFile}
14301436
# cat ${pathToRegularRebaseTodoFile} > ${pathToStackedRebaseTodoFile}.regular
14311437
cp -r ${pathToRegularRebaseDirInsideDotGit} ${regularRebaseDirBackupPath}
14321438
1433-
# abort the rebase before even starting it
1439+
# indicate success (MUST BE THE LAST COMMAND BEFORE EXITING)
1440+
touch ${editorScriptSuccessIndicator}
1441+
1442+
# abort the rebase before even starting it --
1443+
# we get what we want - the git-rebase-todo file,
1444+
# and we exit so that the rebase won't proceed
1445+
# and wil cleanup instead.
14341446
exit 1
14351447
`;
14361448
const editorScriptPath: string = path.join(dotGitDirPath, "editorScript.sh");
@@ -1480,13 +1492,17 @@ exit 1
14801492
// https://git-scm.com/docs/git-rebase#Documentation/git-rebase.txt-sequenceeditor
14811493
GIT_SEQUENCE_EDITOR: editorScriptPath,
14821494
},
1495+
stdio: "pipe",
14831496
});
14841497
} catch (e) {
1485-
// as expected. do nothing.
1486-
// TODO verify that it actually came from our script exiting intentionally
1498+
if (!checkIfSucceeded()) {
1499+
throw e;
1500+
} else {
1501+
// as expected. do nothing & continue.
1502+
}
14871503
}
14881504

1489-
console.log("rebase -i exited");
1505+
console.log("rebase -i exited successfully");
14901506

14911507
/** END COPY-PASTA */
14921508

0 commit comments

Comments
 (0)