Skip to content

Commit

Permalink
Add the Revert command for SVK.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.textmate.org/trunk/Bundles/SVK.tmbundle@6875 dfb7d73b-c2ec-0310-8fea-fb051d288c6d
  • Loading branch information
Brian Donovan committed Mar 22, 2007
1 parent c3105ba commit 2203439
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Commands/Revert.tmCommand
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//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>require_cmd "${TM_SVK:=svk}" "If you have installed svk, then you need to either update your &lt;tt&gt;PATH&lt;/tt&gt; or set the &lt;tt&gt;TM_SVK&lt;/tt&gt; shell variable (e.g. in Preferences / Advanced)"
if [[ -z $TM_SELECTED_FILES ]]
then
TM_SELECTED_FILES="'$TM_FILEPATH'"
fi
"$TM_BUNDLE_SUPPORT/revert_file.rb" $TM_SELECTED_FILES
</string>
<key>input</key>
<string>none</string>
<key>keyEquivalent</key>
<string>^~A</string>
<key>name</key>
<string>Revert</string>
<key>output</key>
<string>showAsTooltip</string>
<key>uuid</key>
<string>8FCB4C8F-23CD-4D2E-A9F2-C4564DFFEB2A</string>
</dict>
</plist>
59 changes: 59 additions & 0 deletions Support/revert_file.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env ruby -s

require ENV['TM_SUPPORT_PATH'] + "/lib/dialog"

abort "Wrong arguments: use -path=«file to revert»" if $path.nil? and ARGV.size == 0

svk = ENV['TM_SVK'] || $svk || 'svk'

# get paths from --path or from naked arguments
paths = if ARGV.size > 0
ARGV
else
[e_sh($path)]
end

warn_for_paths = []

# Escape paths for shell
paths_for_shell = paths.sort.uniq #.map {|path| e_sh(path)}

# Ask for status
status = %x{#{svk} status #{paths_for_shell.join(" ")}}

# Get array of [status, path] tuples
status_for_paths = status.scan(/(.{1,8})\s+(.*)$/)

status_for_paths.each do|status_entry|
status = status_entry[0]
path = status_entry[1]

# Reverting added or deleted files will not destroy data
# Unmodified files will be skipped
warn_for_paths << path unless (status =~ /^(A|D|\?)/)
end

# TextMate::Dialog.alert(:warning, "¿Que pasa?", "It's not dangerous to revert the file “#{paths_for_shell.inspect}”.")

res = if warn_for_paths.size > 0 then
paths_to_display = warn_for_paths.map {|x| File.basename(x)}.join("”, “")
plural = (warn_for_paths.size == 1) ? '' : 's'
title_files = (warn_for_paths.size == 1) ? "“#{paths_to_display}”" : 'files'

TextMate::Dialog.alert(:warning, "Revert #{title_files}?", "Do you really want to revert the file#{plural}#{paths_to_display}” and lose all local changes?", 'Revert', 'Cancel')
else
# Nothing dangerous; be happy
'Revert'
end

if res =~ /Revert/i then
# ENV['TM_SVK_REVERT'] = path # by using an env. variable we avoid shell escaping
puts `#{svk} revert #{paths_for_shell.join(' ')}`

# rescan_project
%x{osascript &>/dev/null \
-e 'tell app "SystemUIServer" to activate' \
-e 'tell app "TextMate" to activate' &}
else
exit -128
end
2 changes: 2 additions & 0 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<array>
<string>F41366B2-C373-11D9-8A81-000A95BCAFA8</string>
<string>D79E0650-C374-11D9-8A81-000A95BCAFA8</string>
<string>8FCB4C8F-23CD-4D2E-A9F2-C4564DFFEB2A</string>
<string>------------------------------------</string>
<string>C03C7374-C371-11D9-AAA6-000A95BCAFA8</string>
<string>------------------------------------</string>
Expand All @@ -39,6 +40,7 @@
<string>5263FCE3-C32A-11D9-BFEF-000A95BCAFA8</string>
<string>70BCF12B-C35D-11D9-AB2C-000A95BCAFA8</string>
<string>9BF6E13C-C31A-11D9-820C-000A95BCAFA8</string>
<string>8FCB4C8F-23CD-4D2E-A9F2-C4564DFFEB2A</string>
<string>C17472A0-C36B-11D9-954B-000A95BCAFA8</string>
<string>D79E0650-C374-11D9-8A81-000A95BCAFA8</string>
</array>
Expand Down

0 comments on commit 2203439

Please sign in to comment.