Merge pull request #3536 from gitbutlerapp/use-context-diff-lines

Removes use_diff_context feature flag
This commit is contained in:
Kiril Videlov 2024-04-17 08:10:30 +02:00 committed by GitHub
commit 0d7a0732ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
29 changed files with 168 additions and 1046 deletions

View File

@ -51,16 +51,6 @@ impl GitHunk {
}
}
pub struct Options {
pub context_lines: u32,
}
impl Default for Options {
fn default() -> Self {
Self { context_lines: 3 }
}
}
#[derive(Debug, PartialEq, Clone, Serialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct FileDiff {
@ -76,7 +66,6 @@ pub struct FileDiff {
pub fn workdir(
repository: &Repository,
commit_oid: &git::Oid,
context_lines: u32,
) -> Result<HashMap<path::PathBuf, FileDiff>> {
let commit = repository
.find_commit(*commit_oid)
@ -90,7 +79,7 @@ pub fn workdir(
.show_binary(true)
.show_untracked_content(true)
.ignore_submodules(true)
.context_lines(context_lines);
.context_lines(3);
let mut diff = repository.diff_tree_to_workdir(Some(&tree), Some(&mut diff_opts))?;
let (mut diff_opts, skipped_files) = without_large_files(50_000_000, &diff, diff_opts);
@ -110,7 +99,6 @@ pub fn trees(
repository: &Repository,
old_tree: &git::Tree,
new_tree: &git::Tree,
context_lines: u32,
) -> Result<HashMap<path::PathBuf, FileDiff>> {
let mut diff_opts = git2::DiffOptions::new();
diff_opts
@ -118,7 +106,7 @@ pub fn trees(
.include_untracked(true)
.show_binary(true)
.ignore_submodules(true)
.context_lines(context_lines)
.context_lines(3)
.show_untracked_content(true);
let diff =

View File

@ -92,7 +92,6 @@ impl Controller {
title,
path: path.to_path_buf(),
api: None,
use_diff_context: Some(true),
..Default::default()
};

View File

@ -85,8 +85,6 @@ pub struct Project {
#[serde(default)]
pub omit_certificate_check: Option<bool>,
#[serde(default)]
pub use_diff_context: Option<bool>,
#[serde(default)]
pub use_toml_vbranches_state: Option<bool>,
}

View File

@ -128,10 +128,6 @@ impl Storage {
project.omit_certificate_check = Some(omit_certificate_check);
}
if let Some(use_diff_context) = update_request.use_diff_context {
project.use_diff_context = Some(use_diff_context);
}
self.storage
.write(PROJECTS_FILE, &serde_json::to_string_pretty(&projects)?)?;

View File

@ -1,6 +1,5 @@
pub mod branch;
pub use branch::{Branch, BranchId};
pub mod context;
pub mod target;
pub mod errors;

View File

@ -209,12 +209,7 @@ pub fn set_base_branch(
// if there are any commits on the head branch or uncommitted changes in the working directory, we need to
// put them into a virtual branch
let use_context = project_repository
.project()
.use_diff_context
.unwrap_or(false);
let context_lines = if use_context { 3_u32 } else { 0_u32 };
let wd_diff = diff::workdir(repo, &current_head_commit.id(), context_lines)?;
let wd_diff = diff::workdir(repo, &current_head_commit.id())?;
let wd_diff = diff::diff_files_to_hunks(&wd_diff);
if !wd_diff.is_empty() || current_head_commit.id() != target.sha {
let hunks_by_filepath =
@ -394,12 +389,6 @@ pub fn update_base_branch(
)
.context("failed to create branch writer")?;
let use_context = project_repository
.project()
.use_diff_context
.unwrap_or(false);
let context_lines = if use_context { 3_u32 } else { 0_u32 };
// try to update every branch
let updated_vbranches = super::get_status_by_branch(
gb_repository,
@ -438,7 +427,6 @@ pub fn update_base_branch(
&project_repository.git_repository,
&branch_head_tree,
&branch_tree,
context_lines,
)?;
if non_commited_files.is_empty() {
// if there are no commited files, then the branch is fully merged

View File

@ -1,124 +0,0 @@
use crate::git::diff;
pub fn hunk_with_context(
hunk_diff: &str,
hunk_old_start_line: usize,
hunk_new_start_line: usize,
is_binary: bool,
context_lines: usize,
file_lines_before: &[&str],
change_type: diff::ChangeType,
) -> diff::GitHunk {
let diff_lines = hunk_diff
.lines()
.map(std::string::ToString::to_string)
.collect::<Vec<_>>();
if diff_lines.is_empty() {
#[allow(clippy::cast_possible_truncation)]
return diff::GitHunk {
diff: hunk_diff.to_owned(),
old_start: hunk_old_start_line as u32,
old_lines: 0,
new_start: hunk_new_start_line as u32,
new_lines: 0,
binary: is_binary,
change_type,
};
}
let new_file = hunk_old_start_line == 0;
let deleted_file = hunk_new_start_line == 0;
let removed_count = diff_lines
.iter()
.filter(|line| line.starts_with('-'))
.count();
let added_count = diff_lines
.iter()
.filter(|line| line.starts_with('+'))
.count();
// Get context lines before the diff
let mut context_before = Vec::new();
let before_context_ending_index = if removed_count == 0 {
// Compensate for when the removed_count is 0
hunk_old_start_line
} else {
hunk_old_start_line.saturating_sub(1)
};
let before_context_starting_index = before_context_ending_index.saturating_sub(context_lines);
for index in before_context_starting_index..before_context_ending_index {
if let Some(l) = file_lines_before.get(index) {
let mut s = (*l).to_string();
s.insert(0, ' ');
context_before.push(s);
}
}
// Get context lines after the diff
let mut context_after = Vec::new();
let after_context_starting_index = before_context_ending_index + removed_count;
let after_context_ending_index = after_context_starting_index + context_lines;
for index in after_context_starting_index..after_context_ending_index {
if let Some(l) = file_lines_before.get(index) {
let mut s = (*l).to_string();
s.insert(0, ' ');
context_after.push(s);
}
}
let start_line_before = if new_file {
// If we've created a new file, start_line_before should be 0
0
} else {
before_context_starting_index + 1
};
let start_line_after = if deleted_file {
// If we've deleted a new file, start_line_after should be 0
0
} else if added_count == 0 {
// Compensate for when the added_count is 0
hunk_new_start_line.saturating_sub(context_before.len()) + 1
} else {
hunk_new_start_line.saturating_sub(context_before.len())
};
let line_count_before = removed_count + context_before.len() + context_after.len();
let line_count_after = added_count + context_before.len() + context_after.len();
let header = format!(
"@@ -{},{} +{},{} @@",
start_line_before, line_count_before, start_line_after, line_count_after
);
let body = &diff_lines[1..];
// Update unidiff body with context lines
let mut b = Vec::new();
b.extend(context_before.clone());
b.extend_from_slice(body);
b.extend(context_after.clone());
let body = b;
// Construct a new diff with updated header and body
let mut diff_lines = Vec::new();
diff_lines.push(header);
diff_lines.extend(body);
let mut diff = diff_lines.join("\n");
// Add trailing newline
diff.push('\n');
#[allow(clippy::cast_possible_truncation)]
let hunk = diff::GitHunk {
diff,
old_start: start_line_before as u32,
old_lines: line_count_before as u32,
new_start: start_line_after as u32,
new_lines: line_count_after as u32,
binary: is_binary,
change_type,
};
hunk
}

View File

@ -126,7 +126,7 @@ impl Controller {
pub async fn list_virtual_branches(
&self,
project_id: &ProjectId,
) -> Result<(Vec<super::VirtualBranch>, bool, Vec<git::diff::FileDiff>), Error> {
) -> Result<(Vec<super::VirtualBranch>, Vec<git::diff::FileDiff>), Error> {
self.inner(project_id)
.await
.list_virtual_branches(project_id)
@ -547,7 +547,7 @@ impl ControllerInner {
pub async fn list_virtual_branches(
&self,
project_id: &ProjectId,
) -> Result<(Vec<super::VirtualBranch>, bool, Vec<git::diff::FileDiff>), Error> {
) -> Result<(Vec<super::VirtualBranch>, Vec<git::diff::FileDiff>), Error> {
let _permit = self.semaphore.acquire().await;
self.with_verify_branch(project_id, |gb_repository, project_repository, _| {
@ -624,17 +624,8 @@ impl ControllerInner {
) -> Result<Vec<RemoteBranchFile>, Error> {
let project = self.projects.get(project_id)?;
let project_repository = project_repository::Repository::open(&project)?;
let use_context = project_repository
.project()
.use_diff_context
.unwrap_or(false);
let context_lines = if use_context { 3_u32 } else { 0_u32 };
super::list_remote_commit_files(
&project_repository.git_repository,
commit_oid,
context_lines,
)
.map_err(Into::into)
super::list_remote_commit_files(&project_repository.git_repository, commit_oid)
.map_err(Into::into)
}
pub fn set_base_branch(

View File

@ -4,10 +4,7 @@ use anyhow::{Context, Result};
use serde::Serialize;
use super::errors;
use crate::{
git::{self, diff, show},
virtual_branches::context,
};
use crate::git::{self, diff};
#[derive(Debug, PartialEq, Clone, Serialize)]
#[serde(rename_all = "camelCase")]
@ -20,7 +17,6 @@ pub struct RemoteBranchFile {
pub fn list_remote_commit_files(
repository: &git::Repository,
commit_oid: git::Oid,
context_lines: u32,
) -> Result<Vec<RemoteBranchFile>, errors::ListRemoteCommitFilesError> {
let commit = match repository.find_commit(commit_oid) {
Ok(commit) => Ok(commit),
@ -37,10 +33,10 @@ pub fn list_remote_commit_files(
let parent = commit.parent(0).context("failed to get parent commit")?;
let commit_tree = commit.tree().context("failed to get commit tree")?;
let parent_tree = parent.tree().context("failed to get parent tree")?;
let diff = diff::trees(repository, &parent_tree, &commit_tree, context_lines)?;
let diff = diff::trees(repository, &parent_tree, &commit_tree)?;
let diff = diff::diff_files_to_hunks(&diff);
let mut files = diff
let files = diff
.into_iter()
.map(|(file_path, hunks)| RemoteBranchFile {
path: file_path.clone(),
@ -48,50 +44,5 @@ pub fn list_remote_commit_files(
binary: hunks.iter().any(|h| h.binary),
})
.collect::<Vec<_>>();
if context_lines == 0 {
files = files_with_hunk_context(repository, &parent_tree, files, 3)
.context("failed to add context to hunk")?;
}
Ok(files)
}
fn files_with_hunk_context(
repository: &git::Repository,
parent_tree: &git::Tree,
mut files: Vec<RemoteBranchFile>,
context_lines: usize,
) -> Result<Vec<RemoteBranchFile>> {
for file in &mut files {
if file.binary {
continue;
}
// Get file content as it looked before the diffs
let file_content_before =
show::show_file_at_tree(repository, file.path.clone(), parent_tree)
.context("failed to get file contents at HEAD")?;
let file_lines_before = file_content_before.split('\n').collect::<Vec<_>>();
file.hunks = file
.hunks
.iter()
.map(|hunk| {
if hunk.diff.is_empty() {
// noop on empty diff
hunk.clone()
} else {
context::hunk_with_context(
&hunk.diff,
hunk.old_start as usize,
hunk.new_start as usize,
hunk.binary,
context_lines,
&file_lines_before,
hunk.change_type,
)
}
})
.collect::<Vec<diff::GitHunk>>();
}
Ok(files)
}

View File

@ -18,8 +18,7 @@ use super::{
branch::{
self, Branch, BranchCreateRequest, BranchId, BranchOwnershipClaims, Hunk, OwnershipClaim,
},
branch_to_remote_branch, context, errors, target, Iterator, RemoteBranch,
VirtualBranchesHandle,
branch_to_remote_branch, errors, target, Iterator, RemoteBranch, VirtualBranchesHandle,
};
use crate::{
askpass::AskpassBroker,
@ -28,7 +27,7 @@ use crate::{
git::{
self,
diff::{self, diff_files_to_hunks},
show, Commit, Refname, RemoteRefname,
Commit, Refname, RemoteRefname,
},
keys,
project_repository::{self, conflicts, LogUntil},
@ -824,7 +823,7 @@ fn find_base_tree<'a>(
pub fn list_virtual_branches(
gb_repository: &gb_repository::Repository,
project_repository: &project_repository::Repository,
) -> Result<(Vec<VirtualBranch>, bool, Vec<diff::FileDiff>), errors::ListVirtualBranchesError> {
) -> Result<(Vec<VirtualBranch>, Vec<diff::FileDiff>), errors::ListVirtualBranchesError> {
let mut branches: Vec<VirtualBranch> = Vec::new();
let default_target = gb_repository
@ -985,26 +984,9 @@ pub fn list_virtual_branches(
let branches = branches_with_large_files_abridged(branches);
let mut branches = branches_with_hunk_locks(branches, project_repository)?;
// If there no context lines are used internally, add them here, before returning to the UI
if context_lines(project_repository) == 0 {
for branch in &mut branches {
branch.files = files_with_hunk_context(
&project_repository.git_repository,
branch.files.clone(),
3,
branch.head,
)
.context("failed to add hunk context")?;
}
}
branches.sort_by(|a, b| a.order.cmp(&b.order));
let uses_diff_context = project_repository
.project()
.use_diff_context
.unwrap_or(false);
Ok((branches, uses_diff_context, skipped_files))
Ok((branches, skipped_files))
}
fn branches_with_large_files_abridged(mut branches: Vec<VirtualBranch>) -> Vec<VirtualBranch> {
@ -1042,7 +1024,6 @@ fn branches_with_hunk_locks(
&project_repository.git_repository,
&parent_tree,
&commit_tree,
context_lines(project_repository),
)?;
let commited_file_diffs = diff::diff_files_to_hunks(&commited_file_diffs);
for branch in &mut branches {
@ -1077,60 +1058,6 @@ fn joined(start_a: u32, end_a: u32, start_b: u32, end_b: u32) -> bool {
|| ((start_b >= start_a && start_b <= end_a) || (end_b >= start_a && end_b <= end_a))
}
fn files_with_hunk_context(
repository: &git::Repository,
mut files: Vec<VirtualBranchFile>,
context_lines: usize,
branch_head: git::Oid,
) -> Result<Vec<VirtualBranchFile>> {
for file in &mut files {
if file.binary {
continue;
}
// Get file content as it looked before the diffs
let branch_head_commit = repository.find_commit(branch_head)?;
let head_tree = branch_head_commit.tree()?;
let file_content_before =
show::show_file_at_tree(repository, file.path.clone(), &head_tree)
.context("failed to get file contents at base")?;
let file_lines_before = file_content_before.split('\n').collect::<Vec<_>>();
// Update each hunk with contex lines before & after
file.hunks = file
.hunks
.iter()
.map(|hunk| {
if hunk.diff.is_empty() {
// noop on empty diff
hunk.clone()
} else {
let hunk_with_ctx = context::hunk_with_context(
&hunk.diff,
hunk.old_start as usize,
hunk.start as usize,
hunk.binary,
context_lines,
&file_lines_before,
hunk.change_type,
);
to_virtual_branch_hunk(hunk.clone(), hunk_with_ctx)
}
})
.collect::<Vec<VirtualBranchHunk>>();
}
Ok(files)
}
fn to_virtual_branch_hunk(
mut hunk: VirtualBranchHunk,
diff_with_context: diff::GitHunk,
) -> VirtualBranchHunk {
hunk.diff = diff_with_context.diff;
hunk.start = diff_with_context.new_start;
hunk.end = diff_with_context.new_start + diff_with_context.new_lines;
hunk
}
fn is_requires_force(
project_repository: &project_repository::Repository,
branch: &branch::Branch,
@ -1176,7 +1103,6 @@ fn list_virtual_commit_files(
&project_repository.git_repository,
&parent_tree,
&commit_tree,
context_lines(project_repository),
)?;
let diff = diff::diff_files_to_hunks(&diff);
let hunks_by_filepath = virtual_hunks_by_filepath(&project_repository.project().path, &diff);
@ -1991,12 +1917,8 @@ fn get_non_applied_status(
.tree()
.context("failed to find target tree")?;
let diff = diff::trees(
&project_repository.git_repository,
&head_tree,
&branch_tree,
context_lines(project_repository),
)?;
let diff =
diff::trees(&project_repository.git_repository, &head_tree, &branch_tree)?;
Ok((branch, diff::diff_files_to_hunks(&diff)))
},
@ -2015,12 +1937,8 @@ fn get_applied_status(
target_sha: &git::Oid,
mut virtual_branches: Vec<branch::Branch>,
) -> Result<(AppliedStatuses, Vec<diff::FileDiff>)> {
let base_file_diffs = diff::workdir(
&project_repository.git_repository,
integration_commit,
context_lines(project_repository),
)
.context("failed to diff workdir")?;
let base_file_diffs = diff::workdir(&project_repository.git_repository, integration_commit)
.context("failed to diff workdir")?;
let mut base_diffs: HashMap<PathBuf, Vec<git::diff::GitHunk>> =
diff_files_to_hunks(&base_file_diffs);
@ -2079,7 +1997,6 @@ fn get_applied_status(
&project_repository.git_repository,
&parent_tree,
&commit_tree,
context_lines(project_repository),
);
let commited_file_diffs = diff::diff_files_to_hunks(&commited_file_diffs.unwrap());
for (path, committed_git_hunks) in commited_file_diffs.iter() {
@ -3834,7 +3751,6 @@ pub fn move_commit(
&project_repository.git_repository,
&source_branch_head_parent_tree,
&source_branch_head_tree,
context_lines(project_repository),
)?;
let branch_head_diff = diff::diff_files_to_hunks(&branch_head_diff);
@ -4048,7 +3964,6 @@ pub fn create_virtual_branch_from_branch(
&project_repository.git_repository,
&merge_base_tree,
&head_commit_tree,
context_lines(project_repository),
)
.context("failed to diff trees")?;
let diff = diff::diff_files_to_hunks(&diff);
@ -4117,19 +4032,6 @@ pub fn create_virtual_branch_from_branch(
}
}
pub fn context_lines(project_repository: &project_repository::Repository) -> u32 {
let use_context = project_repository
.project()
.use_diff_context
.unwrap_or(false);
if use_context {
3_u32
} else {
0_u32
}
}
/// Just like [`diffy::apply()`], but on error it will attach hashes of the input `base_image` and `patch`.
pub fn apply(base_image: &str, patch: &Patch<'_, str>) -> Result<String> {
fn md5_hash_hex(b: impl AsRef<[u8]>) -> String {

View File

@ -95,7 +95,7 @@ async fn rebase_commit() {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id);
assert!(branches[0].active);
@ -121,7 +121,7 @@ async fn rebase_commit() {
"one"
);
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
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].files.len(), 0);
@ -134,7 +134,7 @@ async fn rebase_commit() {
controller.update_base_branch(project_id).await.unwrap();
// branch is stil unapplied
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
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].files.len(), 0);
@ -160,7 +160,7 @@ async fn rebase_commit() {
.unwrap();
// it should be rebased
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
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].files.len(), 0);
@ -211,7 +211,7 @@ async fn rebase_work() {
.unwrap();
fs::write(repository.path().join("another_file.txt"), "").unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id);
assert!(branches[0].active);
@ -228,7 +228,7 @@ async fn rebase_work() {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
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].files.len(), 1);
@ -244,7 +244,7 @@ async fn rebase_work() {
controller.update_base_branch(project_id).await.unwrap();
// first branch is stil unapplied
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
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].files.len(), 1);
@ -264,7 +264,7 @@ async fn rebase_work() {
.unwrap();
// workdir should be rebased, and work should be restored
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
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].files.len(), 1);

View File

@ -67,7 +67,7 @@ mod cleanly {
"content two"
);
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert!(branches[0].active);
@ -140,7 +140,7 @@ mod cleanly {
.unwrap();
assert!(cherry_picked_commit_oid.is_some());
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert!(repository.path().join("file_two.txt").exists());
assert_eq!(
fs::read_to_string(repository.path().join("file_two.txt")).unwrap(),
@ -304,7 +304,7 @@ mod with_conflicts {
"<<<<<<< ours\nconflict\n=======\ncontent three\n>>>>>>> theirs\n"
);
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert!(branches[0].active);
@ -325,7 +325,7 @@ mod with_conflicts {
let commit = repository.find_commit(commited_oid).unwrap();
assert_eq!(commit.parent_count(), 2);
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert!(branches[0].active);

View File

@ -147,7 +147,7 @@ async fn no_conflicts() {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert!(branches.is_empty());
let branch_id = controller
@ -158,7 +158,7 @@ async fn no_conflicts() {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert_eq!(branches[0].commits.len(), 1);
@ -193,7 +193,7 @@ async fn conflicts_with_uncommited() {
{
std::fs::write(repository.path().join("file.txt"), "conflict").unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
};
@ -247,7 +247,7 @@ async fn conflicts_with_commited() {
{
std::fs::write(repository.path().join("file.txt"), "conflict").unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
controller
@ -373,7 +373,7 @@ async fn from_state_remote_branch() {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert_eq!(branches[0].commits.len(), 1);

View File

@ -17,14 +17,14 @@ async fn should_unapply_diff() {
// write some
std::fs::write(repository.path().join("file.txt"), "content").unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
controller
.delete_virtual_branch(project_id, &branches[0].id)
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 0);
assert!(!repository.path().join("file.txt").exists());
@ -66,7 +66,7 @@ async fn should_remove_reference() {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 0);
let refnames = repository

View File

@ -76,7 +76,7 @@ async fn dirty_non_target() {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].files.len(), 1);
assert_eq!(branches[0].files[0].hunks.len(), 1);
@ -102,7 +102,7 @@ async fn dirty_target() {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].files.len(), 1);
assert_eq!(branches[0].files[0].hunks.len(), 1);
@ -128,7 +128,7 @@ async fn commit_on_non_target_local() {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert!(branches[0].files.is_empty());
assert_eq!(branches[0].commits.len(), 1);
@ -155,7 +155,7 @@ async fn commit_on_non_target_remote() {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert!(branches[0].files.is_empty());
assert_eq!(branches[0].commits.len(), 1);
@ -180,7 +180,7 @@ async fn commit_on_target() {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert!(branches[0].files.is_empty());
assert_eq!(branches[0].commits.len(), 1);
@ -206,7 +206,7 @@ async fn submodule() {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].files.len(), 1);
assert_eq!(branches[0].files[0].hunks.len(), 1);

View File

@ -107,7 +107,7 @@ async fn resolve_conflict_flow() {
.unwrap();
fs::write(repository.path().join("file.txt"), "conflict").unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id);
assert!(branches[0].active);
@ -120,7 +120,7 @@ async fn resolve_conflict_flow() {
controller.update_base_branch(project_id).await.unwrap();
// there is a conflict now, so the branch should be inactive
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id);
assert!(!branches[0].active);
@ -133,7 +133,7 @@ async fn resolve_conflict_flow() {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id);
assert!(branches[0].active);
@ -169,7 +169,7 @@ async fn resolve_conflict_flow() {
let commit = repository.find_commit(commit_oid).unwrap();
assert_eq!(commit.parent_count(), 2);
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch1_id);
assert!(branches[0].active);

View File

@ -23,7 +23,7 @@ async fn no_diffs() {
std::fs::write(repository.path().join("file.txt"), "content").unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
let source_branch_id = branches[0].id;
@ -83,7 +83,7 @@ async fn diffs_on_source_branch() {
std::fs::write(repository.path().join("file.txt"), "content").unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
let source_branch_id = branches[0].id;
@ -149,7 +149,7 @@ async fn diffs_on_target_branch() {
std::fs::write(repository.path().join("file.txt"), "content").unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
let source_branch_id = branches[0].id;
@ -221,7 +221,7 @@ async fn locked_hunks_on_source_branch() {
std::fs::write(repository.path().join("file.txt"), "content").unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
let source_branch_id = branches[0].id;
@ -264,7 +264,7 @@ async fn no_commit() {
std::fs::write(repository.path().join("file.txt"), "content").unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
let source_branch_id = branches[0].id;
@ -309,7 +309,7 @@ async fn no_branch() {
std::fs::write(repository.path().join("file.txt"), "content").unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
let source_branch_id = branches[0].id;

View File

@ -22,7 +22,7 @@ mod create_virtual_branch {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert_eq!(branches[0].name, "Virtual branch");
@ -71,7 +71,7 @@ mod create_virtual_branch {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 2);
assert_eq!(branches[0].id, branch1_id);
assert_eq!(branches[0].name, "name");
@ -128,7 +128,7 @@ mod update_virtual_branch {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert_eq!(branches[0].name, "new name");
@ -189,7 +189,7 @@ mod update_virtual_branch {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 2);
assert_eq!(branches[0].id, branch1_id);
assert_eq!(branches[0].name, "name");
@ -246,7 +246,7 @@ mod push_virtual_branch {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
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].name, "name");
@ -338,7 +338,7 @@ mod push_virtual_branch {
branch2_id
};
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 2);
// first branch is pushing to old ref remotely
assert_eq!(branches[0].id, branch1_id);

View File

@ -32,7 +32,7 @@ async fn to_head() {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
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(), 1);
@ -53,7 +53,7 @@ async fn to_head() {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
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(), 1);
@ -94,7 +94,7 @@ async fn to_target() {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
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(), 1);
@ -113,7 +113,7 @@ async fn to_target() {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
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(), 0);
@ -154,7 +154,7 @@ async fn to_commit() {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
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(), 1);
@ -177,7 +177,7 @@ async fn to_commit() {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
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(), 2);
@ -197,7 +197,7 @@ async fn to_commit() {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
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(), 1);
@ -238,7 +238,7 @@ async fn to_non_existing() {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
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(), 1);

View File

@ -28,7 +28,7 @@ async fn unapplying_selected_branch_selects_anther() {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
let b = branches.iter().find(|b| b.id == b_id).unwrap();
@ -42,7 +42,7 @@ async fn unapplying_selected_branch_selects_anther() {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 2);
assert_eq!(branches[0].id, b.id);
@ -78,7 +78,7 @@ async fn deleting_selected_branch_selects_anther() {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
let b = branches.iter().find(|b| b.id == b_id).unwrap();
@ -92,7 +92,7 @@ async fn deleting_selected_branch_selects_anther() {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, b2.id);
@ -321,7 +321,7 @@ async fn hunks_distribution() {
std::fs::write(repository.path().join("file.txt"), "content").unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches[0].files.len(), 1);
controller
@ -335,7 +335,7 @@ async fn hunks_distribution() {
.await
.unwrap();
std::fs::write(repository.path().join("another_file.txt"), "content").unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches[0].files.len(), 1);
assert_eq!(branches[1].files.len(), 1);
}
@ -356,7 +356,7 @@ async fn applying_first_branch() {
std::fs::write(repository.path().join("file.txt"), "content").unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
controller
@ -368,7 +368,7 @@ async fn applying_first_branch() {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert!(branches[0].active);
assert!(branches[0].selected_for_changes);

View File

@ -75,7 +75,7 @@ mod go_back_to_integration {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
repository.checkout_commit(oid_one);
@ -85,7 +85,7 @@ mod go_back_to_integration {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, vbranch_id);
assert!(branches[0].active);
@ -111,7 +111,7 @@ mod go_back_to_integration {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert!(branches.is_empty());
repository.checkout_commit(oid_one);
@ -147,7 +147,7 @@ mod go_back_to_integration {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert!(branches.is_empty());
repository.checkout_commit(oid_one);
@ -184,7 +184,7 @@ mod go_back_to_integration {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert!(branches.is_empty());
repository.checkout_commit(oid_one);
@ -196,7 +196,7 @@ mod go_back_to_integration {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 0);
assert_eq!(base_two, base);
}
@ -221,7 +221,7 @@ mod go_back_to_integration {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert!(branches.is_empty());
repository.checkout_commit(oid_one);
@ -231,7 +231,7 @@ mod go_back_to_integration {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 0);
assert_eq!(base_two, base);
}

View File

@ -16,7 +16,7 @@ async fn unapply_with_data() {
std::fs::write(repository.path().join("file.txt"), "content").unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
controller
@ -26,7 +26,7 @@ async fn unapply_with_data() {
assert!(!repository.path().join("file.txt").exists());
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert!(!branches[0].active);
}
@ -60,7 +60,7 @@ async fn conflicting() {
std::fs::write(repository.path().join("file.txt"), "conflict").unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert!(branches[0].base_current);
assert!(branches[0].active);
@ -164,7 +164,7 @@ async fn delete_if_empty() {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
controller
@ -172,6 +172,6 @@ async fn delete_if_empty() {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 0);
}

View File

@ -50,7 +50,7 @@ mod unapplied_branch {
// branch should not be changed.
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert!(!branches[0].active);
@ -69,7 +69,7 @@ mod unapplied_branch {
.apply_virtual_branch(project_id, &branch_id)
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert!(branches[0].active);
@ -136,7 +136,7 @@ mod unapplied_branch {
// should not change the branch.
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert!(!branches[0].active);
@ -155,7 +155,7 @@ mod unapplied_branch {
.apply_virtual_branch(project_id, &branch_id)
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert!(branches[0].active);
@ -227,7 +227,7 @@ mod unapplied_branch {
// should not change the branch.
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert!(!branches[0].active);
@ -246,7 +246,7 @@ mod unapplied_branch {
.apply_virtual_branch(project_id, &branch_id)
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert!(branches[0].active);
@ -315,7 +315,7 @@ mod unapplied_branch {
// should rebase upstream, and leave uncommited file as is
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert!(!branches[0].active);
@ -334,7 +334,7 @@ mod unapplied_branch {
.apply_virtual_branch(project_id, &branch_id)
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert!(branches[0].active);
@ -403,7 +403,7 @@ mod unapplied_branch {
// should not touch the branch
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert!(!branches[0].active);
@ -422,7 +422,7 @@ mod unapplied_branch {
.apply_virtual_branch(project_id, &branch_id)
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert!(branches[0].active);
@ -497,7 +497,7 @@ mod unapplied_branch {
// should update branch base
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert!(!branches[0].active);
@ -517,7 +517,7 @@ mod unapplied_branch {
.apply_virtual_branch(project_id, &branch_id)
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert!(branches[0].active);
@ -601,7 +601,7 @@ mod unapplied_branch {
// should remove integrated commit, but leave work
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert!(!branches[0].active);
@ -621,7 +621,7 @@ mod unapplied_branch {
.apply_virtual_branch(project_id, &branch_id)
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert!(branches[0].active);
@ -690,7 +690,7 @@ mod unapplied_branch {
// should remove identical branch
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 0);
}
}
@ -759,7 +759,7 @@ mod unapplied_branch {
controller.update_base_branch(project_id).await.unwrap();
// just removes integrated branch
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 0);
}
}
@ -811,7 +811,7 @@ mod applied_branch {
// should stash conflicting branch
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert!(!branches[0].active);
@ -830,7 +830,7 @@ mod applied_branch {
.apply_virtual_branch(project_id, &branch_id)
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert!(branches[0].active);
@ -892,7 +892,7 @@ mod applied_branch {
// should stash the branch.
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert!(!branches[0].active);
@ -911,7 +911,7 @@ mod applied_branch {
.apply_virtual_branch(project_id, &branch_id)
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert!(branches[0].active);
@ -978,7 +978,7 @@ mod applied_branch {
// should stash the branch.
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert!(!branches[0].active);
@ -997,7 +997,7 @@ mod applied_branch {
.apply_virtual_branch(project_id, &branch_id)
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert!(branches[0].active);
@ -1061,7 +1061,7 @@ mod applied_branch {
// should rebase upstream, and leave uncommited file as is
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert!(!branches[0].active);
@ -1080,7 +1080,7 @@ mod applied_branch {
.apply_virtual_branch(project_id, &branch_id)
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert!(branches[0].active);
@ -1144,7 +1144,7 @@ mod applied_branch {
// should merge upstream, and leave uncommited file as is.
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert!(!branches[0].active);
@ -1163,7 +1163,7 @@ mod applied_branch {
.apply_virtual_branch(project_id, &branch_id)
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert!(branches[0].active);
@ -1244,7 +1244,7 @@ mod applied_branch {
// rebases branch, since the branch is pushed and force pushing is
// allowed
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert!(branches[0].active);
@ -1323,7 +1323,7 @@ mod applied_branch {
// creates a merge commit, since the branch is pushed
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert!(branches[0].active);
@ -1391,7 +1391,7 @@ mod applied_branch {
// just rebases branch
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert!(branches[0].active);
@ -1409,7 +1409,7 @@ mod applied_branch {
.apply_virtual_branch(project_id, &branch_id)
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert!(branches[0].active);
@ -1492,7 +1492,7 @@ mod applied_branch {
// should remove integrated commit, but leave non integrated work as is
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert!(branches[0].active);
@ -1511,7 +1511,7 @@ mod applied_branch {
.apply_virtual_branch(project_id, &branch_id)
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert!(branches[0].active);
@ -1614,7 +1614,7 @@ mod applied_branch {
// removes integrated commit, leaves non commited work as is
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert!(!branches[0].active);
@ -1628,7 +1628,7 @@ mod applied_branch {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert!(branches[0].active);
assert!(branches[0].conflicted);
@ -1706,7 +1706,7 @@ mod applied_branch {
// removes integrated commit, leaves non commited work as is
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert!(branches[0].active);
@ -1721,7 +1721,7 @@ mod applied_branch {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert!(branches[0].active);
assert!(!branches[0].conflicted);
@ -1788,7 +1788,7 @@ mod applied_branch {
// removes integrated commit, leaves non commited work as is
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].id, branch_id);
assert!(branches[0].active);
@ -1803,7 +1803,7 @@ mod applied_branch {
.await
.unwrap();
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 1);
assert!(branches[0].active);
assert!(!branches[0].conflicted);
@ -1858,7 +1858,7 @@ mod applied_branch {
// just removes integrated branch
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 0);
}
}
@ -1922,7 +1922,7 @@ mod applied_branch {
controller.update_base_branch(project_id).await.unwrap();
// just removes integrated branch
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
let (branches, _) = controller.list_virtual_branches(project_id).await.unwrap();
assert_eq!(branches.len(), 0);
}
}

View File

@ -54,7 +54,7 @@ async fn detect_upstream_commits() {
{
// should correctly detect pushed commits
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
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);
@ -135,7 +135,7 @@ async fn detect_integrated_commits() {
{
// should correctly detect pushed commits
let (branches, _, _) = controller.list_virtual_branches(project_id).await.unwrap();
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);

View File

@ -1,521 +0,0 @@
use gitbutler_core::{git::diff, virtual_branches::context::hunk_with_context};
#[test]
fn replace_line_mid_file() {
let hunk_diff = r#"@@ -8 +8 @@ default = ["serde", "rusqlite"]
-serde = ["dep:serde", "uuid/serde"]
+SERDE = ["dep:serde", "uuid/serde"]
"#;
let with_ctx = hunk_with_context(
hunk_diff,
8,
8,
false,
3,
&file_lines(),
diff::ChangeType::Added,
);
let expected = r#"@@ -5,7 +5,7 @@
[features]
default = ["serde", "rusqlite"]
-serde = ["dep:serde", "uuid/serde"]
+SERDE = ["dep:serde", "uuid/serde"]
rusqlite = ["dep:rusqlite"]
[dependencies]
"#;
assert_eq!(with_ctx.diff.replace("\n \n", "\n\n"), expected);
assert_eq!(with_ctx.old_start, 5);
assert_eq!(with_ctx.old_lines, 7);
assert_eq!(with_ctx.new_start, 5);
assert_eq!(with_ctx.new_lines, 7);
}
#[test]
fn replace_line_top_file() {
let hunk_diff = r#"@@ -2 +2 @@
-name = "gitbutler-core"
+NAME = "gitbutler-core"
"#;
let with_ctx = hunk_with_context(
hunk_diff,
2,
2,
false,
3,
&file_lines(),
diff::ChangeType::Added,
);
assert_eq!(
with_ctx.diff.replace("\n \n", "\n\n"),
r#"@@ -1,5 +1,5 @@
[package]
-name = "gitbutler-core"
+NAME = "gitbutler-core"
version = "0.0.0"
edition = "2021"
"#
);
assert_eq!(with_ctx.old_start, 1);
assert_eq!(with_ctx.old_lines, 5);
assert_eq!(with_ctx.new_start, 1);
assert_eq!(with_ctx.new_lines, 5);
}
#[test]
fn replace_line_start_file() {
let hunk_diff = "@@ -1 +1 @@
-[package]
+[PACKAGE]
";
let with_ctx = hunk_with_context(
hunk_diff,
1,
1,
false,
3,
&file_lines(),
diff::ChangeType::Added,
);
assert_eq!(
with_ctx.diff.replace("\n \n", "\n\n"),
r#"@@ -1,4 +1,4 @@
-[package]
+[PACKAGE]
name = "gitbutler-core"
version = "0.0.0"
edition = "2021"
"#
);
assert_eq!(with_ctx.old_start, 1);
assert_eq!(with_ctx.old_lines, 4);
assert_eq!(with_ctx.new_start, 1);
assert_eq!(with_ctx.new_lines, 4);
}
#[test]
fn replace_line_bottom_file() {
let hunk_diff = "@@ -13 +13 @@
-serde = { workspace = true, optional = true }
+SERDE = { workspace = true, optional = true }
";
let with_ctx = hunk_with_context(
hunk_diff,
13,
13,
false,
3,
&file_lines(),
diff::ChangeType::Added,
);
assert_eq!(
with_ctx.diff.replace("\n \n", "\n\n"),
r#"@@ -10,5 +10,5 @@
[dependencies]
rusqlite = { workspace = true, optional = true }
-serde = { workspace = true, optional = true }
+SERDE = { workspace = true, optional = true }
uuid = { workspace = true, features = ["v4", "fast-rng"] }
"#
);
assert_eq!(with_ctx.old_start, 10);
assert_eq!(with_ctx.old_lines, 5);
assert_eq!(with_ctx.new_start, 10);
assert_eq!(with_ctx.new_lines, 5);
}
#[test]
fn replace_with_more_lines() {
let hunk_diff = r#"@@ -8 +8,4 @@
-serde = ["dep:serde", "uuid/serde"]
+one
+two
+three
+four
"#;
let with_ctx = hunk_with_context(
hunk_diff,
8,
8,
false,
3,
&file_lines(),
diff::ChangeType::Added,
);
assert_eq!(
with_ctx.diff.replace("\n \n", "\n\n"),
r#"@@ -5,7 +5,10 @@
[features]
default = ["serde", "rusqlite"]
-serde = ["dep:serde", "uuid/serde"]
+one
+two
+three
+four
rusqlite = ["dep:rusqlite"]
[dependencies]
"#
);
assert_eq!(with_ctx.old_start, 5);
assert_eq!(with_ctx.old_lines, 7);
assert_eq!(with_ctx.new_start, 5);
assert_eq!(with_ctx.new_lines, 10);
}
#[test]
fn replace_with_less_lines() {
let hunk_diff = r#"@@ -7,3 +7 @@
-default = ["serde", "rusqlite"]
-serde = ["dep:serde", "uuid/serde"]
-rusqlite = ["dep:rusqlite"]
+foo = ["foo"]
"#;
let with_ctx = hunk_with_context(
hunk_diff,
7,
7,
false,
3,
&file_lines(),
diff::ChangeType::Added,
);
assert_eq!(
with_ctx.diff.replace("\n \n", "\n\n"),
r#"@@ -4,9 +4,7 @@
edition = "2021"
[features]
-default = ["serde", "rusqlite"]
-serde = ["dep:serde", "uuid/serde"]
-rusqlite = ["dep:rusqlite"]
+foo = ["foo"]
[dependencies]
rusqlite = { workspace = true, optional = true }
"#
);
assert_eq!(with_ctx.old_start, 4);
assert_eq!(with_ctx.old_lines, 9);
assert_eq!(with_ctx.new_start, 4);
assert_eq!(with_ctx.new_lines, 7);
}
#[test]
fn empty_string_doesnt_panic() {
let hunk_diff = "";
let with_ctx = hunk_with_context(
hunk_diff,
1,
1,
false,
3,
&file_lines(),
diff::ChangeType::Added,
);
assert_eq!(with_ctx.diff, "");
}
#[test]
fn removed_file() {
let hunk_diff = r#"@@ -1,14 +0,0 @@
-[package]
-name = "gitbutler-core"
-version = "0.0.0"
-edition = "2021"
-
-[features]
-default = ["serde", "rusqlite"]
-serde = ["dep:serde", "uuid/serde"]
-rusqlite = ["dep:rusqlite"]
-
-[dependencies]
-rusqlite = { workspace = true, optional = true }
-serde = { workspace = true, optional = true }
-uuid = { workspace = true, features = ["v4", "fast-rng"] }
"#;
let with_ctx = hunk_with_context(
hunk_diff,
1,
0,
false,
3,
&file_lines(),
diff::ChangeType::Added,
);
assert_eq!(with_ctx.diff.replace("\n \n", "\n\n"), hunk_diff);
assert_eq!(with_ctx.old_start, 1);
assert_eq!(with_ctx.old_lines, 14);
assert_eq!(with_ctx.new_start, 0);
assert_eq!(with_ctx.new_lines, 0);
}
#[test]
fn new_file() {
let hunk_diff = "@@ -0,0 +1,5 @@
+line 1
+line 2
+line 3
+line 4
+line 5
";
let with_ctx = hunk_with_context(
hunk_diff,
0,
1,
false,
3,
&Vec::new(),
diff::ChangeType::Added,
);
assert_eq!(with_ctx.diff.replace("\n \n", "\n\n"), hunk_diff);
assert_eq!(with_ctx.old_start, 0);
assert_eq!(with_ctx.old_lines, 0);
assert_eq!(with_ctx.new_start, 1);
assert_eq!(with_ctx.new_lines, 5);
}
#[test]
fn only_add_lines() {
let hunk_diff = "@@ -8,0 +9,3 @@
+one
+two
+three
";
let with_ctx = hunk_with_context(
hunk_diff,
8,
9,
false,
3,
&file_lines(),
diff::ChangeType::Added,
);
let expected = r#"@@ -6,6 +6,9 @@
[features]
default = ["serde", "rusqlite"]
serde = ["dep:serde", "uuid/serde"]
+one
+two
+three
rusqlite = ["dep:rusqlite"]
[dependencies]
"#;
assert_eq!(with_ctx.diff.replace("\n \n", "\n\n"), expected);
assert_eq!(with_ctx.old_start, 6);
assert_eq!(with_ctx.old_lines, 6);
assert_eq!(with_ctx.new_start, 6);
assert_eq!(with_ctx.new_lines, 9);
}
#[test]
fn only_add_lines_with_additions_below() {
let hunk_diff = "@@ -8,0 +13,3 @@
+one
+two
+three
";
let with_ctx = hunk_with_context(
hunk_diff,
8,
13,
false,
3,
&file_lines(),
diff::ChangeType::Added,
);
let expected = r#"@@ -6,6 +10,9 @@
[features]
default = ["serde", "rusqlite"]
serde = ["dep:serde", "uuid/serde"]
+one
+two
+three
rusqlite = ["dep:rusqlite"]
[dependencies]
"#;
assert_eq!(with_ctx.diff.replace("\n \n", "\n\n"), expected);
assert_eq!(with_ctx.old_start, 6);
assert_eq!(with_ctx.old_lines, 6);
assert_eq!(with_ctx.new_start, 10);
assert_eq!(with_ctx.new_lines, 9);
}
#[test]
fn only_remove_lines() {
let hunk_diff = r#"@@ -7,3 +6,0 @@
-default = ["serde", "rusqlite"]
-serde = ["dep:serde", "uuid/serde"]
-rusqlite = ["dep:rusqlite"]
"#;
let expected = r#"@@ -4,9 +4,6 @@
edition = "2021"
[features]
-default = ["serde", "rusqlite"]
-serde = ["dep:serde", "uuid/serde"]
-rusqlite = ["dep:rusqlite"]
[dependencies]
rusqlite = { workspace = true, optional = true }
"#;
let with_ctx = hunk_with_context(
hunk_diff,
7,
6,
false,
3,
&file_lines(),
diff::ChangeType::Added,
);
assert_eq!(with_ctx.diff.replace("\n \n", "\n\n"), expected);
assert_eq!(with_ctx.old_start, 4);
assert_eq!(with_ctx.old_lines, 9);
assert_eq!(with_ctx.new_start, 4);
assert_eq!(with_ctx.new_lines, 6);
}
#[test]
fn only_remove_lines_with_additions_below() {
let hunk_diff = r#"@@ -7,3 +10,0 @@
-default = ["serde", "rusqlite"]
-serde = ["dep:serde", "uuid/serde"]
-rusqlite = ["dep:rusqlite"]
"#;
let expected = r#"@@ -4,9 +8,6 @@
edition = "2021"
[features]
-default = ["serde", "rusqlite"]
-serde = ["dep:serde", "uuid/serde"]
-rusqlite = ["dep:rusqlite"]
[dependencies]
rusqlite = { workspace = true, optional = true }
"#;
let with_ctx = hunk_with_context(
hunk_diff,
7,
10,
false,
3,
&file_lines(),
diff::ChangeType::Added,
);
assert_eq!(with_ctx.diff.replace("\n \n", "\n\n"), expected);
assert_eq!(with_ctx.old_start, 4);
assert_eq!(with_ctx.old_lines, 9);
assert_eq!(with_ctx.new_start, 8);
assert_eq!(with_ctx.new_lines, 6);
}
#[test]
fn weird_testcase() {
let hunk_diff = "@@ -11,2 +10,0 @@
-
- @waiting_users = User.where(approved: false).count
";
let with_ctx = hunk_with_context(
hunk_diff,
11,
10,
false,
3,
&file_lines_2(),
diff::ChangeType::Added,
);
let expected = "@@ -8,8 +8,6 @@
.order(:created_at)
.page params[:page]
@total = @registrations.total_count
-
- @waiting_users = User.where(approved: false).count
end
def invite
";
assert_eq!(with_ctx.diff.replace("\n \n", "\n\n"), expected);
assert_eq!(with_ctx.old_start, 8);
assert_eq!(with_ctx.old_lines, 8);
assert_eq!(with_ctx.new_start, 8);
assert_eq!(with_ctx.new_lines, 6);
}
#[test]
fn new_line_added() {
let hunk_diff = "@@ -2,0 +3 @@ alias(
+ newstuff
";
let with_ctx = hunk_with_context(
hunk_diff,
2,
3,
false,
3,
&file_lines_3(),
diff::ChangeType::Added,
);
let expected = r#"@@ -1,4 +1,5 @@
alias(
name = "rdeps",
+ newstuff
actual = "//java/com/videlov/rdeps:rdeps",
)
"#;
assert_eq!(with_ctx.diff, expected);
}
fn file_lines() -> Vec<&'static str> {
let file_lines_before = r#"[package]
name = "gitbutler-core"
version = "0.0.0"
edition = "2021"
[features]
default = ["serde", "rusqlite"]
serde = ["dep:serde", "uuid/serde"]
rusqlite = ["dep:rusqlite"]
[dependencies]
rusqlite = { workspace = true, optional = true }
serde = { workspace = true, optional = true }
uuid = { workspace = true, features = ["v4", "fast-rng"] }
"#;
file_lines_before.lines().collect::<Vec<_>>()
}
fn file_lines_2() -> Vec<&'static str> {
let file_lines_before = r#"class Admin::WaitingController < Admin::AdminController
def index
@registrations = Registration.where(invited_at: nil)
if params[:q]
@registrations = @registrations.where("email LIKE ?", "%#{params[:q]}%")
end
@registrations = @registrations.includes(:invite_code)
.order(:created_at)
.page params[:page]
@total = @registrations.total_count
@waiting_users = User.where(approved: false).count
end
def invite
if params[:id]
@registrations = Registration.where(id: params[:id])
"#;
file_lines_before.lines().collect::<Vec<_>>()
}
fn file_lines_3() -> Vec<&'static str> {
let file_lines_before = r#"alias(
name = "rdeps",
actual = "//java/com/videlov/rdeps:rdeps",
)
"#;
file_lines_before.lines().collect::<Vec<_>>()
}

View File

@ -1,6 +1,5 @@
use gitbutler_core::virtual_branches::Branch;
mod context;
mod file_ownership;
mod hunk;
mod ownership;

View File

@ -58,8 +58,7 @@ fn commit_on_branch_then_change_file_then_get_status() -> Result<()> {
"line0\nline1\nline2\nline3\nline4\n",
)?;
let (branches, _, _) =
virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let (branches, _) = virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let branch = &branches[0];
assert_eq!(branch.files.len(), 1);
assert_eq!(branch.commits.len(), 0);
@ -77,8 +76,7 @@ fn commit_on_branch_then_change_file_then_get_status() -> Result<()> {
)?;
// status (no files)
let (branches, _, _) =
virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let (branches, _) = virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let branch = &branches[0];
assert_eq!(branch.files.len(), 0);
assert_eq!(branch.commits.len(), 1);
@ -89,8 +87,7 @@ fn commit_on_branch_then_change_file_then_get_status() -> Result<()> {
)?;
// should have just the last change now, the other line is committed
let (branches, _, _) =
virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let (branches, _) = virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let branch = &branches[0];
assert_eq!(branch.files.len(), 1);
assert_eq!(branch.commits.len(), 1);
@ -144,7 +141,7 @@ fn signed_commit() -> Result<()> {
false,
)?;
let (branches, _, _) =
let (branches, _) =
virtual_branches::list_virtual_branches(gb_repository, project_repository).unwrap();
let commit_id = &branches[0].commits[0].id;
let commit_obj = project_repository.git_repository.find_commit(*commit_id)?;
@ -211,8 +208,7 @@ fn track_binary_files() -> Result<()> {
let mut file = std::fs::File::create(Path::new(&project.path).join("image.bin"))?;
file.write_all(&image_data)?;
let (branches, _, _) =
virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let (branches, _) = virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let branch = &branches[0];
assert_eq!(branch.files.len(), 2);
let img_file = &branch
@ -239,7 +235,7 @@ fn track_binary_files() -> Result<()> {
)?;
// status (no files)
let (branches, _, _) =
let (branches, _) =
virtual_branches::list_virtual_branches(gb_repository, project_repository).unwrap();
let commit_id = &branches[0].commits[0].id;
let commit_obj = project_repository.git_repository.find_commit(*commit_id)?;
@ -269,7 +265,7 @@ fn track_binary_files() -> Result<()> {
false,
)?;
let (branches, _, _) =
let (branches, _) =
virtual_branches::list_virtual_branches(gb_repository, project_repository).unwrap();
let commit_id = &branches[0].commits[0].id;
// get tree from commit_id
@ -945,8 +941,7 @@ fn merge_vbranch_upstream_clean_rebase() -> Result<()> {
.context("failed to write target branch after push")?;
// create the branch
let (branches, _, _) =
virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let (branches, _) = virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let branch1 = &branches[0];
assert_eq!(branch1.files.len(), 1);
assert_eq!(branch1.commits.len(), 1);
@ -960,8 +955,7 @@ fn merge_vbranch_upstream_clean_rebase() -> Result<()> {
None,
)?;
let (branches, _, _) =
virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let (branches, _) = virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let branch1 = &branches[0];
let contents = std::fs::read(Path::new(&project.path).join(file_path))?;
@ -1078,8 +1072,7 @@ fn merge_vbranch_upstream_conflict() -> Result<()> {
.context("failed to write target branch after push")?;
// create the branch
let (branches, _, _) =
virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let (branches, _) = virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let branch1 = &branches[0];
assert_eq!(branch1.files.len(), 1);
@ -1088,8 +1081,7 @@ fn merge_vbranch_upstream_conflict() -> Result<()> {
merge_virtual_branch_upstream(gb_repository, project_repository, &branch1.id, None, None)?;
let (branches, _, _) =
virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let (branches, _) = virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let branch1 = &branches[0];
let contents = std::fs::read(Path::new(&project.path).join(file_path))?;
@ -1109,8 +1101,7 @@ fn merge_vbranch_upstream_conflict() -> Result<()> {
)?;
// make gb see the conflict resolution
let (branches, _, _) =
virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let (branches, _) = virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
assert!(branches[0].conflicted);
// commit the merge resolution
@ -1125,8 +1116,7 @@ fn merge_vbranch_upstream_conflict() -> Result<()> {
false,
)?;
let (branches, _, _) =
virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let (branches, _) = virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let branch1 = &branches[0];
assert!(!branch1.conflicted);
assert_eq!(branch1.files.len(), 0);
@ -1167,8 +1157,7 @@ fn unapply_ownership_partial() -> Result<()> {
)
.expect("failed to create virtual branch");
let (branches, _, _) =
virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let (branches, _) = virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].files.len(), 1);
assert_eq!(branches[0].ownership.claims.len(), 1);
@ -1186,8 +1175,7 @@ fn unapply_ownership_partial() -> Result<()> {
)
.unwrap();
let (branches, _, _) =
virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let (branches, _) = virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
assert_eq!(branches.len(), 1);
assert_eq!(branches[0].files.len(), 0);
assert_eq!(branches[0].ownership.claims.len(), 0);
@ -1259,8 +1247,7 @@ fn unapply_branch() -> Result<()> {
let contents = std::fs::read(Path::new(&project.path).join(file_path2))?;
assert_eq!("line5\nline6\n", String::from_utf8(contents)?);
let (branches, _, _) =
virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let (branches, _) = virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
assert_eq!(branch.files.len(), 1);
assert!(branch.active);
@ -1272,8 +1259,7 @@ fn unapply_branch() -> Result<()> {
let contents = std::fs::read(Path::new(&project.path).join(file_path2))?;
assert_eq!("line5\nline6\n", String::from_utf8(contents)?);
let (branches, _, _) =
virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let (branches, _) = virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
assert_eq!(branch.files.len(), 1);
assert!(!branch.active);
@ -1287,8 +1273,7 @@ fn unapply_branch() -> Result<()> {
let contents = std::fs::read(Path::new(&project.path).join(file_path2))?;
assert_eq!("line5\nline6\n", String::from_utf8(contents)?);
let (branches, _, _) =
virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let (branches, _) = virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
assert_eq!(branch.files.len(), 1);
assert!(branch.active);
@ -1534,8 +1519,7 @@ fn detect_mergeable_branch() -> Result<()> {
};
branch_writer.write(&mut branch4)?;
let (branches, _, _) =
virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let (branches, _) = virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
assert_eq!(branches.len(), 4);
let branch1 = &branches.iter().find(|b| b.id == branch1_id).unwrap();
@ -1720,8 +1704,7 @@ fn upstream_integrated_vbranch() -> Result<()> {
false,
)?;
let (branches, _, _) =
virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let (branches, _) = virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let branch1 = &branches.iter().find(|b| b.id == branch1_id).unwrap();
assert!(branch1.commits.iter().any(|c| c.is_integrated));
@ -1769,8 +1752,7 @@ fn 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",
)?;
let (branches, _, _) =
virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let (branches, _) = virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
assert_eq!(branch.files.len(), 1);
@ -1789,8 +1771,7 @@ fn commit_same_hunk_twice() -> Result<()> {
false,
)?;
let (branches, _, _) =
virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let (branches, _) = virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
assert_eq!(branch.files.len(), 0, "no files expected");
@ -1810,8 +1791,7 @@ fn 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",
)?;
let (branches, _, _) =
virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let (branches, _) = virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
assert_eq!(branch.files.len(), 1, "one file should be changed");
@ -1828,8 +1808,7 @@ fn commit_same_hunk_twice() -> Result<()> {
false,
)?;
let (branches, _, _) =
virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let (branches, _) = virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
assert_eq!(
@ -1875,8 +1854,7 @@ fn 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",
)?;
let (branches, _, _) =
virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let (branches, _) = virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
assert_eq!(branch.files.len(), 1);
@ -1895,8 +1873,7 @@ fn commit_same_file_twice() -> Result<()> {
false,
)?;
let (branches, _, _) =
virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let (branches, _) = virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
assert_eq!(branch.files.len(), 0, "no files expected");
@ -1916,8 +1893,7 @@ fn 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",
)?;
let (branches, _, _) =
virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let (branches, _) = virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
assert_eq!(branch.files.len(), 1, "one file should be changed");
@ -1934,8 +1910,7 @@ fn commit_same_file_twice() -> Result<()> {
false,
)?;
let (branches, _, _) =
virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let (branches, _) = virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
assert_eq!(
@ -1981,8 +1956,7 @@ fn 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",
)?;
let (branches, _, _) =
virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let (branches, _) = virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
assert_eq!(branch.files.len(), 1);
@ -2001,8 +1975,7 @@ fn commit_partial_by_hunk() -> Result<()> {
false,
)?;
let (branches, _, _) =
virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let (branches, _) = virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
assert_eq!(branch.files.len(), 1);
@ -2022,8 +1995,7 @@ fn commit_partial_by_hunk() -> Result<()> {
false,
)?;
let (branches, _, _) =
virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let (branches, _) = virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let branch = &branches.iter().find(|b| b.id == branch1_id).unwrap();
assert_eq!(branch.files.len(), 0);
@ -2088,8 +2060,7 @@ fn commit_partial_by_file() -> Result<()> {
false,
)?;
let (branches, _, _) =
virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let (branches, _) = virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let branch1 = &branches.iter().find(|b| b.id == branch1_id).unwrap();
// branch one test.txt has just the 1st and 3rd hunks applied
@ -2163,8 +2134,7 @@ fn commit_add_and_delete_files() -> Result<()> {
false,
)?;
let (branches, _, _) =
virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let (branches, _) = virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let branch1 = &branches.iter().find(|b| b.id == branch1_id).unwrap();
// branch one test.txt has just the 1st and 3rd hunks applied
@ -2236,8 +2206,7 @@ fn commit_executable_and_symlinks() -> Result<()> {
false,
)?;
let (branches, _, _) =
virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let (branches, _) = virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
let branch1 = &branches.iter().find(|b| b.id == branch1_id).unwrap();
let commit = &branch1.commits[0].id;
@ -2337,7 +2306,7 @@ fn verify_branch_commits_to_integration() -> Result<()> {
verify_branch(gb_repository, project_repository).unwrap();
// one virtual branch with two commits was created
let (virtual_branches, _, _) =
let (virtual_branches, _) =
virtual_branches::list_virtual_branches(gb_repository, project_repository)?;
assert_eq!(virtual_branches.len(), 1);

View File

@ -57,24 +57,11 @@ pub mod commands {
handle: AppHandle,
project_id: ProjectId,
) -> Result<VirtualBranches, Error> {
let (branches, uses_diff_context, skipped_files) = handle
let (branches, skipped_files) = handle
.state::<Controller>()
.list_virtual_branches(&project_id)
.await?;
// Migration: If use_diff_context is not already set and if there are no vbranches, set use_diff_context to true
let has_active_branches = branches.iter().any(|branch| branch.active);
if !uses_diff_context && !has_active_branches {
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 branches = proxy.proxy_virtual_branches(branches).await;
Ok(VirtualBranches {

View File

@ -211,7 +211,7 @@ impl Handler {
.list_virtual_branches(&project_id)
.await
{
Ok((branches, _, skipped_files)) => {
Ok((branches, skipped_files)) => {
let branches = self.assets_proxy.proxy_virtual_branches(branches).await;
self.emit_app_event(&app_events::Event::virtual_branches(
project_id,