@@ -44,6 +44,7 @@ const core = __importStar(__nccwpck_require__(2186));
44
44
const uuid_1 = __nccwpck_require__(5840);
45
45
const CHERRYPICK_EMPTY = 'The previous cherry-pick is now empty, possibly due to conflict resolution.';
46
46
const NOTHING_TO_COMMIT = 'nothing to commit, working tree clean';
47
+ const FETCH_DEPTH_MARGIN = 10;
47
48
var WorkingBaseType;
48
49
(function (WorkingBaseType) {
49
50
WorkingBaseType["Branch"] = "branch";
@@ -64,11 +65,12 @@ function getWorkingBaseAndType(git) {
64
65
});
65
66
}
66
67
exports.getWorkingBaseAndType = getWorkingBaseAndType;
67
- function tryFetch(git, remote, branch) {
68
+ function tryFetch(git, remote, branch, depth ) {
68
69
return __awaiter(this, void 0, void 0, function* () {
69
70
try {
70
71
yield git.fetch([`${branch}:refs/remotes/${remote}/${branch}`], remote, [
71
- '--force'
72
+ '--force',
73
+ `--depth=${depth}`
72
74
]);
73
75
return true;
74
76
}
@@ -196,8 +198,13 @@ function createOrUpdateBranch(git, commitMessage, base, branch, branchRemoteName
196
198
// Reset the base
197
199
yield git.fetch([`${base}:${base}`], baseRemote, fetchArgs);
198
200
}
201
+ // Determine the fetch depth for the pull request branch (best effort)
202
+ const tempBranchCommitsAhead = yield commitsAhead(git, base, tempBranch);
203
+ const fetchDepth = tempBranchCommitsAhead > 0
204
+ ? tempBranchCommitsAhead + FETCH_DEPTH_MARGIN
205
+ : FETCH_DEPTH_MARGIN;
199
206
// Try to fetch the pull request branch
200
- if (!(yield tryFetch(git, branchRemoteName, branch))) {
207
+ if (!(yield tryFetch(git, branchRemoteName, branch, fetchDepth ))) {
201
208
// The pull request branch does not exist
202
209
core.info(`Pull request branch '${branch}' does not exist yet.`);
203
210
// Create the pull request branch
@@ -228,7 +235,6 @@ function createOrUpdateBranch(git, commitMessage, base, branch, branchRemoteName
228
235
// temp branch. This catches a case where the base branch has been force pushed to
229
236
// a new commit.
230
237
// For changes on base this reset is equivalent to a rebase of the pull request branch.
231
- const tempBranchCommitsAhead = yield commitsAhead(git, base, tempBranch);
232
238
const branchCommitsAhead = yield commitsAhead(git, base, branch);
233
239
if ((yield git.hasDiff([`${branch}..${tempBranch}`])) ||
234
240
branchCommitsAhead != tempBranchCommitsAhead ||
0 commit comments