Consider the following URL: http://github.com/orgname/reponame/blob/foo/bar/filename.txt
There are two possibilities for what this means:
- this references the filepath bar/filename.txt on a branch foo
- this references the filepath filename.txt on a branch foo/bar
Git itself prevents this ambiguity from occurring within a given repo (e.g. if you have a branch named foo/bar you cannot create a new branch named foo, and vice-versa) but disambiguating the URL path above requires knowledge of the github repository contents.
What I would like is an API query that given a path, such as orgname/reponame/blob/XXX/YYY/ZZZ/filename.txt, will return the name of the branch within the repo that it refers to (here, either XXX or XXX/YYY or XXX/YYY/ZZZ or 404 Not Found). Currently, it seems the only options for this via the V3 REST API are:
List all branches, with a potentially very large number of paginated results for repos with many branches
Query for the contents of all possible branch names, which might hit rate limits in the case of a deeply-nested path where the branch does not exist.
Both have the potential to be problematic in corner cases. Is there a better option?