public
Description: The Git TextMate Bundle
Homepage: http://tim.theenchanter.com/
Clone URL: git://github.com/timcharper/git-tmbundle.git
Search Repo:
submodule stashing is integrated into merge, pull, and switch
timcharper (author)
Tue Apr 29 18:01:54 -0700 2008
commit  a4817ba8583aab2821b6dc93e149b2c57a1ef6a1
tree    435574a5ed018c0c68c9332cc3d81b1f388179c8
parent  c4a7332863dc3ddb66dc681643dfbe8867c8e206
...
76
77
78
79
80
81
 
 
 
 
 
 
82
83
84
...
144
145
146
147
148
149
150
151
152
153
154
155
156
157
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
159
 
 
 
160
161
162
163
164
165
166
167
168
169
170
171
...
76
77
78
 
 
 
79
80
81
82
83
84
85
86
87
...
147
148
149
 
 
 
 
 
 
 
 
 
 
 
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
 
166
167
168
169
 
 
 
 
 
170
171
 
 
172
173
0
@@ -76,9 +76,12 @@ class BranchController < ApplicationController
0
     
0
     puts "<h2>Merging #{@merge_from_branch} into #{@c_branch}</h2>"
0
     flush
0
- @result = git.merge(@merge_from_branch)
0
- render "merge"
0
- update_submodules_si_hay
0
+
0
+ with_submodule_stashing do
0
+ @result = git.merge(@merge_from_branch)
0
+ render "merge"
0
+ true
0
+ end
0
     rescan_project
0
   end
0
     
0
@@ -144,27 +147,26 @@ class BranchController < ApplicationController
0
     end
0
     
0
     def switch_local(target_branch)
0
- output = git.branch.switch(target_branch)
0
- case output
0
- when /fatal: you need to resolve your current index first/
0
- TextMate::UI.alert(:warning, "Error - couldn't switch", "Git said:\n#{output}\nYou're probably in the middle of a conflicted merge, and need to commit", "OK")
0
- exit_discard
0
- when /(fatal|error): Entry '(.+)' not uptodate\. Cannot merge\./
0
- response = TextMate::UI.alert(:informational, "Conflicts may happen if you switch", "There are uncommitted changes that might cause conflicts by this switch (#{$2}).\nSwitch anyways?", "No", "Yes")
0
- if response=="Yes"
0
- output = git.command("checkout", "-m", target_branch)
0
- puts htmlize(output)
0
- output_show_html and return
0
+ with_submodule_stashing do
0
+ output = git.branch.switch(target_branch)
0
+ case output
0
+ when /fatal: you need to resolve your current index first/
0
+ TextMate::UI.alert(:warning, "Error - couldn't switch", "Git said:\n#{output}\nYou're probably in the middle of a conflicted merge, and need to commit", "OK")
0
+ output_discard
0
+ when /(fatal|error): Entry '(.+)' not uptodate\. Cannot merge\./
0
+ response = TextMate::UI.alert(:informational, "Conflicts may happen if you switch", "There are uncommitted changes that might cause conflicts by this switch (#{$2}).\nSwitch anyways?", "No", "Yes")
0
+ if response=="Yes"
0
+ output = git.command("checkout", "-m", target_branch)
0
+ puts htmlize(output)
0
+ output_show_html and return
0
+ else
0
+ output_discard and return
0
+ end
0
         else
0
- output_discard and return
0
+ puts htmlize(output)
0
+ output_show_html
0
+ rescan_project
0
         end
0
- else
0
- puts htmlize(output)
0
- output_show_html
0
- update_submodules_si_hay
0
- rescan_project
0
       end
0
     end
0
-
0
-
0
 end
0
\ No newline at end of file
...
47
48
49
50
51
52
53
54
55
56
57
58
59
 
 
 
 
 
 
 
 
 
 
 
 
60
61
62
...
47
48
49
 
 
50
 
 
 
 
 
 
 
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
0
@@ -47,16 +47,19 @@ class RemoteController < ApplicationController
0
       end
0
       
0
       puts "<p>Pulling from remote source '#{source}'\n</p>"
0
- output = run_pull(source, remote_branch_name)
0
- puts "<pre>#{output[:text]}</pre>"
0
       
0
- if ! output[:pulls].empty?
0
- puts("<h2>Log of changes pulled</h2>")
0
- output_branch_logs(output[:pulls])
0
-
0
- update_submodules_si_hay
0
- elsif output[:nothing_to_pull]
0
- puts "Nothing to pull"
0
+ with_submodule_stashing do
0
+ output = run_pull(source, remote_branch_name)
0
+ puts "<pre>#{output[:text]}</pre>"
0
+
0
+ if ! output[:pulls].empty?
0
+ puts("<h2>Log of changes pulled</h2>")
0
+ output_branch_logs(output[:pulls])
0
+ true
0
+ elsif output[:nothing_to_pull]
0
+ puts "Nothing to pull"
0
+ false
0
+ end
0
       end
0
     end
0
   end
...
1
2
3
4
 
 
 
 
 
 
 
 
 
 
 
 
 
5
6
7
...
1
2
3
 
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
0
@@ -1,7 +1,19 @@
0
 module SubmoduleHelper
0
   module Update
0
     def with_submodule_stashing(&block)
0
- git.submodule.all.each
0
+ modules = git.submodule.all
0
+ if modules.empty?
0
+ yield
0
+ else
0
+ modules.each { |m| m.stash }
0
+ begin
0
+ yield
0
+ ensure
0
+ git.submodule.all.each { |m| m.restore }
0
+ end
0
+
0
+ update_submodules_si_hay
0
+ end
0
     end
0
     
0
     def update_submodules_si_hay
...
37
38
39
 
40
41
42
...
87
88
89
90
 
91
92
93
94
 
 
95
96
97
...
110
111
112
 
113
114
115
...
134
135
136
137
138
139
140
 
141
142
143
...
145
146
147
148
149
 
 
150
151
152
...
37
38
39
40
41
42
43
...
88
89
90
 
91
92
93
94
 
95
96
97
98
99
...
112
113
114
115
116
117
118
...
137
138
139
 
140
141
142
143
144
145
146
...
148
149
150
 
 
151
152
153
154
155
0
@@ -37,6 +37,7 @@ end
0
 
0
 describe BranchController do
0
   before(:each) do
0
+ @git = Git.singleton_new
0
     Git.reset_mock!
0
     Git.command_response["branch", "-r"] = " origin/master\n origin/release\n origin/task"
0
     Git.command_response["branch"] = "* master\n task"
0
@@ -87,11 +88,12 @@ EOF
0
       end
0
       
0
       describe "when you have submodules" do
0
- it "should call submodules.init_and_update" do
0
+ it "should stash, restore, then call submodules.init_and_update" do
0
           @set_branch_to_choose.call("task")
0
           
0
           git = Git.singleton_new
0
- git.submodule.should_receive(:list).and_return([{:name => "mod"}])
0
+ @submodule = stub("submodule", :stash => true, :restore => true)
0
+ git.submodule.should_receive(:all).any_number_of_times.and_return([@submodule])
0
           git.submodule.should_receive(:init_and_update)
0
           output = capture_output do
0
             dispatch(:controller => "branch", :action => "switch")
0
@@ -110,6 +112,7 @@ EOF
0
         TextMate::UI.should_receive(:request_string).with(@get_branch_name_params).and_return("release")
0
         Git.command_response["branch", "--track", "release", "origin/release"] = %{Branch release set up to track remote branch refs/remotes/origin/release.\n}
0
         Git.command_response["checkout", "release"] = %{Switched to branch "release"\n}
0
+ @git.submodule.stub!(:all).and_return([])
0
         output = capture_output do
0
           dispatch(:controller => "branch", :action => "switch")
0
         end
0
@@ -134,10 +137,10 @@ EOF
0
         @git.branch.stub!(:list_names).and_return(["master", "release", "old_skool"])
0
         
0
         TextMate::UI.should_receive(:request_item).with(:title => "Merge", :prompt => "Merge which branch into 'master':", :items => ["release", "old_skool"], :force_pick => true).and_return("release")
0
- @git.should_receive(:merge).with("release").and_return({:text => "Success!", :conflicts => [] })
0
       end
0
       
0
       it "should merge a branch" do
0
+ @git.should_receive(:merge).with("release").and_return({:text => "Success!", :conflicts => [] })
0
         output = capture_output do
0
           dispatch(:controller => "branch", :action => "merge")
0
         end
0
@@ -145,8 +148,8 @@ EOF
0
         output.should include("Success!")
0
       end
0
       
0
- it "should update_submodules_si_hay" do
0
- @controller.should_receive(:update_submodules_si_hay)
0
+ it "should run with_submodule_stashing" do
0
+ @controller.should_receive(:with_submodule_stashing)
0
         capture_output { dispatch(:controller => "branch", :action => "merge") }
0
       end
0
     end
...
67
68
69
70
71
 
 
72
73
74
...
67
68
69
 
 
70
71
72
73
74
0
@@ -67,8 +67,8 @@ describe RemoteController do
0
       @output.should include("Branch 'asdf': dc29d3d..05f9ad9")
0
     end
0
     
0
- it "should update_submodules_si_hay" do
0
- @controller.should_receive(:update_submodules_si_hay)
0
+ it "should with_submodule_stashing" do
0
+ @controller.should_receive(:with_submodule_stashing)
0
       capture_output { dispatch :controller => "remote", :action => "pull" }
0
     end
0
   end

Comments

    No one has commented yet.