Subject: Re: disallowing push to currently checked-out branch

From: Junio C Hamano <[email-masked]>
Date: Mon, 16 Feb 2009 15:23:00 -0800

Jeff King <[email-masked]> writes:

>   1. How can we improve this situation?

The situation you described is all about "don't allow a push that is NOT
CONTROLLED BY YOU and that can interfere with what you are doing into a
live repository", and you are right, we have operations that deliberately
detach the HEAD and expect nobody mucks with the branch.

But is this something even worth considering about in the same context as
the denyCurrentBranch?  The same thing can happen even if you are not
detaching HEAD.

For example, I sometimes end up with an ugly series on a branch, whose
endpoint is a good looking tree.  And a refactoring I would want to do
would be too cumbersome for the interactive rebase (I could do it, but the
machinery does not help as much as it would for a simpler case).  In such
a case, often I would just say:

	$ git branch -f goal
        $ git reset --hard master
        : repeat from here until "diff HEAD goal" becomes empty
        ... cherry-pick $a_commit_in_goal_branch, or
        ... edit "show $a_commit_in_goal_branch" output and apply, or
        ... edit the files in place.
        ... make a commit, perhaps using -c $a_commit_in_goal_branch
	: repeat up to here

I would not push into this repository to update the branch "goal" while I
am doing this, as it will obviously screw up the whole process.  I think
it is the same thing that you would not push from elsewhere to update the
branch you are in the middle of interactively rebasing.  Mucking with the
same repository from two different places at the same time, when you know
there can be only one version of a work tree that is checked out, is
simply insane.

It's just a common sense thing.  What denyCurrentBranch protects you from
is a push from elsewhere *while* you are not there, and then next day,
getting confused by what such a push did in the receiving repository.  In
that scenario, you are not mucking with the receiving repository from two
places at the same time, but still you can get your repository into a
confusing state, and it is worth protecting new people from.

Obviously you can tell receive-pack to refuse pushing into a non-bare
repository, with a "I know what I am doing" configuration, but I think at
that point the whole "you could break things this way, so let's prevent a
new user from making such mistake" goes into the realm of absurdity.