示例#1
0
def repo_branch_detail(request, repo_name, branch_name, username=None):
    try:
        repo = git.get_repo(repo_name, username)
    except KeyError:
        raise Http404

    ref_name = "refs/heads/" + branch_name
    try:
        commit_id = repo.ref(ref_name)
    except KeyError:
        raise Http404

    try:
        commit = repo.commit(commit_id)
    except (KeyError, NotCommitError):
        raise Http404

    return TemplateResponse(
        request,
        "gitaxis/repo_branch_detail.html",
        context={
            "username": username,
            "repo_name": repo_name,
            "repo": repo,
            "branch_name": branch_name,
            "commit_id": commit_id,
            "commit": commit,
        },
    )
示例#2
0
def repo_detail(request, repo_name, username=None):
    try:
        repo = git.get_repo(repo_name, username)
    except KeyError:
        raise Http404
    head_ref = repo.refs.read_ref('HEAD')
    if head_ref is None:
        head_ref = "ref: refs/heads/master"

    target_url = None

    if head_ref.startswith("ref: "):
        if head_ref[5:16] == "refs/heads/":
            branch_name = head_ref[16:]
            target_url = reverse_url(
                "repo_branch_detail",
                kwargs=url_kwargs(
                    repo_name=repo_name,
                    username=username,
                    branch_name=branch_name,
                ),
            )
    else:
        target_url = reverse_url(
            "repo_commit_detail",
            kwargs=url_kwargs(
                repo_name=repo_name,
                username=username,
                commit_id=head_ref,
            ),
        )

    if target_url is None:
        return TemplateResponse(
            request,
            "gitaxis/emptyrepo.html",
            context={
                "username": username,
                "repo_name": repo_name,
                "repo": repo,
            },
        )

    return redirect(target_url)