feat(core): implement Git repository operations with gRPC services
- Add advertise_refs functionality for Git protocol communication - Implement archive service with TAR/ZIP format support and streaming - Create blame service for Git file annotation with line tracking - Add branch management including create, delete, rename and compare operations - Implement merge checking with conflict detection and fast-forward handling - Add cherry-pick functionality for applying commits between branches - Integrate gix library for Git repository operations and object handling - Add comprehensive test suite covering all Git operations - Implement proper error handling and repository validation - Add pagination support for large result sets - Create protobuf definitions for all Git operations and data structures - Add build system for gRPC code generation and dependency management
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
use crate::bare::GitBare;
|
||||
use crate::error::GitResult;
|
||||
use crate::paginate;
|
||||
use crate::pb::{Branch, ListBranchesRequest, ListBranchesResponse};
|
||||
|
||||
impl GitBare {
|
||||
pub fn list_branches(&self, request: ListBranchesRequest) -> GitResult<ListBranchesResponse> {
|
||||
let repo = self.gix_repo()?;
|
||||
|
||||
let merged_set = if request.merged_into_head || request.not_merged_into_head {
|
||||
let flag = if request.merged_into_head {
|
||||
"--merged"
|
||||
} else {
|
||||
"--no-merged"
|
||||
};
|
||||
let check = duct::cmd(
|
||||
"git",
|
||||
[
|
||||
"--git-dir",
|
||||
self.bare_dir.to_string_lossy().as_ref(),
|
||||
"branch",
|
||||
flag,
|
||||
"HEAD",
|
||||
],
|
||||
)
|
||||
.stdout_capture()
|
||||
.stderr_capture()
|
||||
.unchecked()
|
||||
.run();
|
||||
match check {
|
||||
Ok(out) => String::from_utf8_lossy(&out.stdout)
|
||||
.lines()
|
||||
.map(|l| l.trim().trim_start_matches("* ").to_string())
|
||||
.collect::<Vec<_>>(),
|
||||
Err(_) => Vec::new(),
|
||||
}
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
|
||||
let mut branches: Vec<Branch> = Vec::new();
|
||||
for r in repo.references()?.local_branches()? {
|
||||
let mut r = r.map_err(|e| crate::error::GitError::Gix(e.to_string()))?;
|
||||
let name = r.name().shorten().to_string();
|
||||
if !request.pattern.is_empty() && !name.contains(&request.pattern) {
|
||||
continue;
|
||||
}
|
||||
if request.merged_into_head && !merged_set.contains(&name) {
|
||||
continue;
|
||||
}
|
||||
if request.not_merged_into_head && merged_set.contains(&name) {
|
||||
continue;
|
||||
}
|
||||
let hex = r
|
||||
.peel_to_id()
|
||||
.ok()
|
||||
.map(|id| id.to_string())
|
||||
.unwrap_or_default();
|
||||
branches.push(Branch {
|
||||
name,
|
||||
full_ref: r.name().to_string(),
|
||||
target_oid: Some(self.oid_to_pb(hex)),
|
||||
commit: None,
|
||||
upstream: None,
|
||||
is_default: false,
|
||||
is_head: false,
|
||||
is_merged: false,
|
||||
is_detached: false,
|
||||
});
|
||||
}
|
||||
paginate::apply_sort(&mut branches, request.sort_direction);
|
||||
let (branches, page_info) = paginate::paginate(&branches, request.pagination.as_ref());
|
||||
Ok(ListBranchesResponse {
|
||||
branches,
|
||||
page_info: Some(page_info),
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user