0
+CW = ENV['TM_SUPPORT_PATH'] + '/bin/CommitWindow.app/Contents/MacOS/CommitWindow'
0
module PartialCommitWorker
0
class NotOnBranchException < Exception; end
0
class NothingToCommitException < Exception; end
0
class CommitCanceledException < Exception; end
0
def self.factory(_type, *args)
0
- PartialCommitWorker::Amend
0
- PartialCommitWorker::Normal
0
+ klass = (_type == "amend" ? PartialCommitWorker::Amend : PartialCommitWorker::Normal)
0
@@ -30,36 +26,48 @@ module PartialCommitWorker
0
@target_file_or_dir ||= git.paths.first
0
- def show_commit_dialog(files, statuses)
0
- status_helper_tool = ENV['TM_BUNDLE_SUPPORT'] + '/gateway/commit_dialog_helper.rb'
0
+ def split_file_statuses
0
+ [file_candidates.map{ |fc| fc[0] }, file_candidates.map{ |fc| fc[1] }]
0
+ def status_helper_tool
0
+ ENV['TM_BUNDLE_SUPPORT'] + '/gateway/commit_dialog_helper.rb'
0
+ def exec_commit_dialog
0
+ files, statuses = split_file_statuses
0
--diff-cmd '#{git.git},diff' \
0
--action-cmd "M,D:Revert,#{status_helper_tool},revert" \
0
- --status #{statuses.join ':'} \
0
- #{files.join ' '} 2>/dev/console
0
+ --status #{statuses.join(':')} \
0
+ #{files.map{ |f| e_sh(f) }.join(' ')} 2>/dev/console
0
- raise CommitCanceledException if $? != 0
0
res = Shellwords.shellwords(res)
0
+ return canceled, msg, files
0
+ def show_commit_dialog
0
+ canceled, msg, files = exec_commit_dialog
0
+ raise CommitCanceledException if canceled
0
+ git.status(target_file_or_dir).map do |e|
0
+ [shorten(e[:path], @base), e[:status][:short]]
0
raise NotOnBranchException unless ok_to_proceed_with_partial_commit?
0
- files, statuses = [], []
0
- git.status(target_file_or_dir).each do |e|
0
- files << e_sh(shorten(e[:path], @base))
0
- statuses << e_sh(e[:status][:short])
0
- raise NothingToCommitException if files.empty?
0
+ raise NothingToCommitException if nothing_to_commit?
0
- msg, files = show_commit_dialog
(files, statuses)0
+ msg, files = show_commit_dialog
0
res = git.commit(msg, files, :amend => amend)
0
@@ -69,6 +77,10 @@ module PartialCommitWorker
0
"#{title_prefix} in ‘#{htmlize(shorten(target_file_or_dir, ENV['TM_PROJECT_DIRECTORY'] || @base))}’ on branch ‘#{htmlize(git.branch.current_name)}’"
0
+ def nothing_to_commit?
0
+ file_candidates.empty?
0
@@ -82,6 +94,8 @@ module PartialCommitWorker
0
+ COMMIT_MESSAGE_FILENAME = "-- update commit message --"
0
@@ -89,5 +103,25 @@ module PartialCommitWorker
0
+ def show_commit_dialog(*args)
0
+ msg, files = super(*args)
0
+ if files.first==COMMIT_MESSAGE_FILENAME
0
+ msg = git.log(:limit => 1).first[:msg] if msg.strip.empty?
0
+ return @file_candidates if @file_candidates
0
+ @file_candidates.unshift([COMMIT_MESSAGE_FILENAME, "M"])
0
\ No newline at end of file
Comments
No one has commented yet.