Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(packageDiff): useBranchCompare option use branch for compare package descriptor #130

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
31 changes: 17 additions & 14 deletions src/core/package/diff/PackageDiffImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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` };
Expand All @@ -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 };
Expand All @@ -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 };
Expand Down
Loading