Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cli/BaseProjectFilterCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export abstract class BaseProjectFilterCommand<TArgs extends [...unknown[], Proj
// If there is no upper limit, include projects with local changes
!changedIn && !changedTo && p.version.localChanges?.length
// Filter any projects which have any directory changes
|| [p.dir, ...p.dependencies].some(d => directoryChanges.some(c => c.startsWith(d))));
|| [p.dir, ...p.dependencies].some(d => directoryChanges.some(c => c === d || c.startsWith(d + '/'))));
}
return projects;
}
Expand Down
2 changes: 1 addition & 1 deletion src/services/RepositoryService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class RepositoryServiceImpl implements RepositoryService {

const matchingUncommitedChanges = uncommitedChanges
.filter(uc => !!paths.find(p =>
uc.path.startsWith(p) || p.startsWith(uc.path))
uc.path === p || uc.path.startsWith(p === '/' ? '/' : p + '/') || p.startsWith(uc.path))
);

if (matchingUncommitedChanges.length) {
Expand Down
21 changes: 21 additions & 0 deletions test/cli/ListCommand.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe(ListCommand, () => {
const project1Dir = 'project1';
const project2Dir = 'project2';
const dependency1Dir = 'dependency1';
const project1ExtensionsDir = 'project1extensions';

const commits = {
initial: {
Expand Down Expand Up @@ -50,6 +51,13 @@ describe(ListCommand, () => {
timestamp: new Date('2023-01-01'),
ago: '2 years ago',
files: [dependency1Dir],
},
updateExtensions: {
hash: 'Updated project1extensions dir',
hashShort: 'updtextn',
timestamp: new Date('2023-01-02'),
ago: '2 years ago',
files: [`${project1ExtensionsDir}/file.cs`],
}
} satisfies Record<string, MockCommit>;

Expand All @@ -68,6 +76,13 @@ describe(ListCommand, () => {
dependencies: [],
version: commits.newProject,
};
const project1Extensions: ProjectWithVersion = {
...projectExamples.project3,
name: 'Project1Extensions',
dir: project1ExtensionsDir,
dependencies: [],
version: commits.updateExtensions,
};

beforeEach(async () => {
await resetFs();
Expand Down Expand Up @@ -133,6 +148,12 @@ describe(ListCommand, () => {
test('when changed in provided, and no project changes, should not list any proejcts',
() => testHelper.testParse(['--template', '${{name}}', '--changed-in', commits.unrelated.hash], ['No matching projects']));

test('when changed in provided, should not match projects with a directory that is a prefix of the changed directory', async () => {
projectService.addProjects(project1Extensions);
repositoryService.addCommitChanges(commits.updateExtensions);
return testHelper.testParse(['--template', '${{name}}', '--changed-in', commits.updateExtensions.hash], ['Project1Extensions']);
});

test('when changed from provided, should list all project changed since',
() => testHelper.testParse(['--template', '${{name}}', '--changed-from', commits.unrelated.hash], ['Project1']));

Expand Down
15 changes: 15 additions & 0 deletions test/services/RepositoryService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,21 @@ describe(RepositoryServiceImpl, () => {
hashShort: PathStatus.Untracked,
});
});

test('when uncommitted change is in a path with the same prefix but different directory, should use hash', async () => {
// Given
mockSpawnService.addRunOutput(`?? ProjectAExtensions/file.cs`);
mockSpawnService.addRunOutput(`{'hash':'long-hash','hashShort':'short-hash','timestamp':'2024-10-19T00:00:00Z'}`);

// When
const version = await repositoryService.getLatestPathVersion('/ProjectA');

// Verify
expect(version).toMatchObject({
hash: 'long-hash',
hashShort: 'short-hash',
});
});
});

describe(RepositoryServiceImpl.prototype.getChanges, () => {
Expand Down