Skip to content

Commit

Permalink
rebase-tool: Allow 'continue' and 'finish' to work in exec step
Browse files Browse the repository at this point in the history
If using the --exec argument, the rebase may stop during an exec step if,
for example, the tests failed. When stopped during an exec step, there's
no .git/rebase-merge/stopped-sha file, so the tool cannot pick the rebase
back up nor finish early.

Instead, get the SHA from .git/rebase-merge/done, if the last entry in the
file is an 'edit' step. If the last entry is instead an 'exec' step,
handle that separately.
  • Loading branch information
ptomato committed Jan 13, 2025
1 parent a64021c commit 69c2077
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions tools/rebase-upstream-commits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,19 @@ function editSequenceFile(file: string) {
}

function getConflictHash() {
const REBASE_CONFLICT_HASH_FILE = `${currentExecOpts.repository}/.git/rebase-merge/stopped-sha`;
if (!fs.existsSync(REBASE_CONFLICT_HASH_FILE)) {
// This is easily available from .git/rebase-merge/stopped-sha if there is a
// merge conflict, but we may also be stopped in the middle of an exec step,
// where that file doesn't exist. Instead, get it from the 'done' list.
const REBASE_DONE_FILE = `${currentExecOpts.repository}/.git/rebase-merge/done`;
if (!fs.existsSync(REBASE_DONE_FILE)) {
return undefined;
}
return String(fs.readFileSync(REBASE_CONFLICT_HASH_FILE)).trim();
const doneEntries = String(fs.readFileSync(REBASE_DONE_FILE)).trim().split('\n');
const lastEntry = doneEntries[doneEntries.length - 1];
const [action, sha] = lastEntry.split(' ', 3);
if (action === 'edit') return sha;
if (action === 'exec') return 'exec';
return undefined;
}

function continueRebasing() {
Expand All @@ -230,6 +238,14 @@ function continueRebasing() {
// eslint-disable-next-line no-constant-condition
while (true) {
currentConflict = getConflictHash();
if (currentConflict === 'exec') {
if (shouldRetest()) {
console.error('To continue, first run tests with "trt exec".');
return;
}
gitContinue();
return;
}
if (!currentConflict) {
log('No conflict - done!');
if (!inRebase()) cleanupConfigDir();
Expand Down

0 comments on commit 69c2077

Please sign in to comment.