diff --git a/giterated-daemon/src/backend/git.rs b/giterated-daemon/src/backend/git.rs index 9620cf6..b5ff7c8 100644 --- a/giterated-daemon/src/backend/git.rs +++ b/giterated-daemon/src/backend/git.rs @@ -2,6 +2,7 @@ use anyhow::Error; use async_trait::async_trait; use futures_util::StreamExt; +use git2::BranchType; use giterated_models::instance::{Instance, RepositoryCreateRequest}; use giterated_models::repository::{ @@ -572,10 +573,17 @@ impl RepositoryBackend for GitBackend { } }; - // If the reference wasn't found, try parsing it as a commit ID and otherwise return error + // If the reference wasn't found, try parsing it as a commit ID if tree_id.is_none() { - match git2::Oid::from_str(request.rev.as_ref().unwrap()) { - Ok(oid) => tree_id = Some(oid), + if let Ok(oid) = git2::Oid::from_str(request.rev.as_ref().unwrap()) { + tree_id = Some(oid) + } + } + + // If the commit ID wasn't found, try parsing it as a branch and otherwise return error + if tree_id.is_none() { + match git.find_branch(request.rev.as_ref().unwrap(), BranchType::Local) { + Ok(branch) => tree_id = branch.get().target(), Err(_) => { return Err(Box::new(GitBackendError::RefNotFound( request.rev.clone().unwrap(),