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.StagedChangeCacheTest.java

License:Open Source License

@Test
public void shouldListTwoWorkspaceChanges() throws Exception {
    // given//w  ww.  j a  v a  2s  .co  m
    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 commmit").call();
    writeTrashFile(db, "a.txt", "modification");
    writeTrashFile(db, "b.txt", "modification");
    git.add().addFilepattern("a.txt").addFilepattern("b.txt").call();

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

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

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

License:Open Source License

@Test
public void shouldListSingleWorkspaceChangeInFolder() throws Exception {
    // given//from   w  w w.j  a va  2s  .  com
    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/*  www .  j  av a 2 s.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//from w  w w .  jav  a2 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(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// w ww  .ja 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  ava  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(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//ww  w.j a va2 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(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/*  w w w.j ava  2s . 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(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//ww w .j a  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(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 www. j av  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();
    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"));
}