Skip to main content

Module pull_rebase

Module pull_rebase 

Source
Expand description

pre-push-pull-rebase — sync a branch with ITS OWN upstream before pushing, and warn (never act) when the default branch has moved ahead.

The hardening in the shell version is the point, and is preserved exactly: an older version ran git pull --rebase origin HEAD, where the remote ref HEAD resolves to the remote’s DEFAULT branch — so every push silently rebased onto main, autostashing uncommitted work. Hence: never touch a dirty tree, rebase only onto the branch’s own upstream, and abort cleanly on conflict rather than leaving a half-rebased state.

Constants§

PUSH_AGAIN
The words a pull-rebase that moved HEAD ends its message with.

Functions§

ahead_count
Left side of git rev-list --left-right --count <a>...<b>: how far the default branch is ahead of us.
behind_count
behind[[:space:]]+N over git status -sb, present or not — UNLIKE divergence, which only answers when ahead is ALSO on the line.
divergence
lists_branch
^[[:space:]*+]+<name>$ over git branch output — the indentation git always prints, plus the markers it puts in column 0.
publishes_branch
Does this push publish current, the branch checked out here? Only then is syncing it this push’s business. A push of tags, or of another branch, leaves the checkout alone: pushing a release tag from the live checkout used to rebase it onto its upstream and refuse with “push again”. No push lines at all (a hand-run hook) keeps the old behaviour.
run