def get_context_data(self, **kwargs): context = super(CommitDetailView, self).get_context_data(**kwargs) commit_sha = kwargs.get('commit') if not commit_sha: raise Http404("No commit specified.") commit = repository.commit(commit_sha) if not commit: raise Http404("A commit with sha "+commit_sha+" doesn't exists.") context['commit'] = commit context['all_branches'] = repository.branches() return context
def _get_rev(branch_name=None, commit_sha=None, default_branch_name='master'): if not local_repo().branches: raise Http404("There are no branches. The repository might be empty or the repository patrh isn't configured correctly.") if branch_name and commit_sha: raise SuspiciousOperation("A branch and a commit can't be specified at the same time.") # bad request if not (branch_name or commit_sha): if default_branch_name is None: return None if default_branch_name in local_repo().branches: branch_name = default_branch_name else: branch_name = local_repo().branches[0].name if commit_sha: return (repository.commit(commit_sha), 'commit', commit_sha) if branch_name: return (local_repo().branches[branch_name].commit, 'branch', branch_name)