Class: SvnAuto::Bug

Inherits:
Command show all
Defined in:
lib/svnauto/commands/bug.rb

Constant Summary collapse

REL_BRN_PROP =
'sc:bug-fix-release-branch'

Constants inherited from Command

Command::VALID_SET_KEYS

Instance Method Summary collapse

Methods inherited from Command

commands, force?, inherited, options, reset!

Instance Method Details

#close_bugObject



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/svnauto/commands/bug.rb', line 116

def close_bug
  unless Svn.has_path(@project.branches("bug/#@bug_id"))
    raise "there isn't a bug fix branch for bug #@bug_id"
  end

  if Svn.has_path(@project.tags("bug/POST-#@bug_id"))
     Constants::TERMINAL.say("bug #{Constants::TERMINAL.color(@bug_id, :red)} " +
       "already closed and merged to release branch, skipping...")
  else
    # Figure out which release branch to merge to
    version = ''
    Svn.propget(REL_BRN_PROP, @project.branches("bug/#@bug_id")) do |line|
      version << line.chomp
    end

    version.strip!
    if version.empty?
      raise "Woah! missing #{REL_BRN_PROP} prop on #{@project.branches("bug/#@bug_id")}"
    end

    version = Version.new(version)

    unless opthash[:force]
      exit unless Constants::TERMINAL.agree("Merge bug fix branch for bug " +
       Constants::TERMINAL.color(@bug_id, :red) + " to release " +
       Constants::TERMINAL.color(@project.to_s, :green) + "/" +
       Constants::TERMINAL.color(version.to_s, :red) + "? ")
    end

    # tag the end of the branch
    Svn.branch(@project, @project.branches("bug/#@bug_id"), @project.tags("bug/POST-#@bug_id"))

    # merge bug fix changes to the release branch
    @project.merge(version, "bug/PRE-#@bug_id", "bug/POST-#@bug_id") do
      "then commit your changes, and run this tool again to merge to trunk"
    end
  end

  # merge bug fix changes to the trunk
  if opthash[:no_trunk].nil?
    question = "Merge bug fix branch for bug "
    question << Constants::TERMINAL.color(@bug_id, :red) + " to "
    question << Constants::TERMINAL.color(@project.to_s, :green)
    question << "/trunk? "

    if opthash[:force] or Constants::TERMINAL.agree(question)
      @project.merge(nil, "bug/PRE-#@bug_id", "bug/POST-#@bug_id") do
        "then commit your changes to finish the merge to the trunk"
      end
    end
  end
end

#create_bug_fix_branchObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/svnauto/commands/bug.rb', line 82

def create_bug_fix_branch
  if @version.nil?
    raise "there are no release branches for the #{@project} project"
  end

  unless Svn.has_path(@project.release(@version))
    raise "there is no release branch for version #@version"
  end

  unless opthash[:force]
    exit unless Constants::TERMINAL.agree("Create bug fix branch for bug " +
     Constants::TERMINAL.color(@bug_id, :red) + " off release " +
     Constants::TERMINAL.color(@project.to_s, :green) + "/" +
     Constants::TERMINAL.color(@version.to_s, :red) + "? ")
  end

  # create the bug fix branch
  Svn.branch(@project, @project.release(@version), @project.branches("bug/#@bug_id"))

  # tag the start of the branch for merging later
  Svn.branch(@project, @project.branches("bug/#@bug_id"), @project.tags("bug/PRE-#@bug_id"))

  # check it out so that we can do the next step
  dir = @project.checkout(@project.branches("bug/#@bug_id"))

  # record the release branch so we can get back to it later
  Svn.propset(REL_BRN_PROP, @version.to_s, dir) {|line|}
  Svn.commit('-m', "#{Constants::ME}: recording release branch for bug fix #@bug_id", dir)

  Constants::TERMINAL.say("Created bug fix branch and checked out to: " + 
    Constants::TERMINAL.color(Path.relative_to_home(dir), :green))
end

#run(project, args) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/svnauto/commands/bug.rb', line 58

def run (project, args)
  @project = project
  @bug_id = args.first

  unless @bug_id.match(/^\d+/)
    raise "bug id should be an integer: #{@bug_id}"
  end

  if opthash[:diff]
    show_diff
    return
  end

  @version = 
    if opthash[:release]
      Version.new(opthash[:release])
    else
      project.latest_release_branch
    end

  opthash[:close] ? close_bug : create_bug_fix_branch
end

#show_diffObject



170
171
172
# File 'lib/svnauto/commands/bug.rb', line 170

def show_diff
  Svn.diff(@project.tags("bug/PRE-#@bug_id"), @project.tags("bug/POST-#@bug_id"))
end