From 82795cbd5dba29dfd6043883b5885616d24724a5 Mon Sep 17 00:00:00 2001 From: Alan Jaouen Date: Thu, 10 Oct 2024 19:11:59 +0200 Subject: [PATCH 1/2] fix(packageDiff): useBranchCompare option use branch for compare package descriptor --- src/core/package/diff/PackageDiffImpl.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/core/package/diff/PackageDiffImpl.ts b/src/core/package/diff/PackageDiffImpl.ts index 3764d16c3..43ab3b1b5 100644 --- a/src/core/package/diff/PackageDiffImpl.ts +++ b/src/core/package/diff/PackageDiffImpl.ts @@ -47,6 +47,10 @@ export default class PackageDiffImpl { let tag: string; if (!this.diffOptions?.useLatestGitTags && this.diffOptions?.packagesMappedToLastKnownCommitId != null) { tag = this.getLatestCommitFromMap(this.sfdx_package, this.diffOptions?.packagesMappedToLastKnownCommitId); + } else if (this.diffOptions?.useBranchCompare) { + // if branch compare is enabled, we will use the merge base as tag for the whole diff + tag = await git.raw(['merge-base', this.diffOptions.branch, this.diffOptions.baseBranch]); + tag = tag.trim(); } else { tag = await this.getLatestTagFromGit(git, this.sfdx_package); } @@ -57,15 +61,14 @@ export default class PackageDiffImpl { // Get the list of modified files between the tag and HEAD refs let modified_files: string[]; try { - if(this.diffOptions?.useBranchCompare) - { - const mergeBase = await git.raw(['merge-base', this.diffOptions.branch, this.diffOptions.baseBranch]); - modified_files = await git.diff(['--no-renames','--name-only', this.diffOptions.branch, mergeBase.trim()]); + let targetref: string; + if(this.diffOptions?.useBranchCompare) { + targetref = this.diffOptions.branch; } - else - { - modified_files = await git.diff([`${tag}`, `HEAD`, `--no-renames`, `--name-only`]); + else { + targetref = `HEAD`; } + modified_files = await git.diff([`${tag}`, `${targetref}`, `--no-renames`, `--name-only`]); } catch (error) { if(this.diffOptions?.fallBackToNoTag) { From 34bf2ad1e7e16be2943b3308d319d96a7d91d1c4 Mon Sep 17 00:00:00 2001 From: Alan Jaouen Date: Thu, 10 Oct 2024 19:17:08 +0200 Subject: [PATCH 2/2] chore(packageDiff): remove trailling spaces --- src/core/package/diff/PackageDiffImpl.ts | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/core/package/diff/PackageDiffImpl.ts b/src/core/package/diff/PackageDiffImpl.ts index 43ab3b1b5..d1e8f01ac 100644 --- a/src/core/package/diff/PackageDiffImpl.ts +++ b/src/core/package/diff/PackageDiffImpl.ts @@ -72,7 +72,7 @@ export default class PackageDiffImpl { } catch (error) { if(this.diffOptions?.fallBackToNoTag) { - SFPLogger.log(COLOR_WARNING(dedent(`Unable to compute diff, + SFPLogger.log(COLOR_WARNING(dedent(`Unable to compute diff, The head of the branch is not reachable from the commit id ${tag} for ${this.sfdx_package} Attempting to build the package without diffing against the previous version`)),LoggerLevel.INFO,this.logger); return { isToBeBuilt: true, reason: `Previous version is from an earlier branch` }; @@ -99,12 +99,12 @@ export default class PackageDiffImpl { // Check whether the package has been modified for (let filename of modified_files) { - + let normalizedPkgPath = path.normalize(pkgDescriptor.path); let normalizedFilename = path.normalize(filename); - + let relativePath = path.relative(normalizedPkgPath, normalizedFilename); - + if (!relativePath.startsWith('..')) { SFPLogger.log(`Found change(s) in ${filename}`, LoggerLevel.TRACE, this.logger); return { isToBeBuilt: true, reason: `Found change(s) in package`, tag: tag }; @@ -131,12 +131,12 @@ export default class PackageDiffImpl { // Check whether the package has been modified for (let filename of modified_files) { - + let normalizedPkgPath = path.normalize(pkgDescriptor.path); let normalizedFilename = path.normalize(filename); - + let relativePath = path.relative(normalizedPkgPath, normalizedFilename); - + if (!relativePath.startsWith('..')) { SFPLogger.log(`Found change(s) in ${filename}`, LoggerLevel.TRACE, this.logger); return { isToBeBuilt: true, reason: `Found change(s) in package`, tag: tag };