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

License:Open Source License

@Test
public void shouldListTwoWorkspaceDeletions() throws Exception {
    // given/*  w  ww  .ja v  a2s  . com*/
    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/*w  w w  . j ava 2  s  . c om*/
    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 ww  .  j a  v  a  2  s.co  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();
    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//  ww w .ja va 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");
}

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

License:Open Source License

@Test
public void shouldListTwoWorkspaceChanges() throws Exception {
    // given/*from  www .  j  a v  a2s .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 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// w  ww  . j  a va  2s.  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//from  w w w .  j  a 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 .j a 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(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   ww  w .j a v 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(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 av a  2  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(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"));
}