submodule.c: port is_submodule_modified to use porcelain 2
Migrate 'is_submodule_modified' to the new porcelain format of git-status. This conversion attempts to convert faithfully, i.e. the behavior ought to be exactly the same. As the output in the parsing only distinguishes between untracked files and the rest, this is easy to port to the new format, as we only need to identify untracked files and the rest is handled in the "else" case. untracked files are indicated by only a single question mark instead of two question marks, so the conversion is easy. Signed-off-by: Stefan Beller <sbeller@google.com> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stefan Beller committed
Mar 24, 2017 at 17:36 UTC
fcecf0b968b5e262200426ccf1d0b82495c261fe
1 file changed
+5
-4
submodule.c
+5
-4
@@ -1060,7 +1060,7 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
1060
}
1061
strbuf_reset(&buf);
1062
1063
- argv_array_pushl(&cp.args, "status", "--porcelain", NULL);
1063
+ argv_array_pushl(&cp.args, "status", "--porcelain=2", NULL);
1064
if (ignore_untracked)
1065
argv_array_push(&cp.args, "-uno");
1066
@@ -1070,11 +1070,12 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
1070
cp.out = -1;
1071
cp.dir = path;
1072
if (start_command(&cp))
1073
- die("Could not run 'git status --porcelain' in submodule %s", path);
1073
+ die("Could not run 'git status --porcelain=2' in submodule %s", path);
1074
1075
fp = xfdopen(cp.out, "r");
1076
while (strbuf_getwholeline(&buf, fp, '\n') != EOF) {
1077
- if ((buf.buf[0] == '?') && (buf.buf[1] == '?'))
1077
+ /* regular untracked files */
1078
+ if (buf.buf[0] == '?')
1079
dirty_submodule |= DIRTY_SUBMODULE_UNTRACKED;
1080
else
1081
dirty_submodule |= DIRTY_SUBMODULE_MODIFIED;
@@ -1093,7 +1094,7 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked)
1094
fclose(fp);
1095
1096
if (finish_command(&cp) && !ignore_cp_exit_code)
1096
- die("'git status --porcelain' failed in submodule %s", path);
1097
+ die("'git status --porcelain=2' failed in submodule %s", path);
1098
1099
strbuf_release(&buf);
1100
return dirty_submodule;