defunkt-github 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/commands/commands.rb +70 -29
- data/commands/helpers.rb +76 -19
- data/github-gem.gemspec +3 -2
- data/lib/github/command.rb +8 -6
- data/spec/command_spec.rb +11 -0
- data/spec/helper_spec.rb +61 -0
- data/spec/ui_spec.rb +70 -20
- metadata +11 -3
data/commands/commands.rb
CHANGED
@@ -27,10 +27,13 @@ flags :shas => "Only show shas"
|
|
27
27
|
flags :project => "Filter commits on a certain project"
|
28
28
|
flags :author => "Filter commits on a email address of author"
|
29
29
|
flags :applies => "Filter commits to patches that apply cleanly"
|
30
|
+
flags :noapply => "Filter commits to patches that do not apply cleanly"
|
30
31
|
flags :nocache => "Do not use the cached network data"
|
31
32
|
flags :cache => "Use the network data even if it's expired"
|
32
33
|
flags :sort => "How to sort : date(*), branch, author"
|
33
34
|
flags :common => "Show common branch point"
|
35
|
+
flags :thisbranch => "Look at branches that match the current one"
|
36
|
+
flags :limit => "Only look through the first X heads - useful for really large projects"
|
34
37
|
command :network do |command, user|
|
35
38
|
return if !helper.project
|
36
39
|
user ||= helper.owner
|
@@ -54,36 +57,69 @@ command :network do |command, user|
|
|
54
57
|
end
|
55
58
|
when 'commits'
|
56
59
|
# show commits we don't have yet
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
60
|
+
|
61
|
+
$stderr.puts 'gathering heads'
|
62
|
+
cherry = []
|
63
|
+
|
64
|
+
if helper.cache_commits_data(options)
|
65
|
+
ids = []
|
66
|
+
data = helper.get_network_data(user, options)
|
67
|
+
data['users'].each do |hsh|
|
68
|
+
u = hsh['name']
|
69
|
+
if options[:thisbranch]
|
70
|
+
user_ids = hsh['heads'].map { |a| a['id'] if a['name'] == helper.current_branch }.compact
|
71
|
+
else
|
72
|
+
user_ids = hsh['heads'].map { |a| a['id'] }
|
67
73
|
end
|
74
|
+
user_ids.each do |id|
|
75
|
+
if !helper.has_commit?(id) && helper.cache_expired?
|
76
|
+
GitHub.invoke(:track, u) unless helper.tracking?(u)
|
77
|
+
puts "fetching #{u}"
|
78
|
+
GitHub.invoke(:fetch_all, u)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
ids += user_ids
|
82
|
+
end
|
83
|
+
ids.uniq!
|
84
|
+
|
85
|
+
$stderr.puts 'has heads'
|
86
|
+
|
87
|
+
# check that we have all these shas locally
|
88
|
+
local_heads = helper.local_heads
|
89
|
+
local_heads_not = local_heads.map { |a| "^#{a}"}
|
90
|
+
looking_for = (ids - local_heads) + local_heads_not
|
91
|
+
commits = helper.get_commits(looking_for)
|
92
|
+
|
93
|
+
$stderr.puts 'ID SIZE:' + ids.size.to_s
|
94
|
+
|
95
|
+
ignores = helper.ignore_sha_array
|
96
|
+
|
97
|
+
ids.each do |id|
|
98
|
+
next if ignores[id] || !commits.assoc(id)
|
99
|
+
cherries = helper.get_cherry(id)
|
100
|
+
cherries = helper.remove_ignored(cherries, ignores)
|
101
|
+
cherry += cherries
|
102
|
+
helper.ignore_shas([id]) if cherries.size == 0
|
103
|
+
$stderr.puts "checking head #{id} : #{cherry.size.to_s}"
|
104
|
+
break if options[:limit] && cherry.size > options[:limit].to_i
|
68
105
|
end
|
69
|
-
ids += user_ids
|
70
|
-
end
|
71
|
-
ids.uniq!
|
72
|
-
|
73
|
-
# check that we have all these shas locally
|
74
|
-
|
75
|
-
local_heads = helper.local_heads
|
76
|
-
local_heads_not = local_heads.map { |a| "^#{a}"}
|
77
|
-
looking_for = (ids - local_heads) + local_heads_not
|
78
|
-
commits = helper.get_commits(looking_for)
|
79
|
-
|
80
|
-
cherry = []
|
81
|
-
ids.each do |id|
|
82
|
-
cherry += helper.get_cherry(id)
|
83
106
|
end
|
84
|
-
|
107
|
+
|
108
|
+
if cherry.size > 0 || !helper.cache_commits_data(options)
|
85
109
|
helper.print_network_cherry_help if !options[:shas]
|
86
|
-
|
110
|
+
|
111
|
+
if helper.cache_commits_data(options)
|
112
|
+
$stderr.puts "caching..."
|
113
|
+
$stderr.puts "commits: " + cherry.size.to_s
|
114
|
+
our_commits = cherry.map { |item| c = commits.assoc(item[1]); [item, c] if c }
|
115
|
+
our_commits.delete_if { |item| item == nil }
|
116
|
+
helper.cache_commits(our_commits)
|
117
|
+
else
|
118
|
+
$stderr.puts "using cached..."
|
119
|
+
our_commits = helper.commits_cache
|
120
|
+
end
|
121
|
+
|
122
|
+
helper.print_commits(our_commits, options)
|
87
123
|
else
|
88
124
|
puts "no unapplied commits"
|
89
125
|
end
|
@@ -143,9 +179,14 @@ command :fetch do |user, branch|
|
|
143
179
|
user, branch = user.split("/", 2) if branch.nil?
|
144
180
|
branch ||= 'master'
|
145
181
|
GitHub.invoke(:track, user) unless helper.tracking?(user)
|
182
|
+
|
183
|
+
die "Unknown branch (#{branch}) specified" unless helper.remote_branch?(user, branch)
|
184
|
+
die "Unable to switch branches, your current branch has uncommitted changes" if helper.branch_dirty?
|
146
185
|
|
186
|
+
puts "Fetching #{user}/#{branch}"
|
147
187
|
git "fetch #{user} #{branch}:refs/remotes/#{user}/#{branch}"
|
148
|
-
|
188
|
+
git "update-ref refs/heads/#{user}/#{branch} refs/remotes/#{user}/#{branch}"
|
189
|
+
git_exec "checkout #{user}/#{branch}"
|
149
190
|
end
|
150
191
|
|
151
192
|
desc "Pull from a remote."
|
@@ -165,8 +206,8 @@ command :pull do |user, branch|
|
|
165
206
|
git_exec "pull #{user} #{branch}"
|
166
207
|
else
|
167
208
|
puts "Switching to #{user}/#{branch}"
|
168
|
-
git "
|
169
|
-
|
209
|
+
git "update-ref refs/heads/#{user}/#{branch} HEAD"
|
210
|
+
git "checkout #{user}/#{branch}"
|
170
211
|
end
|
171
212
|
end
|
172
213
|
|
data/commands/helpers.rb
CHANGED
@@ -67,6 +67,10 @@ helper :ignore_sha_array do
|
|
67
67
|
File.open( ignore_file_path ) { |yf| YAML::load( yf ) } rescue {}
|
68
68
|
end
|
69
69
|
|
70
|
+
helper :remove_ignored do |array, ignore_array|
|
71
|
+
array.reject { |id| ignore_array[id] }
|
72
|
+
end
|
73
|
+
|
70
74
|
helper :ignore_shas do |shas|
|
71
75
|
ignores = ignore_sha_array
|
72
76
|
shas.each do |sha|
|
@@ -91,9 +95,8 @@ helper :get_common do |branch|
|
|
91
95
|
`git rev-list ..#{branch} --boundary | tail -1 | git name-rev --stdin`.split(' ')[1] rescue 'unknown'
|
92
96
|
end
|
93
97
|
|
94
|
-
helper :print_commits do |
|
98
|
+
helper :print_commits do |our_commits, options|
|
95
99
|
ignores = ignore_sha_array
|
96
|
-
our_commits = cherries.map { |item| c = commits.assoc(item[1]); [item, c] if c }
|
97
100
|
|
98
101
|
case options[:sort]
|
99
102
|
when 'branch'
|
@@ -101,7 +104,7 @@ helper :print_commits do |cherries, commits, options|
|
|
101
104
|
when 'author'
|
102
105
|
our_commits.sort! { |a, b| a[1][1] <=> b[1][1] }
|
103
106
|
else
|
104
|
-
our_commits.sort! { |a, b| Date.parse(a[1][4]) <=> Date.parse(b[1][4]) }
|
107
|
+
our_commits.sort! { |a, b| Date.parse(a[1][4]) <=> Date.parse(b[1][4]) } rescue 'cant parse dates'
|
105
108
|
end
|
106
109
|
|
107
110
|
shown_commits = {}
|
@@ -114,15 +117,17 @@ helper :print_commits do |cherries, commits, options|
|
|
114
117
|
ref_name = ref_name.gsub('remotes/', '')
|
115
118
|
if status == '+' && commit
|
116
119
|
next if options[:author] && !commit[1].match(Regexp.new(options[:author]))
|
117
|
-
next if options[:before] && before && (before < Date.parse(commit[4]))
|
118
|
-
next if options[:after] && after && (after > Date.parse(commit[4]))
|
119
|
-
|
120
|
+
next if options[:before] && before && (before < Date.parse(commit[4])) rescue false
|
121
|
+
next if options[:after] && after && (after > Date.parse(commit[4])) rescue false
|
122
|
+
applies = applies_cleanly(sha)
|
123
|
+
next if options[:applies] && !applies
|
124
|
+
next if options[:noapply] && applies
|
120
125
|
if options[:shas]
|
121
126
|
puts sha
|
122
127
|
else
|
123
128
|
common = options[:common] ? get_common(sha) : ''
|
124
129
|
puts [sha[0,6], ref_name.ljust(25), commit[1][0,20].ljust(21),
|
125
|
-
commit[2][0, 36].ljust(38), commit[3], common].join(" ")
|
130
|
+
commit[2][0, 36].ljust(38), commit[3][0,15], common].join(" ")
|
126
131
|
end
|
127
132
|
end
|
128
133
|
shown_commits[sha] = true
|
@@ -136,7 +141,7 @@ end
|
|
136
141
|
|
137
142
|
helper :remotes do
|
138
143
|
regexp = '^remote\.(.+)\.url$'
|
139
|
-
`git config --get-regexp '#{regexp}'`.split(
|
144
|
+
`git config --get-regexp '#{regexp}'`.split("\n").inject({}) do |memo, line|
|
140
145
|
name_string, url = line.split(/ /, 2)
|
141
146
|
m, name = *name_string.match(/#{regexp}/)
|
142
147
|
memo[name.to_sym] = url
|
@@ -144,6 +149,27 @@ helper :remotes do
|
|
144
149
|
end
|
145
150
|
end
|
146
151
|
|
152
|
+
helper :remote_branches_for do |user|
|
153
|
+
`git ls-remote -h #{user} 2> /dev/null`.split(/\n/).inject({}) do |memo, line|
|
154
|
+
hash, head = line.split(/\t/, 2)
|
155
|
+
head = head[%r{refs/heads/(.+)$},1] unless head.nil?
|
156
|
+
memo[head] = hash unless head.nil?
|
157
|
+
memo
|
158
|
+
end if !(user.nil? || user.strip.empty?)
|
159
|
+
end
|
160
|
+
|
161
|
+
helper :remote_branch? do |user, branch|
|
162
|
+
remote_branches_for(user).key?(branch)
|
163
|
+
end
|
164
|
+
|
165
|
+
helper :branch_dirty? do
|
166
|
+
# see if there are any cached or tracked files that have been modified
|
167
|
+
# originally, we were going to use git-ls-files but that could only
|
168
|
+
# report modified track files...not files that have been staged
|
169
|
+
# for committal
|
170
|
+
!(system("git diff --quiet 2>/dev/null") or !system("git diff --cached --quiet 2>/dev/null"))
|
171
|
+
end
|
172
|
+
|
147
173
|
helper :tracking do
|
148
174
|
remotes.inject({}) do |memo, (name, url)|
|
149
175
|
if ur = user_and_repo_from(url)
|
@@ -163,8 +189,12 @@ helper :owner do
|
|
163
189
|
user_for(:origin)
|
164
190
|
end
|
165
191
|
|
192
|
+
helper :current_branch do
|
193
|
+
`git rev-parse --symbolic-full-name HEAD`.chomp.sub(/^refs\/heads\//, '')
|
194
|
+
end
|
195
|
+
|
166
196
|
helper :user_and_branch do
|
167
|
-
raw_branch =
|
197
|
+
raw_branch = current_branch
|
168
198
|
user, branch = raw_branch.split(/\//, 2)
|
169
199
|
if branch
|
170
200
|
[user, branch]
|
@@ -254,7 +284,7 @@ You have to provide a command :
|
|
254
284
|
end
|
255
285
|
|
256
286
|
helper :print_network_cherry_help do
|
257
|
-
puts "
|
287
|
+
$stderr.puts "
|
258
288
|
=========================================================================================
|
259
289
|
These are all the commits that other people have pushed that you have not
|
260
290
|
applied or ignored yet (see 'github ignore'). Some things you might want to do:
|
@@ -268,29 +298,56 @@ applied or ignored yet (see 'github ignore'). Some things you might want to do:
|
|
268
298
|
"
|
269
299
|
end
|
270
300
|
|
301
|
+
helper :argv do
|
302
|
+
GitHub.original_args
|
303
|
+
end
|
304
|
+
|
305
|
+
helper :network_members do
|
306
|
+
get_network_data(owner, {})['users'].map do |hash|
|
307
|
+
hash['name']
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
|
271
312
|
helper :get_network_data do |user, options|
|
272
313
|
if options[:cache] && has_cache?
|
273
314
|
return get_cache
|
274
315
|
end
|
275
|
-
|
276
|
-
if cache_expired? || options[:nocache] || !has_cache?
|
316
|
+
if cache_network_data(options)
|
277
317
|
return cache_data(user)
|
278
318
|
else
|
279
319
|
return get_cache
|
280
320
|
end
|
281
321
|
end
|
282
322
|
|
283
|
-
helper :
|
284
|
-
|
285
|
-
|
323
|
+
helper :cache_commits do |commits|
|
324
|
+
File.open( commits_cache_path, 'w' ) do |out|
|
325
|
+
out.write(commits.to_yaml)
|
286
326
|
end
|
287
327
|
end
|
288
328
|
|
329
|
+
helper :commits_cache do
|
330
|
+
YAML.load(File.open(commits_cache_path))
|
331
|
+
end
|
332
|
+
|
333
|
+
helper :cache_commits_data do |options|
|
334
|
+
cache_expired? || options[:nocache] || !has_commits_cache?
|
335
|
+
end
|
336
|
+
|
337
|
+
helper :cache_network_data do |options|
|
338
|
+
cache_expired? || options[:nocache] || !has_cache?
|
339
|
+
end
|
340
|
+
|
289
341
|
helper :network_cache_path do
|
290
342
|
dir = `git rev-parse --git-dir`.chomp
|
291
343
|
File.join(dir, 'network-cache')
|
292
344
|
end
|
293
345
|
|
346
|
+
helper :commits_cache_path do
|
347
|
+
dir = `git rev-parse --git-dir`.chomp
|
348
|
+
File.join(dir, 'commits-cache')
|
349
|
+
end
|
350
|
+
|
294
351
|
helper :cache_data do |user|
|
295
352
|
raw_data = Kernel.open(network_meta_for(user)).read
|
296
353
|
File.open( network_cache_path, 'w' ) do |out|
|
@@ -310,10 +367,10 @@ helper :has_cache? do
|
|
310
367
|
File.file?(network_cache_path)
|
311
368
|
end
|
312
369
|
|
313
|
-
helper :
|
314
|
-
|
370
|
+
helper :has_commits_cache? do
|
371
|
+
File.file?(commits_cache_path)
|
315
372
|
end
|
316
373
|
|
317
|
-
helper :
|
318
|
-
|
374
|
+
helper :get_cache do
|
375
|
+
JSON.parse(File.read(network_cache_path))
|
319
376
|
end
|
data/github-gem.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
|
-
s.name =
|
3
|
-
s.version = "0.3.
|
2
|
+
s.name = "github"
|
3
|
+
s.version = "0.3.1"
|
4
4
|
|
5
5
|
s.specification_version = 2 if s.respond_to? :specification_version=
|
6
6
|
|
@@ -22,4 +22,5 @@ Gem::Specification.new do |s|
|
|
22
22
|
s.summary = %q{The official `github` command line helper for simplifying your GitHub experience.}
|
23
23
|
|
24
24
|
# s.add_dependency(%q<launchy>, [">= 0"])
|
25
|
+
s.add_dependency('json', [">= 0"])
|
25
26
|
end
|
data/lib/github/command.rb
CHANGED
@@ -46,13 +46,16 @@ module GitHub
|
|
46
46
|
def sh(*command)
|
47
47
|
Shell.new(*command).run
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
def die(message)
|
51
51
|
puts "=> #{message}"
|
52
52
|
exit!
|
53
53
|
end
|
54
54
|
|
55
55
|
class Shell < String
|
56
|
+
attr_reader :error
|
57
|
+
attr_reader :out
|
58
|
+
|
56
59
|
def initialize(*command)
|
57
60
|
@command = command
|
58
61
|
end
|
@@ -64,11 +67,10 @@ module GitHub
|
|
64
67
|
out = out.read.strip
|
65
68
|
err = err.read.strip
|
66
69
|
|
67
|
-
if
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
end
|
70
|
+
replace @error = err if err.any?
|
71
|
+
replace @out = out if out.any?
|
72
|
+
|
73
|
+
self
|
72
74
|
end
|
73
75
|
|
74
76
|
def command
|
data/spec/command_spec.rb
CHANGED
@@ -24,7 +24,9 @@ describe GitHub::Command do
|
|
24
24
|
unguard(Kernel, :exec)
|
25
25
|
hi = @command.sh("echo hi")
|
26
26
|
hi.should == "hi"
|
27
|
+
hi.out.should == "hi"
|
27
28
|
hi.out?.should be(true)
|
29
|
+
hi.error.should be_nil
|
28
30
|
hi.error?.should be(false)
|
29
31
|
hi.command.should == "echo hi"
|
30
32
|
if RUBY_PLATFORM =~ /mingw|mswin/
|
@@ -34,9 +36,18 @@ describe GitHub::Command do
|
|
34
36
|
end
|
35
37
|
bye = @command.sh(command)
|
36
38
|
bye.should == "bye"
|
39
|
+
bye.out.should be_nil
|
37
40
|
bye.out?.should be(false)
|
41
|
+
bye.error.should == "bye"
|
38
42
|
bye.error?.should be(true)
|
39
43
|
bye.command.should == command
|
44
|
+
hi_and_bye = @command.sh("echo hi; echo bye >&2")
|
45
|
+
hi_and_bye.should == "hi"
|
46
|
+
hi_and_bye.out.should == "hi"
|
47
|
+
hi_and_bye.out?.should be(true)
|
48
|
+
hi_and_bye.error.should == "bye"
|
49
|
+
hi_and_bye.error?.should be(true)
|
50
|
+
hi_and_bye.command.should == "echo hi; echo bye >&2"
|
40
51
|
end
|
41
52
|
|
42
53
|
it "should return the results of a git operation" do
|
data/spec/helper_spec.rb
CHANGED
@@ -149,6 +149,67 @@ remote.nex3.url git://github.com/nex3/github-gem.git
|
|
149
149
|
end
|
150
150
|
end
|
151
151
|
|
152
|
+
helper :remote_branches_for do
|
153
|
+
it "should return an empty list because no user was provided" do
|
154
|
+
@helper.remote_branches_for(nil).should == nil
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should return a list of remote branches for defunkt" do
|
158
|
+
@helper.should_receive(:`).with('git ls-remote -h defunkt 2> /dev/null').and_return <<-EOF
|
159
|
+
fe1f852f3cf719c7cd86147031732f570ad89619 refs/heads/kballard/master
|
160
|
+
f8a6bb42b0ed43ac7336bfcda246e59a9da949d6 refs/heads/master
|
161
|
+
624d9c2f742ff24a79353a7e02bf289235c72ff1 refs/heads/restart
|
162
|
+
EOF
|
163
|
+
@helper.remote_branches_for("defunkt").should == {
|
164
|
+
"master" => "f8a6bb42b0ed43ac7336bfcda246e59a9da949d6",
|
165
|
+
"kballard/master" => "fe1f852f3cf719c7cd86147031732f570ad89619",
|
166
|
+
"restart" => "624d9c2f742ff24a79353a7e02bf289235c72ff1"
|
167
|
+
}
|
168
|
+
end
|
169
|
+
|
170
|
+
it "should return an empty list of remote branches for nex3 and nex4" do
|
171
|
+
# the following use-case should never happen as the -h parameter should only return heads on remote branches
|
172
|
+
# however, we are testing this particular case to verify how remote_branches_for would respond if random
|
173
|
+
# git results
|
174
|
+
@helper.should_receive(:`).with('git ls-remote -h nex3 2> /dev/null').and_return <<-EOF
|
175
|
+
fe1f852f3cf719c7cd86147031732f570ad89619 HEAD
|
176
|
+
a1a392369e5b7842d01cce965272d4b96c2fd343 refs/tags/v0.1.3
|
177
|
+
624d9c2f742ff24a79353a7e02bf289235c72ff1 refs/remotes/origin/master
|
178
|
+
random
|
179
|
+
random_again
|
180
|
+
EOF
|
181
|
+
@helper.remote_branches_for("nex3").should be_empty
|
182
|
+
|
183
|
+
@helper.should_receive(:`).with('git ls-remote -h nex4 2> /dev/null').and_return ""
|
184
|
+
@helper.remote_branches_for("nex4").should be_empty
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
helper :remote_branch? do
|
189
|
+
it "should return whether the branch exists at the remote user" do
|
190
|
+
@helper.should_receive(:remote_branches_for).with("defunkt").any_number_of_times.and_return({
|
191
|
+
"master" => "f8a6bb42b0ed43ac7336bfcda246e59a9da949d6",
|
192
|
+
"kballard/master" => "fe1f852f3cf719c7cd86147031732f570ad89619",
|
193
|
+
"restart" => "624d9c2f742ff24a79353a7e02bf289235c72ff1"
|
194
|
+
})
|
195
|
+
@helper.remote_branch?("defunkt", "master").should == true
|
196
|
+
@helper.remote_branch?("defunkt", "not_master").should == false
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
helper :branch_dirty? do
|
201
|
+
it "should return false" do
|
202
|
+
@helper.should_receive(:system).with(/^git diff/).and_return(0, 0)
|
203
|
+
@helper.branch_dirty?.should == 0
|
204
|
+
end
|
205
|
+
|
206
|
+
it "should return true" do
|
207
|
+
@helper.should_receive(:system).with(/^git diff/).and_return(1, 1, 0, 1)
|
208
|
+
@helper.branch_dirty?.should == 1
|
209
|
+
@helper.branch_dirty?.should == 1
|
210
|
+
end
|
211
|
+
end
|
212
|
+
|
152
213
|
helper :tracking do
|
153
214
|
it "should return a list of remote/user_or_url pairs" do
|
154
215
|
@helper.should_receive(:remotes).and_return({
|
data/spec/ui_spec.rb
CHANGED
@@ -157,10 +157,10 @@ EOF
|
|
157
157
|
end
|
158
158
|
end
|
159
159
|
|
160
|
-
# --
|
161
|
-
specify "
|
162
|
-
running :
|
163
|
-
@command.should_receive(:die).with("Specify a user to pull from").and_return { raise "Died"
|
160
|
+
# -- fetch --
|
161
|
+
specify "fetch should die with no args" do
|
162
|
+
running :fetch do
|
163
|
+
@command.should_receive(:die).with("Specify a user to pull from").and_return { raise "Died "}
|
164
164
|
self.should raise_error("Died")
|
165
165
|
end
|
166
166
|
end
|
@@ -179,10 +179,10 @@ EOF
|
|
179
179
|
running :pull, "defunkt" do
|
180
180
|
mock_members 'defunkt'
|
181
181
|
setup_remote(:defunkt)
|
182
|
-
@
|
183
|
-
|
184
|
-
|
185
|
-
@command.should_receive(:git_exec).with("
|
182
|
+
@helper.should_receive(:branch_dirty?).and_return false
|
183
|
+
@command.should_receive(:git).with("update-ref refs/heads/defunkt/master HEAD").ordered
|
184
|
+
@command.should_receive(:git).with("checkout defunkt/master").ordered
|
185
|
+
@command.should_receive(:git_exec).with("fetch defunkt master").ordered
|
186
186
|
stdout.should == "Switching to defunkt/master\n"
|
187
187
|
end
|
188
188
|
end
|
@@ -191,11 +191,55 @@ EOF
|
|
191
191
|
running :pull, "defunkt" do
|
192
192
|
mock_members 'defunkt'
|
193
193
|
setup_remote(:defunkt)
|
194
|
-
@
|
195
|
-
|
196
|
-
|
194
|
+
@helper.should_receive(:branch_dirty?).and_return true
|
195
|
+
@command.should_receive(:die).with("Unable to switch branches, your current branch has uncommitted changes").and_return { raise "Died" }
|
196
|
+
self.should raise_error("Died")
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
specify "fetch defunkt/wip should create defunkt/wip and fetch from wip branch on defunkt remote" do
|
201
|
+
running :fetch, "defunkt/wip" do
|
202
|
+
setup_remote(:defunkt, :remote_branches => ["master", "wip"])
|
203
|
+
@helper.should_receive(:branch_dirty?).and_return false
|
204
|
+
@command.should_receive(:git).with("update-ref refs/heads/defunkt/wip HEAD").ordered
|
205
|
+
@command.should_receive(:git).with("checkout defunkt/wip").ordered
|
206
|
+
@command.should_receive(:git_exec).with("fetch defunkt wip").ordered
|
207
|
+
stdout.should == "Switching to defunkt/wip\n"
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
specify "fetch --merge defunkt should fetch from defunkt remote into current branch" do
|
212
|
+
running :fetch, "--merge", "defunkt" do
|
213
|
+
setup_remote(:defunkt)
|
214
|
+
@helper.should_receive(:branch_dirty?).and_return false
|
215
|
+
@command.should_receive(:git_exec).with("fetch defunkt master")
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
# -- fetch --
|
220
|
+
specify "fetch should die with no args" do
|
221
|
+
running :fetch do
|
222
|
+
@command.should_receive(:die).with("Specify a user to fetch from").and_return { raise "Died" }
|
223
|
+
self.should raise_error("Died")
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
specify "fetch defunkt should start tracking defunkt if they're not already tracked" do
|
228
|
+
running :fetch, "defunkt" do
|
229
|
+
setup_remote(:origin, :user => "user", :ssh => true)
|
230
|
+
setup_remote(:external, :url => "home:/path/to/project.git")
|
231
|
+
GitHub.should_receive(:invoke).with(:track, "defunkt").and_return { raise "Tracked" }
|
232
|
+
self.should raise_error("Tracked")
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
specify "fetch defunkt should create defunkt/master and fetch from the defunkt remote" do
|
237
|
+
running :fetch, "defunkt" do
|
238
|
+
setup_remote(:defunkt)
|
239
|
+
@helper.should_receive(:branch_dirty?).and_return false
|
240
|
+
@command.should_receive(:git).with("update-ref refs/heads/defunkt/master HEAD").ordered
|
197
241
|
@command.should_receive(:git).with("checkout defunkt/master").ordered
|
198
|
-
@command.should_receive(:git_exec).with("
|
242
|
+
@command.should_receive(:git_exec).with("fetch defunkt master").ordered
|
199
243
|
stdout.should == "Switching to defunkt/master\n"
|
200
244
|
end
|
201
245
|
end
|
@@ -204,11 +248,9 @@ EOF
|
|
204
248
|
running :pull, "defunkt", "wip" do
|
205
249
|
mock_members 'defunkt'
|
206
250
|
setup_remote(:defunkt)
|
207
|
-
@
|
208
|
-
|
209
|
-
|
210
|
-
@command.should_receive(:git_exec).with("pull defunkt wip").ordered
|
211
|
-
stdout.should == "Switching to defunkt/wip\n"
|
251
|
+
@helper.should_receive(:branch_dirty?).and_return true
|
252
|
+
@command.should_receive(:die).with("Unable to switch branches, your current branch has uncommitted changes").and_return { raise "Died" }
|
253
|
+
self.should raise_error("Died")
|
212
254
|
end
|
213
255
|
end
|
214
256
|
|
@@ -220,7 +262,7 @@ EOF
|
|
220
262
|
mock("checkout -b defunkt/wip").tap { |m| m.should_receive(:error?) { true } }
|
221
263
|
end
|
222
264
|
@command.should_receive(:git).with("checkout defunkt/wip").ordered
|
223
|
-
@command.should_receive(:git_exec).with("
|
265
|
+
@command.should_receive(:git_exec).with("fetch defunkt wip").ordered
|
224
266
|
stdout.should == "Switching to defunkt/wip\n"
|
225
267
|
end
|
226
268
|
end
|
@@ -229,7 +271,8 @@ EOF
|
|
229
271
|
running :pull, "--merge", "defunkt" do
|
230
272
|
mock_members 'defunkt'
|
231
273
|
setup_remote(:defunkt)
|
232
|
-
@
|
274
|
+
@helper.should_receive(:branch_dirty?).and_return false
|
275
|
+
@command.should_receive(:git_exec).with("fetch defunkt master")
|
233
276
|
end
|
234
277
|
end
|
235
278
|
|
@@ -434,12 +477,14 @@ EOF
|
|
434
477
|
@stderr_mock.invoke unless @stderr_mock.nil?
|
435
478
|
end
|
436
479
|
|
437
|
-
def setup_remote(remote, options = {:user => nil, :project => "project"})
|
480
|
+
def setup_remote(remote, options = {:user => nil, :project => "project", :remote_branches => nil})
|
438
481
|
@remotes ||= {}
|
482
|
+
@remote_branches ||= {}
|
439
483
|
user = options[:user] || remote
|
440
484
|
project = options[:project]
|
441
485
|
ssh = options[:ssh]
|
442
486
|
url = options[:url]
|
487
|
+
remote_branches = options[:remote_branches] || ["master"]
|
443
488
|
if url
|
444
489
|
@remotes[remote.to_sym] = url
|
445
490
|
elsif ssh
|
@@ -447,6 +492,11 @@ EOF
|
|
447
492
|
else
|
448
493
|
@remotes[remote.to_sym] = "git://github.com/#{user}/#{project}.git"
|
449
494
|
end
|
495
|
+
|
496
|
+
@remote_branches[remote.to_sym] = (@remote_branches[remote.to_sym] || Array.new) | remote_branches
|
497
|
+
@helper.should_receive(:remote_branch?).any_number_of_times.and_return do |remote, branch|
|
498
|
+
@remote_branches.fetch(remote.to_sym,[]).include?(branch)
|
499
|
+
end
|
450
500
|
end
|
451
501
|
|
452
502
|
def mock_remotes()
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: defunkt-github
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Wanstrath, Kevin Ballard, Scott Chacon
|
@@ -11,8 +11,16 @@ cert_chain: []
|
|
11
11
|
|
12
12
|
date: 2008-05-18 00:00:00 -07:00
|
13
13
|
default_executable: gh
|
14
|
-
dependencies:
|
15
|
-
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: json
|
17
|
+
version_requirement:
|
18
|
+
version_requirements: !ruby/object:Gem::Requirement
|
19
|
+
requirements:
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: "0"
|
23
|
+
version:
|
16
24
|
description: The official `github` command line helper for simplifying your GitHub experience.
|
17
25
|
email: chris@ozmm.org
|
18
26
|
executables:
|