[scm] Handle warnings in git diff output

The `git diff` output can sometimes include non-fatal warning messages
at the end. For example, if the diff contains at least
`diff.renameLimit` files, the following messages will show up
(newline-separated, even with the `-z` flag) at the end of the stdout:

  warning: exhaustive rename detection was skipped due to too many files.
  warning: you may want to set your diff.renameLimit variable to at least 2458 and retry the command.

We should ignore these messages as long as `git diff` produces a retcode
of zero, rather than erroring out.

Change-Id: I59fa60a36fa8bc76d7f517332588667bea171f8b
Reviewed-on: https://fuchsia-review.googlesource.com/c/shac-project/shac/+/892540
Fuchsia-Auto-Submit: Oliver Newman <olivernewman@google.com>
Commit-Queue: Auto-Submit <auto-submit@fuchsia-infra.iam.gserviceaccount.com>
Reviewed-by: Marc-Antoine Ruel <maruel@google.com>
diff --git a/internal/engine/runtime_ctx_scm.go b/internal/engine/runtime_ctx_scm.go
index ee01fd1..09b6fe8 100644
--- a/internal/engine/runtime_ctx_scm.go
+++ b/internal/engine/runtime_ctx_scm.go
@@ -469,7 +469,14 @@
 			}
 		}
 		if path == "" {
-			g.err = fmt.Errorf("missing trailing NUL character from git diff --name-status -z -C %s", g.upstream.hash)
+			// `git diff` output will sometimes include newline-separated
+			// non-fatal warnings at the end, e.g. if the number of renamed
+			// files in the diff exceeds the `diff.renameLimit` config var.
+			// If we encounter such a warning, we assume it's at the end of the
+			// diff output.
+			if !strings.HasPrefix(o, "warning:") {
+				g.err = fmt.Errorf("missing trailing NUL character from git diff --name-status -z -C %s", g.upstream.hash)
+			}
 			break
 		}
 		if action == "D" && !includeDeleted {