Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does `receive.denyCurrentBranch=updateInstead` interact with the Index?

The receive.denyCurrentBranch config option controls what happens if you push to a repo's branch that is checkout.

By default, it rejects it (which is why you usually only push to bare repos, which have no checkout branches).

It can be disabled via ignore or warn.

Another option is updateInstead.

What this does is that if the HEAD and working directory are the same, and the branch being pushed is HEAD, both the working directory and the branch/HEAD are updated at the same time.

If the working directory is different from HEAD, the push is rejected.
This is useful, for pushing to webservers, for example.

My question is, does this option interact with the Index at all?

Is the Index updated? What if HEAD and the working directory match, but not Index?

like image 337
PyRulez Avatar asked Jan 09 '16 17:01

PyRulez


1 Answers

Is the Index updated? What if HEAD and the working directory match, but not Index?

Commit 0855331 (git 2.4.0-rc0, Dec. 2014) states it clearly:

When receive.denyCurrentBranch is set to updateInstead, a push that tries to update the branch that is currently checked out is accepted only when the index and the working tree exactly matches the currently checked out commit, in which case the index and the working tree are updated to match the pushed commit.
Otherwise the push is refused.

Although that same commit introduced the push-to-checkout hook.

This hook can be used to customize this "push-to-deploy" logic.
The hook receives the commit with which the tip of the current branch is going to be updated, and can decide what kind of local changes are acceptable and how to update the index and the working tree to match the updated tip of the current branch.

That gives a bit of flexibility regarding the index.


Commit 1a51b52, git 2.4.0-rc2, Apr 2015 says it again:

Setting receive.denycurrentbranch to updateinstead and pushing into the current branch, when the working tree and the index is truly clean, is supposed to reset the working tree and the index to match the tree of the pushed commit.

like image 99
VonC Avatar answered Oct 29 '22 22:10

VonC