List of usage examples for org.eclipse.jgit.api Git Git
public Git(Repository repo)
From source file:org.eclipse.egit.core.synchronize.GitCommitsModelCacheTest.java
License:Open Source License
@Test public void shouldListChangeInsideFolderInCommit() throws Exception { // given/* w ww .j a v a 2 s .c o m*/ Git git = new Git(db); writeTrashFile(db, "folder/a.txt", "content"); git.add().addFilepattern("folder/a.txt").call(); RevCommit c1 = commit(git, "first commit"); writeTrashFile(db, "folder/a.txt", "new content"); RevCommit c2 = commit(git, "second commit"); // when List<Commit> leftResult = GitCommitsModelCache.build(db, c1, c2, null); List<Commit> rightResult = GitCommitsModelCache.build(db, c2, c1, null); // then // left assertions assertThat(leftResult, notNullValue()); assertCommit(leftResult.get(0), c2, 1); assertFileChange(c1, c2, leftResult.get(0).getChildren().get("folder/a.txt"), "a.txt", LEFT); // right asserts assertThat(rightResult, notNullValue()); assertCommit(rightResult.get(0), c2, 1); assertFileChange(c2, c1, rightResult.get(0).getChildren().get("folder/a.txt"), "a.txt", RIGHT); }
From source file:org.eclipse.egit.core.synchronize.GitCommitsModelCacheTest.java
License:Open Source License
@Test public void shouldListChangesInsideSeparateFoldersInCommit() throws Exception { // given/*from w ww.j a va 2 s.c o m*/ Git git = new Git(db); writeTrashFile(db, "folder/a.txt", "content"); writeTrashFile(db, "folder2/b.txt", "b content"); git.add().addFilepattern("folder/a.txt").call(); git.add().addFilepattern("folder2/b.txt").call(); RevCommit c1 = commit(git, "first commit"); writeTrashFile(db, "folder/a.txt", "new content"); writeTrashFile(db, "folder2/b.txt", "new b content"); RevCommit c2 = commit(git, "second commit"); // when List<Commit> leftResult = GitCommitsModelCache.build(db, c1, c2, null); List<Commit> rightResult = GitCommitsModelCache.build(db, c2, c1, null); // then // left assertions assertThat(leftResult, notNullValue()); assertThat(Integer.valueOf(leftResult.size()), is(Integer.valueOf(1))); assertThat(leftResult.get(0).getShortMessage(), is("second commit")); assertThat(leftResult.get(0).getChildren(), notNullValue()); assertThat(leftResult.get(0).getChildren().size(), is(2)); assertFileChange(c1, c2, leftResult.get(0).getChildren().get("folder/a.txt"), "a.txt", LEFT); assertFileChange(c1, c2, leftResult.get(0).getChildren().get("folder2/b.txt"), "b.txt", LEFT); // right asserts assertThat(rightResult, notNullValue()); assertThat(Integer.valueOf(rightResult.size()), is(Integer.valueOf(1))); assertThat(rightResult.get(0).getShortMessage(), is("second commit")); assertThat(rightResult.get(0).getChildren().size(), is(2)); assertFileChange(c2, c1, rightResult.get(0).getChildren().get("folder/a.txt"), "a.txt", RIGHT); assertFileChange(c2, c1, rightResult.get(0).getChildren().get("folder2/b.txt"), "b.txt", RIGHT); }
From source file:org.eclipse.egit.core.synchronize.GitCommitsModelCacheTest.java
License:Open Source License
@Test public void shouldListChangesInsideFolderInCommit() throws Exception { // given// ww w .jav a 2s .c o m Git git = new Git(db); writeTrashFile(db, "folder/a.txt", "content"); writeTrashFile(db, "folder/b.txt", "b content"); git.add().addFilepattern("folder").call(); RevCommit c1 = commit(git, "first commit"); writeTrashFile(db, "folder/a.txt", "new content"); writeTrashFile(db, "folder/b.txt", "new b content"); RevCommit c2 = commit(git, "second commit"); // when List<Commit> leftResult = GitCommitsModelCache.build(db, c1, c2, null); List<Commit> rightResult = GitCommitsModelCache.build(db, c2, c1, null); // then // left assertions assertThat(leftResult, notNullValue()); assertThat(Integer.valueOf(leftResult.size()), is(Integer.valueOf(1))); assertCommit(leftResult.get(0), c2, 2); assertFileChange(c1, c2, leftResult.get(0).getChildren().get("folder/a.txt"), "a.txt", LEFT); assertFileChange(c1, c2, leftResult.get(0).getChildren().get("folder/b.txt"), "b.txt", LEFT); // right asserts assertThat(rightResult, notNullValue()); assertThat(Integer.valueOf(rightResult.size()), is(Integer.valueOf(1))); assertCommit(rightResult.get(0), c2, 2); assertFileChange(c2, c1, rightResult.get(0).getChildren().get("folder/a.txt"), "a.txt", RIGHT); assertFileChange(c2, c1, rightResult.get(0).getChildren().get("folder/b.txt"), "b.txt", RIGHT); }
From source file:org.eclipse.egit.core.synchronize.GitCommitsModelCacheTest.java
License:Open Source License
@Test public void shouldListAllTypeOfChangesInOneCommit() throws Exception { // given// w ww. j a v a2 s . c o m Git git = new Git(db); writeTrashFile(db, "a.txt", "a content"); writeTrashFile(db, "c.txt", "c content"); git.add().addFilepattern("a.txt").call(); git.add().addFilepattern("c.txt").call(); RevCommit c1 = commit(git, "first commit"); deleteTrashFile(db, "a.txt"); writeTrashFile(db, "b.txt", "b content"); writeTrashFile(db, "c.txt", "new c content"); git.add().addFilepattern("b.txt").call(); RevCommit c2 = commit(git, "second commit"); // when List<Commit> leftResult = GitCommitsModelCache.build(db, c1, c2, null); List<Commit> rightResult = GitCommitsModelCache.build(db, c2, c1, null); // then // left asserts assertThat(leftResult, notNullValue()); assertCommit(leftResult.get(0), c2, 3); assertFileAddition(c1, c2, leftResult.get(0).getChildren().get("a.txt"), "a.txt", LEFT); assertFileDeletion(c1, c2, leftResult.get(0).getChildren().get("b.txt"), "b.txt", LEFT); assertFileChange(c1, c2, leftResult.get(0).getChildren().get("c.txt"), "c.txt", LEFT); // right asserts assertThat(rightResult, notNullValue()); assertCommit(rightResult.get(0), c2, 3); assertFileDeletion(c2, c1, rightResult.get(0).getChildren().get("a.txt"), "a.txt", RIGHT); assertFileAddition(c2, c1, rightResult.get(0).getChildren().get("b.txt"), "b.txt", RIGHT); assertFileChange(c2, c1, rightResult.get(0).getChildren().get("c.txt"), "c.txt", RIGHT); }
From source file:org.eclipse.egit.core.synchronize.GitCommitsModelCacheTest.java
License:Open Source License
@Test public void shouldListAllTypeOfChangesInsideFolderInOneCommit() throws Exception { // given//from ww w. j a va 2 s .c o m Git git = new Git(db); writeTrashFile(db, "folder/a.txt", "a content"); writeTrashFile(db, "folder/c.txt", "c content"); git.add().addFilepattern("folder/a.txt").call(); git.add().addFilepattern("folder/c.txt").call(); RevCommit c1 = commit(git, "first commit"); deleteTrashFile(db, "folder/a.txt"); writeTrashFile(db, "folder/b.txt", "b content"); writeTrashFile(db, "folder/c.txt", "new c content"); git.add().addFilepattern("folder/b.txt").call(); RevCommit c2 = commit(git, "second commit"); // when List<Commit> leftResult = GitCommitsModelCache.build(db, c1, c2, null); List<Commit> rightResult = GitCommitsModelCache.build(db, c2, c1, null); // then // left assertions assertThat(leftResult, notNullValue()); assertCommit(leftResult.get(0), c2, 3); assertFileAddition(c1, c2, leftResult.get(0).getChildren().get("folder/a.txt"), "a.txt", LEFT); assertFileDeletion(c1, c2, leftResult.get(0).getChildren().get("folder/b.txt"), "b.txt", LEFT); assertFileChange(c1, c2, leftResult.get(0).getChildren().get("folder/c.txt"), "c.txt", LEFT); // right asserts assertThat(rightResult, notNullValue()); assertCommit(rightResult.get(0), c2, 3); assertFileDeletion(c2, c1, rightResult.get(0).getChildren().get("folder/a.txt"), "a.txt", RIGHT); assertFileAddition(c2, c1, rightResult.get(0).getChildren().get("folder/b.txt"), "b.txt", RIGHT); assertFileChange(c2, c1, rightResult.get(0).getChildren().get("folder/c.txt"), "c.txt", RIGHT); }
From source file:org.eclipse.egit.core.synchronize.GitCommitsModelCacheTest.java
License:Open Source License
@Test public void shouldListAllTypeOfChangesInsideSeparateFoldersInOneCommit() throws Exception { // given/* w ww.ja v a 2s .c o m*/ Git git = new Git(db); writeTrashFile(db, "folder/a.txt", "a content"); writeTrashFile(db, "folder2/c.txt", "c content"); git.add().addFilepattern("folder/a.txt").call(); git.add().addFilepattern("folder2/c.txt").call(); RevCommit c1 = commit(git, "first commit"); deleteTrashFile(db, "folder/a.txt"); writeTrashFile(db, "folder1/b.txt", "b content"); writeTrashFile(db, "folder2/c.txt", "new c content"); git.add().addFilepattern("folder1/b.txt").call(); RevCommit c2 = commit(git, "second commit"); // when List<Commit> leftResult = GitCommitsModelCache.build(db, c1, c2, null); List<Commit> rightResult = GitCommitsModelCache.build(db, c2, c1, null); // then // left assertions assertThat(leftResult, notNullValue()); assertThat(Integer.valueOf(leftResult.size()), is(Integer.valueOf(1))); assertThat(leftResult.get(0).getShortMessage(), is("second commit")); assertThat(leftResult.get(0).getChildren(), notNullValue()); assertThat(leftResult.get(0).getChildren().size(), is(3)); assertFileAddition(c1, c2, leftResult.get(0).getChildren().get("folder/a.txt"), "a.txt", LEFT); assertFileDeletion(c1, c2, leftResult.get(0).getChildren().get("folder1/b.txt"), "b.txt", LEFT); assertFileChange(c1, c2, leftResult.get(0).getChildren().get("folder2/c.txt"), "c.txt", LEFT); // right asserts assertThat(rightResult, notNullValue()); assertThat(Integer.valueOf(rightResult.size()), is(Integer.valueOf(1))); assertThat(rightResult.get(0).getShortMessage(), is("second commit")); assertThat(rightResult.get(0).getChildren(), notNullValue()); assertThat(rightResult.get(0).getChildren().size(), is(3)); assertFileDeletion(c2, c1, rightResult.get(0).getChildren().get("folder/a.txt"), "a.txt", RIGHT); assertFileAddition(c2, c1, rightResult.get(0).getChildren().get("folder1/b.txt"), "b.txt", RIGHT); assertFileChange(c2, c1, rightResult.get(0).getChildren().get("folder2/c.txt"), "c.txt", RIGHT); }
From source file:org.eclipse.egit.core.synchronize.GitResourceVariantComparatorTest.java
License:Open Source License
@Before public void setUp() throws Exception { super.setUp(); iProject = project.project;/* w ww. j av a2 s.c o m*/ testRepo = new TestRepository(gitDir); testRepo.connect(iProject); repo = RepositoryMapping.getMapping(iProject).getRepository(); // make initial commit new Git(repo).commit().setAuthor("JUnit", "junit@jgit.org").setMessage("Initall commit").call(); }
From source file:org.eclipse.egit.core.synchronize.GitResourceVariantTreeTest.java
License:Open Source License
/** * roots() method should return list of projects that are associated with * given repository. In this case there is only one project associated with * this repository therefore only one root should be returned. * * @throws Exception//from w ww .jav a2 s .c om */ @Test public void shouldReturnOneRoot() throws Exception { // when new Git(repo).commit().setAuthor("JUnit", "junit@egit.org").setMessage("Initial commit").call(); GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, HEAD, false); GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data); // given GitResourceVariantTree grvt = new GitTestResourceVariantTree(dataSet, null); // then assertEquals(1, grvt.roots().length); IResource actualProject = grvt.roots()[0]; assertEquals(this.project.getProject(), actualProject); }
From source file:org.eclipse.egit.core.synchronize.GitResourceVariantTreeTest.java
License:Open Source License
/** * When we have two or more project associated with repository, roots() * method should return list of project. In this case we have two project * associated with particular repository, therefore '2' value is expected. * * @throws Exception//w ww. ja v a2 s. c o m */ @Test public void shouldReturnTwoRoots() throws Exception { // when // create second project TestProject secondProject = new TestProject(true, "Project-2"); IProject secondIProject = secondProject.project; // add connect project with repository new ConnectProviderOperation(secondIProject, gitDir).execute(null); new Git(repo).commit().setAuthor("JUnit", "junit@egit.org").setMessage("Initial commit").call(); GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, HEAD, false); GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data); // given GitResourceVariantTree grvt = new GitTestResourceVariantTree(dataSet, null); // then IResource[] roots = grvt.roots(); // sort in order to be able to assert the project instances Arrays.sort(roots, new Comparator<IResource>() { public int compare(IResource r1, IResource r2) { String path1 = r1.getFullPath().toString(); String path2 = r2.getFullPath().toString(); return path1.compareTo(path2); } }); assertEquals(2, roots.length); IResource actualProject = roots[0]; assertEquals(this.project.project, actualProject); IResource actualProject1 = roots[1]; assertEquals(secondIProject, actualProject1); }
From source file:org.eclipse.egit.core.synchronize.GitResourceVariantTreeTest.java
License:Open Source License
/** * Checks that getResourceVariant will not throw NPE for null argument. This * method is called with null argument when local or remote resource does * not exist.//from www.j ava 2 s . com * * @throws Exception */ @Test public void shouldReturnNullResourceVariant() throws Exception { // when new Git(repo).commit().setAuthor("JUnit", "junit@egit.org").setMessage("Initial commit").call(); GitSynchronizeData data = new GitSynchronizeData(repo, HEAD, MASTER, false); GitSynchronizeDataSet dataSet = new GitSynchronizeDataSet(data); // given GitResourceVariantTree grvt = new GitRemoteResourceVariantTree(dataSet); // then assertNull(grvt.getResourceVariant(null)); }