[gclient] Fix setdep if relative path is not used

R=aravindvasudev@google.com, jojwang@google.com

Change-Id: Ic4f7046ac4e1a22a82db97466c43afee99c393de
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4795232
Reviewed-by: Aravind Vasudevan <aravindvasudev@google.com>
Auto-Submit: Josip Sokcevic <sokcevic@chromium.org>
Commit-Queue: Josip Sokcevic <sokcevic@chromium.org>
changes/32/4795232/3
Josip Sokcevic 2 years ago committed by LUCI CQ
parent 3aeb682373
commit 5561f8be12

@ -115,7 +115,6 @@ from third_party.repo.progress import Progress
import subcommand import subcommand
import subprocess2 import subprocess2
import setup_color import setup_color
import git_cl
from third_party import six from third_party import six
@ -2722,11 +2721,14 @@ def CMDgitmodules(parser, args):
if prefix_length: if prefix_length:
path = path[prefix_length:] path = path[prefix_length:]
git_cl.RunGit( subprocess2.call([
['update-index', '--add', '--cacheinfo', '160000', commit, path]) 'git', 'update-index', '--add', '--cacheinfo',
f'160000,{commit},{path}'
])
f.write(f'[submodule "{path}"]\n\tpath = {path}\n\turl = {url}\n') f.write(f'[submodule "{path}"]\n\tpath = {path}\n\turl = {url}\n')
if 'condition' in dep: if 'condition' in dep:
f.write(f'\tgclient-condition = {dep["condition"]}\n') f.write(f'\tgclient-condition = {dep["condition"]}\n')
subprocess2.call(['git', 'add', '.gitmodules'])
print('.gitmodules and gitlinks updated. Please check git diff and ' print('.gitmodules and gitlinks updated. Please check git diff and '
'commit changes.') 'commit changes.')
@ -3536,22 +3538,41 @@ def CMDsetdep(parser, args):
# Update git submodules when `git_dependencies` == SYNC or SUBMODULES. # Update git submodules when `git_dependencies` == SYNC or SUBMODULES.
if git_modules and 'git_dependencies' in local_scope and local_scope[ if git_modules and 'git_dependencies' in local_scope and local_scope[
'git_dependencies'] in (gclient_eval.SUBMODULES, gclient_eval.SYNC): 'git_dependencies'] in (gclient_eval.SUBMODULES, gclient_eval.SYNC):
git_module_name = name
if not 'use_relative_paths' in local_scope or \
local_scope['use_relative_paths'] != True:
deps_dir = os.path.dirname(os.path.abspath(options.deps_file))
gclient_path = gclient_paths.FindGclientRoot(deps_dir)
delta_path = None
if gclient_path:
delta_path = os.path.relpath(deps_dir,
os.path.abspath(gclient_path))
if delta_path:
prefix_length = len(delta_path.replace(os.path.sep, '/')) + 1
git_module_name = name[prefix_length:]
# gclient setdep should update the revision, i.e., the gitlink only # gclient setdep should update the revision, i.e., the gitlink only
# when the submodule entry is already present within .gitmodules. # when the submodule entry is already present within .gitmodules.
if name not in git_modules: if git_module_name not in git_modules:
raise KeyError( raise KeyError(
'Could not find any dependency called %s in .gitmodules.' % name) f'Could not find any dependency called "{git_module_name}" in '
f'.gitmodules.')
# Update the gitlink for the submodule. # Update the gitlink for the submodule.
subprocess2.call([ subprocess2.call([
'git', 'update-index', '--add', '--cacheinfo', 'git', 'update-index', '--add', '--cacheinfo',
f'160000,{value},{name}' f'160000,{value},{git_module_name}'
], ],
cwd=cwd) cwd=cwd)
with open(options.deps_file, 'wb') as f: with open(options.deps_file, 'wb') as f:
f.write(gclient_eval.RenderDEPSFile(local_scope).encode('utf-8')) f.write(gclient_eval.RenderDEPSFile(local_scope).encode('utf-8'))
if git_modules:
subprocess2.call(['git', 'add', options.deps_file], cwd=cwd)
print('Changes have been staged. See changes with `git status`.\n'
'Use `git commit -m "Manual roll"` to commit your changes. \n'
'Run gclient sync to update your local dependency checkout.')
@metrics.collector.collect_metrics('gclient verify') @metrics.collector.collect_metrics('gclient verify')
def CMDverify(parser, args): def CMDverify(parser, args):

@ -626,12 +626,77 @@ class GClientSmokeGIT(gclient_smoketest_base.GClientSmokeBase):
], contents) ], contents)
def testSetDep_Submodules(self): def testSetDep_Submodules(self):
self.gclient(['config', self.git_base + 'repo_1', '--name', 'src'])
with open(os.path.join(self.git_base, '.gclient'), 'w') as f:
f.write('')
fake_deps = os.path.join(self.git_base, 'repo_1', 'DEPS')
gitmodules = os.path.join(self.git_base, 'repo_1', '.gitmodules')
with open(fake_deps, 'w') as f:
f.write('\n'.join([
'git_dependencies = "SYNC"',
'vars = { ',
' "foo_var": "foo_val",',
' "foo_rev": "foo_rev",',
'}',
'deps = { ',
' "repo_1/foo": "https://foo" + Var("foo_rev"),',
' "repo_1/bar": "https://bar@barrev",',
'}',
]))
with open(gitmodules, 'w') as f:
f.write('\n'.join([
'[submodule "foo"]', ' url = https://foo', ' path = foo',
'[submodule "bar"]', ' url = https://bar', ' path = bar'
]))
subprocess2.call([
'git', 'update-index', '--add', '--cacheinfo',
'160000,aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,foo'
],
cwd=self.git_base + 'repo_1')
subprocess2.call([
'git', 'update-index', '--add', '--cacheinfo',
'160000,aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,bar'
],
cwd=self.git_base + 'repo_1')
self.gclient([
'setdep',
'-r',
'repo_1/foo@new_foo',
'--var',
'foo_var=new_val',
'-r',
'repo_1/bar@bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb',
],
cwd=self.git_base + 'repo_1')
with open(fake_deps) as f:
contents = f.read().splitlines()
self.assertEqual([
'git_dependencies = "SYNC"',
'vars = { ',
' "foo_var": "new_val",',
' "foo_rev": "new_foo",',
'}',
'deps = { ',
' "repo_1/foo": "https://foo" + Var("foo_rev"),',
' "repo_1/bar": '
'"https://bar@bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",',
'}',
], contents)
def testSetDep_Submodules_relative(self):
self.gclient(['config', self.git_base + 'repo_1', '--name', 'src']) self.gclient(['config', self.git_base + 'repo_1', '--name', 'src'])
fake_deps = os.path.join(self.git_base, 'repo_1', 'DEPS') fake_deps = os.path.join(self.git_base, 'repo_1', 'DEPS')
gitmodules = os.path.join(self.git_base, 'repo_1', '.gitmodules') gitmodules = os.path.join(self.git_base, 'repo_1', '.gitmodules')
with open(fake_deps, 'w') as f: with open(fake_deps, 'w') as f:
f.write('\n'.join([ f.write('\n'.join([
'git_dependencies = "SUBMODULES"', 'git_dependencies = "SUBMODULES"',
'use_relative_paths = True',
'vars = { ', 'vars = { ',
' "foo_var": "foo_val",', ' "foo_var": "foo_val",',
' "foo_rev": "foo_rev",', ' "foo_rev": "foo_rev",',
@ -659,6 +724,7 @@ class GClientSmokeGIT(gclient_smoketest_base.GClientSmokeBase):
self.assertEqual([ self.assertEqual([
'git_dependencies = "SUBMODULES"', 'git_dependencies = "SUBMODULES"',
'use_relative_paths = True',
'vars = { ', 'vars = { ',
' "foo_var": "new_val",', ' "foo_var": "new_val",',
' "foo_rev": "foo_rev",', ' "foo_rev": "foo_rev",',

Loading…
Cancel
Save