@@ -3865,34 +3865,44 @@ async function getChangesOnHead() {
38653865 return parseGitDiffOutput(output);
38663866}
38673867exports.getChangesOnHead = getChangesOnHead;
3868- async function getChangesSinceMergeBase(base, ref , initialFetchDepth) {
3868+ async function getChangesSinceMergeBase(base, head , initialFetchDepth) {
38693869 let baseRef;
3870+ let headRef;
38703871 async function hasMergeBase() {
3871- return (baseRef !== undefined && (await exec_1.default('git', ['merge-base', baseRef, ref], { ignoreReturnCode: true })).code === 0);
3872+ if (baseRef === undefined || headRef === undefined) {
3873+ return false;
3874+ }
3875+ return (await exec_1.default('git', ['merge-base', baseRef, headRef], { ignoreReturnCode: true })).code === 0;
38723876 }
38733877 let noMergeBase = false;
3874- core.startGroup(`Searching for merge-base ${base}...${ref }`);
3878+ core.startGroup(`Searching for merge-base ${base}...${head }`);
38753879 try {
38763880 baseRef = await getFullRef(base);
3881+ headRef = await getFullRef(head);
38773882 if (!(await hasMergeBase())) {
3878- await exec_1.default('git', ['fetch', '--no-tags', `--depth=${initialFetchDepth}`, 'origin', base, ref]);
3879- if (baseRef === undefined) {
3880- baseRef = await getFullRef(base);
3881- if (baseRef === undefined) {
3882- await exec_1.default('git', ['fetch', '--tags', '--depth=1', 'origin', base, ref], {
3883+ await exec_1.default('git', ['fetch', '--no-tags', `--depth=${initialFetchDepth}`, 'origin', base, head]);
3884+ if (baseRef === undefined || headRef === undefined) {
3885+ baseRef = baseRef !== null && baseRef !== void 0 ? baseRef : (await getFullRef(base));
3886+ headRef = headRef !== null && headRef !== void 0 ? headRef : (await getFullRef(head));
3887+ if (baseRef === undefined || headRef === undefined) {
3888+ await exec_1.default('git', ['fetch', '--tags', '--depth=1', 'origin', base, head], {
38833889 ignoreReturnCode: true // returns exit code 1 if tags on remote were updated - we can safely ignore it
38843890 });
3885- baseRef = await getFullRef(base);
3891+ baseRef = baseRef !== null && baseRef !== void 0 ? baseRef : (await getFullRef(base));
3892+ headRef = headRef !== null && headRef !== void 0 ? headRef : (await getFullRef(head));
38863893 if (baseRef === undefined) {
38873894 throw new Error(`Could not determine what is ${base} - fetch works but it's not a branch or tag`);
38883895 }
3896+ if (headRef === undefined) {
3897+ throw new Error(`Could not determine what is ${head} - fetch works but it's not a branch or tag`);
3898+ }
38893899 }
38903900 }
38913901 let depth = initialFetchDepth;
38923902 let lastCommitCount = await getCommitCount();
38933903 while (!(await hasMergeBase())) {
38943904 depth = Math.min(depth * 2, Number.MAX_SAFE_INTEGER);
3895- await exec_1.default('git', ['fetch', `--deepen=${depth}`, 'origin', base, ref ]);
3905+ await exec_1.default('git', ['fetch', `--deepen=${depth}`, 'origin', base, head ]);
38963906 const commitCount = await getCommitCount();
38973907 if (commitCount === lastCommitCount) {
38983908 core.info('No more commits were fetched');
@@ -3910,16 +3920,16 @@ async function getChangesSinceMergeBase(base, ref, initialFetchDepth) {
39103920 finally {
39113921 core.endGroup();
39123922 }
3913- let diffArg = `${baseRef}...${ref}`;
3923+ // Three dots '...' change detection - finds merge-base and compares against it
3924+ let diffArg = `${baseRef}...${headRef}`;
39143925 if (noMergeBase) {
39153926 core.warning('No merge base found - change detection will use direct <commit>..<commit> comparison');
3916- diffArg = `${baseRef}..${ref }`;
3927+ diffArg = `${baseRef}..${headRef }`;
39173928 }
39183929 // Get changes introduced on ref compared to base
39193930 core.startGroup(`Change detection ${diffArg}`);
39203931 let output = '';
39213932 try {
3922- // Three dots '...' change detection - finds merge-base and compares against it
39233933 output = (await exec_1.default('git', ['diff', '--no-renames', '--name-status', '-z', diffArg])).stdout;
39243934 }
39253935 finally {
@@ -4690,6 +4700,7 @@ async function run() {
46904700 process.chdir(workingDirectory);
46914701 }
46924702 const token = core.getInput('token', { required: false });
4703+ const ref = core.getInput('ref', { required: false });
46934704 const base = core.getInput('base', { required: false });
46944705 const filtersInput = core.getInput('filters', { required: true });
46954706 const filtersYaml = isPathInput(filtersInput) ? getConfigFileContent(filtersInput) : filtersInput;
@@ -4700,7 +4711,7 @@ async function run() {
47004711 return;
47014712 }
47024713 const filter = new filter_1.Filter(filtersYaml);
4703- const files = await getChangedFiles(token, base, initialFetchDepth);
4714+ const files = await getChangedFiles(token, base, ref, initialFetchDepth);
47044715 const results = filter.match(files);
47054716 exportResults(results, listFiles);
47064717 }
@@ -4720,7 +4731,7 @@ function getConfigFileContent(configPath) {
47204731 }
47214732 return fs.readFileSync(configPath, { encoding: 'utf8' });
47224733}
4723- async function getChangedFiles(token, base, initialFetchDepth) {
4734+ async function getChangedFiles(token, base, ref, initialFetchDepth) {
47244735 // if base is 'HEAD' only local uncommitted changes will be detected
47254736 // This is the simplest case as we don't need to fetch more commits or evaluate current/before refs
47264737 if (base === git.HEAD) {
@@ -4735,14 +4746,14 @@ async function getChangedFiles(token, base, initialFetchDepth) {
47354746 return await git.getChangesInLastCommit();
47364747 }
47374748 else {
4738- return getChangedFilesFromGit(base, initialFetchDepth);
4749+ return getChangedFilesFromGit(base, ref, initialFetchDepth);
47394750 }
47404751}
4741- async function getChangedFilesFromGit(base, initialFetchDepth) {
4752+ async function getChangedFilesFromGit(base, head, initialFetchDepth) {
47424753 var _a;
47434754 const defaultRef = (_a = github.context.payload.repository) === null || _a === void 0 ? void 0 : _a.default_branch;
47444755 const beforeSha = github.context.eventName === 'push' ? github.context.payload.before : null;
4745- const ref = git.getShortName(github.context.ref) ||
4756+ const ref = git.getShortName(head || github.context.ref) ||
47464757 (core.warning(`'ref' field is missing in event payload - using current branch, tag or commit SHA`),
47474758 await git.getCurrentRef());
47484759 const baseRef = git.getShortName(base) || defaultRef;
0 commit comments