From 923bcf8635a3fbe7a8aa4e4bdcfa90bb037526df Mon Sep 17 00:00:00 2001 From: Greg NISBET Date: Thu, 10 Aug 2023 22:50:46 +0000 Subject: [PATCH] [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 Commit-Queue: Gregory Nisbet --- git_common.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/git_common.py b/git_common.py index 925f2cd91c..7ff03b7fc5 100644 --- a/git_common.py +++ b/git_common.py @@ -871,9 +871,13 @@ def is_dirty_git_tree(cmd): 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 @@ def status(): * 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 @@ def status(): 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):