Prechádzať zdrojové kódy

Merge "Raise a NoManifestException when the manifest DNE"

Conley Owens 13 rokov pred
rodič
commit
a67df63ef1
3 zmenil súbory, kde vykonal 14 pridanie a 1 odobranie
  1. 4 0
      error.py
  2. 5 0
      main.py
  3. 5 1
      project.py

+ 4 - 0
error.py

@@ -21,6 +21,10 @@ class ManifestInvalidRevisionError(Exception):
   """The revision value in a project is incorrect.
   """
 
+class NoManifestException(Exception):
+  """The required manifest does not exist.
+  """
+
 class EditorError(Exception):
   """Unspecified error from the user's text editor.
   """

+ 5 - 0
main.py

@@ -42,6 +42,7 @@ from editor import Editor
 from error import DownloadError
 from error import ManifestInvalidRevisionError
 from error import ManifestParseError
+from error import NoManifestException
 from error import NoSuchProjectError
 from error import RepoChangedException
 from manifest_xml import XmlManifest
@@ -140,6 +141,10 @@ class _Repo(object):
     except ManifestInvalidRevisionError as e:
       print('error: %s' % str(e), file=sys.stderr)
       result = 1
+    except NoManifestException as e:
+      print('error: manifest required for this command -- please run init',
+            file=sys.stderr)
+      result = 1
     except NoSuchProjectError as e:
       if e.name:
         print('error: project %s not found' % e.name, file=sys.stderr)

+ 5 - 1
project.py

@@ -30,6 +30,7 @@ from git_command import GitCommand, git_require
 from git_config import GitConfig, IsId, GetSchemeFromUrl, ID_RE
 from error import GitError, HookError, UploadError
 from error import ManifestInvalidRevisionError
+from error import NoManifestException
 from trace import IsTrace, Trace
 
 from git_refs import GitRefs, HEAD, R_HEADS, R_TAGS, R_PUB, R_M
@@ -1894,7 +1895,10 @@ class Project(object):
         path = os.path.join(self._project.gitdir, HEAD)
       else:
         path = os.path.join(self._project.worktree, '.git', HEAD)
-      fd = open(path, 'rb')
+      try:
+        fd = open(path, 'rb')
+      except IOError:
+        raise NoManifestException(path)
       try:
         line = fd.read()
       finally: