diff --git a/dxr/plugins/omniglot.py b/dxr/plugins/omniglot.py index 72b7bca58..d4b705dcb 100644 --- a/dxr/plugins/omniglot.py +++ b/dxr/plugins/omniglot.py @@ -29,7 +29,7 @@ def items(): yield 'diff', "Diff", self.vcs.generate_diff(vcs_relative_path) yield 'raw', "Raw", self.vcs.generate_raw(vcs_relative_path) - if self.vcs: + if self.vcs and self.vcs.has_upstream(): vcs_relative_path = relpath(self.absolute_path(), self.vcs.get_root_dir()) yield (5, 'VCS Links', items()) diff --git a/dxr/vcs.py b/dxr/vcs.py index b1fc41edb..14b077ff1 100644 --- a/dxr/vcs.py +++ b/dxr/vcs.py @@ -59,6 +59,13 @@ def is_tracked(self, path): """Does the repository track this file?""" return NotImplemented + def has_upstream(self): + """Return true if this VCS has a usable upstream.""" + return NotImplemented + + # Note: the generate_* methods shouldn't be expected to return useful URLs + # unless this VCS has_upstream(). + def generate_log(self, path): """Construct URL to upstream view of log of file at path.""" return NotImplemented @@ -99,8 +106,17 @@ def __init__(self, root): self.previous_revisions = self.find_previous_revisions(client) self.upstream = self._construct_upstream_url() + def has_upstream(self): + return self.upstream != "" + def _construct_upstream_url(self): - upstream = urlparse.urlparse(self.invoke_vcs(['paths', 'default'], self.root).strip()) + with open(os.devnull, 'w') as devnull: + try: + upstream = urlparse.urlparse(self.invoke_vcs(['paths', 'default'], + self.root, stderr=devnull).strip()) + except subprocess.CalledProcessError: + # No default path, so no upstream + return "" recomb = list(upstream) if upstream.scheme == 'ssh': recomb[0] = 'http' @@ -168,6 +184,9 @@ def __init__(self, root): self.revision = self.invoke_vcs(['rev-parse', 'HEAD'], self.root).strip() self.upstream = self._construct_upstream_url() + def has_upstream(self): + return self.upstream != "" + def _construct_upstream_url(self): source_urls = self.invoke_vcs(['remote', '-v'], self.root).split('\n') for src_url in source_urls: @@ -185,8 +204,9 @@ def _construct_upstream_url(self): return repo warn("Your git remote is not supported yet. Please use a " "GitHub remote if you would like version control " - "naviagtion links to show.") + "navigation links to show.") break + return "" @classmethod def claim_vcs_source(cls, path, dirs, tree): @@ -230,6 +250,9 @@ def __init__(self, root, upstream): self.have = dict((x['path'][len(root) + 1:], x) for x in have) self.upstream = upstream + def has_upstream(self): + return self.upstream != "" + @classmethod def claim_vcs_source(cls, path, dirs, tree): if 'P4CONFIG' not in os.environ: