mirror of
https://gerrit.googlesource.com/git-repo
synced 2024-12-21 07:16:21 +00:00
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>
This commit is contained in:
parent
6a5644d392
commit
c95583bf4f
@ -114,3 +114,8 @@ class PagedCommand(Command):
|
|||||||
"""Command which defaults to output in a pager, as its
|
"""Command which defaults to output in a pager, as its
|
||||||
display tends to be larger than one screen full.
|
display tends to be larger than one screen full.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
class MirrorSafeCommand(object):
|
||||||
|
"""Command permits itself to run within a mirror,
|
||||||
|
and does not require a working directory.
|
||||||
|
"""
|
||||||
|
10
main.py
10
main.py
@ -27,7 +27,9 @@ import os
|
|||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from command import InteractiveCommand, PagedCommand
|
from command import InteractiveCommand
|
||||||
|
from command import MirrorSafeCommand
|
||||||
|
from command import PagedCommand
|
||||||
from editor import Editor
|
from editor import Editor
|
||||||
from error import ManifestInvalidRevisionError
|
from error import ManifestInvalidRevisionError
|
||||||
from error import NoSuchProjectError
|
from error import NoSuchProjectError
|
||||||
@ -91,6 +93,12 @@ class _Repo(object):
|
|||||||
cmd.manifest = Manifest(cmd.repodir)
|
cmd.manifest = Manifest(cmd.repodir)
|
||||||
Editor.globalConfig = cmd.manifest.globalConfig
|
Editor.globalConfig = cmd.manifest.globalConfig
|
||||||
|
|
||||||
|
if not isinstance(cmd, MirrorSafeCommand) and cmd.manifest.IsMirror:
|
||||||
|
print >>sys.stderr, \
|
||||||
|
"fatal: '%s' requires a working directory"\
|
||||||
|
% name
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
if not gopts.no_pager and not isinstance(cmd, InteractiveCommand):
|
if not gopts.no_pager and not isinstance(cmd, InteractiveCommand):
|
||||||
config = cmd.manifest.globalConfig
|
config = cmd.manifest.globalConfig
|
||||||
if gopts.pager:
|
if gopts.pager:
|
||||||
|
@ -17,9 +17,9 @@ import sys
|
|||||||
from formatter import AbstractFormatter, DumbWriter
|
from formatter import AbstractFormatter, DumbWriter
|
||||||
|
|
||||||
from color import Coloring
|
from color import Coloring
|
||||||
from command import PagedCommand
|
from command import PagedCommand, MirrorSafeCommand
|
||||||
|
|
||||||
class Help(PagedCommand):
|
class Help(PagedCommand, MirrorSafeCommand):
|
||||||
common = False
|
common = False
|
||||||
helpSummary = "Display detailed help on a command"
|
helpSummary = "Display detailed help on a command"
|
||||||
helpUsage = """
|
helpUsage = """
|
||||||
|
@ -17,12 +17,12 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from color import Coloring
|
from color import Coloring
|
||||||
from command import InteractiveCommand
|
from command import InteractiveCommand, MirrorSafeCommand
|
||||||
from error import ManifestParseError
|
from error import ManifestParseError
|
||||||
from remote import Remote
|
from remote import Remote
|
||||||
from git_command import git, MIN_GIT_VERSION
|
from git_command import git, MIN_GIT_VERSION
|
||||||
|
|
||||||
class Init(InteractiveCommand):
|
class Init(InteractiveCommand, MirrorSafeCommand):
|
||||||
common = True
|
common = True
|
||||||
helpSummary = "Initialize repo in the current directory"
|
helpSummary = "Initialize repo in the current directory"
|
||||||
helpUsage = """
|
helpUsage = """
|
||||||
|
@ -19,11 +19,11 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from git_command import GIT
|
from git_command import GIT
|
||||||
from command import Command
|
from command import Command, MirrorSafeCommand
|
||||||
from error import RepoChangedException, GitError
|
from error import RepoChangedException, GitError
|
||||||
from project import R_HEADS
|
from project import R_HEADS
|
||||||
|
|
||||||
class Sync(Command):
|
class Sync(Command, MirrorSafeCommand):
|
||||||
common = True
|
common = True
|
||||||
helpSummary = "Update working tree to the latest revision"
|
helpSummary = "Update working tree to the latest revision"
|
||||||
helpUsage = """
|
helpUsage = """
|
||||||
|
@ -14,11 +14,11 @@
|
|||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from command import Command
|
from command import Command, MirrorSafeCommand
|
||||||
from git_command import git
|
from git_command import git
|
||||||
from project import HEAD
|
from project import HEAD
|
||||||
|
|
||||||
class Version(Command):
|
class Version(Command, MirrorSafeCommand):
|
||||||
common = False
|
common = False
|
||||||
helpSummary = "Display the version of repo"
|
helpSummary = "Display the version of repo"
|
||||||
helpUsage = """
|
helpUsage = """
|
||||||
|
Loading…
Reference in New Issue
Block a user