OLD | NEW |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """SCM-specific utility classes.""" | 5 """SCM-specific utility classes.""" |
6 | 6 |
7 import cStringIO | 7 import cStringIO |
8 import glob | 8 import glob |
9 import logging | 9 import logging |
10 import os | 10 import os |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 return os.path.abspath(GIT.Capture(['rev-parse', '--git-dir'], cwd=cwd)) | 436 return os.path.abspath(GIT.Capture(['rev-parse', '--git-dir'], cwd=cwd)) |
437 | 437 |
438 @staticmethod | 438 @staticmethod |
439 def IsInsideWorkTree(cwd): | 439 def IsInsideWorkTree(cwd): |
440 try: | 440 try: |
441 return GIT.Capture(['rev-parse', '--is-inside-work-tree'], cwd=cwd) | 441 return GIT.Capture(['rev-parse', '--is-inside-work-tree'], cwd=cwd) |
442 except (OSError, subprocess2.CalledProcessError): | 442 except (OSError, subprocess2.CalledProcessError): |
443 return False | 443 return False |
444 | 444 |
445 @staticmethod | 445 @staticmethod |
| 446 def IsDirectoryVersioned(cwd, relative_dir): |
| 447 """Checks whether the given |relative_dir| is part of cwd's repo.""" |
| 448 return bool(GIT.Capture(['ls-tree', 'HEAD', relative_dir], cwd=cwd)) |
| 449 |
| 450 @staticmethod |
| 451 def CleanupDir(cwd, relative_dir): |
| 452 """Cleans up untracked file inside |relative_dir|.""" |
| 453 return bool(GIT.Capture(['clean', '-df', relative_dir], cwd=cwd)) |
| 454 |
| 455 @staticmethod |
446 def GetGitSvnHeadRev(cwd): | 456 def GetGitSvnHeadRev(cwd): |
447 """Gets the most recently pulled git-svn revision.""" | 457 """Gets the most recently pulled git-svn revision.""" |
448 try: | 458 try: |
449 output = GIT.Capture(['svn', 'info'], cwd=cwd) | 459 output = GIT.Capture(['svn', 'info'], cwd=cwd) |
450 match = re.search(r'^Revision: ([0-9]+)$', output, re.MULTILINE) | 460 match = re.search(r'^Revision: ([0-9]+)$', output, re.MULTILINE) |
451 return int(match.group(1)) if match else None | 461 return int(match.group(1)) if match else None |
452 except (subprocess2.CalledProcessError, ValueError): | 462 except (subprocess2.CalledProcessError, ValueError): |
453 return None | 463 return None |
454 | 464 |
455 @staticmethod | 465 @staticmethod |
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1160 # revert, like for properties. | 1170 # revert, like for properties. |
1161 if not os.path.isdir(cwd): | 1171 if not os.path.isdir(cwd): |
1162 # '.' was deleted. It's not worth continuing. | 1172 # '.' was deleted. It's not worth continuing. |
1163 return | 1173 return |
1164 try: | 1174 try: |
1165 SVN.Capture(['revert', file_status[1]], cwd=cwd) | 1175 SVN.Capture(['revert', file_status[1]], cwd=cwd) |
1166 except subprocess2.CalledProcessError: | 1176 except subprocess2.CalledProcessError: |
1167 if not os.path.exists(file_path): | 1177 if not os.path.exists(file_path): |
1168 continue | 1178 continue |
1169 raise | 1179 raise |
OLD | NEW |