gh-diff 0.0.3 → 0.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8f0ca5acb8cb4b38f633229ea7a43fa0b803ab7a
4
- data.tar.gz: 6975c4a9e86f67f8b147998b7b8c2b2fb1a16b17
3
+ metadata.gz: 15521f2f4b02e468636ac647062099620407d809
4
+ data.tar.gz: 65e651c2a715234b656baff23b367bb0cb5369ae
5
5
  SHA512:
6
- metadata.gz: 7bac507888d8dcbd305173ac5593328813d22725cf622bf5494f79f4fa86c6e690a56b66bea056a2077d19150e0905d5ed38615453325294db2f808f53037be9
7
- data.tar.gz: ec3fc3cfb2d0d7bd1aafdb83a2afc8f5fc1e392f41279bc98254fbe58610aa7ec9b1b37d857075815f16b3745877ad247805d79464bfd1b44e7abe51f2af3b13
6
+ metadata.gz: a2ce5b3b85a2c8c28f48a5254c81cb76f6af5bb8797aad39aa3a241b614af2d3ea5a597c1616490f9b44b0dc4f1ad3fafaf838cf8112166c3faf178e5538d1ec
7
+ data.tar.gz: 429c82cb0063b371fbcbf7d8237f2677e63ad8e076a54648cd7092bc704ee7c0230c1465348d41474ce0633ba61b367d7fefaaf597d4e801d557f28931269e54
data/.travis.yml CHANGED
@@ -1,3 +1,3 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.1.1
3
+ - 2.0.0
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Gh-Diff
2
2
 
3
+ [![Build Status](https://travis-ci.org/melborne/gh-diff.svg?branch=master)](https://travis-ci.org/melborne/gh-diff)
4
+
3
5
  Take diffs between local and a github repository files.
4
6
 
5
7
  ## Installation
data/lib/gh-diff.rb CHANGED
@@ -9,9 +9,11 @@ require "diffy"
9
9
  require "togglate"
10
10
 
11
11
  module GhDiff
12
+ class RepositoryNameError < StandardError; end
12
13
  class Diff
13
14
  attr_accessor :repo, :revision, :dir
14
15
  def initialize(repo, revision:'master', dir:nil)
16
+ raise RepositoryNameError if repo.nil? || repo.empty?
15
17
  @repo = repo
16
18
  @revision = revision
17
19
  @dir = dir
data/lib/gh-diff/cli.rb CHANGED
@@ -29,7 +29,7 @@ module GhDiff
29
29
  opts = Option.new(options).with_env
30
30
  github_auth(opts[:username], opts[:password], opts[:token])
31
31
 
32
- gh = Diff.new(opts[:repo], revision:opts[:revision], dir:opts[:dir])
32
+ gh = init_ghdiff(opts[:repo], opts[:revision], opts[:dir])
33
33
  if opts[:ref]
34
34
  ref = gh.ref(opts[:revision], repo:opts[:repo])
35
35
  print "Base revision: #{ref[:object][:sha]}[#{ref[:ref]}]\n"
@@ -71,7 +71,7 @@ module GhDiff
71
71
  opts = Option.new(options).with_env
72
72
  github_auth(opts[:username], opts[:password], opts[:token])
73
73
 
74
- gh = Diff.new(opts[:repo], revision:opts[:revision], dir:opts[:dir])
74
+ gh = init_ghdiff(opts[:repo], opts[:revision], opts[:dir])
75
75
  diffs = gh.diff(file1, file2, commentout:opts[:commentout],
76
76
  comment_tag:opts[:comment_tag])
77
77
 
@@ -117,7 +117,7 @@ Base revision: #{ref[:object][:sha]}[#{ref[:ref]}]
117
117
  opts = Option.new(options).with_env
118
118
  github_auth(opts[:username], opts[:password], opts[:token])
119
119
 
120
- gh = Diff.new(opts[:repo], revision:opts[:revision], dir:opts[:dir])
120
+ gh = init_ghdiff(opts[:repo], opts[:revision], opts[:dir])
121
121
  added, removed = gh.dir_diff(dir)
122
122
  if [added, removed].all?(&:empty?)
123
123
  puts "\e[33mNothing changed\e[0m"
@@ -133,8 +133,21 @@ Base revision: #{ref[:object][:sha]}[#{ref[:ref]}]
133
133
  end
134
134
  end
135
135
 
136
+ desc "version", "Show gh-diff version"
137
+ def version
138
+ puts "gh-diff #{GhDiff::VERSION} (c) 2014 kyoendo"
139
+ end
140
+ map "-v" => :version
141
+
136
142
  @@login = nil
137
143
  no_tasks do
144
+ def init_ghdiff(repo, rev, dir)
145
+ Diff.new(repo, revision:rev, dir:dir)
146
+ rescue GhDiff::RepositoryNameError
147
+ puts "Repository should be specified with 'repo' option"
148
+ exit(1)
149
+ end
150
+
138
151
  def github_auth(username, password, token)
139
152
  return true if @@login
140
153
  return false unless token || [username, password].all?
@@ -150,8 +163,9 @@ Base revision: #{ref[:object][:sha]}[#{ref[:ref]}]
150
163
  end
151
164
 
152
165
  def save(content, save_dir, file)
153
- file = File.join(File.dirname(file), (File.basename(file, '.*') + '.diff'))
154
- path = File.join(save_dir, file)
166
+ dir = (d=File.dirname(file))=='.' ? '' : d
167
+ file = File.basename(file, '.*') + '.diff'
168
+ path = File.join(save_dir, dir, file)
155
169
  mkdir(File.dirname path)
156
170
  File.write(path, content)
157
171
  print "\e[32mDiff saved at '#{path}'\e[0m\n"
@@ -1,3 +1,3 @@
1
1
  module GhDiff
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/spec/cli_spec.rb CHANGED
@@ -49,6 +49,12 @@ describe GhDiff::CLI do
49
49
  end
50
50
  end
51
51
 
52
+ it "raises an error when repo is empty" do
53
+ ARGV.replace %w(get docs/quickstart.md --repo=)
54
+ expect { GhDiff::CLI.start }.to raise_error(SystemExit)
55
+ expect($stdout.string).to match(/Repository should/)
56
+ end
57
+
52
58
  context "with ref option" do
53
59
  it "also prints reference data of the file" do
54
60
  VCR.use_cassette 'quickstart-ref' do
@@ -74,6 +80,12 @@ describe GhDiff::CLI do
74
80
  end
75
81
  end
76
82
 
83
+ it "raises an error when repo is empty" do
84
+ ARGV.replace %w(diff docs/quickstart.md --repo=)
85
+ expect { GhDiff::CLI.start }.to raise_error(SystemExit)
86
+ expect($stdout.string).to match(/Repository should/)
87
+ end
88
+
77
89
  context "with save option" do
78
90
  it "saves a diff file" do
79
91
  VCR.use_cassette('save-diff') do
@@ -112,5 +124,11 @@ describe GhDiff::CLI do
112
124
  expect($stdout.string).to match(/New files:.*collections.md/m)
113
125
  end
114
126
  end
127
+
128
+ it "raises an error when repo is empty" do
129
+ ARGV.replace %w(dir_diff docs/quickstart.md --repo=)
130
+ expect { GhDiff::CLI.start }.to raise_error(SystemExit)
131
+ expect($stdout.string).to match(/Repository should/)
132
+ end
115
133
  end
116
134
  end
data/spec/gh-diff_spec.rb CHANGED
@@ -59,6 +59,14 @@ describe GhDiff::Diff do
59
59
  Dir.chdir(@original_dir)
60
60
  end
61
61
 
62
+ describe ".new" do
63
+ context "without repo" do
64
+ it "raises an error" do
65
+ expect{ GhDiff::Diff.new '' }.to raise_error(GhDiff::RepositoryNameError)
66
+ end
67
+ end
68
+ end
69
+
62
70
  describe "#get" do
63
71
  it "returns a file content" do
64
72
  VCR.use_cassette('quickstart') do
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.3
4
+ version: 0.0.4
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-03 00:00:00.000000000 Z
11
+ date: 2014-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: togglate