Class: SvnAuto::Experimental

Inherits:
Command
  • Object
show all
Defined in:
lib/svnauto/commands/experimental.rb

Constant Summary

Constants inherited from Command

Command::VALID_SET_KEYS

Instance Method Summary collapse

Methods inherited from Command

commands, force?, inherited, options, reset!

Instance Method Details

#create_experimental_branchObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/svnauto/commands/experimental.rb', line 91

def create_experimental_branch
  raise "branch #@path already exists" if @has_path

  unless opthash[:force]
    name = @branch_name
    name = @path if @prefix != 'exp'

    question = "Create experimental branch "
    question << Constants::TERMINAL.color(name, :green) + " off "
    question << Constants::TERMINAL.color(@project.to_s, :green) + "/trunk"
    question << Constants::TERMINAL.color(":#{opthash[:revision]}", :red) if opthash[:revision]
    question << "? "

    exit unless Constants::TERMINAL.agree(question)
  end

  branch_options = {}
  branch_options[:revision] = opthash[:revision] if opthash[:revision]

  Svn.branch(@project, @project.trunk, @project.branches(@path), branch_options)
  Svn.branch(@project, @project.branches(@path), @project.tags("#{@prefix}/PRE-#{@branch_name}"))

  unless opthash[:no_checkout]
    Constants::TERMINAL.say("Checked out: " + 
      Constants::TERMINAL.color(Path.relative_to_home(@project.checkout(@project.branches(@path))), :green))
  end
end

#latest_merge(prefix) ⇒ Object



139
140
141
142
143
144
145
146
147
148
149
# File 'lib/svnauto/commands/experimental.rb', line 139

def latest_merge (prefix)
  merges = []

  Svn.list(@project.tags(@prefix)) do |line|
    if m = line.match(/^#{prefix}(\d+)-#{@branch_name}\/?$/)
      merges << m[1].to_i
    end
  end

  merges.sort.last
end

#merge(direction, merge_to, end_tag) ⇒ Object



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/svnauto/commands/experimental.rb', line 120

def merge (direction, merge_to, end_tag)
  raise "there is no experimental branch with the name #{@branch_name}" unless @has_path

  last_merge_number = latest_merge(direction)
  start = last_merge_number ? "#{direction}#{last_merge_number}" : "PRE"
  next_merge_number = last_merge_number ? last_merge_number+1 : 1

  start_tag = "#{@prefix}/#{start}-#{@branch_name}"

  # tag the current merge point for our next merge
  Svn.branch(@project, end_tag, @project.tags("#{@prefix}/#{direction}#{next_merge_number}-#{@branch_name}"))

  # merge the trunk to the branch
  @project.merge(merge_to, start_tag, end_tag) do
    "then commit your changes to finish the #{direction} merge"
  end
end

#run(project, args) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/svnauto/commands/experimental.rb', line 59

def run (project, args)
  if opthash[:up] and opthash[:down]
    raise "you can only use one of --up or --down"
  end

  @branch_name = Project.clean_name(args.first)

  unless opthash[:force]
    if @branch_name != args.first and !Constants::TERMINAL.agree("Is #{@branch_name} OK for the branch name? ")
      raise "please pick a branch name that doesn't include any special characters"
    end
  end

  if @branch_name != args.first
    Constants::TERMINAL.say("using #{Constants::TERMINAL.color(@branch_name, :green)} as the branch name")
  end

  @project = project
  @prefix = opthash[:prefix] || 'exp'
  @path = "#{@prefix}/#{@branch_name}"
  @has_path = Svn.has_path(@project.branches(@path))

  if opthash[:up]
    merge('UP', @project.branches(@path), @project.trunk)
  elsif opthash[:down]
    merge('DOWN', @project.trunk, @project.branches(@path))
  else
    create_experimental_branch
  end
end