Merge branch 'jc/receive-deny-current-branch-fix'

The receive.denyCurrentBranch=updateInstead codepath kicked in even
when the push should have been rejected due to other reasons, such
as it does not fast-forward or the update-hook rejects it, which
has been corrected.

* jc/receive-deny-current-branch-fix:
  receive: denyCurrentBranch=updateinstead should not blindly update
This commit is contained in:
Junio C Hamano 2018-10-30 15:43:46 +09:00
commit 4c7f544022
2 changed files with 16 additions and 4 deletions

View File

@ -1025,6 +1025,7 @@ static const char *update(struct command *cmd, struct shallow_info *si)
const char *ret; const char *ret;
struct object_id *old_oid = &cmd->old_oid; struct object_id *old_oid = &cmd->old_oid;
struct object_id *new_oid = &cmd->new_oid; struct object_id *new_oid = &cmd->new_oid;
int do_update_worktree = 0;
/* only refs/... are allowed */ /* only refs/... are allowed */
if (!starts_with(name, "refs/") || check_refname_format(name + 5, 0)) { if (!starts_with(name, "refs/") || check_refname_format(name + 5, 0)) {
@ -1050,9 +1051,8 @@ static const char *update(struct command *cmd, struct shallow_info *si)
refuse_unconfigured_deny(); refuse_unconfigured_deny();
return "branch is currently checked out"; return "branch is currently checked out";
case DENY_UPDATE_INSTEAD: case DENY_UPDATE_INSTEAD:
ret = update_worktree(new_oid->hash); /* pass -- let other checks intervene first */
if (ret) do_update_worktree = 1;
return ret;
break; break;
} }
} }
@ -1117,6 +1117,12 @@ static const char *update(struct command *cmd, struct shallow_info *si)
return "hook declined"; return "hook declined";
} }
if (do_update_worktree) {
ret = update_worktree(new_oid->hash);
if (ret)
return ret;
}
if (is_null_oid(new_oid)) { if (is_null_oid(new_oid)) {
struct strbuf err = STRBUF_INIT; struct strbuf err = STRBUF_INIT;
if (!parse_object(the_repository, old_oid)) { if (!parse_object(the_repository, old_oid)) {

View File

@ -1577,7 +1577,13 @@ test_expect_success 'receive.denyCurrentBranch = updateInstead' '
test $(git -C .. rev-parse master) = $(git rev-parse HEAD) && test $(git -C .. rev-parse master) = $(git rev-parse HEAD) &&
git diff --quiet && git diff --quiet &&
git diff --cached --quiet git diff --cached --quiet
) ) &&
# (6) updateInstead intervened by fast-forward check
test_must_fail git push void master^:master &&
test $(git -C void rev-parse HEAD) = $(git rev-parse master) &&
git -C void diff --quiet &&
git -C void diff --cached --quiet
' '
test_expect_success 'updateInstead with push-to-checkout hook' ' test_expect_success 'updateInstead with push-to-checkout hook' '