pry-git 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -0,0 +1,3 @@
1
+ * 19/7/2011 version 0.2.2
2
+
3
+ Gem release
data/README.md CHANGED
@@ -12,7 +12,7 @@ pry-git enables you to diff an individual _method_ , it can show you
12
12
  the blame for a method and ultimately allow you to commit 'methods' (rather than amorphous
13
13
  'hunks' of code).
14
14
 
15
- pry-git is a plugin for the [pry](http://github.com/pry/pry)
15
+ pry-git is a plugin for the [pry](http://pry.github.com)
16
16
  REPL.
17
17
 
18
18
  pry-git is very much proof of concept right now, stay tuned!
data/Rakefile CHANGED
@@ -26,7 +26,7 @@ def apply_spec_defaults(s)
26
26
  s.files = Dir["lib/**/*.rb", "test/*.rb", "CHANGELOG", "README.md", "Rakefile"]
27
27
  s.add_dependency("diffy")
28
28
  s.add_dependency("grit")
29
- s.add_dependency("pry", ">=0.9.2")
29
+ s.add_dependency("pry", ">=0.9.8")
30
30
  end
31
31
 
32
32
  desc "run pry with plugin enabled"
@@ -39,6 +39,9 @@ task :test do
39
39
  sh "bacon -Itest -rubygems -a"
40
40
  end
41
41
 
42
+ desc "generate a gemspec"
43
+ task :gemspec => "ruby:gemspec"
44
+
42
45
  namespace :ruby do
43
46
  spec = Gem::Specification.new do |s|
44
47
  apply_spec_defaults(s)
@@ -49,6 +52,12 @@ namespace :ruby do
49
52
  pkg.need_zip = false
50
53
  pkg.need_tar = false
51
54
  end
55
+
56
+ task :gemspec do
57
+ File.open("#{spec.name}.gemspec", "w") do |f|
58
+ f << spec.to_ruby
59
+ end
60
+ end
52
61
  end
53
62
 
54
63
  desc "build all platform gems at once"
@@ -8,110 +8,124 @@ require 'diffy'
8
8
  require 'tempfile'
9
9
 
10
10
  module PryGit
11
- GitCommands = Pry::CommandSet.new do
12
- command "git blame", "Show blame for a method (for method in HEAD)" do |meth_name|
13
- if (meth = get_method_object(meth_name, target, {})).nil?
14
- output.puts "Invalid method name: #{meth_name}."
15
- next
16
- end
17
-
18
- file_name = meth.source_location.first
19
- code, start_line = method_code_from_head(meth)
20
-
21
- git_root = find_git_root(File.dirname(file_name))
22
-
11
+ module GitHelpers
12
+ def get_file_from_commit(path)
13
+ git_root = find_git_root(File.dirname(path))
23
14
  repo = Grit::Repo.new(git_root)
24
- num_lines = code.lines.count
25
- authors = repo.blame(relative_path(git_root, file_name), repo.head.commit).lines.select do |v|
26
- v.lineno >= start_line && v.lineno <= start_line + num_lines
27
- end.map do |v|
28
- v.commit.author.output(Time.new).split(/</).first.strip
29
- end
15
+ head = repo.commits.first
16
+ tree_names = relative_path(git_root, path).split("/")
17
+ start_tree = head.tree
18
+ blob_name = tree_names.last
19
+ tree = tree_names[0..-2].inject(start_tree) { |a, v| a.trees.find { |t| t.basename == v } }
20
+ blob = tree.blobs.find { |v| v.basename == blob_name }
21
+ blob.data
22
+ end
30
23
 
31
- lines_with_blame = []
32
- code.lines.zip(authors) { |line, author| lines_with_blame << ("#{author}".ljust(10) + colorize_code(line)) }
33
- output.puts lines_with_blame.join
24
+ def method_code_from_head(meth)
25
+ code = get_file_from_commit(meth.source_location.first)
26
+ search_line = meth.source.lines.first.strip
27
+ _, start_line = code.lines.to_a.each_with_index.find { |v, i| v.strip == search_line }
28
+ start_line
29
+ [Pry.new(:input => StringIO.new(code.lines.to_a[start_line..-1].join)).r(target), start_line + 1]
34
30
  end
35
31
 
36
- command "git diff", "Show the diff for a method (working directory vs HEAD)" do |meth_name|
32
+ def relative_path(root, path)
33
+ path =~ /#{root}\/(.*)/
34
+ $1
35
+ end
37
36
 
38
- if (meth = get_method_object(meth_name, target, {})).nil?
39
- output.puts "Invalid method name: #{meth_name}."
40
- next
37
+ # return the git top level for a give directory
38
+ def find_git_root(dir)
39
+ git_root = "."
40
+ Dir.chdir dir do
41
+ git_root = `git rev-parse --show-toplevel`.chomp
41
42
  end
42
43
 
43
- output.puts colorize_code(Diffy::Diff.new(method_code_from_head(meth).first, meth.source))
44
+ raise "No associated git repository found!" if git_root =~ /fatal:/
45
+ git_root
44
46
  end
47
+ end
45
48
 
46
- command "git add", "Add a method to index" do |meth_name|
47
- if (meth = get_method_object(meth_name, target, {})).nil?
48
- output.puts "Invalid method name: #{meth_name}."
49
- next
50
- end
51
-
52
- file_name = meth.source_location.first
49
+ Commands = Pry::CommandSet.new do
53
50
 
54
- git_root = find_git_root(File.dirname(file_name))
55
- repo = Grit::Repo.new(git_root)
51
+ create_command "git blame", "Show blame for a method (for method in HEAD)" do
52
+ include GitHelpers
56
53
 
57
- rel_file_name = relative_path(git_root, meth.source_location.first)
58
- file_data = get_file_from_commit(file_name)
59
- code, start_line = method_code_from_head(meth)
60
- end_line = start_line + code.lines.count
54
+ def options(opt)
55
+ method_options(opt)
56
+ end
61
57
 
62
- before_code = file_data.lines.to_a[0..(start_line - 2)]
63
- after_code = file_data.lines.to_a[end_line - 1..-1]
58
+ def process
59
+ raise CommandError, "Could not find method source" unless method_object.source
64
60
 
65
- final_code = before_code << meth.source.lines.to_a << after_code
61
+ meth = method_object
66
62
 
67
- t = Tempfile.new("tmp")
68
- t.write final_code.join
69
- t.close
63
+ file_name = meth.source_location.first
64
+ code, start_line = method_code_from_head(meth)
70
65
 
71
- sha1 = `git hash-object -w #{t.path}`.chomp
72
- system("git update-index --cacheinfo 100644 #{sha1} #{rel_file_name}")
73
- end
66
+ git_root = find_git_root(File.dirname(file_name))
74
67
 
75
- helpers do
76
- def get_file_from_commit(path)
77
- git_root = find_git_root(File.dirname(path))
78
68
  repo = Grit::Repo.new(git_root)
79
- head = repo.commits.first
80
- tree_names = relative_path(git_root, path).split("/")
81
- start_tree = head.tree
82
- blob_name = tree_names.last
83
- tree = tree_names[0..-2].inject(start_tree) { |a, v| a.trees.find { |t| t.basename == v } }
84
- blob = tree.blobs.find { |v| v.basename == blob_name }
85
- blob.data
69
+ num_lines = code.lines.count
70
+ authors = repo.blame(relative_path(git_root, file_name), repo.head.commit).lines.select do |v|
71
+ v.lineno >= start_line && v.lineno <= start_line + num_lines
72
+ end.map do |v|
73
+ v.commit.author.output(Time.new).split(/</).first.strip
74
+ end
75
+
76
+ lines_with_blame = []
77
+ code.lines.zip(authors) { |line, author| lines_with_blame << ("#{author}".ljust(20) + colorize_code(line)) }
78
+ output.puts lines_with_blame.join
86
79
  end
80
+ end
87
81
 
88
- def method_code_from_head(meth)
89
- code = get_file_from_commit(meth.source_location.first)
90
- search_line = meth.source.lines.first.strip
91
- _, start_line = code.lines.to_a.each_with_index.find { |v, i| v.strip == search_line }
92
- start_line
93
- [Pry.new(:input => StringIO.new(code.lines.to_a[start_line..-1].join)).r(target), start_line + 1]
82
+ create_command "git diff", "Show the diff for a method (working directory vs HEAD)" do
83
+ include GitHelpers
84
+
85
+ def options(opt)
86
+ method_options(opt)
94
87
  end
95
88
 
96
- def relative_path(root, path)
97
- path =~ /#{root}\/(.*)/
98
- $1
89
+ def process
90
+ output.puts colorize_code(Diffy::Diff.new(method_code_from_head(method_object).first, method_object.instance_variable_get(:@method).source))
99
91
  end
92
+ end
100
93
 
101
- # return the git top level for a give directory
102
- def find_git_root(dir)
103
- git_root = "."
104
- Dir.chdir dir do
105
- git_root = `git rev-parse --show-toplevel`.chomp
106
- end
94
+ create_command "git add", "Add a method to index" do
95
+ include GitHelpers
107
96
 
108
- raise "No associated git repository found!" if git_root =~ /fatal:/
109
- git_root
97
+ def options(opt)
98
+ method_options(opt)
110
99
  end
111
100
 
101
+ def process
102
+ meth = method_object.instance_variable_get(:@method)
103
+
104
+ file_name = meth.source_location.first
105
+
106
+ git_root = find_git_root(File.dirname(file_name))
107
+ repo = Grit::Repo.new(git_root)
108
+
109
+ rel_file_name = relative_path(git_root, meth.source_location.first)
110
+ file_data = get_file_from_commit(file_name)
111
+ code, start_line = method_code_from_head(meth)
112
+ end_line = start_line + code.lines.count
113
+
114
+ before_code = file_data.lines.to_a[0..(start_line - 2)]
115
+ after_code = file_data.lines.to_a[end_line - 1..-1]
116
+
117
+ final_code = before_code << meth.source.lines.to_a << after_code
118
+
119
+ t = Tempfile.new("tmp")
120
+ t.write final_code.join
121
+ t.close
122
+
123
+ sha1 = `git hash-object -w #{t.path}`.chomp
124
+ system("git update-index --cacheinfo 100644 #{sha1} #{rel_file_name}")
125
+ end
112
126
  end
113
127
 
114
128
  end
115
129
  end
116
130
 
117
- Pry.commands.import PryGit::GitCommands
131
+ Pry.commands.import PryGit::Commands
@@ -1,3 +1,3 @@
1
1
  module PryGit
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
metadata CHANGED
@@ -1,59 +1,55 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: pry-git
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.3
4
5
  prerelease:
5
- version: 0.2.2
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - John Mair (banisterfiend)
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-07-19 00:00:00 Z
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
12
+ date: 2012-04-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
16
15
  name: diffy
17
- prerelease: false
18
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &70186494544180 !ruby/object:Gem::Requirement
19
17
  none: false
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
24
22
  type: :runtime
25
- version_requirements: *id001
26
- - !ruby/object:Gem::Dependency
27
- name: grit
28
23
  prerelease: false
29
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *70186494544180
25
+ - !ruby/object:Gem::Dependency
26
+ name: grit
27
+ requirement: &70186494543760 !ruby/object:Gem::Requirement
30
28
  none: false
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
35
33
  type: :runtime
36
- version_requirements: *id002
37
- - !ruby/object:Gem::Dependency
38
- name: pry
39
34
  prerelease: false
40
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *70186494543760
36
+ - !ruby/object:Gem::Dependency
37
+ name: pry
38
+ requirement: &70186494543260 !ruby/object:Gem::Requirement
41
39
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- version: 0.9.2
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: 0.9.8
46
44
  type: :runtime
47
- version_requirements: *id003
45
+ prerelease: false
46
+ version_requirements: *70186494543260
48
47
  description: A Ruby-aware git layer
49
48
  email: jrmair@gmail.com
50
49
  executables: []
51
-
52
50
  extensions: []
53
-
54
51
  extra_rdoc_files: []
55
-
56
- files:
52
+ files:
57
53
  - lib/pry-git/version.rb
58
54
  - lib/pry-git.rb
59
55
  - test/test.rb
@@ -62,30 +58,26 @@ files:
62
58
  - Rakefile
63
59
  homepage: http://github.com/pry/pry-git
64
60
  licenses: []
65
-
66
61
  post_install_message:
67
62
  rdoc_options: []
68
-
69
- require_paths:
63
+ require_paths:
70
64
  - lib
71
- required_ruby_version: !ruby/object:Gem::Requirement
65
+ required_ruby_version: !ruby/object:Gem::Requirement
72
66
  none: false
73
- requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- version: "0"
77
- required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
72
  none: false
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: "0"
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
83
77
  requirements: []
84
-
85
78
  rubyforge_project:
86
- rubygems_version: 1.7.2
79
+ rubygems_version: 1.8.16
87
80
  signing_key:
88
81
  specification_version: 3
89
82
  summary: A Ruby-aware git layer
90
83
  test_files: []
91
-