gemdiff 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +42 -7
- data/lib/gemdiff.rb +2 -0
- data/lib/gemdiff/bundle_inspector.rb +5 -2
- data/lib/gemdiff/cli.rb +22 -2
- data/lib/gemdiff/colorize.rb +44 -0
- data/lib/gemdiff/gem_updater.rb +64 -0
- data/lib/gemdiff/version.rb +1 -1
- data/test/cli_test.rb +167 -0
- data/test/gem_updater_test.rb +46 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a91837ca05f7dba3fc3eb2cefeac019346a9d3c
|
4
|
+
data.tar.gz: efeb3363bdf56d03c5b545f7243f41868bb14bd8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22961ac6e18e487fc6583291052c4ddecd19f584fc1a71055297a3f0bbfaf9311dc82ace8313378d353a09e56f8ed58143ff4e5796b6677262fdd71e06cbee1f
|
7
|
+
data.tar.gz: 15a9367f60bc852519a2bd453a21b11d71d02f476f5fbd38289b570b758ac2db8e263d672a683ed148483b5b17f3531a9bbed2895f126a16701a6502d6d9df41
|
data/README.md
CHANGED
@@ -42,10 +42,45 @@ Open? (y to open, else skip)
|
|
42
42
|
|
43
43
|
You can use `gemdiff` bypassing bundler and query a gem by entering explicit version numbers.
|
44
44
|
|
45
|
-
For example, open the GitHub compare view in browser for difference between `
|
45
|
+
For example, open the GitHub compare view in browser for difference between `haml` versions 4.0.4 and 4.0.5:
|
46
46
|
|
47
47
|
```sh
|
48
|
-
$ gemdiff compare
|
48
|
+
$ gemdiff compare haml --new=4.0.5 --old=4.0.4
|
49
|
+
```
|
50
|
+
|
51
|
+
### `update`
|
52
|
+
|
53
|
+
`gemdiff` can simplify your git workflow around updating gems. Use `update` to update a gem in your
|
54
|
+
bundle and commit the change to your repository. You will be shown a preview of the `git diff` and
|
55
|
+
you may choose to commit or reset the change.
|
56
|
+
|
57
|
+
```sh
|
58
|
+
$ gemdiff update haml
|
59
|
+
|
60
|
+
Updating haml...
|
61
|
+
diff --git a/Gemfile.lock b/Gemfile.lock
|
62
|
+
index d5544ef..2d5def8 100644
|
63
|
+
--- a/Gemfile.lock
|
64
|
+
+++ b/Gemfile.lock
|
65
|
+
@@ -38,7 +38,7 @@ GEM
|
66
|
+
dalli (2.7.0)
|
67
|
+
debugger-linecache (1.2.0)
|
68
|
+
erubis (2.7.0)
|
69
|
+
- haml (4.0.4)
|
70
|
+
+ haml (4.0.5)
|
71
|
+
tilt
|
72
|
+
hike (1.2.3)
|
73
|
+
i18n (0.6.9)
|
74
|
+
|
75
|
+
Commit? (c to commit, r to reset, else do nothing) c
|
76
|
+
|
77
|
+
commit ebcc13f4c9a43f2e844d9d185e527652021c6a8f
|
78
|
+
Author: Tee Parham
|
79
|
+
Date: Mon Mar 3 16:38:32 2014 -0700
|
80
|
+
|
81
|
+
Update haml to 4.0.5
|
82
|
+
|
83
|
+
diff --git a/Gemfile.lock
|
49
84
|
```
|
50
85
|
|
51
86
|
### `find`
|
@@ -53,8 +88,8 @@ $ gemdiff compare arel --new=5.0.0 --old=4.0.2
|
|
53
88
|
Lookup the repository URL using the gemspec. If a GitHub URL is not found, hit the GitHub search API.
|
54
89
|
|
55
90
|
```sh
|
56
|
-
$ gemdiff find
|
57
|
-
http://github.com/
|
91
|
+
$ gemdiff find haml
|
92
|
+
http://github.com/haml/haml
|
58
93
|
```
|
59
94
|
|
60
95
|
### `open`
|
@@ -62,7 +97,7 @@ http://github.com/rails/arel
|
|
62
97
|
Open the repository URL:
|
63
98
|
|
64
99
|
```sh
|
65
|
-
$ gemdiff open
|
100
|
+
$ gemdiff open haml
|
66
101
|
```
|
67
102
|
|
68
103
|
### `releases`
|
@@ -70,7 +105,7 @@ $ gemdiff open arel
|
|
70
105
|
Open the repository's release history page:
|
71
106
|
|
72
107
|
```sh
|
73
|
-
$ gemdiff releases
|
108
|
+
$ gemdiff releases haml
|
74
109
|
```
|
75
110
|
|
76
111
|
### `commits`
|
@@ -78,7 +113,7 @@ $ gemdiff releases arel
|
|
78
113
|
Open the repository's master branch commit history page:
|
79
114
|
|
80
115
|
```sh
|
81
|
-
$ gemdiff commits
|
116
|
+
$ gemdiff commits haml
|
82
117
|
```
|
83
118
|
|
84
119
|
### `help`
|
data/lib/gemdiff.rb
CHANGED
@@ -2,9 +2,8 @@ module Gemdiff
|
|
2
2
|
class BundleInspector
|
3
3
|
def list
|
4
4
|
@list ||= begin
|
5
|
-
output = bundle_outdated_strict
|
6
5
|
gems = []
|
7
|
-
|
6
|
+
outdated.split("\n").each do |line|
|
8
7
|
next unless (outdated_gem = new_outdated_gem(line))
|
9
8
|
gems << outdated_gem
|
10
9
|
end
|
@@ -12,6 +11,10 @@ module Gemdiff
|
|
12
11
|
end
|
13
12
|
end
|
14
13
|
|
14
|
+
def outdated
|
15
|
+
@outdated ||= bundle_outdated_strict
|
16
|
+
end
|
17
|
+
|
15
18
|
def get(gem_name)
|
16
19
|
list.select{ |gem| gem.name == gem_name }.first
|
17
20
|
end
|
data/lib/gemdiff/cli.rb
CHANGED
@@ -2,8 +2,12 @@ require 'thor'
|
|
2
2
|
|
3
3
|
module Gemdiff
|
4
4
|
class CLI < Thor
|
5
|
+
include Colorize
|
6
|
+
|
5
7
|
default_task :outdated
|
6
8
|
|
9
|
+
CHECKING_FOR_OUTDATED = "Checking for outdated gems in your bundle..."
|
10
|
+
|
7
11
|
desc 'find <gem>', 'Find the github repository URL for a gem'
|
8
12
|
def find(gem_name)
|
9
13
|
gem = OutdatedGem.new(gem_name)
|
@@ -45,7 +49,7 @@ DESC
|
|
45
49
|
return unless gem.repo?
|
46
50
|
gem.set_versions options
|
47
51
|
if gem.missing_versions?
|
48
|
-
puts
|
52
|
+
puts CHECKING_FOR_OUTDATED
|
49
53
|
unless gem.load_bundle_versions
|
50
54
|
puts "#{gem_name} is not outdated in your bundle. Specify versions."
|
51
55
|
return
|
@@ -57,13 +61,29 @@ DESC
|
|
57
61
|
|
58
62
|
desc 'outdated', 'Compare each outdated gem in the bundle. You will be prompted to open each compare view.'
|
59
63
|
def outdated
|
60
|
-
puts
|
64
|
+
puts CHECKING_FOR_OUTDATED
|
61
65
|
inspector = BundleInspector.new
|
66
|
+
puts inspector.outdated
|
62
67
|
inspector.list.each do |gem|
|
63
68
|
puts gem.compare_message
|
64
69
|
response = ask("Open? (y to open, else skip)")
|
65
70
|
gem.compare if response == 'y'
|
66
71
|
end
|
67
72
|
end
|
73
|
+
|
74
|
+
desc 'update <gem>', 'Update a gem, show a git diff of the update, and commit or reset'
|
75
|
+
def update(name)
|
76
|
+
puts "Updating #{name}..."
|
77
|
+
gem = GemUpdater.new(name)
|
78
|
+
gem.update
|
79
|
+
puts colorize_git_output(gem.diff)
|
80
|
+
response = ask("\nCommit? (c to commit, r to reset, else do nothing)")
|
81
|
+
if response == 'c'
|
82
|
+
gem.commit
|
83
|
+
puts "\n" + colorize_git_output(gem.show)
|
84
|
+
elsif response == 'r'
|
85
|
+
puts gem.reset
|
86
|
+
end
|
87
|
+
end
|
68
88
|
end
|
69
89
|
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module Gemdiff
|
2
|
+
module Colorize
|
3
|
+
COLORS =
|
4
|
+
{
|
5
|
+
red: 31,
|
6
|
+
green: 32,
|
7
|
+
yellow: 33,
|
8
|
+
blue: 34,
|
9
|
+
magenta: 35,
|
10
|
+
}
|
11
|
+
|
12
|
+
# works with `git show` and `git diff`
|
13
|
+
def colorize_git_output(lines)
|
14
|
+
out = []
|
15
|
+
lines.split("\n").each do |line|
|
16
|
+
out <<
|
17
|
+
if line.start_with?("---") || line.start_with?("+++") || line.start_with?("diff") || line.start_with?("index")
|
18
|
+
colorize line, :blue
|
19
|
+
elsif line.start_with?("@@")
|
20
|
+
colorize line, :magenta
|
21
|
+
elsif line.start_with?("commit")
|
22
|
+
colorize line, :yellow
|
23
|
+
elsif line.start_with?("-")
|
24
|
+
colorize line, :red
|
25
|
+
elsif line.start_with?("+")
|
26
|
+
colorize line, :green
|
27
|
+
else
|
28
|
+
line
|
29
|
+
end
|
30
|
+
end
|
31
|
+
out.join("\n")
|
32
|
+
end
|
33
|
+
|
34
|
+
def colorize(string, color)
|
35
|
+
"\e[#{to_color_code(color)}m#{string}\e[0m"
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def to_color_code(color)
|
41
|
+
COLORS[color] || 30
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Gemdiff
|
2
|
+
class GemUpdater
|
3
|
+
attr_accessor :name
|
4
|
+
|
5
|
+
def initialize(name)
|
6
|
+
@name = name
|
7
|
+
end
|
8
|
+
|
9
|
+
def update
|
10
|
+
bundle_update
|
11
|
+
end
|
12
|
+
|
13
|
+
def diff
|
14
|
+
git_diff
|
15
|
+
end
|
16
|
+
|
17
|
+
def show
|
18
|
+
git_show
|
19
|
+
end
|
20
|
+
|
21
|
+
def commit
|
22
|
+
git_commit
|
23
|
+
end
|
24
|
+
|
25
|
+
def reset
|
26
|
+
git_reset
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def git_show
|
32
|
+
`git show`
|
33
|
+
end
|
34
|
+
|
35
|
+
def git_diff
|
36
|
+
`git diff`
|
37
|
+
end
|
38
|
+
|
39
|
+
def git_commit
|
40
|
+
added = git_changed_line
|
41
|
+
return false if added.empty?
|
42
|
+
version = added.split(' ').last.gsub(/[()]/, '')
|
43
|
+
git_add_and_commit_lockfile version
|
44
|
+
true
|
45
|
+
end
|
46
|
+
|
47
|
+
def git_changed_line
|
48
|
+
`git diff | grep #{name} | grep '+ '`
|
49
|
+
end
|
50
|
+
|
51
|
+
def git_add_and_commit_lockfile(version)
|
52
|
+
`git add Gemfile.lock && git commit -m 'Update #{name} to #{version}'`
|
53
|
+
end
|
54
|
+
|
55
|
+
def git_reset
|
56
|
+
`git checkout Gemfile.lock`
|
57
|
+
end
|
58
|
+
|
59
|
+
def bundle_update
|
60
|
+
`bundle update #{name}`
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
end
|
data/lib/gemdiff/version.rb
CHANGED
data/test/cli_test.rb
ADDED
@@ -0,0 +1,167 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Gemdiff
|
4
|
+
class CLITest < MiniTest::Spec
|
5
|
+
before do
|
6
|
+
@cli = CLI.new
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "#find" do
|
10
|
+
it "finds" do
|
11
|
+
mock_gem "haml"
|
12
|
+
@cli.expects(:puts).with("http://github.com/haml/haml")
|
13
|
+
@cli.find "haml"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "does not find" do
|
17
|
+
mock_missing_gem
|
18
|
+
@cli.expects(:puts).with("Could not find github repository for notfound.")
|
19
|
+
@cli.find "notfound"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#open" do
|
24
|
+
it "opens repo" do
|
25
|
+
gem = mock_gem("haml")
|
26
|
+
@cli.expects(:puts).with("http://github.com/haml/haml")
|
27
|
+
gem.expects :open
|
28
|
+
@cli.open "haml"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#releases" do
|
33
|
+
it "opens releases page" do
|
34
|
+
gem = mock_gem("haml")
|
35
|
+
@cli.expects(:puts).with("http://github.com/haml/haml")
|
36
|
+
gem.expects :releases
|
37
|
+
@cli.releases "haml"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe "#commits" do
|
42
|
+
it "opens commits page" do
|
43
|
+
gem = mock_gem("haml")
|
44
|
+
@cli.expects(:puts).with("http://github.com/haml/haml")
|
45
|
+
gem.expects :commits
|
46
|
+
@cli.commits "haml"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "#compare" do
|
51
|
+
it "opens compare view" do
|
52
|
+
gem = mock_gem("haml")
|
53
|
+
gem.expects(:set_versions).with({})
|
54
|
+
gem.expects(:missing_versions?).returns(false)
|
55
|
+
gem.expects(:compare_message).returns("compare message")
|
56
|
+
@cli.expects(:puts).with("http://github.com/haml/haml")
|
57
|
+
@cli.expects(:puts).with("compare message")
|
58
|
+
gem.expects :compare
|
59
|
+
@cli.compare "haml"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "returns when the gem is not found" do
|
63
|
+
mock_missing_gem
|
64
|
+
@cli.expects(:puts).with("Could not find github repository for notfound.")
|
65
|
+
@cli.compare "notfound"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe "#outdated" do
|
70
|
+
it "does nothing when nothing to update" do
|
71
|
+
mock_inspector = mock do
|
72
|
+
stubs list: []
|
73
|
+
stubs outdated: ""
|
74
|
+
end
|
75
|
+
BundleInspector.stubs new: mock_inspector
|
76
|
+
@cli.expects(:puts).with(CLI::CHECKING_FOR_OUTDATED)
|
77
|
+
@cli.expects(:puts).with("")
|
78
|
+
@cli.outdated
|
79
|
+
end
|
80
|
+
|
81
|
+
it "compares outdated gems with responses of y" do
|
82
|
+
gem = OutdatedGem.new("haml", "4.0.4", "4.0.5")
|
83
|
+
mock_inspector = mock do
|
84
|
+
stubs list: [gem]
|
85
|
+
stubs outdated: "outdated"
|
86
|
+
end
|
87
|
+
BundleInspector.stubs new: mock_inspector
|
88
|
+
@cli.stubs ask: 'y'
|
89
|
+
@cli.expects(:puts).with(CLI::CHECKING_FOR_OUTDATED)
|
90
|
+
@cli.expects(:puts).with("outdated")
|
91
|
+
@cli.expects(:puts).with("haml: 4.0.5 > 4.0.4")
|
92
|
+
gem.expects :compare
|
93
|
+
@cli.outdated
|
94
|
+
end
|
95
|
+
|
96
|
+
it "skips outdated gems without responses of y" do
|
97
|
+
gem = OutdatedGem.new("haml", "4.0.4", "4.0.5")
|
98
|
+
mock_inspector = mock do
|
99
|
+
stubs list: [gem]
|
100
|
+
stubs outdated: "outdated"
|
101
|
+
end
|
102
|
+
BundleInspector.stubs new: mock_inspector
|
103
|
+
@cli.stubs ask: ''
|
104
|
+
@cli.expects(:puts).with(CLI::CHECKING_FOR_OUTDATED)
|
105
|
+
@cli.expects(:puts).with("outdated")
|
106
|
+
@cli.expects(:puts).with("haml: 4.0.5 > 4.0.4")
|
107
|
+
gem.expects(:compare).never
|
108
|
+
@cli.outdated
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe "#update" do
|
113
|
+
before do
|
114
|
+
@mock_gem = mock do
|
115
|
+
stubs diff: "le diff"
|
116
|
+
stubs show: "le show"
|
117
|
+
end
|
118
|
+
GemUpdater.stubs new: @mock_gem
|
119
|
+
end
|
120
|
+
|
121
|
+
it "updates the gem and returns with no response" do
|
122
|
+
@cli.stubs ask: ''
|
123
|
+
@cli.expects(:puts).with("Updating haml...")
|
124
|
+
@mock_gem.expects :update
|
125
|
+
@cli.expects(:puts).with("le diff")
|
126
|
+
@cli.update "haml"
|
127
|
+
end
|
128
|
+
|
129
|
+
it "updates the gem and commits with responses of c" do
|
130
|
+
@cli.stubs ask: 'c'
|
131
|
+
@cli.expects(:puts).with("Updating haml...")
|
132
|
+
@mock_gem.expects :update
|
133
|
+
@cli.expects(:puts).with("le diff")
|
134
|
+
@mock_gem.expects :commit
|
135
|
+
@cli.expects(:puts).with("\nle show")
|
136
|
+
@cli.update "haml"
|
137
|
+
end
|
138
|
+
|
139
|
+
it "updates the gem and resets with responses of r" do
|
140
|
+
@cli.stubs ask: 'r'
|
141
|
+
@cli.expects(:puts).with("Updating haml...")
|
142
|
+
@mock_gem.expects :update
|
143
|
+
@cli.expects(:puts).with("le diff")
|
144
|
+
@mock_gem.expects(:reset).returns("le reset")
|
145
|
+
@cli.expects(:puts).with("le reset")
|
146
|
+
@cli.update "haml"
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
private
|
151
|
+
|
152
|
+
def mock_gem(name)
|
153
|
+
gem = mock do
|
154
|
+
stubs repo?: true
|
155
|
+
stubs repo: "http://github.com/#{name}/#{name}"
|
156
|
+
end
|
157
|
+
OutdatedGem.stubs new: gem
|
158
|
+
gem
|
159
|
+
end
|
160
|
+
|
161
|
+
def mock_missing_gem
|
162
|
+
gem = mock { stubs repo?: false }
|
163
|
+
OutdatedGem.stubs new: gem
|
164
|
+
gem
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
module Gemdiff
|
4
|
+
class GemUpdaterTest < MiniTest::Spec
|
5
|
+
describe "#update" do
|
6
|
+
it "updates the gem" do
|
7
|
+
updater = GemUpdater.new("x")
|
8
|
+
updater.expects :bundle_update
|
9
|
+
updater.update
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#commit" do
|
14
|
+
it "adds a git commit for a gem update" do
|
15
|
+
updater = GemUpdater.new("aws-sdk")
|
16
|
+
updater.stubs git_changed_line: "+ aws-sdk (1.35.0)"
|
17
|
+
updater.expects(:git_add_and_commit_lockfile).with("1.35.0")
|
18
|
+
assert updater.commit
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe "#reset" do
|
23
|
+
it "resets Gemfile.lock" do
|
24
|
+
updater = GemUpdater.new("x")
|
25
|
+
updater.expects :git_reset
|
26
|
+
updater.reset
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe "#diff" do
|
31
|
+
it "returns git diff" do
|
32
|
+
updater = GemUpdater.new("x")
|
33
|
+
updater.expects :git_diff
|
34
|
+
updater.diff
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#show" do
|
39
|
+
it "returns git show" do
|
40
|
+
updater = GemUpdater.new("x")
|
41
|
+
updater.expects :git_show
|
42
|
+
updater.show
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gemdiff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tee Parham
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -141,10 +141,14 @@ files:
|
|
141
141
|
- lib/gemdiff.rb
|
142
142
|
- lib/gemdiff/bundle_inspector.rb
|
143
143
|
- lib/gemdiff/cli.rb
|
144
|
+
- lib/gemdiff/colorize.rb
|
145
|
+
- lib/gemdiff/gem_updater.rb
|
144
146
|
- lib/gemdiff/outdated_gem.rb
|
145
147
|
- lib/gemdiff/repo_finder.rb
|
146
148
|
- lib/gemdiff/version.rb
|
147
149
|
- test/bundle_inspector_test.rb
|
150
|
+
- test/cli_test.rb
|
151
|
+
- test/gem_updater_test.rb
|
148
152
|
- test/outdated_gem_test.rb
|
149
153
|
- test/repo_finder_test.rb
|
150
154
|
- test/test_helper.rb
|
@@ -174,6 +178,8 @@ specification_version: 4
|
|
174
178
|
summary: Compare gem versions
|
175
179
|
test_files:
|
176
180
|
- test/bundle_inspector_test.rb
|
181
|
+
- test/cli_test.rb
|
182
|
+
- test/gem_updater_test.rb
|
177
183
|
- test/outdated_gem_test.rb
|
178
184
|
- test/repo_finder_test.rb
|
179
185
|
- test/test_helper.rb
|