-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
/
hg.ts
57 lines (46 loc) · 1.38 KB
/
hg.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
import * as path from 'path';
import execa = require('execa');
import type {SCMAdapter} from './types';
const env = {...process.env, HGPLAIN: '1'};
const adapter: SCMAdapter = {
findChangedFiles: async (cwd, options) => {
const includePaths = options.includePaths ?? [];
const args = ['status', '-amnu'];
if (options.withAncestor) {
args.push('--rev', 'min((!public() & ::.)+.)^');
} else if (options.changedSince) {
args.push('--rev', `ancestor(., ${options.changedSince})`);
} else if (options.lastCommit === true) {
args.push('--change', '.');
}
args.push(...includePaths);
let result: execa.ExecaReturnValue;
try {
result = await execa('hg', args, {cwd, env});
} catch (e: any) {
// TODO: Should we keep the original `message`?
e.message = e.stderr;
throw e;
}
return result.stdout
.split('\n')
.filter(s => s !== '')
.map(changedPath => path.resolve(cwd, changedPath));
},
getRoot: async cwd => {
try {
const result = await execa('hg', ['root'], {cwd, env});
return result.stdout;
} catch {
return null;
}
},
};
export default adapter;