-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 51a4bc0
Showing
10 changed files
with
301 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Makefile | ||
*.so | ||
*.o | ||
*.def | ||
doc/ | ||
pkg/ | ||
.yardoc/ |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
--markup markdown |
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
License | ||
------- | ||
|
||
(The MIT License) | ||
|
||
Copyright (c) 2011 John Mair (banisterfiend) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
'Software'), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
pry-git | ||
=========== | ||
|
||
(C) John Mair (banisterfiend) 2011 | ||
|
||
_ruby aware git_ | ||
|
||
Retrieve blame, perform diffs, make commits using the natural units of | ||
Ruby code. | ||
|
||
pry-git enables you to diff an individual _method_ , it can show you | ||
the blame for a method and ultimately allow you to commit 'methods' (rather than amorphous | ||
'hunks' of code). | ||
|
||
pry-git is a plugin for the [pry](http://github.com/banister/pry) | ||
REPL, a powerful IRB alternative. | ||
|
||
pry-git is very much proof of concept right now, stay tuned! | ||
|
||
* NOT AVAILABLE: Install the [gem](https://rubygems.org/gems/pry-git): `gem install pry-git` | ||
* NOT AVAILABLE: Read the [documentation](http://rdoc.info/github/banister/pry-git/master/file/README.md) | ||
* See the [source code](http://github.com/banister/pry-git) | ||
|
||
Example: blame | ||
-------- | ||
|
||
pry(main)> blame Pry#repl | ||
John Mair def repl(target=TOPLEVEL_BINDING) | ||
John Mair target = Pry.binding_for(target) | ||
John Mair target_self = target.eval('self') | ||
John Mair | ||
John Mair repl_prologue(target) | ||
Mon ouïe | ||
John Mair # cannot rely on nesting.level as | ||
John Mair # nesting.level changes with new sessions | ||
John Mair nesting_level = nesting.size | ||
John Mair | ||
John Mair break_data = catch(:breakout) do | ||
John Mair nesting.push [nesting.size, target_self, self] | ||
John Mair loop do | ||
John Mair rep(target) | ||
John Mair end | ||
John Mair end | ||
John Mair | ||
John Mair return_value = repl_epilogue(target, nesting_level, break_data) | ||
Lee Jarvis return_value || target_self | ||
John Mair end | ||
|
||
Example: diff | ||
-------- | ||
|
||
pry(main)> diff Pry#repl | ||
def repl(target=TOPLEVEL_BINDING) | ||
+ | ||
+ # hey baby | ||
target = Pry.binding_for(target) | ||
target_self = target.eval('self') | ||
|
||
+ # bink | ||
repl_prologue(target) | ||
|
||
# cannot rely on nesting.level as | ||
# nesting.level changes with new sessions | ||
nesting_level = nesting.size | ||
|
||
break_data = catch(:breakout) do | ||
nesting.push [nesting.size, target_self, self] | ||
loop do | ||
rep(target) | ||
end | ||
end | ||
|
||
return_value = repl_epilogue(target, nesting_level, break_data) | ||
return_value || target_self | ||
end | ||
- | ||
- # Perform a read-eval-print. | ||
- # If no parameter is given, default to top-level (main). | ||
|
||
Features and limitations | ||
------------------------- | ||
|
||
* commit-method not yet implemented | ||
* BETA software, not guaranteed to work properly yet, stay tuned. | ||
|
||
Contact | ||
------- | ||
|
||
Problems or questions contact me at [github](http://github.com/banister) | ||
|
||
|
||
License | ||
------- | ||
|
||
(The MIT License) | ||
|
||
Copyright (c) 2011 John Mair (banisterfiend) | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
'Software'), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
$:.unshift 'lib' | ||
|
||
dlext = Config::CONFIG['DLEXT'] | ||
direc = File.dirname(__FILE__) | ||
|
||
PROJECT_NAME = "pry-git" | ||
|
||
require 'rake/clean' | ||
require 'rake/gempackagetask' | ||
require "#{PROJECT_NAME}/version" | ||
|
||
CLOBBER.include("**/*~", "**/*#*", "**/*.log") | ||
CLEAN.include("**/*#*", "**/*#*.*", "**/*_flymake*.*", "**/*_flymake", | ||
"**/*.rbc", "**/.#*.*") | ||
|
||
def apply_spec_defaults(s) | ||
s.name = PROJECT_NAME | ||
s.summary = "FIX ME" | ||
s.version = PryGit::VERSION | ||
s.date = Time.now.strftime '%Y-%m-%d' | ||
s.author = "John Mair (banisterfiend)" | ||
s.email = '[email protected]' | ||
s.description = s.summary | ||
s.require_path = 'lib' | ||
s.homepage = "http://banisterfiend.wordpress.com" | ||
s.files = Dir["lib/**/*.rb", "test/*.rb", "CHANGELOG", "README.md", "Rakefile"] | ||
end | ||
|
||
desc "run pry with plugin enabled" | ||
task :pry do | ||
exec("pry -I#{direc}/lib/ -r #{direc}/lib/#{PROJECT_NAME}") | ||
end | ||
|
||
desc "run tests" | ||
task :test do | ||
sh "bacon -Itest -rubygems -a" | ||
end | ||
|
||
namespace :ruby do | ||
spec = Gem::Specification.new do |s| | ||
apply_spec_defaults(s) | ||
s.platform = Gem::Platform::RUBY | ||
end | ||
|
||
Rake::GemPackageTask.new(spec) do |pkg| | ||
pkg.need_zip = false | ||
pkg.need_tar = false | ||
end | ||
end | ||
|
||
desc "build all platform gems at once" | ||
task :gems => [:clean, :rmgems, "ruby:gem"] | ||
|
||
desc "remove all platform gems" | ||
task :rmgems => ["ruby:clobber_package"] | ||
|
||
desc "build and push latest gems" | ||
task :pushgems => :gems do | ||
chdir("#{File.dirname(__FILE__)}/pkg") do | ||
Dir["*.gem"].each do |gemfile| | ||
sh "gem push #{gemfile}" | ||
end | ||
end | ||
end | ||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# pry-git.rb | ||
# (C) John Mair (banisterfiend); MIT license | ||
|
||
require "pry-git/version" | ||
require "pry" | ||
|
||
module PryGit | ||
GitCommands = Pry::CommandSet.new do | ||
command "blame", "Show blame for a method", :requires_gem => "grit" do |meth_name| | ||
require 'grit' | ||
if (meth = get_method_object(meth_name, target, {})).nil? | ||
output.puts "Invalid method name: #{meth_name}." | ||
next | ||
end | ||
|
||
repo ||= Grit::Repo.new(Dir.pwd) | ||
start_line = meth.source_location.last | ||
num_lines = meth.source.lines.count | ||
authors = repo.blame(meth.source_location.first).lines.select do |v| | ||
v.lineno >= start_line && v.lineno <= start_line + num_lines | ||
end.map do |v| | ||
v.commit.author.output(Time.new).split(/</).first.strip | ||
end | ||
|
||
lines_with_blame = [] | ||
meth.source.lines.zip(authors) { |line, author| lines_with_blame << ("#{author}".ljust(10) + colorize_code(line)) } | ||
output.puts lines_with_blame.join | ||
end | ||
|
||
command "diff", "Show the diff for a method", :requires_gem => ["grit", "diffy"] do |meth_name| | ||
require 'grit' | ||
require 'diffy' | ||
|
||
if (meth = get_method_object(meth_name, target, {})).nil? | ||
output.puts "Invalid method name: #{meth_name}." | ||
next | ||
end | ||
|
||
output.puts colorize_code(Diffy::Diff.new(method_code_from_head(meth), meth.source)) | ||
end | ||
|
||
helpers do | ||
def get_file_from_commit(path) | ||
repo = Grit::Repo.new(Dir.pwd) | ||
head = repo.commits.first | ||
tree_names = path.split("/") | ||
start_tree = head.tree | ||
blob_name = tree_names.last | ||
tree = tree_names[0..-2].inject(start_tree) { |a, v| a.trees.find { |tree| tree.basename == v } } | ||
blob = tree.blobs.find { |v| v.basename == blob_name } | ||
blob.data | ||
end | ||
|
||
def method_code_from_head(meth) | ||
rel_path = relative_path(meth.source_location.first) | ||
code = get_file_from_commit(rel_path) | ||
start_line = meth.source_location.last | ||
code_length = meth.source.lines.count | ||
code.lines.to_a[(start_line - 1)...((start_line -1) + code_length)].join | ||
end | ||
|
||
def relative_path(path) | ||
path =~ /#{Regexp.escape(File.expand_path(Dir.pwd))}\/(.*)/ | ||
$1 | ||
end | ||
end | ||
|
||
end | ||
end | ||
|
||
Pry.commands.import PryGit::GitCommands |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module PryGit | ||
VERSION = "0.1.0" | ||
end |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
direc = File.dirname(__FILE__) | ||
|
||
require 'rubygems' | ||
require "#{direc}/../lib/pry-git" | ||
require 'bacon' | ||
|
||
puts "Testing pry-git version #{PryGit::VERSION}..." | ||
puts "Ruby version: #{RUBY_VERSION}" | ||
|
||
describe PryGit do | ||
end | ||
|