Commits

Alessio Caiazza committed 42b1962 Merge

flow: Merged <feature> 'mercurial' to <develop> ('develop').

Comments (0)

Files changed (5)

lib/dependency_wiring/configuration.rb

       deps().each { |d| puts d }
     end
 
+    def wire_all
+      deps().each do |dep|
+        puts "wiring #{dep}"
+        dep.prepare_dest
+        dep.wire
+      end
+    end
+
     private
     def read()
       File.open(@src_file, 'r') { |f| f.read }

lib/dependency_wiring/mercurial.rb

 module DependencyWiring
   class Mercurial < SCM
     
-    # def initialize(src, dest, opts = {})
-    #   super(src, dest)
-    #   @opts = default_opts().merge(opts)
-    # end
-
     def clone
       ret = sh_with_code("hg clone #{hg_opts} #{@src} .")
-      raise("Cannot clone #{@src}") if ret[1] != 0
+      raise("Cannot clone #{@src} into #{@dest}! Output: #{ret[0]}") if ret[1] != 0
     end
 
     def pull
       ret = sh_with_code("hg pull #{hg_opts} #{@src}")
-      raise("Cannot clone #{@src}") if ret[1] != 0
+      raise("Cannot pull #{@dest}! Output: #{ret[0]}") if ret[1] != 0
     end
 
     def update
       ret = sh_with_code("hg update -C #{hg_revision}")
-      raise("Cannot clone #{@src}") if ret[1] != 0  
+      if ret[1] != 0
+        raise("Cannot update #{@dest} to #{hg_revision}! Output: #{ret[0]}") 
+      end
     end    
 
+    def wire
+      pull
+      update
+    end
+
+    def to_s
+      "hg(#{@src}, #{@opts}) -> #{@dest}"
+    end
+
+    def default_opts
+      { branch: 'default' }
+    end
+
+    def valid_destination?
+      ret = sh_with_code('hg su')
+      ret[1] == 0
+    end  
+
+    protected
     def hg_opts
       opts = StringIO.new
       branch = @opts[:branch]
           rev
         else
           branch
+        end
       elsif(rev.nil? && tag.nil?)
         branch
       else
         raise("Cannot specify tag, rev and branch")  
       end
     end
-
-    def default_opts
-      { branch: 'default' }
-    end
   end
 end

lib/dependency_wiring/mount_point.rb

       FileUtils.mkdir_p(@dest)
     end
 
+    def wire
+    end
+
     protected
     def sh(cmd, &block)
       out, code = sh_with_code(cmd, &block)

lib/dependency_wiring/scm.rb

       @opts = default_opts().merge(opts)
     end
 
-    def clone
-    end
+    # def clone
+    # end
 
-    def pull
-    end
+    # def pull
+    # end
 
-    def update
-    end    
+    # def update
+    # end    
 
     def default_opts
       {}
     end
 
-    def to_s
-      "hg(#{@src}, #{@opts}) -> #{@dest}"
-    end
-
     def prepare_dest
       if File.exists?(@dest) && File.directory?(@dest)
-        valid_destination?
+        unless valid_destination?
+          raise("#{@dest} doesn't seems to be a working copy.")
+        end
       else
-        super.prepare_dest()
+        super()
         clone
       end
     end

lib/dependency_wiring/thor_app.rb

 
     desc "show", "prints dependencies mount points"
     def show(file=DEFAULT_CONF)
+      load_config(file).show
+    end
+
+    desc "wire", "update all the dependencies"
+    def wire(file=DEFAULT_CONF)
+      load_config(file).wire_all
+    end
+
+    protected
+    def load_config(file)
       c = Configuration.new(file)
       c.load_dependencies
-      c.show
+      c
     end
   end
 end