Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnders Kaseorg <andersk@mit.edu>2021-12-02 01:15:46 +0300
committerJunio C Hamano <gitster@pobox.com>2021-12-02 09:18:25 +0300
commit9fdf4f1db422cc259e4a3ce0023a255102c6fa3b (patch)
treea041ac1de8d1661dbedee3df94834dd453db9781 /builtin/receive-pack.c
parent38baae6cfe4ac3af60e127b9e7f9de04c47c4881 (diff)
receive-pack: protect current branch for bare repository worktree
A bare repository won’t have a working tree at "..", but it may still have separate working trees created with git worktree. We should protect the current branch of such working trees from being updated or deleted, according to receive.denyCurrentBranch. Signed-off-by: Anders Kaseorg <andersk@mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/receive-pack.c')
-rw-r--r--builtin/receive-pack.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index 29dc0e56f7..26ecaa5cd5 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1455,7 +1455,7 @@ static const char *update_worktree(unsigned char *sha1, const struct worktree *w
if (!worktree || !worktree->path)
BUG("worktree->path must be non-NULL");
- if (is_bare_repository())
+ if (worktree->is_bare)
return "denyCurrentBranch = updateInstead needs a worktree";
git_dir = get_worktree_git_dir(worktree);
@@ -1481,9 +1481,7 @@ static const char *update(struct command *cmd, struct shallow_info *si)
int do_update_worktree = 0;
struct worktree **worktrees = get_worktrees();
const struct worktree *worktree =
- is_bare_repository() ?
- NULL :
- find_shared_symref(worktrees, "HEAD", name);
+ find_shared_symref(worktrees, "HEAD", name);
/* only refs/... are allowed */
if (!starts_with(name, "refs/") || check_refname_format(name + 5, 0)) {
@@ -1496,7 +1494,7 @@ static const char *update(struct command *cmd, struct shallow_info *si)
free(namespaced_name);
namespaced_name = strbuf_detach(&namespaced_name_buf, NULL);
- if (worktree) {
+ if (worktree && !worktree->is_bare) {
switch (deny_current_branch) {
case DENY_IGNORE:
break;