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,69 @@
|
||||
use crate::bare::GitBare;
|
||||
use crate::error::{GitError, GitResult};
|
||||
use crate::paginate;
|
||||
use crate::pb::{ListMergeConflictsRequest, ListMergeConflictsResponse, MergeConflict};
|
||||
|
||||
impl GitBare {
|
||||
pub fn list_merge_conflicts(
|
||||
&self,
|
||||
request: ListMergeConflictsRequest,
|
||||
) -> GitResult<ListMergeConflictsResponse> {
|
||||
let target = match request.target.and_then(|s| s.selector) {
|
||||
Some(crate::pb::object_selector::Selector::Oid(oid)) => oid.hex,
|
||||
Some(crate::pb::object_selector::Selector::Revision(name)) => name.revision,
|
||||
None => return Err(GitError::InvalidArgument("target is required".into())),
|
||||
};
|
||||
let source = match request.source.and_then(|s| s.selector) {
|
||||
Some(crate::pb::object_selector::Selector::Oid(oid)) => oid.hex,
|
||||
Some(crate::pb::object_selector::Selector::Revision(name)) => name.revision,
|
||||
None => return Err(GitError::InvalidArgument("source is required".into())),
|
||||
};
|
||||
|
||||
let result = duct::cmd(
|
||||
"git",
|
||||
[
|
||||
"--git-dir",
|
||||
self.bare_dir.to_string_lossy().as_ref(),
|
||||
"merge-tree",
|
||||
"--write-tree",
|
||||
"--name-only",
|
||||
"-z",
|
||||
target.as_str(),
|
||||
source.as_str(),
|
||||
],
|
||||
)
|
||||
.stdout_capture()
|
||||
.stderr_capture()
|
||||
.unchecked()
|
||||
.run()?;
|
||||
|
||||
let stdout = String::from_utf8_lossy(&result.stdout);
|
||||
|
||||
if result.status.success() {
|
||||
return Ok(ListMergeConflictsResponse {
|
||||
conflicts: vec![],
|
||||
page_info: Some(crate::pb::PageInfo {
|
||||
next_page_token: String::new(),
|
||||
has_next_page: false,
|
||||
total_count: 0,
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
let mut conflicts: Vec<MergeConflict> = stdout
|
||||
.split('\0')
|
||||
.filter(|s| !s.is_empty())
|
||||
.map(|path| MergeConflict {
|
||||
path: path.to_string(),
|
||||
..Default::default()
|
||||
})
|
||||
.collect();
|
||||
|
||||
paginate::apply_sort(&mut conflicts, 0);
|
||||
let (conflicts, page_info) = paginate::paginate(&conflicts, request.pagination.as_ref());
|
||||
Ok(ListMergeConflictsResponse {
|
||||
conflicts,
|
||||
page_info: Some(page_info),
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user