Set ignoreSubmodule=all for all repos.

Bug: 1415507

Change-Id: I840508c6972e4640793a12aba287ed8dedfe64c5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4641611
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Joanna Wang <jojwang@chromium.org>
diff --git a/gclient_scm.py b/gclient_scm.py
index 362c81b..8bb1a20 100644
--- a/gclient_scm.py
+++ b/gclient_scm.py
@@ -559,6 +559,22 @@
                    (e.returncode, e.stderr.decode('utf-8')))
       return True
 
+  def set_config(f):
+    def wrapper(*args):
+      return_val = f(*args)
+      if os.path.exists(os.path.join(args[0].checkout_path, '.git')):
+        # If diff.ignoreSubmodules is not already set, set it to `all`.
+        currentIgnore = subprocess2.capture(
+            ['git', 'config', '--get', 'diff.ignoreSubmodules'],
+            cwd=args[0].checkout_path).strip()
+        if not currentIgnore:
+          subprocess2.capture(['git', 'config', 'diff.ignoreSubmodules', 'all'],
+                              cwd=args[0].checkout_path).strip()
+      return return_val
+
+    return wrapper
+
+  @set_config
   def update(self, options, args, file_list):
     """Runs git to update or transparently checkout the working copy.