RFR: 92: GitRepository::currentBranch fails when on a detached HEAD
Erik Helin
ehelin at openjdk.java.net
Mon Dec 2 09:00:43 UTC 2019
On Fri, 29 Nov 2019 11:30:04 GMT, Robin Westberg <rwestberg at openjdk.org> wrote:
> On Fri, 29 Nov 2019 11:27:22 GMT, Robin Westberg <rwestberg at openjdk.org> wrote:
>
>> On Thu, 28 Nov 2019 15:10:50 GMT, Erik Helin <ehelin at openjdk.org> wrote:
>>
>>> Hi all,
>>>
>>> please review this pull request that makes `git webrev` work when the repository is in a "detached HEAD" state (i.e. there is no active branch). The main part of the change is making `ReadOnlyRepository::currentBranch` return `Optional<Branch>` instead of `Branch`.
>>>
>>> Thanks,
>>> Erik
>>>
>>> ## Testing
>>> - [x] `make test` on Linux x64
>>> - [x] Manually running `git webrev` on a repository with a detached HEAD
>>>
>>> ----------------
>>>
>>> Commits:
>>> - 3dc4fea9: 92: GitRepository::currentBranch fails when on a detached HEAD
>>>
>>> Changes: https://git.openjdk.java.net/skara/pull/278/files
>>> Webrev: https://webrevs.openjdk.java.net/skara/278/webrev.00
>>> Issue: https://bugs.openjdk.java.net/browse/SKARA-92
>>> Stats: 40 lines in 8 files changed: 16 ins; 2 del; 22 mod
>>> Patch: https://git.openjdk.java.net/skara/pull/278.diff
>>> Fetch: git fetch https://git.openjdk.java.net/skara pull/278/head:pull/278
>>
>> vcs/src/main/java/org/openjdk/skara/vcs/hg/HgRepository.java line 603:
>>
>>> 602: var current = currentBranch().orElseThrow(() ->
>>> 603: new IOException("No current branch to rebase upon")
>>> 604: );
>>
>> Should this mention the detached head then as well perhaps?
>
> Scratch that, guess this is hg :)
Yes, this is in `HgRepository`, so a "detached HEAD" is not possible. I actually don't think `currentBranch` _can_ fail for `HgRepository`, since the current branch is part of the commit metadata in Mercurial (not just a ref as in git). I added a message anyhow to distinguish this scenario.
PR: https://git.openjdk.java.net/skara/pull/278
More information about the skara-dev
mailing list