mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-20 08:01:46 +03:00
if a project has not virtual branches migrate it to using diffs with context
This commit is contained in:
parent
9d53268a5d
commit
08d22de40e
@ -12,7 +12,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
branch::BranchId,
|
branch::{self, BranchId},
|
||||||
controller::{Controller, ControllerError},
|
controller::{Controller, ControllerError},
|
||||||
BaseBranch, RemoteBranchFile,
|
BaseBranch, RemoteBranchFile,
|
||||||
};
|
};
|
||||||
@ -80,11 +80,23 @@ pub async fn list_virtual_branches(
|
|||||||
code: Code::Validation,
|
code: Code::Validation,
|
||||||
message: "Malformed project id".to_string(),
|
message: "Malformed project id".to_string(),
|
||||||
})?;
|
})?;
|
||||||
let branches = handle
|
let (branches, uses_diff_context) = handle
|
||||||
.state::<Controller>()
|
.state::<Controller>()
|
||||||
.list_virtual_branches(&project_id)
|
.list_virtual_branches(&project_id)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
// Migration: If use_diff_context is not already set and if there are no vbranches, set use_diff_context to true
|
||||||
|
if !uses_diff_context && branches.is_empty() {
|
||||||
|
let _ = handle
|
||||||
|
.state::<projects::Controller>()
|
||||||
|
.update(&projects::UpdateRequest {
|
||||||
|
id: project_id,
|
||||||
|
use_diff_context: Some(true),
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
}
|
||||||
|
|
||||||
let proxy = handle.state::<assets::Proxy>();
|
let proxy = handle.state::<assets::Proxy>();
|
||||||
let branches = proxy.proxy_virtual_branches(branches).await;
|
let branches = proxy.proxy_virtual_branches(branches).await;
|
||||||
Ok(branches)
|
Ok(branches)
|
||||||
|
@ -124,7 +124,8 @@ impl Controller {
|
|||||||
pub async fn list_virtual_branches(
|
pub async fn list_virtual_branches(
|
||||||
&self,
|
&self,
|
||||||
project_id: &ProjectId,
|
project_id: &ProjectId,
|
||||||
) -> Result<Vec<super::VirtualBranch>, ControllerError<errors::ListVirtualBranchesError>> {
|
) -> Result<(Vec<super::VirtualBranch>, bool), ControllerError<errors::ListVirtualBranchesError>>
|
||||||
|
{
|
||||||
self.inner(project_id)
|
self.inner(project_id)
|
||||||
.await
|
.await
|
||||||
.list_virtual_branches(project_id)
|
.list_virtual_branches(project_id)
|
||||||
@ -493,7 +494,8 @@ impl ControllerInner {
|
|||||||
pub async fn list_virtual_branches(
|
pub async fn list_virtual_branches(
|
||||||
&self,
|
&self,
|
||||||
project_id: &ProjectId,
|
project_id: &ProjectId,
|
||||||
) -> Result<Vec<super::VirtualBranch>, ControllerError<errors::ListVirtualBranchesError>> {
|
) -> Result<(Vec<super::VirtualBranch>, bool), ControllerError<errors::ListVirtualBranchesError>>
|
||||||
|
{
|
||||||
let _permit = self.semaphore.acquire().await;
|
let _permit = self.semaphore.acquire().await;
|
||||||
|
|
||||||
self.with_verify_branch(project_id, |gb_repository, project_repository, _| {
|
self.with_verify_branch(project_id, |gb_repository, project_repository, _| {
|
||||||
|
@ -81,7 +81,7 @@ fn test_commit_on_branch_then_change_file_then_get_status() -> Result<()> {
|
|||||||
"line0\nline1\nline2\nline3\nline4\n",
|
"line0\nline1\nline2\nline3\nline4\n",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
|
let (branches, _) = list_virtual_branches(&gb_repository, &project_repository)?;
|
||||||
let branch = &branches[0];
|
let branch = &branches[0];
|
||||||
assert_eq!(branch.files.len(), 1);
|
assert_eq!(branch.files.len(), 1);
|
||||||
assert_eq!(branch.commits.len(), 0);
|
assert_eq!(branch.commits.len(), 0);
|
||||||
@ -99,7 +99,7 @@ fn test_commit_on_branch_then_change_file_then_get_status() -> Result<()> {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
// status (no files)
|
// status (no files)
|
||||||
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
|
let (branches, _) = list_virtual_branches(&gb_repository, &project_repository)?;
|
||||||
let branch = &branches[0];
|
let branch = &branches[0];
|
||||||
assert_eq!(branch.files.len(), 0);
|
assert_eq!(branch.files.len(), 0);
|
||||||
assert_eq!(branch.commits.len(), 1);
|
assert_eq!(branch.commits.len(), 1);
|
||||||
@ -110,7 +110,7 @@ fn test_commit_on_branch_then_change_file_then_get_status() -> Result<()> {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
// should have just the last change now, the other line is committed
|
// should have just the last change now, the other line is committed
|
||||||
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
|
let (branches, _) = list_virtual_branches(&gb_repository, &project_repository)?;
|
||||||
let branch = &branches[0];
|
let branch = &branches[0];
|
||||||
assert_eq!(branch.files.len(), 1);
|
assert_eq!(branch.files.len(), 1);
|
||||||
assert_eq!(branch.commits.len(), 1);
|
assert_eq!(branch.commits.len(), 1);
|
||||||
@ -170,7 +170,7 @@ fn test_signed_commit() -> Result<()> {
|
|||||||
false,
|
false,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let branches = list_virtual_branches(&gb_repository, &project_repository).unwrap();
|
let (branches, _) = list_virtual_branches(&gb_repository, &project_repository).unwrap();
|
||||||
let commit_id = &branches[0].commits[0].id;
|
let commit_id = &branches[0].commits[0].id;
|
||||||
let commit_obj = project_repository.git_repository.find_commit(*commit_id)?;
|
let commit_obj = project_repository.git_repository.find_commit(*commit_id)?;
|
||||||
// check the raw_header contains the string "SSH SIGNATURE"
|
// check the raw_header contains the string "SSH SIGNATURE"
|
||||||
@ -235,7 +235,7 @@ fn test_track_binary_files() -> Result<()> {
|
|||||||
let mut file = fs::File::create(std::path::Path::new(&project.path).join("image.bin"))?;
|
let mut file = fs::File::create(std::path::Path::new(&project.path).join("image.bin"))?;
|
||||||
file.write_all(&image_data)?;
|
file.write_all(&image_data)?;
|
||||||
|
|
||||||
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
|
let (branches, _) = list_virtual_branches(&gb_repository, &project_repository)?;
|
||||||
let branch = &branches[0];
|
let branch = &branches[0];
|
||||||
assert_eq!(branch.files.len(), 2);
|
assert_eq!(branch.files.len(), 2);
|
||||||
let img_file = &branch
|
let img_file = &branch
|
||||||
@ -262,7 +262,7 @@ fn test_track_binary_files() -> Result<()> {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
// status (no files)
|
// status (no files)
|
||||||
let branches = list_virtual_branches(&gb_repository, &project_repository).unwrap();
|
let (branches, _) = list_virtual_branches(&gb_repository, &project_repository).unwrap();
|
||||||
let commit_id = &branches[0].commits[0].id;
|
let commit_id = &branches[0].commits[0].id;
|
||||||
let commit_obj = project_repository.git_repository.find_commit(*commit_id)?;
|
let commit_obj = project_repository.git_repository.find_commit(*commit_id)?;
|
||||||
let tree = commit_obj.tree()?;
|
let tree = commit_obj.tree()?;
|
||||||
@ -291,7 +291,7 @@ fn test_track_binary_files() -> Result<()> {
|
|||||||
false,
|
false,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let branches = list_virtual_branches(&gb_repository, &project_repository).unwrap();
|
let (branches, _) = list_virtual_branches(&gb_repository, &project_repository).unwrap();
|
||||||
let commit_id = &branches[0].commits[0].id;
|
let commit_id = &branches[0].commits[0].id;
|
||||||
// get tree from commit_id
|
// get tree from commit_id
|
||||||
let commit_obj = project_repository.git_repository.find_commit(*commit_id)?;
|
let commit_obj = project_repository.git_repository.find_commit(*commit_id)?;
|
||||||
@ -1040,7 +1040,7 @@ fn test_merge_vbranch_upstream_clean() -> Result<()> {
|
|||||||
.context("failed to write target branch after push")?;
|
.context("failed to write target branch after push")?;
|
||||||
|
|
||||||
// create the branch
|
// create the branch
|
||||||
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
|
let (branches, _) = list_virtual_branches(&gb_repository, &project_repository)?;
|
||||||
let branch1 = &branches[0];
|
let branch1 = &branches[0];
|
||||||
assert_eq!(branch1.files.len(), 1);
|
assert_eq!(branch1.files.len(), 1);
|
||||||
assert_eq!(branch1.commits.len(), 1);
|
assert_eq!(branch1.commits.len(), 1);
|
||||||
@ -1054,7 +1054,7 @@ fn test_merge_vbranch_upstream_clean() -> Result<()> {
|
|||||||
None,
|
None,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
|
let (branches, _) = list_virtual_branches(&gb_repository, &project_repository)?;
|
||||||
let branch1 = &branches[0];
|
let branch1 = &branches[0];
|
||||||
|
|
||||||
let contents = std::fs::read(std::path::Path::new(&project.path).join(file_path))?;
|
let contents = std::fs::read(std::path::Path::new(&project.path).join(file_path))?;
|
||||||
@ -1168,7 +1168,7 @@ fn test_merge_vbranch_upstream_conflict() -> Result<()> {
|
|||||||
.context("failed to write target branch after push")?;
|
.context("failed to write target branch after push")?;
|
||||||
|
|
||||||
// create the branch
|
// create the branch
|
||||||
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
|
let (branches, _) = list_virtual_branches(&gb_repository, &project_repository)?;
|
||||||
let branch1 = &branches[0];
|
let branch1 = &branches[0];
|
||||||
|
|
||||||
assert_eq!(branch1.files.len(), 1);
|
assert_eq!(branch1.files.len(), 1);
|
||||||
@ -1177,7 +1177,7 @@ fn test_merge_vbranch_upstream_conflict() -> Result<()> {
|
|||||||
|
|
||||||
merge_virtual_branch_upstream(&gb_repository, &project_repository, &branch1.id, None, None)?;
|
merge_virtual_branch_upstream(&gb_repository, &project_repository, &branch1.id, None, None)?;
|
||||||
|
|
||||||
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
|
let (branches, _) = list_virtual_branches(&gb_repository, &project_repository)?;
|
||||||
let branch1 = &branches[0];
|
let branch1 = &branches[0];
|
||||||
let contents = std::fs::read(std::path::Path::new(&project.path).join(file_path))?;
|
let contents = std::fs::read(std::path::Path::new(&project.path).join(file_path))?;
|
||||||
|
|
||||||
@ -1197,7 +1197,7 @@ fn test_merge_vbranch_upstream_conflict() -> Result<()> {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
// make gb see the conflict resolution
|
// make gb see the conflict resolution
|
||||||
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
|
let (branches, _) = list_virtual_branches(&gb_repository, &project_repository)?;
|
||||||
assert!(branches[0].conflicted);
|
assert!(branches[0].conflicted);
|
||||||
|
|
||||||
// commit the merge resolution
|
// commit the merge resolution
|
||||||
@ -1212,7 +1212,7 @@ fn test_merge_vbranch_upstream_conflict() -> Result<()> {
|
|||||||
false,
|
false,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
|
let (branches, _) = list_virtual_branches(&gb_repository, &project_repository)?;
|
||||||
let branch1 = &branches[0];
|
let branch1 = &branches[0];
|
||||||
assert!(!branch1.conflicted);
|
assert!(!branch1.conflicted);
|
||||||
assert_eq!(branch1.files.len(), 0);
|
assert_eq!(branch1.files.len(), 0);
|
||||||
@ -1252,7 +1252,7 @@ fn test_unapply_ownership_partial() -> Result<()> {
|
|||||||
)
|
)
|
||||||
.expect("failed to create virtual branch");
|
.expect("failed to create virtual branch");
|
||||||
|
|
||||||
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
|
let (branches, _) = list_virtual_branches(&gb_repository, &project_repository)?;
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
assert_eq!(branches[0].files.len(), 1);
|
assert_eq!(branches[0].files.len(), 1);
|
||||||
assert_eq!(branches[0].ownership.files.len(), 1);
|
assert_eq!(branches[0].ownership.files.len(), 1);
|
||||||
@ -1270,7 +1270,7 @@ fn test_unapply_ownership_partial() -> Result<()> {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
|
let (branches, _) = list_virtual_branches(&gb_repository, &project_repository)?;
|
||||||
assert_eq!(branches.len(), 1);
|
assert_eq!(branches.len(), 1);
|
||||||
assert_eq!(branches[0].files.len(), 0);
|
assert_eq!(branches[0].files.len(), 0);
|
||||||
assert_eq!(branches[0].ownership.files.len(), 0);
|
assert_eq!(branches[0].ownership.files.len(), 0);
|
||||||
@ -1344,7 +1344,7 @@ fn test_apply_unapply_branch() -> Result<()> {
|
|||||||
let contents = std::fs::read(std::path::Path::new(&project.path).join(file_path2))?;
|
let contents = std::fs::read(std::path::Path::new(&project.path).join(file_path2))?;
|
||||||
assert_eq!("line5\nline6\n", String::from_utf8(contents)?);
|
assert_eq!("line5\nline6\n", String::from_utf8(contents)?);
|
||||||
|
|
||||||
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
|
let (branches, _) = list_virtual_branches(&gb_repository, &project_repository)?;
|
||||||
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
||||||
assert_eq!(branch.files.len(), 1);
|
assert_eq!(branch.files.len(), 1);
|
||||||
assert!(branch.active);
|
assert!(branch.active);
|
||||||
@ -1356,7 +1356,7 @@ fn test_apply_unapply_branch() -> Result<()> {
|
|||||||
let contents = std::fs::read(std::path::Path::new(&project.path).join(file_path2))?;
|
let contents = std::fs::read(std::path::Path::new(&project.path).join(file_path2))?;
|
||||||
assert_eq!("line5\nline6\n", String::from_utf8(contents)?);
|
assert_eq!("line5\nline6\n", String::from_utf8(contents)?);
|
||||||
|
|
||||||
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
|
let (branches, _) = list_virtual_branches(&gb_repository, &project_repository)?;
|
||||||
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
||||||
assert_eq!(branch.files.len(), 1);
|
assert_eq!(branch.files.len(), 1);
|
||||||
assert!(!branch.active);
|
assert!(!branch.active);
|
||||||
@ -1370,7 +1370,7 @@ fn test_apply_unapply_branch() -> Result<()> {
|
|||||||
let contents = std::fs::read(std::path::Path::new(&project.path).join(file_path2))?;
|
let contents = std::fs::read(std::path::Path::new(&project.path).join(file_path2))?;
|
||||||
assert_eq!("line5\nline6\n", String::from_utf8(contents)?);
|
assert_eq!("line5\nline6\n", String::from_utf8(contents)?);
|
||||||
|
|
||||||
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
|
let (branches, _) = list_virtual_branches(&gb_repository, &project_repository)?;
|
||||||
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
||||||
assert_eq!(branch.files.len(), 1);
|
assert_eq!(branch.files.len(), 1);
|
||||||
assert!(branch.active);
|
assert!(branch.active);
|
||||||
@ -1626,7 +1626,7 @@ fn test_detect_mergeable_branch() -> Result<()> {
|
|||||||
};
|
};
|
||||||
branch_writer.write(&mut branch4)?;
|
branch_writer.write(&mut branch4)?;
|
||||||
|
|
||||||
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
|
let (branches, _) = list_virtual_branches(&gb_repository, &project_repository)?;
|
||||||
assert_eq!(branches.len(), 4);
|
assert_eq!(branches.len(), 4);
|
||||||
|
|
||||||
let branch1 = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
let branch1 = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
||||||
@ -1808,7 +1808,7 @@ fn test_upstream_integrated_vbranch() -> Result<()> {
|
|||||||
false,
|
false,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
|
let (branches, _) = list_virtual_branches(&gb_repository, &project_repository)?;
|
||||||
|
|
||||||
let branch1 = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
let branch1 = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
||||||
assert!(branch1.commits.iter().any(|c| c.is_integrated));
|
assert!(branch1.commits.iter().any(|c| c.is_integrated));
|
||||||
@ -1855,7 +1855,7 @@ fn test_commit_same_hunk_twice() -> Result<()> {
|
|||||||
"line1\npatch1\nline2\nline3\nline4\nline5\nmiddle\nmiddle\nmiddle\nmiddle\nline6\nline7\nline8\nline9\nline10\nmiddle\nmiddle\nmiddle\nline11\nline12\n",
|
"line1\npatch1\nline2\nline3\nline4\nline5\nmiddle\nmiddle\nmiddle\nmiddle\nline6\nline7\nline8\nline9\nline10\nmiddle\nmiddle\nmiddle\nline11\nline12\n",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
|
let (branches, _) = list_virtual_branches(&gb_repository, &project_repository)?;
|
||||||
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
||||||
|
|
||||||
assert_eq!(branch.files.len(), 1);
|
assert_eq!(branch.files.len(), 1);
|
||||||
@ -1874,7 +1874,7 @@ fn test_commit_same_hunk_twice() -> Result<()> {
|
|||||||
false,
|
false,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
|
let (branches, _) = list_virtual_branches(&gb_repository, &project_repository)?;
|
||||||
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
||||||
|
|
||||||
assert_eq!(branch.files.len(), 0, "no files expected");
|
assert_eq!(branch.files.len(), 0, "no files expected");
|
||||||
@ -1894,7 +1894,7 @@ fn test_commit_same_hunk_twice() -> Result<()> {
|
|||||||
"line1\nPATCH1\nline2\nline3\nline4\nline5\nmiddle\nmiddle\nmiddle\nmiddle\nline6\nline7\nline8\nline9\nline10\nmiddle\nmiddle\nmiddle\nline11\nline12\n",
|
"line1\nPATCH1\nline2\nline3\nline4\nline5\nmiddle\nmiddle\nmiddle\nmiddle\nline6\nline7\nline8\nline9\nline10\nmiddle\nmiddle\nmiddle\nline11\nline12\n",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
|
let (branches, _) = list_virtual_branches(&gb_repository, &project_repository)?;
|
||||||
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
||||||
|
|
||||||
assert_eq!(branch.files.len(), 1, "one file should be changed");
|
assert_eq!(branch.files.len(), 1, "one file should be changed");
|
||||||
@ -1911,7 +1911,7 @@ fn test_commit_same_hunk_twice() -> Result<()> {
|
|||||||
false,
|
false,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
|
let (branches, _) = list_virtual_branches(&gb_repository, &project_repository)?;
|
||||||
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -1956,7 +1956,7 @@ fn test_commit_same_file_twice() -> Result<()> {
|
|||||||
"line1\npatch1\nline2\nline3\nline4\nline5\nmiddle\nmiddle\nmiddle\nmiddle\nline6\nline7\nline8\nline9\nline10\nmiddle\nmiddle\nmiddle\nline11\nline12\n",
|
"line1\npatch1\nline2\nline3\nline4\nline5\nmiddle\nmiddle\nmiddle\nmiddle\nline6\nline7\nline8\nline9\nline10\nmiddle\nmiddle\nmiddle\nline11\nline12\n",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
|
let (branches, _) = list_virtual_branches(&gb_repository, &project_repository)?;
|
||||||
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
||||||
|
|
||||||
assert_eq!(branch.files.len(), 1);
|
assert_eq!(branch.files.len(), 1);
|
||||||
@ -1975,7 +1975,7 @@ fn test_commit_same_file_twice() -> Result<()> {
|
|||||||
false,
|
false,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
|
let (branches, _) = list_virtual_branches(&gb_repository, &project_repository)?;
|
||||||
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
||||||
|
|
||||||
assert_eq!(branch.files.len(), 0, "no files expected");
|
assert_eq!(branch.files.len(), 0, "no files expected");
|
||||||
@ -1995,7 +1995,7 @@ fn test_commit_same_file_twice() -> Result<()> {
|
|||||||
"line1\npatch1\nline2\nline3\nline4\nline5\nmiddle\nmiddle\nmiddle\nmiddle\nline6\nline7\nline8\nline9\nline10\nmiddle\nmiddle\nmiddle\npatch2\nline11\nline12\n",
|
"line1\npatch1\nline2\nline3\nline4\nline5\nmiddle\nmiddle\nmiddle\nmiddle\nline6\nline7\nline8\nline9\nline10\nmiddle\nmiddle\nmiddle\npatch2\nline11\nline12\n",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
|
let (branches, _) = list_virtual_branches(&gb_repository, &project_repository)?;
|
||||||
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
||||||
|
|
||||||
assert_eq!(branch.files.len(), 1, "one file should be changed");
|
assert_eq!(branch.files.len(), 1, "one file should be changed");
|
||||||
@ -2012,7 +2012,7 @@ fn test_commit_same_file_twice() -> Result<()> {
|
|||||||
false,
|
false,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
|
let (branches, _) = list_virtual_branches(&gb_repository, &project_repository)?;
|
||||||
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
@ -2057,7 +2057,7 @@ fn test_commit_partial_by_hunk() -> Result<()> {
|
|||||||
"line1\npatch1\nline2\nline3\nline4\nline5\nmiddle\nmiddle\nmiddle\nmiddle\nline6\nline7\nline8\nline9\nline10\nmiddle\nmiddle\nmiddle\npatch2\nline11\nline12\n",
|
"line1\npatch1\nline2\nline3\nline4\nline5\nmiddle\nmiddle\nmiddle\nmiddle\nline6\nline7\nline8\nline9\nline10\nmiddle\nmiddle\nmiddle\npatch2\nline11\nline12\n",
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
|
let (branches, _) = list_virtual_branches(&gb_repository, &project_repository)?;
|
||||||
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
||||||
|
|
||||||
assert_eq!(branch.files.len(), 1);
|
assert_eq!(branch.files.len(), 1);
|
||||||
@ -2076,7 +2076,7 @@ fn test_commit_partial_by_hunk() -> Result<()> {
|
|||||||
false,
|
false,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
|
let (branches, _) = list_virtual_branches(&gb_repository, &project_repository)?;
|
||||||
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
||||||
|
|
||||||
assert_eq!(branch.files.len(), 1);
|
assert_eq!(branch.files.len(), 1);
|
||||||
@ -2096,7 +2096,7 @@ fn test_commit_partial_by_hunk() -> Result<()> {
|
|||||||
false,
|
false,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
|
let (branches, _) = list_virtual_branches(&gb_repository, &project_repository)?;
|
||||||
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
||||||
|
|
||||||
assert_eq!(branch.files.len(), 0);
|
assert_eq!(branch.files.len(), 0);
|
||||||
@ -2163,7 +2163,7 @@ fn test_commit_partial_by_file() -> Result<()> {
|
|||||||
false,
|
false,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
|
let (branches, _) = list_virtual_branches(&gb_repository, &project_repository)?;
|
||||||
let branch1 = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
let branch1 = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
||||||
|
|
||||||
// branch one test.txt has just the 1st and 3rd hunks applied
|
// branch one test.txt has just the 1st and 3rd hunks applied
|
||||||
@ -2239,7 +2239,7 @@ fn test_commit_add_and_delete_files() -> Result<()> {
|
|||||||
false,
|
false,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
|
let (branches, _) = list_virtual_branches(&gb_repository, &project_repository)?;
|
||||||
let branch1 = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
let branch1 = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
||||||
|
|
||||||
// branch one test.txt has just the 1st and 3rd hunks applied
|
// branch one test.txt has just the 1st and 3rd hunks applied
|
||||||
@ -2310,7 +2310,7 @@ fn test_commit_executable_and_symlinks() -> Result<()> {
|
|||||||
false,
|
false,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
let branches = list_virtual_branches(&gb_repository, &project_repository)?;
|
let (branches, _) = list_virtual_branches(&gb_repository, &project_repository)?;
|
||||||
let branch1 = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
let branch1 = &branches.iter().find(|b| b.id == branch1_id).unwrap();
|
||||||
|
|
||||||
let commit = &branch1.commits[0].id;
|
let commit = &branch1.commits[0].id;
|
||||||
@ -2412,7 +2412,7 @@ fn test_verify_branch_commits_to_integration() -> Result<()> {
|
|||||||
integration::verify_branch(&gb_repository, &project_repository).unwrap();
|
integration::verify_branch(&gb_repository, &project_repository).unwrap();
|
||||||
|
|
||||||
// one virtual branch with two commits was created
|
// one virtual branch with two commits was created
|
||||||
let virtual_branches = list_virtual_branches(&gb_repository, &project_repository)?;
|
let virtual_(branches, _) = list_virtual_branches(&gb_repository, &project_repository)?;
|
||||||
assert_eq!(virtual_branches.len(), 1);
|
assert_eq!(virtual_branches.len(), 1);
|
||||||
|
|
||||||
let branch = &virtual_branches.first().unwrap();
|
let branch = &virtual_branches.first().unwrap();
|
||||||
|
@ -729,7 +729,7 @@ fn find_base_tree<'a>(
|
|||||||
pub fn list_virtual_branches(
|
pub fn list_virtual_branches(
|
||||||
gb_repository: &gb_repository::Repository,
|
gb_repository: &gb_repository::Repository,
|
||||||
project_repository: &project_repository::Repository,
|
project_repository: &project_repository::Repository,
|
||||||
) -> Result<Vec<VirtualBranch>, errors::ListVirtualBranchesError> {
|
) -> Result<(Vec<VirtualBranch>, bool), errors::ListVirtualBranchesError> {
|
||||||
let mut branches: Vec<VirtualBranch> = Vec::new();
|
let mut branches: Vec<VirtualBranch> = Vec::new();
|
||||||
|
|
||||||
let default_target = gb_repository
|
let default_target = gb_repository
|
||||||
@ -908,7 +908,11 @@ pub fn list_virtual_branches(
|
|||||||
|
|
||||||
super::integration::update_gitbutler_integration(gb_repository, project_repository)?;
|
super::integration::update_gitbutler_integration(gb_repository, project_repository)?;
|
||||||
|
|
||||||
Ok(branches)
|
let uses_diff_context = project_repository
|
||||||
|
.project()
|
||||||
|
.use_diff_context
|
||||||
|
.unwrap_or(false);
|
||||||
|
Ok((branches, uses_diff_context))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn branches_with_large_files_abridged(mut branches: Vec<VirtualBranch>) -> Vec<VirtualBranch> {
|
fn branches_with_large_files_abridged(mut branches: Vec<VirtualBranch>) -> Vec<VirtualBranch> {
|
||||||
@ -3851,8 +3855,12 @@ pub fn context_lines(project_repository: &project_repository::Repository) -> u32
|
|||||||
.project()
|
.project()
|
||||||
.use_diff_context
|
.use_diff_context
|
||||||
.unwrap_or(false);
|
.unwrap_or(false);
|
||||||
|
|
||||||
if use_context { 3_u32 } else { 0_u32 }
|
if use_context {
|
||||||
|
3_u32
|
||||||
|
} else {
|
||||||
|
0_u32
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -79,7 +79,7 @@ impl InnerHandler {
|
|||||||
.list_virtual_branches(project_id)
|
.list_virtual_branches(project_id)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
Ok(branches) => Ok(vec![events::Event::Emit(
|
Ok((branches, _)) => Ok(vec![events::Event::Emit(
|
||||||
app_events::Event::virtual_branches(
|
app_events::Event::virtual_branches(
|
||||||
project_id,
|
project_id,
|
||||||
&self.assets_proxy.proxy_virtual_branches(branches).await,
|
&self.assets_proxy.proxy_virtual_branches(branches).await,
|
||||||
|
Loading…
Reference in New Issue
Block a user