diff --git a/Commands/Force Push.tmCommand b/Commands/Force Push.tmCommand new file mode 100644 index 0000000..79b450a --- /dev/null +++ b/Commands/Force Push.tmCommand @@ -0,0 +1,33 @@ + + + + + beforeRunningCommand + nop + command + #!/usr/bin/env ruby18 + +require ENV['TM_BUNDLE_SUPPORT'] + '/environment.rb' +dispatch :controller => "remote", :action => "push", :force => true + input + selection + inputFormat + text + name + Force Push + outputCaret + afterOutput + outputFormat + html + outputLocation + newWindow + scope + attr.scm.git + semanticClass + action.scm.push.force + uuid + 95FA2D08-66F7-41CD-A7C5-6F240CA5ACAD + version + 2 + + diff --git a/Support/app/controllers/remote_controller.rb b/Support/app/controllers/remote_controller.rb index b75778d..7866df2 100644 --- a/Support/app/controllers/remote_controller.rb +++ b/Support/app/controllers/remote_controller.rb @@ -4,6 +4,9 @@ class RemoteController < ApplicationController ALL_REMOTES = "...all remotes..." + FORCE_PUSH_YES = 'Yes, force push' + FORCE_PUSH_NO = 'No, just push normally' + FORCE_PUSH_CANCEL = 'Cancel' include SubmoduleHelper::Update include SubmoduleHelper @@ -74,15 +77,28 @@ def pull end def push + force = !!params[:force] + if (branch = git.branch.current).nil? puts "You can't push the current branch while not being on a branch (and you are not on a branch). Please switch to a branch, and try again." output_show_html and return end - + + case TextMate::UI.alert(:warning, "Force push this branch?", "Force pushing to #{branch.name} branch will OVERWRITE the remote branch, are you sure you want to continue?", FORCE_PUSH_YES, FORCE_PUSH_NO, FORCE_PUSH_CANCEL) + when FORCE_PUSH_CANCEL + puts '

Push aborted

That was a close one!

' + output_show_html and return + when FORCE_PUSH_NO + force = false + end if force + + title = "Push" + title = "Force "+title if force + current_name = branch.name - for_each_selected_remote(:title => "Push", :prompt => "Select a remote source to push the branch #{current_name} to:", :items => git.remote.names) do |remote_name| - puts "

Pushing to remote source '#{remote_name}' for branch '#{current_name}'

" - display_push_output(git, run_push(git, remote_name, :branch => current_name)) + for_each_selected_remote(:title => title, :prompt => "Select a remote source to push the branch #{current_name} to:", :items => git.remote.names) do |remote_name| + puts "

#{title}ing to remote source '#{remote_name}' for branch '#{current_name}'

" + display_push_output(git, run_push(git, remote_name, {:branch => current_name, :force => force})) git.submodule.all.each do |submodule| next unless (current_branch = submodule.git.branch.current) && (current_branch.tracking_branch_name) diff --git a/Support/lib/git.rb b/Support/lib/git.rb index a0f5dcc..4a0e7a2 100644 --- a/Support/lib/git.rb +++ b/Support/lib/git.rb @@ -267,6 +267,7 @@ def show(fullpath, revision) def push(remote, options = {}) options = options.dup args = ["push", remote] + args << "--force" if options[:force] args << options.delete(:branch) if options[:branch] args << options.delete(:tag) if options[:tag]