Skip to content

Commit c55203c

Browse files
authored
fix: drop unnecessary fetch with unshallow on push-to-fork (#2849)
1 parent 6ce4eca commit c55203c

File tree

2 files changed

+6
-26
lines changed

2 files changed

+6
-26
lines changed

dist/index.js

+3-11
Original file line numberDiff line numberDiff line change
@@ -164,20 +164,12 @@ function createOrUpdateBranch(git, commitMessage, base, branch, branchRemoteName
164164
}
165165
// Stash any uncommitted tracked and untracked changes
166166
const stashed = yield git.stashPush(['--include-untracked']);
167-
// Perform fetch and reset the working base
167+
// Reset the working base
168168
// Commits made during the workflow will be removed
169169
if (workingBaseType == WorkingBaseType.Branch) {
170170
core.info(`Resetting working base branch '${workingBase}'`);
171-
if (branchRemoteName == 'fork') {
172-
// If pushing to a fork we must fetch with 'unshallow' to avoid the following error on git push
173-
// ! [remote rejected] HEAD -> tests/push-branch-to-fork (shallow update not allowed)
174-
yield git.fetch([`${workingBase}:${workingBase}`], baseRemote, ['--force'], true);
175-
}
176-
else {
177-
// If the remote is 'origin' we can git reset
178-
yield git.checkout(workingBase);
179-
yield git.exec(['reset', '--hard', `${baseRemote}/${workingBase}`]);
180-
}
171+
yield git.checkout(workingBase);
172+
yield git.exec(['reset', '--hard', `${baseRemote}/${workingBase}`]);
181173
}
182174
// If the working base is not the base, rebase the temp branch commits
183175
// This will also be true if the working base type is a commit

src/create-or-update-branch.ts

+3-15
Original file line numberDiff line numberDiff line change
@@ -173,24 +173,12 @@ export async function createOrUpdateBranch(
173173
// Stash any uncommitted tracked and untracked changes
174174
const stashed = await git.stashPush(['--include-untracked'])
175175

176-
// Perform fetch and reset the working base
176+
// Reset the working base
177177
// Commits made during the workflow will be removed
178178
if (workingBaseType == WorkingBaseType.Branch) {
179179
core.info(`Resetting working base branch '${workingBase}'`)
180-
if (branchRemoteName == 'fork') {
181-
// If pushing to a fork we must fetch with 'unshallow' to avoid the following error on git push
182-
// ! [remote rejected] HEAD -> tests/push-branch-to-fork (shallow update not allowed)
183-
await git.fetch(
184-
[`${workingBase}:${workingBase}`],
185-
baseRemote,
186-
['--force'],
187-
true
188-
)
189-
} else {
190-
// If the remote is 'origin' we can git reset
191-
await git.checkout(workingBase)
192-
await git.exec(['reset', '--hard', `${baseRemote}/${workingBase}`])
193-
}
180+
await git.checkout(workingBase)
181+
await git.exec(['reset', '--hard', `${baseRemote}/${workingBase}`])
194182
}
195183

196184
// If the working base is not the base, rebase the temp branch commits

0 commit comments

Comments
 (0)