Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to support push --force-with-lease but not git push --force?

Eric Pederson August 6, 2020

We have the Reject Force Push hook turned on in our Bitbucket server which is a godsend for most situations but it prevents a real need which is rebasing a topic branch that is undergoing code review in a PR.   For example you might want to:

  • Interactively rebase, squashing commits, fixing commit messages, etc.
  • Rebase --onto another branch.

Let's focus on the first use case because that would be possible with --force-with-lease.  (It expects the remote ref to be the same as on the tracking branch, and that wouldn't be the case with rebase --onto).

Can a server-side hook tell if a push is --force-with-lease vs. --force?  If so then it would be an easy modification to the existing hook.  If not then we would need to use an addon like Control Freak which can let you allow push --force for certain branch types but not others.

 

1 answer

1 accepted

0 votes
Answer accepted
Julius Davies _bit-booster_com_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 24, 2020

 

Hi,

I maintain Control Freak so I'm very familiar with this problem.

Unfortunately there is no way to detect "--force-with-lease" on the server side.  The logic behind "--force-with-lease" is based on data only available to the git client.  The server does not have this data and so it cannot tell the difference between regular "--force" and "--force-with-lease".  On the server side those pushes are indistinguishable.

The git server does not track every time every possible git client has run "git pull" or "git fetch"  - that's the data the server would need if it wanted to implement this.

Eric Pederson September 24, 2020

Thanks Sylvie.  That's what I figured but I wanted to verify. 

Johannes Spangenberg May 29, 2024

I looked at the protocol. It seems like the client is always sending the old target (i.e. the lease) even when not using `--force-with-lease`. Git probably just fetches the old target from the server just before it sends it back. So, it seems to be impossible, as you have written. At least, I couldn't see a way in the protocol to push changes without sending the old target.

https://github.com/git/git/blob/3a57aa566a21e7a510c64881bc6bdff7eb397988/Documentation/gitprotocol-pack.txt#L544

I looked it up because I wasn't quite happy with the response, The server wouldn't have to track the clients, it would have to distinguish cases where the client sends the old target (i.e. the lease) from cases where it doesn't.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
6.3.6
TAGS
AUG Leaders

Atlassian Community Events