public
Description: The Git TextMate Bundle
Homepage: http://tim.theenchanter.com/
Clone URL: git://github.com/timcharper/git-tmbundle.git
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.
timcharper (author)
Thu Apr 24 18:15:27 -0700 2008
commit  ac595dfe7795144a4bb3b302a33517ea9c33e8c8
tree    a67587a16a5dad7a306c1f2995e33cf78a95abc8
parent  c1380df9efc6e2753d10f913adad725b834723b2
...
1
2
3
4
...
 
1
2
3
0
@@ -1,4 +1,3 @@
0
-CW = ENV['TM_SUPPORT_PATH'] + '/bin/CommitWindow.app/Contents/MacOS/CommitWindow'
0
 require LIB_ROOT + '/partial_commit_worker.rb'
0
 class CommitController < ApplicationController
0
   def index
...
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
 
14
15
16
...
30
31
32
33
34
 
 
 
 
 
 
 
 
 
 
35
36
37
38
39
40
 
 
41
42
43
44
 
45
46
47
48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
49
50
51
52
53
54
55
56
57
58
59
60
 
61
62
 
63
64
65
...
69
70
71
 
 
 
 
72
73
74
...
82
83
84
 
 
85
86
87
...
89
90
91
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
93
 
94
...
1
2
3
4
5
6
7
8
 
 
 
 
 
 
 
9
10
11
12
...
26
27
28
 
 
29
30
31
32
33
34
35
36
37
38
39
40
41
42
 
 
43
44
45
 
 
 
46
47
48
49
 
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
 
 
 
 
 
 
 
 
68
69
 
70
71
72
73
...
77
78
79
80
81
82
83
84
85
86
...
94
95
96
97
98
99
100
101
...
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
0
@@ -1,16 +1,12 @@
0
+CW = ENV['TM_SUPPORT_PATH'] + '/bin/CommitWindow.app/Contents/MacOS/CommitWindow'
0
+
0
 module PartialCommitWorker
0
   class NotOnBranchException < Exception; end
0
   class NothingToCommitException < Exception; end
0
   class CommitCanceledException < Exception; end
0
   
0
   def self.factory(_type, *args)
0
- klass = case _type
0
- when "amend" then
0
- PartialCommitWorker::Amend
0
- else
0
- PartialCommitWorker::Normal
0
- end
0
-
0
+ klass = (_type == "amend" ? PartialCommitWorker::Amend : PartialCommitWorker::Normal)
0
     klass.new(*args)
0
   end
0
   
0
@@ -30,36 +26,48 @@ module PartialCommitWorker
0
       @target_file_or_dir ||= git.paths.first
0
     end
0
     
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
+ end
0
+
0
+ def status_helper_tool
0
+ ENV['TM_BUNDLE_SUPPORT'] + '/gateway/commit_dialog_helper.rb'
0
+ end
0
+
0
+ def exec_commit_dialog
0
+ files, statuses = split_file_statuses
0
       
0
       res = %x{#{e_sh CW} \
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
       }
0
-
0
- raise CommitCanceledException if $? != 0
0
-
0
+ canceled = ($? != 0)
0
       res = Shellwords.shellwords(res)
0
       msg = res[1]
0
       files = res[2..-1]
0
- return msg, files
0
+ return canceled, msg, files
0
+ end
0
+
0
+ def show_commit_dialog
0
+ canceled, msg, files = exec_commit_dialog
0
+ raise CommitCanceledException if canceled
0
+ [msg, files]
0
+ end
0
+
0
+ def file_candidates
0
+ @file_candidates ||=
0
+ git.status(target_file_or_dir).map do |e|
0
+ [shorten(e[:path], @base), e[:status][:short]]
0
+ end
0
     end
0
     
0
     def run
0
       raise NotOnBranchException unless ok_to_proceed_with_partial_commit?
0
-
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
- end
0
-
0
- raise NothingToCommitException if files.empty?
0
+ raise NothingToCommitException if nothing_to_commit?
0
     
0
- msg, files = show_commit_dialog(files, statuses)
0
+ msg, files = show_commit_dialog
0
 
0
       git.auto_add_rm(files)
0
       res = git.commit(msg, files, :amend => amend)
0
@@ -69,6 +77,10 @@ module PartialCommitWorker
0
     def title
0
       "#{title_prefix} in ‘#{htmlize(shorten(target_file_or_dir, ENV['TM_PROJECT_DIRECTORY'] || @base))}’ on branch ‘#{htmlize(git.branch.current_name)}’"
0
     end
0
+
0
+ def nothing_to_commit?
0
+ file_candidates.empty?
0
+ end
0
   end
0
   
0
   class Normal < Base
0
@@ -82,6 +94,8 @@ module PartialCommitWorker
0
   end
0
   
0
   class Amend < Base
0
+ COMMIT_MESSAGE_FILENAME = "-- update commit message --"
0
+
0
     def title_prefix
0
       "Amending the commit"
0
     end
0
@@ -89,5 +103,25 @@ module PartialCommitWorker
0
     def amend
0
       true
0
     end
0
+
0
+ def show_commit_dialog(*args)
0
+ msg, files = super(*args)
0
+ if files.first==COMMIT_MESSAGE_FILENAME
0
+ files.shift
0
+ else
0
+ msg = ""
0
+ end
0
+ msg = git.log(:limit => 1).first[:msg] if msg.strip.empty?
0
+
0
+ [msg, files]
0
+ end
0
+
0
+ def file_candidates
0
+ return @file_candidates if @file_candidates
0
+ super
0
+ @file_candidates.unshift([COMMIT_MESSAGE_FILENAME, "M"])
0
+ @file_candidates
0
+ end
0
   end
0
 end
0
+
0
\ No newline at end of file
...
2
3
4
5
 
6
7
8
9
10
11
 
12
13
14
...
26
27
28
29
 
30
31
32
33
34
35
36
 
37
38
39
40
41
...
2
3
4
 
5
6
7
8
9
10
 
11
12
13
14
...
26
27
28
 
29
30
31
32
33
34
35
 
36
37
 
38
39
40
0
@@ -2,13 +2,13 @@ require File.dirname(__FILE__) + '/../../spec_helper'
0
 
0
 describe Git do
0
   before(:each) do
0
- @log = Git.new
0
+ @git = Git.new
0
   end
0
   include SpecHelpers
0
   
0
   describe "when parsing a plain log" do
0
     before(:each) do
0
- @entries = @log.parse_log( fixture_file('log.txt'))
0
+ @entries = @git.parse_log( fixture_file('log.txt'))
0
     end
0
     
0
     it "should parse out all items" do
0
@@ -26,16 +26,15 @@ made more failproof}
0
     end
0
     
0
     it "should stringify results" do
0
- @log.stringify(@entries)
0
+ @git.stringify(@entries)
0
       @entries.first.keys.sort.should == ["author", "date", "msg", "rev"]
0
     end
0
   end
0
   
0
   describe "when parsing a log with diffs" do
0
     before(:each) do
0
- @entries = @log.parse_log( fixture_file("log_with_diffs.txt"))
0
+ @entries = @git.parse_log( fixture_file("log_with_diffs.txt"))
0
       @entry = @entries.first
0
-
0
     end
0
     
0
     it "should extract and parse diffs" do
...
17
18
19
 
 
 
 
 
 
 
 
 
 
 
 
 
20
...
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
0
@@ -17,4 +17,17 @@ describe PartialCommitWorker do
0
     @git.should_receive(:initial_commit_pending?).and_return(true)
0
     PartialCommitWorker::Base.new(@git).ok_to_proceed_with_partial_commit?.should == true
0
   end
0
+
0
+ describe "Amend" do
0
+ before(:each) do
0
+ @amend = PartialCommitWorker::Amend.new(@git)
0
+ end
0
+
0
+ it "should use the last log message when 'log message' not checked" do
0
+ @git.stub!(:log).and_return([{:msg => "My Message"}])
0
+ @amend.stub!(:exec_commit_dialog).and_return([false, "", ["file.txt"]])
0
+ @amend.show_commit_dialog.should == ["My Message", ["file.txt"]]
0
+ end
0
+ end
0
+
0
 end

Comments

    No one has commented yet.