Skip to content

Commit

Permalink
perf: unshallow only when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-evans committed Nov 30, 2023
1 parent f5ba48a commit c10b207
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
9 changes: 4 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,7 @@ function createOrUpdateBranch(git, commitMessage, base, branch, branchRemoteName
if (branchRemoteName == 'fork') {
// If pushing to a fork we must fetch with 'unshallow' to avoid the following error on git push
// ! [remote rejected] HEAD -> tests/push-branch-to-fork (shallow update not allowed)
yield git.fetch([`${workingBase}:${workingBase}`], baseRemote, [
'--force'
]);
yield git.fetch([`${workingBase}:${workingBase}`], baseRemote, ['--force'], true);
}
else {
// If the remote is 'origin' we can git reset
Expand Down Expand Up @@ -793,14 +791,15 @@ class GitCommandManager {
return output.exitCode === 0;
});
}
fetch(refSpec, remoteName, options) {
fetch(refSpec, remoteName, options, unshallow = false) {
return __awaiter(this, void 0, void 0, function* () {
const args = ['-c', 'protocol.version=2', 'fetch'];
if (!refSpec.some(x => x === tagsRefSpec)) {
args.push('--no-tags');
}
args.push('--progress', '--no-recurse-submodules');
if (utils.fileExistsSync(path.join(this.workingDirectory, '.git', 'shallow'))) {
if (unshallow &&
utils.fileExistsSync(path.join(this.workingDirectory, '.git', 'shallow'))) {
args.push('--unshallow');
}
if (options) {
Expand Down
9 changes: 6 additions & 3 deletions src/create-or-update-branch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,12 @@ export async function createOrUpdateBranch(
if (branchRemoteName == 'fork') {
// If pushing to a fork we must fetch with 'unshallow' to avoid the following error on git push
// ! [remote rejected] HEAD -> tests/push-branch-to-fork (shallow update not allowed)
await git.fetch([`${workingBase}:${workingBase}`], baseRemote, [
'--force'
])
await git.fetch(
[`${workingBase}:${workingBase}`],
baseRemote,
['--force'],
true
)
} else {
// If the remote is 'origin' we can git reset
await git.checkout(workingBase)
Expand Down
5 changes: 4 additions & 1 deletion src/git-command-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,18 @@ export class GitCommandManager {
async fetch(
refSpec: string[],
remoteName?: string,
options?: string[]
options?: string[],
unshallow = false
): Promise<void> {
const args = ['-c', 'protocol.version=2', 'fetch']
if (!refSpec.some(x => x === tagsRefSpec)) {
args.push('--no-tags')
}

args.push('--progress', '--no-recurse-submodules')

if (
unshallow &&
utils.fileExistsSync(path.join(this.workingDirectory, '.git', 'shallow'))
) {
args.push('--unshallow')
Expand Down

0 comments on commit c10b207

Please sign in to comment.