Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Single commit can be logged

* fixed git dir probing
* added method for logging a single commit
  • Loading branch information...
commit a301649337185b289e7bff1e1222b791eb46fd7d 1 parent 26d8382
@fhopf authored
View
2  src/main/scala/org/synyx/git/ConfigurationService.scala
@@ -9,7 +9,7 @@ object ConfigurationService {
def readRepositoryConfig(path: String) = {
val lines = Source.fromFile(path).getLines
val filtered = lines.map(_.split(" ")).filter(_.length == 3).map {
- tokens: Array[String] => new Repository(tokens lift 0 get, new File(tokens lift 1 get), tokens lift 2 get)
+ tokens: Array[String] => new RepositoryConfig(tokens lift 0 get, new File(tokens lift 1 get), tokens lift 2 get)
}
filtered
}
View
6 src/main/scala/org/synyx/git/Repository.scala
@@ -1,6 +0,0 @@
-package org.synyx.git
-
-import java.io.File
-
-class Repository(val name: String, val folder: File, val url: String) {
-}
View
6 src/main/scala/org/synyx/git/RepositoryConfig.scala
@@ -0,0 +1,6 @@
+package org.synyx.git
+
+import java.io.File
+
+class RepositoryConfig(val name: String, val folder: File, val url: String) {
+}
View
34 src/main/scala/org/synyx/git/RepositoryService.scala
@@ -1,16 +1,16 @@
package org.synyx.git
import org.eclipse.jgit.api.{CloneCommand, LogCommand, Git}
-import org.eclipse.jgit.lib.RepositoryBuilder
-
import java.io.File
+import org.eclipse.jgit.lib.{ObjectId, AnyObjectId, Repository, RepositoryBuilder}
+import org.eclipse.jgit.revwalk.{RevWalk, RevCommit}
/**
* Functionality for talking to a local and remote git repo.
*/
object RepositoryService {
- def updateRepo(repo: Repository) = {
+ def updateRepo(repo: RepositoryConfig) = {
val clone = new CloneCommand().setDirectory(repo.folder);
val git = clone.setURI(repo.url).call();
@@ -18,21 +18,33 @@ object RepositoryService {
}
- def log(repo: Repository) = {
+ def log(repo: RepositoryConfig) = {
val git = readGitDir(repo)
git.log().call();
}
- def readGitDir(repo: Repository) = {
- val builder = new RepositoryBuilder();
- val repository = builder.addCeilingDirectory(repo.folder)
- .readEnvironment() // scan environment GIT_* variables
- .findGitDir() // scan up the file system tree
- .build();
+ def log(repo: RepositoryConfig, commit: String) = {
+ val jGitRepo = buildRepo(repo)
+
+ val commitObject = jGitRepo.resolve(commit)
+ if (commitObject != null) {
+ val walk = new RevWalk(jGitRepo);
+ walk.parseCommit(commitObject);
+ } else {
+ null
+ }
+ }
- new Git(repository);
+ def readGitDir(repo: RepositoryConfig) = {
+
+ new Git(buildRepo(repo));
}
+
+ def buildRepo(repo: RepositoryConfig) = {
+ val builder = new RepositoryBuilder();
+ builder.setWorkTree(repo.folder).build();
+ }
}
View
8 src/test/scala/org/synyx/git/ConfigurationServiceTest.scala
@@ -13,22 +13,22 @@ class ConfigurationServiceTest extends FunSuite with ShouldMatchers {
result.size should be(2)
}
- test("legal lines are converted to Repository") {
+ test("legal lines are converted to RepositoryConfig") {
val result = ConfigurationService.readRepositoryConfig("src/test/resources/repo.config")
for (item <- result) {
- assert(item.isInstanceOf[Repository])
+ assert(item.isInstanceOf[RepositoryConfig])
}
}
test("values are contained in right order") {
val result = ConfigurationService.readRepositoryConfig("src/test/resources/repo.config").toList
// first config line
- val repo1: Repository = result.lift(0).get
+ val repo1: RepositoryConfig = result.lift(0).get
repo1.name should be("name")
repo1.folder.getAbsolutePath should be("/path")
repo1.url should be("git://url")
// last config line
- val repo2: Repository = result.lift(1).get
+ val repo2: RepositoryConfig = result.lift(1).get
repo2.name should be("anotherName")
repo2.folder.getAbsolutePath should be("/some/path")
repo2.url should be("https://url")
View
16 src/test/scala/org/synyx/git/RepositoryServiceTest.scala
@@ -3,8 +3,8 @@ package org.synyx.git
import org.scalatest.FunSuite
import java.io.File
import org.scalatest.junit.JUnitRunner
-import org.scalatest.matchers.ShouldMatchers
import org.junit.runner.RunWith
+import org.scalatest.matchers.ShouldMatchers
@RunWith(classOf[JUnitRunner])
class RepositoryServiceTest extends FunSuite with ShouldMatchers {
@@ -12,7 +12,7 @@ class RepositoryServiceTest extends FunSuite with ShouldMatchers {
val service = RepositoryService
def setupRepo() = {
- val repo = new Repository("test", new File("/tmp/" + System.currentTimeMillis()), "git://github.com/fhopf/maven-deployment-from-webapp.git");
+ val repo = new RepositoryConfig("test", new File("/tmp/" + System.currentTimeMillis()), "git://github.com/fhopf/maven-deployment-from-webapp.git");
service.updateRepo(repo)
repo
}
@@ -40,4 +40,16 @@ class RepositoryServiceTest extends FunSuite with ShouldMatchers {
}
}
+
+ test("log single commit for existing commit") {
+ val repo = setupRepo()
+ val commit = service.log(repo, "762706406039595ddba0")
+ commit.getShortMessage() should be("more debug output")
+ }
+
+ test("log single commit for nonexisting commit") {
+ val repo = setupRepo()
+ val commit = service.log(repo, "nonexisting")
+ commit should be(null)
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.