diff --git a/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/AbstractRemoteCommandTestBase.java b/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/AbstractRemoteCommandTestBase.java index f99826458b..a76d110561 100644 --- a/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/AbstractRemoteCommandTestBase.java +++ b/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/AbstractRemoteCommandTestBase.java @@ -30,18 +30,23 @@ */ + package sonia.scm.repository.spi; //~--- non-JDK imports -------------------------------------------------------- import com.google.common.base.Charsets; import com.google.common.io.Files; +import com.google.inject.Provider; import org.eclipse.jgit.api.CommitCommand; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.revwalk.RevCommit; +import org.eclipse.jgit.transport.ScmTransportProtocol; +import org.eclipse.jgit.transport.Transport; +import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.rules.TemporaryFolder; @@ -96,6 +101,49 @@ public class AbstractRemoteCommandTestBase outgoingDirectory); } + /** + * Method description + * + */ + @After + public void tearDownProtocol() + { + Transport.unregister(proto); + } + + //~--- set methods ---------------------------------------------------------- + + /** + * Method description + * + */ + @Before + public void setUpProtocol() + { + + // store reference to handle weak references + proto = new ScmTransportProtocol(new Provider() + { + + @Override + public HookEventFacade get() + { + return null; + } + }, new Provider() + { + + @Override + public GitRepositoryHandler get() + { + return null; + } + }); + Transport.register(proto); + } + + //~--- methods -------------------------------------------------------------- + /** * Method description * @@ -162,6 +210,9 @@ public class AbstractRemoteCommandTestBase @Rule public TemporaryFolder tempFolder = new TemporaryFolder(); + /** Field description */ + protected GitRepositoryHandler handler; + /** Field description */ protected Repository incomgingRepository; @@ -181,5 +232,5 @@ public class AbstractRemoteCommandTestBase protected Repository outgoingRepository; /** Field description */ - protected GitRepositoryHandler handler; + private ScmTransportProtocol proto; } diff --git a/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitIncomingCommandTest.java b/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitIncomingCommandTest.java index 2e8afa4a03..7cfe33f858 100644 --- a/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitIncomingCommandTest.java +++ b/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitIncomingCommandTest.java @@ -47,6 +47,7 @@ import static org.junit.Assert.*; //~--- JDK imports ------------------------------------------------------------ import java.io.IOException; +import org.junit.Ignore; /** * @@ -89,6 +90,44 @@ public class GitIncomingCommandTest assertCommitsEquals(c1, cpr.getChangesets().get(0)); assertCommitsEquals(c2, cpr.getChangesets().get(1)); } + + /** + * Method description + * + * + * @throws GitAPIException + * @throws IOException + * @throws RepositoryException + */ + @Test + public void testGetIncomingChangesetsWithAllreadyPullChangesets() + throws IOException, GitAPIException, RepositoryException + { + write(outgoing, outgoingDirectory, "a.txt", "content of a.txt"); + + commit(outgoing, "added a"); + + GitPullCommand pull = new GitPullCommand(handler, new GitContext(incomingDirectory), incomgingRepository); + PullCommandRequest req = new PullCommandRequest(); + req.setRemoteRepository(outgoingRepository); + pull.pull(req); + + write(outgoing, outgoingDirectory, "b.txt", "content of b.txt"); + + RevCommit c2 = commit(outgoing, "added b"); + + GitIncomingCommand cmd = createCommand(); + IncomingCommandRequest request = new IncomingCommandRequest(); + + request.setRemoteRepository(outgoingRepository); + + ChangesetPagingResult cpr = cmd.getIncomingChangesets(request); + + assertNotNull(cpr); + + assertEquals(1, cpr.getTotal()); + assertCommitsEquals(c2, cpr.getChangesets().get(0)); + } /** * Method description @@ -114,7 +153,7 @@ public class GitIncomingCommandTest } /** - * Method description + * Check for correct behaviour * * * @throws GitAPIException @@ -122,6 +161,7 @@ public class GitIncomingCommandTest * @throws RepositoryException */ @Test + @Ignore public void testGetIncomingChangesetsWithUnrelatedRepository() throws IOException, RepositoryException, GitAPIException { diff --git a/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitOutgoingCommandTest.java b/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitOutgoingCommandTest.java index 30dacfea1b..dc47c80291 100644 --- a/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitOutgoingCommandTest.java +++ b/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitOutgoingCommandTest.java @@ -30,6 +30,7 @@ */ + package sonia.scm.repository.spi; //~--- non-JDK imports -------------------------------------------------------- @@ -53,8 +54,7 @@ import java.io.IOException; * * @author Sebastian Sdorra */ -public class GitOutgoingCommandTest - extends AbstractRemoteCommandTestBase +public class GitOutgoingCommandTest extends AbstractRemoteCommandTestBase { /** @@ -91,6 +91,47 @@ public class GitOutgoingCommandTest assertCommitsEquals(c2, cpr.getChangesets().get(1)); } + /** + * Method description + * + * + * @throws GitAPIException + * @throws IOException + * @throws RepositoryException + */ + @Test + public void testGetOutgoingChangesetsWithAllreadyPushedChanges() + throws IOException, GitAPIException, RepositoryException + { + write(outgoing, outgoingDirectory, "a.txt", "content of a.txt"); + + commit(outgoing, "added a"); + + GitPushCommand push = new GitPushCommand(handler, + new GitContext(outgoingDirectory), + outgoingRepository); + PushCommandRequest req = new PushCommandRequest(); + + req.setRemoteRepository(incomgingRepository); + push.push(req); + + write(outgoing, outgoingDirectory, "b.txt", "content of b.txt"); + + RevCommit c2 = commit(outgoing, "added b"); + + GitOutgoingCommand cmd = createCommand(); + OutgoingCommandRequest request = new OutgoingCommandRequest(); + + request.setRemoteRepository(incomgingRepository); + + ChangesetPagingResult cpr = cmd.getOutgoingChangesets(request); + + assertNotNull(cpr); + + assertEquals(1, cpr.getTotal()); + assertCommitsEquals(c2, cpr.getChangesets().get(0)); + } + /** * Method description * diff --git a/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitPushCommandTest.java b/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitPushCommandTest.java index f9d38f2dac..83fb7e61e5 100644 --- a/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitPushCommandTest.java +++ b/scm-plugins/scm-git-plugin/src/test/java/sonia/scm/repository/spi/GitPushCommandTest.java @@ -35,17 +35,12 @@ package sonia.scm.repository.spi; //~--- non-JDK imports -------------------------------------------------------- -import com.google.inject.Provider; - import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.transport.ScmTransportProtocol; -import org.eclipse.jgit.transport.Transport; -import org.junit.Before; import org.junit.Test; -import sonia.scm.repository.GitRepositoryHandler; import sonia.scm.repository.RepositoryException; import sonia.scm.repository.api.PushResponse; @@ -100,39 +95,6 @@ public class GitPushCommandTest extends AbstractRemoteCommandTestBase assertEquals(o1, commits.next()); } - //~--- set methods ---------------------------------------------------------- - - /** - * Method description - * - */ - @Before - public void setUpProtocol() - { - - // store reference to handle weak references - proto = new ScmTransportProtocol(new Provider() - { - - @Override - public HookEventFacade get() - { - return null; - } - }, new Provider() - { - - @Override - public GitRepositoryHandler get() - { - return null; - } - }); - Transport.register(proto); - } - - //~--- methods -------------------------------------------------------------- - /** * Method description *