Commits

Greg Ward committed a0532b0

hg: fix parsing of "hg status" output so it's not fooled by crazy filenames

  • Participants
  • Parent commits ab1c6ee

Comments (0)

Files changed (2)

         return;
     }
     char *cstdout = capture->childout.buf;
-    if (context->options->show_unknown) {
-        result->unknown = (strstr(cstdout, "? ") != NULL);
-    }
-
-    if (context->options->show_modified) {
-	result->modified = (strstr(cstdout, "M ") != NULL ||
-			    strstr(cstdout, "A ") != NULL||
-			    strstr(cstdout, "! ") != NULL||
-			    strstr(cstdout, "R ") != NULL);
+    for (char *ch = cstdout; *ch != 0; ch++) {
+        if (ch == cstdout || *(ch-1) == '\n') {
+            // at start of output or start of line: look for ?, M, etc.
+            if (context->options->show_unknown && *ch == '?') {
+                result->unknown = 1;
+            }
+            if (context->options->show_modified &&
+                (*ch == 'M' || *ch == 'A' || *ch == 'R')) {
+                result->modified = 1;
+            }
+        }
     }
 
     cstdout = NULL;

File tests/test-hg

 
     fn="crazy? filename"
     echo "not junk" > "$fn"
-    hg -q add "$fn"
+    hg -q add "$fn" 2>&1 | grep -iv "reserved on windows"
     hg -q commit -m"yes, it's a crazy filename"
     assert_vcprompt "no modified files" "" "%m"
     assert_vcprompt "no unknown files" "" "%u"