Add a few more values for receive.denyCurrentBranch

For a long time, this developer thought that Git's insistence that
pushing into the current branch is evil was completely merited.

Just for fun, the original patch tried to show people that Git is right
there, and that it causes more trouble than it does good when Git allows
you to try to update the working tree for fast-forwards, or to detach the
HEAD, depending on some config settings.

Surprisingly, the opposite was shown.

So here is the support for two new options you can give the config
variable receive.denyCurrentBranch:

'updateInstead':
	Try to merge the working tree with the new tip of the branch
	(which can lead to really horrible merge conflicts).

'detachInstead':
	Detach the HEAD, thereby avoiding a disagreement between the
	HEAD and the index (as well as the working tree), possibly
	leaving the local user wondering how on earth her HEAD became
	so detached.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin
2009-02-16 21:52:51 +01:00
parent 2e07d86f48
commit 495281174b
3 changed files with 97 additions and 2 deletions

View File

@@ -782,4 +782,40 @@ test_expect_success 'push --porcelain --dry-run rejected' '
test_cmp .git/foo .git/bar
'
test_expect_success 'receive.denyCurrentBranch = updateInstead' '
git push testrepo master &&
(cd testrepo &&
git reset --hard &&
git config receive.denyCurrentBranch updateInstead
) &&
test_commit third path2 &&
git push testrepo master &&
test $(git rev-parse HEAD) = $(cd testrepo && git rev-parse HEAD) &&
test third = "$(cat testrepo/path2)" &&
(cd testrepo &&
git update-index --refresh &&
git diff-files --quiet &&
git diff-index --cached HEAD --
)
'
test_expect_success 'receive.denyCurrentBranch = detachInstead' '
(cd testrepo &&
git reset --hard &&
git config receive.denyCurrentBranch detachInstead
) &&
OLDHEAD=$(cd testrepo && git rev-parse HEAD) &&
test_commit fourth path2 &&
test fourth = "$(cat path2)" &&
git push testrepo master &&
test $OLDHEAD = $(cd testrepo && git rev-parse HEAD) &&
test fourth != "$(cat testrepo/path2)" &&
(cd testrepo &&
test_must_fail git symbolic-ref HEAD &&
git update-index --refresh &&
git diff-files --quiet &&
git diff-index --cached HEAD --
)
'
test_done