* 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. */
| 2001 | * and negative values for errors. |
| 2002 | */ |
| 2003 | int 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 | } |
| 2054 | out: |
| 2055 | strbuf_release(&buf); |
| 2056 | return ret; |
| 2057 | } |
| 2058 | |
| 2059 | void submodule_unset_core_worktree(const struct submodule *sub) |
| 2060 | { |
no test coverage detected