Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add force push support #36

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions Commands/Force Push.tmCommand
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>beforeRunningCommand</key>
<string>nop</string>
<key>command</key>
<string>#!/usr/bin/env ruby18

require ENV['TM_BUNDLE_SUPPORT'] + '/environment.rb'
dispatch :controller =&gt; "remote", :action =&gt; "push", :force =&gt; true</string>
<key>input</key>
<string>selection</string>
<key>inputFormat</key>
<string>text</string>
<key>name</key>
<string>Force Push</string>
<key>outputCaret</key>
<string>afterOutput</string>
<key>outputFormat</key>
<string>html</string>
<key>outputLocation</key>
<string>newWindow</string>
<key>scope</key>
<string>attr.scm.git</string>
<key>semanticClass</key>
<string>action.scm.push.force</string>
<key>uuid</key>
<string>95FA2D08-66F7-41CD-A7C5-6F240CA5ACAD</string>
<key>version</key>
<integer>2</integer>
</dict>
</plist>
24 changes: 20 additions & 4 deletions Support/app/controllers/remote_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 '<h1>Push aborted</h1><p>That was a close one!</p>'
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 "<p>Pushing to remote source '#{remote_name}' for branch '#{current_name}'</p>"
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 "<p>#{title}ing to remote source '#{remote_name}' for branch '#{current_name}'</p>"
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)
Expand Down
1 change: 1 addition & 0 deletions Support/lib/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down