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