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

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

Introduction

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

Prototype

public CommitCommand commit() 

Source Link

Document

Return a command object to execute a Commit command

Usage

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

License:Open Source License

@Test
public void shouldListSingleWorkspaceChangeInFolder() throws Exception {
    // given/*from  ww w . jav  a 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();
    writeTrashFile(db, "folder/a.txt", "modification");
    git.add().addFilepattern("folder/a.txt").call();

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

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

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

License:Open Source License

@Test
public void shouldListTwoWorkspaceChagneInFolder() throws Exception {
    // given// w w w . ja  v  a 2s  . c  o  m
    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();
    writeTrashFile(db, "folder/a.txt", "modification");
    writeTrashFile(db, "folder/b.txt", "modification");
    git.add().addFilepattern("folder/a.txt").addFilepattern("folder/b.txt").call();

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

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

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

License:Open Source License

@Test
public void shouldListOutgoingAddition() throws Exception {
    // given/* w  ww  .  jav a 2s  .c  o  m*/
    writeTrashFile("a.txt", "content");
    Git git = new Git(db);
    git.add().addFilepattern("a.txt").call();
    RevCommit c = git.commit().setMessage("initial commit").call();

    // when
    TreeWalk walk = new TreeWalk(db);
    walk.addTree(c.getTree());
    walk.addTree(new EmptyTreeIterator());
    walk.addTree(new EmptyTreeIterator());
    List<ThreeWayDiffEntry> result = ThreeWayDiffEntry.scan(walk);

    // then
    assertThat(result, notNullValue());
    assertThat(Integer.valueOf(result.size()), is(Integer.valueOf(1)));

    ThreeWayDiffEntry entry = result.get(0);
    assertThat(entry.getDirection(), is(Direction.OUTGOING));
    assertThat(entry.getChangeType(), is(ChangeType.ADD));
    assertThat(entry.getPath(), is("a.txt"));
}

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

License:Open Source License

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

    // when
    TreeWalk walk = new TreeWalk(db);
    walk.addTree(new EmptyTreeIterator());
    walk.addTree(new EmptyTreeIterator());
    walk.addTree(c.getTree());
    List<ThreeWayDiffEntry> result = ThreeWayDiffEntry.scan(walk);

    // then
    assertThat(result, notNullValue());
    assertThat(Integer.valueOf(result.size()), is(Integer.valueOf(1)));

    ThreeWayDiffEntry entry = result.get(0);
    assertThat(entry.getDirection(), is(Direction.INCOMING));
    assertThat(entry.getChangeType(), is(ChangeType.ADD));
    assertThat(entry.getPath(), is("a.txt"));
}

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

License:Open Source License

@Test
public void shouldListOutgoingDelete() throws Exception {
    // given/*from   ww  w.j a  v a2 s  .  c om*/
    writeTrashFile("a.txt", "content");
    Git git = new Git(db);
    git.add().addFilepattern("a.txt").call();
    RevCommit c = git.commit().setMessage("initial commit").call();

    // when
    TreeWalk walk = new TreeWalk(db);
    walk.addTree(new EmptyTreeIterator());
    walk.addTree(c.getTree());
    walk.addTree(c.getTree());
    List<ThreeWayDiffEntry> result = ThreeWayDiffEntry.scan(walk);

    // then
    assertThat(result, notNullValue());
    assertThat(Integer.valueOf(result.size()), is(Integer.valueOf(1)));

    ThreeWayDiffEntry entry = result.get(0);
    assertThat(entry.getDirection(), is(Direction.OUTGOING));
    assertThat(entry.getChangeType(), is(ChangeType.DELETE));
    assertThat(entry.getPath(), is("a.txt"));
}

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

License:Open Source License

@Test
public void shouldListIncomingDelete() throws Exception {
    // given/*w w  w  .  ja v a  2 s.c  o  m*/
    writeTrashFile("a.txt", "content");
    Git git = new Git(db);
    git.add().addFilepattern("a.txt").call();
    RevCommit c = git.commit().setMessage("initial commit").call();

    // when
    TreeWalk walk = new TreeWalk(db);
    walk.addTree(c.getTree());
    walk.addTree(c.getTree());
    walk.addTree(new EmptyTreeIterator());
    List<ThreeWayDiffEntry> result = ThreeWayDiffEntry.scan(walk);

    // then
    assertThat(result, notNullValue());
    assertThat(Integer.valueOf(result.size()), is(Integer.valueOf(1)));

    ThreeWayDiffEntry entry = result.get(0);
    assertThat(entry.getDirection(), is(Direction.INCOMING));
    assertThat(entry.getChangeType(), is(ChangeType.DELETE));
    assertThat(entry.getPath(), is("a.txt"));
}

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

License:Open Source License

@Test
public void shouldListConflictingChange() throws Exception {
    // given//from w ww .  ja v a2  s. c  o m
    writeTrashFile("a.txt", "content");
    Git git = new Git(db);
    git.add().addFilepattern("a.txt").call();
    RevCommit c = git.commit().setMessage("initial commit").call();

    // when
    TreeWalk walk = new TreeWalk(db);
    walk.addTree(new EmptyTreeIterator());
    walk.addTree(c.getTree());
    walk.addTree(new EmptyTreeIterator());
    List<ThreeWayDiffEntry> result = ThreeWayDiffEntry.scan(walk);

    // then
    assertThat(result, notNullValue());
    assertThat(Integer.valueOf(result.size()), is(Integer.valueOf(1)));

    ThreeWayDiffEntry entry = result.get(0);
    assertThat(entry.getDirection(), is(Direction.CONFLICTING));
    assertThat(entry.getChangeType(), is(ChangeType.MODIFY));
    // assertThat(entry.getNewPath(), is("a.txt"));
    // assertThat(entry.getOldPath(), is(DEV_NULL));
}

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

License:Open Source License

@Test
public void shouldListConflictingChange2() throws Exception {
    // given//from w ww . j  ava2 s.com
    writeTrashFile("a.txt", "content");
    Git git = new Git(db);
    git.add().addFilepattern("a.txt").call();
    RevCommit c = git.commit().setMessage("initial commit").call();

    // when
    TreeWalk walk = new TreeWalk(db);
    walk.addTree(c.getTree());
    walk.addTree(new EmptyTreeIterator());
    walk.addTree(c.getTree());
    List<ThreeWayDiffEntry> result = ThreeWayDiffEntry.scan(walk);

    // then
    assertThat(result, notNullValue());
    assertThat(Integer.valueOf(result.size()), is(Integer.valueOf(1)));

    ThreeWayDiffEntry entry = result.get(0);
    assertThat(entry.getDirection(), is(Direction.CONFLICTING));
    assertThat(entry.getChangeType(), is(ChangeType.MODIFY));
    assertThat(entry.getPath(), is("a.txt"));
}

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

License:Open Source License

@Test
public void shouldListIncomingModify() throws Exception {
    // given/*from   w ww  .  j a v a2  s .com*/
    writeTrashFile("a.txt", "content");
    Git git = new Git(db);
    git.add().addFilepattern("a.txt").call();
    RevCommit c = git.commit().setMessage("initial commit").call();
    writeTrashFile("a.txt", "new line");
    RevCommit c1 = git.commit().setAll(true).setMessage("second commit").call();

    // when
    TreeWalk walk = new TreeWalk(db);
    walk.addTree(c.getTree());
    walk.addTree(c.getTree());
    walk.addTree(c1.getTree());
    List<ThreeWayDiffEntry> result = ThreeWayDiffEntry.scan(walk);

    // then
    assertThat(result, notNullValue());
    assertThat(Integer.valueOf(result.size()), is(Integer.valueOf(1)));

    ThreeWayDiffEntry entry = result.get(0);
    assertThat(entry.getDirection(), is(Direction.INCOMING));
    assertThat(entry.getChangeType(), is(ChangeType.MODIFY));
    assertThat(entry.getPath(), is("a.txt"));
}

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

License:Open Source License

@Test
public void shouldListOutgoingModify() throws Exception {
    // given//from  w  w w.j  a  v a  2  s. c om
    writeTrashFile("a.txt", "content");
    Git git = new Git(db);
    git.add().addFilepattern("a.txt").call();
    RevCommit c = git.commit().setMessage("initial commit").call();
    writeTrashFile("a.txt", "newe line");
    RevCommit c1 = git.commit().setAll(true).setMessage("second commit").call();

    // when
    TreeWalk walk = new TreeWalk(db);
    walk.addTree(c1.getTree());
    walk.addTree(c.getTree());
    walk.addTree(c.getTree());
    List<ThreeWayDiffEntry> result = ThreeWayDiffEntry.scan(walk);

    // then
    assertThat(result, notNullValue());
    assertThat(Integer.valueOf(result.size()), is(Integer.valueOf(1)));

    ThreeWayDiffEntry entry = result.get(0);
    assertThat(entry.getDirection(), is(Direction.OUTGOING));
    assertThat(entry.getChangeType(), is(ChangeType.MODIFY));
    assertThat(entry.getPath(), is("a.txt"));
}