diff --git a/node-src/git/findAncestorBuildWithCommit.ts b/node-src/git/findAncestorBuildWithCommit.ts index f557a1aab..8d2757ffc 100644 --- a/node-src/git/findAncestorBuildWithCommit.ts +++ b/node-src/git/findAncestorBuildWithCommit.ts @@ -12,6 +12,7 @@ const AncestorBuildsQuery = gql` number commit uncommittedHash + isLocalBuild } } } @@ -26,6 +27,7 @@ export interface AncestorBuildsQueryResult { number: number; commit: string; uncommittedHash: string; + isLocalBuild: boolean; }[]; }; }; diff --git a/node-src/git/getBaselineBuilds.ts b/node-src/git/getBaselineBuilds.ts index ea4867862..1118d2126 100644 --- a/node-src/git/getBaselineBuilds.ts +++ b/node-src/git/getBaselineBuilds.ts @@ -17,6 +17,7 @@ const BaselineCommitsQuery = gql` commit committedAt uncommittedHash + isLocalBuild changeCount } } @@ -31,6 +32,7 @@ interface BaselineCommitsQueryResult { commit: string; committedAt: number; uncommittedHash: string; + isLocalBuild: boolean; changeCount: number; }[]; }; diff --git a/node-src/git/getChangedFilesWithReplacement.test.ts b/node-src/git/getChangedFilesWithReplacement.test.ts index 9e0ee697d..085dede81 100644 --- a/node-src/git/getChangedFilesWithReplacement.test.ts +++ b/node-src/git/getChangedFilesWithReplacement.test.ts @@ -25,6 +25,7 @@ describe('getChangedFilesWithReplacements', () => { number: 3, commit: 'exists', uncommittedHash: '', + isLocalBuild: false, }) ).toEqual({ changedFiles: ['changed', 'files'], @@ -48,6 +49,7 @@ describe('getChangedFilesWithReplacements', () => { number: 3, commit: 'missing', uncommittedHash: '', + isLocalBuild: false, }) ).toEqual({ changedFiles: ['changed', 'files'], @@ -57,7 +59,7 @@ describe('getChangedFilesWithReplacements', () => { expect(client.runQuery).toHaveBeenCalled(); }); - it('uses a replacement when build has uncommitted changes', async () => { + it('uses a replacement when local build has uncommitted changes', async () => { const replacementBuild = { id: 'replacement', number: 2, @@ -72,6 +74,7 @@ describe('getChangedFilesWithReplacements', () => { number: 3, commit: 'exists', uncommittedHash: 'abcdef', + isLocalBuild: true, }) ).toEqual({ changedFiles: ['changed', 'files'], @@ -81,6 +84,28 @@ describe('getChangedFilesWithReplacements', () => { expect(client.runQuery).toHaveBeenCalled(); }); + it('does not use a replacement when non-local build has uncommitted changes', async () => { + const replacementBuild = { + id: 'replacement', + number: 2, + commit: 'exists', + uncommittedHash: '', + }; + client.runQuery.mockReturnValue({ app: { build: { ancestorBuilds: [replacementBuild] } } }); + + expect( + await getChangedFilesWithReplacement(context, { + id: 'id', + number: 3, + commit: 'exists', + uncommittedHash: 'abcdef', + isLocalBuild: false, + }) + ).toEqual({ + changedFiles: ['changed', 'files'], + }); + }); + it('throws if there is no replacement', async () => { const replacementBuild = { id: 'replacement', @@ -96,6 +121,7 @@ describe('getChangedFilesWithReplacements', () => { number: 3, commit: 'missing', uncommittedHash: '', + isLocalBuild: false, }) ).rejects.toThrow(/fatal: bad object missing/); }); diff --git a/node-src/git/getChangedFilesWithReplacement.ts b/node-src/git/getChangedFilesWithReplacement.ts index 4e6218673..63d257f14 100644 --- a/node-src/git/getChangedFilesWithReplacement.ts +++ b/node-src/git/getChangedFilesWithReplacement.ts @@ -7,6 +7,7 @@ type BuildWithCommitInfo = { number: number; commit: string; uncommittedHash: string; + isLocalBuild: boolean; }; /** @@ -22,7 +23,10 @@ export async function getChangedFilesWithReplacement( build: BuildWithCommitInfo ): Promise<{ changedFiles: string[]; replacementBuild?: BuildWithCommitInfo }> { try { - if (build.uncommittedHash) throw new Error('Build had uncommitted changes'); + if (build.isLocalBuild && build.uncommittedHash) { + throw new Error('Local build had uncommitted changes'); + } + const changedFiles = await getChangedFiles(build.commit); return { changedFiles }; } catch (err) { diff --git a/node-src/tasks/gitInfo.test.ts b/node-src/tasks/gitInfo.test.ts index 6dc922e37..432b72d52 100644 --- a/node-src/tasks/gitInfo.test.ts +++ b/node-src/tasks/gitInfo.test.ts @@ -112,6 +112,7 @@ describe('setGitInfo', () => { number: 1, commit: '987bca', uncommittedHash: '', + isLocalBuild: false, }, }); const ctx = { log, options: { onlyChanged: true }, client } as any;