diff options
| author | Conley Owens <cco3@android.com> | 2012-11-15 17:33:11 -0800 |
|---|---|---|
| committer | Conley Owens <cco3@android.com> | 2012-11-15 18:50:11 -0800 |
| commit | 75ee0570da09abb1d2bbefe0d25f0560727e6b71 (patch) | |
| tree | c62ab4990212282d9c18c694ec21830ad33481f2 | |
| parent | 88b86728a4451b97a2c6dcae2feb98014c077793 (diff) | |
| download | git-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.py | 4 | ||||
| -rwxr-xr-x | main.py | 5 | ||||
| -rw-r--r-- | project.py | 6 |
3 files changed, 14 insertions, 1 deletions
| @@ -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 | ||
| 24 | class NoManifestException(Exception): | ||
| 25 | """The required manifest does not exist. | ||
| 26 | """ | ||
| 27 | |||
| 24 | class EditorError(Exception): | 28 | class EditorError(Exception): |
| 25 | """Unspecified error from the user's text editor. | 29 | """Unspecified error from the user's text editor. |
| 26 | """ | 30 | """ |
| @@ -42,6 +42,7 @@ from editor import Editor | |||
| 42 | from error import DownloadError | 42 | from error import DownloadError |
| 43 | from error import ManifestInvalidRevisionError | 43 | from error import ManifestInvalidRevisionError |
| 44 | from error import ManifestParseError | 44 | from error import ManifestParseError |
| 45 | from error import NoManifestException | ||
| 45 | from error import NoSuchProjectError | 46 | from error import NoSuchProjectError |
| 46 | from error import RepoChangedException | 47 | from error import RepoChangedException |
| 47 | from manifest_xml import XmlManifest | 48 | from 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) |
| @@ -30,6 +30,7 @@ from git_command import GitCommand, git_require | |||
| 30 | from git_config import GitConfig, IsId, GetSchemeFromUrl, ID_RE | 30 | from git_config import GitConfig, IsId, GetSchemeFromUrl, ID_RE |
| 31 | from error import GitError, HookError, UploadError | 31 | from error import GitError, HookError, UploadError |
| 32 | from error import ManifestInvalidRevisionError | 32 | from error import ManifestInvalidRevisionError |
| 33 | from error import NoManifestException | ||
| 33 | from trace import IsTrace, Trace | 34 | from trace import IsTrace, Trace |
| 34 | 35 | ||
| 35 | from git_refs import GitRefs, HEAD, R_HEADS, R_TAGS, R_PUB, R_M | 36 | from 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: |
