public
Description: The Git TextMate Bundle
Homepage: http://tim.theenchanter.com/
Clone URL: git://github.com/timcharper/git-tmbundle.git
added stash / restore to SubmoduleProxy
timcharper (author)
Tue Apr 29 17:33:01 -0700 2008
commit  c4a7332863dc3ddb66dc681643dfbe8867c8e206
tree    6c4d7182482321ede7062cf53ad15f718eb24b38
parent  e4a36d80f9b63996ca64ce72f08b04a3d9872d34
...
1
2
 
 
 
 
3
4
5
...
1
2
3
4
5
6
7
8
9
0
@@ -1,5 +1,9 @@
0
 module SubmoduleHelper
0
   module Update
0
+ def with_submodule_stashing(&block)
0
+ git.submodule.all.each
0
+ end
0
+
0
     def update_submodules_si_hay
0
       unless git.submodule.all.empty?
0
         puts "<br /><br /><h3>Updating submodules</h3>"
...
 
1
2
3
...
23
24
25
26
 
27
28
29
30
31
32
33
 
34
35
 
36
37
38
39
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
42
43
...
1
2
3
4
...
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
0
@@ -1,3 +1,4 @@
0
+require 'md5'
0
 class SCM::Git::Submodule < SCM::Git::CommandProxyBase
0
   def init_and_update
0
     output = @base.command("submodule", "init")
0
@@ -23,21 +24,53 @@ class SCM::Git::Submodule < SCM::Git::CommandProxyBase
0
         {
0
           :state => {" " => 0, "-" => -1, "+" => 1}[$1],
0
           :revision => $2,
0
- :name => $3,
0
+ :path => $3,
0
           :tag => ($5 == "undefined" ? nil : $5)
0
         }
0
       end.compact
0
     end
0
     
0
   class SubmoduleProxy
0
- attr_reader :revision, :name, :tag, :state
0
+ attr_reader :revision, :path, :tag, :state
0
   
0
     def initialize(base, parent, options = {})
0
+ @base, @parent, @tag = base, parent, tag
0
       options.each do |key, value|
0
         instance_variable_set("@#{key}", value)
0
       end
0
     end
0
-
0
+
0
+ def url
0
+ @base.command("config", "--file", File.join(@base.git_base, ".gitmodules"), "submodule.#{path}.url")
0
+ end
0
+
0
+ def name
0
+ path
0
+ end
0
+
0
+ def abs_stash_path
0
+ @abs_stash_path ||= File.join(@base.git_base, ".git/submodule_stash", MD5.hexdigest(path + "\n" + url))
0
+ end
0
+
0
+ def abs_path
0
+ @abs_path ||= File.join(@base.git_base, @path)
0
+ end
0
+
0
+ def stash
0
+ if File.exist?(abs_path)
0
+ FileUtils.rm_rf(abs_stash_path)
0
+ FileUtils.mkdir_p(File.dirname(abs_stash_path))
0
+ FileUtils.mv(abs_path, abs_stash_path, :force => true)
0
+ true
0
+ end
0
+ end
0
+
0
+ def restore
0
+ if ! File.exist?(abs_path) && File.exist?(abs_stash_path)
0
+ FileUtils.mkdir_p(File.dirname(abs_path))
0
+ FileUtils.mv(abs_stash_path, abs_path, :force => true)
0
+ end
0
+ end
0
   end
0
 end
0
 
...
49
50
51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
...
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
0
@@ -49,4 +49,28 @@ EOF
0
     submodules = @git.submodule.all
0
     submodules.should have(1).submodules
0
   end
0
+
0
+ describe "when working with a submodule" do
0
+ before(:each) do
0
+ @path = "vendor/plugins/acts_as_plugin"
0
+ @submodule = SCM::Git::Submodule::SubmoduleProxy.new(@git, @git.submodule, :revision => "1234", :path => @path, :tag => "release")
0
+ @submodule.stub!(:url).and_return("git@url.com/path/to/repo.git")
0
+ end
0
+
0
+ it "should stash" do
0
+ File.should_receive(:exist?).with(@submodule.abs_path).and_return(true)
0
+ FileUtils.should_receive(:mkdir_p).with(File.join(@git.git_base, ".git/submodule_stash"))
0
+ FileUtils.should_receive(:rm_rf).with(@submodule.abs_stash_path)
0
+ FileUtils.should_receive(:mv).with(@submodule.abs_path, @submodule.abs_stash_path, :force => true)
0
+ @submodule.stash
0
+ end
0
+
0
+ it "should restore when submodule isn't in working copy" do
0
+ File.should_receive(:exist?).with(@submodule.abs_path).and_return(false)
0
+ File.should_receive(:exist?).with(@submodule.abs_stash_path).and_return(true)
0
+ FileUtils.should_receive(:mkdir_p).with(File.dirname(@submodule.abs_path))
0
+ FileUtils.should_receive(:mv).with(@submodule.abs_stash_path, @submodule.abs_path, :force => true)
0
+ @submodule.restore
0
+ end
0
+ end
0
 end

Comments

    No one has commented yet.