| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | */ |
| 7 | |
| 8 | import type {MergeConflicts} from '../types'; |
| 9 | |
| 10 | import {Operation} from './Operation'; |
| 11 | |
| 12 | export class AbortMergeOperation extends Operation { |
| 13 | constructor( |
| 14 | private conflicts: MergeConflicts, |
| 15 | private isPartialAbort: boolean, |
| 16 | ) { |
| 17 | super('AbortMergeOperation'); |
| 18 | } |
| 19 | |
| 20 | static opName = 'Abort'; |
| 21 | |
| 22 | // `sl abort` isn't a real command like `sl continue` is. |
| 23 | // however, the merge conflict data we've fetched includes the command to abort |
| 24 | getArgs() { |
| 25 | if (this.isPartialAbort) { |
| 26 | // only rebase supports partial aborts |
| 27 | return ['rebase', '--quit']; |
| 28 | } |
| 29 | if (this.conflicts.toAbort == null) { |
| 30 | // if conflicts are still loading we don't know the right command... |
| 31 | // just try `rebase --abort`... |
| 32 | return ['rebase', '--abort']; |
| 33 | } |
| 34 | return this.conflicts.toAbort.split(' '); |
| 35 | } |
| 36 | |
| 37 | // It's tempting to add makeOptimisticMergeConflictsApplier to `abort`, |
| 38 | // but hiding optimistic conflicts may reveal temporary uncommitted changes |
| 39 | // we could use optimistic uncommitted changes to hide those as well, |
| 40 | // but it gets complicated. More robust is to just show a spinner on the abort button instead. |
| 41 | // Abort should be relatively quick. |
| 42 | // TODO: if this is a slow point in workflows, we could make this experience smoother. |
| 43 | } |
| 44 | |