diff --git a/java/com/google/gerrit/server/project/RefUtil.java b/java/com/google/gerrit/server/project/RefUtil.java index 9f1fa4a21c..4e08137a1c 100644 --- a/java/com/google/gerrit/server/project/RefUtil.java +++ b/java/com/google/gerrit/server/project/RefUtil.java @@ -19,6 +19,7 @@ import static org.eclipse.jgit.lib.Constants.R_TAGS; import com.google.common.collect.Iterables; import com.google.common.flogger.FluentLogger; +import com.google.gerrit.common.Nullable; import com.google.gerrit.extensions.restapi.BadRequestException; import com.google.gerrit.reviewdb.client.Project; import com.google.gerrit.reviewdb.client.RefNames; @@ -46,16 +47,15 @@ public class RefUtil { try { ObjectId revid = repo.resolve(baseRevision); if (revid == null) { - throw new InvalidRevisionException(); + throw new InvalidRevisionException(baseRevision); } return revid; } catch (IOException err) { logger.atSevere().withCause(err).log( "Cannot resolve \"%s\" in project \"%s\"", baseRevision, projectName.get()); - throw new InvalidRevisionException(); + throw new InvalidRevisionException(baseRevision); } catch (RevisionSyntaxException err) { - logger.atSevere().withCause(err).log("Invalid revision syntax \"%s\"", baseRevision); - throw new InvalidRevisionException(); + throw new InvalidRevisionException(baseRevision); } } @@ -66,7 +66,7 @@ public class RefUtil { try { rw.markStart(rw.parseCommit(revid)); } catch (IncorrectObjectTypeException err) { - throw new InvalidRevisionException(); + throw new InvalidRevisionException(revid.name()); } RefDatabase refDb = repo.getRefDatabase(); Iterable refs = @@ -86,11 +86,11 @@ public class RefUtil { rw.checkConnectivity(); return rw; } catch (IncorrectObjectTypeException | MissingObjectException err) { - throw new InvalidRevisionException(); + throw new InvalidRevisionException(revid.name()); } catch (IOException err) { logger.atSevere().withCause(err).log( "Repository \"%s\" may be corrupt; suggest running git fsck", repo.getDirectory()); - throw new InvalidRevisionException(); + throw new InvalidRevisionException(revid.name()); } } @@ -125,8 +125,8 @@ public class RefUtil { public static final String MESSAGE = "Invalid Revision"; - InvalidRevisionException() { - super(MESSAGE); + InvalidRevisionException(@Nullable String invalidRevision) { + super(MESSAGE + ": " + invalidRevision); } } } diff --git a/java/com/google/gerrit/server/restapi/project/CreateBranch.java b/java/com/google/gerrit/server/restapi/project/CreateBranch.java index 62106e8c1d..ec1f56e718 100644 --- a/java/com/google/gerrit/server/restapi/project/CreateBranch.java +++ b/java/com/google/gerrit/server/restapi/project/CreateBranch.java @@ -16,6 +16,7 @@ package com.google.gerrit.server.restapi.project; import static com.google.gerrit.reviewdb.client.RefNames.isConfigRef; +import com.google.common.base.Strings; import com.google.common.flogger.FluentLogger; import com.google.gerrit.extensions.api.projects.BranchInfo; import com.google.gerrit.extensions.api.projects.BranchInput; @@ -91,7 +92,10 @@ public class CreateBranch if (input.ref != null && !ref.equals(input.ref)) { throw new BadRequestException("ref must match URL"); } - if (input.revision == null) { + if (input.revision != null) { + input.revision = input.revision.trim(); + } + if (Strings.isNullOrEmpty(input.revision)) { input.revision = Constants.HEAD; } while (ref.startsWith("/")) { diff --git a/java/com/google/gerrit/server/restapi/project/CreateTag.java b/java/com/google/gerrit/server/restapi/project/CreateTag.java index e72deaf255..855a7c7429 100644 --- a/java/com/google/gerrit/server/restapi/project/CreateTag.java +++ b/java/com/google/gerrit/server/restapi/project/CreateTag.java @@ -87,7 +87,10 @@ public class CreateTag implements RestCollectionCreateView expected, List actual) throws Exception { assertThat(actual).hasSize(expected.size());