| 1602 | } |
| 1603 | |
| 1604 | static int delete_remote_branch(const char *pattern, int force) |
| 1605 | { |
| 1606 | struct ref *refs = remote_refs; |
| 1607 | struct ref *remote_ref = NULL; |
| 1608 | struct object_id head_oid; |
| 1609 | char *symref = NULL; |
| 1610 | int match; |
| 1611 | int patlen = strlen(pattern); |
| 1612 | int i; |
| 1613 | struct active_request_slot *slot; |
| 1614 | struct slot_results results; |
| 1615 | char *url; |
| 1616 | |
| 1617 | /* Find the remote branch(es) matching the specified branch name */ |
| 1618 | for (match = 0; refs; refs = refs->next) { |
| 1619 | char *name = refs->name; |
| 1620 | int namelen = strlen(name); |
| 1621 | if (namelen < patlen || |
| 1622 | memcmp(name + namelen - patlen, pattern, patlen)) |
| 1623 | continue; |
| 1624 | if (namelen != patlen && name[namelen - patlen - 1] != '/') |
| 1625 | continue; |
| 1626 | match++; |
| 1627 | remote_ref = refs; |
| 1628 | } |
| 1629 | if (match == 0) |
| 1630 | return error("No remote branch matches %s", pattern); |
| 1631 | if (match != 1) |
| 1632 | return error("More than one remote branch matches %s", |
| 1633 | pattern); |
| 1634 | |
| 1635 | /* |
| 1636 | * Remote HEAD must be a symref (not exactly foolproof; a remote |
| 1637 | * symlink to a symref will look like a symref) |
| 1638 | */ |
| 1639 | fetch_symref("HEAD", &symref, &head_oid); |
| 1640 | if (!symref) |
| 1641 | return error("Remote HEAD is not a symref"); |
| 1642 | |
| 1643 | /* Remote branch must not be the remote HEAD */ |
| 1644 | for (i = 0; symref && i < MAXDEPTH; i++) { |
| 1645 | if (!strcmp(remote_ref->name, symref)) |
| 1646 | return error("Remote branch %s is the current HEAD", |
| 1647 | remote_ref->name); |
| 1648 | fetch_symref(symref, &symref, &head_oid); |
| 1649 | } |
| 1650 | |
| 1651 | /* Run extra sanity checks if delete is not forced */ |
| 1652 | if (!force) { |
| 1653 | /* Remote HEAD must resolve to a known object */ |
| 1654 | if (symref) |
| 1655 | return error("Remote HEAD symrefs too deep"); |
| 1656 | if (is_null_oid(&head_oid)) |
| 1657 | return error("Unable to resolve remote HEAD"); |
| 1658 | if (!odb_has_object(the_repository->objects, &head_oid, |
| 1659 | ODB_HAS_OBJECT_RECHECK_PACKED | ODB_HAS_OBJECT_FETCH_PROMISOR)) |
| 1660 | return error("Remote HEAD resolves to object %s\nwhich does not exist locally, perhaps you need to fetch?", oid_to_hex(&head_oid)); |
| 1661 |
no test coverage detected