From 409effc172e106c7868806f4d9b11576f36888d5 Mon Sep 17 00:00:00 2001 From: Zhaolong Zhu Date: Tue, 10 Dec 2024 14:41:38 -0800 Subject: [PATCH] rebase: add partial abort check box Summary: D58370354 added `sl rebase --quit` to quit the rebase state and keep the already rebased commits. The feature received many positive feedback. And adding it to ISL will enhance its discoverability. > This is so awesome - as someone who carries around massive stacks holding old/wip changes, > I hit mid stack conflicts a lot, and aborting to avoid working through conflicts is always a pain. > Also as someone who uses ISL, +1 on your comment in the shared post in Sapling Developers > on adding this there too This diff expose it to ISL by adding a partial abort check box for rebase operations and pass the `isPartialAbort` value to `AbortMergeOperation`, so it can return the right commands for partially aborting rebase operations. Reviewed By: evangrayk Differential Revision: D62334053 fbshipit-source-id: 58682a623bf9419e3c8b4a101b2e7e03af5cd475 --- addons/isl/src/UncommittedChanges.tsx | 7 ++++++- addons/isl/src/mergeConflicts/state.tsx | 15 +++++++++++++++ addons/isl/src/operations/AbortMergeOperation.ts | 6 +++++- addons/isl/src/types.ts | 3 ++- 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/addons/isl/src/UncommittedChanges.tsx b/addons/isl/src/UncommittedChanges.tsx index 695285cdf3b35..da3e988bbf2b5 100644 --- a/addons/isl/src/UncommittedChanges.tsx +++ b/addons/isl/src/UncommittedChanges.tsx @@ -48,6 +48,8 @@ import {localStorageBackedAtom, readAtom, useAtomGet, writeAtom} from './jotaiUt import { AutoResolveSettingCheckbox, shouldAutoResolveAllBeforeContinue, + shouldPartialAbort, + PartialAbortSettingCheckbox, } from './mergeConflicts/state'; import {AbortMergeOperation} from './operations/AbortMergeOperation'; import {AddRemoveOperation} from './operations/AddRemoveOperation'; @@ -911,7 +913,9 @@ function MergeConflictButtons({ key="abort" disabled={shouldDisableButtons} onClick={() => { - runOperation(new AbortMergeOperation(conflicts)); + const partialAbortAvailable = conflicts?.command === 'rebase'; + const isPartialAbort = partialAbortAvailable && readAtom(shouldPartialAbort); + runOperation(new AbortMergeOperation(conflicts, isPartialAbort)); }}> Abort @@ -980,6 +984,7 @@ function MergeConflictButtons({ {Internal.showInlineAutoRunMergeDriversOption === true && ( )} + {conflicts?.command === 'rebase' && } ); } diff --git a/addons/isl/src/mergeConflicts/state.tsx b/addons/isl/src/mergeConflicts/state.tsx index ceb4c8ade1068..036dd05c0bae5 100644 --- a/addons/isl/src/mergeConflicts/state.tsx +++ b/addons/isl/src/mergeConflicts/state.tsx @@ -38,6 +38,21 @@ export function AutoResolveSettingCheckbox({subtle}: {subtle?: boolean}) { ); } +export const shouldPartialAbort = localStorageBackedAtom('isl.partial-abort', false); + +export function PartialAbortSettingCheckbox({subtle}: {subtle?: boolean}) { + const [isPartialAbort, setShouldPartialAbort] = useAtom(shouldPartialAbort); + + const label = Keep Rebased Commits on Abort; + return ( + + + {subtle ? {label} : label} + + + ); +} + export const CONFLICT_SIDE_LABELS = { /* Label used for the local / destination side of a conflict */ local: t('dest - rebasing onto'), diff --git a/addons/isl/src/operations/AbortMergeOperation.ts b/addons/isl/src/operations/AbortMergeOperation.ts index acce4af4422aa..a0233a68aa002 100644 --- a/addons/isl/src/operations/AbortMergeOperation.ts +++ b/addons/isl/src/operations/AbortMergeOperation.ts @@ -10,7 +10,7 @@ import type {MergeConflicts} from '../types'; import {Operation} from './Operation'; export class AbortMergeOperation extends Operation { - constructor(private conflicts: MergeConflicts) { + constructor(private conflicts: MergeConflicts, private isPartialAbort: boolean) { super('AbortMergeOperation'); } @@ -19,6 +19,10 @@ export class AbortMergeOperation extends Operation { // `sl abort` isn't a real command like `sl continue` is. // however, the merge conflict data we've fetched includes the command to abort getArgs() { + if (this.isPartialAbort) { + // only rebase supports partial aborts + return ['rebase', '--quit']; + } if (this.conflicts.toAbort == null) { // if conflicts are still loading we don't know the right command... // just try `rebase --abort`... diff --git a/addons/isl/src/types.ts b/addons/isl/src/types.ts index 5dc3f5b258eef..3b9ba6fb5ecf8 100644 --- a/addons/isl/src/types.ts +++ b/addons/isl/src/types.ts @@ -791,7 +791,8 @@ export type LocalStorageName = | 'isl.hide-non-blocking-diagnostics' | 'isl.rebase-off-warm-warning-enabled' // These keys are prefixes, with further dynamic keys appended afterwards - | 'isl.edited-commit-messages:'; + | 'isl.edited-commit-messages:' + | 'isl.partial-abort'; export type ClientToServerMessage = | {type: 'heartbeat'; id: string}