Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/renderer/changes-note.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@ function discardOutcome(res) {
return { ok: false, message: `Failed to discard changes: ${res && res.error ? res.error : 'Unknown error'}` };
}

/**
* Apply-related feedback after attempting the destructive exit from a ticket.
* A failure preserves the layer and the error that explains why it remains;
* success clears both because the ticket is back at its base.
*
* @param {{ok?: boolean}} outcome The discard result.
* @param {*} current The apply feedback currently on screen.
* @return {*}
*/
function applyFeedbackAfterDiscard(outcome, current) {
if (!outcome || !outcome.ok) return current;
return { appliedPatch: null, applyError: '', applyConflict: null, applyNotice: '' };
}

/**
* What the note shows in the frame straight after a discard, before any probe
* has walked the checkout again.
Expand Down Expand Up @@ -161,4 +175,4 @@ function discardDisabledReason({ patchLoading, patchLoadFailed, patchHasChanges,
return null;
}

module.exports = { changesNoteParts, discardOutcome, noteAfterDiscard, noteAfterProbe, discardBlocked, discardDisabledReason, DISCARD_CONFIRM_MESSAGE };
module.exports = { changesNoteParts, discardOutcome, applyFeedbackAfterDiscard, noteAfterDiscard, noteAfterProbe, discardBlocked, discardDisabledReason, DISCARD_CONFIRM_MESSAGE };
8 changes: 6 additions & 2 deletions src/renderer/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ import { describeSwitchProgress } from '../switch-progress.cjs';
import { highlightDiff, hasDiffLines } from './diff-highlight.cjs';
import { highlightLog } from './log-highlight.cjs';
import { carryTestMode } from './github-account.cjs';
import { changesNoteParts, discardOutcome, noteAfterDiscard, noteAfterProbe, discardBlocked, discardDisabledReason, DISCARD_CONFIRM_MESSAGE } from './changes-note.cjs';
import { changesNoteParts, discardOutcome, applyFeedbackAfterDiscard, noteAfterDiscard, noteAfterProbe, discardBlocked, discardDisabledReason, DISCARD_CONFIRM_MESSAGE } from './changes-note.cjs';
import { initialConfirmations, confirmationReducer, prConfirmationMessage } from './confirmations.cjs';

const TERMINAL_ALLOWED_SCRIPTS = ['build', 'build:dev', 'dev', 'test', 'watch', 'grunt'];
Expand Down Expand Up @@ -3456,7 +3456,11 @@ function SiteRow({ sitePath, initialized, createdAt, label, onInitialized, onSit
return;
}
applyDiscardToNote(outcome);
setAppliedPatch(null);
const feedback = applyFeedbackAfterDiscard(outcome);
setAppliedPatch(feedback.appliedPatch);
setApplyError(feedback.applyError);
setApplyConflict(feedback.applyConflict);
setApplyNotice(feedback.applyNotice);
writeToTerminal('\nDiscarded local changes.\n');
confirm('All changes discarded.');
if (isPatchOpen) await loadPatchText();
Expand Down
29 changes: 29 additions & 0 deletions test/discard-apply-state.test.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

const test = require('node:test');
const assert = require('node:assert/strict');
const { applyFeedbackAfterDiscard } = require('../src/renderer/changes-note.cjs');

test('a successful discard clears the apply failure it resolved', () => {
assert.deepEqual(applyFeedbackAfterDiscard({ ok: true }, {
appliedPatch: { label: 'PR #13017' },
applyError: 'The patch could not be lifted back out.',
applyConflict: { headline: '1 change needs rework' },
applyNotice: 'Older notice'
}), {
appliedPatch: null,
applyError: '',
applyConflict: null,
applyNotice: ''
});
});

test('a failed discard preserves the failure the contributor still needs', () => {
const current = {
appliedPatch: { label: 'PR #13017' },
applyError: 'The patch could not be lifted back out.',
applyConflict: { headline: '1 change needs rework' },
applyNotice: ''
};
assert.strictEqual(applyFeedbackAfterDiscard({ ok: false }, current), current);
});
Loading