Skip to content

Commit 38baae6

Browse files
anderskgitster
authored andcommitted
receive-pack: clean dead code from update_worktree()
update_worktree() can only be called with a non-NULL worktree parameter, because that’s the only case where we set do_update_worktree = 1. worktree->path is always initialized to non-NULL. Signed-off-by: Anders Kaseorg <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8bc1f39 commit 38baae6

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

builtin/receive-pack.c

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,29 +1449,22 @@ static const char *push_to_checkout(unsigned char *hash,
14491449

14501450
static const char *update_worktree(unsigned char *sha1, const struct worktree *worktree)
14511451
{
1452-
const char *retval, *work_tree, *git_dir = NULL;
1452+
const char *retval, *git_dir;
14531453
struct strvec env = STRVEC_INIT;
14541454

1455-
if (worktree && worktree->path)
1456-
work_tree = worktree->path;
1457-
else if (git_work_tree_cfg)
1458-
work_tree = git_work_tree_cfg;
1459-
else
1460-
work_tree = "..";
1455+
if (!worktree || !worktree->path)
1456+
BUG("worktree->path must be non-NULL");
14611457

14621458
if (is_bare_repository())
14631459
return "denyCurrentBranch = updateInstead needs a worktree";
1464-
if (worktree)
1465-
git_dir = get_worktree_git_dir(worktree);
1466-
if (!git_dir)
1467-
git_dir = get_git_dir();
1460+
git_dir = get_worktree_git_dir(worktree);
14681461

14691462
strvec_pushf(&env, "GIT_DIR=%s", absolute_path(git_dir));
14701463

14711464
if (!hook_exists(push_to_checkout_hook))
1472-
retval = push_to_deploy(sha1, &env, work_tree);
1465+
retval = push_to_deploy(sha1, &env, worktree->path);
14731466
else
1474-
retval = push_to_checkout(sha1, &env, work_tree);
1467+
retval = push_to_checkout(sha1, &env, worktree->path);
14751468

14761469
strvec_clear(&env);
14771470
return retval;
@@ -1592,9 +1585,7 @@ static const char *update(struct command *cmd, struct shallow_info *si)
15921585
}
15931586

15941587
if (do_update_worktree) {
1595-
ret = update_worktree(new_oid->hash,
1596-
find_shared_symref(worktrees, "HEAD",
1597-
name));
1588+
ret = update_worktree(new_oid->hash, worktree);
15981589
if (ret)
15991590
goto out;
16001591
}

0 commit comments

Comments
 (0)