]> source.dussan.org Git - jgit.git/commitdiff
BundleWriter: Support including HEAD in bundle 92/35092/1
authorRobin Stocker <robin@nibor.org>
Sun, 19 Oct 2014 03:40:29 +0000 (14:40 +1100)
committerRobin Stocker <robin@nibor.org>
Sun, 19 Oct 2014 03:40:29 +0000 (14:40 +1100)
Bug: 446813
Change-Id: Ide64aec2a995dd7ff6c1325c3ada242a4eb4565e
Signed-off-by: Robin Stocker <robin@nibor.org>
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/BundleWriterTest.java
org.eclipse.jgit/src/org/eclipse/jgit/transport/BundleWriter.java

index efc3834f457e5af97c624d9c732a7d0e597b7c11..24cee0a6a105befb04a229c6d6c05502eaa9d7e3 100644 (file)
@@ -73,20 +73,19 @@ import org.junit.Test;
 public class BundleWriterTest extends SampleDataRepositoryTestCase {
 
        @Test
-       public void testWrite0() throws Exception {
+       public void testWriteSingleRef() throws Exception {
                // Create a tiny bundle, (well one of) the first commits only
                final byte[] bundle = makeBundle("refs/heads/firstcommit",
                                "42e4e7c5e507e113ebbb7801b16b52cf867b7ce1", null);
 
                // Then we clone a new repo from that bundle and do a simple test. This
-               // makes sure
-               // we could read the bundle we created.
+               // makes sure we could read the bundle we created.
                Repository newRepo = createBareRepository();
                FetchResult fetchResult = fetchFromBundle(newRepo, bundle);
                Ref advertisedRef = fetchResult
                                .getAdvertisedRef("refs/heads/firstcommit");
 
-               // We expect firstcommit to appear by id
+               // We expect first commit to appear by id
                assertEquals("42e4e7c5e507e113ebbb7801b16b52cf867b7ce1", advertisedRef
                                .getObjectId().name());
                // ..and by name as the bundle created a new ref
@@ -94,13 +93,21 @@ public class BundleWriterTest extends SampleDataRepositoryTestCase {
                                .resolve("refs/heads/firstcommit").name());
        }
 
-       /**
-        * Incremental bundle test
-        *
-        * @throws Exception
-        */
        @Test
-       public void testWrite1() throws Exception {
+       public void testWriteHEAD() throws Exception {
+               byte[] bundle = makeBundle("HEAD",
+                               "42e4e7c5e507e113ebbb7801b16b52cf867b7ce1", null);
+
+               Repository newRepo = createBareRepository();
+               FetchResult fetchResult = fetchFromBundle(newRepo, bundle);
+               Ref advertisedRef = fetchResult.getAdvertisedRef("HEAD");
+
+               assertEquals("42e4e7c5e507e113ebbb7801b16b52cf867b7ce1", advertisedRef
+                               .getObjectId().name());
+       }
+
+       @Test
+       public void testIncrementalBundle() throws Exception {
                byte[] bundle;
 
                // Create a small bundle, an early commit
index 4f5cda7abd517a0a92f4c690e6af22bfee352fbb..d0f005cde8127b9321c459e8393461b9f1441922 100644 (file)
@@ -128,7 +128,8 @@ public class BundleWriter {
         *            object to pack. Multiple refs may point to the same object.
         */
        public void include(final String name, final AnyObjectId id) {
-               if (!Repository.isValidRefName(name))
+               boolean validRefName = Repository.isValidRefName(name) || Constants.HEAD.equals(name);
+               if (!validRefName)
                        throw new IllegalArgumentException(MessageFormat.format(JGitText.get().invalidRefName, name));
                if (include.containsKey(name))
                        throw new IllegalStateException(JGitText.get().duplicateRef + name);