List of usage examples for org.eclipse.jgit.api Git Git
public Git(Repository repo)
From source file:org.dstadler.jgit.porcelain.WalkAllCommits.java
License:Apache License
public static void main(String[] args) throws IOException, GitAPIException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { try (Git git = new Git(repository)) { Iterable<RevCommit> commits = git.log().all().call(); int count = 0; for (RevCommit commit : commits) { System.out.println("LogCommit: " + commit); count++;// w ww. j ava 2 s.c o m } System.out.println(count); } } }
From source file:org.dstadler.jgit.unfinished.ListRefLog.java
License:Apache License
private static void listReflog(Repository repository, Ref ref) throws GitAPIException { /*/*from w w w . j ava 2s . c om*/ * Ref head = repository.getRef(ref.getName()); * RevWalk walk = new RevWalk(repository); * RevCommit commit = walk.parseCommit(head.getObjectId()); */ try (Git git = new Git(repository)) { Collection<ReflogEntry> call = git.reflog().setRef(ref.getName()).call(); for (ReflogEntry reflog : call) { System.out.println("Reflog: " + reflog); } } }
From source file:org.dstadler.jgit.unfinished.PullFromRemoteRepository.java
License:Apache License
public static void main(String[] args) throws IOException, GitAPIException { // prepare a new folder for the cloned repository File localPath = File.createTempFile("TestGitRepository", ""); if (!localPath.delete()) { throw new IOException("Could not delete temporary file " + localPath); }/*from w w w .jav a 2 s. co m*/ // then clone System.out.println("Cloning from " + REMOTE_URL + " to " + localPath); try (Git result = Git.cloneRepository().setURI(REMOTE_URL).setDirectory(localPath).call()) { // Note: the call() returns an opened repository already which needs to be closed to avoid file handle leaks! System.out.println("Having repository: " + result.getRepository().getDirectory()); try (Git git = new Git(result.getRepository())) { git.pull().call(); } System.out.println("Pulled from remote repository to local repository at " + result.getRepository().getDirectory()); } }
From source file:org.dstadler.jgit.unfinished.PullRemoteRepository.java
License:Apache License
public static void main(String[] args) throws IOException, GitAPIException { try (Repository repository = cloneRepository()) { System.out.println("Having repository: " + repository.getDirectory() + " with head: " + repository.findRef(Constants.HEAD) + "/" + repository.resolve("HEAD") + "/" + repository.resolve("refs/heads/master")); // TODO: why do we get null here for HEAD?!? See also // http://stackoverflow.com/questions/17979660/jgit-pull-noheadexception try (Git git = new Git(repository)) { PullResult call = git.pull().call(); System.out.println("Pulled from the remote repository: " + call); }//from w ww . j a v a 2s.c o m } }
From source file:org.dstadler.jgit.unfinished.PushToRemoteRepository.java
License:Apache License
public static void main(String[] args) throws IOException, GitAPIException { // prepare a new folder for the cloned repository File localPath = File.createTempFile("TestGitRepository", ""); if (!localPath.delete()) { throw new IOException("Could not delete temporary file " + localPath); }/*from w ww . j av a2s.c o m*/ // then clone System.out.println("Cloning from " + REMOTE_URL + " to " + localPath); try (Git result = Git.cloneRepository().setURI(REMOTE_URL).setDirectory(localPath).call()) { // prepare a second folder for the 2nd clone File localPath2 = File.createTempFile("TestGitRepository", ""); if (!localPath2.delete()) { throw new IOException("Could not delete temporary file " + localPath2); } // then clone again System.out.println("Cloning from file://" + localPath + " to " + localPath2); try (Git result2 = Git.cloneRepository().setURI("file://" + localPath).setDirectory(localPath2) .call()) { System.out.println("Result: " + result2); // now open the created repository FileRepositoryBuilder builder = new FileRepositoryBuilder(); try (Repository repository = builder.setGitDir(localPath2).readEnvironment() // scan environment GIT_* variables .findGitDir() // scan up the file system tree .build()) { try (Git git = new Git(repository)) { git.push().call(); } System.out.println("Pushed from repository: " + repository.getDirectory() + " to remote repository at " + REMOTE_URL); } } } }
From source file:org.dstadler.jgit.unfinished.TrackMaster.java
License:Apache License
public static void main(String[] args) throws IOException, GitAPIException { // prepare a new folder for the cloned repository File localPath = File.createTempFile("TestGitRepository", ""); if (!localPath.delete()) { throw new IOException("Could not delete temporary file " + localPath); }// w w w . j av a 2s . co m // then clone System.out.println("Cloning from " + REMOTE_URL + " to " + localPath); try (Git result = Git.cloneRepository().setURI(REMOTE_URL).setDirectory(localPath).call()) { System.out.println("Result: " + result); // now open the created repository FileRepositoryBuilder builder = new FileRepositoryBuilder(); try (Repository repository = builder.setGitDir(localPath).readEnvironment() // scan environment GIT_* variables .findGitDir() // scan up the file system tree .build()) { try (Git git = new Git(repository)) { git.branchCreate().setName("master") // ?!? .setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM) .setStartPoint("origin/master").setForce(true).call(); } System.out.println("Now tracking master in repository at " + repository.getDirectory() + " from origin/master at " + REMOTE_URL); } } }
From source file:org.dstadler.jgit.unfinished.UpdateIndex.java
License:Apache License
public static void main(String[] args) throws IOException, GitAPIException { try (final Repository repo = CookbookHelper.openJGitCookbookRepository()) { try (final Git git = new Git(repo)) { final String testFile = "README.md"; // Modify the file FileUtils.write(new File(testFile), new Date().toString(), "UTF-8"); System.out.println("Modified files: " + getModifiedFiles(git)); new AssumeChangedCommand(repo, testFile, true).call(); System.out.println("Modified files after assume-changed: " + getModifiedFiles(git)); new AssumeChangedCommand(repo, testFile, false).call(); System.out.println("Modified files after no-assume-changed: " + getModifiedFiles(git)); git.checkout().addPath(testFile).call(); System.out.println("Modified files after reset: " + getModifiedFiles(git)); }//from w w w . ja v a 2 s . c o m } }
From source file:org.eclipse.che.git.impl.jgit.JGitConnection.java
License:Open Source License
private Git getGit() { if (git != null) { return git; } return git = new Git(repository); }
From source file:org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheTest.java
License:Open Source License
@Test public void testAddingAFile() throws Exception { new ConnectProviderOperation(project.project, repository.getDirectory()).execute(null); // create first commit containing a dummy file testRepository.createInitialCommit("testBranchOperation\n\nfirst commit\n"); prepareCacheEntry();//from www .j a v a 2 s . co m waitForListenerCalled(); final String fileName = "aFile"; // This call should trigger an indexDiffChanged event (triggered via // resource changed event) project.createFile(fileName, "content".getBytes("UTF-8")); IndexDiffData indexDiffData = waitForListenerCalled(); String path = project.project.getFile(fileName).getFullPath().toString().substring(1); if (!indexDiffData.getUntracked().contains(path)) fail("IndexDiffData did not contain aFile as untracked"); // This call should trigger an indexDiffChanged event new Git(repository).add().addFilepattern(path).call(); IndexDiffData indexDiffData2 = waitForListenerCalled(); if (indexDiffData2.getUntracked().contains(path)) fail("IndexDiffData contains aFile as untracked"); if (!indexDiffData2.getAdded().contains(path)) fail("IndexDiffData does not contain aFile as added"); }
From source file:org.eclipse.egit.core.internal.merge.VariantsTestCase.java
License:Open Source License
@Before @Override// www. j av a 2 s . c o m public void setUp() throws Exception { super.setUp(); iProject = project.project; testRepo = new TestRepository(gitDir); testRepo.connect(iProject); repo = RepositoryMapping.getMapping(iProject).getRepository(); // make initial commit try (Git git = new Git(repo)) { git.commit().setAuthor("JUnit", "junit@jgit.org").setMessage("Initial commit").call(); } }