MCPcopy Create free account
hub / github.com/git/git / update

Function update

builtin/receive-pack.c:1497–1675  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1495}
1496
1497static const char *update(struct command *cmd, struct shallow_info *si)
1498{
1499 const char *name = cmd->ref_name;
1500 struct strbuf namespaced_name_buf = STRBUF_INIT;
1501 static char *namespaced_name;
1502 const char *ret;
1503 struct object_id *old_oid = &cmd->old_oid;
1504 struct object_id *new_oid = &cmd->new_oid;
1505 int do_update_worktree = 0;
1506 struct worktree **worktrees = get_worktrees();
1507 const struct worktree *worktree =
1508 find_shared_symref(worktrees, "HEAD", name);
1509
1510 /* only refs/... are allowed */
1511 if (!starts_with(name, "refs/") ||
1512 check_refname_format(name + 5, is_null_oid(new_oid) ?
1513 REFNAME_ALLOW_ONELEVEL : 0)) {
1514 rp_error("refusing to update funny ref '%s' remotely", name);
1515 ret = "funny refname";
1516 goto out;
1517 }
1518
1519 strbuf_addf(&namespaced_name_buf, "%s%s", get_git_namespace(), name);
1520 free(namespaced_name);
1521 namespaced_name = strbuf_detach(&namespaced_name_buf, NULL);
1522
1523 if (worktree && !worktree->is_bare) {
1524 switch (deny_current_branch) {
1525 case DENY_IGNORE:
1526 break;
1527 case DENY_WARN:
1528 rp_warning("updating the current branch");
1529 break;
1530 case DENY_REFUSE:
1531 case DENY_UNCONFIGURED:
1532 rp_error("refusing to update checked out branch: %s", name);
1533 if (deny_current_branch == DENY_UNCONFIGURED)
1534 refuse_unconfigured_deny();
1535 ret = "branch is currently checked out";
1536 goto out;
1537 case DENY_UPDATE_INSTEAD:
1538 /* pass -- let other checks intervene first */
1539 do_update_worktree = 1;
1540 break;
1541 }
1542 }
1543
1544 if (!is_null_oid(new_oid) &&
1545 !odb_has_object(the_repository->objects, new_oid,
1546 ODB_HAS_OBJECT_RECHECK_PACKED | ODB_HAS_OBJECT_FETCH_PROMISOR)) {
1547 error("unpack should have generated %s, "
1548 "but I can't find it!", oid_to_hex(new_oid));
1549 ret = "bad pack";
1550 goto out;
1551 }
1552
1553 if (!is_null_oid(old_oid) && is_null_oid(new_oid)) {
1554 if (deny_deletes && starts_with(name, "refs/heads/")) {

Callers 2

execute_commands_atomicFunction · 0.70

Calls 15

get_worktreesFunction · 0.85
find_shared_symrefFunction · 0.85
starts_withFunction · 0.85
check_refname_formatFunction · 0.85
is_null_oidFunction · 0.85
rp_errorFunction · 0.85
strbuf_addfFunction · 0.85
get_git_namespaceFunction · 0.85
strbuf_detachFunction · 0.85
rp_warningFunction · 0.85
refuse_unconfigured_denyFunction · 0.85
odb_has_objectFunction · 0.85

Tested by

no test coverage detected