Commit 6260242fd432241af845ecd514bf154184cf32a0

fixed naming consistency to use "remote" vs. "source". "remote" instead of "remote_name". fetching from multiple remotes no longer updates the top-most progress percentage for each remote

Commit diff

Support/app/controllers/remote_controller.rb

 
1414 branch = git.branch.current_branch
1515 branch_remote = branch && branch_remote
1616
17 for_each_selected_remote(:title => "Fetch", :prompt => "Fetch from which shared repository?", :items => git.sources, :default => branch.remote) do |source|
18 puts "<h2>Fetching from #{source}</h2>"
19 output = run_fetch(source)
17 for_each_selected_remote(:title => "Fetch", :prompt => "Fetch from which shared repository?", :items => git.remotes, :default => branch.remote) do |remote|
18 puts "<h2>Fetching from #{remote}</h2>"
19 output = run_fetch(remote)
2020 puts htmlize(output[:text])
2121
2222 unless output[:fetches].empty?
2424 output_branch_logs(output[:fetches])
2525 end
2626
27 puts "<h2>Pruning stale branches from #{source}</h2>"
28 puts git.command('remote', 'prune', source)
27 puts "<h2>Pruning stale branches from #{remote}</h2>"
28 puts git.command('remote', 'prune', remote)
2929 puts "<p>Done.</p>"
3030 end
3131 end
3636 output_show_html and return
3737 end
3838
39 sources = git.sources.with_this_at_front(branch.remote)
39 remotes = git.remotes.with_this_at_front(branch.remote)
4040
41 TextMate::UI.request_item(:title => "Push", :prompt => "Pull from where?", :items => sources) do |source|
42 # check to see if the branch has a pull source set up. if not, prompt them for which branch to pull from
43 if (source != branch.remote) || branch.merge.nil?
41 TextMate::UI.request_item(:title => "Push", :prompt => "Pull from where?", :items => remotes) do |remote|
42 # check to see if the branch has a pull remote set up. if not, prompt them for which branch to pull from
43 if (remote != branch.remote) || branch.merge.nil?
4444 # select a branch to merge from
45 remote_branch_name = setup_auto_merge(source, branch)
45 remote_branch_name = setup_auto_merge(remote, branch)
4646 return false unless remote_branch_name
4747 end
4848
49 puts "<p>Pulling from remote source '#{source}'\n</p>"
49 puts "<p>Pulling from remote source '#{remote}'\n</p>"
5050
5151 with_submodule_cacheing do
52 output = run_pull(source, remote_branch_name)
52 output = run_pull(remote, remote_branch_name)
5353 puts "<pre>#{output[:text]}</pre>"
5454
5555 if ! output[:pulls].empty?
6666
6767 def push
6868 current_name = git.branch.current.name
69 for_each_selected_remote(:title => "Push", :prompt => "Select a remote source to push the branch #{current_name} to:", :items => git.sources) do |source_name|
70 puts "<p>Pushing to remote source '#{source_name}'\n</p>"
71 display_push_output(run_push(source_name, :branch => current_name))
69 for_each_selected_remote(:title => "Push", :prompt => "Select a remote source to push the branch #{current_name} to:", :items => git.remotes) do |remote|
70 puts "<p>Pushing to remote source '#{remote}'\n</p>"
71 display_push_output(run_push(remote, :branch => current_name))
7272 end
7373 end
7474
7575 def push_tag
7676 tag = params[:tag] || (raise "select tag not yet implemented")
77 for_each_selected_remote(:title => "Push", :prompt => "Select a remote source to push the tag #{tag} to:", :items => git.sources) do |source_name|
78 puts "<p>Pushing tag #{tag} to '#{source_name}'\n</p>"
79 display_push_output(run_push(source_name, :tag => tag))
77 for_each_selected_remote(:title => "Push", :prompt => "Select a remote source to push the tag #{tag} to:", :items => git.remotes) do |remote|
78 puts "<p>Pushing tag #{tag} to '#{remote}'\n</p>"
79 display_push_output(run_push(remote, :tag => tag))
8080 end
8181 end
8282
8383 protected
84 def setup_auto_merge(source, branch)
85 remote_branches = git.branch.list_names(:remote, :remote_name => source ).with_this_at_front(/(\/|^)#{branch.name}$/)
84 def setup_auto_merge(remote, branch)
85 remote_branches = git.branch.list_names(:remote, :remote => remote ).with_this_at_front(/(\/|^)#{branch.name}$/)
8686 remote_branch_name = TextMate::UI.request_item(:title => "Branch to merge from?", :prompt => "Merge which branch to '#{branch.name}'?", :items => remote_branches, :force_pick => true)
8787 if remote_branch_name.nil? || remote_branch_name.empty?
8888 puts "Aborted"
9090 end
9191
9292 if TextMate::UI.alert(:warning, "Setup automerge for these branches?", "Would you like me to tell git to always merge:\n #{remote_branch_name} -> #{branch.name}?", 'Yes', 'No') == "Yes"
93 branch.remote = source
93 branch.remote = remote
9494 branch.merge = "refs/heads/" + remote_branch_name.split("/").last
9595 end
9696 remote_branch_name
117117 end
118118 end
119119
120 def run_pull(source, remote_branch_name)
120 def run_pull(remote, remote_branch_name)
121121 flush
122 pulls = git.pull(source, remote_branch_name,
123 :start => lambda { |state, count| progress_start(state, count) },
124 :progress => lambda { |state, percentage, index, count| progress(state, percentage, index, count)},
125 :end => lambda { |state, count| progress_end(state, count) }
122 pulls = git.pull(remote, remote_branch_name,
123 :start => lambda { |state, count| progress_start(remote, state, count) },
124 :progress => lambda { |state, percentage, index, count| progress(remote, state, percentage, index, count)},
125 :end => lambda { |state, count| progress_end(remote, state, count) }
126126 )
127127 rescan_project
128128 pulls
129129 end
130130
131 def run_push(source_name, options = {})
131 def run_push(remote, options = {})
132132 flush
133 git.push(source_name, options.merge(
134 :start => lambda { |state, count| progress_start(state, count) },
135 :progress => lambda { |state, percentage, index, count| progress(state, percentage, index, count)},
136 :end => lambda { |state, count| progress_end(state, count) }
133 git.push(remote, options.merge(
134 :start => lambda { |state, count| progress_start(remote, state, count) },
135 :progress => lambda { |state, percentage, index, count| progress(remote, state, percentage, index, count)},
136 :end => lambda { |state, count| progress_end(remote, state, count) }
137137 ))
138138 end
139139
140 def run_fetch(source)
140 def run_fetch(remote)
141141 flush
142 git.fetch(source,
143 :start => lambda { |state, count| progress_start(state, count) },
144 :progress => lambda { |state, percentage, index, count| progress(state, percentage, index, count)},
145 :end => lambda { |state, count| progress_end(state, count) }
142 git.fetch(remote,
143 :start => lambda { |state, count| progress_start(remote, state, count) },
144 :progress => lambda { |state, percentage, index, count| progress(remote, state, percentage, index, count)},
145 :end => lambda { |state, count| progress_end(remote, state, count) }
146146 )
147147 end
148148
149 def progress_start(state, count)
150 puts("<div>#{state} #{count} objects. <span id='#{state}_progress'>0% 0 / #{count}</span></div>")
149 def progress_start(remote, state, count)
150 puts("<div>#{remote}_#{state} #{count} objects. <span id='#{state}_progress'>0% 0 / #{count}</span></div>")
151151 end
152152
153 def progress(state, percentage, index, count)
153 def progress(remote, state, percentage, index, count)
154154 puts <<-EOF
155155 <script language='JavaScript'>
156 $('#{state}_progress').update('#{percentage}% #{index} / #{count}')
156 $('#{remote}_#{state}_progress').update('#{percentage}% #{index} / #{count}')
157157 </script>
158158 EOF
159159
160160 flush
161161 end
162162
163 def progress_end(state, count)
163 def progress_end(remote, state, count)
164164 puts <<-EOF
165165 <script language='JavaScript'>
166 $('#{state}_progress').update('Done')
166 $('#{remote}_#{state}_progress').update('Done')
167167 </script>
168168 EOF
169169 flush
172172 def for_each_selected_remote(options, &block)
173173 options = {:title => "Select remote", :prompt => "Select a remote...", :force_pick => true}.merge(options)
174174 default = options.delete(:default)
175 sources = options[:items]
175 remotes = options[:items]
176176 if default
177 sources.unshift(default)
178 sources.uniq!
177 remotes.unshift(default)
178 remotes.uniq!
179179 end
180180
181 sources << ALL_REMOTES if sources.length > 1
181 remotes << ALL_REMOTES if remotes.length > 1
182182 TextMate::UI.request_item(options) do |selections|
183 ((selections == ALL_REMOTES) ? (sources-[ALL_REMOTES]) : [selections]).each do |selection|
183 ((selections == ALL_REMOTES) ? (remotes-[ALL_REMOTES]) : [selections]).each do |selection|
184184 yield selection
185185 end
186186 end
toggle raw diff

Support/lib/commands/branch.rb

 
4949 end
5050 result = base.command("branch", *params).split("\n").map { |e| { :name => e[2..-1], :default => e[0..1] == '* ' } }
5151 result.delete_if { |r| r[:name] == "(no branch)"}
52 if options[:remote_name]
53 r_prefix = remote_branch_prefix(options[:remote_name])
52 if options[:remote]
53 r_prefix = remote_branch_prefix(options[:remote])
5454 result.delete_if {|r| ! Regexp.new("^#{Regexp.escape(r_prefix)}\/").match(r[:name]) }
5555 end
5656 result
7272
7373 alias current_branch current
7474
75 def remote_branch_prefix(remote_name)
76 /\*:refs\/remotes\/(.+)\/\*/.match(base.config["remote.#{remote_name}.fetch"])
75 def remote_branch_prefix(remote)
76 /\*:refs\/remotes\/(.+)\/\*/.match(base.config["remote.#{remote}.fetch"])
7777 $1
7878 end
7979
toggle raw diff

Support/lib/git.rb

 
124124 end
125125 end
126126
127 def sources
127 def remotes
128128 command("remote").split("\n")
129129 end
130130
250250 command("show", "#{revision}:#{path}")
251251 end
252252
253 def push(source, options = {})
253 def push(remote, options = {})
254254 options = options.dup
255 args = ["push", source]
255 args = ["push", remote]
256256 args << options.delete(:branch) if options[:branch]
257257 args << options.delete(:tag) if options[:tag]
258258
260260 process_push(p, options)
261261 end
262262
263 def pull(source, remote_merge_branch = nil, callbacks = {})
264 args = ["pull", source]
263 def pull(remote, remote_merge_branch = nil, callbacks = {})
264 args = ["pull", remote]
265265 args << remote_merge_branch.split('/').last if remote_merge_branch
266266 p = popen_command(*args)
267267 process_pull(p, callbacks)
268268 end
269269
270 def fetch(source, callbacks = {})
271 p = popen_command("fetch", source)
270 def fetch(remote, callbacks = {})
271 p = popen_command("fetch", remote)
272272 process_fetch(p, callbacks)
273273 end
274274
toggle raw diff

Support/spec/controllers/remote_controller_spec.rb

 
1313
1414 describe "fetching" do
1515 before(:each) do
16 # query the sources
16 # query the remotes
1717 Git.command_response["branch"] = "* master\n"
1818 Git.command_response["config", "branch.master.remote"] = %Q{origin}
1919 Git.command_response["remote"] = %Q{origin}
2929 end
3030
3131 it "should use javascript to output the progress" do
32 @output.should include("$('Compressing_progress').update('Done')")
32 @output.should include("$('origin_Compressing_progress').update('Done')")
3333 end
3434
3535 it "should output a log" do
4141
4242 describe "pulling" do
4343 before(:each) do
44 # query the sources
44 # query the remotes
4545 @controller = RemoteController.singleton_new
4646 Git.command_response["branch"] = "* master\n"
4747 Git.command_response["branch", "-r"] = " origin/master\n origin/release\n"
4949 @git.config.stub!(:[]).with("branch.master.merge").and_return("refs/heads/master")
5050 Git.command_response["remote"] = %Q{origin}
5151
52 # query the config - if source != self["remote.#{current_branch}.remote"] || self["remote.#{current_branch}.merge"].nil?
52 # query the config - if remote != self["remote.#{current_branch}.remote"] || self["remote.#{current_branch}.merge"].nil?
5353
5454 # Git.command_response[]
5555 Git.command_response["log", "-p", "791a587..4bfc230", "."] = fixture_file("log_with_diffs.txt")
106106 describe "pushing a tag" do
107107 before(:each) do
108108 @git = Git.singleton_new
109 @git.should_receive(:sources).and_return(["origin"])
109 @git.should_receive(:remotes).and_return(["origin"])
110110 @controller = RemoteController.singleton_new
111111 def @controller.for_each_selected_remote(options = {}, &block)
112112 yield "origin"
toggle raw diff

Support/spec/lib/git_spec.rb

 
3030 EOF
3131 Git.command_output << "+refs/heads/*:refs/remotes/satellite/*"
3232
33 branches = @git.branch.list(:remote, :remote_name => "satellite")
33 branches = @git.branch.list(:remote, :remote => "satellite")
3434 branches.map{|r|r[:name]}.should == ["satellite/asdf", "satellite/master", "satellite/mybranch", "satellite/satellite"]
3535 end
3636 end
toggle raw diff