Compare commits
No commits in common. "afb1bbeb71ad9e85aa2bd40d43bc5d06eb26ae8b" and "ee4ff6c752297e82b272e985b1a37e277e110c46" have entirely different histories.
afb1bbeb71
...
ee4ff6c752
@ -15,8 +15,10 @@ impl GitDomain {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let mut branches = Vec::with_capacity(16);
|
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| {
|
||||||
let head_name = self.repo.head().ok().and_then(|r| r.name().map(String::from));
|
r.name()
|
||||||
|
.map(|name| name.strip_prefix("refs/heads/").unwrap_or(name).to_string())
|
||||||
|
});
|
||||||
|
|
||||||
for branch_result in self
|
for branch_result in self
|
||||||
.repo()
|
.repo()
|
||||||
@ -30,7 +32,6 @@ impl GitDomain {
|
|||||||
};
|
};
|
||||||
let name = name.to_string();
|
let name = name.to_string();
|
||||||
let oid = CommitOid::from_git2(target);
|
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_head = head_name.as_ref().map_or(false, |h| h == &name);
|
||||||
let is_current = branch.is_head();
|
let is_current = branch.is_head();
|
||||||
|
|
||||||
@ -77,28 +78,24 @@ impl GitDomain {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn branch_get(&self, name: &str) -> GitResult<BranchInfo> {
|
pub fn branch_get(&self, name: &str) -> GitResult<BranchInfo> {
|
||||||
// Determine candidates: try full refs as-is, then construct refs/heads/ and refs/remotes/
|
// Determine full ref name and branch type
|
||||||
let candidates: Vec<String> = if name.starts_with("refs/") {
|
let full_name = if name.starts_with("refs/heads/") {
|
||||||
vec![name.to_string()]
|
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 {
|
} else {
|
||||||
vec![
|
format!("refs/heads/{}", name)
|
||||||
format!("refs/heads/{}", name),
|
|
||||||
format!("refs/remotes/{}", name),
|
|
||||||
]
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Try local branch first, then remote
|
let branch = self
|
||||||
let branch = candidates
|
.repo()
|
||||||
.iter()
|
.find_branch(&full_name, git2::BranchType::Local)
|
||||||
.find_map(|full_name| {
|
.or_else(|_| self.repo.find_branch(&full_name, git2::BranchType::Remote))
|
||||||
self.repo
|
.map_err(|_e| GitError::RefNotFound(name.to_string()))?;
|
||||||
.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 full_name = branch.name().ok().flatten().unwrap_or_default().to_string();
|
|
||||||
let target = branch
|
let target = branch
|
||||||
.get()
|
.get()
|
||||||
.target()
|
.target()
|
||||||
@ -128,25 +125,19 @@ impl GitDomain {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn branch_exists(&self, name: &str) -> bool {
|
pub fn branch_exists(&self, name: &str) -> bool {
|
||||||
// Same candidate logic as branch_get
|
let full_name = if name.starts_with("refs/heads/") || name.starts_with("refs/remotes/") {
|
||||||
let candidates: Vec<String> = if name.starts_with("refs/") {
|
name.to_string()
|
||||||
vec![name.to_string()]
|
} else if name.contains('/') {
|
||||||
|
format!("refs/remotes/{}", name)
|
||||||
} else {
|
} else {
|
||||||
vec![
|
format!("refs/heads/{}", name)
|
||||||
format!("refs/heads/{}", name),
|
|
||||||
format!("refs/remotes/{}", name),
|
|
||||||
]
|
|
||||||
};
|
};
|
||||||
|
|
||||||
candidates.iter().any(|full_name| {
|
self.repo.find_branch(&full_name, BranchType::Local).is_ok()
|
||||||
self.repo
|
|| self
|
||||||
.find_branch(full_name, BranchType::Local)
|
.repo()
|
||||||
|
.find_branch(&full_name, BranchType::Remote)
|
||||||
.is_ok()
|
.is_ok()
|
||||||
|| self
|
|
||||||
.repo()
|
|
||||||
.find_branch(full_name, BranchType::Remote)
|
|
||||||
.is_ok()
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn branch_is_head(&self, name: &str) -> GitResult<bool> {
|
pub fn branch_is_head(&self, name: &str) -> GitResult<bool> {
|
||||||
|
|||||||
@ -89,24 +89,9 @@ impl HookMetaDataSync {
|
|||||||
tagger_email: String::new(),
|
tagger_email: String::new(),
|
||||||
});
|
});
|
||||||
} else if is_branch && !is_remote {
|
} else if is_branch && !is_remote {
|
||||||
// Try to get upstream branch name from the reference's upstream target
|
let upstream = reference
|
||||||
let upstream: Option<String> = if reference.target().is_some() {
|
.shorthand()
|
||||||
if let Ok(branch) = self.domain.repo().find_branch(&name, git2::BranchType::Local) {
|
.map(|short| format!("refs/remotes/{{}}/{}", short));
|
||||||
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
|
|
||||||
};
|
|
||||||
|
|
||||||
branches.push(BranchTip {
|
branches.push(BranchTip {
|
||||||
name,
|
name,
|
||||||
|
|||||||
@ -1031,15 +1031,6 @@ impl AppService {
|
|||||||
) -> Result<Vec<CommitReflogEntryResponse>, AppError> {
|
) -> Result<Vec<CommitReflogEntryResponse>, AppError> {
|
||||||
let repo = self.utils_find_repo(namespace, repo_name, ctx).await?;
|
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 -> {
|
let entries = git_spawn!(repo, domain -> {
|
||||||
domain.reflog_entries(refname.as_deref())
|
domain.reflog_entries(refname.as_deref())
|
||||||
})?;
|
})?;
|
||||||
@ -1073,13 +1064,7 @@ impl AppService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let repo = self.utils_find_repo(namespace, repo_name, ctx).await?;
|
let repo = self.utils_find_repo(namespace, repo_name, ctx).await?;
|
||||||
let rev_clone = query.rev.clone().or_else(|| {
|
let rev_clone = query.rev.clone();
|
||||||
if repo.default_branch.is_empty() {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(format!("refs/heads/{}", repo.default_branch))
|
|
||||||
}
|
|
||||||
});
|
|
||||||
let limit = query.limit.unwrap_or(0);
|
let limit = query.limit.unwrap_or(0);
|
||||||
|
|
||||||
let graph = git_spawn!(repo, domain -> {
|
let graph = git_spawn!(repo, domain -> {
|
||||||
@ -1127,13 +1112,7 @@ impl AppService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let repo = self.utils_find_repo(namespace, repo_name, ctx).await?;
|
let repo = self.utils_find_repo(namespace, repo_name, ctx).await?;
|
||||||
let rev_clone = query.rev.clone().or_else(|| {
|
let rev_clone = query.rev.clone();
|
||||||
if repo.default_branch.is_empty() {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(format!("refs/heads/{}", repo.default_branch))
|
|
||||||
}
|
|
||||||
});
|
|
||||||
let limit = query.limit.unwrap_or(0);
|
let limit = query.limit.unwrap_or(0);
|
||||||
|
|
||||||
let (graph, refs_grouped) = git_spawn!(repo, domain -> {
|
let (graph, refs_grouped) = git_spawn!(repo, domain -> {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user