Class: BetweenMeals::Repo::Svn

Inherits:
BetweenMeals::Repo show all
Defined in:
lib/between_meals/repo/svn.rb

Overview

SVN implementation

Instance Attribute Summary

Attributes inherited from BetweenMeals::Repo

#bin, #repo_path

Instance Method Summary collapse

Methods inherited from BetweenMeals::Repo

#create, get, #head, #head_msg, #head_msg=, #head_parents, #initialize, #last_author, #last_msg, #last_msg=, #status

Constructor Details

This class inherits a constructor from BetweenMeals::Repo

Instance Method Details

#changes(start_ref, end_ref) ⇒ Object

Return files changed between two revisions



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/between_meals/repo/svn.rb', line 60

def changes(start_ref, end_ref)
  check_refs(start_ref, end_ref)
  s = Mixlib::ShellOut.new(
    "#{@bin} diff -r #{start_ref}:#{end_ref} --summarize #{@repo_path}")
  s.run_command.error!
  @logger.info("Diff between #{start_ref} and #{end_ref}")
  s.stdout.lines.map do |line|
    m = line.match(/^(\w)\w?\s+(\S+)$/)
    fail "Could not parse line: #{line}" unless m

    {
      :status => m[1] == 'D' ? :deleted : :modified,
      :path => m[2].sub("#{@repo_path}/", '')
    }
  end
end

#checkout(url) ⇒ Object



53
54
55
56
57
# File 'lib/between_meals/repo/svn.rb', line 53

def checkout(url)
  s = Mixlib::ShellOut.new(
    "#{@bin} co --ignore-externals #{url} #{@repo_path}").run_command
  s.error!
end

#exists?Boolean

Returns:

  • (Boolean)


30
31
32
33
# File 'lib/between_meals/repo/svn.rb', line 30

def exists?
  # this shuold be better
  Dir.exists?(@repo_path)
end

#filesObject

Return all files



84
85
86
87
88
89
90
91
# File 'lib/between_meals/repo/svn.rb', line 84

def files
  s = Mixlib::ShellOut.new("#{@bin} ls --depth infinity #{@repo_path}")
  s.run_command
  s.error!
  s.stdout.split("\n").map do |x|
    { :path => x, :status => :created }
  end
end

#head_revObject



35
36
37
38
39
40
41
42
# File 'lib/between_meals/repo/svn.rb', line 35

def head_rev
  s = Mixlib::ShellOut.new("#{@bin} info #{@repo_path}").run_command
  s.error!
  s.stdout.each_line do |line|
    m = line.match(/Last Changed Rev: (\d+)$/)
    return m[1] if m
  end
end

#latest_revisionObject



44
45
46
47
48
49
50
51
# File 'lib/between_meals/repo/svn.rb', line 44

def latest_revision
  s = Mixlib::ShellOut.new("#{@bin} info #{@repo_path}").run_command
  s.error!
  s.stdout.each do |line|
    m = line.match(/Revision: (\d+)$/)
    return m[1] if m
  end
end

#setupObject



26
27
28
# File 'lib/between_meals/repo/svn.rb', line 26

def setup
  @bin = 'svn'
end

#updateObject



77
78
79
80
81
# File 'lib/between_meals/repo/svn.rb', line 77

def update
  cleanup
  revert
  up
end