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