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 <andersk@mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Anders Kaseorg committed
Dec 1, 2021 at 14:15 UTC
38baae6cfe4ac3af60e127b9e7f9de04c47c4881
1 file changed
+7
-16
builtin/receive-pack.c
+7
-16
@@ -1449,29 +1449,22 @@ static const char *push_to_checkout(unsigned char *hash,
1449
1450
static const char *update_worktree(unsigned char *sha1, const struct worktree *worktree)
1451
{
1452
- const char *retval, *work_tree, *git_dir = NULL;
1452
+ const char *retval, *git_dir;
1453
struct strvec env = STRVEC_INIT;
1454
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");
1457
1458
if (is_bare_repository())
1459
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);
1461
1462
strvec_pushf(&env, "GIT_DIR=%s", absolute_path(git_dir));
1463
1464
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);
1466
else
1474
- retval = push_to_checkout(sha1, &env, work_tree);
1467
+ retval = push_to_checkout(sha1, &env, worktree->path);
1468
1469
strvec_clear(&env);
1470
return retval;
@@ -1592,9 +1585,7 @@ static const char *update(struct command *cmd, struct shallow_info *si)
1585
}
1586
1587
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);
1589
if (ret)
1590
goto out;
1591
}