Skip to content
Merged
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
17 changes: 13 additions & 4 deletions packages/adt-flow/src/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,15 +299,24 @@ export function validateDesiredFiles(files: readonly DesiredFile[]): void {
}
}

export async function verifyOwnedHashes(
export async function findDivergedOwnedPath(
root: string,
files: readonly { path: string; hash: string }[],
): Promise<boolean> {
): Promise<string | undefined> {
for (const file of files) {
const content = await readText(root, file.path);
if (content === undefined || sha256(content) !== file.hash) return false;
if (content === undefined || sha256(content) !== file.hash) {
return file.path;
}
}
return true;
return undefined;
}

export async function verifyOwnedHashes(
root: string,
files: readonly { path: string; hash: string }[],
): Promise<boolean> {
return (await findDivergedOwnedPath(root, files)) === undefined;
}

export async function planRepositoryChanges(
Expand Down
6 changes: 4 additions & 2 deletions packages/adt-flow/src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import { repositoryType } from './adt-client-adapter';
import {
applyRepositoryPlan,
findDivergedOwnedPath,
planRepositoryChanges,
readText,
verifyOwnedHashes,
Expand Down Expand Up @@ -1204,11 +1205,12 @@ async function validateIndexedOwnership(
identity,
ctx.dependencies.format,
);
if (!(await verifyOwnedHashes(ctx.root, descriptor.ownedFiles))) {
const path = await findDivergedOwnedPath(ctx.root, descriptor.ownedFiles);
if (path !== undefined) {
throw new AdtFlowError(
'working_tree_diverged',
'An indexed file differs from its recorded content hash.',
{ object: identity.canonical },
{ object: identity.canonical, path },
);
}
}
Expand Down
8 changes: 7 additions & 1 deletion packages/adt-flow/tests/service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,13 @@ describe('transport checkout', () => {

await expect(
flow.checkout({ root: workspace, transports: ['DEVK900001'], config }),
).rejects.toMatchObject({ code: 'working_tree_diverged' });
).rejects.toMatchObject({
code: 'working_tree_diverged',
details: {
object: expect.any(String),
path: 'src/feature/zcl_sample.clas.abap',
},
});
expect(ports.readSource).not.toHaveBeenCalled();
expect(
await readFile(
Expand Down
Loading