fix usage without vcs repo

This commit is contained in:
Manuel Barkhau 2018-12-21 19:22:10 +01:00
parent 481a6625ae
commit 658ef57478

View file

@ -34,6 +34,7 @@ VCS_SUBCOMMANDS_BY_NAME = {
'commit' : "git commit --file {path}", 'commit' : "git commit --file {path}",
'tag' : "git tag --annotate {tag} --message {tag}", 'tag' : "git tag --annotate {tag} --message {tag}",
'push_tag' : "git push origin {tag}", 'push_tag' : "git push origin {tag}",
'show_remotes': "git config --get remote.origin.url",
}, },
'hg': { 'hg': {
'is_usable' : "hg root", 'is_usable' : "hg root",
@ -44,6 +45,7 @@ VCS_SUBCOMMANDS_BY_NAME = {
'commit' : "hg commit --logfile", 'commit' : "hg commit --logfile",
'tag' : "hg tag {tag} --message {tag}", 'tag' : "hg tag {tag} --message {tag}",
'push_tag' : "hg push {tag}", 'push_tag' : "hg push {tag}",
'show_remotes': "hg paths",
}, },
} }
@ -71,6 +73,9 @@ class VCS:
@property @property
def is_usable(self) -> bool: def is_usable(self) -> bool:
"""Detect availability of subcommand.""" """Detect availability of subcommand."""
if not os.path.exists(f".{self.name}"):
return False
cmd = self.subcommands['is_usable'].split() cmd = self.subcommands['is_usable'].split()
try: try:
@ -82,8 +87,19 @@ class VCS:
return False return False
raise raise
@property
def has_remote(self) -> bool:
try:
output = self('show_remotes')
if output.strip() == "":
return False
return True
except Exception:
return False
def fetch(self) -> None: def fetch(self) -> None:
"""Fetch updates from remote origin.""" """Fetch updates from remote origin."""
if self.has_remote:
self('fetch') self('fetch')
def status(self) -> typ.List[str]: def status(self) -> typ.List[str]:
@ -130,6 +146,7 @@ class VCS:
def push(self, tag_name: str) -> None: def push(self, tag_name: str) -> None:
"""Push changes to origin.""" """Push changes to origin."""
if self.has_remote:
self('push_tag', tag=tag_name) self('push_tag', tag=tag_name)
def __repr__(self) -> str: def __repr__(self) -> str: