Open default GH branch
PavelSafronov opened this issue · 3 comments
git-peek seems to open the master branch, but if a repo has a non-master default branch this ends up opening the "wrong" branch, and it's not immediately obvious how to open the "correct" branch.
Take this repo as an example: https://github.com/jdiwnab/OrbitSim
- The default branch is "gh-pages".
- Running
git-peek https://github.com/jdiwnab/OrbitSim
results in the editor being opened to a very sparse repo, since git-peek is opening https://github.com/jdiwnab/OrbitSim/tree/master. - This experience doesn't match what we see when landing on https://github.com/jdiwnab/OrbitSim , and made me wonder if git-peek was still in the process of cloning the repo or if there was a bug.
The way to open the default branch is to run git-peek https://github.com/jdiwnab/OrbitSim/tree/gh-pages
. But this is a url that needs to be constructed manually, as GH doesn't seem to expose it in the UI: the url for the gh-pages
branch is just https://github.com/jdiwnab/OrbitSim
It would be nice if git-peek accepted a "branch" parameter or opened the default branch of the repo.
Currently, the logic is:
- If no branch is specified in the url (https://github.com/jdiwnab/OrbitSim/tree/gh-pages works but https://github.com/jdiwnab/OrbitSim) doesn't, assume
master
. If request tomaster
fails, assumemain
is the default branch. - If coming from search or a pull request, rely on
default_branch
returned by GitHub API
I can add a --branch
flag though.
The reason for this heuristic is to keep it fast. Sending one additional request before downloading the tarball would slow it down, and most repositories don't use the default branch feature
Added in v1.1.35
Also: added a -d
flag so you can just do: git peek jdiwnab/OrbitSim -d
and it will figure out what the default_branch
is automatically instead of guessing