addons/isl/src/operations/BookmarkCreateOperation.tsblame
View source
b69ab311/**
b69ab312 * Copyright (c) Meta Platforms, Inc. and affiliates.
b69ab313 *
b69ab314 * This source code is licensed under the MIT license found in the
b69ab315 * LICENSE file in the root directory of this source tree.
b69ab316 */
b69ab317
b69ab318import type {Dag} from '../previews';
b69ab319import type {ExactRevset, OptimisticRevset, SucceedableRevset} from '../types';
b69ab3110
b69ab3111import {Operation} from './Operation';
b69ab3112
b69ab3113export class BookmarkCreateOperation extends Operation {
b69ab3114 /**
b69ab3115 * @param bookmark local bookmark name to create. Should NOT be a remote bookmark or stable location.
b69ab3116 */
b69ab3117 constructor(
b69ab3118 private revset: SucceedableRevset | ExactRevset | OptimisticRevset,
b69ab3119 private bookmark: string,
b69ab3120 ) {
b69ab3121 super('BookmarkCreateOperation');
b69ab3122 }
b69ab3123
b69ab3124 static opName = 'BookmarkCreate';
b69ab3125
b69ab3126 getArgs() {
b69ab3127 return ['bookmark', this.bookmark, '--rev', this.revset];
b69ab3128 }
b69ab3129
b69ab3130 optimisticDag(dag: Dag): Dag {
b69ab3131 const commit = dag.resolve(this.bookmark);
b69ab3132 if (commit) {
b69ab3133 return dag.replaceWith(commit.hash, (_h, c) =>
b69ab3134 c?.merge({
b69ab3135 bookmarks: [...commit.bookmarks, this.bookmark],
b69ab3136 }),
b69ab3137 );
b69ab3138 }
b69ab3139 return dag;
b69ab3140 }
b69ab3141}