gh-diff 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gh-diff/cli.rb +19 -3
- data/lib/gh-diff/version.rb +1 -1
- data/spec/cassettes/save-dir-diff.yml +145 -0
- data/spec/cli_spec.rb +15 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a06727c1dc58fa3d5a219d7b2f6f720f8d0cec2
|
4
|
+
data.tar.gz: 004961bbb8b9e19793d79b5e3bfef515289c97e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1ea9453e4b55cabb64dd3f819601d29d0e9e1bb0182086b6e7bd9969ef663ac6d25c55460434d88e23ea2c3eb723022b1be0871de23cb0da81af16251bfceeca
|
7
|
+
data.tar.gz: c322447f5a99d1f35e6299e2055454d7c1548032c4b0cd16666d90a2adb240e41408edac92727d34b9de1ebf5a1841ccb28a2637ed3c8d506bcee135412f7245
|
data/lib/gh-diff/cli.rb
CHANGED
@@ -113,6 +113,13 @@ Base revision: #{ref[:object][:sha]}[#{ref[:ref]}]
|
|
113
113
|
end
|
114
114
|
|
115
115
|
desc "dir_diff DIRECTORY", "Print added and removed files in remote repository"
|
116
|
+
option :save,
|
117
|
+
aliases:'-s',
|
118
|
+
default:false,
|
119
|
+
type: :boolean
|
120
|
+
option :save_dir,
|
121
|
+
default:'diff',
|
122
|
+
desc:'save directory'
|
116
123
|
def dir_diff(dir)
|
117
124
|
opts = Option.new(options).with_env
|
118
125
|
github_auth(opts[:username], opts[:password], opts[:token])
|
@@ -125,6 +132,15 @@ Base revision: #{ref[:object][:sha]}[#{ref[:ref]}]
|
|
125
132
|
if added.any?
|
126
133
|
puts "\e[33mNew files:\e[0m"
|
127
134
|
puts added.map { |f| " \e[32m" + f + "\e[0m" }
|
135
|
+
if opts[:save]
|
136
|
+
added.each do |f|
|
137
|
+
path = File.join(dir, f)
|
138
|
+
content = gh.get(path)
|
139
|
+
unless content.empty?
|
140
|
+
save(content, opts[:save_dir], path, File.extname(path))
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
128
144
|
end
|
129
145
|
if removed.any?
|
130
146
|
puts "\e[33mRemoved files:\e[0m"
|
@@ -162,13 +178,13 @@ Base revision: #{ref[:object][:sha]}[#{ref[:ref]}]
|
|
162
178
|
FileUtils.mkdir_p(dir) unless Dir.exist?(dir)
|
163
179
|
end
|
164
180
|
|
165
|
-
def save(content, save_dir, file)
|
181
|
+
def save(content, save_dir, file, ext='.diff')
|
166
182
|
dir = (d=File.dirname(file))=='.' ? '' : d
|
167
|
-
file = File.basename(file, '.*') +
|
183
|
+
file = File.basename(file, '.*') + ext
|
168
184
|
path = File.join(save_dir, dir, file)
|
169
185
|
mkdir(File.dirname path)
|
170
186
|
File.write(path, content)
|
171
|
-
print "\e[
|
187
|
+
print "\e[32mFile saved at '#{path}'\e[0m\n"
|
172
188
|
end
|
173
189
|
|
174
190
|
def file_not_found?(f1, f2, content)
|
data/lib/gh-diff/version.rb
CHANGED
@@ -0,0 +1,145 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: get
|
5
|
+
uri: https://api.github.com/repos/melborne/gh-diff/contents/bin?ref=master
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ''
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- application/vnd.github.v3+json
|
12
|
+
User-Agent:
|
13
|
+
- Octokit Ruby Gem 3.1.2
|
14
|
+
Accept-Encoding:
|
15
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 200
|
19
|
+
message: OK
|
20
|
+
headers:
|
21
|
+
Server:
|
22
|
+
- GitHub.com
|
23
|
+
Date:
|
24
|
+
- Wed, 16 Jul 2014 01:04:14 GMT
|
25
|
+
Content-Type:
|
26
|
+
- application/json; charset=utf-8
|
27
|
+
Transfer-Encoding:
|
28
|
+
- chunked
|
29
|
+
Status:
|
30
|
+
- 200 OK
|
31
|
+
X-Ratelimit-Limit:
|
32
|
+
- '60'
|
33
|
+
X-Ratelimit-Remaining:
|
34
|
+
- '57'
|
35
|
+
X-Ratelimit-Reset:
|
36
|
+
- '1405475907'
|
37
|
+
Cache-Control:
|
38
|
+
- public, max-age=60, s-maxage=60
|
39
|
+
Last-Modified:
|
40
|
+
- Sun, 06 Jul 2014 14:29:03 GMT
|
41
|
+
Etag:
|
42
|
+
- '"a98e37e86a4246a85b31e0297c2b068b"'
|
43
|
+
Vary:
|
44
|
+
- Accept
|
45
|
+
- Accept-Encoding
|
46
|
+
X-Github-Media-Type:
|
47
|
+
- github.v3; format=json
|
48
|
+
X-Xss-Protection:
|
49
|
+
- 1; mode=block
|
50
|
+
X-Frame-Options:
|
51
|
+
- deny
|
52
|
+
Content-Security-Policy:
|
53
|
+
- default-src 'none'
|
54
|
+
Access-Control-Allow-Credentials:
|
55
|
+
- 'true'
|
56
|
+
Access-Control-Expose-Headers:
|
57
|
+
- ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset,
|
58
|
+
X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
|
59
|
+
Access-Control-Allow-Origin:
|
60
|
+
- "*"
|
61
|
+
X-Github-Request-Id:
|
62
|
+
- DE962F8B:5BD6:B8A7707:53C5CF8E
|
63
|
+
Strict-Transport-Security:
|
64
|
+
- max-age=31536000; includeSubdomains
|
65
|
+
X-Content-Type-Options:
|
66
|
+
- nosniff
|
67
|
+
X-Served-By:
|
68
|
+
- 971af40390ac4398fcdd45c8dab0fbe7
|
69
|
+
body:
|
70
|
+
encoding: UTF-8
|
71
|
+
string: '[{"name":"gh-diff","path":"bin/gh-diff","sha":"97f13c6aafe6520b33960b32c398e4c8bbeb4bf7","size":64,"url":"https://api.github.com/repos/melborne/gh-diff/contents/bin/gh-diff?ref=master","html_url":"https://github.com/melborne/gh-diff/blob/master/bin/gh-diff","git_url":"https://api.github.com/repos/melborne/gh-diff/git/blobs/97f13c6aafe6520b33960b32c398e4c8bbeb4bf7","type":"file","_links":{"self":"https://api.github.com/repos/melborne/gh-diff/contents/bin/gh-diff?ref=master","git":"https://api.github.com/repos/melborne/gh-diff/git/blobs/97f13c6aafe6520b33960b32c398e4c8bbeb4bf7","html":"https://github.com/melborne/gh-diff/blob/master/bin/gh-diff"}}]'
|
72
|
+
http_version:
|
73
|
+
recorded_at: Wed, 16 Jul 2014 01:04:14 GMT
|
74
|
+
- request:
|
75
|
+
method: get
|
76
|
+
uri: https://api.github.com/repos/melborne/gh-diff/contents/bin/gh-diff?ref=master
|
77
|
+
body:
|
78
|
+
encoding: US-ASCII
|
79
|
+
string: ''
|
80
|
+
headers:
|
81
|
+
Accept:
|
82
|
+
- application/vnd.github.v3+json
|
83
|
+
User-Agent:
|
84
|
+
- Octokit Ruby Gem 3.1.2
|
85
|
+
Accept-Encoding:
|
86
|
+
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
87
|
+
response:
|
88
|
+
status:
|
89
|
+
code: 200
|
90
|
+
message: OK
|
91
|
+
headers:
|
92
|
+
Server:
|
93
|
+
- GitHub.com
|
94
|
+
Date:
|
95
|
+
- Wed, 16 Jul 2014 01:04:15 GMT
|
96
|
+
Content-Type:
|
97
|
+
- application/json; charset=utf-8
|
98
|
+
Transfer-Encoding:
|
99
|
+
- chunked
|
100
|
+
Status:
|
101
|
+
- 200 OK
|
102
|
+
X-Ratelimit-Limit:
|
103
|
+
- '60'
|
104
|
+
X-Ratelimit-Remaining:
|
105
|
+
- '56'
|
106
|
+
X-Ratelimit-Reset:
|
107
|
+
- '1405475907'
|
108
|
+
Cache-Control:
|
109
|
+
- public, max-age=60, s-maxage=60
|
110
|
+
Last-Modified:
|
111
|
+
- Thu, 10 Jul 2014 01:28:49 GMT
|
112
|
+
Etag:
|
113
|
+
- '"ea0aae4ec6b8ddf249d9c8f9c21e8f90"'
|
114
|
+
Vary:
|
115
|
+
- Accept
|
116
|
+
- Accept-Encoding
|
117
|
+
X-Github-Media-Type:
|
118
|
+
- github.v3; format=json
|
119
|
+
X-Xss-Protection:
|
120
|
+
- 1; mode=block
|
121
|
+
X-Frame-Options:
|
122
|
+
- deny
|
123
|
+
Content-Security-Policy:
|
124
|
+
- default-src 'none'
|
125
|
+
Access-Control-Allow-Credentials:
|
126
|
+
- 'true'
|
127
|
+
Access-Control-Expose-Headers:
|
128
|
+
- ETag, Link, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset,
|
129
|
+
X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
|
130
|
+
Access-Control-Allow-Origin:
|
131
|
+
- "*"
|
132
|
+
X-Github-Request-Id:
|
133
|
+
- DE962F8B:5BD7:F28324F:53C5CF8E
|
134
|
+
Strict-Transport-Security:
|
135
|
+
- max-age=31536000; includeSubdomains
|
136
|
+
X-Content-Type-Options:
|
137
|
+
- nosniff
|
138
|
+
X-Served-By:
|
139
|
+
- 03d91026ad8428f4d9966d7434f9d82e
|
140
|
+
body:
|
141
|
+
encoding: UTF-8
|
142
|
+
string: '{"name":"gh-diff","path":"bin/gh-diff","sha":"97f13c6aafe6520b33960b32c398e4c8bbeb4bf7","size":64,"url":"https://api.github.com/repos/melborne/gh-diff/contents/bin/gh-diff?ref=master","html_url":"https://github.com/melborne/gh-diff/blob/master/bin/gh-diff","git_url":"https://api.github.com/repos/melborne/gh-diff/git/blobs/97f13c6aafe6520b33960b32c398e4c8bbeb4bf7","type":"file","content":"IyEvdXNyL2Jpbi9lbnYgcnVieQoKcmVxdWlyZSAnZ2gtZGlmZicKCkdoRGlm\nZjo6Q0xJLnN0YXJ0KEFSR1YpCg==\n","encoding":"base64","_links":{"self":"https://api.github.com/repos/melborne/gh-diff/contents/bin/gh-diff?ref=master","git":"https://api.github.com/repos/melborne/gh-diff/git/blobs/97f13c6aafe6520b33960b32c398e4c8bbeb4bf7","html":"https://github.com/melborne/gh-diff/blob/master/bin/gh-diff"}}'
|
143
|
+
http_version:
|
144
|
+
recorded_at: Wed, 16 Jul 2014 01:04:15 GMT
|
145
|
+
recorded_with: VCR 2.9.2
|
data/spec/cli_spec.rb
CHANGED
@@ -94,7 +94,7 @@ describe GhDiff::CLI do
|
|
94
94
|
--save)
|
95
95
|
GhDiff::CLI.start
|
96
96
|
path = 'diff/docs/quickstart.diff'
|
97
|
-
expect($stdout.string).to match(/
|
97
|
+
expect($stdout.string).to match(/File saved at '#{path}'/)
|
98
98
|
expect(File.exist? path).to be true
|
99
99
|
expect(File.read path).to match(/-prev_section: old-home/)
|
100
100
|
end
|
@@ -130,5 +130,19 @@ describe GhDiff::CLI do
|
|
130
130
|
expect { GhDiff::CLI.start }.to raise_error(SystemExit)
|
131
131
|
expect($stdout.string).to match(/Repository should/)
|
132
132
|
end
|
133
|
+
|
134
|
+
context "with save option" do
|
135
|
+
it "saves new files" do
|
136
|
+
VCR.use_cassette('save-dir-diff') do
|
137
|
+
ARGV.replace %w(dir_diff bin
|
138
|
+
--repo=melborne/gh-diff
|
139
|
+
--save)
|
140
|
+
GhDiff::CLI.start
|
141
|
+
path = "diff/bin/gh-diff"
|
142
|
+
expect(File.exist? path).to be true
|
143
|
+
expect(File.read path).to match(/require.*gh-diff/)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
133
147
|
end
|
134
148
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gh-diff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kyoendo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: togglate
|
@@ -197,6 +197,7 @@ files:
|
|
197
197
|
- spec/cassettes/ref.yml
|
198
198
|
- spec/cassettes/save-diff.yml
|
199
199
|
- spec/cassettes/save-diffs.yml
|
200
|
+
- spec/cassettes/save-dir-diff.yml
|
200
201
|
- spec/cli_spec.rb
|
201
202
|
- spec/fixtures/docs/migrations.md
|
202
203
|
- spec/fixtures/docs/quickstart.md
|
@@ -224,7 +225,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
224
225
|
version: '0'
|
225
226
|
requirements: []
|
226
227
|
rubyforge_project:
|
227
|
-
rubygems_version: 2.
|
228
|
+
rubygems_version: 2.3.0
|
228
229
|
signing_key:
|
229
230
|
specification_version: 4
|
230
231
|
summary: Take diffs between local and a github repository files.
|
@@ -239,6 +240,7 @@ test_files:
|
|
239
240
|
- spec/cassettes/ref.yml
|
240
241
|
- spec/cassettes/save-diff.yml
|
241
242
|
- spec/cassettes/save-diffs.yml
|
243
|
+
- spec/cassettes/save-dir-diff.yml
|
242
244
|
- spec/cli_spec.rb
|
243
245
|
- spec/fixtures/docs/migrations.md
|
244
246
|
- spec/fixtures/docs/quickstart.md
|