don't fail if a ref can't be peeled (#3129)

Sometimes, symbolic refs are used as tracking branches, like
`refs/remotes/origin/HEAD`, and after some changes are dangling,
pointing to a ref which doesn't exist anymore (maybe it was renamed
from `master` to `main`).

Now, this isn't fatal anymore, but will be logged instead.
This commit is contained in:
Sebastian Thiel 2024-04-23 09:44:50 +02:00 committed by Kiril Videlov
parent b70a2eef6f
commit 5ea4bb3c58
2 changed files with 13 additions and 1 deletions

View File

@ -64,6 +64,8 @@ impl FromStr for Refname {
return Err(Error::NotRemote(value.to_string()));
};
// TODO(ST): use `gix` (which respects refspecs and settings) to do this transformation
// Alternatively, `git2` also has support for respecting refspecs.
let value = value.strip_prefix("refs/remotes/").unwrap();
if let Some((remote, branch)) = value.split_once('/') {

View File

@ -111,7 +111,17 @@ pub fn get_branch_data(
}
pub fn branch_to_remote_branch(branch: &git::Branch) -> Result<Option<RemoteBranch>> {
let commit = branch.peel_to_commit()?;
let commit = match branch.peel_to_commit() {
Ok(c) => c,
Err(err) => {
tracing::warn!(
?err,
"ignoring branch {:?} as peeling failed",
branch.name()
);
return Ok(None);
}
};
branch
.target()
.map(|sha| {