From e8f720335f86198d4dc99af10ffb6f52e40ba06f Mon Sep 17 00:00:00 2001 From: Robin Stocker Date: Sat, 27 Apr 2013 13:30:11 +0200 Subject: Add test for RefUpdate delete without HEAD Bug: 406722 Change-Id: I555fb366ee64d885de2a71a67cf00833f4c62561 --- .../jgit/internal/storage/file/RefUpdateTest.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java index 7388dce237..21df179ad8 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java @@ -1,7 +1,7 @@ /* * Copyright (C) 2008, Charles O'Farrell * Copyright (C) 2009-2010, Google Inc. - * Copyright (C) 2008-2009, Robin Rosenberg + * Copyright (C) 2008-2013, Robin Rosenberg * and other copyright owners as documented in the project's IP log. * * This program and the accompanying materials are made available @@ -283,6 +283,21 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase { delete(ref, Result.FORCED); } + @Test + public void testDeleteWithoutHead() throws IOException { + // Prepare repository without HEAD + RefUpdate refUpdate = db.updateRef(Constants.HEAD, true); + refUpdate.setForceUpdate(true); + refUpdate.setNewObjectId(ObjectId.zeroId()); + Result updateResult = refUpdate.update(); + assertEquals(Result.FORCED, updateResult); + Result deleteHeadResult = db.updateRef(Constants.HEAD).delete(); + assertEquals(Result.NO_CHANGE, deleteHeadResult); + + // Any result is ok as long as it's not an NPE + db.updateRef(Constants.R_HEADS + "master").delete(); + } + @Test public void testRefKeySameAsName() { Map allRefs = db.getAllRefs(); -- cgit v1.2.3