summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test/tst
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java36
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java92
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java36
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/fnmatch/FileNameMatcherTest.java40
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsOutputStreamTest.java150
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileRepositoryBuilderTest.java9
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackIndexTestCase.java15
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/HttpAuthTest.java162
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportTest.java16
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathSuffixFilterTest.java100
10 files changed, 592 insertions, 64 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java
index f66661a52f..2668c116a0 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CherryPickCommandTest.java
@@ -111,6 +111,42 @@ public class CherryPickCommandTest extends RepositoryTestCase {
assertFalse(history.hasNext());
}
+ @Test
+ public void testSequentialCherryPick() throws IOException, JGitInternalException,
+ GitAPIException {
+ Git git = new Git(db);
+
+ writeTrashFile("a", "first line\nsec. line\nthird line\n");
+ git.add().addFilepattern("a").call();
+ RevCommit firstCommit = git.commit().setMessage("create a").call();
+
+ writeTrashFile("a", "first line\nsec. line\nthird line\nfourth line\n");
+ git.add().addFilepattern("a").call();
+ RevCommit enlargingA = git.commit().setMessage("enlarged a").call();
+
+ writeTrashFile("a",
+ "first line\nsecond line\nthird line\nfourth line\n");
+ git.add().addFilepattern("a").call();
+ RevCommit fixingA = git.commit().setMessage("fixed a").call();
+
+ git.branchCreate().setName("side").setStartPoint(firstCommit).call();
+ checkoutBranch("refs/heads/side");
+
+ writeTrashFile("b", "nothing to do with a");
+ git.add().addFilepattern("b").call();
+ git.commit().setMessage("create b").call();
+
+ CherryPickResult result = git.cherryPick().include(enlargingA).include(fixingA).call();
+ assertEquals(CherryPickResult.CherryPickStatus.OK, result.getStatus());
+
+ Iterator<RevCommit> history = git.log().call().iterator();
+ assertEquals("fixed a", history.next().getFullMessage());
+ assertEquals("enlarged a", history.next().getFullMessage());
+ assertEquals("create b", history.next().getFullMessage());
+ assertEquals("create a", history.next().getFullMessage());
+ assertFalse(history.hasNext());
+ }
+
@Test
public void testCherryPickDirtyIndex() throws Exception {
Git git = new Git(db);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
index 9aa13caf94..ef5a1eaa0c 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
@@ -74,6 +74,7 @@ import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.PersonIdent;
import org.eclipse.jgit.lib.RefUpdate;
+import org.eclipse.jgit.lib.ReflogEntry;
import org.eclipse.jgit.lib.RepositoryState;
import org.eclipse.jgit.merge.MergeStrategy;
import org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason;
@@ -107,6 +108,8 @@ public class RebaseCommandTest extends RepositoryTestCase {
// update the HEAD
RefUpdate refUpdate = db.updateRef(Constants.HEAD, true);
refUpdate.setNewObjectId(commit);
+ refUpdate.setRefLogMessage("checkout: moving to " + head.getName(),
+ false);
refUpdate.forceUpdate();
}
@@ -123,7 +126,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
// create file2 on master
File file2 = writeTrashFile("file2", "file2");
git.add().addFilepattern("file2").call();
- git.commit().setMessage("Add file2").call();
+ RevCommit second = git.commit().setMessage("Add file2").call();
assertTrue(new File(db.getWorkTree(), "file2").exists());
checkoutBranch("refs/heads/topic");
@@ -133,6 +136,22 @@ public class RebaseCommandTest extends RepositoryTestCase {
assertTrue(new File(db.getWorkTree(), "file2").exists());
checkFile(file2, "file2");
assertEquals(Status.FAST_FORWARD, res.getStatus());
+
+ List<ReflogEntry> headLog = db.getReflogReader(Constants.HEAD)
+ .getReverseEntries();
+ List<ReflogEntry> topicLog = db.getReflogReader("refs/heads/topic")
+ .getReverseEntries();
+ List<ReflogEntry> masterLog = db.getReflogReader("refs/heads/master")
+ .getReverseEntries();
+ assertEquals("rebase finished: returning to refs/heads/topic", headLog
+ .get(0).getComment());
+ assertEquals("checkout: moving from topic to " + second.getName(),
+ headLog.get(1).getComment());
+ assertEquals(2, masterLog.size());
+ assertEquals(2, topicLog.size());
+ assertEquals(
+ "rebase finished: refs/heads/topic onto " + second.getName(),
+ topicLog.get(0).getComment());
}
@Test
@@ -153,7 +172,8 @@ public class RebaseCommandTest extends RepositoryTestCase {
// write a second commit
writeTrashFile("file2", "file2 new content");
git.add().addFilepattern("file2").call();
- git.commit().setMessage("Change content of file2").call();
+ RevCommit second = git.commit().setMessage("Change content of file2")
+ .call();
checkoutBranch("refs/heads/topic");
assertFalse(new File(db.getWorkTree(), "file2").exists());
@@ -162,6 +182,22 @@ public class RebaseCommandTest extends RepositoryTestCase {
assertTrue(new File(db.getWorkTree(), "file2").exists());
checkFile(file2, "file2 new content");
assertEquals(Status.FAST_FORWARD, res.getStatus());
+
+ List<ReflogEntry> headLog = db.getReflogReader(Constants.HEAD)
+ .getReverseEntries();
+ List<ReflogEntry> topicLog = db.getReflogReader("refs/heads/topic")
+ .getReverseEntries();
+ List<ReflogEntry> masterLog = db.getReflogReader("refs/heads/master")
+ .getReverseEntries();
+ assertEquals("rebase finished: returning to refs/heads/topic", headLog
+ .get(0).getComment());
+ assertEquals("checkout: moving from topic to " + second.getName(),
+ headLog.get(1).getComment());
+ assertEquals(3, masterLog.size());
+ assertEquals(2, topicLog.size());
+ assertEquals(
+ "rebase finished: refs/heads/topic onto " + second.getName(),
+ topicLog.get(0).getComment());
}
/**
@@ -242,6 +278,29 @@ public class RebaseCommandTest extends RepositoryTestCase {
assertDerivedFrom(rw.next(), c);
assertEquals(b, rw.next());
assertEquals(a, rw.next());
+
+ List<ReflogEntry> headLog = db.getReflogReader(Constants.HEAD)
+ .getReverseEntries();
+ List<ReflogEntry> sideLog = db.getReflogReader("refs/heads/side")
+ .getReverseEntries();
+ List<ReflogEntry> topicLog = db.getReflogReader("refs/heads/topic")
+ .getReverseEntries();
+ List<ReflogEntry> masterLog = db.getReflogReader("refs/heads/master")
+ .getReverseEntries();
+ assertEquals("rebase finished: returning to refs/heads/topic", headLog
+ .get(0).getComment());
+ assertEquals("rebase: update file2 on side", headLog.get(1)
+ .getComment());
+ assertEquals("rebase: Add file2", headLog.get(2).getComment());
+ assertEquals("rebase: update file3 on topic", headLog.get(3)
+ .getComment());
+ assertEquals("checkout: moving from topic to " + b.getName(), headLog
+ .get(4).getComment());
+ assertEquals(2, masterLog.size());
+ assertEquals(2, sideLog.size());
+ assertEquals(5, topicLog.size());
+ assertEquals("rebase finished: refs/heads/topic onto " + b.getName(),
+ topicLog.get(0).getComment());
}
static void assertDerivedFrom(RevCommit derived, RevCommit original) {
@@ -261,6 +320,11 @@ public class RebaseCommandTest extends RepositoryTestCase {
RebaseResult result = git.rebase().setUpstream(parent).call();
assertEquals(Status.UP_TO_DATE, result.getStatus());
+
+ assertEquals(2, db.getReflogReader(Constants.HEAD).getReverseEntries()
+ .size());
+ assertEquals(2, db.getReflogReader("refs/heads/master")
+ .getReverseEntries().size());
}
@Test
@@ -274,6 +338,11 @@ public class RebaseCommandTest extends RepositoryTestCase {
RebaseResult res = git.rebase().setUpstream(first).call();
assertEquals(Status.UP_TO_DATE, res.getStatus());
+
+ assertEquals(1, db.getReflogReader(Constants.HEAD).getReverseEntries()
+ .size());
+ assertEquals(1, db.getReflogReader("refs/heads/master")
+ .getReverseEntries().size());
}
@Test
@@ -328,6 +397,18 @@ public class RebaseCommandTest extends RepositoryTestCase {
assertEquals(lastMasterChange, new RevWalk(db).parseCommit(
db.resolve(Constants.HEAD)).getParent(0));
assertEquals(origHead, db.readOrigHead());
+ List<ReflogEntry> headLog = db.getReflogReader(Constants.HEAD)
+ .getReverseEntries();
+ List<ReflogEntry> topicLog = db.getReflogReader("refs/heads/topic")
+ .getReverseEntries();
+ List<ReflogEntry> masterLog = db.getReflogReader("refs/heads/master")
+ .getReverseEntries();
+ assertEquals(2, masterLog.size());
+ assertEquals(3, topicLog.size());
+ assertEquals("rebase finished: refs/heads/topic onto "
+ + lastMasterChange.getName(), topicLog.get(0).getComment());
+ assertEquals("rebase finished: returning to refs/heads/topic", headLog
+ .get(0).getComment());
}
@Test
@@ -366,6 +447,13 @@ public class RebaseCommandTest extends RepositoryTestCase {
assertEquals(lastMasterChange, new RevWalk(db).parseCommit(
db.resolve(Constants.HEAD)).getParent(0));
+ List<ReflogEntry> headLog = db.getReflogReader(Constants.HEAD)
+ .getReverseEntries();
+ assertEquals(8, headLog.size());
+ assertEquals("rebase: change file1 in topic", headLog.get(0)
+ .getComment());
+ assertEquals("checkout: moving from " + topicCommit.getName() + " to "
+ + lastMasterChange.getName(), headLog.get(1).getComment());
}
@Test
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java
index e98263a2ac..8b3e87f2dc 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java
@@ -132,6 +132,42 @@ public class StatusCommandTest extends RepositoryTestCase {
assertTrue(stat.getUntrackedFolders().contains("sub"));
}
+ @Test
+ public void testDifferentStatesWithPaths() throws IOException,
+ NoFilepatternException, GitAPIException {
+ Git git = new Git(db);
+ writeTrashFile("a", "content of a");
+ writeTrashFile("D/b", "content of b");
+ writeTrashFile("D/c", "content of c");
+ writeTrashFile("D/D/d", "content of d");
+ git.add().addFilepattern(".").call();
+
+ writeTrashFile("a", "new content of a");
+ writeTrashFile("D/b", "new content of b");
+ writeTrashFile("D/D/d", "new content of d");
+
+
+ // filter on an not existing path
+ Status stat = git.status().addPath("x").call();
+ assertEquals(0, stat.getModified().size());
+
+ // filter on an existing file
+ stat = git.status().addPath("a").call();
+ assertEquals(set("a"), stat.getModified());
+
+ // filter on an existing folder
+ stat = git.status().addPath("D").call();
+ assertEquals(set("D/b", "D/D/d"), stat.getModified());
+
+ // filter on an existing folder and file
+ stat = git.status().addPath("D/D").addPath("a").call();
+ assertEquals(set("a", "D/D/d"), stat.getModified());
+
+ // do not filter at all
+ stat = git.status().call();
+ assertEquals(set("a", "D/b", "D/D/d"), stat.getModified());
+ }
+
public static Set<String> set(String... elements) {
Set<String> ret = new HashSet<String>();
for (String element : elements)
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/fnmatch/FileNameMatcherTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/fnmatch/FileNameMatcherTest.java
index ec0724406b..1db6c80304 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/fnmatch/FileNameMatcherTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/fnmatch/FileNameMatcherTest.java
@@ -802,6 +802,46 @@ public class FileNameMatcherTest {
}
@Test
+ public void testEscapedBracket1() throws Exception {
+ assertMatch("\\[", "[", true, false);
+ }
+
+ @Test
+ public void testEscapedBracket2() throws Exception {
+ assertMatch("\\[[a]", "[", false, true);
+ }
+
+ @Test
+ public void testEscapedBracket3() throws Exception {
+ assertMatch("\\[[a]", "a", false, false);
+ }
+
+ @Test
+ public void testEscapedBracket4() throws Exception {
+ assertMatch("\\[[a]", "[a", true, false);
+ }
+
+ @Test
+ public void testEscapedBracket5() throws Exception {
+ assertMatch("[a\\]]", "]", true, false);
+ }
+
+ @Test
+ public void testEscapedBracket6() throws Exception {
+ assertMatch("[a\\]]", "a", true, false);
+ }
+
+ @Test
+ public void testEscapedBackslash() throws Exception {
+ assertMatch("a\\\\b", "a\\b", true, false);
+ }
+
+ @Test
+ public void testMultipleEscapedCharacters1() throws Exception {
+ assertMatch("\\]a?c\\*\\[d\\?\\]", "]abc*[d?]", true, false);
+ }
+
+ @Test
public void testFilePathSimpleCase() throws Exception {
assertFileNameMatch("a/b", "a/b", '/', true, false);
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsOutputStreamTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsOutputStreamTest.java
new file mode 100644
index 0000000000..fc092e69d0
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/dfs/DfsOutputStreamTest.java
@@ -0,0 +1,150 @@
+/*
+ * Copyright (C) 2013, Google Inc.
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.eclipse.jgit.internal.storage.dfs;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.eclipse.jgit.lib.Constants;
+import org.eclipse.jgit.util.RawParseUtils;
+import org.junit.Test;
+
+public class DfsOutputStreamTest {
+ @Test
+ public void testReadEmpty() throws IOException {
+ DfsOutputStream os = newDfsOutputStream(8);
+ os.write(Constants.encode(""));
+ assertEquals("", readBuffered(os.openInputStream(0)));
+ assertEquals("", readByByte(os.openInputStream(0)));
+ assertEquals("", readBuffered(os.openInputStream(1)));
+ assertEquals("", readByByte(os.openInputStream(1)));
+ }
+
+ @Test
+ public void testRead() throws IOException {
+ DfsOutputStream os = newDfsOutputStream(8);
+ os.write(Constants.encode("data"));
+ assertEquals("data", readBuffered(os.openInputStream(0)));
+ assertEquals("data", readByByte(os.openInputStream(0)));
+ assertEquals("ata", readBuffered(os.openInputStream(1)));
+ assertEquals("ata", readByByte(os.openInputStream(1)));
+ assertEquals("ta", readBuffered(os.openInputStream(2)));
+ assertEquals("ta", readByByte(os.openInputStream(2)));
+ assertEquals("a", readBuffered(os.openInputStream(3)));
+ assertEquals("a", readByByte(os.openInputStream(3)));
+ assertEquals("", readBuffered(os.openInputStream(4)));
+ assertEquals("", readByByte(os.openInputStream(4)));
+ assertEquals("", readBuffered(os.openInputStream(5)));
+ assertEquals("", readByByte(os.openInputStream(5)));
+ }
+
+ @Test
+ public void testReadSmallBuffer() throws IOException {
+ DfsOutputStream os = newDfsOutputStream(8);
+ os.write(Constants.encode("data"));
+ assertEquals("data", readBuffered(os.openInputStream(0), 2));
+ assertEquals("ata", readBuffered(os.openInputStream(1), 2));
+ assertEquals("ta", readBuffered(os.openInputStream(2), 2));
+ assertEquals("a", readBuffered(os.openInputStream(3), 2));
+ assertEquals("", readBuffered(os.openInputStream(4), 2));
+ assertEquals("", readBuffered(os.openInputStream(5), 2));
+ }
+
+ @Test
+ public void testReadMultipleBlocks() throws IOException {
+ DfsOutputStream os = newDfsOutputStream(2);
+ os.write(Constants.encode("data"));
+ assertEquals("data", readBuffered(os.openInputStream(0)));
+ assertEquals("data", readByByte(os.openInputStream(0)));
+ assertEquals("ata", readBuffered(os.openInputStream(1)));
+ assertEquals("ata", readByByte(os.openInputStream(1)));
+ assertEquals("ta", readBuffered(os.openInputStream(2)));
+ assertEquals("ta", readByByte(os.openInputStream(2)));
+ assertEquals("a", readBuffered(os.openInputStream(3)));
+ assertEquals("a", readByByte(os.openInputStream(3)));
+ assertEquals("", readBuffered(os.openInputStream(4)));
+ assertEquals("", readByByte(os.openInputStream(4)));
+ assertEquals("", readBuffered(os.openInputStream(5)));
+ assertEquals("", readByByte(os.openInputStream(5)));
+ }
+
+ private static DfsOutputStream newDfsOutputStream(final int blockSize) {
+ return new InMemoryOutputStream() {
+ @Override
+ public int blockSize() {
+ return blockSize;
+ }
+ };
+ }
+
+ private static String readBuffered(InputStream is, int bufsize)
+ throws IOException {
+ StringBuilder out = new StringBuilder();
+ byte[] buf = new byte[bufsize];
+ while (true) {
+ int n = is.read(buf, 0, buf.length);
+ if (n < 0)
+ break;
+ out.append(RawParseUtils.decode(buf, 0, n));
+ }
+ return out.toString();
+ }
+
+ private static String readBuffered(InputStream is) throws IOException {
+ return readBuffered(is, 64);
+ }
+
+ private static String readByByte(InputStream is) throws IOException {
+ StringBuilder out = new StringBuilder();
+ while (true) {
+ int c = is.read();
+ if (c < 0)
+ break;
+ out.append(RawParseUtils.decode(new byte[] {(byte) c}));
+ }
+ return out.toString();
+ }
+}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileRepositoryBuilderTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileRepositoryBuilderTest.java
index 0655415a9d..efdcfeb472 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileRepositoryBuilderTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/FileRepositoryBuilderTest.java
@@ -148,7 +148,10 @@ public class FileRepositoryBuilderTest extends LocalDiskRepositoryTestCase {
builder.setMustExist(true);
Repository repo2 = builder.build();
- assertEquals(repo1.getDirectory(), repo2.getDirectory());
+ // The tmp directory may be a symlink so the actual path
+ // may not
+ assertEquals(repo1.getDirectory().getCanonicalPath(), repo2
+ .getDirectory().getCanonicalPath());
assertEquals(dir, repo2.getWorkTree());
}
@@ -168,7 +171,9 @@ public class FileRepositoryBuilderTest extends LocalDiskRepositoryTestCase {
builder.setMustExist(true);
Repository repo2 = builder.build();
- assertEquals(repo1.getDirectory(), repo2.getDirectory());
+ // The tmp directory may be a symlink
+ assertEquals(repo1.getDirectory().getCanonicalPath(), repo2
+ .getDirectory().getCanonicalPath());
assertEquals(dir, repo2.getWorkTree());
}
}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackIndexTestCase.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackIndexTestCase.java
index aa3817e3ad..7eeb0c0eaa 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackIndexTestCase.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackIndexTestCase.java
@@ -158,6 +158,21 @@ public abstract class PackIndexTestCase extends RepositoryTestCase {
}
/**
+ * Compare offset from iterator entries with output of getOffset() method.
+ */
+ @Test
+ public void testCompareEntriesOffsetsWithGetOffsets() {
+ int i = 0;
+ for (MutableEntry me : smallIdx) {
+ assertEquals(smallIdx.getOffset(i++), me.getOffset());
+ }
+ int j = 0;
+ for (MutableEntry me : denseIdx) {
+ assertEquals(denseIdx.getOffset(j++), me.getOffset());
+ }
+ }
+
+ /**
* Test partial results of iterator comparing to content of well-known
* (prepared) dense index, that may need multi-level indexing.
*/
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/HttpAuthTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/HttpAuthTest.java
new file mode 100644
index 0000000000..c142bc23aa
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/HttpAuthTest.java
@@ -0,0 +1,162 @@
+/*
+ * Copyright (C) 2013, Microsoft Corporation
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.eclipse.jgit.transport;
+
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Test;
+
+public class HttpAuthTest {
+ private static String digestHeader = "WWW-Authenticate: Digest qop=\"auth\",algorithm=MD5-sess,nonce=\"+Upgraded+v1b9...ba\",charset=utf-8,realm=\"Digest\"";
+
+ private static String basicHeader = "WWW-Authenticate: Basic realm=\"everyones.loves.git\"";
+
+ private static String ntlmHeader = "WWW-Authenticate: NTLM";
+
+ private static String bearerHeader = "WWW-Authenticate: Bearer";
+
+ private static String URL_SAMPLE = "http://everyones.loves.git/u/2";
+
+ private static String BASIC = "Basic";
+
+ private static String DIGEST = "Digest";
+
+ @Test
+ public void testHttpAuthScanResponse() throws MalformedURLException {
+ checkResponse(new String[] { basicHeader }, BASIC);
+ checkResponse(new String[] { digestHeader }, DIGEST);
+ checkResponse(new String[] { basicHeader, digestHeader }, DIGEST);
+ checkResponse(new String[] { digestHeader, basicHeader }, DIGEST);
+ checkResponse(new String[] { ntlmHeader, basicHeader, digestHeader,
+ bearerHeader }, DIGEST);
+ checkResponse(new String[] { ntlmHeader, basicHeader, bearerHeader },
+ BASIC);
+ }
+
+ private static void checkResponse(String[] headers,
+ String expectedAuthMethod) throws MalformedURLException {
+
+ AuthHeadersResponse responce = new AuthHeadersResponse(headers);
+ HttpAuthMethod authMethod = HttpAuthMethod.scanResponse(responce);
+
+ if (!expectedAuthMethod.equals(getAuthMethodName(authMethod))) {
+ fail("Wrong authentication method: expected " + expectedAuthMethod
+ + ", but received " + getAuthMethodName(authMethod));
+ }
+ }
+
+ private static String getAuthMethodName(HttpAuthMethod authMethod) {
+ return authMethod.getClass().getSimpleName();
+ }
+
+ private static class AuthHeadersResponse extends HttpURLConnection {
+ Map<String, List<String>> headerFields = new HashMap<String, List<String>>();
+
+ public AuthHeadersResponse(String[] authHeaders)
+ throws MalformedURLException {
+ super(new URL(URL_SAMPLE));
+ parseHeaders(authHeaders);
+ }
+
+ @Override
+ public void disconnect() {
+ fail("The disconnect method shouldn't be invoked");
+ }
+
+ @Override
+ public boolean usingProxy() {
+ return false;
+ }
+
+ @Override
+ public void connect() throws IOException {
+ fail("The connect method shouldn't be invoked");
+ }
+
+ @Override
+ public String getHeaderField(String name) {
+ if (!headerFields.containsKey(name))
+ return null;
+ else {
+ int n = headerFields.get(name).size();
+
+ if (n > 0)
+ return headerFields.get(name).get(n - 1);
+ else
+ return null;
+ }
+ }
+
+ @Override
+ public Map<String, List<String>> getHeaderFields() {
+ return headerFields;
+ }
+
+ private void parseHeaders(String[] headers) {
+ for (String header : headers) {
+ int i = header.indexOf(':');
+
+ if (i < 0)
+ continue;
+
+ String key = header.substring(0, i);
+ String value = header.substring(i + 1).trim();
+
+ if (!headerFields.containsKey(key))
+ headerFields.put(key, new ArrayList<String>());
+
+ List<String> values = headerFields.get(key);
+ values.add(value);
+ }
+ }
+ }
+}
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportTest.java
index aba4e6a8f8..b9691836b6 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/TransportTest.java
@@ -57,7 +57,9 @@ import java.util.List;
import org.eclipse.jgit.junit.SampleDataRepositoryTestCase;
import org.eclipse.jgit.lib.Config;
+import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
+import org.eclipse.jgit.lib.Ref;
import org.eclipse.jgit.lib.Repository;
import org.junit.After;
import org.junit.Before;
@@ -227,6 +229,20 @@ public class TransportTest extends SampleDataRepositoryTestCase {
}
@Test
+ public void testLocalTransportFetchWithoutLocalRepository()
+ throws Exception {
+ URIish uri = new URIish("file://" + db.getWorkTree().getPath());
+ transport = Transport.open(uri);
+ FetchConnection fetchConnection = transport.openFetch();
+ try {
+ Ref head = fetchConnection.getRef(Constants.HEAD);
+ assertNotNull(head);
+ } finally {
+ fetchConnection.close();
+ }
+ }
+
+ @Test
public void testSpi() {
List<TransportProtocol> protocols = Transport.getTransportProtocols();
assertNotNull(protocols);
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathSuffixFilterTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathSuffixFilterTest.java
index 6c3b62a62b..d871c5ec10 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathSuffixFilterTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathSuffixFilterTest.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009, Google Inc.
+ * Copyright (C) 2009, 2013 Google Inc.
* and other copyright owners as documented in the project's IP log.
*
* This program and the accompanying materials are made available
@@ -43,11 +43,11 @@
package org.eclipse.jgit.treewalk.filter;
-import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
import static org.junit.Assert.assertEquals;
import java.io.IOException;
-import java.util.LinkedList;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import org.eclipse.jgit.dircache.DirCache;
@@ -64,84 +64,64 @@ public class PathSuffixFilterTest extends RepositoryTestCase {
@Test
public void testNonRecursiveFiltering() throws IOException {
- final ObjectInserter odi = db.newObjectInserter();
- final ObjectId aSth = odi.insert(OBJ_BLOB, "a.sth".getBytes());
- final ObjectId aTxt = odi.insert(OBJ_BLOB, "a.txt".getBytes());
- final DirCache dc = db.readDirCache();
- final DirCacheBuilder builder = dc.builder();
- final DirCacheEntry aSthEntry = new DirCacheEntry("a.sth");
- aSthEntry.setFileMode(FileMode.REGULAR_FILE);
- aSthEntry.setObjectId(aSth);
- final DirCacheEntry aTxtEntry = new DirCacheEntry("a.txt");
- aTxtEntry.setFileMode(FileMode.REGULAR_FILE);
- aTxtEntry.setObjectId(aTxt);
- builder.add(aSthEntry);
- builder.add(aTxtEntry);
- builder.finish();
- final ObjectId treeId = dc.writeTree(odi);
- odi.flush();
+ ObjectId treeId = createTree("a.sth", "a.txt");
+ List<String> paths = getMatchingPaths(".txt", treeId);
+ List<String> expected = Arrays.asList("a.txt");
- final TreeWalk tw = new TreeWalk(db);
- tw.setFilter(PathSuffixFilter.create(".txt"));
- tw.addTree(treeId);
+ assertEquals(expected, paths);
+ }
- List<String> paths = new LinkedList<String>();
- while (tw.next()) {
- paths.add(tw.getPathString());
- }
+ @Test
+ public void testRecursiveFiltering() throws IOException {
+ ObjectId treeId = createTree("a.sth", "a.txt", "sub/b.sth", "sub/b.txt");
- List<String> expected = new LinkedList<String>();
- expected.add("a.txt");
+ List<String> paths = getMatchingPaths(".txt", treeId, true);
+ List<String> expected = Arrays.asList("a.txt", "sub/b.txt");
assertEquals(expected, paths);
}
@Test
- public void testRecursiveFiltering() throws IOException {
+ public void testEdgeCases() throws IOException {
+ ObjectId treeId = createTree("abc", "abcd", "bcd", "c");
+ assertEquals(new ArrayList<String>(), getMatchingPaths("xbcd", treeId));
+ assertEquals(new ArrayList<String>(), getMatchingPaths("abcx", treeId));
+ assertEquals(Arrays.asList("abcd"), getMatchingPaths("abcd", treeId));
+ assertEquals(Arrays.asList("abcd", "bcd"), getMatchingPaths("bcd", treeId));
+ assertEquals(Arrays.asList("abc", "c"), getMatchingPaths("c", treeId));
+ }
+
+ private ObjectId createTree(String... paths) throws IOException {
final ObjectInserter odi = db.newObjectInserter();
- final ObjectId aSth = odi.insert(OBJ_BLOB, "a.sth".getBytes());
- final ObjectId aTxt = odi.insert(OBJ_BLOB, "a.txt".getBytes());
- final ObjectId bSth = odi.insert(OBJ_BLOB, "b.sth".getBytes());
- final ObjectId bTxt = odi.insert(OBJ_BLOB, "b.txt".getBytes());
final DirCache dc = db.readDirCache();
final DirCacheBuilder builder = dc.builder();
- final DirCacheEntry aSthEntry = new DirCacheEntry("a.sth");
- aSthEntry.setFileMode(FileMode.REGULAR_FILE);
- aSthEntry.setObjectId(aSth);
- final DirCacheEntry aTxtEntry = new DirCacheEntry("a.txt");
- aTxtEntry.setFileMode(FileMode.REGULAR_FILE);
- aTxtEntry.setObjectId(aTxt);
- builder.add(aSthEntry);
- builder.add(aTxtEntry);
- final DirCacheEntry bSthEntry = new DirCacheEntry("sub/b.sth");
- bSthEntry.setFileMode(FileMode.REGULAR_FILE);
- bSthEntry.setObjectId(bSth);
- final DirCacheEntry bTxtEntry = new DirCacheEntry("sub/b.txt");
- bTxtEntry.setFileMode(FileMode.REGULAR_FILE);
- bTxtEntry.setObjectId(bTxt);
- builder.add(bSthEntry);
- builder.add(bTxtEntry);
+ for (String path : paths) {
+ DirCacheEntry entry = createEntry(path, FileMode.REGULAR_FILE);
+ builder.add(entry);
+ }
builder.finish();
final ObjectId treeId = dc.writeTree(odi);
odi.flush();
+ return treeId;
+ }
+ private List<String> getMatchingPaths(String suffixFilter,
+ final ObjectId treeId) throws IOException {
+ return getMatchingPaths(suffixFilter, treeId, false);
+ }
+ private List<String> getMatchingPaths(String suffixFilter,
+ final ObjectId treeId, boolean recursiveWalk) throws IOException {
final TreeWalk tw = new TreeWalk(db);
- tw.setRecursive(true);
- tw.setFilter(PathSuffixFilter.create(".txt"));
+ tw.setFilter(PathSuffixFilter.create(suffixFilter));
+ tw.setRecursive(recursiveWalk);
tw.addTree(treeId);
- List<String> paths = new LinkedList<String>();
- while (tw.next()) {
+ List<String> paths = new ArrayList<String>();
+ while (tw.next())
paths.add(tw.getPathString());
- }
-
- List<String> expected = new LinkedList<String>();
- expected.add("a.txt");
- expected.add("sub/b.txt");
-
- assertEquals(expected, paths);
+ return paths;
}
}