From de200c8e207382855a27f6dea08e25dd57562b78 Mon Sep 17 00:00:00 2001 From: Kiril Videlov Date: Tue, 9 Jul 2024 01:14:28 +0200 Subject: [PATCH] move reference module from core to its own crate --- Cargo.lock | 19 +++++++++++ Cargo.toml | 2 ++ crates/gitbutler-branch/Cargo.toml | 1 + crates/gitbutler-branch/src/branch.rs | 15 ++++----- crates/gitbutler-branch/src/lib.rs | 4 +-- crates/gitbutler-branch/src/target.rs | 7 ++-- crates/gitbutler-branchstate/Cargo.toml | 1 + crates/gitbutler-branchstate/src/state.rs | 5 +-- crates/gitbutler-core/src/git/mod.rs | 3 -- crates/gitbutler-reference/Cargo.toml | 13 ++++++++ .../mod.rs => gitbutler-reference/src/lib.rs} | 0 .../src}/refname/error.rs | 0 .../src}/refname/local.rs | 0 .../src}/refname/mod.rs | 0 .../src}/refname/remote.rs | 0 .../src}/refname/virtual.rs | 0 crates/gitbutler-repo/Cargo.toml | 1 + crates/gitbutler-repo/src/repository.rs | 9 ++--- crates/gitbutler-repo/src/repository_ext.rs | 3 +- crates/gitbutler-sync/Cargo.toml | 1 + crates/gitbutler-sync/src/cloud.rs | 6 ++-- crates/gitbutler-tauri/Cargo.toml | 1 + crates/gitbutler-tauri/src/app.rs | 4 +-- crates/gitbutler-tauri/src/commands.rs | 4 +-- .../gitbutler-tauri/src/virtual_branches.rs | 9 ++--- crates/gitbutler-testsupport/Cargo.toml | 1 + .../gitbutler-testsupport/src/test_project.rs | 33 +++++++++---------- crates/gitbutler-virtual/Cargo.toml | 1 + crates/gitbutler-virtual/src/base.rs | 10 +++--- crates/gitbutler-virtual/src/controller.rs | 10 +++--- crates/gitbutler-virtual/src/remote.rs | 21 ++++++------ crates/gitbutler-virtual/src/virtual.rs | 28 ++++++++-------- crates/gitbutler-virtual/tests/extra/mod.rs | 13 ++++---- .../virtual_branches/apply_virtual_branch.rs | 6 ++-- .../convert_to_real_branch.rs | 4 ++- .../create_virtual_branch_from_branch.rs | 10 +++--- .../tests/virtual_branches/mod.rs | 3 +- .../virtual_branches/selected_for_changes.rs | 2 +- .../tests/virtual_branches/set_base_branch.rs | 4 ++- .../virtual_branches/update_base_branch.rs | 12 +++---- .../tests/virtual_branches/verify_branch.rs | 4 ++- crates/gitbutler-watcher/Cargo.toml | 1 + crates/gitbutler-watcher/src/handler.rs | 9 ++--- 43 files changed, 162 insertions(+), 118 deletions(-) create mode 100644 crates/gitbutler-reference/Cargo.toml rename crates/{gitbutler-core/src/git/reference/mod.rs => gitbutler-reference/src/lib.rs} (100%) rename crates/{gitbutler-core/src/git/reference => gitbutler-reference/src}/refname/error.rs (100%) rename crates/{gitbutler-core/src/git/reference => gitbutler-reference/src}/refname/local.rs (100%) rename crates/{gitbutler-core/src/git/reference => gitbutler-reference/src}/refname/mod.rs (100%) rename crates/{gitbutler-core/src/git/reference => gitbutler-reference/src}/refname/remote.rs (100%) rename crates/{gitbutler-core/src/git/reference => gitbutler-reference/src}/refname/virtual.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 8418b7d74..6b18dad7c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2110,6 +2110,7 @@ dependencies = [ "bstr", "git2", "gitbutler-core", + "gitbutler-reference", "hex", "itertools 0.13.0", "lazy_static", @@ -2126,6 +2127,7 @@ dependencies = [ "gitbutler-branch", "gitbutler-core", "gitbutler-project", + "gitbutler-reference", "itertools 0.13.0", "serde", "toml 0.8.14", @@ -2304,6 +2306,17 @@ dependencies = [ "uuid", ] +[[package]] +name = "gitbutler-reference" +version = "0.0.0" +dependencies = [ + "git2", + "gitbutler-core", + "regex", + "serde", + "thiserror", +] + [[package]] name = "gitbutler-repo" version = "0.0.0" @@ -2317,6 +2330,7 @@ dependencies = [ "gitbutler-core", "gitbutler-git", "gitbutler-project", + "gitbutler-reference", "gitbutler-testsupport", "gitbutler-user", "log", @@ -2341,6 +2355,7 @@ dependencies = [ "gitbutler-core", "gitbutler-oplog", "gitbutler-project", + "gitbutler-reference", "gitbutler-user", "itertools 0.13.0", "tracing", @@ -2364,6 +2379,7 @@ dependencies = [ "gitbutler-feedback", "gitbutler-oplog", "gitbutler-project", + "gitbutler-reference", "gitbutler-repo", "gitbutler-testsupport", "gitbutler-user", @@ -2403,6 +2419,7 @@ dependencies = [ "gitbutler-command-context", "gitbutler-core", "gitbutler-project", + "gitbutler-reference", "gitbutler-repo", "gitbutler-user", "gitbutler-virtual", @@ -2443,6 +2460,7 @@ dependencies = [ "gitbutler-git", "gitbutler-oplog", "gitbutler-project", + "gitbutler-reference", "gitbutler-repo", "gitbutler-testsupport", "gitbutler-user", @@ -2475,6 +2493,7 @@ dependencies = [ "gitbutler-notify-debouncer", "gitbutler-oplog", "gitbutler-project", + "gitbutler-reference", "gitbutler-sync", "gitbutler-user", "gitbutler-virtual", diff --git a/Cargo.toml b/Cargo.toml index 9315a8192..1b3b32133 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ members = [ "crates/gitbutler-project", "crates/gitbutler-user", "crates/gitbutler-branch", + "crates/gitbutler-reference", ] resolver = "2" @@ -47,6 +48,7 @@ gitbutler-config = { path = "crates/gitbutler-config" } gitbutler-project = { path = "crates/gitbutler-project" } gitbutler-user = { path = "crates/gitbutler-user" } gitbutler-branch = { path = "crates/gitbutler-branch" } +gitbutler-reference = { path = "crates/gitbutler-reference" } [profile.release] codegen-units = 1 # Compile crates one after another so the compiler can optimize better diff --git a/crates/gitbutler-branch/Cargo.toml b/crates/gitbutler-branch/Cargo.toml index 5c801b6d4..e7ba7d673 100644 --- a/crates/gitbutler-branch/Cargo.toml +++ b/crates/gitbutler-branch/Cargo.toml @@ -9,6 +9,7 @@ publish = false anyhow = "1.0.86" git2.workspace = true gitbutler-core.workspace = true +gitbutler-reference.workspace = true itertools = "0.13" serde = { workspace = true, features = ["std"]} bstr = "1.9.1" diff --git a/crates/gitbutler-branch/src/branch.rs b/crates/gitbutler-branch/src/branch.rs index 841503e13..e686d7e04 100644 --- a/crates/gitbutler-branch/src/branch.rs +++ b/crates/gitbutler-branch/src/branch.rs @@ -1,13 +1,10 @@ use anyhow::Result; +use gitbutler_reference::{normalize_branch_name, Refname, RemoteRefname, VirtualRefname}; use serde::{Deserialize, Serialize}; -use gitbutler_core::{ - git::{self}, - id::Id, -}; +use gitbutler_core::id::Id; use crate::ownership::BranchOwnershipClaims; -use gitbutler_core::git::normalize_branch_name; pub type BranchId = Id; @@ -20,8 +17,8 @@ pub struct Branch { pub id: BranchId, pub name: String, pub notes: String, - pub source_refname: Option, - pub upstream: Option, + pub source_refname: Option, + pub upstream: Option, // upstream_head is the last commit on we've pushed to the upstream branch #[serde(with = "gitbutler_core::serde::oid_opt", default)] pub upstream_head: Option, @@ -78,12 +75,12 @@ where } impl Branch { - pub fn refname(&self) -> git::VirtualRefname { + pub fn refname(&self) -> VirtualRefname { self.into() } } -impl From<&Branch> for git::VirtualRefname { +impl From<&Branch> for VirtualRefname { fn from(value: &Branch) -> Self { Self { branch: normalize_branch_name(&value.name), diff --git a/crates/gitbutler-branch/src/lib.rs b/crates/gitbutler-branch/src/lib.rs index 60aa24c00..b2961533c 100644 --- a/crates/gitbutler-branch/src/lib.rs +++ b/crates/gitbutler-branch/src/lib.rs @@ -8,8 +8,8 @@ pub mod target; use lazy_static::lazy_static; lazy_static! { - pub static ref GITBUTLER_INTEGRATION_REFERENCE: gitbutler_core::git::LocalRefname = - gitbutler_core::git::LocalRefname::new("gitbutler/integration", None); + pub static ref GITBUTLER_INTEGRATION_REFERENCE: gitbutler_reference::LocalRefname = + gitbutler_reference::LocalRefname::new("gitbutler/integration", None); } pub const GITBUTLER_INTEGRATION_COMMIT_AUTHOR_NAME: &str = "GitButler"; diff --git a/crates/gitbutler-branch/src/target.rs b/crates/gitbutler-branch/src/target.rs index 9b6d09ffc..2c605bdee 100644 --- a/crates/gitbutler-branch/src/target.rs +++ b/crates/gitbutler-branch/src/target.rs @@ -1,10 +1,9 @@ +use gitbutler_reference::RemoteRefname; use serde::{ser::SerializeStruct, Deserialize, Deserializer, Serialize, Serializer}; -use gitbutler_core::git; - #[derive(Debug, PartialEq, Clone)] pub struct Target { - pub branch: git::RemoteRefname, + pub branch: RemoteRefname, pub remote_url: String, pub sha: git2::Oid, pub push_remote_name: Option, @@ -43,7 +42,7 @@ impl<'de> serde::Deserialize<'de> for Target { .map_err(|x| serde::de::Error::custom(x.message()))?; let target = Target { - branch: git::RemoteRefname::new(&target_data.remote_name, &target_data.branch_name), + branch: RemoteRefname::new(&target_data.remote_name, &target_data.branch_name), remote_url: target_data.remote_url, sha, push_remote_name: target_data.push_remote_name, diff --git a/crates/gitbutler-branchstate/Cargo.toml b/crates/gitbutler-branchstate/Cargo.toml index c982e814c..ff35c36b4 100644 --- a/crates/gitbutler-branchstate/Cargo.toml +++ b/crates/gitbutler-branchstate/Cargo.toml @@ -13,3 +13,4 @@ toml = "0.8.13" serde = { workspace = true, features = ["std"]} gitbutler-project.workspace = true gitbutler-branch.workspace = true +gitbutler-reference.workspace = true diff --git a/crates/gitbutler-branchstate/src/state.rs b/crates/gitbutler-branchstate/src/state.rs index 828a12ae5..08a671acb 100644 --- a/crates/gitbutler-branchstate/src/state.rs +++ b/crates/gitbutler-branchstate/src/state.rs @@ -9,8 +9,9 @@ use gitbutler_branch::{ branch::{Branch, BranchId}, target::Target, }; -use gitbutler_core::{error::Code, fs::read_toml_file_or_default, git}; +use gitbutler_core::{error::Code, fs::read_toml_file_or_default}; use gitbutler_project::Project; +use gitbutler_reference::Refname; use itertools::Itertools; use serde::{Deserialize, Serialize}; @@ -125,7 +126,7 @@ impl VirtualBranchesHandle { pub fn find_by_source_refname_where_not_in_workspace( &self, - refname: &git::Refname, + refname: &Refname, ) -> Result> { self.list_all_branches().map(|branches| { branches.into_iter().find(|branch| { diff --git a/crates/gitbutler-core/src/git/mod.rs b/crates/gitbutler-core/src/git/mod.rs index 2fce72bb0..d79ee1c4e 100644 --- a/crates/gitbutler-core/src/git/mod.rs +++ b/crates/gitbutler-core/src/git/mod.rs @@ -1,6 +1,3 @@ -mod reference; -pub use reference::*; - mod url; pub use self::url::*; diff --git a/crates/gitbutler-reference/Cargo.toml b/crates/gitbutler-reference/Cargo.toml new file mode 100644 index 000000000..075b74b13 --- /dev/null +++ b/crates/gitbutler-reference/Cargo.toml @@ -0,0 +1,13 @@ +[package] +name = "gitbutler-reference" +version = "0.0.0" +edition = "2021" +authors = ["GitButler "] +publish = false + +[dependencies] +regex = "1.10" +git2.workspace = true +gitbutler-core.workspace = true +serde = { workspace = true, features = ["std"]} +thiserror.workspace = true diff --git a/crates/gitbutler-core/src/git/reference/mod.rs b/crates/gitbutler-reference/src/lib.rs similarity index 100% rename from crates/gitbutler-core/src/git/reference/mod.rs rename to crates/gitbutler-reference/src/lib.rs diff --git a/crates/gitbutler-core/src/git/reference/refname/error.rs b/crates/gitbutler-reference/src/refname/error.rs similarity index 100% rename from crates/gitbutler-core/src/git/reference/refname/error.rs rename to crates/gitbutler-reference/src/refname/error.rs diff --git a/crates/gitbutler-core/src/git/reference/refname/local.rs b/crates/gitbutler-reference/src/refname/local.rs similarity index 100% rename from crates/gitbutler-core/src/git/reference/refname/local.rs rename to crates/gitbutler-reference/src/refname/local.rs diff --git a/crates/gitbutler-core/src/git/reference/refname/mod.rs b/crates/gitbutler-reference/src/refname/mod.rs similarity index 100% rename from crates/gitbutler-core/src/git/reference/refname/mod.rs rename to crates/gitbutler-reference/src/refname/mod.rs diff --git a/crates/gitbutler-core/src/git/reference/refname/remote.rs b/crates/gitbutler-reference/src/refname/remote.rs similarity index 100% rename from crates/gitbutler-core/src/git/reference/refname/remote.rs rename to crates/gitbutler-reference/src/refname/remote.rs diff --git a/crates/gitbutler-core/src/git/reference/refname/virtual.rs b/crates/gitbutler-reference/src/refname/virtual.rs similarity index 100% rename from crates/gitbutler-core/src/git/reference/refname/virtual.rs rename to crates/gitbutler-reference/src/refname/virtual.rs diff --git a/crates/gitbutler-repo/Cargo.toml b/crates/gitbutler-repo/Cargo.toml index 64e9f2209..198a0e8bf 100644 --- a/crates/gitbutler-repo/Cargo.toml +++ b/crates/gitbutler-repo/Cargo.toml @@ -22,6 +22,7 @@ gitbutler-command-context.workspace = true gitbutler-config.workspace = true gitbutler-project.workspace = true gitbutler-branch.workspace = true +gitbutler-reference.workspace = true [[test]] name="repo" diff --git a/crates/gitbutler-repo/src/repository.rs b/crates/gitbutler-repo/src/repository.rs index 1d33e867f..3ef4d7327 100644 --- a/crates/gitbutler-repo/src/repository.rs +++ b/crates/gitbutler-repo/src/repository.rs @@ -9,6 +9,7 @@ use gitbutler_core::{ git::{self, CommitHeadersV2}, ssh, }; +use gitbutler_reference::{Refname, RemoteRefname}; use crate::{askpass, Config}; use gitbutler_project::AuthKey; @@ -20,7 +21,7 @@ pub trait RepoActions { fn push( &self, head: &git2::Oid, - branch: &git::RemoteRefname, + branch: &RemoteRefname, with_force: bool, credentials: &Helper, refspec: Option, @@ -58,7 +59,7 @@ impl RepoActions for ProjectRepo { askpass: Option>, ) -> Result<()> { let target_branch_refname = - git::Refname::from_str(&format!("refs/remotes/{}/{}", remote_name, branch_name))?; + Refname::from_str(&format!("refs/remotes/{}/{}", remote_name, branch_name))?; let branch = self .repo() .find_branch_by_refname(&target_branch_refname)? @@ -70,7 +71,7 @@ impl RepoActions for ProjectRepo { let branch_name = format!("test-push-{now}"); let refname = - git::RemoteRefname::from_str(&format!("refs/remotes/{remote_name}/{branch_name}",))?; + RemoteRefname::from_str(&format!("refs/remotes/{remote_name}/{branch_name}",))?; match self.push(&commit_id, &refname, false, credentials, None, askpass) { Ok(()) => Ok(()), @@ -248,7 +249,7 @@ impl RepoActions for ProjectRepo { fn push( &self, head: &git2::Oid, - branch: &git::RemoteRefname, + branch: &RemoteRefname, with_force: bool, credentials: &Helper, refspec: Option, diff --git a/crates/gitbutler-repo/src/repository_ext.rs b/crates/gitbutler-repo/src/repository_ext.rs index 19ffd2edc..316da371d 100644 --- a/crates/gitbutler-repo/src/repository_ext.rs +++ b/crates/gitbutler-repo/src/repository_ext.rs @@ -2,12 +2,13 @@ use anyhow::{anyhow, bail, Context, Result}; use bstr::BString; use git2::{BlameOptions, Repository, Tree}; use gitbutler_config::git::{GbConfig, GitConfig}; +use gitbutler_reference::{Refname, RemoteRefname}; use std::{path::Path, process::Stdio, str}; use tracing::instrument; use gitbutler_core::error::Code; -use gitbutler_core::git::{CommitBuffer, CommitHeadersV2, Refname, RemoteRefname}; +use gitbutler_core::git::{CommitBuffer, CommitHeadersV2}; use std::io::Write; #[cfg(unix)] use std::os::unix::fs::PermissionsExt; diff --git a/crates/gitbutler-sync/Cargo.toml b/crates/gitbutler-sync/Cargo.toml index 641b10db8..0aa2667a3 100644 --- a/crates/gitbutler-sync/Cargo.toml +++ b/crates/gitbutler-sync/Cargo.toml @@ -17,3 +17,4 @@ gitbutler-command-context.workspace = true gitbutler-project.workspace = true gitbutler-user.workspace = true gitbutler-branch.workspace = true +gitbutler-reference.workspace = true diff --git a/crates/gitbutler-sync/src/cloud.rs b/crates/gitbutler-sync/src/cloud.rs index 1adfcfe45..b2c0a24dc 100644 --- a/crates/gitbutler-sync/src/cloud.rs +++ b/crates/gitbutler-sync/src/cloud.rs @@ -7,12 +7,12 @@ use gitbutler_branch::target::Target; use gitbutler_branchstate::VirtualBranchesAccess; use gitbutler_command_context::ProjectRepo; use gitbutler_core::error::Code; -use gitbutler_core::git; use gitbutler_core::git::Url; use gitbutler_core::id::Id; use gitbutler_oplog::oplog::Oplog; use gitbutler_project as projects; use gitbutler_project::{CodePushState, Project}; +use gitbutler_reference::Refname; use gitbutler_user as users; use itertools::Itertools; @@ -138,7 +138,7 @@ fn batch_rev_walk( Ok(oids) } -fn collect_refs(project_repository: &ProjectRepo) -> anyhow::Result> { +fn collect_refs(project_repository: &ProjectRepo) -> anyhow::Result> { Ok(project_repository .repo() .references_glob("refs/*")? @@ -161,7 +161,7 @@ fn push_all_refs( .filter(|r| { matches!( r, - git::Refname::Remote(_) | git::Refname::Virtual(_) | git::Refname::Local(_) + Refname::Remote(_) | Refname::Virtual(_) | Refname::Local(_) ) }) .map(|r| format!("+{}:{}", r, r)) diff --git a/crates/gitbutler-tauri/Cargo.toml b/crates/gitbutler-tauri/Cargo.toml index eb910bd10..4645f2307 100644 --- a/crates/gitbutler-tauri/Cargo.toml +++ b/crates/gitbutler-tauri/Cargo.toml @@ -57,6 +57,7 @@ gitbutler-config.workspace = true gitbutler-project.workspace = true gitbutler-user.workspace = true gitbutler-branch.workspace = true +gitbutler-reference.workspace = true open = "5" [dependencies.tauri] diff --git a/crates/gitbutler-tauri/src/app.rs b/crates/gitbutler-tauri/src/app.rs index 94c1b6b9a..d8349d228 100644 --- a/crates/gitbutler-tauri/src/app.rs +++ b/crates/gitbutler-tauri/src/app.rs @@ -1,9 +1,9 @@ use anyhow::{Context, Result}; use gitbutler_branch::branch::BranchId; use gitbutler_command_context::ProjectRepo; -use gitbutler_core::git; use gitbutler_project as projects; use gitbutler_project::ProjectId; +use gitbutler_reference::RemoteRefname; use gitbutler_repo::{credentials::Helper, RepoActions, RepositoryExt}; use gitbutler_virtual::conflicts; @@ -25,7 +25,7 @@ impl App { Ok(()) } - pub fn git_remote_branches(&self, project_id: ProjectId) -> Result> { + pub fn git_remote_branches(&self, project_id: ProjectId) -> Result> { let project = self.projects.get(project_id)?; let project_repository = ProjectRepo::open(&project)?; project_repository.repo().remote_branches() diff --git a/crates/gitbutler-tauri/src/commands.rs b/crates/gitbutler-tauri/src/commands.rs index 598b1f9c6..2d7a0b284 100644 --- a/crates/gitbutler-tauri/src/commands.rs +++ b/crates/gitbutler-tauri/src/commands.rs @@ -1,5 +1,5 @@ -use gitbutler_core::git; use gitbutler_project::ProjectId; +use gitbutler_reference::RemoteRefname; use gitbutler_repo::credentials::Helper; use tauri::Manager; use tracing::instrument; @@ -12,7 +12,7 @@ use crate::error::Error; pub async fn git_remote_branches( handle: tauri::AppHandle, project_id: ProjectId, -) -> Result, Error> { +) -> Result, Error> { let app = handle.state::(); let branches = app.git_remote_branches(project_id)?; Ok(branches) diff --git a/crates/gitbutler-tauri/src/virtual_branches.rs b/crates/gitbutler-tauri/src/virtual_branches.rs index 85d55f318..6e89e668a 100644 --- a/crates/gitbutler-tauri/src/virtual_branches.rs +++ b/crates/gitbutler-tauri/src/virtual_branches.rs @@ -3,9 +3,10 @@ pub mod commands { use anyhow::{anyhow, Context}; use gitbutler_branch::branch::{BranchCreateRequest, BranchId, BranchUpdateRequest}; use gitbutler_branch::ownership::BranchOwnershipClaims; - use gitbutler_core::{error::Code, git, types::ReferenceName}; + use gitbutler_core::{error::Code, types::ReferenceName}; use gitbutler_project as projects; use gitbutler_project::ProjectId; + use gitbutler_reference::{Refname, RemoteRefname}; use gitbutler_virtual::assets; use gitbutler_virtual::base::BaseBranch; use gitbutler_virtual::files::RemoteBranchFile; @@ -76,7 +77,7 @@ pub mod commands { pub async fn create_virtual_branch_from_branch( handle: AppHandle, project_id: ProjectId, - branch: git::Refname, + branch: Refname, ) -> Result { let project = handle.state::().get(project_id)?; let branch_id = handle @@ -278,7 +279,7 @@ pub mod commands { pub async fn can_apply_remote_branch( handle: AppHandle, project_id: ProjectId, - branch: git::RemoteRefname, + branch: RemoteRefname, ) -> Result { let project = handle.state::().get(project_id)?; Ok(handle @@ -442,7 +443,7 @@ pub mod commands { pub async fn get_remote_branch_data( handle: tauri::AppHandle, project_id: ProjectId, - refname: git::Refname, + refname: Refname, ) -> Result { let project = handle.state::().get(project_id)?; let branch_data = handle diff --git a/crates/gitbutler-testsupport/Cargo.toml b/crates/gitbutler-testsupport/Cargo.toml index cf460eb6a..0e6feeff9 100644 --- a/crates/gitbutler-testsupport/Cargo.toml +++ b/crates/gitbutler-testsupport/Cargo.toml @@ -25,3 +25,4 @@ gitbutler-command-context.workspace = true gitbutler-project.workspace = true gitbutler-user.workspace = true gitbutler-branch.workspace = true +gitbutler-reference.workspace = true diff --git a/crates/gitbutler-testsupport/src/test_project.rs b/crates/gitbutler-testsupport/src/test_project.rs index 3fd8d669d..c4c7b6e99 100644 --- a/crates/gitbutler-testsupport/src/test_project.rs +++ b/crates/gitbutler-testsupport/src/test_project.rs @@ -2,6 +2,7 @@ use std::path::PathBuf; use std::{fs, path}; use gitbutler_core::git; +use gitbutler_reference::{LocalRefname, Refname}; use gitbutler_repo::RepositoryExt; use tempfile::TempDir; @@ -94,7 +95,7 @@ impl TestProject { self.local_repository.workdir().unwrap() } - pub fn push_branch(&self, branch: &git::LocalRefname) { + pub fn push_branch(&self, branch: &LocalRefname) { let mut origin = self.local_repository.find_remote("origin").unwrap(); origin.push(&[&format!("{branch}:{branch}")], None).unwrap(); } @@ -138,12 +139,10 @@ impl TestProject { .unwrap(); } - pub fn rebase_and_merge(&self, branch_name: &git::Refname) { - let branch_name: git::Refname = match branch_name { - git::Refname::Local(local) => format!("refs/heads/{}", local.branch()).parse().unwrap(), - git::Refname::Remote(remote) => { - format!("refs/heads/{}", remote.branch()).parse().unwrap() - } + pub fn rebase_and_merge(&self, branch_name: &Refname) { + let branch_name: Refname = match branch_name { + Refname::Local(local) => format!("refs/heads/{}", local.branch()).parse().unwrap(), + Refname::Remote(remote) => format!("refs/heads/{}", remote.branch()).parse().unwrap(), _ => "INVALID".parse().unwrap(), // todo }; let branch = self @@ -153,7 +152,7 @@ impl TestProject { let branch_commit = branch.unwrap().get().peel_to_commit().unwrap(); let master_branch = { - let name: git::Refname = "refs/heads/master".parse().unwrap(); + let name: Refname = "refs/heads/master".parse().unwrap(); self.remote_repository .find_branch_by_refname(&name) .unwrap() @@ -217,12 +216,10 @@ impl TestProject { } /// works like if we'd open and merge a PR on github. does not update local. - pub fn merge(&self, branch_name: &git::Refname) { - let branch_name: git::Refname = match branch_name { - git::Refname::Local(local) => format!("refs/heads/{}", local.branch()).parse().unwrap(), - git::Refname::Remote(remote) => { - format!("refs/heads/{}", remote.branch()).parse().unwrap() - } + pub fn merge(&self, branch_name: &Refname) { + let branch_name: Refname = match branch_name { + Refname::Local(local) => format!("refs/heads/{}", local.branch()).parse().unwrap(), + Refname::Remote(remote) => format!("refs/heads/{}", remote.branch()).parse().unwrap(), _ => "INVALID".parse().unwrap(), // todo }; let branch = self @@ -232,7 +229,7 @@ impl TestProject { let branch_commit = branch.as_ref().unwrap().get().peel_to_commit().unwrap(); let master_branch = { - let name: git::Refname = "refs/heads/master".parse().unwrap(); + let name: Refname = "refs/heads/master".parse().unwrap(); self.remote_repository .find_branch_by_refname(&name) .unwrap() @@ -295,8 +292,8 @@ impl TestProject { .unwrap(); } - pub fn checkout(&self, branch: &git::LocalRefname) { - let refname: git::Refname = branch.into(); + pub fn checkout(&self, branch: &LocalRefname) { + let refname: Refname = branch.into(); let head_commit = self .local_repository .head() @@ -342,7 +339,7 @@ impl TestProject { index.write().expect("failed to write index"); let oid = index.write_tree().expect("failed to write tree"); let signature = git2::Signature::now("test", "test@email.com").unwrap(); - let refname: git::Refname = head.name().unwrap().parse().unwrap(); + let refname: Refname = head.name().unwrap().parse().unwrap(); let repo: &git2::Repository = &self.local_repository; repo.commit_with_signature( Some(&refname), diff --git a/crates/gitbutler-virtual/Cargo.toml b/crates/gitbutler-virtual/Cargo.toml index 11305e975..1fc126a14 100644 --- a/crates/gitbutler-virtual/Cargo.toml +++ b/crates/gitbutler-virtual/Cargo.toml @@ -16,6 +16,7 @@ gitbutler-branchstate.workspace = true gitbutler-repo.workspace = true gitbutler-user.workspace = true gitbutler-branch.workspace = true +gitbutler-reference.workspace = true serde = { workspace = true, features = ["std"]} bstr = "1.9.1" diffy = "0.3.0" diff --git a/crates/gitbutler-virtual/src/base.rs b/crates/gitbutler-virtual/src/base.rs index 90930a194..1c30aac53 100644 --- a/crates/gitbutler-virtual/src/base.rs +++ b/crates/gitbutler-virtual/src/base.rs @@ -9,6 +9,7 @@ use gitbutler_branch::target::Target; use gitbutler_branchstate::{VirtualBranchesAccess, VirtualBranchesHandle}; use gitbutler_command_context::ProjectRepo; use gitbutler_project::FetchResult; +use gitbutler_reference::{Refname, RemoteRefname}; use gitbutler_repo::{LogUntil, RepoActions, RepositoryExt}; use serde::Serialize; @@ -20,7 +21,6 @@ use crate::remote::{commit_to_remote_commit, RemoteCommit}; use crate::VirtualBranchHunk; use gitbutler_branch::GITBUTLER_INTEGRATION_REFERENCE; use gitbutler_core::error::Marker; -use gitbutler_core::git; use gitbutler_repo::rebase::cherry_rebase; #[derive(Debug, Serialize, PartialEq, Clone)] @@ -115,7 +115,7 @@ fn go_back_to_integration( pub fn set_base_branch( project_repository: &ProjectRepo, - target_branch_ref: &git::RemoteRefname, + target_branch_ref: &RemoteRefname, ) -> Result { let repo = project_repository.repo(); @@ -174,7 +174,7 @@ pub fn set_base_branch( vb_state.set_default_target(target.clone())?; // TODO: make sure this is a real branch - let head_name: git::Refname = current_head + let head_name: Refname = current_head .name() .map(|name| name.parse().expect("libgit2 provides valid refnames")) .context("Failed to get HEAD reference name")?; @@ -208,12 +208,12 @@ pub fn set_base_branch( let now_ms = gitbutler_core::time::now_ms(); - let (upstream, upstream_head) = if let git::Refname::Local(head_name) = &head_name { + let (upstream, upstream_head) = if let Refname::Local(head_name) = &head_name { let upstream_name = target_branch_ref.with_branch(head_name.branch()); if upstream_name.eq(target_branch_ref) { (None, None) } else { - match repo.find_reference(&git::Refname::from(&upstream_name).to_string()) { + match repo.find_reference(&Refname::from(&upstream_name).to_string()) { Ok(upstream) => { let head = upstream .peel_to_commit() diff --git a/crates/gitbutler-virtual/src/controller.rs b/crates/gitbutler-virtual/src/controller.rs index e8dc84524..babe6d626 100644 --- a/crates/gitbutler-virtual/src/controller.rs +++ b/crates/gitbutler-virtual/src/controller.rs @@ -13,6 +13,7 @@ use gitbutler_oplog::{ snapshot::Snapshot, }; use gitbutler_project::{FetchResult, Project}; +use gitbutler_reference::{Refname, RemoteRefname}; use gitbutler_repo::{credentials::Helper, RepoActions, RepositoryExt}; use std::{path::Path, sync::Arc}; @@ -30,7 +31,6 @@ use super::r#virtual as branch; use crate::files::RemoteBranchFile; use gitbutler_branch::target; -use gitbutler_core::git; #[derive(Clone)] pub struct Controller { @@ -79,7 +79,7 @@ impl Controller { pub async fn can_apply_remote_branch( &self, project: &Project, - branch_name: &git::RemoteRefname, + branch_name: &RemoteRefname, ) -> Result { let project_repository = ProjectRepo::open(project)?; branch::is_remote_branch_mergeable(&project_repository, branch_name).map_err(Into::into) @@ -110,7 +110,7 @@ impl Controller { pub async fn create_virtual_branch_from_branch( &self, project: &Project, - branch: &git::Refname, + branch: &Refname, ) -> Result { self.permit(project.ignore_project_semaphore).await; @@ -136,7 +136,7 @@ impl Controller { pub async fn set_base_branch( &self, project: &Project, - target_branch: &git::RemoteRefname, + target_branch: &RemoteRefname, ) -> Result { let project_repository = ProjectRepo::open(project)?; let _ = project_repository @@ -397,7 +397,7 @@ impl Controller { pub async fn get_remote_branch_data( &self, project: &Project, - refname: &git::Refname, + refname: &Refname, ) -> Result { let project_repository = ProjectRepo::open(project)?; get_branch_data(&project_repository, refname) diff --git a/crates/gitbutler-virtual/src/remote.rs b/crates/gitbutler-virtual/src/remote.rs index f2fc25457..9161575b7 100644 --- a/crates/gitbutler-virtual/src/remote.rs +++ b/crates/gitbutler-virtual/src/remote.rs @@ -4,11 +4,12 @@ use anyhow::{Context, Result}; use bstr::BString; use gitbutler_branchstate::VirtualBranchesHandle; use gitbutler_command_context::ProjectRepo; +use gitbutler_reference::{Refname, RemoteRefname}; use gitbutler_repo::{LogUntil, RepoActions, RepositoryExt}; use serde::Serialize; use gitbutler_branch::target; -use gitbutler_core::git::{self, CommitExt}; +use gitbutler_core::git::CommitExt; use crate::author::Author; @@ -26,8 +27,8 @@ use crate::author::Author; pub struct RemoteBranch { #[serde(with = "gitbutler_core::serde::oid")] pub sha: git2::Oid, - pub name: git::Refname, - pub upstream: Option, + pub name: Refname, + pub upstream: Option, pub last_commit_timestamp_ms: Option, pub last_commit_author: Option, } @@ -37,8 +38,8 @@ pub struct RemoteBranch { pub struct RemoteBranchData { #[serde(with = "gitbutler_core::serde::oid")] pub sha: git2::Oid, - pub name: git::Refname, - pub upstream: Option, + pub name: Refname, + pub upstream: Option, pub behind: u32, pub commits: Vec, #[serde(with = "gitbutler_core::serde::oid_opt", default)] @@ -89,7 +90,7 @@ pub fn list_remote_branches(project_repository: &ProjectRepo) -> Result Result { let default_target = default_target(&project_repository.project().gb_dir())?; @@ -114,7 +115,7 @@ pub fn branch_to_remote_branch(branch: &git2::Branch) -> Result branch .get() @@ -122,7 +123,7 @@ pub fn branch_to_remote_branch(branch: &git2::Branch) -> Result; @@ -377,7 +375,7 @@ pub fn convert_to_real_branch( let vb_state = project_repository.project().virtual_branches(); let branch = repo.branch(&branch_name, &target_commit, true)?; - vbranch.source_refname = Some(git::Refname::try_from(&branch)?); + vbranch.source_refname = Some(Refname::try_from(&branch)?); vb_state.set_branch(vbranch.clone())?; build_metadata_commit(project_repository, vbranch, &branch)?; @@ -533,7 +531,7 @@ pub fn list_virtual_branches( update_conflict_markers(project_repository, &files)?; let upstream_branch = match branch.clone().upstream { - Some(upstream) => repo.find_branch_by_refname(&git::Refname::from(upstream))?, + Some(upstream) => repo.find_branch_by_refname(&Refname::from(upstream))?, None => None, }; @@ -1126,7 +1124,7 @@ pub fn update_branch( upstream_remote, normalize_branch_name(updated_upstream) ) - .parse::() + .parse::() .unwrap(); branch.upstream = Some(remote_branch); }; @@ -2135,7 +2133,7 @@ pub fn push( upstream_remote, normalize_branch_name(&vbranch.name) ) - .parse::() + .parse::() .context("failed to parse remote branch name")?; let remote_branches = project_repository.repo().remote_branches()?; @@ -2244,7 +2242,7 @@ fn is_commit_integrated( pub fn is_remote_branch_mergeable( project_repository: &ProjectRepo, - branch_name: &git::RemoteRefname, + branch_name: &RemoteRefname, ) -> Result { let vb_state = project_repository.project().virtual_branches(); @@ -3152,7 +3150,7 @@ pub fn move_commit( pub fn create_virtual_branch_from_branch( project_repository: &ProjectRepo, - upstream: &git::Refname, + upstream: &Refname, ) -> Result { fn apply_branch(project_repository: &ProjectRepo, branch_id: BranchId) -> Result { project_repository.assure_resolved()?; @@ -3395,12 +3393,12 @@ pub fn create_virtual_branch_from_branch( // only set upstream if it's not the default target let upstream_branch = match upstream { - git::Refname::Other(_) | git::Refname::Virtual(_) => { + Refname::Other(_) | Refname::Virtual(_) => { // we only support local or remote branches bail!("branch {upstream} must be a local or remote branch"); } - git::Refname::Remote(remote) => Some(remote.clone()), - git::Refname::Local(local) => local.remote().cloned(), + Refname::Remote(remote) => Some(remote.clone()), + Refname::Local(local) => local.remote().cloned(), }; let branch_name = upstream @@ -3416,7 +3414,7 @@ pub fn create_virtual_branch_from_branch( let default_target = vb_state.get_default_target()?; - if let git::Refname::Remote(remote_upstream) = upstream { + if let Refname::Remote(remote_upstream) = upstream { if default_target.branch == *remote_upstream { bail!("cannot create a branch from default target") } diff --git a/crates/gitbutler-virtual/tests/extra/mod.rs b/crates/gitbutler-virtual/tests/extra/mod.rs index c3eabca16..3afb7b6c7 100644 --- a/crates/gitbutler-virtual/tests/extra/mod.rs +++ b/crates/gitbutler-virtual/tests/extra/mod.rs @@ -18,6 +18,7 @@ use gitbutler_branch::{ }; use gitbutler_branchstate::VirtualBranchesAccess; use gitbutler_core::git::{self, CommitExt}; +use gitbutler_reference::{Refname, RemoteRefname}; use gitbutler_repo::RepositoryExt; use gitbutler_virtual::integration; use gitbutler_virtual::r#virtual as virtual_branches; @@ -692,7 +693,7 @@ fn commit_id_can_be_generated_or_specified() -> Result<()> { let oid = index.write_tree().expect("failed to write tree"); let signature = git2::Signature::now("test", "test@email.com").unwrap(); let head = repository.head().expect("failed to get head"); - let refname: git::Refname = head.name().unwrap().parse().unwrap(); + let refname: Refname = head.name().unwrap().parse().unwrap(); project_repository .repo() .commit_with_signature( @@ -789,7 +790,7 @@ fn merge_vbranch_upstream_clean_rebase() -> Result<()> { // Update integration commit integration::update_gitbutler_integration(&vb_state, project_repository)?; - let remote_branch: git::RemoteRefname = "refs/remotes/origin/master".parse().unwrap(); + let remote_branch: RemoteRefname = "refs/remotes/origin/master".parse().unwrap(); let mut branch = create_virtual_branch(project_repository, &BranchCreateRequest::default()) .expect("failed to create virtual branch"); branch.upstream = Some(remote_branch.clone()); @@ -886,7 +887,7 @@ async fn merge_vbranch_upstream_conflict() -> Result<()> { "line1\nline2\nline3\nline4\nupstream\nother side\n", )?; - let remote_branch: git::RemoteRefname = "refs/remotes/origin/master".parse().unwrap(); + let remote_branch: RemoteRefname = "refs/remotes/origin/master".parse().unwrap(); let mut branch = create_virtual_branch(project_repository, &BranchCreateRequest::default()) .expect("failed to create virtual branch"); branch.upstream = Some(remote_branch.clone()); @@ -1077,7 +1078,7 @@ fn unapply_branch() -> Result<()> { let branch1_id = virtual_branches::create_virtual_branch_from_branch( project_repository, - &git::Refname::try_from(&real_branch)?, + &Refname::try_from(&real_branch)?, )?; let contents = std::fs::read(Path::new(&project.path).join(file_path))?; assert_eq!( @@ -1165,7 +1166,7 @@ fn apply_unapply_added_deleted_files() -> Result<()> { create_virtual_branch_from_branch( project_repository, - &git::Refname::try_from(&real_branch_2).unwrap(), + &Refname::try_from(&real_branch_2).unwrap(), ) .unwrap(); @@ -1174,7 +1175,7 @@ fn apply_unapply_added_deleted_files() -> Result<()> { create_virtual_branch_from_branch( project_repository, - &git::Refname::try_from(&real_branch_3).unwrap(), + &Refname::try_from(&real_branch_3).unwrap(), ) .unwrap(); diff --git a/crates/gitbutler-virtual/tests/virtual_branches/apply_virtual_branch.rs b/crates/gitbutler-virtual/tests/virtual_branches/apply_virtual_branch.rs index 4ed349e9a..a1a09935e 100644 --- a/crates/gitbutler-virtual/tests/virtual_branches/apply_virtual_branch.rs +++ b/crates/gitbutler-virtual/tests/virtual_branches/apply_virtual_branch.rs @@ -1,3 +1,5 @@ +use gitbutler_reference::Refname; + use super::*; #[tokio::test] @@ -67,7 +69,7 @@ async fn rebase_commit() { let (branches, _) = controller.list_virtual_branches(project).await.unwrap(); assert_eq!(branches.len(), 0); - git::Refname::from_str(&unapplied_branch).unwrap() + Refname::from_str(&unapplied_branch).unwrap() }; { @@ -171,7 +173,7 @@ async fn rebase_work() { assert!(!repository.path().join("another_file.txt").exists()); assert!(!repository.path().join("file.txt").exists()); - git::Refname::from_str(&unapplied_branch).unwrap() + Refname::from_str(&unapplied_branch).unwrap() }; { diff --git a/crates/gitbutler-virtual/tests/virtual_branches/convert_to_real_branch.rs b/crates/gitbutler-virtual/tests/virtual_branches/convert_to_real_branch.rs index 5614dbd92..474e22022 100644 --- a/crates/gitbutler-virtual/tests/virtual_branches/convert_to_real_branch.rs +++ b/crates/gitbutler-virtual/tests/virtual_branches/convert_to_real_branch.rs @@ -1,3 +1,5 @@ +use gitbutler_reference::Refname; + use super::*; #[tokio::test] @@ -73,7 +75,7 @@ async fn conflicting() { .await .unwrap(); - git::Refname::from_str(&unapplied_branch).unwrap() + Refname::from_str(&unapplied_branch).unwrap() }; { diff --git a/crates/gitbutler-virtual/tests/virtual_branches/create_virtual_branch_from_branch.rs b/crates/gitbutler-virtual/tests/virtual_branches/create_virtual_branch_from_branch.rs index 3ef5951e0..4cc9ae2e2 100644 --- a/crates/gitbutler-virtual/tests/virtual_branches/create_virtual_branch_from_branch.rs +++ b/crates/gitbutler-virtual/tests/virtual_branches/create_virtual_branch_from_branch.rs @@ -1,3 +1,5 @@ +use gitbutler_reference::LocalRefname; + use super::*; #[tokio::test] @@ -131,7 +133,7 @@ async fn no_conflicts() { { // create a remote branch - let branch_name: git::LocalRefname = "refs/heads/branch".parse().unwrap(); + let branch_name: LocalRefname = "refs/heads/branch".parse().unwrap(); repository.checkout(&branch_name); fs::write(repository.path().join("file.txt"), "first").unwrap(); repository.commit_all("first"); @@ -170,7 +172,7 @@ async fn conflicts_with_uncommited() { { // create a remote branch - let branch_name: git::LocalRefname = "refs/heads/branch".parse().unwrap(); + let branch_name: LocalRefname = "refs/heads/branch".parse().unwrap(); repository.checkout(&branch_name); fs::write(repository.path().join("file.txt"), "first").unwrap(); repository.commit_all("first"); @@ -221,7 +223,7 @@ async fn conflicts_with_commited() { { // create a remote branch - let branch_name: git::LocalRefname = "refs/heads/branch".parse().unwrap(); + let branch_name: LocalRefname = "refs/heads/branch".parse().unwrap(); repository.checkout(&branch_name); fs::write(repository.path().join("file.txt"), "first").unwrap(); repository.commit_all("first"); @@ -333,7 +335,7 @@ async fn from_state_remote_branch() { { // create a remote branch - let branch_name: git::LocalRefname = "refs/heads/branch".parse().unwrap(); + let branch_name: LocalRefname = "refs/heads/branch".parse().unwrap(); repository.checkout(&branch_name); fs::write(repository.path().join("file.txt"), "branch commit").unwrap(); repository.commit_all("branch commit"); diff --git a/crates/gitbutler-virtual/tests/virtual_branches/mod.rs b/crates/gitbutler-virtual/tests/virtual_branches/mod.rs index 89cb95b8f..9c746dec2 100644 --- a/crates/gitbutler-virtual/tests/virtual_branches/mod.rs +++ b/crates/gitbutler-virtual/tests/virtual_branches/mod.rs @@ -5,6 +5,7 @@ use gitbutler_branch::branch; use gitbutler_core::error::Marker; use gitbutler_core::git; use gitbutler_project::{self as projects, Project, ProjectId}; +use gitbutler_reference::Refname; use gitbutler_virtual::Controller; use tempfile::TempDir; @@ -131,7 +132,7 @@ async fn resolve_conflict_flow() { let (branches, _) = controller.list_virtual_branches(project).await.unwrap(); assert_eq!(branches.len(), 0); - git::Refname::from_str(&unapplied_branches[0]).unwrap() + Refname::from_str(&unapplied_branches[0]).unwrap() }; let branch1_id = { diff --git a/crates/gitbutler-virtual/tests/virtual_branches/selected_for_changes.rs b/crates/gitbutler-virtual/tests/virtual_branches/selected_for_changes.rs index 763f66828..cb1f8ab76 100644 --- a/crates/gitbutler-virtual/tests/virtual_branches/selected_for_changes.rs +++ b/crates/gitbutler-virtual/tests/virtual_branches/selected_for_changes.rs @@ -373,7 +373,7 @@ async fn applying_first_branch() { .convert_to_real_branch(project, branches[0].id, Default::default()) .await .unwrap(); - let unapplied_branch = git::Refname::from_str(&unapplied_branch).unwrap(); + let unapplied_branch = Refname::from_str(&unapplied_branch).unwrap(); controller .create_virtual_branch_from_branch(project, &unapplied_branch) .await diff --git a/crates/gitbutler-virtual/tests/virtual_branches/set_base_branch.rs b/crates/gitbutler-virtual/tests/virtual_branches/set_base_branch.rs index dbbae9221..a741cc4bf 100644 --- a/crates/gitbutler-virtual/tests/virtual_branches/set_base_branch.rs +++ b/crates/gitbutler-virtual/tests/virtual_branches/set_base_branch.rs @@ -15,6 +15,8 @@ async fn success() { } mod error { + use gitbutler_reference::RemoteRefname; + use super::*; #[tokio::test] @@ -29,7 +31,7 @@ mod error { controller .set_base_branch( project, - &git::RemoteRefname::from_str("refs/remotes/origin/missing").unwrap(), + &RemoteRefname::from_str("refs/remotes/origin/missing").unwrap(), ) .await .unwrap_err() diff --git a/crates/gitbutler-virtual/tests/virtual_branches/update_base_branch.rs b/crates/gitbutler-virtual/tests/virtual_branches/update_base_branch.rs index 6804e94fc..4bfc4c998 100644 --- a/crates/gitbutler-virtual/tests/virtual_branches/update_base_branch.rs +++ b/crates/gitbutler-virtual/tests/virtual_branches/update_base_branch.rs @@ -48,7 +48,7 @@ mod applied_branch { let (branches, _) = controller.list_virtual_branches(project).await.unwrap(); assert_eq!(branches.len(), 0); - git::Refname::from_str(unapplied_branches[0].as_str()).unwrap() + Refname::from_str(unapplied_branches[0].as_str()).unwrap() }; { @@ -118,7 +118,7 @@ mod applied_branch { let (branches, _) = controller.list_virtual_branches(project).await.unwrap(); assert_eq!(branches.len(), 0); - git::Refname::from_str(unapplied_branches[0].as_str()).unwrap() + Refname::from_str(unapplied_branches[0].as_str()).unwrap() }; { @@ -194,7 +194,7 @@ mod applied_branch { let (branches, _) = controller.list_virtual_branches(project).await.unwrap(); assert_eq!(branches.len(), 0); - git::Refname::from_str(unapplied_branches[0].as_str()).unwrap() + Refname::from_str(unapplied_branches[0].as_str()).unwrap() }; { @@ -267,7 +267,7 @@ mod applied_branch { let (branches, _) = controller.list_virtual_branches(project).await.unwrap(); assert_eq!(branches.len(), 0); - git::Refname::from_str(unapplied_branches[0].as_str()).unwrap() + Refname::from_str(unapplied_branches[0].as_str()).unwrap() }; { @@ -340,7 +340,7 @@ mod applied_branch { let (branches, _) = controller.list_virtual_branches(project).await.unwrap(); assert_eq!(branches.len(), 0); - git::Refname::from_str(unapplied_branches[0].as_str()).unwrap() + Refname::from_str(unapplied_branches[0].as_str()).unwrap() }; { @@ -765,7 +765,7 @@ mod applied_branch { controller .create_virtual_branch_from_branch( project, - &git::Refname::from_str(unapplied_refname.as_str()).unwrap(), + &Refname::from_str(unapplied_refname.as_str()).unwrap(), ) .await .unwrap(); diff --git a/crates/gitbutler-virtual/tests/virtual_branches/verify_branch.rs b/crates/gitbutler-virtual/tests/virtual_branches/verify_branch.rs index 7c7085ef9..f856be34d 100644 --- a/crates/gitbutler-virtual/tests/virtual_branches/verify_branch.rs +++ b/crates/gitbutler-virtual/tests/virtual_branches/verify_branch.rs @@ -1,3 +1,5 @@ +use gitbutler_reference::LocalRefname; + use super::*; // Ensures that `verify_branch` returns an error when not on the integration branch. @@ -10,7 +12,7 @@ async fn should_fail_on_incorrect_branch() { .. } = &Test::default(); - let branch_name: git::LocalRefname = "refs/heads/somebranch".parse().unwrap(); + let branch_name: LocalRefname = "refs/heads/somebranch".parse().unwrap(); repository.checkout(&branch_name); let result = controller.list_virtual_branches(project).await; diff --git a/crates/gitbutler-watcher/Cargo.toml b/crates/gitbutler-watcher/Cargo.toml index c1d8213cf..625940471 100644 --- a/crates/gitbutler-watcher/Cargo.toml +++ b/crates/gitbutler-watcher/Cargo.toml @@ -23,6 +23,7 @@ gix = { workspace = true, features = ["excludes"] } gitbutler-command-context.workspace = true gitbutler-project.workspace = true gitbutler-user.workspace = true +gitbutler-reference.workspace = true backoff = "0.4.0" diff --git a/crates/gitbutler-watcher/src/handler.rs b/crates/gitbutler-watcher/src/handler.rs index 5ecd14786..d5c94635e 100644 --- a/crates/gitbutler-watcher/src/handler.rs +++ b/crates/gitbutler-watcher/src/handler.rs @@ -4,13 +4,13 @@ use std::sync::Arc; use anyhow::{Context, Result}; use gitbutler_command_context::ProjectRepo; use gitbutler_core::error::Marker; -use gitbutler_core::git; use gitbutler_oplog::{ entry::{OperationKind, SnapshotDetails}, oplog::Oplog, }; use gitbutler_project as projects; use gitbutler_project::ProjectId; +use gitbutler_reference::{LocalRefname, Refname}; use gitbutler_sync::cloud::sync_with_gitbutler; use gitbutler_user as users; use gitbutler_virtual::assets; @@ -184,11 +184,8 @@ impl Handler { let head_ref_name = head_ref.name().context("failed to get head name")?; if head_ref_name != "refs/heads/gitbutler/integration" { let mut integration_reference = project_repository.repo().find_reference( - &git::Refname::from(git::LocalRefname::new( - "gitbutler/integration", - None, - )) - .to_string(), + &Refname::from(LocalRefname::new("gitbutler/integration", None)) + .to_string(), )?; integration_reference.delete()?; }