Chromium Code Reviews| Index: gclient_scm.py |
| diff --git a/gclient_scm.py b/gclient_scm.py |
| index 01dfd54675b32151d38eb6fe27629650397a32bd..b78be83ff69626017b77d4a4a3369b0bc358b71c 100644 |
| --- a/gclient_scm.py |
| +++ b/gclient_scm.py |
| @@ -237,6 +237,17 @@ class GitWrapper(SCMWrapper): |
| gclient_utils.CheckCallAndFilter(cmd4, **kwargs) |
| + def _FetchAndReset(self, revision, file_list, options): |
|
M-A Ruel
2013/06/11 19:01:36
"""Equivalent of git fetch; git reset."""
Mike Stip (use stip instead)
2013/06/11 20:38:54
Done.
|
| + quiet = [] |
| + if not options.verbose: |
| + quiet = ['--quiet'] |
| + self._UpdateBranchHeads(options, fetch=False) |
| + self._Run(['fetch', 'origin', '--prune'] + quiet, options) |
| + self._Run(['reset', '--hard', revision] + quiet, options) |
| + self.UpdateSubmoduleConfig() |
| + files = self._Capture(['ls-files']).splitlines() |
| + file_list.extend([os.path.join(self.checkout_path, f) for f in files]) |
| + |
| def update(self, options, args, file_list): |
| """Runs git to update or transparently checkout the working copy. |
| @@ -338,17 +349,21 @@ class GitWrapper(SCMWrapper): |
| self._CheckClean(rev_str) |
| # Switch over to the new upstream |
| self._Run(['remote', 'set-url', 'origin', url], options) |
| - quiet = [] |
| - if not options.verbose: |
| - quiet = ['--quiet'] |
| - self._UpdateBranchHeads(options, fetch=False) |
| - self._Run(['fetch', 'origin', '--prune'] + quiet, options) |
| - self._Run(['reset', '--hard', revision] + quiet, options) |
| - self.UpdateSubmoduleConfig() |
| - files = self._Capture(['ls-files']).splitlines() |
| - file_list.extend([os.path.join(self.checkout_path, f) for f in files]) |
| + self._FetchAndReset(revision, file_list, options) |
| return |
| + if not self._IsValidGitRepo(options): |
| + # .git directory is hosed for some reason, set it back up. |
| + print('_____ %s/.git is corrupted, rebuilding' % self.relpath) |
| + self._Run(['init'], options) |
| + self._Run(['remote', 'set-url', 'origin', url], options) |
| + |
| + if not self._HasHead(): |
| + # Previous checkout was aborted before branches could be created in repo, |
| + # so we need to reconstruct them here. |
| + self._Run(['pull', 'origin', 'master'], options) |
|
M-A Ruel
2013/06/11 19:01:36
Why pull when you're about to fetch right after?
Mike Stip (use stip instead)
2013/06/11 20:38:54
Pull sets up the remote tracking branches (includi
M-A Ruel
2013/06/11 22:43:50
ORLY? Wow.
|
| + self._FetchAndReset(revision, file_list, options) |
| + |
| cur_branch = self._GetCurrentBranch() |
| # Cases: |
| @@ -801,6 +816,22 @@ class GitWrapper(SCMWrapper): |
| # whitespace between projects when syncing. |
| print('') |
| + def _IsValidGitRepo(self, options): |
| + """Check if git status works in the current repository.""" |
|
M-A Ruel
2013/06/11 19:01:36
"""Returns if the directory is a valid git reposit
Mike Stip (use stip instead)
2013/06/11 20:38:54
Done.
|
| + try: |
| + self._Run(['status'], options) |
| + return True |
| + except subprocess2.CalledProcessError: |
| + return False |
| + |
| + def _HasHead(self): |
| + """Check if rev-parse HEAD works in the current repository.""" |
|
M-A Ruel
2013/06/11 19:01:36
"""Returns True if any commit is checked out.
Thi
|
| + try: |
| + self._GetCurrentBranch() |
| + return True |
| + except subprocess2.CalledProcessError: |
| + return False |
| + |
| @staticmethod |
| def _CheckMinVersion(min_version): |
| (ok, current_version) = scm.GIT.AssertVersion(min_version) |