1.0 KB38 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 {CommandArg, RepoRelativePath} from '../types';
9
10import {Operation} from './Operation';
11
12export class CommitBaseOperation extends Operation {
13 constructor(
14 public message: string,
15 protected filesPathsToCommit?: Array<RepoRelativePath>,
16 ) {
17 super(filesPathsToCommit ? 'CommitFileSubsetOperation' : 'CommitOperation');
18 }
19
20 static opName = 'Commit';
21
22 getArgs() {
23 const args: Array<CommandArg> = ['commit', '--addremove', '--message', this.message];
24 if (this.filesPathsToCommit) {
25 args.push(
26 ...this.filesPathsToCommit.map(file =>
27 // tag file arguments specially so the remote repo can convert them to the proper cwd-relative format.
28 ({
29 type: 'repo-relative-file' as const,
30 path: file,
31 }),
32 ),
33 );
34 }
35 return args;
36 }
37}
38