MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / renamed_branch_target

Function renamed_branch_target

atomic-cli/src/commands/git/ref_mapping.rs:375–394  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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).
375fn 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).
397pub(crate) fn persist_diverged_status(

Callers 1

Calls 6

getMethod · 0.65
okMethod · 0.45
nameMethod · 0.45
iterMethod · 0.45
messageMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected