forked from microsoft/vscode-pull-request-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile.ts
More file actions
62 lines (53 loc) · 1.47 KB
/
Copy pathfile.ts
File metadata and controls
62 lines (53 loc) · 1.47 KB
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
58
59
60
61
62
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { DiffHunk } from './diffHunk';
import { exec } from './git';
export async function getFileContent(rootDir: string, commitSha: string, sourceFilePath: string): Promise<string> {
const result = await exec([
'show',
`${commitSha}:` + sourceFilePath.replace(/\\/g, '/')
], {
cwd: rootDir
});
const out = result.stdout;
const error = result.stderr;
if (result.exitCode === 0) {
if (out.endsWith('\n')) {
return out.substr(0, out.length - 1);
}
return out;
} else {
throw error;
}
}
export enum GitChangeType {
ADD,
COPY,
DELETE,
MODIFY,
RENAME,
TYPE,
UNKNOWN,
UNMERGED
}
export class InMemFileChange {
constructor(
public readonly baseCommit: string,
public readonly status: GitChangeType,
public readonly fileName: string,
public readonly previousFileName: string | undefined,
public readonly patch: string,
public readonly diffHunks: DiffHunk[],
public readonly isPartial: boolean,
public readonly blobUrl: string
) { }
}
export class SlimFileChange {
constructor(
public readonly blobUrl: string,
public readonly status: GitChangeType,
public readonly fileName: string
) { }
}