Commit ac595dfe7795144a4bb3b302a33517ea9c33e8c8

amend last commit has the ability to update the commit message only. If you leave it blank or uncheck the commit message entry in the files, it will use the previous message.

Commit diff

Support/app/controllers/commit_controller.rb

 
1CW = ENV['TM_SUPPORT_PATH'] + '/bin/CommitWindow.app/Contents/MacOS/CommitWindow'
21require LIB_ROOT + '/partial_commit_worker.rb'
32class CommitController < ApplicationController
43 def index
toggle raw diff

Support/lib/partial_commit_worker.rb

 
1CW = ENV['TM_SUPPORT_PATH'] + '/bin/CommitWindow.app/Contents/MacOS/CommitWindow'
2
13module PartialCommitWorker
24 class NotOnBranchException < Exception; end
35 class NothingToCommitException < Exception; end
46 class CommitCanceledException < Exception; end
57
68 def self.factory(_type, *args)
7 klass = case _type
8 when "amend" then
9 PartialCommitWorker::Amend
10 else
11 PartialCommitWorker::Normal
12 end
13
9 klass = (_type == "amend" ? PartialCommitWorker::Amend : PartialCommitWorker::Normal)
1410 klass.new(*args)
1511 end
1612
2626 @target_file_or_dir ||= git.paths.first
2727 end
2828
29 def show_commit_dialog(files, statuses)
30 status_helper_tool = ENV['TM_BUNDLE_SUPPORT'] + '/gateway/commit_dialog_helper.rb'
29 def split_file_statuses
30 [file_candidates.map{ |fc| fc[0] }, file_candidates.map{ |fc| fc[1] }]
31 end
32
33 def status_helper_tool
34 ENV['TM_BUNDLE_SUPPORT'] + '/gateway/commit_dialog_helper.rb'
35 end
36
37 def exec_commit_dialog
38 files, statuses = split_file_statuses
3139
3240 res = %x{#{e_sh CW} \
3341 --diff-cmd '#{git.git},diff' \
3442 --action-cmd "M,D:Revert,#{status_helper_tool},revert" \
35 --status #{statuses.join ':'} \
36 #{files.join ' '} 2>/dev/console
43 --status #{statuses.join(':')} \
44 #{files.map{ |f| e_sh(f) }.join(' ')} 2>/dev/console
3745 }
38
39 raise CommitCanceledException if $? != 0
40
46 canceled = ($? != 0)
4147 res = Shellwords.shellwords(res)
4248 msg = res[1]
4349 files = res[2..-1]
44 return msg, files
50 return canceled, msg, files
51 end
52
53 def show_commit_dialog
54 canceled, msg, files = exec_commit_dialog
55 raise CommitCanceledException if canceled
56 [msg, files]
57 end
58
59 def file_candidates
60 @file_candidates ||=
61 git.status(target_file_or_dir).map do |e|
62 [shorten(e[:path], @base), e[:status][:short]]
63 end
4564 end
4665
4766 def run
4867 raise NotOnBranchException unless ok_to_proceed_with_partial_commit?
49
50 files, statuses = [], []
51 git.status(target_file_or_dir).each do |e|
52 files << e_sh(shorten(e[:path], @base))
53 statuses << e_sh(e[:status][:short])
54 end
55
56 raise NothingToCommitException if files.empty?
68 raise NothingToCommitException if nothing_to_commit?
5769
58 msg, files = show_commit_dialog(files, statuses)
70 msg, files = show_commit_dialog
5971
6072 git.auto_add_rm(files)
6173 res = git.commit(msg, files, :amend => amend)
7777 def title
7878 "#{title_prefix} in ‘#{htmlize(shorten(target_file_or_dir, ENV['TM_PROJECT_DIRECTORY'] || @base))}’ on branch ‘#{htmlize(git.branch.current_name)}’"
7979 end
80
81 def nothing_to_commit?
82 file_candidates.empty?
83 end
8084 end
8185
8286 class Normal < Base
9494 end
9595
9696 class Amend < Base
97 COMMIT_MESSAGE_FILENAME = "-- update commit message --"
98
9799 def title_prefix
98100 "Amending the commit"
99101 end
103103 def amend
104104 true
105105 end
106
107 def show_commit_dialog(*args)
108 msg, files = super(*args)
109 if files.first==COMMIT_MESSAGE_FILENAME
110 files.shift
111 else
112 msg = ""
113 end
114 msg = git.log(:limit => 1).first[:msg] if msg.strip.empty?
115
116 [msg, files]
117 end
118
119 def file_candidates
120 return @file_candidates if @file_candidates
121 super
122 @file_candidates.unshift([COMMIT_MESSAGE_FILENAME, "M"])
123 @file_candidates
124 end
106125 end
107126end
127
toggle raw diff

Support/spec/lib/commands/log_spec.rb

 
22
33describe Git do
44 before(:each) do
5 @log = Git.new
5 @git = Git.new
66 end
77 include SpecHelpers
88
99 describe "when parsing a plain log" do
1010 before(:each) do
11 @entries = @log.parse_log( fixture_file('log.txt'))
11 @entries = @git.parse_log( fixture_file('log.txt'))
1212 end
1313
1414 it "should parse out all items" do
2626 end
2727
2828 it "should stringify results" do
29 @log.stringify(@entries)
29 @git.stringify(@entries)
3030 @entries.first.keys.sort.should == ["author", "date", "msg", "rev"]
3131 end
3232 end
3333
3434 describe "when parsing a log with diffs" do
3535 before(:each) do
36 @entries = @log.parse_log( fixture_file("log_with_diffs.txt"))
36 @entries = @git.parse_log( fixture_file("log_with_diffs.txt"))
3737 @entry = @entries.first
38
3938 end
4039
4140 it "should extract and parse diffs" do
toggle raw diff

Support/spec/lib/partial_commit_worker_spec.rb

 
1717 @git.should_receive(:initial_commit_pending?).and_return(true)
1818 PartialCommitWorker::Base.new(@git).ok_to_proceed_with_partial_commit?.should == true
1919 end
20
21 describe "Amend" do
22 before(:each) do
23 @amend = PartialCommitWorker::Amend.new(@git)
24 end
25
26 it "should use the last log message when 'log message' not checked" do
27 @git.stub!(:log).and_return([{:msg => "My Message"}])
28 @amend.stub!(:exec_commit_dialog).and_return([false, "", ["file.txt"]])
29 @amend.show_commit_dialog.should == ["My Message", ["file.txt"]]
30 end
31 end
32
2033end
toggle raw diff