diff --git a/src/renderer/changes-note.cjs b/src/renderer/changes-note.cjs index cc2dbeb..c0179a2 100644 --- a/src/renderer/changes-note.cjs +++ b/src/renderer/changes-note.cjs @@ -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. @@ -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 }; diff --git a/src/renderer/index.jsx b/src/renderer/index.jsx index 71fb6dc..39c5b08 100644 --- a/src/renderer/index.jsx +++ b/src/renderer/index.jsx @@ -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']; @@ -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(); diff --git a/test/discard-apply-state.test.cjs b/test/discard-apply-state.test.cjs new file mode 100644 index 0000000..a347957 --- /dev/null +++ b/test/discard-apply-state.test.cjs @@ -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); +});