diff --git a/gclient_scm.py b/gclient_scm.py index 12e1bf0aa..bcd9d11da 100644 --- a/gclient_scm.py +++ b/gclient_scm.py @@ -589,7 +589,14 @@ class GitWrapper(SCMWrapper): if options.verbose: print('Running git svn fetch. This might take a while.\n') scm.GIT.Capture(['svn', 'fetch'], cwd=self.checkout_path) - sha1 = scm.GIT.GetSha1ForSvnRev(cwd=self.checkout_path, rev=rev) + try: + sha1 = scm.GIT.GetSha1ForSvnRev(cwd=self.checkout_path, rev=rev) + except gclient_utils.Error, e: + sha1 = e.message + print('\nWarning: Could not find a git revision with accurate\n' + '.DEPS.git that maps to SVN revision %s. Sync-ing to\n' + 'the closest sane git revision, which is:\n' + ' %s\n' % (rev, e.message)) if not sha1: raise gclient_utils.Error( ( 'It appears that either your git-svn remote is incorrectly\n' diff --git a/scm.py b/scm.py index e99acc061..77a62994e 100644 --- a/scm.py +++ b/scm.py @@ -402,8 +402,23 @@ class GIT(object): if not GIT.IsGitSvn(cwd=cwd): return None try: - output = GIT.Capture(['svn', 'find-rev', 'r' + str(rev)], cwd=cwd) - return GIT.ParseGitSvnSha1(output) + git_svn_rev = GIT.Capture( + ['svn', 'find-rev', 'r' + str(rev)], cwd=cwd).rstrip() + if not git_svn_rev: + return None + output = GIT.Capture( + ['rev-list', '--ancestry-path', '--reverse', + '--grep', 'SVN changes up to revision [0-9]*', + '%s..refs/remotes/origin/master' % git_svn_rev], cwd=cwd) + if not output: + return None + sha1 = output.splitlines()[0] + if not sha1: + return None + output = GIT.Capture(['rev-list', '-n', '1', '%s^1' % sha1], cwd=cwd) + if git_svn_rev != output.rstrip(): + raise gclient_utils.Error(sha1) + return sha1 except subprocess2.CalledProcessError: return None