addons/isl/src/operations/RebaseAllDraftCommitsOperation.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 {latestSuccessor} from '../successionUtils';
b69ab3112import {exactRevset} from '../types';
b69ab3113import {Operation} from './Operation';
b69ab3114
b69ab3115export class RebaseAllDraftCommitsOperation extends Operation {
b69ab3116 constructor(
b69ab3117 private timeRangeDays: number | undefined,
b69ab3118 private destination: SucceedableRevset | ExactRevset | OptimisticRevset,
b69ab3119 ) {
b69ab3120 super('RebaseAllDraftCommitsOperation');
b69ab3121 }
b69ab3122
b69ab3123 static opName = 'Rebase all draft commits';
b69ab3124
b69ab3125 getArgs() {
b69ab3126 return [
b69ab3127 'rebase',
b69ab3128 '-s',
b69ab3129 exactRevset(
b69ab3130 this.timeRangeDays == null ? 'draft()' : `draft() & date(-${this.timeRangeDays})`,
b69ab3131 ),
b69ab3132 '-d',
b69ab3133 this.destination,
b69ab3134 ];
b69ab3135 }
b69ab3136
b69ab3137 optimisticDag(dag: Dag): Dag {
b69ab3138 const dest = dag.resolve(latestSuccessor(dag, this.destination))?.hash;
b69ab3139 const draft = dag.draft();
b69ab3140 return dag.rebase(draft, dest);
b69ab3141 }
b69ab3142}