Skip to content

Commit d306e66

Browse files
fix(diff): some false positives in diff command (#7806)
* fix(diff): error on disabled actions * fix(diff): some false positives in diff command --------- Co-authored-by: Jon Edvald <edvald@gmail.com>
1 parent d069e42 commit d306e66

File tree

4 files changed

+30
-15
lines changed

4 files changed

+30
-15
lines changed

core/src/commands/diff.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ async function actionDiffPreliminary({
420420
node: RenderedNode
421421
resolveAction: boolean
422422
}): Promise<ActionDiffPreliminary> {
423-
const actionA = graphA.getActionByRef({ kind: node.kind, name: node.name })
423+
const actionA = graphA.getActionByRef({ kind: node.kind, name: node.name }, { includeDisabled: true })
424424

425425
log = actionA.createLog(log)
426426
log.debug({ msg: "Comparison (phase 1)" })
@@ -573,7 +573,7 @@ export async function actionDiffFinal(
573573
}
574574
}
575575

576-
const actionA = graphA.getActionByRef({ kind: diff.kind, name: diff.name })
576+
const actionA = graphA.getActionByRef({ kind: diff.kind, name: diff.name }, { includeDisabled: true })
577577
// const actionB = graphB.getActionByRef({ kind: diffB.kind, name: diffB.name })
578578

579579
const status = diff.status
@@ -774,27 +774,29 @@ async function computeFiles({
774774

775775
if (actionA) {
776776
const sourcePath = actionA.sourcePath()
777-
filesA = await gardenA.vcs.getFiles({
777+
const treeVersionWithHashes = await gardenA.vcs.getTreeVersionWithHashes({
778778
log,
779-
path: sourcePath,
779+
projectName: gardenA.projectName,
780+
config: actionA.getConfig(),
780781
// FIXME: We should use the minimal roots, as when resolving the graph
781782
scanRoot: sourcePath,
782783
})
783-
filesA = filesA.map((file) => ({
784+
filesA = treeVersionWithHashes.files.map((file) => ({
784785
...file,
785786
path: relative(sourcePath, file.path),
786787
}))
787788
}
788789

789790
if (actionB) {
790791
const sourcePath = actionB.sourcePath()
791-
filesB = await gardenB.vcs.getFiles({
792+
const treeVersionWithHashes = await gardenB.vcs.getTreeVersionWithHashes({
792793
log,
793-
path: sourcePath,
794+
projectName: gardenB.projectName,
795+
config: actionB.getConfig(),
794796
// FIXME: We should use the minimal roots, as when resolving the graph
795797
scanRoot: sourcePath,
796798
})
797-
filesB = filesB.map((file) => ({
799+
filesB = treeVersionWithHashes.files.map((file) => ({
798800
...file,
799801
path: relative(sourcePath, file.path),
800802
}))

core/src/vcs/vcs.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ export interface TreeVersion {
7070
files: string[]
7171
}
7272

73+
export interface TreeVersionWithHashes {
74+
contentHash: string
75+
files: VcsFile[]
76+
}
77+
7378
export interface TreeVersions {
7479
[moduleName: string]: TreeVersion
7580
}
@@ -208,13 +213,13 @@ export abstract class VcsHandler {
208213
this.cache.clear()
209214
}
210215

211-
async getTreeVersion({
216+
async getTreeVersionWithHashes({
212217
log,
213218
projectName,
214219
config,
215220
force = false,
216221
scanRoot,
217-
}: GetTreeVersionParams): Promise<TreeVersion> {
222+
}: GetTreeVersionParams): Promise<TreeVersionWithHashes> {
218223
const cacheKey = getResourceTreeCacheKey(config)
219224
const description = describeConfig(config)
220225

@@ -231,7 +236,7 @@ export abstract class VcsHandler {
231236
const configPath = getConfigFilePath(config)
232237
const path = getSourcePath(config)
233238

234-
let result: TreeVersion = { contentHash: NEW_RESOURCE_VERSION, files: [] }
239+
let result: TreeVersionWithHashes = { contentHash: NEW_RESOURCE_VERSION, files: [] }
235240

236241
// Make sure we don't concurrently scan the exact same context
237242
await scanLock.acquire(cacheKey.join(":"), async () => {
@@ -296,7 +301,7 @@ export abstract class VcsHandler {
296301
stringsForContentHash = filesToHash.map((f) => f.hash)
297302
}
298303
result.contentHash = hashStrings(stringsForContentHash)
299-
result.files = files.map((f) => f.path)
304+
result.files = files
300305
}
301306

302307
this.cache.set(log, cacheKey, result, pathToCacheContext(path))
@@ -306,6 +311,14 @@ export abstract class VcsHandler {
306311
return result
307312
}
308313

314+
async getTreeVersion(params: GetTreeVersionParams): Promise<TreeVersion> {
315+
const treeVersionWithHashes = await this.getTreeVersionWithHashes(params)
316+
return {
317+
contentHash: treeVersionWithHashes.contentHash,
318+
files: treeVersionWithHashes.files.map((f) => f.path),
319+
}
320+
}
321+
309322
/**
310323
* Write a file and ensure relevant caches are invalidated after writing.
311324
*/

core/test/integ/src/commands/diff.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ describe("DiffCommand", () => {
135135
expect(summary).to.include("Source files changed")
136136
expect(summary).to.include("M Dockerfile")
137137
expect(summary).to.include("+ test.txt")
138-
expect(summary).to.include("8 files unchanged")
138+
expect(summary).to.include("7 files unchanged")
139139

140140
const files = result.actions["build.api"].files
141141
const changedFiles = files.filter((file) => file.status === "modified")

core/test/unit/src/vcs/vcs.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,15 @@ describe("VcsHandler", () => {
215215
const moduleConfig = await gardenA.resolveModule("module-a")
216216
const cacheKey = getResourceTreeCacheKey(moduleConfig)
217217

218-
const cachedResult = { contentHash: "abcdef", files: ["foo"] }
218+
const cachedResult = { contentHash: "abcdef", files: [{ path: "foo", hash: "abcdef" }] }
219219
handlerA["cache"].set(gardenA.log, cacheKey, cachedResult, ["foo", "bar"])
220220

221221
const result = await handlerA.getTreeVersion({
222222
log: gardenA.log,
223223
projectName: gardenA.projectName,
224224
config: moduleConfig,
225225
})
226-
expect(result).to.eql(cachedResult)
226+
expect(result).to.eql({ contentHash: "abcdef", files: ["foo"] })
227227
})
228228

229229
it("should cache the resolved version", async () => {

0 commit comments

Comments
 (0)