public
Description: The Git TextMate Bundle
Homepage: http://tim.theenchanter.com/
Clone URL: git://github.com/timcharper/git-tmbundle.git
extracted out partial commit functionality to a polymorphic worker class 
to handle subtle differences between amend commits and normal commits
timcharper (author)
Thu Apr 24 13:33:51 -0700 2008
commit  c1380df9efc6e2753d10f913adad725b834723b2
tree    15f38e5f11e45d451c5d351f6f5a134094794a0d
parent  88e756e3c9db72f2a17af875167e2ec29bfbf66e
...
1
2
 
3
4
5
...
23
24
25
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
 
 
89
90
91
...
1
 
2
3
4
5
...
23
24
25
 
 
 
 
 
26
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
27
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
30
31
32
33
34
35
36
37
38
39
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
41
42
43
44
0
@@ -1,5 +1,5 @@
0
 CW = ENV['TM_SUPPORT_PATH'] + '/bin/CommitWindow.app/Contents/MacOS/CommitWindow'
0
-
0
+require LIB_ROOT + '/partial_commit_worker.rb'
0
 class CommitController < ApplicationController
0
   def index
0
     if git.merge_message
0
@@ -23,68 +23,21 @@ class CommitController < ApplicationController
0
   end
0
   
0
   protected
0
-
0
- def ok_to_proceed_with_partial_commit?
0
- (! git.branch.current_name.nil?) || git.initial_commit_pending?
0
- end
0
-
0
     def run_partial_commit
0
- @base = git.git_base
0
-
0
- unless ok_to_proceed_with_partial_commit?
0
- render "not_on_a_branch"
0
- return false
0
- end
0
-
0
- target_file_or_dir = git.paths.first
0
-
0
- puts "<h1>"
0
- if params[:type] == "amend"
0
- puts "Amending the commit"
0
- else
0
- puts "Committing Files"
0
- end
0
- puts " in ‘#{htmlize(shorten(target_file_or_dir, ENV['TM_PROJECT_DIRECTORY'] || @base))}’ on branch ‘#{htmlize(git.branch.current_name)}’</h1>"
0
+ puts "<h2>#{commit_worker.title}</h2>"
0
       flush
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
- if files.empty?
0
- puts (git.clean_directory? ? "Working directory is clean (nothing to commit)" : "No changes to commit within the current scope. (Try selecting the root folder in the project drawer?)")
0
- return
0
- end
0
-
0
- msg, files = show_commit_dialog(files, statuses)
0
-
0
- unless files.empty?
0
- git.auto_add_rm(files)
0
- res = git.commit(msg, files, :amend => (params[:type] == "amend"))
0
- render "_commit_result", :locals => { :files => files, :message => msg, :result => res}
0
- end
0
+ result = commit_worker.run
0
+ render "_commit_result", :locals => result if result
0
+ rescue PartialCommitWorker::NotOnBranchException
0
+ render "not_on_a_branch"
0
+ false
0
+ rescue PartialCommitWorker::NothingToCommitException
0
+ puts(git.clean_directory? ? "Working directory is clean (nothing to commit)" : "No changes to commit within the current scope. (Try selecting the root folder in the project drawer?)")
0
+ rescue PartialCommitWorker::CommitCanceledException
0
+ puts "<strong>Canceled</strong>"
0
     end
0
     
0
- def show_commit_dialog(files, statuses)
0
- status_helper_tool = ENV['TM_BUNDLE_SUPPORT'] + '/gateway/commit_dialog_helper.rb'
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
- }
0
-
0
- if $? != 0
0
- puts "<strong>Cancel</strong>"
0
- abort
0
- end
0
-
0
- res = Shellwords.shellwords(res)
0
- msg = res[1]
0
- files = res[2..-1]
0
- return msg, files
0
+ def commit_worker
0
+ @commit_worker ||= PartialCommitWorker.factory(params[:type], git)
0
     end
0
 end
0
\ No newline at end of file
...
16
17
18
19
 
 
20
21
22
...
45
46
47
48
 
49
50
51
52
 
 
53
54
55
...
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
...
16
17
18
 
19
20
21
22
23
...
46
47
48
 
49
50
51
52
 
53
54
55
56
57
...
85
86
87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
89
90
0
@@ -16,7 +16,8 @@ describe CommitController do
0
     before(:each) do
0
       @message = "My commit message"
0
       @git.should_receive(:merge_message).and_return(nil)
0
- @controller.stub!(:show_commit_dialog).and_return([@message, ["file1.txt", "file2.txt"]])
0
+ @worker = PartialCommitWorker::Normal.singleton_new(@git)
0
+ @worker.stub!(:show_commit_dialog).and_return([@message, ["file1.txt", "file2.txt"]])
0
       
0
       @git.should_receive(:commit).
0
         with("My commit message", ["file1.txt", "file2.txt"], :amend => false).
0
@@ -45,11 +46,12 @@ describe CommitController do
0
     end
0
   end
0
   
0
- describe "Ammend commit" do
0
+ describe "Amend commit" do
0
     before(:each) do
0
       @message = "My commit message"
0
       @git.should_receive(:merge_message).and_return(nil)
0
- @controller.stub!(:show_commit_dialog).and_return([@message, ["file1.txt", "file2.txt"]])
0
+ @worker = PartialCommitWorker::Amend.singleton_new(@git)
0
+ @worker.stub!(:show_commit_dialog).and_return([@message, ["file1.txt", "file2.txt"]])
0
       
0
       @git.should_receive(:commit).
0
         with("My commit message", ["file1.txt", "file2.txt"], :amend => true).
0
@@ -83,20 +85,6 @@ describe CommitController do
0
     end
0
   end
0
   
0
- it "should NOT be OK to proceed when not on a branch but performing an initial commit" do
0
- @git.branch.should_receive(:current_name).and_return(nil)
0
- @git.should_receive(:initial_commit_pending?).and_return(false)
0
-
0
- @controller.send(:ok_to_proceed_with_partial_commit?).should == false
0
- end
0
-
0
- it "should be OK to proceed when not on a branch but performing an initial commit" do
0
- @git.branch.should_receive(:current_name).and_return(nil)
0
- @git.should_receive(:initial_commit_pending?).and_return(true)
0
-
0
- @controller.send(:ok_to_proceed_with_partial_commit?).should == true
0
- end
0
-
0
   describe "when in the middle of a merge" do
0
     it "should run the mege dialog" do
0
       @merge_message = "Merged some branch into another branch..."
...
53
54
55
 
56
57
58
...
53
54
55
56
57
58
59
0
@@ -53,6 +53,7 @@ class ApplicationController
0
   
0
   def initialize
0
     @output_buffer = StringIO.new
0
+ @params = {}
0
   end
0
   
0
   def puts(*args)

Comments

    No one has commented yet.