Class: SvnHelper
- Inherits:
-
Object
- Object
- SvnHelper
- Defined in:
- lib/svn_helper.rb
Constant Summary collapse
- TRUNK_REGEXP =
matches a trunk checkout
/\/trunk$/
- BRANCH_REGEXP =
matches a branch checkout
/\/branches\/\S+$/
- RELEASE_BRANCH_REGEXP =
matches release branch names
/^RB-([0-9.]+)/
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #base_url ⇒ Object
-
#branch? ⇒ Boolean
Is the current directory a branch checkout?.
- #branch_url(branch) ⇒ Object
- #branches ⇒ Object
- #head_revision ⇒ Object
-
#initialize ⇒ SvnHelper
constructor
A new instance of SvnHelper.
- #latest_release_branch ⇒ Object
- #latest_release_branch_url ⇒ Object
-
#trunk? ⇒ Boolean
Is the current directory a trunk checkout?.
- #trunk_url ⇒ Object
- #valid_branch?(branch) ⇒ Boolean
Constructor Details
#initialize ⇒ SvnHelper
Returns a new instance of SvnHelper.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/svn_helper.rb', line 14 def initialize begin @svn_path = `which svn` raise SvnNotFound, "svn not found in path" if @svn_path.empty? svn_info = `svn info` raise PwdNotSvn, "Current directory does not appear to be under SVN" unless $? == 0 svn_info.detect{|line| line =~ /^URL: (.*)$/} @url = $1 # The current url raise UnrecognizedSvnUrl, "SVN url is neither trunk nor a branch: #{@url}" unless trunk? || branch? end end |
Instance Attribute Details
#url ⇒ Object (readonly)
Returns the value of attribute url.
12 13 14 |
# File 'lib/svn_helper.rb', line 12 def url @url end |
Instance Method Details
#base_url ⇒ Object
36 37 38 |
# File 'lib/svn_helper.rb', line 36 def base_url @base_url ||= @url.gsub(trunk? ? TRUNK_REGEXP : BRANCH_REGEXP, '') end |
#branch? ⇒ Boolean
Is the current directory a branch checkout?
32 33 34 |
# File 'lib/svn_helper.rb', line 32 def branch? @url =~ BRANCH_REGEXP end |
#branch_url(branch) ⇒ Object
64 65 66 |
# File 'lib/svn_helper.rb', line 64 def branch_url(branch) "#{base_url}/branches/#{branch}" end |
#branches ⇒ Object
40 41 42 |
# File 'lib/svn_helper.rb', line 40 def branches @branches ||= `svn ls #{base_url}/branches`.split("\n").map{|name| name.sub(/\/$/, '')} end |
#head_revision ⇒ Object
56 57 58 59 |
# File 'lib/svn_helper.rb', line 56 def head_revision # TODO: there must be a better way to compute this @head_revision ||= `svn log --limit 1 -q`.split[1].sub(/^r/, '') end |
#latest_release_branch ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/svn_helper.rb', line 48 def latest_release_branch begin @latest_release ||= branches.inject(Revision.new('0')){|rev, branch| branch =~ RELEASE_BRANCH_REGEXP ? [rev, Revision.new($1)].max : rev} raise LatestReleaseBranchNotFound, "could not find a latest release branch\ntry specifying a source with '-b BRANCH' instead" if @latest_release == Revision.new('0') @latest_release_branch ||= "RB-#{@latest_release}" end end |
#latest_release_branch_url ⇒ Object
68 69 70 |
# File 'lib/svn_helper.rb', line 68 def latest_release_branch_url branch_url(latest_release_branch) end |
#trunk? ⇒ Boolean
Is the current directory a trunk checkout?
27 28 29 |
# File 'lib/svn_helper.rb', line 27 def trunk? @url =~ TRUNK_REGEXP end |
#trunk_url ⇒ Object
60 61 62 |
# File 'lib/svn_helper.rb', line 60 def trunk_url "#{base_url}/trunk" end |
#valid_branch?(branch) ⇒ Boolean
44 45 46 |
# File 'lib/svn_helper.rb', line 44 def valid_branch?(branch) branches.include? branch end |