mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
Avoid silently overwriting diff.ignoreSubmodules config.
Setting this to `dirty` is generally desirable. If the user has explicitly set it to something else on their chromium checkout, warn rather than silently overwriting. Rev^2: https://crrev.com/c/5832742 Change-Id: I8392c7976af0a1f8754a630bd865830ba6698051 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/5836831 Reviewed-by: Josip Sokcevic <sokcevic@chromium.org> Commit-Queue: Helmut Januschka <helmut@januschka.com>
This commit is contained in:
committed by
LUCI CQ
parent
ab2fe54f4d
commit
eb0cb70185
@@ -30,6 +30,7 @@ class GClientSmokeGIT(gclient_smoketest_base.GClientSmokeBase):
|
||||
super(GClientSmokeGIT, self).setUp()
|
||||
self.env['PATH'] = (os.path.join(ROOT_DIR, 'testing_support') +
|
||||
os.pathsep + self.env['PATH'])
|
||||
self.env['GCLIENT_SUPPRESS_SUBMODULE_WARNING'] = '1'
|
||||
self.enabled = self.FAKE_REPOS.set_up_git()
|
||||
if not self.enabled:
|
||||
self.skipTest('git fake repos not available')
|
||||
|
||||
@@ -396,26 +396,38 @@ class ManagedGitWrapperTestCase(BaseGitWrapperTestCase):
|
||||
if not self.enabled:
|
||||
return
|
||||
options = self.Options()
|
||||
expected_file_list = [
|
||||
join(self.base_path, x) for x in ['a', 'b', 'submodule']
|
||||
]
|
||||
expected_file_list = [join(self.base_path, x) for x in ['a', 'b']]
|
||||
git_wrapper = gclient_scm.GitWrapper(self.url, self.root_dir,
|
||||
self.relpath)
|
||||
file_list = []
|
||||
|
||||
# Set diff.ignoreSubmodules to something other than 'dirty'
|
||||
git_wrapper._Run(['config', 'diff.ignoreSubmodules', 'all'], options)
|
||||
git_wrapper.update(options, (), file_list)
|
||||
expected_warning = "diff.ignoreSubmodules is not set to 'dirty'"
|
||||
self.assertTrue(
|
||||
any(expected_warning in w for w in gclient_utils._WARNINGS),
|
||||
f"Expected warning not found. "
|
||||
f"New warnings: {gclient_utils._WARNINGS}")
|
||||
self.assertEqual(file_list, expected_file_list)
|
||||
self.assertEqual(git_wrapper.revinfo(options, (), None),
|
||||
'4091c7d010ca99d0f2dd416d4b70b758ae432187')
|
||||
self.assertEqual(
|
||||
git_wrapper._Capture(['config', '--get', 'diff.ignoreSubmodules']),
|
||||
'dirty')
|
||||
'all')
|
||||
self.assertEqual(
|
||||
git_wrapper._Capture(['config', '--get',
|
||||
'fetch.recurseSubmodules']), 'off')
|
||||
self.assertEqual(
|
||||
git_wrapper._Capture(['config', '--get', 'push.recurseSubmodules']),
|
||||
'off')
|
||||
os.environ['GCLIENT_SUPPRESS_SUBMODULE_WARNING'] = '1'
|
||||
gclient_utils._WARNINGS.clear()
|
||||
git_wrapper.update(options, (), file_list)
|
||||
self.assertEqual(len(gclient_utils._WARNINGS), 0,
|
||||
"Warning was added despite being suppressed")
|
||||
# Clean up
|
||||
del os.environ['GCLIENT_SUPPRESS_SUBMODULE_WARNING']
|
||||
sys.stdout.close()
|
||||
|
||||
def testUpdateMerge(self):
|
||||
|
||||
@@ -11,6 +11,7 @@ import os
|
||||
import sys
|
||||
import tempfile
|
||||
import threading
|
||||
from collections import defaultdict
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
@@ -193,6 +194,27 @@ class RealGitTest(fake_repos.FakeReposTestBase):
|
||||
self.assertEqual(['DEPS', 'foo bar', 'origin'],
|
||||
scm.GIT.GetAllFiles(self.cwd))
|
||||
|
||||
def testScopedConfig(self):
|
||||
scm.GIT.SetConfig(self.cwd,
|
||||
"diff.test-key",
|
||||
value="some value",
|
||||
scope="global")
|
||||
self.assertEqual(scm.GIT.GetConfig(self.cwd, "diff.test-key", None),
|
||||
"some value")
|
||||
self.assertEqual(
|
||||
scm.GIT.GetConfig(self.cwd, "diff.test-key", None, scope="local"),
|
||||
None)
|
||||
|
||||
scm.GIT.SetConfig(self.cwd,
|
||||
"diff.test-key1",
|
||||
value="some value",
|
||||
scope="local")
|
||||
self.assertEqual(scm.GIT.GetConfig(self.cwd, "diff.test-key1", None),
|
||||
"some value")
|
||||
self.assertEqual(
|
||||
scm.GIT.GetConfig(self.cwd, "diff.test-key1", None, scope="local"),
|
||||
"some value")
|
||||
|
||||
def testGetSetConfig(self):
|
||||
key = 'scm.test-key'
|
||||
|
||||
@@ -449,28 +471,82 @@ class GitConfigStateTestTest(unittest.TestCase):
|
||||
self.assertDictEqual(m.load_config(), {})
|
||||
|
||||
gs['section.key'] = ['override']
|
||||
self.assertDictEqual(m.load_config(), {'section.key': ['override']})
|
||||
self.assertDictEqual(
|
||||
m.load_config(), {
|
||||
"global": {
|
||||
'section.key': ['override']
|
||||
},
|
||||
"default": {
|
||||
'section.key': ['override']
|
||||
},
|
||||
})
|
||||
|
||||
def defaultdict_to_dict(self, d):
|
||||
if isinstance(d, defaultdict):
|
||||
return {k: self.defaultdict_to_dict(v) for k, v in d.items()}
|
||||
return d
|
||||
|
||||
def test_construction_global(self):
|
||||
m, gs = self._make(global_state={'section.key': ['global']})
|
||||
self.assertDictEqual(gs, {'section.key': ['global']})
|
||||
self.assertDictEqual(m.load_config(), {'section.key': ['global']})
|
||||
|
||||
m, gs = self._make(global_state={
|
||||
'section.key': ['global'],
|
||||
})
|
||||
self.assertDictEqual(self.defaultdict_to_dict(gs),
|
||||
{'section.key': ['global']})
|
||||
self.assertDictEqual(
|
||||
self.defaultdict_to_dict(m.load_config()), {
|
||||
"global": {
|
||||
'section.key': ['global']
|
||||
},
|
||||
"default": {
|
||||
'section.key': ['global']
|
||||
},
|
||||
})
|
||||
|
||||
gs['section.key'] = ['override']
|
||||
self.assertDictEqual(m.load_config(), {'section.key': ['override']})
|
||||
self.assertDictEqual(
|
||||
self.defaultdict_to_dict(m.load_config()), {
|
||||
"global": {
|
||||
'section.key': ['override']
|
||||
},
|
||||
"default": {
|
||||
'section.key': ['override']
|
||||
},
|
||||
})
|
||||
|
||||
def test_construction_system(self):
|
||||
m, gs = self._make(
|
||||
global_state={'section.key': ['global']},
|
||||
system_state={'section.key': ['system']},
|
||||
)
|
||||
self.assertDictEqual(gs, {'section.key': ['global']})
|
||||
self.assertDictEqual(m.load_config(),
|
||||
{'section.key': ['system', 'global']})
|
||||
self.assertDictEqual(self.defaultdict_to_dict(gs),
|
||||
{'section.key': ['global']})
|
||||
self.assertDictEqual(
|
||||
self.defaultdict_to_dict(m.load_config()), {
|
||||
'default': {
|
||||
'section.key': ['system', 'global']
|
||||
},
|
||||
"global": {
|
||||
'section.key': ['global']
|
||||
},
|
||||
"system": {
|
||||
'section.key': ['system']
|
||||
}
|
||||
})
|
||||
|
||||
gs['section.key'] = ['override']
|
||||
self.assertDictEqual(m.load_config(),
|
||||
{'section.key': ['system', 'override']})
|
||||
self.assertDictEqual(
|
||||
self.defaultdict_to_dict(m.load_config()), {
|
||||
"global": {
|
||||
'section.key': ['override']
|
||||
},
|
||||
"system": {
|
||||
'section.key': ['system']
|
||||
},
|
||||
'default': {
|
||||
'section.key': ['system', 'override']
|
||||
}
|
||||
})
|
||||
|
||||
def test_set_config_system(self):
|
||||
m, _ = self._make()
|
||||
@@ -496,9 +572,15 @@ class GitConfigStateTestTest(unittest.TestCase):
|
||||
self.assertDictEqual(m.load_config(), {})
|
||||
|
||||
m.set_config('section.key', 'new_global', append=True, scope='global')
|
||||
self.assertDictEqual(m.load_config(), {
|
||||
'section.key': ['new_global'],
|
||||
})
|
||||
self.assertDictEqual(
|
||||
m.load_config(), {
|
||||
"default": {
|
||||
'section.key': ['new_global']
|
||||
},
|
||||
"global": {
|
||||
'section.key': ['new_global']
|
||||
}
|
||||
})
|
||||
|
||||
def test_set_config_global(self):
|
||||
m, gs = self._make()
|
||||
@@ -506,44 +588,64 @@ class GitConfigStateTestTest(unittest.TestCase):
|
||||
self.assertDictEqual(m.load_config(), {})
|
||||
|
||||
m.set_config('section.key', 'new_global', append=False, scope='global')
|
||||
self.assertDictEqual(m.load_config(), {
|
||||
'section.key': ['new_global'],
|
||||
})
|
||||
self.assertDictEqual(
|
||||
self.defaultdict_to_dict(m.load_config()), {
|
||||
"global": {
|
||||
'section.key': ['new_global']
|
||||
},
|
||||
"default": {
|
||||
'section.key': ['new_global']
|
||||
}
|
||||
})
|
||||
|
||||
m.set_config('section.key', 'new_global2', append=True, scope='global')
|
||||
self.assertDictEqual(m.load_config(), {
|
||||
'section.key': ['new_global', 'new_global2'],
|
||||
})
|
||||
self.assertDictEqual(
|
||||
self.defaultdict_to_dict(m.load_config()), {
|
||||
"global": {
|
||||
'section.key': ['new_global', 'new_global2']
|
||||
},
|
||||
"default": {
|
||||
'section.key': ['new_global', 'new_global2']
|
||||
},
|
||||
})
|
||||
|
||||
self.assertDictEqual(gs, {
|
||||
'section.key': ['new_global', 'new_global2'],
|
||||
})
|
||||
self.assertDictEqual(self.defaultdict_to_dict(gs),
|
||||
{'section.key': ['new_global', 'new_global2']})
|
||||
|
||||
def test_set_config_multi_global(self):
|
||||
m, gs = self._make(global_state={
|
||||
'section.key': ['1', '2'],
|
||||
})
|
||||
m, gs = self._make(global_state={'section.key': ['1', '2']})
|
||||
|
||||
m.set_config_multi('section.key',
|
||||
'new_global',
|
||||
value_pattern=None,
|
||||
scope='global')
|
||||
self.assertDictEqual(m.load_config(), {
|
||||
'section.key': ['new_global'],
|
||||
})
|
||||
self.assertDictEqual(
|
||||
self.defaultdict_to_dict(m.load_config()), {
|
||||
"default": {
|
||||
'section.key': ['new_global']
|
||||
},
|
||||
"global": {
|
||||
'section.key': ['new_global']
|
||||
}
|
||||
})
|
||||
|
||||
self.assertDictEqual(gs, {
|
||||
'section.key': ['new_global'],
|
||||
})
|
||||
self.assertDictEqual(gs, {'section.key': ['new_global']})
|
||||
|
||||
m.set_config_multi('othersection.key',
|
||||
'newval',
|
||||
value_pattern=None,
|
||||
scope='global')
|
||||
self.assertDictEqual(m.load_config(), {
|
||||
'section.key': ['new_global'],
|
||||
'othersection.key': ['newval'],
|
||||
})
|
||||
self.assertDictEqual(
|
||||
m.load_config(), {
|
||||
"global": {
|
||||
'section.key': ['new_global'],
|
||||
'othersection.key': ['newval'],
|
||||
},
|
||||
"default": {
|
||||
'section.key': ['new_global'],
|
||||
'othersection.key': ['newval'],
|
||||
}
|
||||
})
|
||||
|
||||
self.assertDictEqual(gs, {
|
||||
'section.key': ['new_global'],
|
||||
@@ -559,17 +661,29 @@ class GitConfigStateTestTest(unittest.TestCase):
|
||||
'new_global',
|
||||
value_pattern='2',
|
||||
scope='global')
|
||||
self.assertDictEqual(m.load_config(), {
|
||||
'section.key': ['1', '1', 'new_global', '3'],
|
||||
})
|
||||
self.assertDictEqual(
|
||||
m.load_config(), {
|
||||
"global": {
|
||||
'section.key': ['1', '1', 'new_global', '3']
|
||||
},
|
||||
"default": {
|
||||
'section.key': ['1', '1', 'new_global', '3']
|
||||
}
|
||||
})
|
||||
|
||||
m.set_config_multi('section.key',
|
||||
'additional',
|
||||
value_pattern='narp',
|
||||
scope='global')
|
||||
self.assertDictEqual(m.load_config(), {
|
||||
'section.key': ['1', '1', 'new_global', '3', 'additional'],
|
||||
})
|
||||
self.assertDictEqual(
|
||||
m.load_config(), {
|
||||
"default": {
|
||||
'section.key': ['1', '1', 'new_global', '3', 'additional']
|
||||
},
|
||||
"global": {
|
||||
'section.key': ['1', '1', 'new_global', '3', 'additional']
|
||||
}
|
||||
})
|
||||
|
||||
def test_unset_config_global(self):
|
||||
m, _ = self._make(global_state={
|
||||
@@ -595,19 +709,34 @@ class GitConfigStateTestTest(unittest.TestCase):
|
||||
|
||||
m.unset_config('section.key', scope='global', missing_ok=False)
|
||||
self.assertDictEqual(m.load_config(), {
|
||||
'extra': ['another'],
|
||||
"global": {
|
||||
'extra': ['another']
|
||||
},
|
||||
"default": {
|
||||
'extra': ['another']
|
||||
}
|
||||
})
|
||||
|
||||
with self.assertRaises(scm.GitConfigUnsetMissingValue):
|
||||
m.unset_config('section.key', scope='global', missing_ok=False)
|
||||
|
||||
self.assertDictEqual(m.load_config(), {
|
||||
'extra': ['another'],
|
||||
"global": {
|
||||
'extra': ['another']
|
||||
},
|
||||
"default": {
|
||||
'extra': ['another']
|
||||
}
|
||||
})
|
||||
|
||||
m.unset_config('section.key', scope='global', missing_ok=True)
|
||||
self.assertDictEqual(m.load_config(), {
|
||||
'extra': ['another'],
|
||||
"global": {
|
||||
'extra': ['another']
|
||||
},
|
||||
"default": {
|
||||
'extra': ['another']
|
||||
}
|
||||
})
|
||||
|
||||
def test_unset_config_global_multi(self):
|
||||
@@ -644,9 +773,15 @@ class GitConfigStateTestTest(unittest.TestCase):
|
||||
value_pattern='2',
|
||||
scope='global',
|
||||
missing_ok=False)
|
||||
self.assertDictEqual(m.load_config(), {
|
||||
'section.key': ['1', '3', '1'],
|
||||
})
|
||||
self.assertDictEqual(
|
||||
m.load_config(), {
|
||||
'global': {
|
||||
'section.key': ['1', '3', '1'],
|
||||
},
|
||||
'default': {
|
||||
'section.key': ['1', '3', '1'],
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
class CanonicalizeGitConfigKeyTest(unittest.TestCase):
|
||||
|
||||
Reference in New Issue
Block a user