Merge with 2.0.0-m3

This commit is contained in:
René Pfeuffer
2018-11-08 09:21:41 +01:00
71 changed files with 1812 additions and 1548 deletions

View File

@@ -0,0 +1,93 @@
package sonia.scm.repository.spi;
import org.junit.Test;
import java.io.ByteArrayOutputStream;
import static org.junit.Assert.assertEquals;
public class GitDiffCommandTest extends AbstractGitCommandTestBase {
public static final String DIFF_FILE_A = "diff --git a/a.txt b/a.txt\n" +
"index 7898192..1dc60c7 100644\n" +
"--- a/a.txt\n" +
"+++ b/a.txt\n" +
"@@ -1 +1 @@\n" +
"-a\n" +
"+a and b\n";
public static final String DIFF_FILE_B = "diff --git a/b.txt b/b.txt\n" +
"deleted file mode 100644\n" +
"index 6178079..0000000\n" +
"--- a/b.txt\n" +
"+++ /dev/null\n" +
"@@ -1 +0,0 @@\n" +
"-b\n";
public static final String DIFF_FILE_A_MULTIPLE_REVISIONS = "diff --git a/a.txt b/a.txt\n" +
"index 7898192..2f8bc28 100644\n" +
"--- a/a.txt\n" +
"+++ b/a.txt\n" +
"@@ -1 +1,2 @@\n" +
" a\n" +
"+line for blame\n";
public static final String DIFF_FILE_F_MULTIPLE_REVISIONS = "diff --git a/f.txt b/f.txt\n" +
"new file mode 100644\n" +
"index 0000000..6a69f92\n" +
"--- /dev/null\n" +
"+++ b/f.txt\n" +
"@@ -0,0 +1 @@\n" +
"+f\n";
@Test
public void diffForOneRevisionShouldCreateDiff() {
GitDiffCommand gitDiffCommand = new GitDiffCommand(createContext(), repository);
DiffCommandRequest diffCommandRequest = new DiffCommandRequest();
diffCommandRequest.setRevision("3f76a12f08a6ba0dc988c68b7f0b2cd190efc3c4");
ByteArrayOutputStream output = new ByteArrayOutputStream();
gitDiffCommand.getDiffResult(diffCommandRequest, output);
assertEquals(DIFF_FILE_A + DIFF_FILE_B, output.toString());
}
@Test
public void diffForOneBranchShouldCreateDiff() {
GitDiffCommand gitDiffCommand = new GitDiffCommand(createContext(), repository);
DiffCommandRequest diffCommandRequest = new DiffCommandRequest();
diffCommandRequest.setRevision("test-branch");
ByteArrayOutputStream output = new ByteArrayOutputStream();
gitDiffCommand.getDiffResult(diffCommandRequest, output);
assertEquals(DIFF_FILE_A + DIFF_FILE_B, output.toString());
}
@Test
public void diffForPathShouldCreateLimitedDiff() {
GitDiffCommand gitDiffCommand = new GitDiffCommand(createContext(), repository);
DiffCommandRequest diffCommandRequest = new DiffCommandRequest();
diffCommandRequest.setRevision("test-branch");
diffCommandRequest.setPath("a.txt");
ByteArrayOutputStream output = new ByteArrayOutputStream();
gitDiffCommand.getDiffResult(diffCommandRequest, output);
assertEquals(DIFF_FILE_A, output.toString());
}
@Test
public void diffBetweenTwoBranchesShouldCreateDiff() {
GitDiffCommand gitDiffCommand = new GitDiffCommand(createContext(), repository);
DiffCommandRequest diffCommandRequest = new DiffCommandRequest();
diffCommandRequest.setRevision("master");
diffCommandRequest.setAncestorChangeset("test-branch");
ByteArrayOutputStream output = new ByteArrayOutputStream();
gitDiffCommand.getDiffResult(diffCommandRequest, output);
assertEquals(DIFF_FILE_A_MULTIPLE_REVISIONS + DIFF_FILE_F_MULTIPLE_REVISIONS, output.toString());
}
@Test
public void diffBetweenTwoBranchesForPathShouldCreateLimitedDiff() {
GitDiffCommand gitDiffCommand = new GitDiffCommand(createContext(), repository);
DiffCommandRequest diffCommandRequest = new DiffCommandRequest();
diffCommandRequest.setRevision("master");
diffCommandRequest.setAncestorChangeset("test-branch");
diffCommandRequest.setPath("a.txt");
ByteArrayOutputStream output = new ByteArrayOutputStream();
gitDiffCommand.getDiffResult(diffCommandRequest, output);
assertEquals(DIFF_FILE_A_MULTIPLE_REVISIONS, output.toString());
}
}

View File

@@ -64,7 +64,7 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
* Tests log command with the usage of a default branch.
*/
@Test
public void testGetDefaultBranch() throws Exception {
public void testGetDefaultBranch() {
// without default branch, the repository head should be used
ChangesetPagingResult result = createCommand().getChangesets(new LogCommandRequest());
@@ -92,7 +92,7 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
}
@Test
public void testGetAll() throws Exception
public void testGetAll()
{
ChangesetPagingResult result =
createCommand().getChangesets(new LogCommandRequest());
@@ -103,7 +103,7 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
}
@Test
public void testGetAllByPath() throws Exception
public void testGetAllByPath()
{
LogCommandRequest request = new LogCommandRequest();
@@ -119,7 +119,7 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
}
@Test
public void testGetAllWithLimit() throws Exception
public void testGetAllWithLimit()
{
LogCommandRequest request = new LogCommandRequest();
@@ -143,7 +143,7 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
}
@Test
public void testGetAllWithPaging() throws Exception
public void testGetAllWithPaging()
{
LogCommandRequest request = new LogCommandRequest();
@@ -194,7 +194,7 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
}
@Test
public void testGetRange() throws Exception
public void testGetRange()
{
LogCommandRequest request = new LogCommandRequest();
@@ -216,6 +216,26 @@ public class GitLogCommandTest extends AbstractGitCommandTestBase
assertEquals("435df2f061add3589cb326cc64be9b9c3897ceca", c2.getId());
}
@Test
public void testGetAncestor()
{
LogCommandRequest request = new LogCommandRequest();
request.setBranch("test-branch");
request.setAncestorChangeset("master");
ChangesetPagingResult result = createCommand().getChangesets(request);
assertNotNull(result);
assertEquals(1, result.getTotal());
assertEquals(1, result.getChangesets().size());
Changeset c = result.getChangesets().get(0);
assertNotNull(c);
assertEquals("3f76a12f08a6ba0dc988c68b7f0b2cd190efc3c4", c.getId());
}
@Test
public void shouldFindDefaultBranchFromHEAD() throws Exception {
setRepositoryHeadReference("ref: refs/heads/test-branch");