Sha256: 1114131afbead568d3a4ea15c2bf6d57d60f0b0483d1715fe404db3462d14881

Contents?: true

Size: 1.92 KB

Versions: 7

Compression:

Stored size: 1.92 KB

Contents

require 'date'

module Rudy
  module SCM
    class SVN
      attr_accessor :base_uri
      
      def initialize(args={:base => ''})
        @base_uri = args[:base]
      end
      
      def create_release(username=nil, msg=nil)
        local_uri, local_revision = local_info
        rtag = find_next_rtag(username)
        release_uri = "#{@base_uri}/#{rtag}"
        msg ||= 'Another Release by Rudy!'
        msg.tr!("'", "\\'")
        cmd = "svn copy -m '#{msg}' #{local_uri} #{release_uri}"
        
        `#{cmd} 2>&1`
        
        release_uri
      end
      
      def switch_working_copy(tag)
        raise "Invalid release tag (#{tag})." unless valid_rtag?(tag)
        `svn switch #{tag}`
      end
      
      # rel-2009-03-05-user-rev
      def find_next_rtag(username=nil)
        now = Time.now
        mon = now.mon.to_s.rjust(2, '0')
        day = now.day.to_s.rjust(2, '0')
        rev = "01"
        criteria = ['rel', now.year, mon, day, rev]
        criteria.insert(-2, username) if username
        tag = criteria.join(Rudy::DELIM)
        # Keep incrementing the revision number until we find the next one.
        tag.succ! while (valid_rtag?("#{@base_uri}/#{tag}"))
        tag
      end
      
      def local_info
        ret = `svn info 2>&1`
        # URL: http://some/uri/path
        # Repository Root: http://some/uri
        # Repository UUID: c5abe49d-53e4-4ea3-9314-89e1e25aa7e1
        # Revision: 921
        ret.scan(/URL: (http:.+?)\s*\n.+Revision: (\d+)/m).flatten
      end
      
      def working_copy?(path)
        (File.exists?(File.join(path, '.svn')))
      end
      
      def valid_rtag?(uri)
        ret = `svn info #{uri} 2>&1` || '' # Valid SVN URIs will return some info
        (ret =~ /Repository UUID/) ? true : false
      end
      
      # Are all local changes committed?
      def clean_working_copy?
        `svn diff . 2>&1` == '' # svn diff should return nothing
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
solutious-rudy-0.7.0 lib/rudy/scm/svn.rb
solutious-rudy-0.7.1 lib/rudy/scm/svn.rb
solutious-rudy-0.7.2 lib/rudy/scm/svn.rb
solutious-rudy-0.7.3 lib/rudy/scm/svn.rb
rudy-0.7.0 lib/rudy/scm/svn.rb
rudy-0.7.1 lib/rudy/scm/svn.rb
rudy-0.7.3 lib/rudy/scm/svn.rb