| 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 {Dag} from '../previews'; |
| 9 | |
| 10 | import {Operation} from './Operation'; |
| 11 | |
| 12 | export class BookmarkDeleteOperation extends Operation { |
| 13 | /** |
| 14 | * @param bookmark local bookmark name to delete. Should NOT be a remote bookmark or stable location. |
| 15 | */ |
| 16 | constructor(private bookmark: string) { |
| 17 | super('BookmarkDeleteOperation'); |
| 18 | } |
| 19 | |
| 20 | static opName = 'BookmarkDelete'; |
| 21 | |
| 22 | getArgs() { |
| 23 | return ['bookmark', '--delete', this.bookmark]; |
| 24 | } |
| 25 | |
| 26 | optimisticDag(dag: Dag): Dag { |
| 27 | const commit = dag.resolve(this.bookmark); |
| 28 | if (commit) { |
| 29 | return dag.replaceWith(commit.hash, (_h, c) => |
| 30 | c?.merge({ |
| 31 | bookmarks: commit.bookmarks.filter(b => b !== this.bookmark), |
| 32 | }), |
| 33 | ); |
| 34 | } |
| 35 | return dag; |
| 36 | } |
| 37 | } |
| 38 | |