diff --git a/src/core/package/diff/PackageDiffImpl.ts b/src/core/package/diff/PackageDiffImpl.ts index 3764d16c3..d1e8f01ac 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,19 +61,18 @@ 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) { - 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` }; @@ -96,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 }; @@ -128,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 };