Skip to content

Commit

Permalink
Add force push support
Browse files Browse the repository at this point in the history
  • Loading branch information
gdsmith committed Aug 31, 2017
1 parent 9cf5c12 commit 51a2fda
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
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>
13 changes: 9 additions & 4 deletions Support/app/controllers/remote_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,20 @@ 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


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

0 comments on commit 51a2fda

Please sign in to comment.