Quellcode durchsuchen

Warn when fsmonitor is enabled and git submodules are used

Change-Id: I181bf180f762282d5b4bc614d12a91125f56e063
Bug: 1475405
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4814429
Auto-Submit: Aravind Vasudevan <aravindvasudev@google.com>
Reviewed-by: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Aravind Vasudevan <aravindvasudev@google.com>
Commit-Queue: Josip Sokcevic <sokcevic@chromium.org>
Aravind Vasudevan vor 2 Jahren
Ursprung
Commit
b8164180d2
5 geänderte Dateien mit 56 neuen und 1 gelöschten Zeilen
  1. 12 0
      gclient.py
  2. 5 0
      git_cl.py
  3. 24 0
      git_common.py
  4. 6 1
      tests/git_cl_test.py
  5. 9 0
      tests/git_common_test.py

+ 12 - 0
gclient.py

@@ -97,6 +97,7 @@ import urllib.parse
 
 
 import detect_host_arch
 import detect_host_arch
 import fix_encoding
 import fix_encoding
+import git_common
 import gclient_eval
 import gclient_eval
 import gclient_paths
 import gclient_paths
 import gclient_scm
 import gclient_scm
@@ -2137,6 +2138,17 @@ it or fix the checkout.
               patch_repo + '@' + patch_ref
               patch_repo + '@' + patch_ref
               for patch_repo, patch_ref in patch_refs.items())))
               for patch_repo, patch_ref in patch_refs.items())))
 
 
+    # TODO(crbug.com/1475405): Warn users if the project uses submodules and
+    # they have fsmonitor enabled.
+    if command == 'update':
+      # Check if any of the root dependency have submodules.
+      is_submoduled = any(
+          map(
+              lambda d: d.git_dependencies_state in
+              (gclient_eval.SUBMODULES, gclient_eval.SYNC), self.dependencies))
+      if is_submoduled:
+        git_common.warn_submodule()
+
     # Once all the dependencies have been processed, it's now safe to write
     # Once all the dependencies have been processed, it's now safe to write
     # out the gn_args_file and run the hooks.
     # out the gn_args_file and run the hooks.
     removed_cipd_entries = []
     removed_cipd_entries = []

+ 5 - 0
git_cl.py

@@ -4738,6 +4738,11 @@ def CMDupload(parser, args):
                    if opt.help != optparse.SUPPRESS_HELP))
                    if opt.help != optparse.SUPPRESS_HELP))
     return
     return
 
 
+  # TODO(crbug.com/1475405): Warn users if the project uses submodules and
+  # they have fsmonitor enabled.
+  if os.path.isfile('.gitmodules'):
+    git_common.warn_submodule()
+
   if git_common.is_dirty_git_tree('upload'):
   if git_common.is_dirty_git_tree('upload'):
     return 1
     return 1
 
 

+ 24 - 0
git_common.py

@@ -11,6 +11,9 @@ import threading
 
 
 from multiprocessing.pool import IMapIterator
 from multiprocessing.pool import IMapIterator
 
 
+from third_party import colorama
+
+
 def wrapper(func):
 def wrapper(func):
   def wrap(self, timeout=None):
   def wrap(self, timeout=None):
     default_timeout = (1 << 31 if sys.version_info.major == 2 else
     default_timeout = (1 << 31 if sys.version_info.major == 2 else
@@ -410,6 +413,27 @@ def get_config_regexp(pattern):
   return run('config', '--get-regexp', pattern).splitlines()
   return run('config', '--get-regexp', pattern).splitlines()
 
 
 
 
+def is_fsmonitor_enabled():
+  """Returns true if core.fsmonitor is enabled in git config."""
+  fsmonitor = get_config('core.fsmonitor', 'False')
+  return fsmonitor.strip().lower() == 'true'
+
+
+def warn_submodule():
+  """Print warnings for submodules."""
+  # TODO(crbug.com/1475405): Warn users if the project uses submodules and
+  # they have fsmonitor enabled.
+  if is_fsmonitor_enabled():
+    print(colorama.Fore.RED)
+    print('WARNING: You have fsmonitor enabled. There is a major issue '
+          'resulting in git diff-index returning wrong results. Please '
+          'disable it by running:')
+    print('    git config --global core.fsmonitor false')
+    print('We will remove this warning once https://crbug.com/1475405 is '
+          'fixed.')
+    print(colorama.Style.RESET_ALL)
+
+
 def current_branch():
 def current_branch():
   try:
   try:
     return run('rev-parse', '--abbrev-ref', 'HEAD')
     return run('rev-parse', '--abbrev-ref', 'HEAD')

+ 6 - 1
tests/git_cl_test.py

@@ -731,7 +731,12 @@ class TestGitCl(unittest.TestCase):
                          custom_cl_base=None, short_hostname='chromium',
                          custom_cl_base=None, short_hostname='chromium',
                          change_id=None, default_branch='main',
                          change_id=None, default_branch='main',
                          reset_issue=False):
                          reset_issue=False):
-    calls = []
+    calls = [
+        (
+            (['os.path.isfile', '.gitmodules'], ),
+            'True',
+        ),
+    ]
     if custom_cl_base:
     if custom_cl_base:
       ancestor_revision = custom_cl_base
       ancestor_revision = custom_cl_base
     else:
     else:

+ 9 - 0
tests/git_common_test.py

@@ -454,6 +454,15 @@ class GitMutableFunctionsTest(git_test_utils.GitRepoReadWriteTestBase,
 
 
     self.assertEqual('catfood', self.repo.run(self.gc.root))
     self.assertEqual('catfood', self.repo.run(self.gc.root))
 
 
+    self.repo.git('config', '--add', 'core.fsmonitor', 'true')
+    self.assertEqual(True, self.repo.run(self.gc.is_fsmonitor_enabled))
+
+    self.repo.git('config', '--add', 'core.fsmonitor', 't')
+    self.assertEqual(False, self.repo.run(self.gc.is_fsmonitor_enabled))
+
+    self.repo.git('config', '--add', 'core.fsmonitor', 'false')
+    self.assertEqual(False, self.repo.run(self.gc.is_fsmonitor_enabled))
+
   def testRoot(self):
   def testRoot(self):
     origin_schema = git_test_utils.GitRepoSchema("""
     origin_schema = git_test_utils.GitRepoSchema("""
     A B C
     A B C