public
Rubygem
Fork of evilchelu/braid
Description: A simple tool for tracking vendor branches in git
Homepage: http://evil.che.lu/projects/braid
Clone URL: git://github.com/norbert/braid.git
Search Repo:
Random cleaning
norbert (author)
Tue Jul 15 06:27:30 -0700 2008
commit  6aa4fcf6f7b2a359acf80f74cd8e813635113327
tree    306628ef701c41d471a134f430cc798ad155775f
parent  50d2953d4658fa00319d8087cfe75259c0551977
...
8
9
10
11
12
13
14
15
...
30
31
32
33
 
34
35
36
...
58
59
60
61
 
62
63
 
 
 
 
 
64
65
...
8
9
10
 
 
11
12
13
...
28
29
30
 
31
32
33
34
...
56
57
58
 
59
60
61
62
63
64
65
66
67
68
0
@@ -8,8 +8,6 @@ module Braid
0
     class MirrorDoesNotExist < BraidError
0
     end
0
 
0
- attr_reader :db
0
-
0
     def initialize(config_file = CONFIG_FILE)
0
       @db = YAML::Store.new(config_file)
0
     end
0
@@ -30,7 +28,7 @@ module Braid
0
     def add(mirror)
0
       @db.transaction do
0
         raise PathAlreadyInUse if @db[mirror.path]
0
- @db[mirror.path] = mirror.attributes
0
+ @db[mirror.path] = clean_attributes(mirror.attributes)
0
       end
0
     end
0
 
0
@@ -58,8 +56,13 @@ module Braid
0
       @db.transaction do
0
         raise MirrorDoesNotExist unless @db[mirror.path]
0
         @db.delete(mirror)
0
- @db[mirror.path] = mirror.attributes
0
+ @db[mirror.path] = clean_attributes(mirror.attributes)
0
       end
0
     end
0
+
0
+ private
0
+ def clean_attributes(hash)
0
+ (hash = hash.dup).each { |k,v| hash.delete(k) if v.nil? }
0
+ end
0
   end
0
 end
...
14
15
16
17
 
18
19
20
...
47
48
49
50
 
51
52
53
...
73
74
75
76
77
 
 
78
79
 
80
81
82
...
113
114
115
116
117
 
 
118
119
120
...
14
15
16
 
17
18
19
20
...
47
48
49
 
50
51
52
53
...
73
74
75
 
 
76
77
78
 
79
80
81
82
...
113
114
115
 
 
116
117
118
119
120
0
@@ -14,7 +14,7 @@ module Braid
0
 
0
     attr_reader :path, :attributes
0
 
0
- def initialize(path, attributes)
0
+ def initialize(path, attributes = {})
0
       @path = path.sub(/\/$/, '')
0
       @attributes = attributes
0
     end
0
@@ -47,7 +47,7 @@ module Braid
0
         branch = nil
0
       end
0
 
0
- attributes = { "url" => url, "remote" => remote, "type" => type, "branch" => branch, "squashed" => squashed, "revision" => nil, "lock" => nil }
0
+ attributes = { "url" => url, "remote" => remote, "type" => type, "branch" => branch, "squashed" => squashed }
0
       self.new(path, attributes)
0
     end
0
 
0
@@ -73,10 +73,10 @@ module Braid
0
       # tip from spearce in #git:
0
       # `test z$(git merge-base A B) = z$(git rev-parse --verify A)`
0
       commit = git.rev_parse(commit)
0
- unless squashed?
0
- git.merge_base(commit, "HEAD") == commit
0
+ if squashed?
0
+ !!base_revision && git.merge_base(commit, base_revision) == commit
0
       else
0
- git.merge_base(commit, base_revision) == commit
0
+ git.merge_base(commit, "HEAD") == commit
0
       end
0
     end
0
 
0
@@ -113,8 +113,8 @@ module Braid
0
       end
0
 
0
       def base_revision
0
- unless type == "svn"
0
- revision
0
+ revision && unless type == "svn"
0
+ git.rev_parse(revision)
0
         else
0
           git_svn.commit_hash(remote, revision)
0
         end
...
49
50
51
52
 
53
54
55
56
57
58
59
60
...
92
93
94
95
 
96
97
98
...
119
120
121
122
123
 
124
125
126
127
128
129
130
 
131
132
133
...
173
174
175
176
 
177
178
179
...
49
50
51
 
52
53
54
55
56
 
57
58
59
...
91
92
93
 
94
95
96
97
...
118
119
120
 
 
121
122
123
124
125
126
 
 
127
128
129
130
...
170
171
172
 
173
174
175
176
0
@@ -49,12 +49,11 @@ module Braid
0
         end
0
 
0
         def invoke(arg, *args)
0
- exec!("#{command(arg)} #{args.join(' ')}".strip)
0
+ exec!("#{command(arg)} #{args.join(' ')}".strip)[1] # return stdout
0
         end
0
 
0
         def method_missing(name, *args)
0
           invoke(name, *args)
0
- true
0
         end
0
 
0
         def exec(cmd)
0
@@ -92,7 +91,7 @@ module Braid
0
       end
0
 
0
       def commit(message)
0
- status, out, err = invoke(:commit, "-m #{message.inspect} --no-verify")
0
+ status, out, err = exec("git commit -m #{message.inspect} --no-verify")
0
 
0
         if status == 0
0
           true
0
@@ -119,15 +118,13 @@ module Braid
0
 
0
       # Returns the base commit or nil.
0
       def merge_base(target, source)
0
- status, out, err = invoke(:merge_base, target, source)
0
- out.strip
0
+ invoke(:merge_base, target, source)
0
       rescue ShellExecutionError
0
         nil
0
       end
0
 
0
       def rev_parse(opt)
0
- status, out, err = invoke(:rev_parse, opt)
0
- out.strip
0
+ invoke(:rev_parse, opt)
0
       rescue ShellExecutionError
0
         raise UnknownRevision, opt
0
       end
0
@@ -173,7 +170,7 @@ module Braid
0
       end
0
 
0
       def tree_hash(path, treeish = "HEAD")
0
- status, out, err = invoke(:ls_tree, treeish, "-d", path)
0
+ out = invoke(:ls_tree, treeish, "-d", path)
0
         out.split[2]
0
       end
0
 
...
47
48
49
50
 
51
52
53
...
61
62
63
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
47
48
49
 
50
51
52
53
...
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
0
@@ -47,7 +47,7 @@ end
0
 
0
 describe "Braid::Mirror#local_changes?" do
0
   before(:each) do
0
- @mirror = Braid::Mirror.new_from_options("git://path")
0
+ @mirror = new_from_options("git://path")
0
     Braid::Operations::Git.any_instance.expects(:rev_parse)
0
   end
0
 
0
@@ -61,3 +61,17 @@ describe "Braid::Mirror#local_changes?" do
0
     @mirror.local_changes?.should == false
0
   end
0
 end
0
+
0
+describe "Braid::Mirror#base_revision" do
0
+ it "should be nil when no revision is set" do
0
+ @mirror = Braid::Mirror.new("path")
0
+ @mirror.revision.should.be.nil
0
+ @mirror.send(:base_revision).should.be.nil
0
+ end
0
+
0
+ it "should be the parsed hash for git mirrors" do
0
+ Braid::Operations::Git.any_instance.expects(:rev_parse).returns('a' * 40)
0
+ @mirror = Braid::Mirror.new("path", "revision" => ('a' * 7))
0
+ @mirror.send(:base_revision).should == 'a' * 40
0
+ end
0
+end

Comments

    No one has commented yet.