[git] add ignore_submodules option to status command in git_common.py

The `git addf` function implemented in the CL given below needs the ability to
ignore submodules in the output of `status`. Therefore, I am adding a flag to
the status command in `git_common` that resembles the git command line flag.

https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4771336

Change-Id: I447c0dc853014ef49562f3130b22d038912011c8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4771343
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Gregory Nisbet <gregorynisbet@google.com>
diff --git a/git_common.py b/git_common.py
index 925f2cd..7ff03b7 100644
--- a/git_common.py
+++ b/git_common.py
@@ -871,9 +871,13 @@
   return False
 
 
-def status():
+def status(ignore_submodules=None):
   """Returns a parsed version of git-status.
 
+  Args:
+   ignore_submodules (str|None): "all", "none", or None.
+                                 None is equivalent to "none".
+
   Returns a generator of (current_name, (lstat, rstat, src)) pairs where:
     * current_name is the name of the file
     * lstat is the left status code letter from git-status
@@ -881,6 +885,11 @@
     * src is the current name of the file, or the original name of the file
       if lstat == 'R'
   """
+
+  ignore_submodules = ignore_submodules or 'none'
+  assert ignore_submodules in (
+      'all', 'none'), f'ignore_submodules value {ignore_submodules} is invalid'
+
   stat_entry = collections.namedtuple('stat_entry', 'lstat rstat src')
 
   def tokenizer(stream):
@@ -909,7 +918,12 @@
         src = dest
       yield (dest, stat_entry(lstat, rstat, src))
 
-  return parser(tokenizer(run_stream('status', '-z', bufsize=-1)))
+  return parser(
+      tokenizer(
+          run_stream('status',
+                     '-z',
+                     f'--ignore-submodules={ignore_submodules}',
+                     bufsize=-1)))
 
 
 def squash_current_branch(header=None, merge_base=None):