MCPcopy Index your code
hub / github.com/git/git / bad_to_remove_submodule

Function bad_to_remove_submodule

submodule.c:2003–2057  ·  view source on GitHub ↗

* Check if it is a bad idea to remove a submodule, i.e. if we'd lose data * when doing so. * * Return 1 if we'd lose data, return 0 if the removal is fine, * and negative values for errors. */

Source from the content-addressed store, hash-verified

2001 * and negative values for errors.
2002 */
2003int bad_to_remove_submodule(const char *path, unsigned flags)
2004{
2005 ssize_t len;
2006 struct child_process cp = CHILD_PROCESS_INIT;
2007 struct strbuf buf = STRBUF_INIT;
2008 int ret = 0;
2009
2010 if (validate_submodule_path(path) < 0)
2011 exit(128);
2012
2013 if (!file_exists(path) || is_empty_dir(path))
2014 return 0;
2015
2016 if (!submodule_uses_gitfile(path))
2017 return 1;
2018
2019 strvec_pushl(&cp.args, "status", "--porcelain",
2020 "--ignore-submodules=none", NULL);
2021
2022 if (flags & SUBMODULE_REMOVAL_IGNORE_UNTRACKED)
2023 strvec_push(&cp.args, "-uno");
2024 else
2025 strvec_push(&cp.args, "-uall");
2026
2027 if (!(flags & SUBMODULE_REMOVAL_IGNORE_IGNORED_UNTRACKED))
2028 strvec_push(&cp.args, "--ignored");
2029
2030 prepare_submodule_repo_env(&cp.env);
2031 cp.git_cmd = 1;
2032 cp.no_stdin = 1;
2033 cp.out = -1;
2034 cp.dir = path;
2035 if (start_command(&cp)) {
2036 if (flags & SUBMODULE_REMOVAL_DIE_ON_ERROR)
2037 die(_("could not start 'git status' in submodule '%s'"),
2038 path);
2039 ret = -1;
2040 goto out;
2041 }
2042
2043 len = strbuf_read(&buf, cp.out, 1024);
2044 if (len > 2)
2045 ret = 1;
2046 close(cp.out);
2047
2048 if (finish_command(&cp)) {
2049 if (flags & SUBMODULE_REMOVAL_DIE_ON_ERROR)
2050 die(_("could not run 'git status' in submodule '%s'"),
2051 path);
2052 ret = -1;
2053 }
2054out:
2055 strbuf_release(&buf);
2056 return ret;
2057}
2058
2059void submodule_unset_core_worktree(const struct submodule *sub)
2060{

Callers 1

check_local_modFunction · 0.85

Calls 12

validate_submodule_pathFunction · 0.85
file_existsFunction · 0.85
is_empty_dirFunction · 0.85
submodule_uses_gitfileFunction · 0.85
strvec_pushlFunction · 0.85
strvec_pushFunction · 0.85
start_commandFunction · 0.85
strbuf_readFunction · 0.85
finish_commandFunction · 0.85
strbuf_releaseFunction · 0.85
dieFunction · 0.70

Tested by

no test coverage detected