RefNames#fullName: Don't prepend "refs/heads/" for HEAD

In I5d9864d7, the need of 'correcting code' for branch refs was reduced
but a bug was introduced.

'refs/heads' would get prepended onto 'HEAD' since the string did not
start with 'refs/'. This resulted in an invalid URL when clicking the
gitweb link in the branches page.

Bug: Issue 4238
Change-Id: Ic27e1306bef04e225a2b349b180878ffec21b312
This commit is contained in:
Alexandre Philbert 2016-07-14 15:02:07 -04:00 committed by David Pursehouse
parent 1bf5784825
commit 597e198116
2 changed files with 5 additions and 1 deletions

View File

@ -17,6 +17,8 @@ package com.google.gerrit.reviewdb.client;
/** Constants and utilities for Gerrit-specific ref names. */
public class RefNames {
public static final String HEAD = "HEAD";
public static final String REFS = "refs/";
public static final String REFS_HEADS = "refs/heads/";
@ -60,7 +62,8 @@ public class RefNames {
public static final String EDIT_PREFIX = "edit-";
public static String fullName(String ref) {
return ref.startsWith(REFS) ? ref : REFS_HEADS + ref;
return (ref.startsWith(REFS) || ref.equals(HEAD)) ?
ref : REFS_HEADS + ref;
}
public static final String shortName(String ref) {

View File

@ -29,6 +29,7 @@ public class RefNamesTest {
assertThat(RefNames.fullName("refs/heads/master")).isEqualTo("refs/heads/master");
assertThat(RefNames.fullName("master")).isEqualTo("refs/heads/master");
assertThat(RefNames.fullName("refs/tags/v1.0")).isEqualTo("refs/tags/v1.0");
assertThat(RefNames.fullName("HEAD")).isEqualTo("HEAD");
}
@Test