#873 implemented default branch repository property for git

This commit is contained in:
Sebastian Sdorra
2016-11-10 19:28:46 +01:00
parent 807eccf459
commit df7b554b80
12 changed files with 182 additions and 42 deletions

View File

@@ -47,12 +47,39 @@ import static org.junit.Assert.*;
import java.io.IOException;
/**
*
* Unit tests for {@link GitBlameCommand}.
*
* @author Sebastian Sdorra
*/
public class GitBlameCommandTest extends AbstractGitCommandTestBase
{
/**
* Tests blame command with default branch.
*
* @throws IOException
* @throws RepositoryException
*/
@Test
public void testDefaultBranch() throws IOException, RepositoryException {
// without default branch, the repository head should be used
BlameCommandRequest request = new BlameCommandRequest();
request.setPath("a.txt");
BlameResult result = createCommand().getBlameResult(request);
assertNotNull(result);
assertEquals(2, result.getTotal());
assertEquals("435df2f061add3589cb326cc64be9b9c3897ceca", result.getLine(0).getRevision());
assertEquals("fcd0ef1831e4002ac43ea539f4094334c79ea9ec", result.getLine(1).getRevision());
// set default branch and test again
repository.setProperty(AbstractGitCommand.PROPERTY_DEFAULT_BRANCH, "test-branch");
result = createCommand().getBlameResult(request);
assertNotNull(result);
assertEquals(1, result.getTotal());
assertEquals("3f76a12f08a6ba0dc988c68b7f0b2cd190efc3c4", result.getLine(0).getRevision());
}
/**
* Method description
*

View File

@@ -50,11 +50,48 @@ import java.io.IOException;
import java.util.List;
/**
*
* Unit tests for {@link GitBrowseCommand}.
*
* @author Sebastian Sdorra
*/
public class GitBrowseCommandTest extends AbstractGitCommandTestBase
{
/**
* Test browse command with default branch.
*
* @throws IOException
* @throws RepositoryException
*/
@Test
public void testDefaultBranch() throws IOException, RepositoryException {
// without default branch, the repository head should be used
BrowserResult result = createCommand().getBrowserResult(new BrowseCommandRequest());
assertNotNull(result);
List<FileObject> foList = result.getFiles();
assertNotNull(foList);
assertFalse(foList.isEmpty());
assertEquals(4, foList.size());
assertEquals("a.txt", foList.get(0).getName());
assertEquals("b.txt", foList.get(1).getName());
assertEquals("c", foList.get(2).getName());
assertEquals("f.txt", foList.get(3).getName());
// set default branch and fetch again
repository.setProperty(AbstractGitCommand.PROPERTY_DEFAULT_BRANCH, "test-branch");
result = createCommand().getBrowserResult(new BrowseCommandRequest());
assertNotNull(result);
foList = result.getFiles();
assertNotNull(foList);
assertFalse(foList.isEmpty());
assertEquals(2, foList.size());
assertEquals("a.txt", foList.get(0).getName());
assertEquals("c", foList.get(1).getName());
}
/**
* Method description

View File

@@ -46,12 +46,33 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
/**
* Unit tests for {@link GitCatCommand}.
*
* TODO add not found test
*
* @author Sebastian Sdorra
*/
public class GitCatCommandTest extends AbstractGitCommandTestBase
{
/**
* Tests cat command with default branch.
*
* @throws IOException
* @throws RepositoryException
*/
@Test
public void testDefaultBranch() throws IOException, RepositoryException {
// without default branch, the repository head should be used
CatCommandRequest request = new CatCommandRequest();
request.setPath("a.txt");
assertEquals("a\nline for blame", execute(request));
// set default branch for repository and check again
repository.setProperty(AbstractGitCommand.PROPERTY_DEFAULT_BRANCH, "test-branch");
assertEquals("a and b", execute(request));
}
/**
* Method description

View File

@@ -49,14 +49,47 @@ import static org.junit.Assert.*;
//~--- JDK imports ------------------------------------------------------------
import java.io.IOException;
import org.eclipse.jgit.api.errors.GitAPIException;
/**
*
* Unit tests for {@link GitLogCommand}.
*
* @author Sebastian Sdorra
*/
public class GitLogCommandTest extends AbstractGitCommandTestBase
{
/**
* Tests log command with the usage of a default branch.
*
* @throws IOException
* @throws GitAPIException
* @throws RepositoryException
*/
@Test
public void testGetDefaultBranch() throws IOException, GitAPIException, RepositoryException {
// without default branch, the repository head should be used
ChangesetPagingResult result = createCommand().getChangesets(new LogCommandRequest());
assertNotNull(result);
assertEquals(4, result.getTotal());
assertEquals("fcd0ef1831e4002ac43ea539f4094334c79ea9ec", result.getChangesets().get(0).getId());
assertEquals("86a6645eceefe8b9a247db5eb16e3d89a7e6e6d1", result.getChangesets().get(1).getId());
assertEquals("592d797cd36432e591416e8b2b98154f4f163411", result.getChangesets().get(2).getId());
assertEquals("435df2f061add3589cb326cc64be9b9c3897ceca", result.getChangesets().get(3).getId());
// set default branch and fetch again
repository.setProperty(AbstractGitCommand.PROPERTY_DEFAULT_BRANCH, "test-branch");
result = createCommand().getChangesets(new LogCommandRequest());
assertNotNull(result);
assertEquals(3, result.getTotal());
assertEquals("3f76a12f08a6ba0dc988c68b7f0b2cd190efc3c4", result.getChangesets().get(0).getId());
assertEquals("592d797cd36432e591416e8b2b98154f4f163411", result.getChangesets().get(1).getId());
assertEquals("435df2f061add3589cb326cc64be9b9c3897ceca", result.getChangesets().get(2).getId());
}
/**
* Method description
*

View File

@@ -51,7 +51,8 @@ import static org.junit.Assert.assertNotNull;
import java.io.IOException;
/**
*
* Unit tests for {@link OutgoingCommand}.
*
* @author Sebastian Sdorra
*/
public class GitOutgoingCommandTest extends AbstractRemoteCommandTestBase