1.1 KB43 lines
Blame
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
8import type {Dag} from '../previews';
9import type {ExactRevset, OptimisticRevset, SucceedableRevset} from '../types';
10
11import {latestSuccessor} from '../successionUtils';
12import {exactRevset} from '../types';
13import {Operation} from './Operation';
14
15export class RebaseAllDraftCommitsOperation extends Operation {
16 constructor(
17 private timeRangeDays: number | undefined,
18 private destination: SucceedableRevset | ExactRevset | OptimisticRevset,
19 ) {
20 super('RebaseAllDraftCommitsOperation');
21 }
22
23 static opName = 'Rebase all draft commits';
24
25 getArgs() {
26 return [
27 'rebase',
28 '-s',
29 exactRevset(
30 this.timeRangeDays == null ? 'draft()' : `draft() & date(-${this.timeRangeDays})`,
31 ),
32 '-d',
33 this.destination,
34 ];
35 }
36
37 optimisticDag(dag: Dag): Dag {
38 const dest = dag.resolve(latestSuccessor(dag, this.destination))?.hash;
39 const draft = dag.draft();
40 return dag.rebase(draft, dest);
41 }
42}
43