Skip to content

Commit 61d9aa6

Browse files
authored
Fix hasChangesInDirectorySinceGitTag (#39)
To determine whether a package needs a new release, we ask if there have been any new commits that contain changes to any of the files within that package. In other words, we run a `git diff` on the repo and look for any files that match that package. The problem is that `git diff` returns partial file paths, that is, file paths which are relative to the repository directory, whereas the subdirectory path that `hasChangesInDirectorySinceGitTag` takes is an absolute path. So when we look for matching packages we always come up short. This confuses the tool because it doesn't think there are any new changes to release.
1 parent 577de5e commit 61d9aa6

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/repo.test.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,7 @@ describe('repo', () => {
175175
.calledWith('git', ['diff', 'v1.0.0', 'HEAD', '--name-only'], {
176176
cwd: '/path/to/repo',
177177
})
178-
.mockResolvedValue([
179-
'/path/to/repo/file1',
180-
'/path/to/repo/subdirectory/file1',
181-
]);
178+
.mockResolvedValue(['file1', 'subdirectory/file1']);
182179

183180
const hasChanges = await hasChangesInDirectorySinceGitTag(
184181
'/path/to/repo',
@@ -194,7 +191,7 @@ describe('repo', () => {
194191
.calledWith('git', ['diff', 'v2.0.0', 'HEAD', '--name-only'], {
195192
cwd: '/path/to/repo',
196193
})
197-
.mockResolvedValue(['/path/to/repo/file1', '/path/to/repo/file2']);
194+
.mockResolvedValue(['file1', 'file2']);
198195

199196
const hasChanges = await hasChangesInDirectorySinceGitTag(
200197
'/path/to/repo',

src/repo.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import path from 'path';
12
import {
23
runCommand,
34
getStdoutFromCommand,
@@ -112,11 +113,14 @@ async function getFilesChangedSince(
112113
repositoryDirectoryPath: string,
113114
tagName: string,
114115
): Promise<string[]> {
115-
return await getLinesFromGitCommandWithin(repositoryDirectoryPath, 'diff', [
116-
tagName,
117-
'HEAD',
118-
'--name-only',
119-
]);
116+
const partialFilePaths = await getLinesFromGitCommandWithin(
117+
repositoryDirectoryPath,
118+
'diff',
119+
[tagName, 'HEAD', '--name-only'],
120+
);
121+
return partialFilePaths.map((partialFilePath) =>
122+
path.join(repositoryDirectoryPath, partialFilePath),
123+
);
120124
}
121125

122126
/**

0 commit comments

Comments
 (0)