Compare commits

..

No commits in common. "afb1bbeb71ad9e85aa2bd40d43bc5d06eb26ae8b" and "ee4ff6c752297e82b272e985b1a37e277e110c46" have entirely different histories.

3 changed files with 32 additions and 77 deletions

View File

@ -15,8 +15,10 @@ impl GitDomain {
};
let mut branches = Vec::with_capacity(16);
// Keep head_name as full ref for comparison with branch names
let head_name = self.repo.head().ok().and_then(|r| r.name().map(String::from));
let head_name = self.repo.head().ok().and_then(|r| {
r.name()
.map(|name| name.strip_prefix("refs/heads/").unwrap_or(name).to_string())
});
for branch_result in self
.repo()
@ -30,7 +32,6 @@ impl GitDomain {
};
let name = name.to_string();
let oid = CommitOid::from_git2(target);
// Compare full ref names (e.g., "refs/heads/main" == "refs/heads/main")
let is_head = head_name.as_ref().map_or(false, |h| h == &name);
let is_current = branch.is_head();
@ -77,28 +78,24 @@ impl GitDomain {
}
pub fn branch_get(&self, name: &str) -> GitResult<BranchInfo> {
// Determine candidates: try full refs as-is, then construct refs/heads/ and refs/remotes/
let candidates: Vec<String> = if name.starts_with("refs/") {
vec![name.to_string()]
// Determine full ref name and branch type
let full_name = if name.starts_with("refs/heads/") {
name.to_string()
} else if name.starts_with("refs/remotes/") {
name.to_string()
} else if name.contains('/') {
// e.g. "origin/main" → remote branch
format!("refs/remotes/{}", name)
} else {
vec![
format!("refs/heads/{}", name),
format!("refs/remotes/{}", name),
]
format!("refs/heads/{}", name)
};
// Try local branch first, then remote
let branch = candidates
.iter()
.find_map(|full_name| {
self.repo
.find_branch(full_name, git2::BranchType::Local)
.ok()
.or_else(|| self.repo.find_branch(full_name, git2::BranchType::Remote).ok())
})
.ok_or_else(|| GitError::RefNotFound(name.to_string()))?;
let branch = self
.repo()
.find_branch(&full_name, git2::BranchType::Local)
.or_else(|_| self.repo.find_branch(&full_name, git2::BranchType::Remote))
.map_err(|_e| GitError::RefNotFound(name.to_string()))?;
let full_name = branch.name().ok().flatten().unwrap_or_default().to_string();
let target = branch
.get()
.target()
@ -128,25 +125,19 @@ impl GitDomain {
}
pub fn branch_exists(&self, name: &str) -> bool {
// Same candidate logic as branch_get
let candidates: Vec<String> = if name.starts_with("refs/") {
vec![name.to_string()]
let full_name = if name.starts_with("refs/heads/") || name.starts_with("refs/remotes/") {
name.to_string()
} else if name.contains('/') {
format!("refs/remotes/{}", name)
} else {
vec![
format!("refs/heads/{}", name),
format!("refs/remotes/{}", name),
]
format!("refs/heads/{}", name)
};
candidates.iter().any(|full_name| {
self.repo
.find_branch(full_name, BranchType::Local)
.is_ok()
self.repo.find_branch(&full_name, BranchType::Local).is_ok()
|| self
.repo()
.find_branch(full_name, BranchType::Remote)
.find_branch(&full_name, BranchType::Remote)
.is_ok()
})
}
pub fn branch_is_head(&self, name: &str) -> GitResult<bool> {

View File

@ -89,24 +89,9 @@ impl HookMetaDataSync {
tagger_email: String::new(),
});
} else if is_branch && !is_remote {
// Try to get upstream branch name from the reference's upstream target
let upstream: Option<String> = if reference.target().is_some() {
if let Ok(branch) = self.domain.repo().find_branch(&name, git2::BranchType::Local) {
if let Ok(upstream_ref) = branch.upstream() {
if let Some(upstream_name) = upstream_ref.name().ok().flatten() {
Some(upstream_name.to_string())
} else {
None
}
} else {
None
}
} else {
None
}
} else {
None
};
let upstream = reference
.shorthand()
.map(|short| format!("refs/remotes/{{}}/{}", short));
branches.push(BranchTip {
name,

View File

@ -1031,15 +1031,6 @@ impl AppService {
) -> Result<Vec<CommitReflogEntryResponse>, AppError> {
let repo = self.utils_find_repo(namespace, repo_name, ctx).await?;
// If refname is None and HEAD is detached, fall back to default_branch
let refname = refname.or_else(|| {
if repo.default_branch.is_empty() {
None
} else {
Some(repo.default_branch.clone())
}
});
let entries = git_spawn!(repo, domain -> {
domain.reflog_entries(refname.as_deref())
})?;
@ -1073,13 +1064,7 @@ impl AppService {
}
let repo = self.utils_find_repo(namespace, repo_name, ctx).await?;
let rev_clone = query.rev.clone().or_else(|| {
if repo.default_branch.is_empty() {
None
} else {
Some(format!("refs/heads/{}", repo.default_branch))
}
});
let rev_clone = query.rev.clone();
let limit = query.limit.unwrap_or(0);
let graph = git_spawn!(repo, domain -> {
@ -1127,13 +1112,7 @@ impl AppService {
}
let repo = self.utils_find_repo(namespace, repo_name, ctx).await?;
let rev_clone = query.rev.clone().or_else(|| {
if repo.default_branch.is_empty() {
None
} else {
Some(format!("refs/heads/{}", repo.default_branch))
}
});
let rev_clone = query.rev.clone();
let limit = query.limit.unwrap_or(0);
let (graph, refs_grouped) = git_spawn!(repo, domain -> {