Просмотр исходного кода

Report better errors when a project revision is invalid

If a manifest specifies an invalid revision property, give the
user a better error message detaling the problem, instead of an
ugly Python traceback with a strange Git error message.

Bug: REPO-2
Signed-off-by: Shawn O. Pearce <sop@google.com>
Shawn O. Pearce 17 лет назад
Родитель
Сommit
559b846b17
3 измененных файлов с 15 добавлено и 0 удалено
  1. 4 0
      error.py
  2. 4 0
      main.py
  3. 7 0
      project.py

+ 4 - 0
error.py

@@ -17,6 +17,10 @@ class ManifestParseError(Exception):
   """Failed to parse the manifest file.
   """Failed to parse the manifest file.
   """
   """
 
 
+class ManifestInvalidRevisionError(Exception):
+  """The revision value in a project is incorrect.
+  """
+
 class EditorError(Exception):
 class EditorError(Exception):
   """Unspecified error from the user's text editor.
   """Unspecified error from the user's text editor.
   """
   """

+ 4 - 0
main.py

@@ -29,6 +29,7 @@ import sys
 
 
 from command import InteractiveCommand, PagedCommand
 from command import InteractiveCommand, PagedCommand
 from editor import Editor
 from editor import Editor
+from error import ManifestInvalidRevisionError
 from error import NoSuchProjectError
 from error import NoSuchProjectError
 from error import RepoChangedException
 from error import RepoChangedException
 from manifest import Manifest
 from manifest import Manifest
@@ -94,6 +95,9 @@ class _Repo(object):
     copts, cargs = cmd.OptionParser.parse_args(argv)
     copts, cargs = cmd.OptionParser.parse_args(argv)
     try:
     try:
       cmd.Execute(copts, cargs)
       cmd.Execute(copts, cargs)
+    except ManifestInvalidRevisionError, e:
+      print >>sys.stderr, 'error: %s' % str(e)
+      sys.exit(1)
     except NoSuchProjectError, e:
     except NoSuchProjectError, e:
       if e.name:
       if e.name:
         print >>sys.stderr, 'error: project %s not found' % e.name
         print >>sys.stderr, 'error: project %s not found' % e.name

+ 7 - 0
project.py

@@ -25,6 +25,7 @@ from color import Coloring
 from git_command import GitCommand
 from git_command import GitCommand
 from git_config import GitConfig, IsId
 from git_config import GitConfig, IsId
 from error import GitError, ImportError, UploadError
 from error import GitError, ImportError, UploadError
+from error import ManifestInvalidRevisionError
 from remote import Remote
 from remote import Remote
 
 
 HEAD    = 'HEAD'
 HEAD    = 'HEAD'
@@ -582,6 +583,12 @@ class Project(object):
 
 
     rem = self.GetRemote(self.remote.name)
     rem = self.GetRemote(self.remote.name)
     rev = rem.ToLocal(self.revision)
     rev = rem.ToLocal(self.revision)
+    try:
+      self.bare_git.rev_parse('--verify', '%s^0' % rev)
+    except GitError:
+      raise ManifestInvalidRevisionError(
+        'revision %s in %s not found' % (self.revision, self.name))
+
     branch = self.CurrentBranch
     branch = self.CurrentBranch
 
 
     if branch is None:
     if branch is None: