Don't fail on removing star labels from change without star labels

Setting no star labels on a change that doesn't have star labels should
be a no-op, but it currently fails with 500 Internal Server Error
because it attempts to delete a ref that doesn't exist.

Change-Id: Id180e4ff4f928aa229e29ed030b7af640e4605ff
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin 2018-06-11 16:40:56 +02:00
parent 0e69d16a37
commit 036751e0e3
2 changed files with 16 additions and 0 deletions

View File

@ -476,6 +476,11 @@ public class StarredChangesUtil {
private void deleteRef(Repository repo, String refName, ObjectId oldObjectId)
throws IOException, OrmException {
if (ObjectId.zeroId().equals(oldObjectId)) {
// ref doesn't exist
return;
}
RefUpdate u = repo.updateRef(refName);
u.setForceUpdate(true);
u.setExpectedOldObjectId(oldObjectId);

View File

@ -727,6 +727,17 @@ public class AccountIT extends AbstractDaemonTest {
ImmutableSet.of(DEFAULT_LABEL, "invalid label", "blue", "another invalid label")));
}
@Test
public void deleteStarLabelsFromChangeWithoutStarLabels() throws Exception {
PushOneCommit.Result r = createChange();
String triplet = project.get() + "~master~" + r.getChangeId();
assertThat(gApi.accounts().self().getStars(triplet)).isEmpty();
gApi.accounts().self().setStars(triplet, new StarsInput());
assertThat(gApi.accounts().self().getStars(triplet)).isEmpty();
}
@Test
public void starWithDefaultAndIgnoreLabel() throws Exception {
PushOneCommit.Result r = createChange();