Skip to content

Commit

Permalink
rebase: add partial abort check box
Browse files Browse the repository at this point in the history
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
  • Loading branch information
zzl0 authored and facebook-github-bot committed Dec 10, 2024
1 parent 4e8b320 commit 409effc
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
7 changes: 6 additions & 1 deletion addons/isl/src/UncommittedChanges.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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));
}}>
<Icon slot="start" icon={isRunningAbort ? 'loading' : 'circle-slash'} />
<T>Abort</T>
Expand Down Expand Up @@ -980,6 +984,7 @@ function MergeConflictButtons({
{Internal.showInlineAutoRunMergeDriversOption === true && (
<AutoResolveSettingCheckbox subtle />
)}
{conflicts?.command === 'rebase' && <PartialAbortSettingCheckbox subtle />}
</Row>
);
}
15 changes: 15 additions & 0 deletions addons/isl/src/mergeConflicts/state.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ export function AutoResolveSettingCheckbox({subtle}: {subtle?: boolean}) {
);
}

export const shouldPartialAbort = localStorageBackedAtom<boolean>('isl.partial-abort', false);

export function PartialAbortSettingCheckbox({subtle}: {subtle?: boolean}) {
const [isPartialAbort, setShouldPartialAbort] = useAtom(shouldPartialAbort);

const label = <T>Keep Rebased Commits on Abort</T>;
return (
<Tooltip title={t('Keep already rebased commits when aborting a rebase operation.')}>
<Checkbox checked={isPartialAbort} onChange={setShouldPartialAbort}>
{subtle ? <Subtle>{label}</Subtle> : label}
</Checkbox>
</Tooltip>
);
}

export const CONFLICT_SIDE_LABELS = {
/* Label used for the local / destination side of a conflict */
local: t('dest - rebasing onto'),
Expand Down
6 changes: 5 additions & 1 deletion addons/isl/src/operations/AbortMergeOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

Expand All @@ -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`...
Expand Down
3 changes: 2 additions & 1 deletion addons/isl/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit 409effc

Please sign in to comment.