Skip to content

Commit 80197b5

Browse files
committed
fix: replace force-push with regular push in SDK release task
The SDK push task used `git push --force-with-lease` which fails on repos with branch protection rules that disallow force pushes. Instead, checkout the existing remote dev branch and commit on top of it so a regular push is always a fast-forward.
1 parent 8fcba8b commit 80197b5

1 file changed

Lines changed: 17 additions & 18 deletions

File tree

src/Appwrite/Platform/Tasks/SDKs.php

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -622,29 +622,28 @@ private function pushToGit(array $language, string $target, string $result, stri
622622
$repo->execute('config', 'advice.defaultBranchName', 'false');
623623
$repo->addRemote('origin', $gitUrl);
624624

625-
// Fetch and checkout base branch (or create if new repo)
625+
// Fetch and checkout the target branch (e.g. dev) if it exists on remote,
626+
// otherwise create it from the base branch (e.g. main).
627+
// We build on top of the existing remote branch so a regular push
628+
// works without force-pushing against protected branches.
629+
$hasBranch = false;
626630
try {
627-
$repo->execute('fetch', 'origin', '--quiet', '--no-tags', '--depth', '1', $repoBranch);
631+
$repo->execute('fetch', 'origin', '--quiet', '--no-tags', '--depth', '1', $gitBranch);
632+
$hasBranch = true;
633+
} catch (\Throwable) {
634+
// Branch doesn't exist on remote yet
635+
}
636+
637+
if ($hasBranch) {
638+
$repo->execute('checkout', '-f', $gitBranch);
639+
} else {
640+
// Fetch base branch to create the target branch from it
628641
try {
642+
$repo->execute('fetch', 'origin', '--quiet', '--no-tags', '--depth', '1', $repoBranch);
629643
$repo->execute('checkout', '-f', $repoBranch);
630644
} catch (\Throwable) {
631645
$repo->execute('checkout', '-b', $repoBranch);
632646
}
633-
} catch (\Throwable) {
634-
$repo->execute('checkout', '-b', $repoBranch);
635-
}
636-
637-
try {
638-
$repo->execute('pull', 'origin', $repoBranch, '--quiet', '--no-tags');
639-
} catch (\Throwable) {
640-
}
641-
642-
// Create or checkout dev branch from the base branch
643-
// This ensures dev always starts from the latest base branch,
644-
// avoiding history divergence caused by squash merges.
645-
try {
646-
$repo->execute('checkout', '-B', $gitBranch, $repoBranch);
647-
} catch (\Throwable) {
648647
$repo->execute('checkout', '-b', $gitBranch);
649648
}
650649

@@ -685,7 +684,7 @@ private function pushToGit(array $language, string $target, string $result, stri
685684
return true;
686685
}
687686

688-
$repo->execute('push', '--force-with-lease', '-u', 'origin', $gitBranch, '--quiet');
687+
$repo->execute('push', '-u', 'origin', $gitBranch, '--quiet');
689688
} catch (\Throwable $e) {
690689
Console::warning(" Git push failed: " . $e->getMessage());
691690
return false;

0 commit comments

Comments
 (0)