| 1878 | } |
| 1879 | |
| 1880 | unsigned is_submodule_modified(const char *path, int ignore_untracked) |
| 1881 | { |
| 1882 | struct child_process cp = CHILD_PROCESS_INIT; |
| 1883 | struct strbuf buf = STRBUF_INIT; |
| 1884 | FILE *fp; |
| 1885 | unsigned dirty_submodule = 0; |
| 1886 | const char *git_dir; |
| 1887 | int ignore_cp_exit_code = 0; |
| 1888 | |
| 1889 | if (validate_submodule_path(path) < 0) |
| 1890 | exit(128); |
| 1891 | |
| 1892 | strbuf_addf(&buf, "%s/.git", path); |
| 1893 | git_dir = read_gitfile(buf.buf); |
| 1894 | if (!git_dir) |
| 1895 | git_dir = buf.buf; |
| 1896 | if (!is_git_directory(git_dir)) { |
| 1897 | if (is_directory(git_dir)) |
| 1898 | die(_("'%s' not recognized as a git repository"), git_dir); |
| 1899 | strbuf_release(&buf); |
| 1900 | /* The submodule is not checked out, so it is not modified */ |
| 1901 | return 0; |
| 1902 | } |
| 1903 | strbuf_reset(&buf); |
| 1904 | |
| 1905 | strvec_pushl(&cp.args, "status", "--porcelain=2", NULL); |
| 1906 | if (ignore_untracked) |
| 1907 | strvec_push(&cp.args, "-uno"); |
| 1908 | |
| 1909 | prepare_submodule_repo_env(&cp.env); |
| 1910 | cp.git_cmd = 1; |
| 1911 | cp.no_stdin = 1; |
| 1912 | cp.out = -1; |
| 1913 | cp.dir = path; |
| 1914 | if (start_command(&cp)) |
| 1915 | die(_("Could not run 'git status --porcelain=2' in submodule %s"), path); |
| 1916 | |
| 1917 | fp = xfdopen(cp.out, "r"); |
| 1918 | while (strbuf_getwholeline(&buf, fp, '\n') != EOF) { |
| 1919 | /* regular untracked files */ |
| 1920 | if (buf.buf[0] == '?') |
| 1921 | dirty_submodule |= DIRTY_SUBMODULE_UNTRACKED; |
| 1922 | |
| 1923 | if (buf.buf[0] == 'u' || |
| 1924 | buf.buf[0] == '1' || |
| 1925 | buf.buf[0] == '2') { |
| 1926 | /* T = line type, XY = status, SSSS = submodule state */ |
| 1927 | if (buf.len < strlen("T XY SSSS")) |
| 1928 | BUG("invalid status --porcelain=2 line %s", |
| 1929 | buf.buf); |
| 1930 | |
| 1931 | if (buf.buf[5] == 'S' && buf.buf[8] == 'U') |
| 1932 | /* nested untracked file */ |
| 1933 | dirty_submodule |= DIRTY_SUBMODULE_UNTRACKED; |
| 1934 | |
| 1935 | if (buf.buf[0] == 'u' || |
| 1936 | buf.buf[0] == '2' || |
| 1937 | memcmp(buf.buf + 5, "S..U", 4)) |
no test coverage detected