dcb0fb74c5
- 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
301 lines
9.4 KiB
Rust
301 lines
9.4 KiB
Rust
mod common;
|
|
|
|
use gitks::pb::*;
|
|
|
|
#[test]
|
|
fn test_check_merge_no_conflict() {
|
|
let (_dir, gb) = common::setup_bare_repo();
|
|
let result = gb
|
|
.check_merge(CheckMergeRequest {
|
|
repository: None,
|
|
target: Some(ObjectSelector {
|
|
selector: Some(object_selector::Selector::Revision(ObjectName {
|
|
revision: "main".into(),
|
|
})),
|
|
}),
|
|
source: Some(ObjectSelector {
|
|
selector: Some(object_selector::Selector::Revision(ObjectName {
|
|
revision: "feature".into(),
|
|
})),
|
|
}),
|
|
options: None,
|
|
})
|
|
.expect("check_merge");
|
|
|
|
assert!(
|
|
result.status == merge_result::Status::MergeResultStatusMerged as i32
|
|
|| result.status == merge_result::Status::MergeResultStatusFastForward as i32
|
|
|| result.status == merge_result::Status::MergeResultStatusAlreadyUpToDate as i32,
|
|
"merge should be clean, got status: {}",
|
|
result.status
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_check_merge_with_conflict() {
|
|
let (_dir, gb) = common::setup_bare_repo_with_conflict();
|
|
let result = gb
|
|
.check_merge(CheckMergeRequest {
|
|
repository: None,
|
|
target: Some(ObjectSelector {
|
|
selector: Some(object_selector::Selector::Revision(ObjectName {
|
|
revision: "branch-a".into(),
|
|
})),
|
|
}),
|
|
source: Some(ObjectSelector {
|
|
selector: Some(object_selector::Selector::Revision(ObjectName {
|
|
revision: "branch-b".into(),
|
|
})),
|
|
}),
|
|
options: None,
|
|
})
|
|
.expect("check_merge with conflict");
|
|
|
|
assert_eq!(
|
|
result.status,
|
|
merge_result::Status::MergeResultStatusConflicts as i32,
|
|
"merge should have conflicts"
|
|
);
|
|
assert!(!result.conflicts.is_empty(), "should list conflicted files");
|
|
}
|
|
|
|
#[test]
|
|
fn test_check_merge_already_up_to_date() {
|
|
let (_dir, gb) = common::setup_bare_repo();
|
|
let result = gb
|
|
.check_merge(CheckMergeRequest {
|
|
repository: None,
|
|
target: Some(ObjectSelector {
|
|
selector: Some(object_selector::Selector::Revision(ObjectName {
|
|
revision: "main".into(),
|
|
})),
|
|
}),
|
|
source: Some(ObjectSelector {
|
|
selector: Some(object_selector::Selector::Revision(ObjectName {
|
|
revision: "main".into(),
|
|
})),
|
|
}),
|
|
options: None,
|
|
})
|
|
.expect("check_merge same ref");
|
|
|
|
assert_eq!(
|
|
result.status,
|
|
merge_result::Status::MergeResultStatusAlreadyUpToDate as i32
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_merge_fast_forward() {
|
|
let (_dir, gb) = common::setup_bare_repo();
|
|
let result = gb
|
|
.merge(MergeRequest {
|
|
repository: None,
|
|
target_branch: "feature".into(),
|
|
source: Some(ObjectSelector {
|
|
selector: Some(object_selector::Selector::Revision(ObjectName {
|
|
revision: "main".into(),
|
|
})),
|
|
}),
|
|
committer: None,
|
|
message: String::new(),
|
|
options: None,
|
|
})
|
|
.expect("merge fast-forward");
|
|
|
|
assert!(
|
|
result.status == merge_result::Status::MergeResultStatusFastForward as i32
|
|
|| result.status == merge_result::Status::MergeResultStatusAlreadyUpToDate as i32,
|
|
"feature should fast-forward to main, got: {}",
|
|
result.status
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_merge_with_conflict() {
|
|
let (_dir, gb) = common::setup_bare_repo_with_conflict();
|
|
let result = gb
|
|
.merge(MergeRequest {
|
|
repository: None,
|
|
target_branch: "branch-a".into(),
|
|
source: Some(ObjectSelector {
|
|
selector: Some(object_selector::Selector::Revision(ObjectName {
|
|
revision: "branch-b".into(),
|
|
})),
|
|
}),
|
|
committer: None,
|
|
message: String::new(),
|
|
options: None,
|
|
})
|
|
.expect("merge with conflict");
|
|
|
|
assert_eq!(
|
|
result.status,
|
|
merge_result::Status::MergeResultStatusConflicts as i32,
|
|
"should detect conflicts"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_merge_fast_forward_only_aborts_non_fast_forward() {
|
|
let (_dir, gb) = common::setup_bare_repo_with_conflict();
|
|
let result = gb
|
|
.merge(MergeRequest {
|
|
repository: None,
|
|
target_branch: "branch-a".into(),
|
|
source: Some(ObjectSelector {
|
|
selector: Some(object_selector::Selector::Revision(ObjectName {
|
|
revision: "branch-b".into(),
|
|
})),
|
|
}),
|
|
committer: None,
|
|
message: String::new(),
|
|
options: Some(MergeOptions {
|
|
fast_forward: merge_options::FastForwardMode::MergeFastForwardModeOnly as i32,
|
|
..Default::default()
|
|
}),
|
|
})
|
|
.expect("merge fast-forward only");
|
|
|
|
assert_eq!(
|
|
result.status,
|
|
merge_result::Status::MergeResultStatusAborted as i32
|
|
);
|
|
assert!(result.commit.is_none());
|
|
}
|
|
|
|
#[test]
|
|
fn test_list_merge_conflicts() {
|
|
let (_dir, gb) = common::setup_bare_repo_with_conflict();
|
|
let result = gb
|
|
.list_merge_conflicts(ListMergeConflictsRequest {
|
|
repository: None,
|
|
target: Some(ObjectSelector {
|
|
selector: Some(object_selector::Selector::Revision(ObjectName {
|
|
revision: "branch-a".into(),
|
|
})),
|
|
}),
|
|
source: Some(ObjectSelector {
|
|
selector: Some(object_selector::Selector::Revision(ObjectName {
|
|
revision: "branch-b".into(),
|
|
})),
|
|
}),
|
|
pagination: None,
|
|
})
|
|
.expect("list_merge_conflicts");
|
|
|
|
assert!(!result.conflicts.is_empty(), "should list conflicted files");
|
|
assert!(
|
|
result.conflicts.iter().any(|c| c.path == "file.txt"),
|
|
"file.txt should be conflicted"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_resolve_merge_conflicts() {
|
|
let (_dir, gb) = common::setup_bare_repo_with_conflict();
|
|
|
|
let result = gb
|
|
.resolve_merge_conflicts(ResolveMergeConflictsRequest {
|
|
repository: None,
|
|
target_branch: "branch-a".into(),
|
|
source: Some(ObjectSelector {
|
|
selector: Some(object_selector::Selector::Revision(ObjectName {
|
|
revision: "branch-b".into(),
|
|
})),
|
|
}),
|
|
resolutions: vec![ResolveMergeConflict {
|
|
path: "file.txt".into(),
|
|
content: b"resolved content\n".to_vec(),
|
|
}],
|
|
committer: None,
|
|
message: "resolved conflicts".into(),
|
|
})
|
|
.expect("resolve_merge_conflicts");
|
|
|
|
assert_eq!(
|
|
result.status,
|
|
merge_result::Status::MergeResultStatusMerged as i32
|
|
);
|
|
assert!(result.commit.is_some());
|
|
|
|
let blob = gb
|
|
.get_blob(GetBlobRequest {
|
|
repository: None,
|
|
revision: Some(ObjectSelector {
|
|
selector: Some(object_selector::Selector::Revision(ObjectName {
|
|
revision: "branch-a".into(),
|
|
})),
|
|
}),
|
|
path: "file.txt".into(),
|
|
oid: None,
|
|
max_bytes: 0,
|
|
})
|
|
.expect("get resolved blob");
|
|
assert_eq!(String::from_utf8_lossy(&blob.data), "resolved content\n");
|
|
}
|
|
|
|
#[test]
|
|
fn test_rebase() {
|
|
let (_dir, gb) = common::setup_bare_repo();
|
|
|
|
gb.create_commit(CreateCommitRequest {
|
|
repository: None,
|
|
branch: "feature".into(),
|
|
message: "feature work".into(),
|
|
author: None,
|
|
committer: None,
|
|
actions: vec![CreateCommitAction {
|
|
action: create_commit_action::Action::CreateCommitActionCreate as i32,
|
|
file_path: "feature.txt".into(),
|
|
previous_path: String::new(),
|
|
content: b"feature content".to_vec(),
|
|
encoding: String::new(),
|
|
executable: false,
|
|
last_commit_oid: None,
|
|
}],
|
|
start_revision: Some(ObjectSelector {
|
|
selector: Some(object_selector::Selector::Revision(ObjectName {
|
|
revision: "feature".into(),
|
|
})),
|
|
}),
|
|
force: false,
|
|
trailers: vec![],
|
|
})
|
|
.expect("create feature commit");
|
|
|
|
let result = gb
|
|
.rebase(RebaseRequest {
|
|
repository: None,
|
|
branch: "feature".into(),
|
|
upstream: Some(ObjectSelector {
|
|
selector: Some(object_selector::Selector::Revision(ObjectName {
|
|
revision: "main".into(),
|
|
})),
|
|
}),
|
|
committer: None,
|
|
})
|
|
.expect("rebase");
|
|
|
|
assert_eq!(
|
|
result.status,
|
|
rebase_result::Status::RebaseResultStatusRebased as i32
|
|
);
|
|
assert!(result.head.is_some());
|
|
|
|
let blob = gb
|
|
.get_blob(GetBlobRequest {
|
|
repository: None,
|
|
revision: Some(ObjectSelector {
|
|
selector: Some(object_selector::Selector::Revision(ObjectName {
|
|
revision: "feature".into(),
|
|
})),
|
|
}),
|
|
path: "feature.txt".into(),
|
|
oid: None,
|
|
max_bytes: 0,
|
|
})
|
|
.expect("get rebased feature file");
|
|
assert_eq!(String::from_utf8_lossy(&blob.data), "feature content");
|
|
}
|