List of usage examples for org.eclipse.jgit.api Git open
public static Git open(File dir) throws IOException
From source file:com.romanenco.gitt.git.GitHelper.java
License:Open Source License
/** * Read log messages, up to maxRecords//from w ww .j a va2 s. c o m * * @param repoPath * @param maxRecords * @return */ public static List<LogEntry> readRepoHistory(String repoPath, int maxRecords) { ArrayList<LogEntry> result = new ArrayList<GitHelper.LogEntry>(maxRecords); try { Git git = Git.open(new File(repoPath)); Iterable<RevCommit> logs = git.log().call(); for (RevCommit commit : logs) { result.add(new LogEntry(commit)); if (--maxRecords == 0) break; } } catch (IOException e) { Log.e(TAG, "IO", e); } catch (NoHeadException e) { Log.e(TAG, "NoHead", e); } catch (GitAPIException e) { Log.e(TAG, "GitApi", e); } if (maxRecords > 0) { result.trimToSize(); } return result; }
From source file:com.sebastian_daschner.asciiblog.business.source.control.GitExtractorTest.java
License:Apache License
private void changeAndRenameFile() throws IOException, GitAPIException { final Git git = Git.open(gitCloneDirectory); git.pull().setRemote("origin").setRemoteBranchName("master").call(); try (FileWriter writer = new FileWriter(file2, true)) { writer.append("\nchanged"); }// w w w.j a v a2 s . c o m if (!file2.renameTo(file2.toPath().resolveSibling("file3.adoc").toFile())) throw new IOException("Could not rename file2 to file3"); git.add().setUpdate(true).addFilepattern(".").call(); git.add().addFilepattern(".").call(); git.commit().setMessage("changed file2 and renamed to file3").call(); git.push().setRemote("origin").add("master").call(); git.close(); }
From source file:com.sebastian_daschner.asciiblog.business.source.control.GitExtractorTest.java
License:Apache License
private void addTestCommits() throws IOException, GitAPIException { final Git git = Git.open(gitCloneDirectory); try (FileWriter writer = new FileWriter(file1, true)) { writer.write("hello world"); }/*from w w w . j ava 2 s . c o m*/ git.add().addFilepattern(".").call(); git.commit().setMessage("updated").call(); try (FileWriter writer = new FileWriter(file1, true)) { writer.append("\nhello world"); } git.add().addFilepattern(".").call(); git.commit().setMessage("updated").call(); try (FileWriter writer = new FileWriter(file2, true)) { writer.write("hi world"); } git.add().addFilepattern(".").call(); git.commit().setMessage("updated").call(); git.push().setRemote("origin").add("master").call(); git.close(); }
From source file:com.sebastian_daschner.asciiblog.business.source.control.GitExtractorTest.java
License:Apache License
private void createNextCommit() throws IOException, GitAPIException { final Git git = Git.open(gitCloneDirectory); git.pull().setRemote("origin").setRemoteBranchName("master").call(); try (FileWriter writer = new FileWriter(file1, true)) { writer.write("hi world!\nhello hi"); }/*from w ww .ja v a 2s. co m*/ git.add().addFilepattern(".").call(); git.commit().setMessage("updated file1").call(); try (FileWriter writer = new FileWriter(file2, true)) { writer.write("world"); } git.add().addFilepattern(".").call(); git.commit().setMessage("updated file2").call(); git.push().setRemote("origin").add("master").call(); git.close(); }
From source file:com.sebastian_daschner.asciiblog.business.source.control.GitExtractorTest.java
License:Apache License
private void renameFile() throws IOException, GitAPIException { final Git git = Git.open(gitCloneDirectory); git.pull().setRemote("origin").setRemoteBranchName("master").call(); if (!file2.renameTo(file2.toPath().resolveSibling("file3.adoc").toFile())) throw new IOException("Could not rename file2 to file3"); git.add().setUpdate(true).addFilepattern(".").call(); git.add().addFilepattern(".").call(); git.commit().setMessage("renamed file2 to file3").call(); git.push().setRemote("origin").add("master").call(); git.close();/*from w w w. j a v a 2 s . c o m*/ }
From source file:com.sebastian_daschner.asciiblog.business.source.control.GitExtractorTest.java
License:Apache License
private void deleteFile() throws IOException, GitAPIException { final Git git = Git.open(gitCloneDirectory); git.pull().setRemote("origin").setRemoteBranchName("master").call(); if (!file2.delete()) throw new IOException("Could not delete file2"); git.add().setUpdate(true).addFilepattern(".").call(); git.commit().setMessage("deleted file2").call(); git.push().setRemote("origin").add("master").call(); git.close();/*from w w w . j a va2 s. c o m*/ }
From source file:com.sebastian_daschner.asciiblog.business.source.control.GitExtractorTest.java
License:Apache License
private void addNotRelevantFile(final String fileName) throws GitAPIException, IOException { final Git git = Git.open(gitCloneDirectory); git.pull().setRemote("origin").setRemoteBranchName("master").call(); try (FileWriter writer = new FileWriter(file1.toPath().resolveSibling(fileName + ".mustache").toFile(), true)) {//from w w w . j av a 2 s . c o m writer.write("hello {{world}}"); } git.add().addFilepattern(".").call(); git.commit().setMessage("added template").call(); git.push().setRemote("origin").add("master").call(); git.close(); }
From source file:com.stormcloud.ide.api.git.GitManager.java
License:Open Source License
@Override public IndexState getIndexState(String repository) throws GitManagerException { IndexState indexState = new IndexState(); try {//from ww w.j a v a 2 s . c om Git git = Git.open(new File(repository)); IndexDiff diff = new IndexDiff(git.getRepository(), "HEAD", new FileTreeIterator(git.getRepository())); diff.diff(); indexState.setAdded(diff.getAdded()); indexState.setAssumeUnchanged(diff.getAssumeUnchanged()); indexState.setChanged(diff.getChanged()); indexState.setConflicting(diff.getConflicting()); indexState.setIgnoredNotInIndex(diff.getIgnoredNotInIndex()); indexState.setMissing(diff.getMissing()); indexState.setModified(diff.getModified()); indexState.setRemoved(diff.getRemoved()); indexState.setUntracked(diff.getUntracked()); indexState.setUntrackedFolders(diff.getUntrackedFolders()); } catch (IOException e) { LOG.error(e); throw new GitManagerException(e); } return indexState; }
From source file:com.stormcloud.ide.api.git.GitManager.java
License:Open Source License
@Override public boolean isModified(String repository) throws GitManagerException { try {/*from www . ja v a 2 s . com*/ Git git = Git.open(new File(repository)); IndexDiff diff = new IndexDiff(git.getRepository(), "HEAD", new FileTreeIterator(git.getRepository())); diff.diff(); if (!diff.getAdded().isEmpty()) { return true; } if (!diff.getChanged().isEmpty()) { return true; } if (!diff.getMissing().isEmpty()) { return true; } if (!diff.getModified().isEmpty()) { return true; } if (!diff.getRemoved().isEmpty()) { return true; } if (!diff.getUntracked().isEmpty()) { return true; } if (!diff.getUntrackedFolders().isEmpty()) { return true; } } catch (IOException e) { LOG.error(e); throw new GitManagerException(e); } return false; }
From source file:com.stormcloud.ide.api.git.GitManager.java
License:Open Source License
@Override public DirCache add(String repository, String pattern) throws GitManagerException { try {//from w w w. j a v a2 s . c o m Git git = Git.open(new File(repository)); AddCommand add = git.add(); add.addFilepattern(pattern); DirCache result = add.call(); return result; } catch (IOException e) { LOG.error(e); throw new GitManagerException(e); } catch (GitAPIException e) { LOG.error(e); throw new GitManagerException(e); } }