summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2018-10-19 04:57:35 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-10-19 06:13:32 (GMT)
commitb072a25fad21b8aecfa29f6ffb813a0a6194a764 (patch)
tree361e7cb31b42f55f584a1b41e8c750580d5b4e19 /builtin
parent268fbcd172cdb306e8a3e7143cc16677c963d6cd (diff)
downloadgit-b072a25fad21b8aecfa29f6ffb813a0a6194a764.zip
git-b072a25fad21b8aecfa29f6ffb813a0a6194a764.tar.gz
git-b072a25fad21b8aecfa29f6ffb813a0a6194a764.tar.bz2
receive: denyCurrentBranch=updateinstead should not blindly update
The handling of receive.denyCurrentBranch=updateInstead was added to a switch statement that handles other values of the variable, but all the other case arms only checked a condition to reject the attempted push, or let later logic in the same function to still intervene, so that a push that does not fast-forward (which is checked after the switch statement in question) is still rejected. But the handling of updateInstead incorrectly took immediate effect, without giving other checks a chance to intervene. Instead of calling update_worktree() that causes the side effect immediately, just note the fact that we will need to call the function later, and first give other checks a chance to reject the request. After the update-hook gets a chance to reject the push (which happens as the last step in a series of checks), call update_worktree() when we earlier detected the need to. Reported-by: Rajesh Madamanchi Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/receive-pack.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 68d36e0..d28a35c 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1037,6 +1037,7 @@ static const char *update(struct command *cmd, struct shallow_info *si)
const char *ret;
struct object_id *old_oid = &cmd->old_oid;
struct object_id *new_oid = &cmd->new_oid;
+ int do_update_worktree = 0;
/* only refs/... are allowed */
if (!starts_with(name, "refs/") || check_refname_format(name + 5, 0)) {
@@ -1062,9 +1063,8 @@ static const char *update(struct command *cmd, struct shallow_info *si)
refuse_unconfigured_deny();
return "branch is currently checked out";
case DENY_UPDATE_INSTEAD:
- ret = update_worktree(new_oid->hash);
- if (ret)
- return ret;
+ /* pass -- let other checks intervene first */
+ do_update_worktree = 1;
break;
}
}
@@ -1129,6 +1129,12 @@ static const char *update(struct command *cmd, struct shallow_info *si)
return "hook declined";
}
+ if (do_update_worktree) {
+ ret = update_worktree(new_oid->hash);
+ if (ret)
+ return ret;
+ }
+
if (is_null_oid(new_oid)) {
struct strbuf err = STRBUF_INIT;
if (!parse_object(old_oid)) {