fix(git-gate): forward force push as +refspec to upstream #234

Merged
didericis merged 1 commits from fix/gate-force-push into main 2026-06-10 22:24:38 -04:00
2 changed files with 9 additions and 0 deletions
+2
View File
@@ -300,6 +300,8 @@ while IFS=' ' read -r old new ref; do
[ -z "$ref" ] && continue
if [ "$new" = "$zero" ]; then
refspec=":$ref"
elif [ "$old" != "$zero" ] && ! git merge-base --is-ancestor "$old" "$new" 2>/dev/null; then
refspec="+$new:$ref"
else
refspec="$new:$ref"
fi
+7
View File
@@ -181,6 +181,13 @@ class TestHookRender(unittest.TestCase):
self.assertIn("BatchMode=yes", hook)
self.assertIn("ConnectTimeout=", hook)
def test_force_push_uses_plus_refspec(self):
# A non-fast-forward push (old != zero, new not a descendant of old)
# must forward +$new:$ref so the upstream accepts the force push.
hook = git_gate_render_hook()
self.assertIn('git merge-base --is-ancestor "$old" "$new"', hook)
self.assertIn('refspec="+$new:$ref"', hook)
def test_forward_preserves_push_options(self):
# Git exposes push options to pre-receive hooks as
# GIT_PUSH_OPTION_COUNT + indexed GIT_PUSH_OPTION_N variables.