mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-11-29 14:25:45 +03:00
move branch name inside git
This commit is contained in:
parent
440f11c96e
commit
9fd64d3b36
@ -6,8 +6,8 @@ use tauri::{AppHandle, Manager};
|
||||
use tokio::task;
|
||||
|
||||
use crate::{
|
||||
bookmarks, deltas, files, gb_repository, keys,
|
||||
project_repository::{self, activity, branch, conflicts, diff},
|
||||
bookmarks, deltas, files, gb_repository, git, keys,
|
||||
project_repository::{self, activity, conflicts, diff},
|
||||
projects, pty, reader, search, sessions, users,
|
||||
virtual_branches::{self, target},
|
||||
watcher,
|
||||
@ -401,14 +401,14 @@ impl App {
|
||||
project_repository.git_match_paths(pattern)
|
||||
}
|
||||
|
||||
pub fn git_branches(&self, project_id: &str) -> Result<Vec<branch::LocalName>> {
|
||||
pub fn git_branches(&self, project_id: &str) -> Result<Vec<git::LocalBranchName>> {
|
||||
let project = self.gb_project(project_id)?;
|
||||
let project_repository = project_repository::Repository::open(&project)
|
||||
.context("failed to open project repository")?;
|
||||
project_repository.git_branches()
|
||||
}
|
||||
|
||||
pub fn git_remote_branches(&self, project_id: &str) -> Result<Vec<branch::RemoteName>> {
|
||||
pub fn git_remote_branches(&self, project_id: &str) -> Result<Vec<git::RemoteBranchName>> {
|
||||
let project = self.gb_project(project_id)?;
|
||||
let project_repository = project_repository::Repository::open(&project)
|
||||
.context("failed to open project repository")?;
|
||||
|
@ -1,3 +1,6 @@
|
||||
mod name;
|
||||
pub use name::{LocalName as LocalBranchName, Name as BranchName, RemoteName as RemoteBranchName};
|
||||
|
||||
use super::{Commit, Oid, Result};
|
||||
|
||||
pub struct Branch<'repo> {
|
@ -10,8 +10,7 @@ use tracing::instrument;
|
||||
|
||||
use git_butler_tauri::*;
|
||||
|
||||
use crate::error::Error;
|
||||
use crate::project_repository::{activity, branch};
|
||||
use crate::{error::Error, git, project_repository::activity};
|
||||
|
||||
#[tauri::command(async)]
|
||||
#[instrument(name = "get_project_archive_path", skip(handle))]
|
||||
@ -331,7 +330,7 @@ async fn git_match_paths(
|
||||
async fn git_branches(
|
||||
handle: tauri::AppHandle,
|
||||
project_id: &str,
|
||||
) -> Result<Vec<branch::LocalName>, Error> {
|
||||
) -> Result<Vec<git::LocalBranchName>, Error> {
|
||||
let app = handle.state::<app::App>();
|
||||
let branches = app
|
||||
.git_branches(project_id)
|
||||
@ -344,7 +343,7 @@ async fn git_branches(
|
||||
async fn git_remote_branches(
|
||||
handle: tauri::AppHandle,
|
||||
project_id: &str,
|
||||
) -> Result<Vec<branch::RemoteName>, Error> {
|
||||
) -> Result<Vec<git::RemoteBranchName>, Error> {
|
||||
let app = handle.state::<app::App>();
|
||||
let branches = app.git_remote_branches(project_id).with_context(|| {
|
||||
format!(
|
||||
|
@ -1,3 +0,0 @@
|
||||
mod names;
|
||||
|
||||
pub use names::*;
|
@ -1,5 +1,4 @@
|
||||
pub mod activity;
|
||||
pub mod branch;
|
||||
pub mod conflicts;
|
||||
pub mod diff;
|
||||
mod repository;
|
||||
|
@ -6,8 +6,6 @@ use walkdir::WalkDir;
|
||||
|
||||
use crate::{git, keys, project_repository::activity, projects, reader};
|
||||
|
||||
use super::branch;
|
||||
|
||||
pub struct Repository<'repository> {
|
||||
pub git_repository: git::Repository,
|
||||
project: &'repository projects::Project,
|
||||
@ -212,28 +210,28 @@ impl<'repository> Repository<'repository> {
|
||||
Ok(files)
|
||||
}
|
||||
|
||||
pub fn git_branches(&self) -> Result<Vec<branch::LocalName>> {
|
||||
pub fn git_branches(&self) -> Result<Vec<git::LocalBranchName>> {
|
||||
self.git_repository
|
||||
.branches(Some(git2::BranchType::Local))?
|
||||
.flatten()
|
||||
.map(|(branch, _)| branch)
|
||||
.map(|branch| {
|
||||
branch::LocalName::try_from(&branch)
|
||||
git::LocalBranchName::try_from(&branch)
|
||||
.context("failed to convert branch to local name")
|
||||
})
|
||||
.collect::<Result<Vec<branch::LocalName>>>()
|
||||
.collect::<Result<Vec<_>>>()
|
||||
}
|
||||
|
||||
pub fn git_remote_branches(&self) -> Result<Vec<branch::RemoteName>> {
|
||||
pub fn git_remote_branches(&self) -> Result<Vec<git::RemoteBranchName>> {
|
||||
self.git_repository
|
||||
.branches(Some(git2::BranchType::Remote))?
|
||||
.flatten()
|
||||
.map(|(branch, _)| branch)
|
||||
.map(|branch| {
|
||||
branch::RemoteName::try_from(&branch)
|
||||
git::RemoteBranchName::try_from(&branch)
|
||||
.context("failed to convert branch to remote name")
|
||||
})
|
||||
.collect::<Result<Vec<branch::RemoteName>>>()
|
||||
.collect::<Result<Vec<_>>>()
|
||||
}
|
||||
|
||||
// returns a list of commit oids from the first oid to the second oid
|
||||
@ -411,7 +409,7 @@ impl<'repository> Repository<'repository> {
|
||||
pub fn push(
|
||||
&self,
|
||||
head: &git::Oid,
|
||||
branch: &branch::RemoteName,
|
||||
branch: &git::RemoteBranchName,
|
||||
key: &keys::PrivateKey,
|
||||
) -> Result<(), Error> {
|
||||
let mut remote = self
|
||||
|
@ -4,7 +4,7 @@ use anyhow::{bail, Context, Result};
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::{
|
||||
gb_repository,
|
||||
gb_repository, git,
|
||||
project_repository::{self, LogUntil},
|
||||
reader, sessions,
|
||||
};
|
||||
@ -45,7 +45,7 @@ pub fn set_base_branch(
|
||||
let mut commit_oid = commit.id();
|
||||
|
||||
let head_ref = repo.head().context("Failed to get HEAD reference")?;
|
||||
let head_name: project_repository::branch::Name = head_ref
|
||||
let head_name: git::BranchName = head_ref
|
||||
.name()
|
||||
.context("Failed to get HEAD reference name")?
|
||||
.parse()
|
||||
@ -479,7 +479,7 @@ pub fn target_to_base_branch(
|
||||
pub fn create_virtual_branch_from_branch(
|
||||
gb_repository: &gb_repository::Repository,
|
||||
project_repository: &project_repository::Repository,
|
||||
upstream: &project_repository::branch::Name,
|
||||
upstream: &git::BranchName,
|
||||
applied: Option<bool>,
|
||||
) -> Result<branch::Branch> {
|
||||
let current_session = gb_repository
|
||||
@ -511,8 +511,8 @@ pub fn create_virtual_branch_from_branch(
|
||||
|
||||
// only set upstream if it's not the default target
|
||||
let upstream_branch = match upstream {
|
||||
project_repository::branch::Name::Remote(remote) => Some(remote.clone()),
|
||||
project_repository::branch::Name::Local(local) => {
|
||||
git::BranchName::Remote(remote) => Some(remote.clone()),
|
||||
git::BranchName::Local(local) => {
|
||||
let remote_name = format!("{}/{}", default_target.remote_name, local.branch());
|
||||
if remote_name != default_target.branch_name {
|
||||
Some(format!("refs/remotes/{}", remote_name).parse().unwrap())
|
||||
|
@ -14,7 +14,7 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
use anyhow::Result;
|
||||
|
||||
use crate::{git, project_repository::branch};
|
||||
use crate::git;
|
||||
|
||||
// this is the struct for the virtual branch data that is stored in our data
|
||||
// store. it is more or less equivalent to a git branch reference, but it is not
|
||||
@ -26,7 +26,7 @@ pub struct Branch {
|
||||
pub name: String,
|
||||
pub notes: String,
|
||||
pub applied: bool,
|
||||
pub upstream: Option<branch::RemoteName>,
|
||||
pub upstream: Option<git::RemoteBranchName>,
|
||||
pub created_timestamp_ms: u128,
|
||||
pub updated_timestamp_ms: u128,
|
||||
// tree is the last git tree written to a session, or merge base tree if this is new. use this for delta calculation from the session data
|
||||
@ -104,7 +104,7 @@ impl TryFrom<&dyn crate::reader::Reader> for Branch {
|
||||
Ok(None)
|
||||
} else {
|
||||
upstream
|
||||
.parse::<branch::RemoteName>()
|
||||
.parse::<git::RemoteBranchName>()
|
||||
.map(Some)
|
||||
.map_err(|e| {
|
||||
crate::reader::Error::IOError(std::io::Error::new(
|
||||
|
@ -1,7 +1,7 @@
|
||||
use tauri::{AppHandle, Manager};
|
||||
use tracing::instrument;
|
||||
|
||||
use crate::{error::Error, project_repository::branch};
|
||||
use crate::{error::Error, git};
|
||||
|
||||
use super::controller::Controller;
|
||||
|
||||
@ -52,7 +52,7 @@ pub async fn create_virtual_branch(
|
||||
pub async fn create_virtual_branch_from_branch(
|
||||
handle: AppHandle,
|
||||
project_id: &str,
|
||||
branch: branch::Name,
|
||||
branch: git::BranchName,
|
||||
) -> Result<String, Error> {
|
||||
handle
|
||||
.state::<Controller>()
|
||||
|
@ -6,7 +6,7 @@ use tauri::{AppHandle, Manager};
|
||||
use tokio::sync::Semaphore;
|
||||
|
||||
use crate::{
|
||||
assets, gb_repository, keys,
|
||||
assets, gb_repository, git, keys,
|
||||
project_repository::{self, conflicts},
|
||||
projects, users, watcher,
|
||||
};
|
||||
@ -109,7 +109,7 @@ impl Controller {
|
||||
pub async fn create_virtual_branch_from_branch(
|
||||
&self,
|
||||
project_id: &str,
|
||||
branch: &project_repository::branch::Name,
|
||||
branch: &git::BranchName,
|
||||
) -> Result<String, Error> {
|
||||
self.with_lock::<Result<String, Error>>(project_id, || {
|
||||
self.with_verify_branch(project_id, |gb_repository, project_repository| {
|
||||
|
@ -2070,8 +2070,7 @@ fn test_detect_remote_commits() -> Result<()> {
|
||||
// push the commit upstream
|
||||
let branch1 = branch_reader.read(&branch1_id)?;
|
||||
let up_target = branch1.head;
|
||||
let remote_branch: project_repository::branch::RemoteName =
|
||||
"refs/remotes/origin/remote_branch".parse().unwrap();
|
||||
let remote_branch: git::RemoteBranchName = "refs/remotes/origin/remote_branch".parse().unwrap();
|
||||
repository.reference(&remote_branch.to_string(), up_target, true, "update target")?;
|
||||
// set the upstream reference
|
||||
branch_writer.write(&Branch {
|
||||
@ -2130,7 +2129,7 @@ fn test_create_vbranch_from_remote_branch() -> Result<()> {
|
||||
)?;
|
||||
test_utils::commit_all(&repository);
|
||||
|
||||
let upstream: project_repository::branch::Name = "refs/remotes/origin/branch1".parse().unwrap();
|
||||
let upstream: git::BranchName = "refs/remotes/origin/branch1".parse().unwrap();
|
||||
|
||||
repository.reference(
|
||||
&upstream.to_string(),
|
||||
@ -2271,8 +2270,7 @@ fn test_create_vbranch_from_behind_remote_branch() -> Result<()> {
|
||||
test_utils::commit_all(&repository);
|
||||
let remote_commit = repository.head().unwrap().target().unwrap();
|
||||
|
||||
let remote_branch: project_repository::branch::Name =
|
||||
"refs/remotes/origin/branch1".parse().unwrap();
|
||||
let remote_branch: git::BranchName = "refs/remotes/origin/branch1".parse().unwrap();
|
||||
repository.reference(
|
||||
&remote_branch.to_string(),
|
||||
remote_commit,
|
||||
|
@ -43,7 +43,7 @@ pub struct VirtualBranch {
|
||||
pub merge_conflicts: Vec<String>, // if mergeable is false, this will contain a list of files that have merge conflicts (only for unapplied branches)
|
||||
pub conflicted: bool, // is this branch currently in a conflicted state (only for applied branches)
|
||||
pub order: usize, // the order in which this branch should be displayed in the UI
|
||||
pub upstream: Option<project_repository::branch::RemoteName>, // the name of the upstream branch this branch this pushes to
|
||||
pub upstream: Option<git::RemoteBranchName>, // the name of the upstream branch this branch this pushes to
|
||||
pub base_current: bool, // is this vbranch based on the current base branch? if false, this needs to be manually merged with conflicts
|
||||
}
|
||||
|
||||
@ -127,7 +127,7 @@ pub struct RemoteBranch {
|
||||
pub first_commit_ts: u128,
|
||||
pub ahead: u32,
|
||||
pub behind: u32,
|
||||
pub upstream: Option<project_repository::branch::RemoteName>,
|
||||
pub upstream: Option<git::RemoteBranchName>,
|
||||
pub authors: Vec<Author>,
|
||||
pub mergeable: bool,
|
||||
pub merge_conflicts: Vec<String>,
|
||||
@ -504,12 +504,12 @@ pub fn list_remote_branches(
|
||||
continue;
|
||||
}
|
||||
|
||||
let branch_name = project_repository::branch::Name::try_from(&branch)
|
||||
.context("could not get branch name")?;
|
||||
let branch_name =
|
||||
git::BranchName::try_from(&branch).context("could not get branch name")?;
|
||||
|
||||
// skip the default target branch (both local and remote)
|
||||
match branch_name {
|
||||
project_repository::branch::Name::Remote(ref remote_branch_name) => {
|
||||
git::BranchName::Remote(ref remote_branch_name) => {
|
||||
if format!(
|
||||
"{}/{}",
|
||||
remote_branch_name.remote(),
|
||||
@ -520,7 +520,7 @@ pub fn list_remote_branches(
|
||||
continue;
|
||||
}
|
||||
}
|
||||
project_repository::branch::Name::Local(ref local_branch_name) => {
|
||||
git::BranchName::Local(ref local_branch_name) => {
|
||||
if let Some(upstream_branch_name) = local_branch_name.remote() {
|
||||
if format!(
|
||||
"{}/{}",
|
||||
@ -616,9 +616,7 @@ pub fn list_remote_branches(
|
||||
let upstream = branch
|
||||
.upstream()
|
||||
.ok()
|
||||
.map(|upstream_branch| {
|
||||
project_repository::branch::RemoteName::try_from(&upstream_branch)
|
||||
})
|
||||
.map(|upstream_branch| git::RemoteBranchName::try_from(&upstream_branch))
|
||||
.transpose()?;
|
||||
|
||||
if count_ahead > 0 {
|
||||
@ -1925,7 +1923,7 @@ pub fn push(
|
||||
target.remote_name,
|
||||
name_to_branch(&vbranch.name)
|
||||
)
|
||||
.parse::<project_repository::branch::RemoteName>()
|
||||
.parse::<git::RemoteBranchName>()
|
||||
.unwrap(),
|
||||
None => return Err(PushError::Other(anyhow::anyhow!("no default target set"))),
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user