Remove .git suffix from git submodules
.git suffix is not well supported by the systems that utilize
submodules. Since some tools expect DEPS to have .git suffix, it's not
possible to simply update DEPS without breaking the tools.
This patch updates `gclient gitmodules` to omit .git suffix and trailing
slashes. However, if `.gitmodule` already exists, we are expecting the
tool to generate the same result if DEPS didn't change.
R=aravindvasudev@google.com
Bug: b/303296048
Change-Id: I30497b9d5f4e9681e16b4a913151de0f4a7c9545
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5008942
Reviewed-by: Aravind Vasudevan <aravindvasudev@google.com>
Commit-Queue: Josip Sokcevic <sokcevic@chromium.org>
diff --git a/gclient.py b/gclient.py
index ec633dc..9d490f8 100755
--- a/gclient.py
+++ b/gclient.py
@@ -2874,6 +2874,18 @@
prefix_length = len(delta_path.replace(os.path.sep, '/')) + 1
cache_info = []
+
+ # Git submodules shouldn't use .git suffix since it's not well supported.
+ # However, we can't update .gitmodules files since there is no guarantee
+ # that user has the latest version of depot_tools, and also they are not on
+ # some old branch which contains already contains submodules with .git.
+ # This check makes the transition easier.
+ strip_git_suffix = True
+ if os.path.exists(options.output_gitmodules):
+ dot_git_pattern = re.compile('^(\s*)url(\s*)=.*\.git$')
+ with open(options.output_gitmodules) as f:
+ strip_git_suffix = not any(dot_git_pattern.match(l) for l in f)
+
with open(options.output_gitmodules, 'w', newline='') as f:
for path, dep in ls.get('deps').items():
if path in options.skip_dep:
@@ -2889,6 +2901,11 @@
if prefix_length:
path = path[prefix_length:]
+ if strip_git_suffix:
+ if url.endswith('.git'):
+ url = url[:-4] # strip .git
+ url = url.rstrip('/') # remove trailing slash for consistency
+
cache_info += ['--cacheinfo', f'160000,{commit},{path}']
f.write(f'[submodule "{path}"]\n\tpath = {path}\n\turl = {url}\n')
if 'condition' in dep: