Sha256: 120529d23e9c29fce458253705098a1a64269f2dfcc0f7ce2091bcf63383ee1a

Contents?: true

Size: 1.48 KB

Versions: 7

Compression:

Stored size: 1.48 KB

Contents

require 'r10k/util/subprocess'

module R10K
  module SVN
    class WorkingDir

      # @param full_path [Pathname]
      def initialize(full_path)
        @full_path = full_path
      end

      def is_svn?
        dot_svn = @full_path + '.svn'
        dot_svn.exist?
      end

      def revision
        info.slice(/^Revision: (\d+)$/, 1)
      end

      def url
        info.slice(/^URL: (.*)$/, 1)
      end

      def root
        info.slice(/^Repository Root: (.*)$/, 1)
      end

      def update(revision = nil)
        argv = %w[update]
        argv << '-r' << revision if revision

        svn argv, :cwd => @full_path
      end

      def checkout(url, revision = nil)
        argv = ['checkout', url]
        argv << '-r' << revision if revision
        argv << @full_path.basename.to_s

        svn argv, :cwd => @full_path.parent
      end

      private

      def info
        svn ["info"], :cwd => @full_path
      end

      include R10K::Logging

      # Wrap SVN commands
      #
      # @param argv [Array<String>]
      # @param opts [Hash]
      #
      # @option opts [Pathname] :cwd The directory to run the command in
      #
      # @return [String] The stdout from the given command
      def svn(argv, opts = {})
        argv.unshift('svn')

        subproc = R10K::Util::Subprocess.new(argv)
        subproc.raise_on_fail = true
        subproc.logger = self.logger

        subproc.cwd = opts[:cwd]
        result = subproc.execute

        result.stdout
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
r10k-1.3.5 lib/r10k/svn/working_dir.rb
r10k-1.3.4 lib/r10k/svn/working_dir.rb
r10k-1.3.3 lib/r10k/svn/working_dir.rb
r10k-1.3.2 lib/r10k/svn/working_dir.rb
r10k-1.3.1 lib/r10k/svn/working_dir.rb
r10k-1.3.0 lib/r10k/svn/working_dir.rb
r10k-1.3.0rc1 lib/r10k/svn/working_dir.rb