Skip to content

Instantly share code, notes, and snippets.

@billdueber
Last active December 28, 2015 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billdueber/7548043 to your computer and use it in GitHub Desktop.
Save billdueber/7548043 to your computer and use it in GitHub Desktop.
Playing around with JGit in JRuby
require 'jgit-3.1.0.jar'
dirpath = '.'
# get the repo
dir = java.io::File.new(dirpath)
frb = org.eclipse.jgit.storage.file.FileRepositoryBuilder.new
frb.set_work_tree dir
frb.find_git_dir
frb.build
repo = org.eclipse.jgit.internal.storage.file::FileRepository.new(frb)
git = org.eclipse.jgit.api::Git.new(repo)
HEAD = org.eclipse.jgit.lib::Constants::HEAD
head = repo.resolve(HEAD)
commits = git.log.add(head).set_max_count(10).call
commits.each do |c|
dt = Time.at( c.commit_time).to_datetime
author = c.author_ident.name
msg = c.full_message
puts "#{dt} #{author} #{msg}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment