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>
(cherry picked from commit 036751e0e3)
This commit is contained in:
Edwin Kempin
2018-06-11 16:40:56 +02:00
committed by David Pursehouse
parent a5d14bdd0a
commit 6c54b4eaa9
2 changed files with 16 additions and 0 deletions

View File

@@ -504,6 +504,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();

View File

@@ -477,6 +477,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);