aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java58
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushConnectionTest.java2
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java67
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/treewalk/NameConflictTreeWalk.java3
4 files changed, 123 insertions, 7 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java
index a08dbbcc83..255262255a 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java
@@ -586,6 +586,64 @@ public class ResolveMergerTest extends RepositoryTestCase {
}
}
+ @Theory
+ public void checkContentMergeNoConflict(MergeStrategy strategy)
+ throws Exception {
+ Git git = Git.wrap(db);
+
+ writeTrashFile("file", "1\n2\n3");
+ git.add().addFilepattern("file").call();
+ RevCommit first = git.commit().setMessage("added file").call();
+
+ writeTrashFile("file", "1master\n2\n3");
+ git.commit().setAll(true).setMessage("modified file on master").call();
+
+ git.checkout().setCreateBranch(true).setStartPoint(first)
+ .setName("side").call();
+ writeTrashFile("file", "1\n2\n3side");
+ RevCommit sideCommit = git.commit().setAll(true)
+ .setMessage("modified file on side").call();
+
+ git.checkout().setName("master").call();
+ MergeResult result =
+ git.merge().setStrategy(strategy).include(sideCommit).call();
+ assertEquals(MergeStatus.MERGED, result.getMergeStatus());
+ String expected = "1master\n2\n3side";
+ assertEquals(expected, read("file"));
+ }
+
+ @Theory
+ public void checkContentMergeConflict(MergeStrategy strategy)
+ throws Exception {
+ Git git = Git.wrap(db);
+
+ writeTrashFile("file", "1\n2\n3");
+ git.add().addFilepattern("file").call();
+ RevCommit first = git.commit().setMessage("added file").call();
+
+ writeTrashFile("file", "1master\n2\n3");
+ git.commit().setAll(true).setMessage("modified file on master").call();
+
+ git.checkout().setCreateBranch(true).setStartPoint(first)
+ .setName("side").call();
+ writeTrashFile("file", "1side\n2\n3");
+ RevCommit sideCommit = git.commit().setAll(true)
+ .setMessage("modified file on side").call();
+
+ git.checkout().setName("master").call();
+ MergeResult result =
+ git.merge().setStrategy(strategy).include(sideCommit).call();
+ assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus());
+ String expected = "<<<<<<< HEAD\n"
+ + "1master\n"
+ + "=======\n"
+ + "1side\n"
+ + ">>>>>>> " + sideCommit.name() + "\n"
+ + "2\n"
+ + "3";
+ assertEquals(expected, read("file"));
+ }
+
/**
* Merging after criss-cross merges. In this case we merge together two
* commits which have two equally good common ancestors
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushConnectionTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushConnectionTest.java
index 4aebc1d32c..908a1bab26 100644
--- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushConnectionTest.java
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PushConnectionTest.java
@@ -184,7 +184,7 @@ public class PushConnectionTest {
updates.put(rru.getRemoteName(), rru);
}
- server.getConfig().setInt("receive", null, "maxCommandBytes", 170);
+ server.getConfig().setInt("receive", null, "maxCommandBytes", 180);
try (Transport tn = testProtocol.open(uri, client, "server");
PushConnection connection = tn.openPush()) {
try {
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
index 58fdd25745..6b16f550d9 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/UploadPack.java
@@ -58,6 +58,7 @@ import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_SIDE_BAND;
import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_SIDE_BAND_64K;
import static org.eclipse.jgit.transport.GitProtocolConstants.OPTION_THIN_PACK;
+import java.io.ByteArrayOutputStream;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
@@ -71,6 +72,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
+import org.eclipse.jgit.annotations.Nullable;
import org.eclipse.jgit.errors.CorruptObjectException;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
@@ -235,7 +237,7 @@ public class UploadPack {
private InputStream rawIn;
- private OutputStream rawOut;
+ private ResponseBufferedOutputStream rawOut;
private PacketLineIn pckIn;
@@ -644,11 +646,10 @@ public class UploadPack {
* other network connections this should be null.
* @throws IOException
*/
- public void upload(final InputStream input, final OutputStream output,
+ public void upload(final InputStream input, OutputStream output,
final OutputStream messages) throws IOException {
try {
rawIn = input;
- rawOut = output;
if (messages != null)
msgOut = messages;
@@ -656,11 +657,17 @@ public class UploadPack {
final Thread caller = Thread.currentThread();
timer = new InterruptTimer(caller.getName() + "-Timer"); //$NON-NLS-1$
TimeoutInputStream i = new TimeoutInputStream(rawIn, timer);
- TimeoutOutputStream o = new TimeoutOutputStream(rawOut, timer);
+ @SuppressWarnings("resource")
+ TimeoutOutputStream o = new TimeoutOutputStream(output, timer);
i.setTimeout(timeout * 1000);
o.setTimeout(timeout * 1000);
rawIn = i;
- rawOut = o;
+ output = o;
+ }
+
+ rawOut = new ResponseBufferedOutputStream(output);
+ if (biDirectionalPipe) {
+ rawOut.stopBuffering();
}
pckIn = new PacketLineIn(rawIn);
@@ -714,6 +721,8 @@ public class UploadPack {
private void service() throws IOException {
boolean sendPack;
+ // If it's a non-bidi request, we need to read the entire request before
+ // writing a response. Buffer the response until then.
try {
if (biDirectionalPipe)
sendAdvertisedRefs(new PacketLineOutRefAdvertiser(pckOut));
@@ -769,6 +778,8 @@ public class UploadPack {
throw new UploadPackInternalServerErrorException(err);
}
throw err;
+ } finally {
+ rawOut.stopBuffering();
}
if (sendPack)
@@ -1572,4 +1583,50 @@ public class UploadPack {
adv.addSymref(Constants.HEAD, head.getLeaf().getName());
}
}
+
+ private static class ResponseBufferedOutputStream extends OutputStream {
+ private final OutputStream rawOut;
+
+ private OutputStream out;
+ @Nullable
+ private ByteArrayOutputStream buffer;
+
+ ResponseBufferedOutputStream(OutputStream rawOut) {
+ this.rawOut = rawOut;
+ this.out = this.buffer = new ByteArrayOutputStream();
+ }
+
+ @Override
+ public void write(int b) throws IOException {
+ out.write(b);
+ }
+
+ @Override
+ public void write(byte b[]) throws IOException {
+ out.write(b);
+ }
+
+ @Override
+ public void write(byte b[], int off, int len) throws IOException {
+ out.write(b, off, len);
+ }
+
+ @Override
+ public void flush() throws IOException {
+ out.flush();
+ }
+
+ @Override
+ public void close() throws IOException {
+ out.close();
+ }
+
+ void stopBuffering() throws IOException {
+ if (buffer != null) {
+ buffer.writeTo(rawOut);
+ buffer = null;
+ out = rawOut;
+ }
+ }
+ }
}
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/NameConflictTreeWalk.java b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/NameConflictTreeWalk.java
index c0b29ef930..59cf7989d4 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/NameConflictTreeWalk.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/treewalk/NameConflictTreeWalk.java
@@ -45,6 +45,7 @@ package org.eclipse.jgit.treewalk;
import java.io.IOException;
+import org.eclipse.jgit.annotations.Nullable;
import org.eclipse.jgit.dircache.DirCacheBuilder;
import org.eclipse.jgit.errors.CorruptObjectException;
import org.eclipse.jgit.lib.FileMode;
@@ -110,7 +111,7 @@ public class NameConflictTreeWalk extends TreeWalk {
* the reader the walker will obtain tree data from.
* @since 4.3
*/
- public NameConflictTreeWalk(Repository repo, final ObjectReader or) {
+ public NameConflictTreeWalk(@Nullable Repository repo, final ObjectReader or) {
super(repo, or);
}