Do git stuff from Ruby.
Add this line to your application's Gemfile:
gem 'git.rb'
And then execute:
$ bundle
Or install it yourself as:
$ gem install git.rb
require 'git.rb' # or require each sub-library separately as per below...
require 'Git/Blame'
git_blame = Git::Blame.new('file/in/git/repository.rb')
# => #<Git::Blame @filename='file/in/git/repository.rb'>
git_blame.entries
# => [#<Git::PorcelainEntry @porcelain_output='...', @line_number=1>, ...]
line_number = 123
git_blame_porcelain_entry = git_blame.find(line_number)
# => #<Git::PorcelainEntry @porcelain_output='...', @line_number=123>
git_blame_porcelain_entry.commit_hash
# => "c9ab2bce79441f15d0a37e2af68017e7680b7e8d"
git_blame_porcelain_entry.author
# => "thoran"
require 'Git/Branch'
Git::Branch.default
# => 'branch_name'
Git::Branch.local
# => #<Git::Branch>
Git::Branch.remote
# => #<Git::Branch>
Git::Branch.local.all, Git::Branch.all
# => [#<Git::Branch @name="master">, ...]
Git::Branch.remote.all
# => [#<Git::Branch @name="master">, ...]
Git::Branch.merged.all
# => [#<Git::Branch @name="master">, ...]
Git::Branch.remote.merged.all
# => [#<Git::Branch @name="master">, ...]
Git::Branch.current
# => #<Git::Branch @name="master">
Git::Branch.current.master?
# => true
git_branch = Git::Branch.new('branch_name')
# => #<Git::Branch @name="branch_name">
git_branch.merged?
# => true/false
git_branch.name, git_branch.to_s
# => 'branch_name'
git_branch = Git::Branch.new('branch_name', remote: 'remote_name')
# => #<Git::Branch @name="branch_name" @remote="remote_name">
git_branch.remote
# => "remote_name"
require 'Git/Log'
git_log = Git::Log.parse(`git log`)
# => [#<Git::Log @commits = [#<Git::Log::Commit @hash=..., @author="thoran", @date=..., @message=...>, ...]>
git_log.commits
# => [#<Git::Log::Commit @hash=..., @author="thoran", @date=..., @message=...>, ...]
git_log.commits.first
# => #<Git::Log::Commit @hash=..., @author="thoran", @date=..., @message=...>
git_log.commits.first.author
# => "thoran"
require 'Git/Remote'
Git::Remote.all
# => [#<Git::Remote @name='origin', @url='[email protected]:thoran/rails.git'>, #<Git::Remote @name='upstream', @url='[email protected]:rails/rails.git'>]
Git::Remote.exist?('origin')
# => true
git_remote = Git::Remote.find('origin')
# => #<Git::Remote @name='origin' @url='[email protected]:thoran/rails.git'>
git_remote.to_s
# => "origin [email protected]:thoran/rails.git"
git_remote.name
# => "origin"
- Fork it ( https://github.com/thoran/git.rb/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new pull request