Created
March 27, 2015 15:06
-
-
Save rohitvvv/63128bb859ef65e6e174 to your computer and use it in GitHub Desktop.
ReadRepositoryTest - Sample Test File to read an existing GIT repository using JGIT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package com.mycompany.jgitplayground; | |
import java.io.File; | |
import java.io.IOException; | |
import org.eclipse.jgit.lib.Repository; | |
import org.eclipse.jgit.revwalk.RevCommit; | |
import org.eclipse.jgit.revwalk.RevWalk; | |
import org.eclipse.jgit.storage.file.FileRepositoryBuilder; | |
/** | |
* | |
* @author rvvaidya | |
*/ | |
public class ReadRepositoryTest { | |
public static void main(String[] args) throws IOException { | |
FileRepositoryBuilder builder = new FileRepositoryBuilder(); | |
Repository repository = builder.setGitDir(new File("/Users/rvvaidya/Downloads/GitFx/.git")) | |
.readEnvironment() | |
.setMustExist(true) | |
.findGitDir() | |
.build(); | |
System.out.println("Repository Directory: " + repository.getDirectory()); | |
System.out.println("Full Branch: " + repository.getFullBranch()); | |
RevWalk walk = new RevWalk(repository); | |
walk.markStart(walk.parseCommit(repository.resolve("HEAD"))); | |
//Iterator<RevCommit> iterator = walk.iterator(); | |
for (RevCommit commit : walk) { | |
System.out.println("Commit" + commit.getName() + "Commit Message" + commit.getFullMessage()); | |
System.out.println("Short Message: " + commit.getShortMessage()); | |
} | |
System.out.println("Branch: " + repository.getBranch()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment