git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* RFC: --force-with-lease default behaviour
@ 2017-01-05  2:34 G. Sylvie Davies
  2017-01-05  6:52 ` G. Sylvie Davies
  0 siblings, 1 reply; 3+ messages in thread
From: G. Sylvie Davies @ 2017-01-05  2:34 UTC (permalink / raw
  To: git

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!

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: RFC: --force-with-lease default behaviour
  2017-01-05  2:34 RFC: --force-with-lease default behaviour G. Sylvie Davies
@ 2017-01-05  6:52 ` G. Sylvie Davies
  2017-01-07 21:04   ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: G. Sylvie Davies @ 2017-01-05  6:52 UTC (permalink / raw
  To: git

On Wed, Jan 4, 2017 at 6:34 PM, G. Sylvie Davies <sylvie@bit-booster.com> wrote:
> 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})"'
>

Nevermind!   I realize this essentially removes the "--force" and
turns it into the original non-forced "fast-forwardable" only style
push.   [BLUSH!]

I wonder if there's anything one could do to help those who type "git
fetch" and still want to enjoy "--force-with-lease"...


> 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!

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: RFC: --force-with-lease default behaviour
  2017-01-05  6:52 ` G. Sylvie Davies
@ 2017-01-07 21:04   ` Junio C Hamano
  0 siblings, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2017-01-07 21:04 UTC (permalink / raw
  To: G. Sylvie Davies; +Cc: git

"G. Sylvie Davies" <sylvie@bit-booster.com> writes:

> I wonder if there's anything one could do to help those who type "git
> fetch" and still want to enjoy "--force-with-lease"...

The entire idea behind "force-with-lease" is that you plan to later
force update the tip of a branch at the remote to replace the commit
that used to be at the tip at some point, that you do not want other
people to have their own work on that branch that will be lost by
your later force-pushing, yet you cannot "lock" a branch at the
remote repository remotely because that goes against the distributed
nature of the development.  Instead of locking others out, forcing
others to wait and sit idle while you complete the material to be
force-pushed (which may never happen), you base your work on one
state of the remote branch, and make sure the remote branch hasn't
advanced in the meantime (or you redo your work)---the cost of the
extra work due to your planned force-pushing is beared by you, not
by others.

There however is no place in Git where you explicitly declare "this
is where I start working on producing a new commit.  That commit
will replace this state and will not fast-forward from it." and
store it locally.  The "--force-with-lease" was designed to take
that information from the command line, expecting that the script
that drives it does something like

	#!/bin/sh
	LEASE=$(git rev-parse --verify @{u})
	# do whatever that requires non-fast-forward push
	git commit --amend ...
	... maybe more ...
	# finally push it out
	git push --force-with-lease $LEASE ...

Lazy people decided that as long as they promise to themselves that
they are not going to do anything to cause @{u} to move, they can
use it as a lazy-man's approximate.  Perhaps that was a misguided
attempt to add convenience.

A possible answer to your wordering may be to deprecate the
defaulting to @{u} and always require the expected commit to be
specified explicitly.



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-01-07 21:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-01-05  2:34 RFC: --force-with-lease default behaviour G. Sylvie Davies
2017-01-05  6:52 ` G. Sylvie Davies
2017-01-07 21:04   ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).