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.storage.GitBlobStorageTest.java

License:Open Source License

@Test
public void testGitFileHistorySingleProjectOk() throws Exception {
    IProgressMonitor progress = new NullProgressMonitor();
    TestProject singleRepoProject = new TestProject(true, "Project-2");
    IProject proj = singleRepoProject.getProject();
    File singleProjectGitDir = new File(proj.getLocation().toFile(), Constants.DOT_GIT);
    if (singleProjectGitDir.exists())
        FileUtils.delete(singleProjectGitDir, FileUtils.RECURSIVE | FileUtils.RETRY);

    Repository singleProjectRepo = FileRepositoryBuilder.create(singleProjectGitDir);
    singleProjectRepo.create();//from  w  w w .  j a v  a 2s.com

    // Repository must be mapped in order to test the GitFileHistory
    Activator.getDefault().getRepositoryUtil().addConfiguredRepository(singleProjectGitDir);
    ConnectProviderOperation connectOp = new ConnectProviderOperation(proj, singleProjectGitDir);
    connectOp.execute(progress);

    try {
        IFile file = proj.getFile("file");
        file.create(new ByteArrayInputStream("data".getBytes("UTF-8")), 0, progress);
        Git git = new Git(singleProjectRepo);
        git.add().addFilepattern(".").call();
        RevCommit commit = git.commit().setAuthor("JUnit", "junit@jgit.org").setAll(true)
                .setMessage("First commit").call();

        GitFileHistoryProvider fhProvider = new GitFileHistoryProvider();
        IFileHistory fh = fhProvider.getFileHistoryFor(singleRepoProject.getProject(), 0, null);
        assertNotNull(fh);
        assertEquals(fh.getFileRevisions().length, 1);
        assertNotNull(fh.getFileRevision(commit.getId().getName()));
    } finally {
        DisconnectProviderOperation disconnectOp = new DisconnectProviderOperation(
                Collections.singletonList(proj));
        disconnectOp.execute(progress);
        Activator.getDefault().getRepositoryUtil().removeDir(singleProjectGitDir);
        singleProjectRepo.close();
        singleRepoProject.dispose();
    }
}

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

License:Open Source License

@Before
@Override//from  www  .  j  a va 2 s. c  o  m
// copied from org.eclipse.jgit.lib.RepositoryTestCase
public void setUp() throws Exception {
    super.setUp();
    db = createWorkRepository();
    Git git = new Git(db);
    git.commit().setMessage("initial commit").call();
    git.tag().setName(INITIAL_TAG).call();
}

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

License:Open Source License

private RevCommit commit(Git git, String msg) throws Exception {
    tick();/* w  w  w. j  a v a 2s  .  c  o  m*/
    return git.commit().setAll(true).setMessage(msg).setCommitter(committer).call();
}

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

License:Open Source License

private RevCommit commit() throws Exception {
    Git git = new Git(repo);
    CommitCommand commit = git.commit();
    commit.setMessage("Initial  commit");
    commit.setAuthor("EGit", "egi@eclipse.org");
    return commit.call();
}

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

License:Open Source License

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