Class: Submerge
- Inherits:
-
Object
- Object
- Submerge
- Defined in:
- lib/submerge.rb
Constant Summary collapse
- VERSION =
'0.1'
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #compute_source_url ⇒ Object
-
#initialize(args) ⇒ Submerge
constructor
A new instance of Submerge.
-
#parse_changesets ⇒ Object
Convert all changesets to ranges by merging from prevision changeset.
- #run ⇒ Object
- #source_url ⇒ Object
Constructor Details
#initialize(args) ⇒ Submerge
Returns a new instance of Submerge.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/submerge.rb', line 25 def initialize(args) # Set default options @options = OpenStruct.new @options.quiet = false @options.verbose = false # Parse options opts = OptionParser.new opts.on('-v', '--version') { output_version; exit 0 } opts.on('-h', '--help', '-?') { output_help; exit 0 } opts.on('-V', '--verbose') { @options.verbose = true } opts.on('-q', '--quiet') { @options.quiet = true } opts.on('-u', '--undo') { @options.undo = true} opts.on("-b", "--branch BRANCH", "merge from branch BRANCH") {|branch| @branch = branch} opts.parse!(args) begin @svn = SvnHelper.new rescue => e puts e. exit 1 end @changesets = opts.default_argv if @changesets.empty? puts "No changesets specified, using HEAD" if @options.verbose @changesets << 'HEAD' end end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
23 24 25 |
# File 'lib/submerge.rb', line 23 def @options end |
Instance Method Details
#compute_source_url ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/submerge.rb', line 69 def compute_source_url # Compute the source_url from which to merge if @branch unless @svn.valid_branch?(@branch) puts "Invalid branch #{@branch}" exit 1 end url = @svn.branch_url(@branch) else url = @svn.trunk? ? @svn.latest_release_branch_url : @svn.trunk_url end puts "Merging from #{url}" unless @options.quiet url end |
#parse_changesets ⇒ Object
Convert all changesets to ranges by merging from prevision changeset. E.g., “5” => “4:5”; “5:” => “5:HEAD”
88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/submerge.rb', line 88 def parse_changesets @changesets.map! do |changeset| if changeset.include?(':') # Changeset range s,e = changeset.split(':') [s,e].each{|rev| rev = (rev.to_i == 0) ? @svn.head_revision : rev} "#{s}:#{e}" else # Single changeset rev = (changeset.to_i == 0) ? @svn.head_revision.to_i : changeset.to_i @options.undo ? "#{rev}:#{rev-1}" : "#{rev-1}:#{rev}" end end end |
#run ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/submerge.rb', line 55 def run parse_changesets @changesets.each do |changeset| cmd = "svn merge -r#{changeset} #{source_url}" puts cmd unless @options.quiet system(cmd) end end |
#source_url ⇒ Object
65 66 67 |
# File 'lib/submerge.rb', line 65 def source_url @source_url ||= compute_source_url end |