|
277 | 277 |
|
278 | 278 | # Parse the provided version into an AppVersion object |
279 | 279 | parsed_version = VERSION_FORMATTER.parse(new_version) |
| 280 | + # Validate that this is a hotfix version (must have a patch component > 0) |
| 281 | + UI.user_error!("Invalid hotfix version '#{new_version}'. Must include a patch number.") unless parsed_version.patch.to_i.positive? |
280 | 282 | previous_version = VERSION_FORMATTER.release_version(VERSION_CALCULATOR.previous_patch_version(version: parsed_version)) |
| 283 | + previous_release_branch = compute_release_branch_name(options: options, version: previous_version) |
| 284 | + |
| 285 | + # Determine the base for the hotfix branch: either a tag or a release branch |
| 286 | + base_ref_for_hotfix = if git_tag_exists(tag: previous_version, remote: true) |
| 287 | + previous_version |
| 288 | + elsif Fastlane::Helper::GitHelper.branch_exists_on_remote?(branch_name: previous_release_branch) |
| 289 | + UI.message("ℹ️ Tag '#{previous_version}' not found on the remote. Using release branch '#{previous_release_branch}' as the base for hotfix instead.") |
| 290 | + previous_release_branch |
| 291 | + else |
| 292 | + UI.user_error!("Neither tag '#{previous_version}' nor branch '#{previous_release_branch}' exists on the remote! A hotfix branch cannot be created.") |
| 293 | + end |
281 | 294 |
|
282 | 295 | # Check versions |
283 | 296 | message = <<~MESSAGE |
|
286 | 299 | • Current release version and build code: #{release_version_current} (#{build_code_current}). |
287 | 300 | • New release version and build code: #{new_version} (#{build_code_hotfix}). |
288 | 301 |
|
289 | | - Branching from tag: #{previous_version} |
| 302 | + Branching from #{base_ref_for_hotfix} |
290 | 303 | MESSAGE |
291 | 304 |
|
292 | 305 | UI.important(message) |
293 | 306 | UI.user_error!('Aborted by user request') unless options[:skip_confirm] || UI.confirm('Do you want to continue?') |
294 | 307 |
|
295 | 308 | # Check tags |
296 | | - UI.user_error!("Version #{new_version} already exists! Abort!") if git_tag_exists(tag: new_version) |
297 | | - UI.user_error!("Version #{previous_version} is not tagged! A hotfix branch cannot be created.") unless git_tag_exists(tag: previous_version) |
| 309 | + UI.user_error!("Version '#{new_version}' already exists on the remote! Abort!") if git_tag_exists(tag: new_version, remote: true) |
| 310 | + |
| 311 | + # Fetch the base ref to ensure it's available locally |
| 312 | + sh('git', 'fetch', 'origin', base_ref_for_hotfix) |
| 313 | + |
| 314 | + hotfix_branch = compute_release_branch_name(options: options, version: new_version) |
| 315 | + ensure_branch_does_not_exist!(hotfix_branch) |
298 | 316 |
|
299 | 317 | # Create the hotfix branch |
300 | | - UI.message 'Creating hotfix branch...' |
301 | | - Fastlane::Helper::GitHelper.create_branch(compute_release_branch_name(options: options, version: new_version), from: previous_version) |
302 | | - UI.success "Done! New hotfix branch is: #{git_branch}" |
| 318 | + UI.message("Creating hotfix branch from '#{base_ref_for_hotfix}'...") |
| 319 | + Fastlane::Helper::GitHelper.create_branch(hotfix_branch, from: base_ref_for_hotfix) |
| 320 | + UI.success("Done! New hotfix branch is: '#{git_branch}'") |
303 | 321 |
|
304 | 322 | # Bump the hotfix version and build code and write it to the `xcconfig` file |
305 | | - UI.message 'Bumping hotfix version and build code...' |
| 323 | + UI.message('Bumping hotfix version and build code...') |
306 | 324 | PUBLIC_VERSION_FILE.write( |
307 | 325 | version_short: new_version, |
308 | 326 | version_long: build_code_hotfix |
309 | 327 | ) |
310 | | - UI.success "Done! New Release Version: #{release_version_current}. New Build Code: #{build_code_current}" |
| 328 | + UI.success("Done! New Release Version: '#{release_version_current}'. New Build Code: '#{build_code_current}'") |
311 | 329 |
|
312 | 330 | commit_version_and_build_files |
313 | 331 |
|
|
0 commit comments