public
Description: The Git TextMate Bundle
Homepage: http://tim.theenchanter.com/
Clone URL: git://github.com/timcharper/git-tmbundle.git
Search Repo:
Added "Ammend Last Commit" feature
timcharper (author)
Fri Apr 11 14:24:53 -0700 2008
commit  57d4ef4e20589827a0ed6c19843cfe749718ad2e
tree    45088fec490e8f2cf6cb6640ea17cefd4126d3b7
parent  cac609ff1040cba9dc74f0c33c6151f5ea84e35e
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
0
@@ -1 +1,22 @@
0
+<?xml version="1.0" encoding="UTF-8"?>
0
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
0
+<plist version="1.0">
0
+<dict>
0
+ <key>beforeRunningCommand</key>
0
+ <string>nop</string>
0
+ <key>command</key>
0
+ <string>#!/usr/bin/env ruby
0
+
0
+require ENV['TM_BUNDLE_SUPPORT'] + '/environment.rb'
0
+dispatch(:controller =&gt; "commit", :type =&gt; "amend")</string>
0
+ <key>input</key>
0
+ <string>none</string>
0
+ <key>name</key>
0
+ <string>Amend Last Commit…</string>
0
+ <key>output</key>
0
+ <string>showAsHTML</string>
0
+ <key>uuid</key>
0
+ <string>2F24C9CB-23D0-4FDA-9C8D-210027DCEB27</string>
0
+</dict>
0
+</plist>
...
37
38
39
40
 
 
 
 
 
 
 
 
41
42
43
...
55
56
57
58
 
59
60
61
...
37
38
39
 
40
41
42
43
44
45
46
47
48
49
50
...
62
63
64
 
65
66
67
68
0
@@ -37,7 +37,14 @@
0
       end
0
       
0
       target_file_or_dir = git.paths.first
0
- puts "<h1>Committing Files in ‘#{htmlize(shorten(target_file_or_dir, ENV['TM_PROJECT_DIRECTORY'] || @base))}’ on branch ‘#{htmlize(git.branch.current_name)}’</h1>"
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
       flush
0
 
0
       files, statuses = [], []
0
@@ -55,7 +62,7 @@
0
 
0
       unless files.empty?
0
         auto_add_rm(files)
0
- res = git.commit(msg, 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
     end
...
4
5
6
7
8
 
 
 
9
10
11
...
64
65
66
67
 
 
 
 
 
 
 
 
68
...
4
5
6
 
 
7
8
9
10
11
12
...
65
66
67
 
68
69
70
71
72
73
74
75
76
0
@@ -4,8 +4,9 @@
0
     show_diff_title unless params[:layout].to_s=="false"
0
     @rev = params[:rev]
0
     @title = params[:title] || "Uncomitted changes"
0
- params[:context_lines] = git.config["git-tmbundle.log.context-lines"] if git.config["git-tmbundle.log.context-lines"]
0
- render("_diff_results", :locals => {:diff_results => git.diff(params)})
0
+
0
+ diff_params = extract_diff_params(params)
0
+ render("_diff_results", :locals => {:diff_results => git.diff(diff_params)})
0
   end
0
   
0
   def uncommitted_changes
0
@@ -64,6 +65,13 @@
0
     end
0
     puts "</h2>"
0
   end
0
-
0
+
0
+ def extract_diff_params(params)
0
+ diff_params = params.dup.delete_if do |key, value|
0
+ ! [:revisions, :revision, :branches, :tags, :path].include?(key)
0
+ end
0
+ diff_params[:context_lines] = git.config["git-tmbundle.log.context-lines"] if git.config["git-tmbundle.log.context-lines"]
0
+ diff_params
0
+ end
0
 end
...
215
216
217
218
219
 
 
 
 
 
220
221
222
...
215
216
217
 
 
218
219
220
221
222
223
224
225
0
@@ -215,8 +215,11 @@
0
       status.empty?
0
     end
0
 
0
- def commit(msg, files = ["."])
0
- parse_commit(command("commit", "-m", msg, *files))
0
+ def commit(msg, files = ["."], options = {})
0
+ args = ["commit"]
0
+ args << "--amend" if options[:amend]
0
+ args += ["-m", msg, *files]
0
+ parse_commit(command(*args))
0
     end
0
     
0
     def add(files = ["."])
...
257
258
259
 
260
...
257
258
259
260
261
0
@@ -257,5 +257,6 @@
0
   end
0
   
0
   include StreamProgressMethods
0
+ extend self
0
 end
...
3
4
5
 
6
7
8
...
16
17
18
19
20
21
 
 
 
 
 
 
 
 
 
 
22
23
24
...
26
27
28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
30
31
...
3
4
5
6
7
8
9
...
17
18
19
 
 
 
20
21
22
23
24
25
26
27
28
29
30
31
32
...
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
0
@@ -3,6 +3,7 @@
0
 describe CommitController do
0
   include SpecHelpers
0
   before(:each) do
0
+ Git.reset_mock!
0
     @controller = CommitController.singleton_new
0
     @git = Git.singleton_new
0
     Git.command_response["status"] = fixture_file("status_output.txt")
0
@@ -16,9 +17,16 @@
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
- Git.command_response["commit", "-m", "My commit message", "file1.txt", "file2.txt"] = fixture_file("commit_result.txt")
0
- Git.command_response["diff", "24ff719^..24ff719", "."] = fixture_file("small.diff")
0
- Git.command_response["branch"] = "* master"
0
+
0
+ @git.should_receive(:commit).
0
+ with("My commit message", ["file1.txt", "file2.txt"], :amend => false).
0
+ and_return(:rev => "1234567")
0
+
0
+ @git.should_receive(:diff).
0
+ with(:path => ".", :revisions => "1234567^..1234567").
0
+ and_return( Parsers.parse_diff(fixture_file("small.diff")) )
0
+
0
+ @git.branch.stub!(:current_name).and_return("master")
0
       @output = capture_output do
0
         dispatch(:controller => "commit")
0
       end
0
@@ -26,6 +34,44 @@
0
     
0
     after(:each) do
0
       # puts Git.commands_ran.inspect
0
+ end
0
+
0
+ it "should output the commit message" do
0
+ @output.should include(@message)
0
+ end
0
+
0
+ it "should output the diff" do
0
+ @output.should include("No newline at end of file")
0
+ end
0
+ end
0
+
0
+ describe "Ammend 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
+
0
+ @git.should_receive(:commit).
0
+ with("My commit message", ["file1.txt", "file2.txt"], :amend => true).
0
+ and_return(:rev => "1234567")
0
+
0
+ @git.should_receive(:diff).
0
+ with(:path => ".", :revisions => "1234567^..1234567").
0
+ and_return( Parsers.parse_diff(fixture_file("small.diff")) )
0
+
0
+ @git.branch.stub!(:current_name).and_return("master")
0
+
0
+ @output = capture_output do
0
+ dispatch(:controller => "commit", :type => "amend")
0
+ end
0
+ end
0
+
0
+ after(:each) do
0
+ # puts Git.commands_ran.inspect
0
+ end
0
+
0
+ it "should say mention we're amending a commit" do
0
+ @output.should include("Amending")
0
     end
0
     
0
     it "should output the commit message" do
...
93
94
95
 
96
97
98
...
93
94
95
96
97
98
99
0
@@ -93,6 +93,7 @@
0
     <string>B3577B4D-A3F1-4CB4-94B0-7A87CA658664</string>
0
     <string>46662F92-7739-42A7-B7CD-0527A0474BDC</string>
0
     <string>55CCBE51-3C13-46D8-92D9-52EAD7A5D2D6</string>
0
+ <string>2F24C9CB-23D0-4FDA-9C8D-210027DCEB27</string>
0
     <string>CDEA521C-8963-414F-8F8E-F9B81EF79ADA</string>
0
     <string>7F8D2058-E106-40DC-9FBE-F32A1202D158</string>
0
     <string>508C7FCD-E5DD-4E60-88C3-A668C48273B7</string>

Comments

    No one has commented yet.