OLD | NEW |
1 #!/usr/bin/python | 1 #!/usr/bin/python |
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """Meta checkout manager supporting both Subversion and GIT. | 6 """Meta checkout manager supporting both Subversion and GIT. |
7 | 7 |
8 Files | 8 Files |
9 .gclient : Current client configuration, written by 'config' command. | 9 .gclient : Current client configuration, written by 'config' command. |
10 Format is a Python script defining 'solutions', a list whose | 10 Format is a Python script defining 'solutions', a list whose |
(...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
614 | 614 |
615 def SaveConfig(self): | 615 def SaveConfig(self): |
616 gclient_utils.FileWrite(os.path.join(self.root_dir(), | 616 gclient_utils.FileWrite(os.path.join(self.root_dir(), |
617 self._options.config_filename), | 617 self._options.config_filename), |
618 self.config_content) | 618 self.config_content) |
619 | 619 |
620 @staticmethod | 620 @staticmethod |
621 def LoadCurrentConfig(options): | 621 def LoadCurrentConfig(options): |
622 """Searches for and loads a .gclient file relative to the current working | 622 """Searches for and loads a .gclient file relative to the current working |
623 dir. Returns a GClient object.""" | 623 dir. Returns a GClient object.""" |
624 path = gclient_utils.FindGclientRoot(os.getcwd(), options.config_filename) | 624 cwd = os.getcwd() |
| 625 path = gclient_utils.FindGclientRoot(cwd, options.config_filename) |
625 if not path: | 626 if not path: |
626 return None | 627 return None |
627 client = GClient(path, options) | 628 client = GClient(path, options) |
628 client.SetConfig(gclient_utils.FileRead( | 629 client.SetConfig(gclient_utils.FileRead( |
629 os.path.join(path, options.config_filename))) | 630 os.path.join(path, options.config_filename))) |
630 return client | 631 if path == cwd: |
| 632 return client |
| 633 # Validate the current directory we are in belongs to the .gclient file we |
| 634 # found. |
| 635 cwd = cwd[len(path)+1:] |
| 636 all_solutions = client.tree(False) |
| 637 while len(cwd): |
| 638 if cwd in all_solutions: |
| 639 return client |
| 640 cwd = os.path.dirname(cwd) |
| 641 return None |
631 | 642 |
632 def SetDefaultConfig(self, solution_name, solution_url, safesync_url): | 643 def SetDefaultConfig(self, solution_name, solution_url, safesync_url): |
633 self.SetConfig(self.DEFAULT_CLIENT_FILE_TEXT % { | 644 self.SetConfig(self.DEFAULT_CLIENT_FILE_TEXT % { |
634 'solution_name': solution_name, | 645 'solution_name': solution_name, |
635 'solution_url': solution_url, | 646 'solution_url': solution_url, |
636 'safesync_url' : safesync_url, | 647 'safesync_url' : safesync_url, |
637 }) | 648 }) |
638 | 649 |
639 def _SaveEntries(self): | 650 def _SaveEntries(self): |
640 """Creates a .gclient_entries file to record the list of unique checkouts. | 651 """Creates a .gclient_entries file to record the list of unique checkouts. |
(...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1228 return CMDhelp(parser, argv) | 1239 return CMDhelp(parser, argv) |
1229 except gclient_utils.Error, e: | 1240 except gclient_utils.Error, e: |
1230 print >> sys.stderr, 'Error: %s' % str(e) | 1241 print >> sys.stderr, 'Error: %s' % str(e) |
1231 return 1 | 1242 return 1 |
1232 | 1243 |
1233 | 1244 |
1234 if '__main__' == __name__: | 1245 if '__main__' == __name__: |
1235 sys.exit(Main(sys.argv[1:])) | 1246 sys.exit(Main(sys.argv[1:])) |
1236 | 1247 |
1237 # vim: ts=2:sw=2:tw=80:et: | 1248 # vim: ts=2:sw=2:tw=80:et: |
OLD | NEW |