summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorMike Williams <miwilliams@google.com>2016-01-25 12:45:33 -0500
committerMike Williams <miwilliams@google.com>2016-01-28 11:43:59 -0500
commit48ad6842fc20ce1aaf1198d5f30239633c89c52c (patch)
tree661b4b0f523151dc6101169eee39c6c9760473ee /org.eclipse.jgit.test
parent114ee5a613007d21ed7a25320f8b5029c9b808bd (diff)
downloadjgit-48ad6842fc20ce1aaf1198d5f30239633c89c52c.tar.gz
jgit-48ad6842fc20ce1aaf1198d5f30239633c89c52c.zip
Allow deletion of HEAD ref if the repository is bare.
Change-Id: I2281d818c9f76019e7e053e89b20214f2d663957 Signed-off-by: Mike Williams <miwilliams@google.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java20
1 files changed, 18 insertions, 2 deletions
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 48434189e4..4d91a2368d 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
@@ -104,9 +104,14 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
private void delete(final RefUpdate ref, final Result expected,
final boolean exists, final boolean removed) throws IOException {
- assertEquals(exists, db.getAllRefs().containsKey(ref.getName()));
+ delete(db, ref, expected, exists, removed);
+ }
+
+ private void delete(Repository repo, final RefUpdate ref, final Result expected,
+ final boolean exists, final boolean removed) throws IOException {
+ assertEquals(exists, repo.getAllRefs().containsKey(ref.getName()));
assertEquals(expected, ref.delete());
- assertEquals(!removed, db.getAllRefs().containsKey(ref.getName()));
+ assertEquals(!removed, repo.getAllRefs().containsKey(ref.getName()));
}
@Test
@@ -232,6 +237,17 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
assertEquals(0, db.getReflogReader("HEAD").getReverseEntries().size());
}
+ @Test
+ public void testDeleteHeadInBareRepo() throws IOException {
+ try (Repository bareRepo = createBareRepository()) {
+ RefUpdate ref = bareRepo.updateRef(Constants.HEAD);
+ ref.setNewObjectId(ObjectId.fromString("0123456789012345678901234567890123456789"));
+ // Create the HEAD ref so we can delete it.
+ assertEquals(Result.NEW, ref.update());
+ ref = bareRepo.updateRef(Constants.HEAD);
+ delete(bareRepo, ref, Result.NO_CHANGE, true, true);
+ }
+ }
/**
* Delete a loose ref and make sure the directory in refs is deleted too,
* and the reflog dir too