forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrepo-files.ts
49 lines (41 loc) · 1.57 KB
/
repo-files.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
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {getRepoBaseDir} from './config';
import {exec} from './shelljs';
/**
* A list of all files currently in the repo which have been modified since the provided sha.
*
* git diff
* Deleted files (--diff-filter=d) are not included as they are not longer present in the repo
* and can not be checked anymore.
*
* git ls-files
* Untracked files (--others), which are not matched by .gitignore (--exclude-standard)
* as they are expected to become tracked files.
*/
export function allChangedFilesSince(sha = 'HEAD') {
const diffFiles = gitOutputAsArray(`git diff --name-only --diff-filter=d ${sha}`);
const untrackedFiles = gitOutputAsArray(`git ls-files --others --exclude-standard`);
// Use a set to deduplicate the list as its possible for a file to show up in both lists.
return Array.from(new Set([...diffFiles, ...untrackedFiles]));
}
/**
* A list of all staged files which have been modified.
*
* Only added, created and modified files are listed as others (deleted, renamed, etc) aren't
* changed or available as content to act upon.
*/
export function allStagedFiles() {
return gitOutputAsArray(`git diff --staged --name-only --diff-filter=ACM`);
}
export function allFiles() {
return gitOutputAsArray(`git ls-files`);
}
function gitOutputAsArray(cmd: string) {
return exec(cmd, {cwd: getRepoBaseDir()}).split('\n').map(x => x.trim()).filter(x => !!x);
}