diff options
author | Shawn O. Pearce <sop@google.com> | 2009-03-03 17:47:06 -0800 |
---|---|---|
committer | Shawn O. Pearce <sop@google.com> | 2009-03-03 17:47:06 -0800 |
commit | c95583bf4f17b8467f815b6391ffc6c7add08804 (patch) | |
tree | c69bf8a061279b79326fb00f2197efcd8726864c | |
parent | 6a5644d392069b67f17c8ce6cb10f07cce71cc1c (diff) | |
download | git-repo-c95583bf4f17b8467f815b6391ffc6c7add08804.tar.gz |
Don't permit users to run repo status in a mirror client
If a client was created with "repo init --mirror" then there are
no working directories present, and no files checked out. Using
a command like "repo status" in this context makes no sense, and
actually throws back a Pytyon traceback at the console when the
underlying commands fail out.
We now tag commands with the MirrorSafeCommand type if they are
able to be executed within a mirror directory safely. Using a
command in a mirror which lacks this base class results in a
useful error letting you know the command isn't supported.
Bug: REPO-14
Signed-off-by: Shawn O. Pearce <sop@google.com>
-rw-r--r-- | command.py | 5 | ||||
-rwxr-xr-x | main.py | 10 | ||||
-rw-r--r-- | subcmds/help.py | 4 | ||||
-rw-r--r-- | subcmds/init.py | 4 | ||||
-rw-r--r-- | subcmds/sync.py | 4 | ||||
-rw-r--r-- | subcmds/version.py | 4 |
6 files changed, 22 insertions, 9 deletions
@@ -114,3 +114,8 @@ class PagedCommand(Command): | |||
114 | """Command which defaults to output in a pager, as its | 114 | """Command which defaults to output in a pager, as its |
115 | display tends to be larger than one screen full. | 115 | display tends to be larger than one screen full. |
116 | """ | 116 | """ |
117 | |||
118 | class MirrorSafeCommand(object): | ||
119 | """Command permits itself to run within a mirror, | ||
120 | and does not require a working directory. | ||
121 | """ | ||
@@ -27,7 +27,9 @@ import os | |||
27 | import re | 27 | import re |
28 | import sys | 28 | import sys |
29 | 29 | ||
30 | from command import InteractiveCommand, PagedCommand | 30 | from command import InteractiveCommand |
31 | from command import MirrorSafeCommand | ||
32 | from command import PagedCommand | ||
31 | from editor import Editor | 33 | from editor import Editor |
32 | from error import ManifestInvalidRevisionError | 34 | from error import ManifestInvalidRevisionError |
33 | from error import NoSuchProjectError | 35 | from error import NoSuchProjectError |
@@ -91,6 +93,12 @@ class _Repo(object): | |||
91 | cmd.manifest = Manifest(cmd.repodir) | 93 | cmd.manifest = Manifest(cmd.repodir) |
92 | Editor.globalConfig = cmd.manifest.globalConfig | 94 | Editor.globalConfig = cmd.manifest.globalConfig |
93 | 95 | ||
96 | if not isinstance(cmd, MirrorSafeCommand) and cmd.manifest.IsMirror: | ||
97 | print >>sys.stderr, \ | ||
98 | "fatal: '%s' requires a working directory"\ | ||
99 | % name | ||
100 | sys.exit(1) | ||
101 | |||
94 | if not gopts.no_pager and not isinstance(cmd, InteractiveCommand): | 102 | if not gopts.no_pager and not isinstance(cmd, InteractiveCommand): |
95 | config = cmd.manifest.globalConfig | 103 | config = cmd.manifest.globalConfig |
96 | if gopts.pager: | 104 | if gopts.pager: |
diff --git a/subcmds/help.py b/subcmds/help.py index 6e0238a0..a2814e11 100644 --- a/subcmds/help.py +++ b/subcmds/help.py | |||
@@ -17,9 +17,9 @@ import sys | |||
17 | from formatter import AbstractFormatter, DumbWriter | 17 | from formatter import AbstractFormatter, DumbWriter |
18 | 18 | ||
19 | from color import Coloring | 19 | from color import Coloring |
20 | from command import PagedCommand | 20 | from command import PagedCommand, MirrorSafeCommand |
21 | 21 | ||
22 | class Help(PagedCommand): | 22 | class Help(PagedCommand, MirrorSafeCommand): |
23 | common = False | 23 | common = False |
24 | helpSummary = "Display detailed help on a command" | 24 | helpSummary = "Display detailed help on a command" |
25 | helpUsage = """ | 25 | helpUsage = """ |
diff --git a/subcmds/init.py b/subcmds/init.py index ad28a611..d1fb4316 100644 --- a/subcmds/init.py +++ b/subcmds/init.py | |||
@@ -17,12 +17,12 @@ import os | |||
17 | import sys | 17 | import sys |
18 | 18 | ||
19 | from color import Coloring | 19 | from color import Coloring |
20 | from command import InteractiveCommand | 20 | from command import InteractiveCommand, MirrorSafeCommand |
21 | from error import ManifestParseError | 21 | from error import ManifestParseError |
22 | from remote import Remote | 22 | from remote import Remote |
23 | from git_command import git, MIN_GIT_VERSION | 23 | from git_command import git, MIN_GIT_VERSION |
24 | 24 | ||
25 | class Init(InteractiveCommand): | 25 | class Init(InteractiveCommand, MirrorSafeCommand): |
26 | common = True | 26 | common = True |
27 | helpSummary = "Initialize repo in the current directory" | 27 | helpSummary = "Initialize repo in the current directory" |
28 | helpUsage = """ | 28 | helpUsage = """ |
diff --git a/subcmds/sync.py b/subcmds/sync.py index 8050e515..fff1281a 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py | |||
@@ -19,11 +19,11 @@ import subprocess | |||
19 | import sys | 19 | import sys |
20 | 20 | ||
21 | from git_command import GIT | 21 | from git_command import GIT |
22 | from command import Command | 22 | from command import Command, MirrorSafeCommand |
23 | from error import RepoChangedException, GitError | 23 | from error import RepoChangedException, GitError |
24 | from project import R_HEADS | 24 | from project import R_HEADS |
25 | 25 | ||
26 | class Sync(Command): | 26 | class Sync(Command, MirrorSafeCommand): |
27 | common = True | 27 | common = True |
28 | helpSummary = "Update working tree to the latest revision" | 28 | helpSummary = "Update working tree to the latest revision" |
29 | helpUsage = """ | 29 | helpUsage = """ |
diff --git a/subcmds/version.py b/subcmds/version.py index 4f19a0ca..83e77d0b 100644 --- a/subcmds/version.py +++ b/subcmds/version.py | |||
@@ -14,11 +14,11 @@ | |||
14 | # limitations under the License. | 14 | # limitations under the License. |
15 | 15 | ||
16 | import sys | 16 | import sys |
17 | from command import Command | 17 | from command import Command, MirrorSafeCommand |
18 | from git_command import git | 18 | from git_command import git |
19 | from project import HEAD | 19 | from project import HEAD |
20 | 20 | ||
21 | class Version(Command): | 21 | class Version(Command, MirrorSafeCommand): |
22 | common = False | 22 | common = False |
23 | helpSummary = "Display the version of repo" | 23 | helpSummary = "Display the version of repo" |
24 | helpUsage = """ | 24 | helpUsage = """ |