Skip to content

Commit

Permalink
improve remote uri and latest commit behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
tgbugs committed Nov 20, 2019
1 parent b5287d5 commit 4ff3365
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 9 additions & 3 deletions augpathlib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ def repo_relative_path(self):

def _remote_uri(self, prefix, infix=None, ref=None):
repo = self.repo
url_base = next(repo.remote().urls)
remote = repo.remote()
rnprefix = remote.name + '/'
url_base = next(remote.urls)
if url_base.startswith('git@'):
url_base = 'ssh://' + url_base

Expand All @@ -228,7 +230,8 @@ def _remote_uri(self, prefix, infix=None, ref=None):
if netloc == 'github.com':
if not ref or ref == 'HEAD':
ref = repo.active_branch.name
elif ref not in [r.name.replace(rnprefix, '') for r in repo.refs]:
elif (ref not in [r.name.replace(rnprefix, '') for r in repo.refs] and
ref not in [c.hexsha for c in repo.iter_commits(ref, max_count=1)]):
log.warning(f'unknown ref {ref}')

if infix is not None:
Expand All @@ -247,7 +250,10 @@ def remote_uri_machine(self, ref=None):

@property
def latest_commit(self):
return next(self.repo.iter_commits(paths=self.as_posix(), max_count=1))
try:
return next(self.repo.iter_commits(paths=self.as_posix(), max_count=1))
except StopIteration as e:
raise exc.NoCommitsForFile(self) from e

# a variety of change detection

Expand Down
4 changes: 4 additions & 0 deletions augpathlib/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,7 @@ class RepoExistsError(AugPathlibError):
class NotInRepoError(AugPathlibError):
""" a repository does not exist in this
or any of the parents of this path """


class NoCommitsForFile(AugPathlibError):
""" could not find any commits for file """

0 comments on commit 4ff3365

Please sign in to comment.