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

Function deinit_submodule

builtin/submodule--helper.c:1578–1668  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1576#define DEINIT_CB_INIT { 0 }
1577
1578static void deinit_submodule(const char *path, const char *prefix,
1579 unsigned int flags)
1580{
1581 const struct submodule *sub;
1582 char *displaypath = NULL;
1583 struct child_process cp_config = CHILD_PROCESS_INIT;
1584 struct strbuf sb_config = STRBUF_INIT;
1585 char *sub_git_dir = xstrfmt("%s/.git", path);
1586
1587 if (validate_submodule_path(path) < 0)
1588 die(NULL);
1589
1590 sub = submodule_from_path(the_repository, null_oid(the_hash_algo), path);
1591
1592 if (!sub || !sub->name)
1593 goto cleanup;
1594
1595 displaypath = get_submodule_displaypath(path, prefix, NULL);
1596
1597 /* remove the submodule work tree (unless the user already did it) */
1598 if (is_directory(path)) {
1599 struct strbuf sb_rm = STRBUF_INIT;
1600 const char *format;
1601
1602 if (is_directory(sub_git_dir)) {
1603 if (!(flags & OPT_QUIET))
1604 warning(_("Submodule work tree '%s' contains a .git "
1605 "directory. This will be replaced with a "
1606 ".git file by using absorbgitdirs."),
1607 displaypath);
1608
1609 absorb_git_dir_into_superproject(path, NULL);
1610
1611 }
1612
1613 if (!(flags & OPT_FORCE)) {
1614 struct child_process cp_rm = CHILD_PROCESS_INIT;
1615
1616 cp_rm.git_cmd = 1;
1617 strvec_pushl(&cp_rm.args, "rm", "-qn",
1618 path, NULL);
1619
1620 if (run_command(&cp_rm))
1621 die(_("Submodule work tree '%s' contains local "
1622 "modifications; use '-f' to discard them"),
1623 displaypath);
1624 }
1625
1626 strbuf_addstr(&sb_rm, path);
1627
1628 if (!remove_dir_recursively(&sb_rm, 0))
1629 format = _("Cleared directory '%s'\n");
1630 else
1631 format = _("Could not remove submodule work tree '%s'\n");
1632
1633 if (!(flags & OPT_QUIET))
1634 printf(format, displaypath);
1635

Callers 1

deinit_submodule_cbFunction · 0.85

Calls 15

xstrfmtFunction · 0.85
validate_submodule_pathFunction · 0.85
submodule_from_pathFunction · 0.85
null_oidFunction · 0.85
is_directoryFunction · 0.85
warningFunction · 0.85
strvec_pushlFunction · 0.85
run_commandFunction · 0.85
strbuf_addstrFunction · 0.85
remove_dir_recursivelyFunction · 0.85

Tested by

no test coverage detected