mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-07-14 23:50:29 +03:00
Rename 'list_branches' to convey more meaning
This commit is contained in:
parent
ec4a555b75
commit
64414fc438
@ -79,7 +79,7 @@ impl Project {
|
||||
let mut branches_tree_builder = repo.treebuilder(None)?;
|
||||
let mut head_tree_ids = Vec::new();
|
||||
|
||||
for branch in vb_state.list_branches()? {
|
||||
for branch in vb_state.list_branches_in_workspace()? {
|
||||
head_tree_ids.push(branch.tree);
|
||||
|
||||
// commits in virtual branches (tree and commit data)
|
||||
@ -685,7 +685,7 @@ fn lines_since_snapshot(project: &Project, repo: &git2::Repository) -> Result<us
|
||||
return Ok(0);
|
||||
};
|
||||
|
||||
let vbranches = project.virtual_branches().list_branches()?;
|
||||
let vbranches = project.virtual_branches().list_branches_in_workspace()?;
|
||||
let mut lines_changed = 0;
|
||||
let dirty_branches = vbranches.iter().filter(|b| !b.ownership.claims.is_empty());
|
||||
for branch in dirty_branches {
|
||||
@ -782,7 +782,7 @@ fn tree_from_applied_vbranches(
|
||||
let vbs_from_toml: crate::virtual_branches::VirtualBranchesState =
|
||||
toml::from_str(from_utf8(vb_toml_blob.content())?)?;
|
||||
let applied_branch_trees: Vec<git2::Oid> = vbs_from_toml
|
||||
.list_branches()?
|
||||
.list_branches_in_workspace()?
|
||||
.iter()
|
||||
.map(|b| b.tree)
|
||||
.collect();
|
||||
|
@ -63,7 +63,7 @@ fn go_back_to_integration(
|
||||
|
||||
let vb_state = project_repository.project().virtual_branches();
|
||||
let virtual_branches = vb_state
|
||||
.list_branches()
|
||||
.list_branches_in_workspace()
|
||||
.context("failed to read virtual branches")?;
|
||||
|
||||
let target_commit = project_repository
|
||||
|
@ -43,7 +43,7 @@ pub fn get_workspace_head(
|
||||
let repo: &git2::Repository = project_repo.repo();
|
||||
let vb_state = project_repo.project().virtual_branches();
|
||||
|
||||
let virtual_branches = vb_state.list_branches()?;
|
||||
let virtual_branches = vb_state.list_branches_in_workspace()?;
|
||||
|
||||
let target_commit = repo.find_commit(target.sha)?;
|
||||
let mut workspace_tree = target_commit.tree()?;
|
||||
@ -170,7 +170,7 @@ pub fn update_gitbutler_integration(
|
||||
|
||||
// get all virtual branches, we need to try to update them all
|
||||
let virtual_branches = vb_state
|
||||
.list_branches()
|
||||
.list_branches_in_workspace()
|
||||
.context("failed to list virtual branches")?;
|
||||
|
||||
let integration_commit =
|
||||
|
@ -23,10 +23,10 @@ pub struct VirtualBranches {
|
||||
}
|
||||
|
||||
impl VirtualBranches {
|
||||
/// Lists all virtual branches.
|
||||
/// Lists all virtual branches that are in the user's workspace.
|
||||
///
|
||||
/// Errors if the file cannot be read or written.
|
||||
pub fn list_branches(&self) -> Result<Vec<Branch>> {
|
||||
pub fn list_branches_in_workspace(&self) -> Result<Vec<Branch>> {
|
||||
let branches: Vec<Branch> = self.branches.values().cloned().collect();
|
||||
Ok(branches)
|
||||
}
|
||||
@ -112,10 +112,10 @@ impl VirtualBranchesHandle {
|
||||
Ok(virtual_branches.branches.get(&id).cloned())
|
||||
}
|
||||
|
||||
/// Lists all virtual branches.
|
||||
/// Lists all virtual branches that are in the user's workspace.
|
||||
///
|
||||
/// Errors if the file cannot be read or written.
|
||||
pub fn list_branches(&self) -> Result<Vec<Branch>> {
|
||||
pub fn list_branches_in_workspace(&self) -> Result<Vec<Branch>> {
|
||||
let virtual_branches = self.read_file()?;
|
||||
let branches: Vec<Branch> = virtual_branches.branches.values().cloned().collect();
|
||||
Ok(branches)
|
||||
@ -141,7 +141,7 @@ impl VirtualBranchesHandle {
|
||||
|
||||
pub fn update_ordering(&self) -> Result<()> {
|
||||
let succeeded = self
|
||||
.list_branches()?
|
||||
.list_branches_in_workspace()?
|
||||
.iter()
|
||||
.sorted_by_key(|branch| branch.order)
|
||||
.enumerate()
|
||||
@ -161,7 +161,7 @@ impl VirtualBranchesHandle {
|
||||
pub fn next_order_index(&self) -> Result<usize> {
|
||||
self.update_ordering()?;
|
||||
let order = self
|
||||
.list_branches()?
|
||||
.list_branches_in_workspace()?
|
||||
.iter()
|
||||
.sorted_by_key(|branch| branch.order)
|
||||
.collect::<Vec<&Branch>>()
|
||||
|
@ -245,7 +245,7 @@ pub fn unapply_ownership(
|
||||
let default_target = vb_state.get_default_target()?;
|
||||
|
||||
let virtual_branches = vb_state
|
||||
.list_branches()
|
||||
.list_branches_in_workspace()
|
||||
.context("failed to read virtual branches")?;
|
||||
|
||||
let integration_commit_id = get_workspace_head(&vb_state, project_repository)?;
|
||||
@ -781,7 +781,7 @@ pub fn create_virtual_branch(
|
||||
.context("failed to find defaut target commit tree")?;
|
||||
|
||||
let mut all_virtual_branches = vb_state
|
||||
.list_branches()
|
||||
.list_branches_in_workspace()
|
||||
.context("failed to read virtual branches")?;
|
||||
|
||||
let name = dedup(
|
||||
@ -806,7 +806,7 @@ pub fn create_virtual_branch(
|
||||
let selected_for_changes = if let Some(selected_for_changes) = create.selected_for_changes {
|
||||
if selected_for_changes {
|
||||
for mut other_branch in vb_state
|
||||
.list_branches()
|
||||
.list_branches_in_workspace()
|
||||
.context("failed to read virtual branches")?
|
||||
{
|
||||
other_branch.selected_for_changes = None;
|
||||
@ -1095,7 +1095,7 @@ pub fn update_branch(
|
||||
|
||||
if let Some(name) = &branch_update.name {
|
||||
let all_virtual_branches = vb_state
|
||||
.list_branches()
|
||||
.list_branches_in_workspace()
|
||||
.context("failed to read virtual branches")?;
|
||||
|
||||
project_repository.delete_branch_reference(&branch)?;
|
||||
@ -1139,7 +1139,7 @@ pub fn update_branch(
|
||||
if let Some(selected_for_changes) = branch_update.selected_for_changes {
|
||||
branch.selected_for_changes = if selected_for_changes {
|
||||
for mut other_branch in vb_state
|
||||
.list_branches()
|
||||
.list_branches_in_workspace()
|
||||
.context("failed to read virtual branches")?
|
||||
.into_iter()
|
||||
.filter(|b| b.id != branch.id)
|
||||
@ -1180,7 +1180,7 @@ pub fn delete_branch(
|
||||
let base_tree = target_commit.tree().context("failed to get target tree")?;
|
||||
|
||||
let virtual_branches = vb_state
|
||||
.list_branches()
|
||||
.list_branches_in_workspace()
|
||||
.context("failed to read virtual branches")?;
|
||||
|
||||
let (applied_statuses, _) = get_applied_status(
|
||||
@ -1230,7 +1230,7 @@ pub fn delete_branch(
|
||||
|
||||
fn ensure_selected_for_changes(vb_state: &VirtualBranchesHandle) -> Result<()> {
|
||||
let mut virtual_branches = vb_state
|
||||
.list_branches()
|
||||
.list_branches_in_workspace()
|
||||
.context("failed to list branches")?;
|
||||
|
||||
if virtual_branches.is_empty() {
|
||||
@ -1264,7 +1264,7 @@ fn set_ownership(
|
||||
}
|
||||
|
||||
let virtual_branches = vb_state
|
||||
.list_branches()
|
||||
.list_branches_in_workspace()
|
||||
.context("failed to read virtual branches")?;
|
||||
|
||||
let mut claim_outcomes =
|
||||
@ -1354,7 +1354,7 @@ pub fn get_status_by_branch(
|
||||
let default_target = vb_state.get_default_target()?;
|
||||
|
||||
let virtual_branches = vb_state
|
||||
.list_branches()
|
||||
.list_branches_in_workspace()
|
||||
.context("failed to read virtual branches")?;
|
||||
|
||||
let (applied_status, skipped_files) = get_applied_status(
|
||||
@ -2545,7 +2545,7 @@ pub fn amend(
|
||||
let vb_state = project_repository.project().virtual_branches();
|
||||
|
||||
let virtual_branches = vb_state
|
||||
.list_branches()
|
||||
.list_branches_in_workspace()
|
||||
.context("failed to read virtual branches")?;
|
||||
|
||||
if !virtual_branches.iter().any(|b| b.id == branch_id) {
|
||||
@ -3060,7 +3060,7 @@ pub fn move_commit(
|
||||
let vb_state = project_repository.project().virtual_branches();
|
||||
|
||||
let applied_branches = vb_state
|
||||
.list_branches()
|
||||
.list_branches_in_workspace()
|
||||
.context("failed to read virtual branches")?;
|
||||
|
||||
if !applied_branches.iter().any(|b| b.id == target_branch_id) {
|
||||
@ -3238,7 +3238,7 @@ pub fn create_virtual_branch_from_branch(
|
||||
if merge_index.has_conflicts() {
|
||||
// currently we can only deal with the merge problem branch
|
||||
for branch in vb_state
|
||||
.list_branches()?
|
||||
.list_branches_in_workspace()?
|
||||
.iter()
|
||||
.filter(|branch| branch.id != branch_id)
|
||||
{
|
||||
@ -3477,7 +3477,7 @@ pub fn create_virtual_branch_from_branch(
|
||||
let head_commit_tree = head_commit.tree().context("failed to find tree")?;
|
||||
|
||||
let virtual_branches = vb_state
|
||||
.list_branches()
|
||||
.list_branches_in_workspace()
|
||||
.context("failed to read virtual branches")?
|
||||
.into_iter()
|
||||
.collect::<Vec<branch::Branch>>();
|
||||
|
@ -259,11 +259,23 @@ async fn restores_gitbutler_integration() -> anyhow::Result<()> {
|
||||
.set_base_branch(project, &"refs/remotes/origin/master".parse()?)
|
||||
.await?;
|
||||
|
||||
assert_eq!(project.virtual_branches().list_branches()?.len(), 0);
|
||||
assert_eq!(
|
||||
project
|
||||
.virtual_branches()
|
||||
.list_branches_in_workspace()?
|
||||
.len(),
|
||||
0
|
||||
);
|
||||
let branch_id = controller
|
||||
.create_virtual_branch(project, &branch::BranchCreateRequest::default())
|
||||
.await?;
|
||||
assert_eq!(project.virtual_branches().list_branches()?.len(), 1);
|
||||
assert_eq!(
|
||||
project
|
||||
.virtual_branches()
|
||||
.list_branches_in_workspace()?
|
||||
.len(),
|
||||
1
|
||||
);
|
||||
|
||||
// create commit
|
||||
fs::write(repository.path().join("file.txt"), "content")?;
|
||||
@ -313,7 +325,7 @@ async fn restores_gitbutler_integration() -> anyhow::Result<()> {
|
||||
"head now points to the first commit, it's not commit 2 anymore"
|
||||
);
|
||||
|
||||
let vbranches = project.virtual_branches().list_branches()?;
|
||||
let vbranches = project.virtual_branches().list_branches_in_workspace()?;
|
||||
assert_eq!(
|
||||
vbranches.len(),
|
||||
1,
|
||||
|
@ -73,7 +73,7 @@ fn empty_iterator() -> Result<()> {
|
||||
let Case { project, .. } = &suite.new_case();
|
||||
|
||||
let vb_state = project.virtual_branches();
|
||||
let iter = vb_state.list_branches()?;
|
||||
let iter = vb_state.list_branches_in_workspace()?;
|
||||
|
||||
assert_eq!(iter.len(), 0);
|
||||
|
||||
@ -94,7 +94,7 @@ fn iterate_all() -> Result<()> {
|
||||
let branch_3 = new_test_branch();
|
||||
vb_state.set_branch(branch_3.clone())?;
|
||||
|
||||
let iter = vb_state.list_branches()?;
|
||||
let iter = vb_state.list_branches_in_workspace()?;
|
||||
assert_eq!(iter.len(), 3);
|
||||
assert!(iter.contains(&branch_1));
|
||||
assert!(iter.contains(&branch_2));
|
||||
|
@ -263,7 +263,9 @@ fn create_branch_in_the_middle() -> Result<()> {
|
||||
.expect("failed to create virtual branch");
|
||||
|
||||
let vb_state = project_repository.project().virtual_branches();
|
||||
let mut branches = vb_state.list_branches().expect("failed to read branches");
|
||||
let mut branches = vb_state
|
||||
.list_branches_in_workspace()
|
||||
.expect("failed to read branches");
|
||||
branches.sort_by_key(|b| b.order);
|
||||
assert_eq!(branches.len(), 3);
|
||||
assert_eq!(branches[0].name, "Virtual branch");
|
||||
@ -286,7 +288,9 @@ fn create_branch_no_arguments() -> Result<()> {
|
||||
.expect("failed to create virtual branch");
|
||||
|
||||
let vb_state = project_repository.project().virtual_branches();
|
||||
let branches = vb_state.list_branches().expect("failed to read branches");
|
||||
let branches = vb_state
|
||||
.list_branches_in_workspace()
|
||||
.expect("failed to read branches");
|
||||
assert_eq!(branches.len(), 1);
|
||||
assert_eq!(branches[0].name, "Virtual branch");
|
||||
assert_eq!(branches[0].ownership, BranchOwnershipClaims::default());
|
||||
|
Loading…
Reference in New Issue
Block a user