git/list[1] front-page[2] threads[3] people[4] search[5] about
 

RFC: --force-with-lease default behaviour

From
G. Sylvie Davies <sylvie@bit-booster.com>
Date
Jan 5, 2017, 02:34 UTC
Message-ID
<CAAj3zPz-jMVoxNTRZ0iR1ZPTFh873gEo33QjynBE1vaHsMmg3A@mail.gmail.com>
Right now the default variant does this:
> --force-with-lease alone, without specifying the details, will protect all remote refs that are going to be updated by requiring their current value to be the same as the remote-tracking branch we have for them.

The problem is people sometimes run "git fetch". And so "git push --force-with-lease" is going to do the push even if the local version is stale.

Instead I think the default behavior should require that the remote ref's current value be equal to the merge-base of the local-branch and remote-tracking-branch.

Here's an example (password is "test" for the push):

git clone http://test@vm.bit-booster.com/bitbucket/scm/bb/a.git cd a git checkout bugfix/TKT-123 git reset --hard HEAD~1 (to simulate situation where local is stale, but remote is up to date)

At this point "git push --force-with-lease" is going to work. But I think it shouldn't. (Note: I use push.default = simple).

Here's how I think it should work:
git push --force-with-lease=bugfix/TKT-123:$(git merge-base HEAD
origin/bugfix/TKT-123)
To http://vm.bit-booster.com/bitbucket/scm/bb/a.git
 ! [rejected]        bugfix/TKT-123 -> bugfix/TKT-123 (stale info)
For now I'm happy with this alias:

git config --global alias.please '!sh -c "git push --force-with-lease=$(git rev-parse --abbrev-ref HEAD):$(git merge-base HEAD @{u})"'

But I'd like to put together a patch if people are interested in a tweak like this to the --force-with-lease default behaviour. I haven't written much C in my life, but thought this might make a good force-myself-to-learn-C exercise.

- Sylvie Davies

ps. I never thought about the fetch problem with --force-with-lease until reading https://developer.atlassian.com/blog/2015/04/force-with-lease/ and https://buddyreno.me/git-please-a182f28efeb5#.s291gh5jn , so thanks to them!

Next: G. Sylvie Davies
Message 1 of 3 in “RFC: --force-with-lease default behaviour”
  1. G. Sylvie DaviesJan 5, 2017
  2. G. Sylvie DaviesJan 5, 2017
  3. Junio C HamanoJan 7, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.