From 2509f86654355fe459e6dc2fa35d568764ffa72f Mon Sep 17 00:00:00 2001 From: "jochen@chromium.org" Date: Thu, 2 Sep 2010 17:03:06 +0000 Subject: [PATCH] Do not blindly assume that a .gclient file in a parent directory belongs to the current directory. BUG=54238 TEST=GClientSmoke.testWrongConfig Review URL: http://codereview.chromium.org/3300007 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@58371 0039d316-1c4b-4281-b951-d872f2087c98 --- gclient.py | 15 +++++++++++++-- tests/gclient_smoketest.py | 12 ++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/gclient.py b/gclient.py index 5ca703635..3cabc14ae 100644 --- a/gclient.py +++ b/gclient.py @@ -621,13 +621,24 @@ solutions = [ def LoadCurrentConfig(options): """Searches for and loads a .gclient file relative to the current working dir. Returns a GClient object.""" - path = gclient_utils.FindGclientRoot(os.getcwd(), options.config_filename) + cwd = os.getcwd() + path = gclient_utils.FindGclientRoot(cwd, options.config_filename) if not path: return None client = GClient(path, options) client.SetConfig(gclient_utils.FileRead( os.path.join(path, options.config_filename))) - return client + if path == cwd: + return client + # Validate the current directory we are in belongs to the .gclient file we + # found. + cwd = cwd[len(path)+1:] + all_solutions = [d.name for d in client.tree(False)] + while len(cwd): + if cwd in all_solutions: + return client + cwd = os.path.dirname(cwd) + return None def SetDefaultConfig(self, solution_name, solution_url, safesync_url): self.SetConfig(self.DEFAULT_CLIENT_FILE_TEXT % { diff --git a/tests/gclient_smoketest.py b/tests/gclient_smoketest.py index 2ebbc335f..d7ae9fe3f 100755 --- a/tests/gclient_smoketest.py +++ b/tests/gclient_smoketest.py @@ -145,6 +145,18 @@ class GClientSmoke(GClientSmokeBase): self.check(res, self.gclient(['sync'])) self.check(res, self.gclient(['update'])) + def testWrongConfig(self): + # tested in testConfig. + self.gclient(['config', self.svn_base + 'trunk/src/']) + other_src = join(self.root_dir, 'src-other') + os.mkdir(other_src) + res = ('', 'Error: client not configured; see \'gclient config\'\n', 1) + self.check(res, self.gclient(['status'], other_src)) + src = join(self.root_dir, 'src') + os.mkdir(src) + res = self.gclient(['status'], src) + self.checkBlock(res[0], [('running', src)]) + def testConfig(self): p = join(self.root_dir, '.gclient') def test(cmd, expected):