List of usage examples for org.eclipse.jgit.api Git Git
public Git(Repository repo)
From source file:org.eclipse.egit.ui.view.synchronize.AbstractSynchronizeViewTest.java
License:Open Source License
protected void createTag(String tagName) throws Exception { new Git(lookupRepository(repositoryFile)).tag().setName(tagName).setMessage(tagName).call(); }
From source file:org.eclipse.egit.ui.view.synchronize.SynchronizeViewGitChangeSetModelTest.java
License:Open Source License
@Test public void shouldStagePartialChangeInCompareEditor() throws Exception { // given//from w w w.ja v a 2 s.c om changeFilesInProject(); launchSynchronization(HEAD, HEAD, true); getCompareEditorForFileInGitChangeSet(FILE1, true).bot(); // when Display.getDefault().syncExec(new Runnable() { public void run() { CommonUtils.runCommand("org.eclipse.compare.copyLeftToRight", null); } }); bot.activeEditor().save(); // then file FILE1 should be in index FileRepository repo = lookupRepository(repositoryFile); Status status = new Git(repo).status().call(); assertThat(Long.valueOf(status.getChanged().size()), is(Long.valueOf(1L))); assertThat(status.getChanged().iterator().next(), is(PROJ1 + "/" + FOLDER + "/" + FILE1)); }
From source file:org.eclipse.egit.ui.view.synchronize.SynchronizeViewGitChangeSetModelTest.java
License:Open Source License
@Test public void shouldUnStagePartialChangeInCompareEditor() throws Exception { // given/*from w ww. j a va2 s. c o m*/ changeFilesInProject(); launchSynchronization(HEAD, HEAD, true); getCompareEditorForFileInGitChangeSet(FILE1, true).bot(); // when Display.getDefault().syncExec(new Runnable() { public void run() { CommonUtils.runCommand("org.eclipse.compare.copyRightToLeft", null); } }); bot.activeEditor().save(); // then file FILE1 should be unchanged in working tree FileRepository repo = lookupRepository(repositoryFile); Status status = new Git(repo).status().call(); assertThat(Long.valueOf(status.getModified().size()), is(Long.valueOf(1))); assertThat(status.getModified().iterator().next(), is(PROJ1 + "/" + FOLDER + "/" + FILE2)); }
From source file:org.eclipse.emf.compare.diagram.papyrus.tests.egit.fixture.GitTestRepository.java
License:Open Source License
/** * Adds all changes and creates a commit. * /*from w ww . j a v a 2 s .co m*/ * @param commitMessage * The commit message. * @param addDeleted * Specifies whether missing or deleted files should added to * index, too. * @return The reference to the created commit. * @throws Exception * if anything goes wrong. */ public RevCommit addAllAndCommit(String commitMessage, boolean addDeleted) throws Exception { Git git = new Git(repository); try { git.add().addFilepattern(".").call(); if (addDeleted) { addDeletedFiles(); } return commit(commitMessage); } finally { git.close(); } }
From source file:org.eclipse.emf.compare.diagram.papyrus.tests.egit.fixture.GitTestRepository.java
License:Open Source License
/** * Adds all missing or deleted files to the index. * /* w ww . j a va2 s .c om*/ * @throws Exception * if anything goes wrong. */ public void addDeletedFiles() throws Exception { Git git = new Git(repository); try { Status status = git.status().call(); if (!status.getMissing().isEmpty() || !status.getRemoved().isEmpty()) { RmCommand rm = git.rm(); for (String deletedFile : Iterables.concat(status.getMissing(), status.getRemoved())) { rm.addFilepattern(deletedFile); } rm.call(); } } finally { git.close(); } }
From source file:org.eclipse.emf.compare.diagram.papyrus.tests.egit.fixture.GitTestRepository.java
License:Open Source License
/** * Adds all changes and amends the latest commit, also changing its message to the given message. * /*from w w w.jav a 2 s .c om*/ * @param message * the amended commit message, must not be null * @return The RevCommit of the amended commit. * @throws Exception * if anything goes wrong. */ public RevCommit addAllAndAmend(String message) throws Exception { Git git = new Git(repository); try { git.add().addFilepattern(".").call(); return git.commit().setAmend(true).setMessage(message).call(); } finally { git.close(); } }
From source file:org.eclipse.emf.compare.diagram.papyrus.tests.egit.fixture.GitTestRepository.java
License:Open Source License
/** * Adds the given resource to the index//ww w .j ava2 s . c om * * @param resource * @throws CoreException * @throws IOException * @throws GitAPIException * @throws NoFilepatternException */ public void addToIndex(IResource resource) throws CoreException, IOException, NoFilepatternException, GitAPIException { String repoPath = getRepoRelativePath(resource.getLocation().toString()); Git git = new Git(repository); try { git.add().addFilepattern(repoPath).call(); } finally { git.close(); } }
From source file:org.eclipse.emf.compare.diagram.papyrus.tests.egit.fixture.GitTestRepository.java
License:Open Source License
/** * Adds the given resources to the index * // w w w .j a v a 2 s . c o m * @param resources * Resources to add to the index. */ public void addToIndex(IResource... resources) throws CoreException, IOException, NoFilepatternException, GitAPIException { Git git = new Git(repository); try { for (IResource resource : resources) { String repoPath = getRepoRelativePath(resource.getLocation().toString()); git.add().addFilepattern(repoPath).call(); } } finally { git.close(); } }
From source file:org.eclipse.emf.compare.diagram.papyrus.tests.egit.fixture.GitTestRepository.java
License:Open Source License
/** * Adds the given resources to the index * /*from w ww . jav a2s .co m*/ * @param resources * Resources to add to the index. */ public void removeFromIndex(IResource... resources) throws CoreException, IOException, NoFilepatternException, GitAPIException { Git git = new Git(repository); try { for (IResource resource : resources) { String repoPath = getRepoRelativePath(resource.getLocation().toString()); git.rm().addFilepattern(repoPath).call(); } } finally { git.close(); } }