@@ -3830,19 +3830,19 @@ async function getChangesInLastCommit() {
3830
3830
return parseGitDiffOutput(output);
3831
3831
}
3832
3832
exports.getChangesInLastCommit = getChangesInLastCommit;
3833
- async function getChanges(ref ) {
3834
- if (!(await hasCommit(ref ))) {
3833
+ async function getChanges(baseRef ) {
3834
+ if (!(await hasCommit(baseRef ))) {
3835
3835
// Fetch single commit
3836
- core.startGroup(`Fetching ${ref } from origin`);
3837
- await exec_1.default('git', ['fetch', '--depth=1', '--no-tags', 'origin', ref ]);
3836
+ core.startGroup(`Fetching ${baseRef } from origin`);
3837
+ await exec_1.default('git', ['fetch', '--depth=1', '--no-tags', 'origin', baseRef ]);
3838
3838
core.endGroup();
3839
3839
}
3840
3840
// Get differences between ref and HEAD
3841
- core.startGroup(`Change detection ${ref }..HEAD`);
3841
+ core.startGroup(`Change detection ${baseRef }..HEAD`);
3842
3842
let output = '';
3843
3843
try {
3844
3844
// Two dots '..' change detection - directly compares two versions
3845
- output = (await exec_1.default('git', ['diff', '--no-renames', '--name-status', '-z', `${ref }..HEAD`])).stdout;
3845
+ output = (await exec_1.default('git', ['diff', '--no-renames', '--name-status', '-z', `${baseRef }..HEAD`])).stdout;
3846
3846
}
3847
3847
finally {
3848
3848
fixStdOutNullTermination();
@@ -3865,47 +3865,51 @@ async function getChangesOnHead() {
3865
3865
return parseGitDiffOutput(output);
3866
3866
}
3867
3867
exports.getChangesOnHead = getChangesOnHead;
3868
- async function getChangesSinceMergeBase(ref, initialFetchDepth) {
3869
- if (!(await hasCommit(ref))) {
3870
- // Fetch and add base branch
3871
- core.startGroup(`Fetching ${ref}`);
3872
- try {
3873
- await exec_1.default('git', ['fetch', `--depth=${initialFetchDepth}`, '--no-tags', 'origin', `${ref}:${ref}`]);
3874
- }
3875
- finally {
3876
- core.endGroup();
3877
- }
3878
- }
3868
+ async function getChangesSinceMergeBase(baseRef, ref, initialFetchDepth) {
3879
3869
async function hasMergeBase() {
3880
- return (await exec_1.default('git', ['merge-base', ref, 'HEAD'], { ignoreReturnCode: true })).code === 0;
3881
- }
3882
- async function countCommits() {
3883
- return (await getNumberOfCommits('HEAD')) + (await getNumberOfCommits(ref));
3884
- }
3885
- core.startGroup(`Searching for merge-base with ${ref}`);
3886
- // Fetch more commits until merge-base is found
3887
- if (!(await hasMergeBase())) {
3888
- let deepen = initialFetchDepth;
3889
- let lastCommitsCount = await countCommits();
3890
- do {
3891
- await exec_1.default('git', ['fetch', `--deepen=${deepen}`, '--no-tags']);
3892
- const count = await countCommits();
3893
- if (count <= lastCommitsCount) {
3894
- core.info('No merge base found - all files will be listed as added');
3895
- core.endGroup();
3896
- return await listAllFilesAsAdded();
3870
+ return (await exec_1.default('git', ['merge-base', baseRef, ref], { ignoreReturnCode: true })).code === 0;
3871
+ }
3872
+ let noMergeBase = false;
3873
+ core.startGroup(`Searching for merge-base ${baseRef}...${ref}`);
3874
+ try {
3875
+ let init = true;
3876
+ let lastCommitCount = await getCommitCount();
3877
+ let depth = Math.max(lastCommitCount * 2, initialFetchDepth);
3878
+ while (!(await hasMergeBase())) {
3879
+ if (init) {
3880
+ await exec_1.default('git', ['fetch', `--depth=${depth}`, 'origin', `${baseRef}:${baseRef}`, `${ref}`]);
3881
+ init = false;
3882
+ }
3883
+ else {
3884
+ await exec_1.default('git', ['fetch', `--deepen=${depth}`, 'origin', baseRef, ref]);
3897
3885
}
3898
- lastCommitsCount = count;
3899
- deepen = Math.min(deepen * 2, Number.MAX_SAFE_INTEGER);
3900
- } while (!(await hasMergeBase()));
3886
+ const commitCount = await getCommitCount();
3887
+ if (commitCount === lastCommitCount) {
3888
+ core.info('No more commits were fetched');
3889
+ core.info('Last attempt will be to fetch full history');
3890
+ await exec_1.default('git', ['fetch', '--unshallow']);
3891
+ if (!(await hasMergeBase())) {
3892
+ noMergeBase = true;
3893
+ }
3894
+ break;
3895
+ }
3896
+ depth = Math.min(depth * 2, Number.MAX_SAFE_INTEGER);
3897
+ lastCommitCount = commitCount;
3898
+ }
3899
+ }
3900
+ finally {
3901
+ core.endGroup();
3902
+ }
3903
+ if (noMergeBase) {
3904
+ core.warning('No merge base found - all files will be listed as added');
3905
+ return await listAllFilesAsAdded();
3901
3906
}
3902
- core.endGroup();
3903
3907
// Get changes introduced on HEAD compared to ref
3904
- core.startGroup(`Change detection ${ref }...HEAD `);
3908
+ core.startGroup(`Change detection ${baseRef }...${ref} `);
3905
3909
let output = '';
3906
3910
try {
3907
3911
// Three dots '...' change detection - finds merge-base and compares against it
3908
- output = (await exec_1.default('git', ['diff', '--no-renames', '--name-status', '-z', `${ref }...HEAD `])).stdout;
3912
+ output = (await exec_1.default('git', ['diff', '--no-renames', '--name-status', '-z', `${baseRef }...${ref} `])).stdout;
3909
3913
}
3910
3914
finally {
3911
3915
fixStdOutNullTermination();
@@ -3956,7 +3960,7 @@ async function getCurrentRef() {
3956
3960
if (describe.code === 0) {
3957
3961
return describe.stdout.trim();
3958
3962
}
3959
- return (await exec_1.default('git', ['rev-parse', ' HEAD' ])).stdout.trim();
3963
+ return (await exec_1.default('git', ['rev-parse', exports. HEAD])).stdout.trim();
3960
3964
}
3961
3965
finally {
3962
3966
core.endGroup();
@@ -3988,8 +3992,8 @@ async function hasCommit(ref) {
3988
3992
core.endGroup();
3989
3993
}
3990
3994
}
3991
- async function getNumberOfCommits(ref ) {
3992
- const output = (await exec_1.default('git', ['rev-list', ` --count`, ref ])).stdout;
3995
+ async function getCommitCount( ) {
3996
+ const output = (await exec_1.default('git', ['rev-list', ' --count', '--all' ])).stdout;
3993
3997
const count = parseInt(output);
3994
3998
return isNaN(count) ? 0 : count;
3995
3999
}
@@ -4676,7 +4680,7 @@ async function run() {
4676
4680
}
4677
4681
}
4678
4682
function isPathInput(text) {
4679
- return !text.includes('\n');
4683
+ return !( text.includes('\n') || text.includes(':') );
4680
4684
}
4681
4685
function getConfigFileContent(configPath) {
4682
4686
if (!fs.existsSync(configPath)) {
@@ -4709,18 +4713,18 @@ async function getChangedFilesFromGit(base, initialFetchDepth) {
4709
4713
var _a;
4710
4714
const defaultRef = (_a = github.context.payload.repository) === null || _a === void 0 ? void 0 : _a.default_branch;
4711
4715
const beforeSha = github.context.eventName === 'push' ? github.context.payload.before : null;
4712
- const pushRef = git.getShortName(github.context.ref) ||
4716
+ const ref = git.getShortName(github.context.ref) ||
4713
4717
(core.warning(`'ref' field is missing in event payload - using current branch, tag or commit SHA`),
4714
4718
await git.getCurrentRef());
4715
4719
const baseRef = git.getShortName(base) || defaultRef;
4716
4720
if (!baseRef) {
4717
4721
throw new Error("This action requires 'base' input to be configured or 'repository.default_branch' to be set in the event payload");
4718
4722
}
4719
4723
const isBaseRefSha = git.isGitSha(baseRef);
4720
- const isBaseSameAsPush = baseRef === pushRef ;
4724
+ const isBaseRefSameAsRef = baseRef === ref ;
4721
4725
// If base is commit SHA we will do comparison against the referenced commit
4722
4726
// Or if base references same branch it was pushed to, we will do comparison against the previously pushed commit
4723
- if (isBaseRefSha || isBaseSameAsPush ) {
4727
+ if (isBaseRefSha || isBaseRefSameAsRef ) {
4724
4728
if (!isBaseRefSha && !beforeSha) {
4725
4729
core.warning(`'before' field is missing in event payload - changes will be detected from last commit`);
4726
4730
return await git.getChangesInLastCommit();
@@ -4731,7 +4735,7 @@ async function getChangedFilesFromGit(base, initialFetchDepth) {
4731
4735
if (baseSha === git.NULL_SHA) {
4732
4736
if (defaultRef && baseRef !== defaultRef) {
4733
4737
core.info(`First push of a branch detected - changes will be detected against the default branch ${defaultRef}`);
4734
- return await git.getChangesSinceMergeBase(defaultRef, initialFetchDepth);
4738
+ return await git.getChangesSinceMergeBase(defaultRef, ref, initialFetchDepth);
4735
4739
}
4736
4740
else {
4737
4741
core.info('Initial push detected - all files will be listed as added');
@@ -4743,7 +4747,7 @@ async function getChangedFilesFromGit(base, initialFetchDepth) {
4743
4747
}
4744
4748
// Changes introduced by current branch against the base branch
4745
4749
core.info(`Changes will be detected against the branch ${baseRef}`);
4746
- return await git.getChangesSinceMergeBase(baseRef, initialFetchDepth);
4750
+ return await git.getChangesSinceMergeBase(baseRef, ref, initialFetchDepth);
4747
4751
}
4748
4752
// Uses github REST api to get list of files changed in PR
4749
4753
async function getChangedFilesFromApi(token, pullRequest) {
0 commit comments