Skip to content

support some convenient warpper functions?Β #44

@Roger-luo

Description

@Roger-luo

I'm wondering if people are open to have some convenient functions in this package? e.g

function remote_repo_url(repo::String=pwd())
    return cd(repo) do
        readchomp(`$(git()) config --get remote.origin.url`)
    end
end

function remote_exists(repo::String=pwd())
    url = remote_repo_url(repo)
    p = cd(repo) do
        redirect_stdio(stderr=devnull, stdout=devnull) do
            run(ignorestatus(`$(git()) ls-remote --exit-code $url`))
        end
    end
    return p.exitcode == 0
end

function default_branch(repo::String=pwd(); remote::String="origin")
    remote_exists(repo) || error("cannot determine default branch, remote does not exist")

    url = remote_repo_url(repo)
    return cd(repo) do
        s = redirect_stdio(stderr=devnull) do
            readchomp(ignorestatus(`$(git()) ls-remote --symref $url HEAD`))
        end
        m = match(r"'s|^ref: refs/heads/(\S+)\s+HEAD|\1|p'", s)
        m === nothing && error("invalid remote response: $s")
        return m[1]
    end
end

I think it would be nice to have some convenient Julian functions like these in this package so that we can just use them as Git.default_branch etc. instead of searching how to do X then do the interpolations manually.

The reason why I don't like them in a separate package is that I find this package is already wrapping Git_jll and the module name Git is shorter than a separate one such as GitHelper, what do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions