The local branch `git branch -m` renamed `old_ref` to, found through the `renamed to ` reflog entry Git writes on the new branch, or `None` when no branch carries such a trail (the ref was deleted).
(git: &GitRepository, old_ref: &str)
| 373 | /// `renamed <old> to <new>` reflog entry Git writes on the new branch, or |
| 374 | /// `None` when no branch carries such a trail (the ref was deleted). |
| 375 | fn renamed_branch_target(git: &GitRepository, old_ref: &str) -> Option<String> { |
| 376 | let needle = format!("renamed {old_ref} to "); |
| 377 | let branches = git.branches(Some(git2::BranchType::Local)).ok()?; |
| 378 | for (branch, _) in branches.flatten() { |
| 379 | let Ok(name) = branch.get().name() else { |
| 380 | continue; |
| 381 | }; |
| 382 | let Ok(reflog) = git.reflog(name) else { |
| 383 | continue; |
| 384 | }; |
| 385 | if reflog.iter().any(|entry| { |
| 386 | entry |
| 387 | .message() |
| 388 | .is_ok_and(|message| message.is_some_and(|text| text.contains(&needle))) |
| 389 | }) { |
| 390 | return Some(name.to_string()); |
| 391 | } |
| 392 | } |
| 393 | None |
| 394 | } |
| 395 | |
| 396 | /// Persist the `Diverged` status without moving either side (RFC §8.5). |
| 397 | pub(crate) fn persist_diverged_status( |