Skip to content

Commit 4c7f544

Browse files
committed
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
2 parents 5742ba5 + b072a25 commit 4c7f544

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

builtin/receive-pack.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,7 @@ static const char *update(struct command *cmd, struct shallow_info *si)
10251025
const char *ret;
10261026
struct object_id *old_oid = &cmd->old_oid;
10271027
struct object_id *new_oid = &cmd->new_oid;
1028+
int do_update_worktree = 0;
10281029

10291030
/* only refs/... are allowed */
10301031
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)
10501051
refuse_unconfigured_deny();
10511052
return "branch is currently checked out";
10521053
case DENY_UPDATE_INSTEAD:
1053-
ret = update_worktree(new_oid->hash);
1054-
if (ret)
1055-
return ret;
1054+
/* pass -- let other checks intervene first */
1055+
do_update_worktree = 1;
10561056
break;
10571057
}
10581058
}
@@ -1117,6 +1117,12 @@ static const char *update(struct command *cmd, struct shallow_info *si)
11171117
return "hook declined";
11181118
}
11191119

1120+
if (do_update_worktree) {
1121+
ret = update_worktree(new_oid->hash);
1122+
if (ret)
1123+
return ret;
1124+
}
1125+
11201126
if (is_null_oid(new_oid)) {
11211127
struct strbuf err = STRBUF_INIT;
11221128
if (!parse_object(the_repository, old_oid)) {

t/t5516-fetch-push.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1577,7 +1577,13 @@ test_expect_success 'receive.denyCurrentBranch = updateInstead' '
15771577
test $(git -C .. rev-parse master) = $(git rev-parse HEAD) &&
15781578
git diff --quiet &&
15791579
git diff --cached --quiet
1580-
)
1580+
) &&
1581+
1582+
# (6) updateInstead intervened by fast-forward check
1583+
test_must_fail git push void master^:master &&
1584+
test $(git -C void rev-parse HEAD) = $(git rev-parse master) &&
1585+
git -C void diff --quiet &&
1586+
git -C void diff --cached --quiet
15811587
'
15821588

15831589
test_expect_success 'updateInstead with push-to-checkout hook' '

0 commit comments

Comments
 (0)