public
Rubygem
Description: Simple tool to help track git and svn vendor branches in a git repository
Homepage: http://evil.che.lu/projects/braid
Clone URL: git://github.com/evilchelu/braid.git
Search Repo:
Run fetch earlier when updating. Fix config initialization bug.
norbert (author)
Tue Apr 29 01:06:13 -0700 2008
commit  00a5546be26ebb580c2ada63862a980dd4c1dcdd
tree    f7e3cee67726a2b8fc7ae0f3a40a6c2c7caf6526
parent  9175d5668d9db7d998cbb9195d2ebaf7c4a3e9a8
...
122
123
124
125
 
126
127
128
...
122
123
124
 
125
126
127
128
0
@@ -122,7 +122,7 @@ Main {
0
 
0
   mode(:diff) {
0
     description <<-TXT
0
- Show diff between #{Braid::TRACK_BRANCH} and HEAD.
0
+ Show diff between '#{Braid::WORK_BRANCH}' and HEAD.
0
     TXT
0
 
0
     examples <<-TXT
...
7
8
9
10
 
11
12
13
...
7
8
9
 
10
11
12
13
0
@@ -7,7 +7,7 @@ end
0
 
0
 module Braid
0
   MIRROR_TYPES = %w[git svn]
0
- TRACK_BRANCH = "braid/track"
0
+ WORK_BRANCH = "braid/track"
0
   CONFIG_FILE = ".braids"
0
 end
0
 
...
3
4
5
6
7
8
9
10
11
12
13
14
...
20
21
22
 
 
 
 
23
24
25
26
27
28
 
29
30
31
32
33
 
34
35
36
...
38
39
40
41
 
42
43
44
45
46
 
 
 
47
48
49
...
3
4
5
 
 
 
 
 
 
6
7
8
...
14
15
16
17
18
19
20
21
22
23
24
25
 
26
27
28
29
30
 
31
32
33
34
...
36
37
38
 
39
40
41
 
 
 
42
43
44
45
46
47
0
@@ -3,12 +3,6 @@ module Braid
0
     include Operations::Mirror
0
     include Operations::Helpers
0
 
0
- attr_accessor :config
0
-
0
- def initialize(options = {})
0
- @config = options["config"] || Braid::Config.new
0
- end
0
-
0
     def self.run(command, *args)
0
       klass = Braid::Commands.const_get(command.to_s.capitalize)
0
       klass.new.run(*args)
0
@@ -20,17 +14,21 @@ module Braid
0
       puts str
0
     end
0
 
0
+ def config
0
+ @config ||= Braid::Config.new
0
+ end
0
+
0
     private
0
       def msg(str)
0
         self.class.msg(str)
0
       end
0
 
0
- def in_track_branch
0
+ def in_work_branch
0
         # make sure there is a git repository
0
         begin
0
           old_branch = get_current_branch
0
         rescue => e
0
- msg "Error occured: #{e}"
0
+ msg "Error occured: #{e.message}"
0
           raise e
0
         end
0
 
0
@@ -38,12 +36,12 @@ module Braid
0
         work_head = get_work_head
0
 
0
         begin
0
- invoke(:git_checkout, TRACK_BRANCH)
0
+ invoke(:git_checkout, WORK_BRANCH)
0
           yield
0
         rescue => e
0
- msg "Error occured: #{e}"
0
- if get_current_branch == TRACK_BRANCH
0
- msg "Resetting '#{TRACK_BRANCH}' to #{work_head}."
0
+ msg "Error occured: #{e.message}"
0
+ if get_current_branch == WORK_BRANCH
0
+ msg "Resetting '#{WORK_BRANCH}' to '#{work_head}'."
0
             invoke(:git_reset_hard, work_head)
0
           end
0
           raise e
...
1
2
3
4
5
6
7
 
8
9
10
...
17
18
19
20
21
22
23
...
 
 
1
2
3
4
 
5
6
7
8
...
15
16
17
 
18
19
20
0
@@ -1,10 +1,8 @@
0
-require 'yaml'
0
-
0
 module Braid
0
   module Commands
0
     class Add < Command
0
       def run(remote, options = {})
0
- in_track_branch do
0
+ in_work_branch do
0
           mirror, params = config.add_from_options(remote, options)
0
           local_branch = get_local_branch_name(mirror, params)
0
 
0
@@ -17,7 +15,6 @@ module Braid
0
           # http://www.kernel.org/pub/software/scm/git/docs/howto/using-merge-subtree.html
0
 
0
           setup_remote(mirror)
0
- msg "Fetching data from '#{local_branch}'."
0
           fetch_remote(params["type"], local_branch)
0
 
0
           validate_revision_option(params, options)
...
3
4
5
6
 
7
8
9
...
3
4
5
 
6
7
8
9
0
@@ -3,7 +3,7 @@ module Braid
0
     class Diff < Command
0
       def run(mirror)
0
         # easiest call, liek, evar.
0
- system("git diff #{TRACK_BRANCH} HEAD #{mirror}")
0
+ system("git diff #{WORK_BRANCH} HEAD #{mirror}")
0
       end
0
     end
0
   end
...
2
3
4
5
6
7
8
9
 
 
 
 
 
 
10
11
12
13
14
...
2
3
4
 
 
 
 
 
5
6
7
8
9
10
11
 
12
13
14
0
@@ -2,13 +2,13 @@ module Braid
0
   module Commands
0
     class Remove < Command
0
       def run(mirror)
0
- params = config.get(mirror)
0
- unless params
0
- msg "Mirror '#{mirror}/' does not exist."
0
- return
0
- end
0
+ in_work_branch do
0
+ params = config.get(mirror)
0
+ unless params
0
+ msg "Mirror '#{mirror}/' does not exist."
0
+ return
0
+ end
0
 
0
- in_track_branch do
0
           msg "Removing #{params["type"]} mirror from '#{mirror}/'."
0
 
0
           invoke(:git_rm_r, mirror)
...
2
3
4
5
 
 
 
6
7
8
...
26
27
28
29
30
31
32
33
34
35
...
2
3
4
 
5
6
7
8
9
10
...
28
29
30
 
 
 
 
31
32
33
0
@@ -2,7 +2,9 @@ module Braid
0
   module Commands
0
     class Setup < Command
0
       def run(mirror)
0
- mirror ? setup_one(mirror) : setup_all
0
+ in_track_branch do
0
+ mirror ? setup_one(mirror) : setup_all
0
+ end
0
       end
0
 
0
       protected
0
@@ -26,10 +28,6 @@ module Braid
0
           end
0
 
0
           msg "Setting up remote for '#{mirror}/'."
0
- create_remote(params)
0
- end
0
-
0
- def create_remote(params)
0
           case params["type"]
0
           when "git"
0
             invoke(:git_remote_add, params["local_branch"], params["remote"], params["branch"])
...
2
3
4
5
 
6
7
8
...
35
36
37
 
 
38
39
40
41
42
43
44
45
...
2
3
4
 
5
6
7
8
...
35
36
37
38
39
40
41
42
 
 
43
44
45
0
@@ -2,7 +2,7 @@ module Braid
0
   module Commands
0
     class Update < Command
0
       def run(mirror, options = {})
0
- in_track_branch do
0
+ in_work_branch do
0
           mirror ? update_one(mirror, options) : update_all
0
         end
0
       end
0
@@ -35,11 +35,11 @@ module Braid
0
           end
0
 
0
           begin
0
+ fetch_remote(params["type"], local_branch)
0
+
0
             validate_revision_option(params, options)
0
             target = determine_target_commit(params, options)
0
 
0
- fetch_remote(params["type"], local_branch)
0
-
0
             check_merge_status(target)
0
           rescue Braid::Commands::MirrorAlreadyUpToDate
0
             msg "Mirror '#{mirror}/' is already up to date. Skipping."
...
192
193
194
195
 
196
197
198
199
 
 
200
201
202
203
204
205
206
 
207
208
209
...
223
224
225
 
226
227
228
...
192
193
194
 
195
196
197
 
 
198
199
200
201
202
203
204
205
 
206
207
208
209
...
223
224
225
226
227
228
229
0
@@ -192,18 +192,18 @@ module Braid
0
 
0
       def create_work_branch
0
         # check if branch exists
0
- status, out, err = exec("git branch | grep '#{TRACK_BRANCH}'")
0
+ status, out, err = exec("git branch | grep '#{WORK_BRANCH}'")
0
         if status != 0
0
           # then create it
0
- msg "Creating work branch '#{TRACK_BRANCH}'."
0
- exec!("git branch #{TRACK_BRANCH}")
0
+ msg "Creating work branch '#{WORK_BRANCH}'."
0
+ exec!("git branch #{WORK_BRANCH}")
0
         end
0
 
0
         true
0
       end
0
 
0
       def get_work_head
0
- find_git_revision(TRACK_BRANCH)
0
+ find_git_revision(WORK_BRANCH)
0
       end
0
 
0
       def add_config_file
0
@@ -223,6 +223,7 @@ module Braid
0
       end
0
 
0
       def fetch_remote(type, remote)
0
+ msg "Fetching data from '#{local_branch}'."
0
         case type
0
         when "git"
0
           invoke(:git_fetch, remote)

Comments

    No one has commented yet.