Skip to content

Commit 20b1af0

Browse files
committed
fix(cli): fix whitelist option when working in a subdirectory of the git directory
1 parent 6677752 commit 20b1af0

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/index.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {join} from "path";
1+
import {isAbsolute, join, relative, sep} from "path";
22

33
import {getModifiedFilenames, resolveNearestGitDirectoryParent} from "./git-utils";
44
import {NO_LINE_CHANGE_DATA_ERROR, generateFilesWhitelistPredicate} from "./utils";
@@ -76,6 +76,10 @@ export function main(
7676
options.base,
7777
options.head
7878
)
79+
.map(path => join(gitDirectoryParent, path))
80+
.map(path => relative(workingDirectory, path))
81+
.filter(path => !isAbsolute(path))
82+
.filter(path => path !== ".." && !path.startsWith(`..${sep}`))
7983
.filter(selectedFormatter.hasSupportedFileExtension)
8084
.filter(generateFilesWhitelistPredicate(options.filesWhitelist))
8185
.filter(selectedFormatter.generateIgnoreFilePredicate(workingDirectory));
@@ -93,7 +97,7 @@ export function main(
9397
* Read the modified file contents and resolve the relevant formatter.
9498
*/
9599
const modifiedFile = new ModifiedFile({
96-
fullPath: join(gitDirectoryParent, filename),
100+
fullPath: join(workingDirectory, filename),
97101
gitDirectoryParent,
98102
base: options.base,
99103
head: options.head,

0 commit comments

Comments
 (0)