mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2025-01-04 15:53:30 +03:00
move upstream detection tests to integration
This commit is contained in:
parent
d8a54e5c49
commit
6044cf874d
@ -2243,115 +2243,6 @@ fn test_detect_mergeable_branch() -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_detect_remote_commits() -> Result<()> {
|
||||
let Case {
|
||||
project_repository,
|
||||
project,
|
||||
gb_repository,
|
||||
..
|
||||
} = Suite::default().new_case();
|
||||
let current_session = gb_repository.get_or_create_current_session()?;
|
||||
let current_session_reader = sessions::Reader::open(&gb_repository, ¤t_session)?;
|
||||
let branch_reader = branch::Reader::new(¤t_session_reader);
|
||||
let branch_writer = branch::Writer::new(&gb_repository);
|
||||
|
||||
// create a commit and set the target
|
||||
let file_path = std::path::Path::new("test.txt");
|
||||
std::fs::write(
|
||||
std::path::Path::new(&project.path).join(file_path),
|
||||
"line1\nline2\nline3\nline4\n",
|
||||
)?;
|
||||
test_utils::commit_all(&project_repository.git_repository);
|
||||
|
||||
set_test_target(&gb_repository, &project_repository)?;
|
||||
|
||||
let branch1_id = create_virtual_branch(
|
||||
&gb_repository,
|
||||
&project_repository,
|
||||
&BranchCreateRequest::default(),
|
||||
)
|
||||
.expect("failed to create virtual branch")
|
||||
.id;
|
||||
|
||||
// create a commit to push upstream
|
||||
std::fs::write(
|
||||
std::path::Path::new(&project.path).join(file_path),
|
||||
"line1\nline2\nline3\nline4\nupstream\n",
|
||||
)?;
|
||||
|
||||
commit(
|
||||
&gb_repository,
|
||||
&project_repository,
|
||||
&branch1_id,
|
||||
"upstream commit 1",
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
)?;
|
||||
|
||||
// create another commit to push upstream
|
||||
std::fs::write(
|
||||
std::path::Path::new(&project.path).join(file_path),
|
||||
"line1\nline2\nline3\nline4\nupstream\nmore upstream\n",
|
||||
)?;
|
||||
|
||||
commit(
|
||||
&gb_repository,
|
||||
&project_repository,
|
||||
&branch1_id,
|
||||
"upstream commit 2",
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
)?;
|
||||
|
||||
// push the commit upstream
|
||||
let branch1 = branch_reader.read(&branch1_id)?;
|
||||
let up_target = branch1.head;
|
||||
let remote_branch: git::RemoteBranchName = "refs/remotes/origin/remote_branch".parse().unwrap();
|
||||
project_repository.git_repository.reference(
|
||||
&remote_branch.to_string(),
|
||||
up_target,
|
||||
true,
|
||||
"update target",
|
||||
)?;
|
||||
// set the upstream reference
|
||||
branch_writer.write(&Branch {
|
||||
upstream: Some(remote_branch),
|
||||
..branch1
|
||||
})?;
|
||||
|
||||
// create another commit that is not pushed up
|
||||
std::fs::write(
|
||||
std::path::Path::new(&project.path).join(file_path),
|
||||
"line1\nline2\nline3\nline4\nupstream\nmore upstream\nmore work\n",
|
||||
)?;
|
||||
|
||||
commit(
|
||||
&gb_repository,
|
||||
&project_repository,
|
||||
&branch1_id,
|
||||
"local commit",
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
)?;
|
||||
|
||||
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
|
||||
assert_eq!(branches.len(), 1);
|
||||
|
||||
let branch = &branches.first().unwrap();
|
||||
assert_eq!(branch.commits.len(), 3);
|
||||
assert_eq!(branch.commits[0].description, "local commit");
|
||||
assert!(!branch.commits[0].is_remote);
|
||||
assert_eq!(branch.commits[1].description, "upstream commit 2");
|
||||
assert!(branch.commits[1].is_remote);
|
||||
assert!(branch.commits[2].is_remote);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_create_vbranch_from_remote_branch() -> Result<()> {
|
||||
let Case {
|
||||
|
@ -1169,3 +1169,75 @@ mod reset {
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
mod upstream {
|
||||
use super::*;
|
||||
|
||||
#[tokio::test]
|
||||
async fn detect_upstream_commits() {
|
||||
let Test {
|
||||
repository,
|
||||
project_id,
|
||||
controller,
|
||||
} = Test::default();
|
||||
|
||||
controller
|
||||
.set_base_branch(
|
||||
&project_id,
|
||||
&git::RemoteBranchName::from_str("refs/remotes/origin/master").unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let branch1_id = controller
|
||||
.create_virtual_branch(&project_id, &branch::BranchCreateRequest::default())
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let oid1 = {
|
||||
// create first commit
|
||||
fs::write(repository.path().join("file.txt"), "content").unwrap();
|
||||
controller
|
||||
.create_commit(&project_id, &branch1_id, "commit", None)
|
||||
.await
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
let oid2 = {
|
||||
// create second commit
|
||||
fs::write(repository.path().join("file.txt"), "content2").unwrap();
|
||||
controller
|
||||
.create_commit(&project_id, &branch1_id, "commit", None)
|
||||
.await
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
// push
|
||||
controller
|
||||
.push_virtual_branch(&project_id, &branch1_id, false)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let oid3 = {
|
||||
// create third commit
|
||||
fs::write(repository.path().join("file.txt"), "content3").unwrap();
|
||||
controller
|
||||
.create_commit(&project_id, &branch1_id, "commit", None)
|
||||
.await
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
{
|
||||
// should correctly detect pushed commits
|
||||
let branches = controller.list_virtual_branches(&project_id).await.unwrap();
|
||||
assert_eq!(branches.len(), 1);
|
||||
assert_eq!(branches[0].id, branch1_id);
|
||||
assert_eq!(branches[0].commits.len(), 3);
|
||||
assert_eq!(branches[0].commits[0].id, oid3);
|
||||
assert!(!branches[0].commits[0].is_remote);
|
||||
assert_eq!(branches[0].commits[1].id, oid2);
|
||||
assert!(branches[0].commits[1].is_remote);
|
||||
assert_eq!(branches[0].commits[2].id, oid1);
|
||||
assert!(branches[0].commits[2].is_remote);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user