summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorConley Owens <cco3@android.com>2012-11-15 17:33:11 -0800
committerConley Owens <cco3@android.com>2012-11-15 18:50:11 -0800
commit75ee0570da09abb1d2bbefe0d25f0560727e6b71 (patch)
treec62ab4990212282d9c18c694ec21830ad33481f2
parent88b86728a4451b97a2c6dcae2feb98014c077793 (diff)
downloadgit-repo-75ee0570da09abb1d2bbefe0d25f0560727e6b71.tar.gz
Raise a NoManifestException when the manifest DNE
When a command (eg, `repo forall`) expects the manifest project to exist, but there is no manifest, an IOException gets raised. This change defines a new Exception type to be raised in these cases and raises it when project.py fails to read the manifest. Change-Id: Iac576c293a37f7d8f60cd4f6aa95b2c97f9e7957
-rw-r--r--error.py4
-rwxr-xr-xmain.py5
-rw-r--r--project.py6
3 files changed, 14 insertions, 1 deletions
diff --git a/error.py b/error.py
index 21482486..7e52b016 100644
--- a/error.py
+++ b/error.py
@@ -21,6 +21,10 @@ class ManifestInvalidRevisionError(Exception):
21 """The revision value in a project is incorrect. 21 """The revision value in a project is incorrect.
22 """ 22 """
23 23
24class NoManifestException(Exception):
25 """The required manifest does not exist.
26 """
27
24class EditorError(Exception): 28class EditorError(Exception):
25 """Unspecified error from the user's text editor. 29 """Unspecified error from the user's text editor.
26 """ 30 """
diff --git a/main.py b/main.py
index 95944546..83967f77 100755
--- a/main.py
+++ b/main.py
@@ -42,6 +42,7 @@ from editor import Editor
42from error import DownloadError 42from error import DownloadError
43from error import ManifestInvalidRevisionError 43from error import ManifestInvalidRevisionError
44from error import ManifestParseError 44from error import ManifestParseError
45from error import NoManifestException
45from error import NoSuchProjectError 46from error import NoSuchProjectError
46from error import RepoChangedException 47from error import RepoChangedException
47from manifest_xml import XmlManifest 48from manifest_xml import XmlManifest
@@ -140,6 +141,10 @@ class _Repo(object):
140 except ManifestInvalidRevisionError as e: 141 except ManifestInvalidRevisionError as e:
141 print('error: %s' % str(e), file=sys.stderr) 142 print('error: %s' % str(e), file=sys.stderr)
142 result = 1 143 result = 1
144 except NoManifestException as e:
145 print('error: manifest required for this command -- please run init',
146 file=sys.stderr)
147 result = 1
143 except NoSuchProjectError as e: 148 except NoSuchProjectError as e:
144 if e.name: 149 if e.name:
145 print('error: project %s not found' % e.name, file=sys.stderr) 150 print('error: project %s not found' % e.name, file=sys.stderr)
diff --git a/project.py b/project.py
index 75c5e5e8..08b27710 100644
--- a/project.py
+++ b/project.py
@@ -30,6 +30,7 @@ from git_command import GitCommand, git_require
30from git_config import GitConfig, IsId, GetSchemeFromUrl, ID_RE 30from git_config import GitConfig, IsId, GetSchemeFromUrl, ID_RE
31from error import GitError, HookError, UploadError 31from error import GitError, HookError, UploadError
32from error import ManifestInvalidRevisionError 32from error import ManifestInvalidRevisionError
33from error import NoManifestException
33from trace import IsTrace, Trace 34from trace import IsTrace, Trace
34 35
35from git_refs import GitRefs, HEAD, R_HEADS, R_TAGS, R_PUB, R_M 36from git_refs import GitRefs, HEAD, R_HEADS, R_TAGS, R_PUB, R_M
@@ -1894,7 +1895,10 @@ class Project(object):
1894 path = os.path.join(self._project.gitdir, HEAD) 1895 path = os.path.join(self._project.gitdir, HEAD)
1895 else: 1896 else:
1896 path = os.path.join(self._project.worktree, '.git', HEAD) 1897 path = os.path.join(self._project.worktree, '.git', HEAD)
1897 fd = open(path, 'rb') 1898 try:
1899 fd = open(path, 'rb')
1900 except IOError:
1901 raise NoManifestException(path)
1898 try: 1902 try:
1899 line = fd.read() 1903 line = fd.read()
1900 finally: 1904 finally: