Skip to content

Commit

Permalink
fix(core): use file full path in git show
Browse files Browse the repository at this point in the history
Use file full path in git show to identify affected files to fix an issue when nx workspace is not at the root of git repository

Closes #2292
  • Loading branch information
jsaguet committed Feb 23, 2020
1 parent c508241 commit 093a2fc
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/workspace/src/core/file-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,17 @@ function defaultReadFileAtRevision(
revision: void | string
): string {
try {
const fileFullPath = `${appRootPath}${path.sep}${file}`;
const gitRepositoryPath = execSync('git rev-parse --show-toplevel')
.toString()
.trim();
const filePathInGitRepository = path
.relative(gitRepositoryPath, fileFullPath)
.split(path.sep)
.join('/');
return !revision
? readFileSync(file).toString()
: execSync(`git show ${revision}:${file}`, {
: execSync(`git show ${revision}:${filePathInGitRepository}`, {
maxBuffer: TEN_MEGABYTES
})
.toString()
Expand Down

0 comments on commit 093a2fc

Please sign in to comment.