GitWrapper
A set of classes for working with git repositories. The repository is examined using a wrapper around native git calls.
The current feature set is limited.
Setup
GitWrapper uses the Gradle build system.
Using ./gradlew build
will assemble a .jar file containing the library in the build/libs
directory.
The dependencies of the library may be displayed using ./gradlew dependencies --configuration compile
.
If the project using the library is also a gradle project it is far more convenient to add the library as a sub-project. The code below assumes that the directory of your clone of GitWrapper is a sibling of the project directory using it. Extend your settings.gradle
and build.gradle
as follows:
settings.gradle
#!groovy
includeFlat 'GitWrapper'
build.gradle
#!groovy
dependencies {
compile project(':GitWrapper')
}
Example
The following example code will clone a given repository to the current working directory and display the SHA1 hashes of all merge commits.
#!Java
GitWrapper git;
try {
git = new GitWrapper("git");
} catch (ToolNotWorkingException ex) {
// Handle that case that git can not be called using the supplied command.
return;
}
Optional<Repository> optRepo = git.clone(new File("."), "A VALID GIT REPOSITORY URL", false);
optRepo.ifPresent(repo -> repo.getMergeCommits().forEach(mergeCommit -> {
System.out.println("Merge Commit: " + mergeCommit.getId());
}));
Contact
- Georg Seibt (seibt[at]fim.uni-passau.de)