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

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

Introduction

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

Prototype

public AddCommand add() 

Source Link

Document

Return a command object to execute a Add command

Usage

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

License:Open Source License

@Test
public void shouldListChangesInsideSeparateFoldersInCommit() throws Exception {
    // given//w w  w. j ava  2s .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//  w w  w  .ja v  a  2s  . co  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/*from ww w .  j  a  v a2s.  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 w w w .j  ava2  s  .  com
    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/*from   ww  w  . ja  v a  2 s .  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.StagedChangeCacheTest.java

License:Open Source License

@Test
public void shouldListSingleWorkspaceDeletion() throws Exception {
    // given/*from w ww .j a  va2  s.  c  o m*/
    Git git = new Git(db);
    writeTrashFile(db, "a.txt", "trash");
    git.add().addFilepattern("a.txt").call();
    git.commit().setMessage("initial add").call();
    git.rm().addFilepattern("a.txt").call();

    // when
    Map<String, Change> result = StagedChangeCache.build(db);

    // then
    assertThat(result.size(), is(1));
    assertFileDeletion(result, "a.txt", "a.txt");
}

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

License:Open Source License

@Test
public void shouldListTwoWorkspaceDeletions() throws Exception {
    // given// w ww. j  a va2s  .c om
    Git git = new Git(db);
    writeTrashFile(db, "a.txt", "trash");
    writeTrashFile(db, "b.txt", "trash");
    git.add().addFilepattern("a.txt").addFilepattern("b.txt").call();
    git.commit().setMessage("new commit").call();
    git.rm().addFilepattern("a.txt").addFilepattern("b.txt").call();

    // when
    Map<String, Change> result = StagedChangeCache.build(db);

    // then
    assertThat(result.size(), is(2));
    assertFileDeletion(result, "a.txt", "a.txt");
    assertFileDeletion(result, "b.txt", "b.txt");
}

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

License:Open Source License

@Test
public void shouldListSingleWorkspaceDeletionInFolder() throws Exception {
    // given/*from w  ww  .  j  a va 2 s .  c  o  m*/
    Git git = new Git(db);
    writeTrashFile(db, "folder/a.txt", "trash");
    git.add().addFilepattern("folder/a.txt").call();
    git.commit().setMessage("new commit").call();
    git.rm().addFilepattern("folder/a.txt").call();

    // when
    Map<String, Change> result = StagedChangeCache.build(db);

    // then
    assertThat(result.size(), is(1));
    assertFileDeletion(result, "folder/a.txt", "a.txt");
}

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

License:Open Source License

@Test
public void shouldListTwoWorkspaceDeletionsInFolder() throws Exception {
    // given//from   w  w  w. j ava2  s . com
    Git git = new Git(db);
    writeTrashFile(db, "folder/a.txt", "trash");
    writeTrashFile(db, "folder/b.txt", "trash");
    git.add().addFilepattern("folder/a.txt").addFilepattern("folder/b.txt").call();
    git.commit().setMessage("new commit").call();
    git.rm().addFilepattern("folder/a.txt").call();
    git.rm().addFilepattern("folder/b.txt").call();

    // when
    Map<String, Change> result = StagedChangeCache.build(db);

    // then
    assertThat(result.size(), is(2));
    assertFileDeletion(result, "folder/a.txt", "a.txt");
    assertFileDeletion(result, "folder/b.txt", "b.txt");
}

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

License:Open Source License

@Test
public void shouldListSingleWorkspaceChange() throws Exception {
    // given/*from  w  w  w  .  ja v  a 2 s  .  co m*/
    Git git = new Git(db);
    writeTrashFile(db, "a.txt", "trash");
    git.add().addFilepattern("a.txt").call();
    git.commit().setMessage("initial a.txt commit").call();
    writeTrashFile(db, "a.txt", "modification");
    git.add().addFilepattern("a.txt").call();

    // when
    Map<String, Change> result = StagedChangeCache.build(db);

    // then
    assertThat(result.size(), is(1));
    assertFileChange(result, "a.txt", "a.txt");
}