remove field access

This commit is contained in:
Kiril Videlov 2024-06-05 01:19:23 +02:00
parent e63081c69d
commit 4a54f74aa2
12 changed files with 186 additions and 314 deletions

View File

@ -107,7 +107,7 @@ impl Helper {
project_repository: &'a project_repository::Repository,
remote_name: &str,
) -> Result<Vec<(git2::Remote, Vec<Credential>)>, HelpError> {
let remote = project_repository.git_repository.find_remote(remote_name)?;
let remote = project_repository.repo().find_remote(remote_name)?;
let remote_url = Url::from_str(remote.url().ok_or(HelpError::NoUrlSet)?)
.context("failed to parse remote url")?;
@ -123,7 +123,7 @@ impl Helper {
} else {
let ssh_url = remote_url.as_ssh()?;
project_repository
.git_repository
.repo()
.remote_anonymous(&ssh_url.to_string())
}?;
@ -140,9 +140,7 @@ impl Helper {
Ok(remote)
} else {
let url = remote_url.as_https()?;
project_repository
.git_repository
.remote_anonymous(&url.to_string())
project_repository.repo().remote_anonymous(&url.to_string())
}?;
let flow = Self::https_flow(project_repository, &remote_url)?
.into_iter()
@ -175,7 +173,7 @@ impl Helper {
} else {
let ssh_url = remote_url.as_ssh()?;
project_repository
.git_repository
.repo()
.remote_anonymous(&ssh_url.to_string())
}?;
@ -193,7 +191,7 @@ impl Helper {
let mut flow = vec![];
let mut helper = git2::CredentialHelper::new(&remote_url.to_string());
let config = project_repository.git_repository.config()?;
let config = project_repository.repo().config()?;
helper.config(&config);
if let Some((username, password)) = helper.execute() {
flow.push(HttpsCredential::CredentialHelper { username, password });

View File

@ -25,7 +25,7 @@ pub fn mark<P: AsRef<Path>, A: AsRef<[P]>>(
if paths.is_empty() {
return Ok(());
}
let conflicts_path = repository.git_repository.path().join("conflicts");
let conflicts_path = repository.repo().path().join("conflicts");
// write all the file paths to a file on disk
let mut file = std::fs::File::create(conflicts_path)?;
for path in paths {
@ -34,7 +34,7 @@ pub fn mark<P: AsRef<Path>, A: AsRef<[P]>>(
}
if let Some(parent) = parent {
let merge_path = repository.git_repository.path().join("base_merge_parent");
let merge_path = repository.repo().path().join("base_merge_parent");
// write all the file paths to a file on disk
let mut file = std::fs::File::create(merge_path)?;
file.write_all(parent.to_string().as_bytes())?;
@ -44,7 +44,7 @@ pub fn mark<P: AsRef<Path>, A: AsRef<[P]>>(
}
pub fn merge_parent(repository: &Repository) -> Result<Option<git::Oid>> {
let merge_path = repository.git_repository.path().join("base_merge_parent");
let merge_path = repository.repo().path().join("base_merge_parent");
if !merge_path.exists() {
return Ok(None);
}
@ -63,7 +63,7 @@ pub fn merge_parent(repository: &Repository) -> Result<Option<git::Oid>> {
pub fn resolve<P: AsRef<Path>>(repository: &Repository, path: P) -> Result<()> {
let path = path.as_ref();
let conflicts_path = repository.git_repository.path().join("conflicts");
let conflicts_path = repository.repo().path().join("conflicts");
let file = std::fs::File::open(conflicts_path.clone())?;
let reader = std::io::BufReader::new(file);
let mut remaining = Vec::new();
@ -85,7 +85,7 @@ pub fn resolve<P: AsRef<Path>>(repository: &Repository, path: P) -> Result<()> {
}
pub fn conflicting_files(repository: &Repository) -> Result<Vec<String>> {
let conflicts_path = repository.git_repository.path().join("conflicts");
let conflicts_path = repository.repo().path().join("conflicts");
if !conflicts_path.exists() {
return Ok(vec![]);
}
@ -98,7 +98,7 @@ pub fn conflicting_files(repository: &Repository) -> Result<Vec<String>> {
/// Check if `path` is conflicting in `repository`, or if `None`, check if there is any conflict.
// TODO(ST): Should this not rather check the conflicting state in the index?
pub fn is_conflicting(repository: &Repository, path: Option<&Path>) -> Result<bool> {
let conflicts_path = repository.git_repository.path().join("conflicts");
let conflicts_path = repository.repo().path().join("conflicts");
if !conflicts_path.exists() {
return Ok(false);
}
@ -125,15 +125,11 @@ pub fn is_conflicting(repository: &Repository, path: Option<&Path>) -> Result<bo
// is this project still in a resolving conflict state?
// - could be that there are no more conflicts, but the state is not committed
pub fn is_resolving(repository: &Repository) -> bool {
repository
.git_repository
.path()
.join("base_merge_parent")
.exists()
repository.repo().path().join("base_merge_parent").exists()
}
pub fn clear(repository: &Repository) -> Result<()> {
let merge_path = repository.git_repository.path().join("base_merge_parent");
let merge_path = repository.repo().path().join("base_merge_parent");
std::fs::remove_file(merge_path)?;
for file in conflicting_files(repository)? {

View File

@ -18,7 +18,7 @@ use crate::{error::Code, git::Oid};
use crate::{git::RepositoryExt, virtual_branches::errors::Marker};
pub struct Repository {
pub git_repository: git2::Repository,
git_repository: git2::Repository,
project: projects::Project,
}

View File

@ -63,7 +63,7 @@ async fn push_target(
batch_size: usize,
) -> Result<()> {
let ids = batch_rev_walk(
&project_repository.git_repository,
project_repository.repo(),
batch_size,
default_target.sha,
gb_code_last_commit,
@ -136,7 +136,7 @@ fn collect_refs(
project_repository: &project_repository::Repository,
) -> anyhow::Result<Vec<git::Refname>> {
Ok(project_repository
.git_repository
.repo()
.references_glob("refs/*")?
.flatten()
.filter_map(|r| {

View File

@ -49,7 +49,7 @@ fn go_back_to_integration(
default_target: &target::Target,
) -> Result<BaseBranch> {
let statuses = project_repository
.git_repository
.repo()
.statuses(Some(
git2::StatusOptions::new()
.show(git2::StatusShow::IndexAndWorkdir)
@ -71,7 +71,7 @@ fn go_back_to_integration(
.collect::<Vec<_>>();
let target_commit = project_repository
.git_repository
.repo()
.find_commit(default_target.sha.into())
.context("failed to find target commit")?;
@ -84,27 +84,27 @@ fn go_back_to_integration(
for branch in &applied_virtual_branches {
// merge this branches tree with our tree
let branch_head = project_repository
.git_repository
.repo()
.find_commit(branch.head.into())
.context("failed to find branch head")?;
let branch_tree = branch_head
.tree()
.context("failed to get branch head tree")?;
let mut result = project_repository
.git_repository
.repo()
.merge_trees(&base_tree, &final_tree, &branch_tree, None)
.context("failed to merge")?;
let final_tree_oid = result
.write_tree_to(project_repository.repo())
.context("failed to write tree")?;
final_tree = project_repository
.git_repository
.repo()
.find_tree(final_tree_oid)
.context("failed to find written tree")?;
}
project_repository
.git_repository
.repo()
.checkout_tree_builder(&final_tree)
.force()
.checkout()
@ -119,7 +119,7 @@ pub fn set_base_branch(
project_repository: &project_repository::Repository,
target_branch_ref: &git::RemoteRefname,
) -> Result<BaseBranch> {
let repo = &project_repository.git_repository;
let repo = project_repository.repo();
// if target exists, and it is the same as the requested branch, we should go back
if let Ok(target) = default_target(&project_repository.project().gb_dir()) {
@ -274,7 +274,7 @@ pub fn set_target_push_remote(
push_remote_name: &str,
) -> Result<()> {
let remote = project_repository
.git_repository
.repo()
.find_remote(push_remote_name)
.context(format!("failed to find remote {}", push_remote_name))?;
@ -292,7 +292,7 @@ pub fn set_target_push_remote(
}
fn set_exclude_decoration(project_repository: &project_repository::Repository) -> Result<()> {
let repo = &project_repository.git_repository;
let repo = project_repository.repo();
let mut config = repo.config()?;
config
.set_multivar("log.excludeDecoration", "refs/gitbutler", "refs/gitbutler")
@ -334,7 +334,7 @@ pub fn update_base_branch(
// look up the target and see if there is a new oid
let target = default_target(&project_repository.project().gb_dir())?;
let repo = &project_repository.git_repository;
let repo = project_repository.repo();
let target_branch = repo
.find_branch_by_refname(&target.branch.clone().into())
.context(format!("failed to find branch {}", target.branch))?;
@ -398,7 +398,7 @@ pub fn update_base_branch(
branch.upstream_head = None;
let non_commited_files = diff::trees(
&project_repository.git_repository,
project_repository.repo(),
&branch_head_tree,
&branch_tree,
)?;
@ -576,7 +576,7 @@ pub fn target_to_base_branch(
project_repository: &project_repository::Repository,
target: &target::Target,
) -> Result<super::BaseBranch> {
let repo = &project_repository.git_repository;
let repo = project_repository.repo();
let branch = repo.find_branch_by_refname(&target.branch.clone().into())?;
let commit = branch.get().peel_to_commit()?;
let oid = commit.id();

View File

@ -531,8 +531,7 @@ impl ControllerInner {
) -> Result<Vec<RemoteBranchFile>> {
let project = self.projects.get(project_id)?;
let project_repository = project_repository::Repository::open(&project)?;
super::list_remote_commit_files(&project_repository.git_repository, commit_oid)
.map_err(Into::into)
super::list_remote_commit_files(project_repository.repo(), commit_oid).map_err(Into::into)
}
pub fn set_base_branch(

View File

@ -40,7 +40,7 @@ pub fn get_workspace_head(
let target = vb_state
.get_default_target()
.context("failed to get target")?;
let repo: &git2::Repository = &project_repo.git_repository;
let repo: &git2::Repository = project_repo.repo();
let vb_state = project_repo.project().virtual_branches();
let all_virtual_branches = vb_state.list_branches()?;
@ -149,7 +149,7 @@ pub fn update_gitbutler_integration(
.get_default_target()
.context("failed to get target")?;
let repo: &git2::Repository = &project_repository.git_repository;
let repo: &git2::Repository = project_repository.repo();
// get commit object from target.sha
let target_commit = repo.find_commit(target.sha.into())?;
@ -330,7 +330,7 @@ impl project_repository::Repository {
fn verify_head_is_clean(&self) -> Result<&Self> {
let head_commit = self
.git_repository
.repo()
.head()
.context("failed to get head")?
.peel_to_commit()
@ -360,7 +360,7 @@ impl project_repository::Repository {
return Ok(self);
}
self.git_repository
self.repo()
.reset(
integration_commit.as_ref().unwrap().as_object(),
git2::ResetType::Soft,
@ -385,7 +385,7 @@ impl project_repository::Repository {
let mut head = new_branch.head;
for commit in extra_commits {
let new_branch_head = self
.git_repository
.repo()
.find_commit(head.into())
.context("failed to find new branch head")?;
@ -406,7 +406,7 @@ impl project_repository::Repository {
))?;
let rebased_commit = self
.git_repository
.repo()
.find_commit(rebased_commit_oid)
.context(format!(
"failed to find rebased commit {}",

View File

@ -61,7 +61,7 @@ pub fn list_remote_branches(
let mut remote_branches = vec![];
for (branch, _) in project_repository
.git_repository
.repo()
.branches(None)
.context("failed to list remote branches")?
.flatten()
@ -90,7 +90,7 @@ pub fn get_branch_data(
let default_target = default_target(&project_repository.project().gb_dir())?;
let branch = project_repository
.git_repository
.repo()
.find_branch(
&refname.simple_name(),
match refname {

View File

@ -225,7 +225,7 @@ pub fn apply_branch(
user: Option<&users::User>,
) -> Result<String> {
project_repository.assure_resolved()?;
let repo = &project_repository.git_repository;
let repo = project_repository.repo();
let vb_state = project_repository.project().virtual_branches();
let default_target = vb_state.get_default_target()?;
@ -503,7 +503,7 @@ pub fn unapply_ownership(
}
}
let repo = &project_repository.git_repository;
let repo = project_repository.repo();
let target_commit = repo
.find_commit(integration_commit_id.into())
@ -548,7 +548,7 @@ pub fn reset_files(
// for each tree, we need to checkout the entry from the index at that path
// or if it doesn't exist, remove the file from the working directory
let repo = &project_repository.git_repository;
let repo = project_repository.repo();
let index = repo.index().context("failed to get index")?;
for file in files {
let entry = index.get_path(Path::new(file), 0);
@ -581,7 +581,7 @@ pub fn unapply_branch(
}
let default_target = vb_state.get_default_target()?;
let repo = &project_repository.git_repository;
let repo = project_repository.repo();
let target_commit = repo
.find_commit(default_target.sha.into())
.context("failed to find target commit")?;
@ -716,7 +716,7 @@ pub fn list_virtual_branches(
let integration_commit_id =
super::integration::get_workspace_head(&vb_state, project_repository)?;
let integration_commit = project_repository
.git_repository
.repo()
.find_commit(integration_commit_id.into())
.unwrap();
@ -729,7 +729,7 @@ pub fn list_virtual_branches(
.unwrap_or(-1);
for (branch, files) in statuses {
let repo = &project_repository.git_repository;
let repo = project_repository.repo();
update_conflict_markers(project_repository, &files)?;
let upstream_branch = match branch
@ -902,7 +902,7 @@ fn is_requires_force(
};
let reference = match project_repository
.git_repository
.repo()
.refname_to_id(&upstream.to_string())
{
Ok(reference) => reference,
@ -911,12 +911,12 @@ fn is_requires_force(
};
let upstream_commit = project_repository
.git_repository
.repo()
.find_commit(reference)
.context("failed to find upstream commit")?;
let merge_base = project_repository
.git_repository
.repo()
.merge_base(upstream_commit.id(), branch.head.into())?;
Ok(merge_base != upstream_commit.id())
@ -932,11 +932,7 @@ fn list_virtual_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(
&project_repository.git_repository,
&parent_tree,
&commit_tree,
)?;
let diff = diff::trees(project_repository.repo(), &parent_tree, &commit_tree)?;
let hunks_by_filepath = virtual_hunks_by_file_diffs(&project_repository.project().path, diff);
Ok(virtual_hunks_into_virtual_files(
project_repository,
@ -991,7 +987,7 @@ pub fn create_virtual_branch(
let default_target = vb_state.get_default_target()?;
let commit = project_repository
.git_repository
.repo()
.find_commit(default_target.sha.into())
.context("failed to find default target commit")?;
@ -1115,7 +1111,7 @@ pub fn integrate_upstream_commits(
) -> Result<()> {
conflicts::is_conflicting(project_repository, None)?;
let repo = &project_repository.git_repository;
let repo = project_repository.repo();
let project = project_repository.project();
let vb_state = project.virtual_branches();
@ -1260,7 +1256,7 @@ pub fn integrate_with_merge(
merge_base: git::Oid,
) -> Result<git2::Oid> {
let wd_tree = project_repository.repo().get_wd_tree()?;
let repo = &project_repository.git_repository;
let repo = project_repository.repo();
let remote_tree = upstream_commit.tree().context("failed to get tree")?;
let upstream_branch = branch.upstream.as_ref().context("upstream not found")?;
// let merge_tree = repo.find_commit(merge_base).and_then(|c| c.tree())?;
@ -1591,18 +1587,18 @@ fn get_non_applied_status(
bail!("branch {} is applied", branch.name);
}
let branch_tree = project_repository
.git_repository
.repo()
.find_tree(branch.tree.into())
.context(format!("failed to find tree {}", branch.tree))?;
let head_tree = project_repository
.git_repository
.repo()
.find_commit(branch.head.into())
.context("failed to find target commit")?
.tree()
.context("failed to find target tree")?;
let diff = diff::trees(&project_repository.git_repository, &head_tree, &branch_tree)?;
let diff = diff::trees(project_repository.repo(), &head_tree, &branch_tree)?;
Ok((branch, diff::diff_files_into_hunks(diff).collect()))
})
@ -1614,7 +1610,7 @@ fn compute_merge_base(
target_sha: &git::Oid,
virtual_branches: &Vec<branch::Branch>,
) -> Result<git::Oid> {
let repo = &project_repository.git_repository;
let repo = project_repository.repo();
let mut merge_base = *target_sha;
for branch in virtual_branches {
if let Some(last) = project_repository
@ -1701,7 +1697,7 @@ fn get_applied_status(
mut virtual_branches: Vec<branch::Branch>,
) -> Result<(AppliedStatuses, Vec<diff::FileDiff>)> {
let base_file_diffs = diff::workdir(
&project_repository.git_repository,
project_repository.repo(),
&integration_commit.to_owned().into(),
)
.context("failed to diff workdir")?;
@ -1966,7 +1962,7 @@ pub fn reset_branch(
vb_state.set_branch(branch.clone())?;
let updated_head = get_workspace_head(&vb_state, project_repository)?;
let repo = &project_repository.git_repository;
let repo = project_repository.repo();
let diff = trees(
repo,
&repo
@ -2030,7 +2026,7 @@ pub fn write_tree_onto_commit(
files: impl IntoIterator<Item = (impl Borrow<PathBuf>, impl Borrow<Vec<diff::GitHunk>>)>,
) -> Result<git::Oid> {
// read the base sha into an index
let git_repository = &project_repository.git_repository;
let git_repository = project_repository.repo();
let head_commit = git_repository.find_commit(commit_oid.into())?;
let base_tree = head_commit.tree()?;
@ -2043,7 +2039,7 @@ pub fn write_tree_onto_tree(
base_tree: &git2::Tree,
files: impl IntoIterator<Item = (impl Borrow<PathBuf>, impl Borrow<Vec<diff::GitHunk>>)>,
) -> Result<git::Oid> {
let git_repository = &project_repository.git_repository;
let git_repository = project_repository.repo();
let mut builder = git2::build::TreeUpdateBuilder::new();
// now update the index with content in the working directory for each file
for (rel_path, hunks) in files {
@ -2218,7 +2214,7 @@ pub fn commit(
if run_hooks {
let hook_result = git2_hooks::hooks_commit_msg(
&project_repository.git_repository,
project_repository.repo(),
Some(&["../.husky"]),
&mut message_buffer,
)
@ -2229,7 +2225,7 @@ pub fn commit(
}
let hook_result =
git2_hooks::hooks_pre_commit(&project_repository.git_repository, Some(&["../.husky"]))
git2_hooks::hooks_pre_commit(project_repository.repo(), Some(&["../.husky"]))
.context("failed to run hook")?;
if let HookResult::RunNotSuccessful { stdout, .. } = hook_result {
@ -2281,7 +2277,7 @@ pub fn commit(
write_tree_onto_commit(project_repository, branch.head, files)?
};
let git_repository = &project_repository.git_repository;
let git_repository = project_repository.repo();
let parent_commit = git_repository
.find_commit(branch.head.into())
.context(format!("failed to find commit {:?}", branch.head))?;
@ -2312,7 +2308,7 @@ pub fn commit(
};
if run_hooks {
git2_hooks::hooks_post_commit(&project_repository.git_repository, Some(&["../.husky"]))
git2_hooks::hooks_post_commit(project_repository.repo(), Some(&["../.husky"]))
.context("failed to run hook")?;
}
@ -2401,7 +2397,7 @@ fn is_commit_integrated(
commit: &git2::Commit,
) -> Result<bool> {
let remote_branch = project_repository
.git_repository
.repo()
.find_branch_by_refname(&target.branch.clone().into())?;
let remote_head = remote_branch.get().peel_to_commit()?;
let upstream_commits = project_repository.l(
@ -2424,7 +2420,7 @@ fn is_commit_integrated(
}
let merge_base_id = project_repository
.git_repository
.repo()
.merge_base(target.sha.into(), commit.id())?;
if merge_base_id.eq(&commit.id()) {
// if merge branch is the same as branch head and there are upstream commits
@ -2432,13 +2428,9 @@ fn is_commit_integrated(
return Ok(true);
}
let merge_base = project_repository
.git_repository
.find_commit(merge_base_id)?;
let merge_base = project_repository.repo().find_commit(merge_base_id)?;
let merge_base_tree = merge_base.tree()?;
let upstream = project_repository
.git_repository
.find_commit(remote_head.id())?;
let upstream = project_repository.repo().find_commit(remote_head.id())?;
let upstream_tree = upstream.tree()?;
if merge_base_tree.id() == upstream_tree.id() {
@ -2448,7 +2440,7 @@ fn is_commit_integrated(
// try to merge our tree into the upstream tree
let mut merge_index = project_repository
.git_repository
.repo()
.merge_trees(&merge_base_tree, &commit.tree()?, &upstream_tree, None)
.context("failed to merge trees")?;
@ -2473,30 +2465,26 @@ pub fn is_remote_branch_mergeable(
let default_target = vb_state.get_default_target()?;
let target_commit = project_repository
.git_repository
.repo()
.find_commit(default_target.sha.into())
.context("failed to find target commit")?;
let branch = project_repository
.git_repository
.repo()
.find_branch_by_refname(&branch_name.into())?;
let branch_oid = branch.get().target().context("detatched head")?;
let branch_commit = project_repository
.git_repository
.repo()
.find_commit(branch_oid)
.context("failed to find branch commit")?;
let base_tree = find_base_tree(
&project_repository.git_repository,
&branch_commit,
&target_commit,
)?;
let base_tree = find_base_tree(project_repository.repo(), &branch_commit, &target_commit)?;
let wd_tree = project_repository.repo().get_wd_tree()?;
let branch_tree = branch_commit.tree().context("failed to find branch tree")?;
let mergeable = !project_repository
.git_repository
.repo()
.merge_trees(&base_tree, &branch_tree, &wd_tree, None)
.context("failed to merge trees")?
.has_conflicts();
@ -2517,7 +2505,7 @@ pub fn is_virtual_branch_mergeable(
let default_target = vb_state.get_default_target()?;
// determine if this branch is up to date with the target/base
let merge_base = project_repository
.git_repository
.repo()
.merge_base(default_target.sha.into(), branch.head.into())
.context("failed to find merge base")?;
@ -2526,31 +2514,27 @@ pub fn is_virtual_branch_mergeable(
}
let branch_commit = project_repository
.git_repository
.repo()
.find_commit(branch.head.into())
.context("failed to find branch commit")?;
let target_commit = project_repository
.git_repository
.repo()
.find_commit(default_target.sha.into())
.context("failed to find target commit")?;
let base_tree = find_base_tree(
&project_repository.git_repository,
&branch_commit,
&target_commit,
)?;
let base_tree = find_base_tree(project_repository.repo(), &branch_commit, &target_commit)?;
let wd_tree = project_repository.repo().get_wd_tree()?;
// determine if this tree is mergeable
let branch_tree = project_repository
.git_repository
.repo()
.find_tree(branch.tree.into())
.context("failed to find branch tree")?;
let is_mergeable = !project_repository
.git_repository
.repo()
.merge_trees(&base_tree, &branch_tree, &wd_tree, None)
.context("failed to merge trees")?
.has_conflicts();
@ -2582,7 +2566,7 @@ pub fn move_commit_file(
let mut to_amend_oid = to_commit_id;
let mut amend_commit = project_repository
.git_repository
.repo()
.find_commit(to_amend_oid.into())
.context("failed to find commit")?;
@ -2593,11 +2577,8 @@ pub fn move_commit_file(
)?;
// get a list of all the diffs across all the virtual branches
let base_file_diffs = diff::workdir(
&project_repository.git_repository,
&default_target.sha.into(),
)
.context("failed to diff workdir")?;
let base_file_diffs = diff::workdir(project_repository.repo(), &default_target.sha.into())
.context("failed to diff workdir")?;
// filter base_file_diffs to HashMap<filepath, Vec<GitHunk>> only for hunks in target_ownership
// this is essentially the group of patches that we're "moving"
@ -2643,7 +2624,7 @@ pub fn move_commit_file(
// first, let's get the from commit data and it's parent data
let from_commit = project_repository
.git_repository
.repo()
.find_commit(from_commit_id.into())
.context("failed to find commit")?;
let from_tree = from_commit.tree().context("failed to find tree")?;
@ -2654,12 +2635,9 @@ pub fn move_commit_file(
// we need to remove the parts of this patch that are in target_ownership (the parts we're moving)
// and then apply the rest to the parent tree of the "from" commit to
// create the new "from" commit without the changes we're moving
let from_commit_diffs = diff::trees(
&project_repository.git_repository,
&from_parent_tree,
&from_tree,
)
.context("failed to diff trees")?;
let from_commit_diffs =
diff::trees(project_repository.repo(), &from_parent_tree, &from_tree)
.context("failed to diff trees")?;
// filter from_commit_diffs to HashMap<filepath, Vec<GitHunk>> only for hunks NOT in target_ownership
// this is the patch parts we're keeping
@ -2688,7 +2666,7 @@ pub fn move_commit_file(
})
.collect::<HashMap<_, _>>();
let repo = &project_repository.git_repository;
let repo = project_repository.repo();
// write our new tree and commit for the new "from" commit without the moved changes
let new_from_tree_id =
@ -2748,7 +2726,7 @@ pub fn move_commit_file(
// reset the "to" commit variable for writing the changes back to
amend_commit = project_repository
.git_repository
.repo()
.find_commit(to_amend_oid.into())
.context("failed to find commit")?;
@ -2768,7 +2746,7 @@ pub fn move_commit_file(
// and write a new commit with the changes we're moving
let new_tree_oid = write_tree_onto_commit(project_repository, to_amend_oid, &diffs_to_amend)?;
let new_tree = project_repository
.git_repository
.repo()
.find_tree(new_tree_oid.into())
.context("failed to find new tree")?;
let parents: Vec<_> = amend_commit.parents().collect();
@ -2879,7 +2857,7 @@ pub fn amend(
// find commit oid
let amend_commit = project_repository
.git_repository
.repo()
.find_commit(commit_oid.into())
.context("failed to find commit")?;
@ -2917,7 +2895,7 @@ pub fn amend(
// apply diffs_to_amend to the commit tree
let new_tree_oid = write_tree_onto_commit(project_repository, commit_oid, &diffs_to_amend)?;
let new_tree = project_repository
.git_repository
.repo()
.find_tree(new_tree_oid.into())
.context("failed to find new tree")?;
@ -2984,7 +2962,7 @@ pub fn reorder_commit(
let mut branch = vb_state.get_branch(branch_id)?;
// find the commit to offset from
let commit = project_repository
.git_repository
.repo()
.find_commit(commit_oid.into())
.context("failed to find commit")?;
@ -3076,7 +3054,7 @@ pub fn insert_blank_commit(
let mut branch = vb_state.get_branch(branch_id)?;
// find the commit to offset from
let mut commit = project_repository
.git_repository
.repo()
.find_commit(commit_oid.into())
.context("failed to find commit")?;
@ -3128,7 +3106,7 @@ pub fn undo_commit(
let mut branch = vb_state.get_branch(branch_id)?;
let commit = project_repository
.git_repository
.repo()
.find_commit(commit_oid.into())
.context("failed to find commit")?;
@ -3207,11 +3185,7 @@ fn cherry_rebase_group(
// now, rebase unchanged commits onto the new commit
let commits_to_rebase = ids_to_rebase
.iter()
.map(|oid| {
project_repository
.git_repository
.find_commit(oid.to_owned().into())
})
.map(|oid| project_repository.repo().find_commit(oid.to_owned().into()))
.collect::<Result<Vec<_>, _>>()
.context("failed to read commits to rebase")?;
@ -3219,14 +3193,14 @@ fn cherry_rebase_group(
.into_iter()
.fold(
project_repository
.git_repository
.repo()
.find_commit(target_commit_oid.into())
.context("failed to find new commit"),
|head, to_rebase| {
let head = head?;
let mut cherrypick_index = project_repository
.git_repository
.repo()
.cherrypick_commit(&to_rebase, &head, 0, None)
.context("failed to cherry pick")?;
@ -3239,7 +3213,7 @@ fn cherry_rebase_group(
.context("failed to write merge tree")?;
let merge_tree = project_repository
.git_repository
.repo()
.find_tree(merge_tree_oid)
.context("failed to find merge tree")?;
@ -3259,7 +3233,7 @@ fn cherry_rebase_group(
.context("failed to create commit")?;
project_repository
.git_repository
.repo()
.find_commit(commit_oid)
.context("failed to find commit")
},
@ -3288,7 +3262,7 @@ pub fn cherry_pick(
}
let target_commit = project_repository
.git_repository
.repo()
.find_commit(target_commit_id)
.map_err(|err| match err {
err if err.code() == git2::ErrorCode::NotFound => {
@ -3298,7 +3272,7 @@ pub fn cherry_pick(
})?;
let branch_head_commit = project_repository
.git_repository
.repo()
.find_commit(branch.head.into())
.context("failed to find branch tree")?;
@ -3331,7 +3305,7 @@ pub fn cherry_pick(
let wip_commit = {
let wip_tree_oid = write_tree(project_repository, &branch.head, branch_files)?;
let wip_tree = project_repository
.git_repository
.repo()
.find_tree(wip_tree_oid.into())
.context("failed to find tree")?;
@ -3350,13 +3324,13 @@ pub fn cherry_pick(
)
.context("failed to commit wip work")?;
project_repository
.git_repository
.repo()
.find_commit(oid)
.context("failed to find wip commit")?
};
let mut cherrypick_index = project_repository
.git_repository
.repo()
.cherrypick_commit(&target_commit, &wip_commit, 0, None)
.context("failed to cherry pick")?;
@ -3372,7 +3346,7 @@ pub fn cherry_pick(
let commit_oid = if cherrypick_index.has_conflicts() {
// checkout the conflicts
project_repository
.git_repository
.repo()
.checkout_index_builder(&mut cherrypick_index)
.allow_conflicts()
.conflict_style_merge()
@ -3401,12 +3375,12 @@ pub fn cherry_pick(
.write_tree_to(project_repository.repo())
.context("failed to write merge tree")?;
let merge_tree = project_repository
.git_repository
.repo()
.find_tree(merge_tree_oid)
.context("failed to find merge tree")?;
let branch_head_commit = project_repository
.git_repository
.repo()
.find_commit(branch.head.into())
.context("failed to find branch head commit")?;
@ -3426,7 +3400,7 @@ pub fn cherry_pick(
// checkout final_tree into the working directory
project_repository
.git_repository
.repo()
.checkout_tree_builder(&merge_tree)
.force()
.remove_untracked()
@ -3468,7 +3442,7 @@ pub fn squash(
}
let commit_to_squash = project_repository
.git_repository
.repo()
.find_commit(commit_id.into())
.context("failed to find commit")?;
@ -3592,7 +3566,7 @@ pub fn update_commit_message(
}
let target_commit = project_repository
.git_repository
.repo()
.find_commit(commit_id.into())
.context("failed to find commit")?;
@ -3679,7 +3653,7 @@ pub fn move_commit(
let source_branch_non_comitted_files = source_status;
let source_branch_head = project_repository
.git_repository
.repo()
.find_commit(commit_id.into())
.context("failed to find commit")?;
let source_branch_head_parent = source_branch_head
@ -3692,7 +3666,7 @@ pub fn move_commit(
.tree()
.context("failed to get parent tree")?;
let branch_head_diff = diff::trees(
&project_repository.git_repository,
project_repository.repo(),
&source_branch_head_parent_tree,
&source_branch_head_tree,
)?;
@ -3754,7 +3728,7 @@ pub fn move_commit(
)
.context("failed to write tree onto commit")?;
let new_destination_tree = project_repository
.git_repository
.repo()
.find_tree(new_destination_tree_oid.into())
.context("failed to find tree")?;
@ -3765,7 +3739,7 @@ pub fn move_commit(
&source_branch_head.message_bstr().to_str_lossy(),
&new_destination_tree,
&[&project_repository
.git_repository
.repo()
.find_commit(destination_branch.head.into())
.context("failed to get dst branch head commit")?],
change_id.as_deref(),
@ -3816,7 +3790,7 @@ pub fn create_virtual_branch_from_branch(
}
}
let repo = &project_repository.git_repository;
let repo = project_repository.repo();
let head_reference = repo
.find_reference(&upstream.to_string())
.map_err(|err| match err {
@ -3852,7 +3826,7 @@ pub fn create_virtual_branch_from_branch(
// do a diff between the head of this branch and the target base
let diff = diff::trees(
&project_repository.git_repository,
project_repository.repo(),
&merge_base_tree,
&head_commit_tree,
)?;

View File

@ -115,7 +115,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)?;
commit_all(&project_repository.git_repository);
commit_all(project_repository.repo());
set_test_target(project_repository)?;
@ -169,10 +169,10 @@ fn track_binary_files() -> Result<()> {
let (branches, _) = virtual_branches::list_virtual_branches(project_repository).unwrap();
let commit_id = &branches[0].commits[0].id;
let commit_obj = project_repository
.git_repository
.repo()
.find_commit(commit_id.to_owned().into())?;
let tree = commit_obj.tree()?;
let files = tree_to_entry_list(&project_repository.git_repository, &tree);
let files = tree_to_entry_list(project_repository.repo(), &tree);
assert_eq!(files[0].0, "image.bin");
assert_eq!(
files[0].3, img_oid_hex,
@ -202,10 +202,10 @@ fn track_binary_files() -> Result<()> {
let commit_id = &branches[0].commits[0].id;
// get tree from commit_id
let commit_obj = project_repository
.git_repository
.repo()
.find_commit(commit_id.to_owned().into())?;
let tree = commit_obj.tree()?;
let files = tree_to_entry_list(&project_repository.git_repository, &tree);
let files = tree_to_entry_list(project_repository.repo(), &tree);
assert_eq!(files[0].0, "image.bin");
assert_eq!(files[0].3, "ea6901a04d1eed6ebf6822f4360bda9f008fa317");
@ -684,19 +684,11 @@ fn commit_id_can_be_generated_or_specified() -> Result<()> {
Path::new(&project.path).join(file_path),
"line1\nline2\nline3\nline4\n",
)?;
commit_all(&project_repository.git_repository);
commit_all(project_repository.repo());
// lets make sure a change id is generated
let target_oid = project_repository
.git_repository
.head()
.unwrap()
.target()
.unwrap();
let target = project_repository
.git_repository
.find_commit(target_oid)
.unwrap();
let target_oid = project_repository.repo().head().unwrap().target().unwrap();
let target = project_repository.repo().find_commit(target_oid).unwrap();
let change_id = target.change_id();
// make sure we created a change-id
@ -709,7 +701,7 @@ fn commit_id_can_be_generated_or_specified() -> Result<()> {
"line1\nline2\nline3\nline4\nline5\n",
)?;
let repository = &project_repository.git_repository;
let repository = project_repository.repo();
let mut index = repository.index().expect("failed to get index");
index
.add_all(["."], git2::IndexAddOption::DEFAULT, None)
@ -738,16 +730,8 @@ fn commit_id_can_be_generated_or_specified() -> Result<()> {
)
.expect("failed to commit");
let target_oid = project_repository
.git_repository
.head()
.unwrap()
.target()
.unwrap();
let target = project_repository
.git_repository
.find_commit(target_oid)
.unwrap();
let target_oid = project_repository.repo().head().unwrap().target().unwrap();
let target = project_repository.repo().find_commit(target_oid).unwrap();
let change_id = target.change_id();
// the change id should be what we specified, rather than randomly generated
@ -770,26 +754,16 @@ fn merge_vbranch_upstream_clean_rebase() -> Result<()> {
Path::new(&project.path).join(file_path),
"line1\nline2\nline3\nline4\n",
)?;
commit_all(&project_repository.git_repository);
let target_oid = project_repository
.git_repository
.head()
.unwrap()
.target()
.unwrap();
commit_all(project_repository.repo());
let target_oid = project_repository.repo().head().unwrap().target().unwrap();
std::fs::write(
Path::new(&project.path).join(file_path),
"line1\nline2\nline3\nline4\nupstream\n",
)?;
// add a commit to the target branch it's pointing to so there is something "upstream"
commit_all(&project_repository.git_repository);
let last_push = project_repository
.git_repository
.head()
.unwrap()
.target()
.unwrap();
commit_all(project_repository.repo());
let last_push = project_repository.repo().head().unwrap().target().unwrap();
// coworker adds some work
std::fs::write(
@ -797,16 +771,11 @@ fn merge_vbranch_upstream_clean_rebase() -> Result<()> {
"line1\nline2\nline3\nline4\nupstream\ncoworker work\n",
)?;
commit_all(&project_repository.git_repository);
let coworker_work = project_repository
.git_repository
.head()
.unwrap()
.target()
.unwrap();
commit_all(project_repository.repo());
let coworker_work = project_repository.repo().head().unwrap().target().unwrap();
//update repo ref refs/remotes/origin/master to up_target oid
project_repository.git_repository.reference(
project_repository.repo().reference(
"refs/remotes/origin/master",
coworker_work,
true,
@ -894,26 +863,16 @@ async fn merge_vbranch_upstream_conflict() -> Result<()> {
Path::new(&project.path).join(file_path),
"line1\nline2\nline3\nline4\n",
)?;
commit_all(&project_repository.git_repository);
let target_oid = project_repository
.git_repository
.head()
.unwrap()
.target()
.unwrap();
commit_all(project_repository.repo());
let target_oid = project_repository.repo().head().unwrap().target().unwrap();
std::fs::write(
Path::new(&project.path).join(file_path),
"line1\nline2\nline3\nline4\nupstream\n",
)?;
// add a commit to the target branch it's pointing to so there is something "upstream"
commit_all(&project_repository.git_repository);
let last_push = project_repository
.git_repository
.head()
.unwrap()
.target()
.unwrap();
commit_all(project_repository.repo());
let last_push = project_repository.repo().head().unwrap().target().unwrap();
// coworker adds some work
std::fs::write(
@ -921,16 +880,11 @@ async fn merge_vbranch_upstream_conflict() -> Result<()> {
"line1\nline2\nline3\nline4\nupstream\ncoworker work\n",
)?;
commit_all(&project_repository.git_repository);
let coworker_work = project_repository
.git_repository
.head()
.unwrap()
.target()
.unwrap();
commit_all(project_repository.repo());
let coworker_work = project_repository.repo().head().unwrap().target().unwrap();
//update repo ref refs/remotes/origin/master to up_target oid
project_repository.git_repository.reference(
project_repository.repo().reference(
"refs/remotes/origin/master",
coworker_work,
true,
@ -1017,7 +971,7 @@ async fn merge_vbranch_upstream_conflict() -> Result<()> {
// make sure the last commit was a merge commit (2 parents)
let last_id = &branch1.commits[0].id;
let last_commit = project_repository
.git_repository
.repo()
.find_commit(last_id.to_owned().into())?;
assert_eq!(last_commit.parent_count(), 2);
@ -1086,7 +1040,7 @@ fn unapply_branch() -> Result<()> {
Path::new(&project.path).join(file_path),
"line1\nline2\nline3\nline4\n",
)?;
commit_all(&project_repository.git_repository);
commit_all(project_repository.repo());
set_test_target(project_repository)?;
@ -1169,7 +1123,7 @@ fn apply_unapply_added_deleted_files() -> Result<()> {
std::fs::write(Path::new(&project.path).join(file_path), "file1\n")?;
let file_path2 = Path::new("test2.txt");
std::fs::write(Path::new(&project.path).join(file_path2), "file2\n")?;
commit_all(&project_repository.git_repository);
commit_all(project_repository.repo());
set_test_target(project_repository)?;
@ -1238,7 +1192,7 @@ fn detect_mergeable_branch() -> Result<()> {
Path::new(&project.path).join(file_path),
"line1\nline2\nline3\nline4\n",
)?;
commit_all(&project_repository.git_repository);
commit_all(project_repository.repo());
set_test_target(project_repository)?;
@ -1270,11 +1224,9 @@ fn detect_mergeable_branch() -> Result<()> {
virtual_branches::unapply_branch(project_repository, branch1_id)?;
virtual_branches::unapply_branch(project_repository, branch2_id)?;
project_repository.repo().set_head("refs/heads/master")?;
project_repository
.git_repository
.set_head("refs/heads/master")?;
project_repository
.git_repository
.repo()
.checkout_head(Some(&mut git2::build::CheckoutBuilder::default().force()))?;
// create an upstream remote conflicting commit
@ -1282,14 +1234,9 @@ fn detect_mergeable_branch() -> Result<()> {
Path::new(&project.path).join(file_path),
"line1\nline2\nline3\nline4\nupstream\n",
)?;
commit_all(&project_repository.git_repository);
let up_target = project_repository
.git_repository
.head()
.unwrap()
.target()
.unwrap();
project_repository.git_repository.reference(
commit_all(project_repository.repo());
let up_target = project_repository.repo().head().unwrap().target().unwrap();
project_repository.repo().reference(
"refs/remotes/origin/remote_branch",
up_target,
true,
@ -1303,14 +1250,9 @@ fn detect_mergeable_branch() -> Result<()> {
)?;
let file_path3 = Path::new("test3.txt");
std::fs::write(Path::new(&project.path).join(file_path3), "file3\n")?;
commit_all(&project_repository.git_repository);
let up_target = project_repository
.git_repository
.head()
.unwrap()
.target()
.unwrap();
project_repository.git_repository.reference(
commit_all(project_repository.repo());
let up_target = project_repository.repo().head().unwrap().target().unwrap();
project_repository.repo().reference(
"refs/remotes/origin/remote_branch2",
up_target,
true,
@ -1320,10 +1262,10 @@ fn detect_mergeable_branch() -> Result<()> {
std::fs::remove_file(Path::new(&project.path).join(file_path3))?;
project_repository
.git_repository
.repo()
.set_head("refs/heads/gitbutler/integration")?;
project_repository
.git_repository
.repo()
.checkout_head(Some(&mut git2::build::CheckoutBuilder::default().force()))?;
// create branches that conflict with our earlier branches
@ -1409,26 +1351,16 @@ fn upstream_integrated_vbranch() -> Result<()> {
let vb_state = project_repository.project().virtual_branches();
let base_commit = project_repository
.git_repository
.head()
.unwrap()
.target()
.unwrap();
let base_commit = project_repository.repo().head().unwrap().target().unwrap();
std::fs::write(
Path::new(&project.path).join("test.txt"),
"file1\nversion2\n",
)?;
commit_all(&project_repository.git_repository);
commit_all(project_repository.repo());
let upstream_commit = project_repository
.git_repository
.head()
.unwrap()
.target()
.unwrap();
project_repository.git_repository.reference(
let upstream_commit = project_repository.repo().head().unwrap().target().unwrap();
project_repository.repo().reference(
"refs/remotes/origin/master",
upstream_commit,
true,
@ -1442,7 +1374,7 @@ fn upstream_integrated_vbranch() -> Result<()> {
push_remote_name: None,
})?;
project_repository
.git_repository
.repo()
.remote("origin", "http://origin.com/project")?;
virtual_branches::integration::update_gitbutler_integration(&vb_state, project_repository)?;
@ -1804,16 +1736,8 @@ fn commit_partial_by_file() -> Result<()> {
(PathBuf::from("test2.txt"), "file2\n"),
]));
let commit1_oid = project_repository
.git_repository
.head()
.unwrap()
.target()
.unwrap();
let commit1 = project_repository
.git_repository
.find_commit(commit1_oid)
.unwrap();
let commit1_oid = project_repository.repo().head().unwrap().target().unwrap();
let commit1 = project_repository.repo().find_commit(commit1_oid).unwrap();
set_test_target(project_repository)?;
@ -1843,17 +1767,17 @@ fn commit_partial_by_file() -> Result<()> {
// branch one test.txt has just the 1st and 3rd hunks applied
let commit2 = &branch1.commits[0].id;
let commit2 = project_repository
.git_repository
.repo()
.find_commit(commit2.to_owned().into())
.expect("failed to get commit object");
let tree = commit1.tree().expect("failed to get tree");
let file_list = tree_to_file_list(&project_repository.git_repository, &tree);
let file_list = tree_to_file_list(project_repository.repo(), &tree);
assert_eq!(file_list, vec!["test.txt", "test2.txt"]);
// get the tree
let tree = commit2.tree().expect("failed to get tree");
let file_list = tree_to_file_list(&project_repository.git_repository, &tree);
let file_list = tree_to_file_list(project_repository.repo(), &tree);
assert_eq!(file_list, vec!["test.txt", "test3.txt"]);
Ok(())
@ -1871,16 +1795,8 @@ fn commit_add_and_delete_files() -> Result<()> {
(PathBuf::from("test2.txt"), "file2\n"),
]));
let commit1_oid = project_repository
.git_repository
.head()
.unwrap()
.target()
.unwrap();
let commit1 = project_repository
.git_repository
.find_commit(commit1_oid)
.unwrap();
let commit1_oid = project_repository.repo().head().unwrap().target().unwrap();
let commit1 = project_repository.repo().find_commit(commit1_oid).unwrap();
set_test_target(project_repository)?;
@ -1910,17 +1826,17 @@ fn commit_add_and_delete_files() -> Result<()> {
// branch one test.txt has just the 1st and 3rd hunks applied
let commit2 = &branch1.commits[0].id;
let commit2 = project_repository
.git_repository
.repo()
.find_commit(commit2.to_owned().into())
.expect("failed to get commit object");
let tree = commit1.tree().expect("failed to get tree");
let file_list = tree_to_file_list(&project_repository.git_repository, &tree);
let file_list = tree_to_file_list(project_repository.repo(), &tree);
assert_eq!(file_list, vec!["test.txt", "test2.txt"]);
// get the tree
let tree = commit2.tree().expect("failed to get tree");
let file_list = tree_to_file_list(&project_repository.git_repository, &tree);
let file_list = tree_to_file_list(project_repository.repo(), &tree);
assert_eq!(file_list, vec!["test.txt", "test3.txt"]);
Ok(())
@ -1974,13 +1890,13 @@ fn commit_executable_and_symlinks() -> Result<()> {
let commit = &branch1.commits[0].id;
let commit = project_repository
.git_repository
.repo()
.find_commit(commit.to_owned().into())
.expect("failed to get commit object");
let tree = commit.tree().expect("failed to get tree");
let list = tree_to_entry_list(&project_repository.git_repository, &tree);
let list = tree_to_entry_list(project_repository.repo(), &tree);
assert_eq!(list[0].0, "test.txt");
assert_eq!(list[0].1, "100644");
assert_eq!(list[1].0, "test2.txt");
@ -2060,9 +1976,9 @@ fn verify_branch_commits_to_integration() -> Result<()> {
// write two commits
let file_path2 = Path::new("test2.txt");
std::fs::write(Path::new(&project.path).join(file_path2), "file")?;
commit_all(&project_repository.git_repository);
commit_all(project_repository.repo());
std::fs::write(Path::new(&project.path).join(file_path2), "update")?;
commit_all(&project_repository.git_repository);
commit_all(project_repository.repo());
// verify puts commits onto the virtual branch
verify_branch(project_repository).unwrap();
@ -2089,9 +2005,7 @@ fn verify_branch_not_integration() -> Result<()> {
verify_branch(project_repository).unwrap();
project_repository
.git_repository
.set_head("refs/heads/master")?;
project_repository.repo().set_head("refs/heads/master")?;
let verify_result = verify_branch(project_repository);
assert!(verify_result.is_err());
@ -2131,11 +2045,7 @@ fn pre_commit_hook_rejection() -> Result<()> {
exit 1
";
git2_hooks::create_hook(
&project_repository.git_repository,
git2_hooks::HOOK_PRE_COMMIT,
hook,
);
git2_hooks::create_hook(project_repository.repo(), git2_hooks::HOOK_PRE_COMMIT, hook);
let res = commit(
project_repository,
@ -2180,13 +2090,13 @@ fn post_commit_hook() -> Result<()> {
";
git2_hooks::create_hook(
&project_repository.git_repository,
project_repository.repo(),
git2_hooks::HOOK_POST_COMMIT,
hook,
);
let hook_ran_proof = project_repository
.git_repository
.repo()
.path()
.parent()
.unwrap()
@ -2236,11 +2146,7 @@ fn commit_msg_hook_rejection() -> Result<()> {
exit 1
";
git2_hooks::create_hook(
&project_repository.git_repository,
git2_hooks::HOOK_COMMIT_MSG,
hook,
);
git2_hooks::create_hook(project_repository.repo(), git2_hooks::HOOK_COMMIT_MSG, hook);
let res = commit(
project_repository,

View File

@ -28,7 +28,7 @@ pub mod virtual_branches {
let vb_state = project_repository.project().virtual_branches();
let (remote_repo, _tmp) = empty_bare_repository();
let mut remote = project_repository
.git_repository
.repo()
.remote("origin", remote_repo.path().to_str().unwrap())
.expect("failed to add remote");
remote.push(&["refs/heads/master:refs/heads/master"], None)?;

View File

@ -178,14 +178,13 @@ impl Handler {
.context("failed to get head")?;
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.git_repository.find_reference(
&git::Refname::from(git::LocalRefname::new(
"gitbutler/integration",
None,
))
.to_string(),
)?;
let mut integration_reference = project_repository.repo().find_reference(
&git::Refname::from(git::LocalRefname::new(
"gitbutler/integration",
None,
))
.to_string(),
)?;
integration_reference.delete()?;
}
if let Some(head) = head_ref.name() {