Example usage for org.eclipse.jgit.api Git Git

List of usage examples for org.eclipse.jgit.api Git Git

Introduction

In this page you can find the example usage for org.eclipse.jgit.api Git Git.

Prototype

public Git(Repository repo) 

Source Link

Document

Construct a new org.eclipse.jgit.api.Git object which can interact with the specified git repository.

Usage

From source file:org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataTest.java

License:Open Source License

@Test
public void shouldReturnSourceMergeForLocalRef() throws Exception {
    // given//from   w  ww .  j  a  v  a 2  s  .co m
    Git git = new Git(repo);
    git.branchCreate().setName("test2").setStartPoint("refs/heads/master")
            .setUpstreamMode(SetupUpstreamMode.TRACK).call();
    git.checkout().setName("test2").call();
    GitSynchronizeData gsd = new GitSynchronizeData(repo, R_HEADS + "test2", HEAD, false);

    // when
    String srcMerge = gsd.getSrcMerge();

    // then
    assertThat(srcMerge, is("refs/heads/master"));
}

From source file:org.eclipse.egit.core.synchronize.dto.GitSynchronizeDataTest.java

License:Open Source License

@Test
public void shouldReturnSourceMergeForRemoteBranch() throws Exception {
    // given//from  w ww  .  java2s  .com
    Git git = new Git(repo);
    git.branchCreate().setName("test3").setStartPoint("refs/heads/master")
            .setUpstreamMode(SetupUpstreamMode.TRACK).call();
    git.checkout().setName("test3").call();
    repo.renameRef(R_HEADS + "test3", Constants.R_REMOTES + "origin/master").rename();
    GitSynchronizeData gsd = new GitSynchronizeData(repo, "refs/remotes/origin/master", HEAD, false);

    // when
    String srcMerge = gsd.getSrcMerge();

    // then
    assertThat(srcMerge, is("refs/heads/master"));
}

From source file:org.eclipse.egit.core.synchronize.GitCommitsModelCacheTest.java

License:Open Source License

@Test
public void shouldReturnEmptyListForSameSrcAndDstCommit() throws Exception {
    // given//from   w  w w  .  j  av  a2 s. c om
    Git git = new Git(db);
    RevCommit c = commit(git, "second commit");
    // when
    List<Commit> result = GitCommitsModelCache.build(db, c, c, null);
    // then
    assertThat(result, notNullValue());
    assertThat(result.size(), is(0));
}

From source file:org.eclipse.egit.core.synchronize.GitCommitsModelCacheTest.java

License:Open Source License

@Test
public void shouldNotListEmptyCommits() throws Exception {
    // given/* w w w. jav a2s. c o  m*/
    Git git = new Git(db);
    RevCommit c = commit(git, "second commit");
    // when
    List<Commit> result = GitCommitsModelCache.build(db, initialTagId(), c, null);
    // then
    assertThat(result, notNullValue());
    assertThat(result.size(), is(0));
}

From source file:org.eclipse.egit.core.synchronize.GitCommitsModelCacheTest.java

License:Open Source License

@Test
public void shouldListAdditionOrDeletionInCommit() throws Exception {
    // given//from   w ww.  j  a v a  2 s.co m
    Git git = new Git(db);
    writeTrashFile(db, "a.txt", "content");
    git.add().addFilepattern("a.txt").call();
    RevCommit c = commit(git, "first commit");
    // when
    List<Commit> leftResult = GitCommitsModelCache.build(db, initialTagId(), c, null);
    List<Commit> rightResult = GitCommitsModelCache.build(db, c, initialTagId(), null);
    // then
    // left assertions
    assertThat(leftResult, notNullValue());
    assertCommit(leftResult.get(0), c, 1);
    assertFileDeletion(c, leftResult.get(0).getChildren().get("a.txt"), "a.txt", LEFT);
    // right asserts, after changing sides addition becomes deletion
    assertThat(rightResult, notNullValue());
    assertCommit(rightResult.get(0), c, 1);
    assertFileAddition(c, rightResult.get(0).getChildren().get("a.txt"), "a.txt", RIGHT);
}

From source file:org.eclipse.egit.core.synchronize.GitCommitsModelCacheTest.java

License:Open Source License

@Test
public void shouldListAdditionOrDeletionInsideFolderInCommit() throws Exception {
    // given/*from www . ja v a  2s. c o m*/
    Git git = new Git(db);
    writeTrashFile(db, "folder/a.txt", "content");
    git.add().addFilepattern("folder/a.txt").call();
    RevCommit c = commit(git, "first commit");
    // when
    List<Commit> leftResult = GitCommitsModelCache.build(db, initialTagId(), c, null);
    List<Commit> rightResult = GitCommitsModelCache.build(db, c, initialTagId(), null);
    // then
    // left assertions
    assertThat(leftResult, notNullValue());
    assertCommit(leftResult.get(0), c, 1);
    assertThat(leftResult.get(0).getChildren().size(), is(1));
    assertFileDeletion(c, leftResult.get(0).getChildren().get("folder/a.txt"), "a.txt", LEFT);
    // right asserts, after changing sides addition becomes deletion
    assertThat(rightResult, notNullValue());
    assertCommit(rightResult.get(0), c, 1);
    assertThat(rightResult.get(0).getChildren().size(), is(1));
    assertFileAddition(c, 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 shouldListAdditionsOrDeletionsInsideSeparateFoldersInCommit() throws Exception {
    // given//from  www.j a  va2  s .  com
    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 c = commit(git, "first commit");
    // when
    List<Commit> leftResult = GitCommitsModelCache.build(db, initialTagId(), c, null);
    List<Commit> rightResult = GitCommitsModelCache.build(db, c, initialTagId(), null);
    // then
    // left assertions
    assertThat(leftResult, notNullValue());
    assertThat(Integer.valueOf(leftResult.size()), is(Integer.valueOf(1)));
    assertThat(leftResult.get(0).getShortMessage(), is("first commit"));
    assertThat(leftResult.get(0).getChildren(), notNullValue());
    assertThat(leftResult.get(0).getChildren().size(), is(2));
    assertFileDeletion(c, leftResult.get(0).getChildren().get("folder/a.txt"), "a.txt", LEFT);
    assertFileDeletion(c, leftResult.get(0).getChildren().get("folder2/b.txt"), "b.txt", LEFT);
    // right asserts, after changing sides addition becomes deletion
    assertThat(rightResult, notNullValue());
    assertThat(Integer.valueOf(rightResult.size()), is(Integer.valueOf(1)));
    assertThat(rightResult.get(0).getShortMessage(), is("first commit"));
    assertThat(rightResult.get(0).getChildren(), notNullValue());
    assertThat(rightResult.get(0).getChildren().size(), is(2));
    assertFileAddition(c, rightResult.get(0).getChildren().get("folder/a.txt"), "a.txt", RIGHT);
    assertFileAddition(c, 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 shouldApplyPathFilter() throws Exception {
    // given/*from  ww  w .  j  av a  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 c = commit(git, "first commit");

    // when
    PathFilter pathFilter = PathFilter.create("folder");
    List<Commit> leftResult = GitCommitsModelCache.build(db, initialTagId(), c, pathFilter);
    // then
    assertThat(leftResult, notNullValue());
    assertThat(Integer.valueOf(leftResult.size()), is(Integer.valueOf(1)));
    assertThat(leftResult.get(0).getShortMessage(), is("first commit"));
    assertThat(leftResult.get(0).getChildren(), notNullValue());
    assertThat(leftResult.get(0).getChildren().size(), is(1));
    assertFileDeletion(c, leftResult.get(0).getChildren().get("folder/a.txt"), "a.txt", LEFT);
}

From source file:org.eclipse.egit.core.synchronize.GitCommitsModelCacheTest.java

License:Open Source License

@Test
public void shouldListAdditionsOrDeletionsInsideFolderInCommit() throws Exception {
    // given//from   w w  w. j a  v  a2  s .  c om
    Git git = new Git(db);
    writeTrashFile(db, "folder/a.txt", "content");
    writeTrashFile(db, "folder/b.txt", "b content");
    git.add().addFilepattern("folder").call();
    RevCommit c = commit(git, "first commit");
    // when
    List<Commit> leftResult = GitCommitsModelCache.build(db, initialTagId(), c, null);
    List<Commit> rightResult = GitCommitsModelCache.build(db, c, initialTagId(), null);
    // then
    // left assertions
    assertThat(leftResult, notNullValue());
    assertThat(Integer.valueOf(leftResult.size()), is(Integer.valueOf(1)));
    assertCommit(leftResult.get(0), c, 2);
    assertThat(leftResult.get(0).getChildren().size(), is(2));
    assertFileDeletion(c, leftResult.get(0).getChildren().get("folder/a.txt"), "a.txt", LEFT);
    assertFileDeletion(c, leftResult.get(0).getChildren().get("folder/b.txt"), "b.txt", LEFT);
    // right asserts, after changing sides addition becomes deletion
    assertThat(rightResult, notNullValue());
    assertThat(Integer.valueOf(rightResult.size()), is(Integer.valueOf(1)));
    assertCommit(rightResult.get(0), c, 2);
    assertThat(rightResult.get(0).getChildren().size(), is(2));
    assertFileAddition(c, rightResult.get(0).getChildren().get("folder/a.txt"), "a.txt", RIGHT);
    assertFileAddition(c, 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 shouldListChangeInCommit() throws Exception {
    // given//from w w w .  j  a v a2  s.  c o m
    Git git = new Git(db);
    writeTrashFile(db, "a.txt", "content");
    git.add().addFilepattern("a.txt").call();
    RevCommit c1 = commit(git, "first commit");
    writeTrashFile(db, "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("a.txt"), "a.txt", LEFT);
    // right asserts
    assertThat(rightResult, notNullValue());
    assertCommit(rightResult.get(0), c2, 1);
    assertFileChange(c2, c1, rightResult.get(0).getChildren().get("a.txt"), "a.txt", RIGHT);
}