Created
April 9, 2015 22:05
-
-
Save jlcanela/49fd4cd4a0ce41c189c7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| object MyJGitSample { | |
| import scalaz._ | |
| import scalaz.effect.IO | |
| def lift[T](f: => T) = EitherT(IO(\/.fromTryCatchNonFatal(f))) | |
| def abortIf(b: Boolean, msg: String) = EitherT(IO(if (b) -\/(new Throwable(msg)) else \/-(()))) | |
| def createCommand = { | |
| import org.eclipse.jgit.api._ | |
| import org.eclipse.jgit.internal.storage.file.FileRepository | |
| val localPath = "."; | |
| val localRepo = new FileRepository(localPath + "/.git") | |
| val git = new Git(localRepo) | |
| for { | |
| addAll <- lift(git.add().addFilepattern("*").call.getEntryCount) | |
| st <- lift(git.status.call()) | |
| _ = println(st.getUncommittedChanges) | |
| _ <- abortIf(st.getUncommittedChanges.isEmpty, "No committed change") | |
| } yield addAll | |
| } | |
| def main(args: Array[String]) = { | |
| println(createCommand.run.unsafePerformIO) | |
| } | |
| } |
Author
looks good, but pretty tough to read due to scalaz.
Thanks a lot for pointing me to this implementation.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here are the sbt dependencies used in this sample :