mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-10-06 00:47:09 +03:00
Merge pull request #4012 from gitbutlerapp/update-pnpm-lock-file-and-dependencieds
remove proxy core::Oid
This commit is contained in:
commit
f289ed7b6e
@ -7,7 +7,6 @@ use bstr::{BStr, BString, ByteSlice, ByteVec};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tracing::instrument;
|
||||
|
||||
use crate::git;
|
||||
use crate::id::Id;
|
||||
use crate::virtual_branches::Branch;
|
||||
|
||||
@ -124,7 +123,8 @@ impl GitHunk {
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct HunkLock {
|
||||
pub branch_id: Id<Branch>,
|
||||
pub commit_id: git::Oid,
|
||||
#[serde(with = "crate::serde::oid")]
|
||||
pub commit_id: git2::Oid,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Serialize, Default)]
|
||||
|
@ -7,9 +7,6 @@ pub use error::*;
|
||||
mod reference;
|
||||
pub use reference::*;
|
||||
|
||||
mod oid;
|
||||
pub use oid::*;
|
||||
|
||||
mod url;
|
||||
pub use self::url::*;
|
||||
|
||||
|
@ -1,69 +0,0 @@
|
||||
use std::{fmt, str::FromStr};
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, PartialEq, Copy, Clone, Hash, Eq)]
|
||||
pub struct Oid {
|
||||
oid: git2::Oid,
|
||||
}
|
||||
|
||||
impl Oid {
|
||||
pub fn from_bytes(bytes: &[u8]) -> Result<Self, git2::Error> {
|
||||
Ok(Self {
|
||||
oid: git2::Oid::from_bytes(bytes)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Oid {
|
||||
fn default() -> Self {
|
||||
git2::Oid::zero().into()
|
||||
}
|
||||
}
|
||||
|
||||
impl Serialize for Oid {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
self.oid.to_string().serialize(serializer)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for Oid {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: serde::Deserializer<'de>,
|
||||
{
|
||||
let s = String::deserialize(deserializer)?;
|
||||
git2::Oid::from_str(&s)
|
||||
.map_err(|e| serde::de::Error::custom(format!("invalid oid: {}", e)))
|
||||
.map(Into::into)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Oid {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
self.oid.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl FromStr for Oid {
|
||||
type Err = git2::Error;
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
git2::Oid::from_str(s).map(Into::into)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<git2::Oid> for Oid {
|
||||
fn from(oid: git2::Oid) -> Self {
|
||||
Self { oid }
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Oid> for git2::Oid {
|
||||
fn from(oid: Oid) -> Self {
|
||||
oid.oid
|
||||
}
|
||||
}
|
@ -67,17 +67,16 @@ pub mod serde {
|
||||
}
|
||||
|
||||
pub mod oid_opt {
|
||||
use crate::git;
|
||||
use serde::{Deserialize, Deserializer, Serialize};
|
||||
|
||||
pub fn serialize<S>(v: &Option<git::Oid>, s: S) -> Result<S::Ok, S::Error>
|
||||
pub fn serialize<S>(v: &Option<git2::Oid>, s: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
v.as_ref().map(|v| v.to_string()).serialize(s)
|
||||
}
|
||||
|
||||
pub fn deserialize<'de, D>(d: D) -> Result<Option<git::Oid>, D::Error>
|
||||
pub fn deserialize<'de, D>(d: D) -> Result<Option<git2::Oid>, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
@ -90,18 +89,44 @@ pub mod serde {
|
||||
}
|
||||
}
|
||||
|
||||
pub mod oid {
|
||||
use crate::git;
|
||||
pub mod oid_vec {
|
||||
use serde::{Deserialize, Deserializer, Serialize};
|
||||
|
||||
pub fn serialize<S>(v: &git::Oid, s: S) -> Result<S::Ok, S::Error>
|
||||
pub fn serialize<S>(v: &[git2::Oid], s: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
let vec: Vec<String> = v.iter().map(|v| v.to_string()).collect();
|
||||
vec.serialize(s)
|
||||
}
|
||||
|
||||
pub fn deserialize<'de, D>(d: D) -> Result<Vec<git2::Oid>, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
let hex = <Vec<String> as Deserialize>::deserialize(d)?;
|
||||
let hex: Result<Vec<git2::Oid>, D::Error> = hex
|
||||
.into_iter()
|
||||
.map(|v| {
|
||||
git2::Oid::from_str(v.as_str())
|
||||
.map_err(|err: git2::Error| serde::de::Error::custom(err.to_string()))
|
||||
})
|
||||
.collect();
|
||||
hex
|
||||
}
|
||||
}
|
||||
|
||||
pub mod oid {
|
||||
use serde::{Deserialize, Deserializer, Serialize};
|
||||
|
||||
pub fn serialize<S>(v: &git2::Oid, s: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: serde::Serializer,
|
||||
{
|
||||
v.to_string().serialize(s)
|
||||
}
|
||||
|
||||
pub fn deserialize<'de, D>(d: D) -> Result<git::Oid, D::Error>
|
||||
pub fn deserialize<'de, D>(d: D) -> Result<git2::Oid, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
|
@ -9,7 +9,6 @@ use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
use strum::EnumString;
|
||||
|
||||
use crate::git;
|
||||
use serde::Serialize;
|
||||
|
||||
/// A snapshot of the repository and virtual branches state that GitButler can restore to.
|
||||
@ -19,7 +18,7 @@ use serde::Serialize;
|
||||
pub struct Snapshot {
|
||||
/// The id of the commit that represents the snapshot
|
||||
#[serde(rename = "id", with = "crate::serde::oid")]
|
||||
pub commit_id: git::Oid,
|
||||
pub commit_id: git2::Oid,
|
||||
/// Snapshot creation time in seconds from Unix epoch seconds, based on a commit as `commit_id`.
|
||||
#[serde(serialize_with = "crate::serde::as_time_seconds_from_unix_epoch")]
|
||||
pub created_at: git2::Time,
|
||||
|
@ -14,7 +14,7 @@ use crate::virtual_branches::integration::{
|
||||
GITBUTLER_INTEGRATION_COMMIT_AUTHOR_EMAIL, GITBUTLER_INTEGRATION_COMMIT_AUTHOR_NAME,
|
||||
};
|
||||
use crate::virtual_branches::Branch;
|
||||
use crate::{git, git::diff::hunks_by_filepath, git::RepositoryExt, projects::Project};
|
||||
use crate::{git::diff::hunks_by_filepath, git::RepositoryExt, projects::Project};
|
||||
|
||||
use super::{
|
||||
entry::{OperationKind, Snapshot, SnapshotDetails, Trailer},
|
||||
@ -47,14 +47,14 @@ impl Project {
|
||||
/// Prepares a snapshot of the current state of the working directory as well as GitButler data.
|
||||
/// Returns a tree hash of the snapshot. The snapshot is not discoverable until it is committed with [`commit_snapshot`](Self::commit_snapshot())
|
||||
/// If there are files that are untracked and larger than `SNAPSHOT_FILE_LIMIT_BYTES`, they are excluded from snapshot creation and restoring.
|
||||
pub(crate) fn prepare_snapshot(&self) -> Result<git::Oid> {
|
||||
pub(crate) fn prepare_snapshot(&self) -> Result<git2::Oid> {
|
||||
let worktree_dir = self.path.as_path();
|
||||
let repo = git2::Repository::open(worktree_dir)?;
|
||||
|
||||
let vb_state = self.virtual_branches();
|
||||
|
||||
// grab the target commit
|
||||
let default_target_commit = repo.find_commit(vb_state.get_default_target()?.sha.into())?;
|
||||
let default_target_commit = repo.find_commit(vb_state.get_default_target()?.sha)?;
|
||||
let target_tree_id = default_target_commit.tree_id();
|
||||
|
||||
// Create a blob out of `.git/gitbutler/virtual_branches.toml`
|
||||
@ -73,7 +73,7 @@ impl Project {
|
||||
let mut tree_builder = repo.treebuilder(None)?;
|
||||
tree_builder.insert("index", index_tree_oid, FileMode::Tree.into())?;
|
||||
tree_builder.insert("target_tree", target_tree_id, FileMode::Tree.into())?;
|
||||
tree_builder.insert("conflicts", conflicts_tree_id.into(), FileMode::Tree.into())?;
|
||||
tree_builder.insert("conflicts", conflicts_tree_id, FileMode::Tree.into())?;
|
||||
tree_builder.insert("virtual_branches.toml", vb_blob_id, FileMode::Blob.into())?;
|
||||
|
||||
// go through all virtual branches and create a subtree for each with the tree and any commits encoded
|
||||
@ -88,11 +88,11 @@ impl Project {
|
||||
// commits in virtual branches (tree and commit data)
|
||||
// calculate all the commits between branch.head and the target and codify them
|
||||
let mut branch_tree_builder = repo.treebuilder(None)?;
|
||||
branch_tree_builder.insert("tree", branch.tree.into(), FileMode::Tree.into())?;
|
||||
branch_tree_builder.insert("tree", branch.tree, FileMode::Tree.into())?;
|
||||
|
||||
// let's get all the commits between the branch head and the target
|
||||
let mut revwalk = repo.revwalk()?;
|
||||
revwalk.push(branch.head.into())?;
|
||||
revwalk.push(branch.head)?;
|
||||
revwalk.hide(default_target_commit.id())?;
|
||||
|
||||
let mut commits_tree_builder = repo.treebuilder(None)?;
|
||||
@ -167,7 +167,7 @@ impl Project {
|
||||
tree_builder.insert("workdir", target_tree_id, FileMode::Tree.into())?;
|
||||
} else if head_tree_ids.len() == 1 {
|
||||
// if there is just one applied branch, then it's just that branch tree
|
||||
tree_builder.insert("workdir", head_tree_ids[0].into(), FileMode::Tree.into())?;
|
||||
tree_builder.insert("workdir", head_tree_ids[0], FileMode::Tree.into())?;
|
||||
} else {
|
||||
// otherwise merge one branch tree at a time with target_tree_oid as the base
|
||||
let mut workdir_tree_id = target_tree_id;
|
||||
@ -176,7 +176,7 @@ impl Project {
|
||||
|
||||
// iterate through all head trees
|
||||
for head_tree_id in head_tree_ids {
|
||||
let current_theirs = repo.find_tree(head_tree_id.into())?;
|
||||
let current_theirs = repo.find_tree(head_tree_id)?;
|
||||
let mut workdir_temp_index =
|
||||
repo.merge_trees(&base_tree, ¤t_ours, ¤t_theirs, None)?;
|
||||
workdir_tree_id = workdir_temp_index.write_tree_to(&repo)?;
|
||||
@ -186,7 +186,7 @@ impl Project {
|
||||
}
|
||||
|
||||
let tree_id = tree_builder.write()?;
|
||||
Ok(tree_id.into())
|
||||
Ok(tree_id)
|
||||
}
|
||||
|
||||
/// Commits the snapshot tree that is created with the [`prepare_snapshot`](Self::prepare_snapshot) method,
|
||||
@ -200,16 +200,16 @@ impl Project {
|
||||
/// commit and the current one (after comparing trees).
|
||||
pub(crate) fn commit_snapshot(
|
||||
&self,
|
||||
snapshot_tree_id: git::Oid,
|
||||
snapshot_tree_id: git2::Oid,
|
||||
details: SnapshotDetails,
|
||||
) -> Result<Option<git::Oid>> {
|
||||
) -> Result<Option<git2::Oid>> {
|
||||
let repo = git2::Repository::open(self.path.as_path())?;
|
||||
let snapshot_tree = repo.find_tree(snapshot_tree_id.into())?;
|
||||
let snapshot_tree = repo.find_tree(snapshot_tree_id)?;
|
||||
|
||||
let oplog_state = OplogHandle::new(&self.gb_dir());
|
||||
let oplog_head_commit = oplog_state
|
||||
.oplog_head()?
|
||||
.and_then(|head_id| repo.find_commit(head_id.into()).ok());
|
||||
.and_then(|head_id| repo.find_commit(head_id).ok());
|
||||
|
||||
// Construct a new commit
|
||||
let signature = git2::Signature::now(
|
||||
@ -230,13 +230,13 @@ impl Project {
|
||||
parents.as_slice(),
|
||||
)?;
|
||||
|
||||
oplog_state.set_oplog_head(snapshot_commit_id.into())?;
|
||||
oplog_state.set_oplog_head(snapshot_commit_id)?;
|
||||
|
||||
let vb_state = self.virtual_branches();
|
||||
let target_commit_id = vb_state.get_default_target()?.sha;
|
||||
set_reference_to_oplog(&self.path, target_commit_id, snapshot_commit_id.into())?;
|
||||
set_reference_to_oplog(&self.path, target_commit_id, snapshot_commit_id)?;
|
||||
|
||||
Ok(Some(snapshot_commit_id.into()))
|
||||
Ok(Some(snapshot_commit_id))
|
||||
}
|
||||
|
||||
/// Creates a snapshot of the current state of the working directory as well as GitButler data.
|
||||
@ -248,7 +248,7 @@ impl Project {
|
||||
///
|
||||
/// Note that errors in snapshot creation is typically ignored, so we want to learn about them.
|
||||
#[instrument(skip(details), err(Debug))]
|
||||
pub fn create_snapshot(&self, details: SnapshotDetails) -> Result<Option<git::Oid>> {
|
||||
pub fn create_snapshot(&self, details: SnapshotDetails) -> Result<Option<git2::Oid>> {
|
||||
let tree_id = self.prepare_snapshot()?;
|
||||
self.commit_snapshot(tree_id, details)
|
||||
}
|
||||
@ -266,7 +266,7 @@ impl Project {
|
||||
pub fn list_snapshots(
|
||||
&self,
|
||||
limit: usize,
|
||||
oplog_commit_id: Option<git::Oid>,
|
||||
oplog_commit_id: Option<git2::Oid>,
|
||||
) -> Result<Vec<Snapshot>> {
|
||||
let repo_path = self.path.as_path();
|
||||
let repo = git2::Repository::open(repo_path)?;
|
||||
@ -283,7 +283,7 @@ impl Project {
|
||||
}
|
||||
};
|
||||
|
||||
let oplog_head_commit = repo.find_commit(traversal_root_id.into())?;
|
||||
let oplog_head_commit = repo.find_commit(traversal_root_id)?;
|
||||
|
||||
let mut revwalk = repo.revwalk()?;
|
||||
revwalk.push(oplog_head_commit.id())?;
|
||||
@ -333,7 +333,7 @@ impl Project {
|
||||
|
||||
let stats = diff.stats()?;
|
||||
snapshots.push(Snapshot {
|
||||
commit_id: commit_id.into(),
|
||||
commit_id,
|
||||
details,
|
||||
lines_added: stats.insertions(),
|
||||
lines_removed: stats.deletions(),
|
||||
@ -343,7 +343,7 @@ impl Project {
|
||||
} else {
|
||||
// this is the very first snapshot
|
||||
snapshots.push(Snapshot {
|
||||
commit_id: commit_id.into(),
|
||||
commit_id,
|
||||
details,
|
||||
lines_added: 0,
|
||||
lines_removed: 0,
|
||||
@ -368,12 +368,12 @@ impl Project {
|
||||
///
|
||||
/// If there are files that are untracked and larger than `SNAPSHOT_FILE_LIMIT_BYTES`, they are excluded from snapshot creation and restoring.
|
||||
/// Returns the sha of the created revert snapshot commit or None if snapshots are disabled.
|
||||
pub fn restore_snapshot(&self, snapshot_commit_id: git::Oid) -> Result<Option<git::Oid>> {
|
||||
pub fn restore_snapshot(&self, snapshot_commit_id: git2::Oid) -> Result<Option<git2::Oid>> {
|
||||
let worktree_dir = self.path.as_path();
|
||||
let repo = git2::Repository::open(worktree_dir)?;
|
||||
|
||||
let before_restore_snapshot_result = self.prepare_snapshot();
|
||||
let snapshot_commit = repo.find_commit(snapshot_commit_id.into())?;
|
||||
let snapshot_commit = repo.find_commit(snapshot_commit_id)?;
|
||||
|
||||
let snapshot_tree = snapshot_commit.tree()?;
|
||||
let vb_toml_entry = snapshot_tree
|
||||
@ -420,11 +420,11 @@ impl Project {
|
||||
// for each commit, recreate the commit from the commit data if it doesn't exist
|
||||
if let Some(commit_id) = commit_entry.name() {
|
||||
// check for the oid in the repo
|
||||
let commit_oid = git::Oid::from_str(commit_id)?;
|
||||
if repo.find_commit(commit_oid.into()).is_err() {
|
||||
let commit_oid = git2::Oid::from_str(commit_id)?;
|
||||
if repo.find_commit(commit_oid).is_err() {
|
||||
// commit is not in the repo, let's build it from our data
|
||||
let new_commit_oid = deserialize_commit(&repo, &commit_entry)?;
|
||||
if new_commit_oid != commit_oid.into() {
|
||||
if new_commit_oid != commit_oid {
|
||||
bail!("commit id mismatch: failed to recreate a commit from its parts");
|
||||
}
|
||||
}
|
||||
@ -440,11 +440,11 @@ impl Project {
|
||||
|
||||
// reset the branch if it's there, otherwise bail as we don't meddle with other branches
|
||||
// need to detach the head for just a moment.
|
||||
repo.set_head_detached(commit_oid.into())?;
|
||||
repo.set_head_detached(commit_oid)?;
|
||||
integration_ref.delete()?;
|
||||
|
||||
// ok, now we set the branch to what it was and update HEAD
|
||||
let integration_commit = repo.find_commit(commit_oid.into())?;
|
||||
let integration_commit = repo.find_commit(commit_oid)?;
|
||||
repo.branch("gitbutler/integration", &integration_commit, true)?;
|
||||
// make sure head is gitbutler/integration
|
||||
repo.set_head("refs/heads/gitbutler/integration")?;
|
||||
@ -552,11 +552,11 @@ impl Project {
|
||||
/// Returns the diff of the snapshot and it's parent. It only includes the workdir changes.
|
||||
///
|
||||
/// This is useful to show what has changed in this particular snapshot
|
||||
pub fn snapshot_diff(&self, sha: git::Oid) -> Result<HashMap<PathBuf, FileDiff>> {
|
||||
pub fn snapshot_diff(&self, sha: git2::Oid) -> Result<HashMap<PathBuf, FileDiff>> {
|
||||
let worktree_dir = self.path.as_path();
|
||||
let repo = git2::Repository::init(worktree_dir)?;
|
||||
|
||||
let commit = repo.find_commit(sha.into())?;
|
||||
let commit = repo.find_commit(sha)?;
|
||||
// Top tree
|
||||
let tree = commit.tree()?;
|
||||
let old_tree = commit.parent(0)?.tree()?;
|
||||
@ -594,7 +594,7 @@ impl Project {
|
||||
}
|
||||
|
||||
/// Gets the sha of the last snapshot commit if present.
|
||||
pub fn oplog_head(&self) -> Result<Option<git::Oid>> {
|
||||
pub fn oplog_head(&self) -> Result<Option<git2::Oid>> {
|
||||
let oplog_state = OplogHandle::new(&self.gb_dir());
|
||||
oplog_state.oplog_head()
|
||||
}
|
||||
@ -635,7 +635,7 @@ fn restore_conflicts_tree(snapshot_tree: &git2::Tree, repo: &git2::Repository) -
|
||||
fn write_conflicts_tree(
|
||||
worktree_dir: &std::path::Path,
|
||||
repo: &git2::Repository,
|
||||
) -> Result<git::Oid> {
|
||||
) -> Result<git2::Oid> {
|
||||
let git_dir = worktree_dir.join(".git");
|
||||
let merge_parent_path = git_dir.join("base_merge_parent");
|
||||
let merge_parent_blob = if merge_parent_path.exists() {
|
||||
@ -663,7 +663,7 @@ fn write_conflicts_tree(
|
||||
tree_builder.insert("conflicts", conflicts_blob.unwrap(), FileMode::Blob.into())?;
|
||||
}
|
||||
let conflicts_tree = tree_builder.write()?;
|
||||
Ok(conflicts_tree.into())
|
||||
Ok(conflicts_tree)
|
||||
}
|
||||
|
||||
/// Exclude files that are larger than the limit (eg. database.sql which may never be intended to be committed)
|
||||
@ -728,11 +728,11 @@ fn lines_since_snapshot(project: &Project, repo: &git2::Repository) -> Result<us
|
||||
fn branch_lines_since_snapshot(
|
||||
branch: &Branch,
|
||||
repo: &git2::Repository,
|
||||
head_sha: git::Oid,
|
||||
head_sha: git2::Oid,
|
||||
) -> Result<usize> {
|
||||
let active_branch_tree = repo.find_tree(branch.tree.into())?;
|
||||
let active_branch_tree = repo.find_tree(branch.tree)?;
|
||||
|
||||
let commit = repo.find_commit(head_sha.into())?;
|
||||
let commit = repo.find_commit(head_sha)?;
|
||||
let head_tree = commit.tree()?;
|
||||
let virtual_branches = head_tree
|
||||
.get_name("virtual_branches")
|
||||
|
@ -1,5 +1,4 @@
|
||||
use crate::fs::write;
|
||||
use crate::git;
|
||||
use anyhow::{Context, Result};
|
||||
use gix::config::tree::Key;
|
||||
use std::path::Path;
|
||||
@ -27,8 +26,8 @@ use crate::virtual_branches::integration::{
|
||||
/// The reflog entry is continuously updated to refer to the current target and oplog head commits.
|
||||
pub(super) fn set_reference_to_oplog(
|
||||
worktree_dir: &Path,
|
||||
target_commit_id: git::Oid,
|
||||
oplog_commit_id: git::Oid,
|
||||
target_commit_id: git2::Oid,
|
||||
oplog_commit_id: git2::Oid,
|
||||
) -> Result<()> {
|
||||
let reflog_file_path = worktree_dir
|
||||
.join(".git")
|
||||
@ -150,13 +149,12 @@ fn serialize_line(line: gix::refs::file::log::LineRef<'_>) -> String {
|
||||
#[cfg(test)]
|
||||
mod set_target_ref {
|
||||
use super::{
|
||||
git, set_reference_to_oplog, GITBUTLER_INTEGRATION_COMMIT_AUTHOR_EMAIL,
|
||||
set_reference_to_oplog, GITBUTLER_INTEGRATION_COMMIT_AUTHOR_EMAIL,
|
||||
GITBUTLER_INTEGRATION_COMMIT_AUTHOR_NAME,
|
||||
};
|
||||
use gix::refs::file::log::LineRef;
|
||||
use pretty_assertions::assert_eq;
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
use tempfile::tempdir;
|
||||
|
||||
#[test]
|
||||
@ -164,13 +162,13 @@ mod set_target_ref {
|
||||
let (dir, commit_id) = setup_repo()?;
|
||||
let worktree_dir = dir.path();
|
||||
|
||||
let oplog = git::Oid::from_str("0123456789abcdef0123456789abcdef0123456")?;
|
||||
set_reference_to_oplog(worktree_dir, commit_id.into(), oplog).expect("success");
|
||||
let oplog = git2::Oid::from_str("0123456789abcdef0123456789abcdef0123456")?;
|
||||
set_reference_to_oplog(worktree_dir, commit_id, oplog).expect("success");
|
||||
|
||||
let log_file_path = worktree_dir.join(".git/logs/refs/heads/gitbutler/target");
|
||||
std::fs::write(&log_file_path, [])?;
|
||||
|
||||
set_reference_to_oplog(worktree_dir, commit_id.into(), oplog).expect("success");
|
||||
set_reference_to_oplog(worktree_dir, commit_id, oplog).expect("success");
|
||||
|
||||
let contents = std::fs::read_to_string(&log_file_path)?;
|
||||
assert_eq!(reflog_lines(&contents).len(), 2);
|
||||
@ -186,13 +184,13 @@ mod set_target_ref {
|
||||
let (dir, commit_id) = setup_repo()?;
|
||||
let worktree_dir = dir.path();
|
||||
|
||||
let oplog = git::Oid::from_str("0123456789abcdef0123456789abcdef0123456")?;
|
||||
set_reference_to_oplog(worktree_dir, commit_id.into(), oplog).expect("success");
|
||||
let oplog = git2::Oid::from_str("0123456789abcdef0123456789abcdef0123456")?;
|
||||
set_reference_to_oplog(worktree_dir, commit_id, oplog).expect("success");
|
||||
|
||||
let log_file_path = worktree_dir.join(".git/logs/refs/heads/gitbutler/target");
|
||||
std::fs::write(&log_file_path, b"a gobbled mess that is no reflog")?;
|
||||
|
||||
set_reference_to_oplog(worktree_dir, commit_id.into(), oplog).expect("success");
|
||||
set_reference_to_oplog(worktree_dir, commit_id, oplog).expect("success");
|
||||
|
||||
let contents = std::fs::read_to_string(&log_file_path)?;
|
||||
assert_eq!(reflog_lines(&contents).len(), 2);
|
||||
@ -204,13 +202,13 @@ mod set_target_ref {
|
||||
let (dir, commit_id) = setup_repo()?;
|
||||
let worktree_dir = dir.path();
|
||||
|
||||
let oplog = git::Oid::from_str("0123456789abcdef0123456789abcdef0123456")?;
|
||||
set_reference_to_oplog(worktree_dir, commit_id.into(), oplog).expect("success");
|
||||
let oplog = git2::Oid::from_str("0123456789abcdef0123456789abcdef0123456")?;
|
||||
set_reference_to_oplog(worktree_dir, commit_id, oplog).expect("success");
|
||||
|
||||
let loose_ref_path = worktree_dir.join(".git/refs/heads/gitbutler/target");
|
||||
std::fs::remove_file(&loose_ref_path)?;
|
||||
|
||||
set_reference_to_oplog(worktree_dir, commit_id.into(), oplog).expect("success");
|
||||
set_reference_to_oplog(worktree_dir, commit_id, oplog).expect("success");
|
||||
assert!(
|
||||
loose_ref_path.is_file(),
|
||||
"the file was recreated, just in case there is only a reflog and no branch"
|
||||
@ -223,13 +221,13 @@ mod set_target_ref {
|
||||
let (dir, commit_id) = setup_repo()?;
|
||||
let worktree_dir = dir.path();
|
||||
|
||||
let oplog = git::Oid::from_str("0123456789abcdef0123456789abcdef0123456")?;
|
||||
set_reference_to_oplog(worktree_dir, commit_id.into(), oplog).expect("success");
|
||||
let oplog = git2::Oid::from_str("0123456789abcdef0123456789abcdef0123456")?;
|
||||
set_reference_to_oplog(worktree_dir, commit_id, oplog).expect("success");
|
||||
|
||||
let log_file_path = worktree_dir.join(".git/logs/refs/heads/gitbutler/target");
|
||||
std::fs::remove_file(&log_file_path)?;
|
||||
|
||||
set_reference_to_oplog(worktree_dir, commit_id.into(), oplog)
|
||||
set_reference_to_oplog(worktree_dir, commit_id, oplog)
|
||||
.expect("missing reflog files are recreated");
|
||||
assert!(log_file_path.is_file(), "the file was recreated");
|
||||
|
||||
@ -251,8 +249,8 @@ mod set_target_ref {
|
||||
|
||||
// Set ref for the first time
|
||||
let oplog_hex = "0123456789abcdef0123456789abcdef01234567";
|
||||
let oplog = git::Oid::from_str(oplog_hex)?;
|
||||
set_reference_to_oplog(worktree_dir, commit_id.into(), oplog).expect("success");
|
||||
let oplog = git2::Oid::from_str(oplog_hex)?;
|
||||
set_reference_to_oplog(worktree_dir, commit_id, oplog).expect("success");
|
||||
assert!(log_file_path.exists());
|
||||
let contents = std::fs::read_to_string(&log_file_path)?;
|
||||
let lines = reflog_lines(&contents);
|
||||
@ -285,8 +283,8 @@ mod set_target_ref {
|
||||
|
||||
// Update the oplog head only
|
||||
let another_oplog_hex = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb";
|
||||
let another_oplog = git::Oid::from_str(another_oplog_hex)?;
|
||||
set_reference_to_oplog(worktree_dir, commit_id.into(), another_oplog).expect("success");
|
||||
let another_oplog = git2::Oid::from_str(another_oplog_hex)?;
|
||||
set_reference_to_oplog(worktree_dir, commit_id, another_oplog).expect("success");
|
||||
|
||||
let contents = std::fs::read_to_string(&log_file_path)?;
|
||||
let lines: Vec<_> = reflog_lines(&contents);
|
||||
@ -314,7 +312,7 @@ mod set_target_ref {
|
||||
|
||||
// Update the target head only
|
||||
let new_target_hex = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
|
||||
let new_target = git::Oid::from_str(new_target_hex)?;
|
||||
let new_target = git2::Oid::from_str(new_target_hex)?;
|
||||
set_reference_to_oplog(worktree_dir, new_target, another_oplog).expect("success");
|
||||
|
||||
let contents = std::fs::read_to_string(&log_file_path)?;
|
||||
|
@ -3,7 +3,6 @@ use std::vec;
|
||||
|
||||
use crate::projects::Project;
|
||||
use crate::{
|
||||
git,
|
||||
ops::entry::{OperationKind, SnapshotDetails},
|
||||
virtual_branches::{branch::BranchUpdateRequest, Branch},
|
||||
};
|
||||
@ -14,7 +13,7 @@ use super::entry::Trailer;
|
||||
impl Project {
|
||||
pub(crate) fn snapshot_branch_applied(
|
||||
&self,
|
||||
snapshot_tree: git::Oid,
|
||||
snapshot_tree: git2::Oid,
|
||||
result: Result<&String, &anyhow::Error>,
|
||||
) -> anyhow::Result<()> {
|
||||
let result = result.map(|o| Some(o.clone()));
|
||||
@ -25,7 +24,7 @@ impl Project {
|
||||
}
|
||||
pub(crate) fn snapshot_branch_unapplied(
|
||||
&self,
|
||||
snapshot_tree: git::Oid,
|
||||
snapshot_tree: git2::Oid,
|
||||
result: Result<&Option<Branch>, &anyhow::Error>,
|
||||
) -> anyhow::Result<()> {
|
||||
let result = result.map(|o| o.clone().map(|b| b.name));
|
||||
@ -36,9 +35,9 @@ impl Project {
|
||||
}
|
||||
pub(crate) fn snapshot_commit_undo(
|
||||
&self,
|
||||
snapshot_tree: git::Oid,
|
||||
snapshot_tree: git2::Oid,
|
||||
result: Result<&(), &anyhow::Error>,
|
||||
commit_sha: git::Oid,
|
||||
commit_sha: git2::Oid,
|
||||
) -> anyhow::Result<()> {
|
||||
let result = result.map(|_| Some(commit_sha.to_string()));
|
||||
let details = SnapshotDetails::new(OperationKind::UndoCommit)
|
||||
@ -48,10 +47,10 @@ impl Project {
|
||||
}
|
||||
pub(crate) fn snapshot_commit_creation(
|
||||
&self,
|
||||
snapshot_tree: git::Oid,
|
||||
snapshot_tree: git2::Oid,
|
||||
error: Option<&anyhow::Error>,
|
||||
commit_message: String,
|
||||
sha: Option<git::Oid>,
|
||||
sha: Option<git2::Oid>,
|
||||
) -> anyhow::Result<()> {
|
||||
let details = SnapshotDetails::new(OperationKind::CreateCommit).with_trailers(
|
||||
[
|
||||
|
@ -5,7 +5,6 @@ use std::{
|
||||
};
|
||||
|
||||
use crate::fs::read_toml_file_or_default;
|
||||
use crate::git;
|
||||
use serde::{Deserialize, Deserializer, Serialize};
|
||||
|
||||
use super::OPLOG_FILE_NAME;
|
||||
@ -27,8 +26,8 @@ fn unix_epoch() -> SystemTime {
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
pub struct Oplog {
|
||||
/// This is the sha of the last oplog commit
|
||||
#[serde(with = "crate::serde::oid_opt")]
|
||||
pub head_sha: Option<git::Oid>,
|
||||
#[serde(with = "crate::serde::oid_opt", default)]
|
||||
pub head_sha: Option<git2::Oid>,
|
||||
/// The time when the last snapshot was created. Seconds since Epoch
|
||||
#[serde(
|
||||
deserialize_with = "unfailing_system_time_deserialize",
|
||||
@ -61,7 +60,7 @@ impl OplogHandle {
|
||||
/// Persists the oplog head for the given repository.
|
||||
///
|
||||
/// Errors if the file cannot be read or written.
|
||||
pub fn set_oplog_head(&self, sha: git::Oid) -> Result<()> {
|
||||
pub fn set_oplog_head(&self, sha: git2::Oid) -> Result<()> {
|
||||
let mut oplog = self.read_file()?;
|
||||
oplog.head_sha = Some(sha);
|
||||
self.write_file(oplog)?;
|
||||
@ -71,7 +70,7 @@ impl OplogHandle {
|
||||
/// Gets the oplog head sha for the given repository.
|
||||
///
|
||||
/// Errors if the file cannot be read or written.
|
||||
pub fn oplog_head(&self) -> Result<Option<git::Oid>> {
|
||||
pub fn oplog_head(&self) -> Result<Option<git2::Oid>> {
|
||||
let oplog = self.read_file()?;
|
||||
Ok(oplog.head_sha)
|
||||
}
|
||||
|
@ -14,12 +14,11 @@ use anyhow::Result;
|
||||
use itertools::Itertools;
|
||||
|
||||
use super::Repository;
|
||||
use crate::git;
|
||||
|
||||
pub fn mark<P: AsRef<Path>, A: AsRef<[P]>>(
|
||||
repository: &Repository,
|
||||
paths: A,
|
||||
parent: Option<git::Oid>,
|
||||
parent: Option<git2::Oid>,
|
||||
) -> Result<()> {
|
||||
let paths = paths.as_ref();
|
||||
if paths.is_empty() {
|
||||
@ -43,7 +42,7 @@ pub fn mark<P: AsRef<Path>, A: AsRef<[P]>>(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn merge_parent(repository: &Repository) -> Result<Option<git::Oid>> {
|
||||
pub fn merge_parent(repository: &Repository) -> Result<Option<git2::Oid>> {
|
||||
let merge_path = repository.repo().path().join("base_merge_parent");
|
||||
if !merge_path.exists() {
|
||||
return Ok(None);
|
||||
@ -54,7 +53,7 @@ pub fn merge_parent(repository: &Repository) -> Result<Option<git::Oid>> {
|
||||
let mut lines = reader.lines();
|
||||
if let Some(parent) = lines.next() {
|
||||
let parent = parent?;
|
||||
let parent: git::Oid = parent.parse()?;
|
||||
let parent: git2::Oid = parent.parse()?;
|
||||
Ok(Some(parent))
|
||||
} else {
|
||||
Ok(None)
|
||||
|
@ -7,6 +7,7 @@ use std::{
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
|
||||
use super::conflicts;
|
||||
use crate::error::Code;
|
||||
use crate::{
|
||||
askpass,
|
||||
git::{self, Url},
|
||||
@ -14,7 +15,6 @@ use crate::{
|
||||
ssh, users,
|
||||
virtual_branches::{Branch, BranchId},
|
||||
};
|
||||
use crate::{error::Code, git::Oid};
|
||||
use crate::{git::RepositoryExt, virtual_branches::errors::Marker};
|
||||
|
||||
pub struct Repository {
|
||||
@ -156,7 +156,7 @@ impl Repository {
|
||||
.find_branch_by_refname(&target_branch_refname)?
|
||||
.ok_or(anyhow!("failed to find branch {}", target_branch_refname))?;
|
||||
|
||||
let commit_id: Oid = branch.get().peel_to_commit()?.id().into();
|
||||
let commit_id: git2::Oid = branch.get().peel_to_commit()?.id();
|
||||
|
||||
let now = crate::time::now_ms();
|
||||
let branch_name = format!("test-push-{now}");
|
||||
@ -191,7 +191,7 @@ impl Repository {
|
||||
.find_reference(&branch.refname().to_string())
|
||||
{
|
||||
Ok(reference) => match reference.target() {
|
||||
Some(head_oid) => Ok((head_oid != branch.head.into(), true)),
|
||||
Some(head_oid) => Ok((head_oid != branch.head, true)),
|
||||
None => Ok((true, true)),
|
||||
},
|
||||
Err(err) => match err.code() {
|
||||
@ -205,7 +205,7 @@ impl Repository {
|
||||
self.git_repository
|
||||
.reference(
|
||||
&branch.refname().to_string(),
|
||||
branch.head.into(),
|
||||
branch.head,
|
||||
with_force,
|
||||
"new vbranch",
|
||||
)
|
||||
@ -235,7 +235,7 @@ impl Repository {
|
||||
}
|
||||
|
||||
// returns a list of commit oids from the first oid to the second oid
|
||||
pub fn l(&self, from: git::Oid, to: LogUntil) -> Result<Vec<git::Oid>> {
|
||||
pub fn l(&self, from: git2::Oid, to: LogUntil) -> Result<Vec<git2::Oid>> {
|
||||
match to {
|
||||
LogUntil::Commit(oid) => {
|
||||
let mut revwalk = self
|
||||
@ -243,10 +243,10 @@ impl Repository {
|
||||
.revwalk()
|
||||
.context("failed to create revwalk")?;
|
||||
revwalk
|
||||
.push(from.into())
|
||||
.push(from)
|
||||
.context(format!("failed to push {}", from))?;
|
||||
revwalk
|
||||
.hide(oid.into())
|
||||
.hide(oid)
|
||||
.context(format!("failed to hide {}", oid))?;
|
||||
revwalk
|
||||
.map(|oid| oid.map(Into::into))
|
||||
@ -258,7 +258,7 @@ impl Repository {
|
||||
.revwalk()
|
||||
.context("failed to create revwalk")?;
|
||||
revwalk
|
||||
.push(from.into())
|
||||
.push(from)
|
||||
.context(format!("failed to push {}", from))?;
|
||||
revwalk
|
||||
.take(n)
|
||||
@ -271,12 +271,12 @@ impl Repository {
|
||||
.revwalk()
|
||||
.context("failed to create revwalk")?;
|
||||
revwalk
|
||||
.push(from.into())
|
||||
.push(from)
|
||||
.context(format!("failed to push {}", from))?;
|
||||
let mut oids: Vec<git::Oid> = vec![];
|
||||
let mut oids: Vec<git2::Oid> = vec![];
|
||||
for oid in revwalk {
|
||||
let oid = oid.context("failed to get oid")?;
|
||||
oids.push(oid.into());
|
||||
oids.push(oid);
|
||||
|
||||
let commit = self
|
||||
.git_repository
|
||||
@ -295,7 +295,7 @@ impl Repository {
|
||||
.revwalk()
|
||||
.context("failed to create revwalk")?;
|
||||
revwalk
|
||||
.push(from.into())
|
||||
.push(from)
|
||||
.context(format!("failed to push {}", from))?;
|
||||
revwalk
|
||||
.map(|oid| oid.map(Into::into))
|
||||
@ -306,29 +306,29 @@ impl Repository {
|
||||
}
|
||||
|
||||
// returns a list of oids from the first oid to the second oid
|
||||
pub fn list(&self, from: git::Oid, to: git::Oid) -> Result<Vec<git::Oid>> {
|
||||
pub fn list(&self, from: git2::Oid, to: git2::Oid) -> Result<Vec<git2::Oid>> {
|
||||
self.l(from, LogUntil::Commit(to))
|
||||
}
|
||||
|
||||
pub fn list_commits(&self, from: git::Oid, to: git::Oid) -> Result<Vec<git2::Commit>> {
|
||||
pub fn list_commits(&self, from: git2::Oid, to: git2::Oid) -> Result<Vec<git2::Commit>> {
|
||||
Ok(self
|
||||
.list(from, to)?
|
||||
.into_iter()
|
||||
.map(|oid| self.git_repository.find_commit(oid.into()))
|
||||
.map(|oid| self.git_repository.find_commit(oid))
|
||||
.collect::<Result<Vec<_>, _>>()?)
|
||||
}
|
||||
|
||||
// returns a list of commits from the first oid to the second oid
|
||||
pub fn log(&self, from: git::Oid, to: LogUntil) -> Result<Vec<git2::Commit>> {
|
||||
pub fn log(&self, from: git2::Oid, to: LogUntil) -> Result<Vec<git2::Commit>> {
|
||||
self.l(from, to)?
|
||||
.into_iter()
|
||||
.map(|oid| self.git_repository.find_commit(oid.into()))
|
||||
.map(|oid| self.git_repository.find_commit(oid))
|
||||
.collect::<Result<Vec<_>, _>>()
|
||||
.context("failed to collect commits")
|
||||
}
|
||||
|
||||
// returns the number of commits between the first oid to the second oid
|
||||
pub fn distance(&self, from: git::Oid, to: git::Oid) -> Result<u32> {
|
||||
pub fn distance(&self, from: git2::Oid, to: git2::Oid) -> Result<u32> {
|
||||
let oids = self.l(from, LogUntil::Commit(to))?;
|
||||
Ok(oids.len().try_into()?)
|
||||
}
|
||||
@ -426,7 +426,7 @@ impl Repository {
|
||||
|
||||
pub fn push(
|
||||
&self,
|
||||
head: &git::Oid,
|
||||
head: &git2::Oid,
|
||||
branch: &git::RemoteRefname,
|
||||
with_force: bool,
|
||||
credentials: &git::credentials::Helper,
|
||||
@ -628,7 +628,7 @@ impl Repository {
|
||||
type OidFilter = dyn Fn(&git2::Commit) -> Result<bool>;
|
||||
|
||||
pub enum LogUntil {
|
||||
Commit(git::Oid),
|
||||
Commit(git2::Oid),
|
||||
Take(usize),
|
||||
When(Box<OidFilter>),
|
||||
End,
|
||||
|
@ -5,9 +5,7 @@ use std::{
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
git, id::Id, types::default_true::DefaultTrue, virtual_branches::VirtualBranchesHandle,
|
||||
};
|
||||
use crate::{id::Id, types::default_true::DefaultTrue, virtual_branches::VirtualBranchesHandle};
|
||||
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize, PartialEq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
@ -57,7 +55,8 @@ impl FetchResult {
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Copy, Clone)]
|
||||
pub struct CodePushState {
|
||||
pub id: git::Oid,
|
||||
#[serde(with = "crate::serde::oid")]
|
||||
pub id: git2::Oid,
|
||||
pub timestamp: time::SystemTime,
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ use std::time;
|
||||
|
||||
use crate::id::Id;
|
||||
use crate::{
|
||||
git::{self, Oid},
|
||||
git::{self},
|
||||
project_repository,
|
||||
projects::{self, CodePushState},
|
||||
users,
|
||||
@ -57,7 +57,7 @@ async fn push_target(
|
||||
projects: &projects::Controller,
|
||||
project_repository: &project_repository::Repository,
|
||||
default_target: &crate::virtual_branches::target::Target,
|
||||
gb_code_last_commit: Option<Oid>,
|
||||
gb_code_last_commit: Option<git2::Oid>,
|
||||
project_id: Id<projects::Project>,
|
||||
user: &users::User,
|
||||
batch_size: usize,
|
||||
@ -106,27 +106,26 @@ async fn push_target(
|
||||
fn batch_rev_walk(
|
||||
repo: &git2::Repository,
|
||||
batch_size: usize,
|
||||
from: Oid,
|
||||
until: Option<Oid>,
|
||||
) -> Result<Vec<Oid>> {
|
||||
from: git2::Oid,
|
||||
until: Option<git2::Oid>,
|
||||
) -> Result<Vec<git2::Oid>> {
|
||||
let mut revwalk = repo.revwalk().context("failed to create revwalk")?;
|
||||
revwalk
|
||||
.push(from.into())
|
||||
.push(from)
|
||||
.context(format!("failed to push {}", from))?;
|
||||
if let Some(oid) = until {
|
||||
revwalk
|
||||
.hide(oid.into())
|
||||
.hide(oid)
|
||||
.context(format!("failed to hide {}", oid))?;
|
||||
}
|
||||
let mut oids = Vec::new();
|
||||
oids.push(from);
|
||||
|
||||
let from = from.into();
|
||||
for batch in &revwalk.chunks(batch_size) {
|
||||
let Some(oid) = batch.last() else { continue };
|
||||
let oid = oid.context("failed to get oid")?;
|
||||
if oid != from {
|
||||
oids.push(oid.into());
|
||||
oids.push(oid);
|
||||
}
|
||||
}
|
||||
Ok(oids)
|
||||
@ -177,7 +176,7 @@ fn push_all_refs(
|
||||
async fn update_project(
|
||||
projects: &projects::Controller,
|
||||
project_id: Id<projects::Project>,
|
||||
id: Oid,
|
||||
id: git2::Oid,
|
||||
) -> Result<()> {
|
||||
projects
|
||||
.update(&projects::UpdateRequest {
|
||||
|
@ -28,8 +28,10 @@ pub struct BaseBranch {
|
||||
pub remote_url: String,
|
||||
pub push_remote_name: Option<String>,
|
||||
pub push_remote_url: String,
|
||||
pub base_sha: git::Oid,
|
||||
pub current_sha: git::Oid,
|
||||
#[serde(with = "crate::serde::oid")]
|
||||
pub base_sha: git2::Oid,
|
||||
#[serde(with = "crate::serde::oid")]
|
||||
pub current_sha: git2::Oid,
|
||||
pub behind: usize,
|
||||
pub upstream_commits: Vec<RemoteCommit>,
|
||||
pub recent_commits: Vec<RemoteCommit>,
|
||||
@ -72,7 +74,7 @@ fn go_back_to_integration(
|
||||
|
||||
let target_commit = project_repository
|
||||
.repo()
|
||||
.find_commit(default_target.sha.into())
|
||||
.find_commit(default_target.sha)
|
||||
.context("failed to find target commit")?;
|
||||
|
||||
let base_tree = target_commit
|
||||
@ -85,7 +87,7 @@ fn go_back_to_integration(
|
||||
// merge this branches tree with our tree
|
||||
let branch_head = project_repository
|
||||
.repo()
|
||||
.find_commit(branch.head.into())
|
||||
.find_commit(branch.head)
|
||||
.context("failed to find branch head")?;
|
||||
let branch_tree = branch_head
|
||||
.tree()
|
||||
@ -168,7 +170,7 @@ pub fn set_base_branch(
|
||||
let target = target::Target {
|
||||
branch: target_branch_ref.clone(),
|
||||
remote_url: remote_url.to_string(),
|
||||
sha: target_commit_oid.into(),
|
||||
sha: target_commit_oid,
|
||||
push_remote_name: None,
|
||||
};
|
||||
|
||||
@ -188,7 +190,7 @@ pub fn set_base_branch(
|
||||
// put them into a virtual branch
|
||||
|
||||
let wd_diff = diff::workdir(repo, ¤t_head_commit.id())?;
|
||||
if !wd_diff.is_empty() || current_head_commit.id() != target.sha.into() {
|
||||
if !wd_diff.is_empty() || current_head_commit.id() != target.sha {
|
||||
// assign ownership to the branch
|
||||
let ownership = wd_diff.iter().fold(
|
||||
BranchOwnershipClaims::default(),
|
||||
@ -241,13 +243,13 @@ pub fn set_base_branch(
|
||||
notes: String::new(),
|
||||
applied: true,
|
||||
upstream,
|
||||
upstream_head: upstream_head.map(|h| h.into()),
|
||||
upstream_head,
|
||||
created_timestamp_ms: now_ms,
|
||||
updated_timestamp_ms: now_ms,
|
||||
head: current_head_commit.id().into(),
|
||||
head: current_head_commit.id(),
|
||||
tree: super::write_tree_onto_commit(
|
||||
project_repository,
|
||||
current_head_commit.id().into(),
|
||||
current_head_commit.id(),
|
||||
diff::diff_files_into_hunks(wd_diff),
|
||||
)?,
|
||||
ownership,
|
||||
@ -345,7 +347,7 @@ pub fn update_base_branch(
|
||||
|
||||
let mut unapplied_branches: Vec<branch::Branch> = Vec::new();
|
||||
|
||||
if new_target_commit.id() == target.sha.into() {
|
||||
if new_target_commit.id() == target.sha {
|
||||
return Ok(unapplied_branches);
|
||||
}
|
||||
|
||||
@ -353,13 +355,10 @@ pub fn update_base_branch(
|
||||
.tree()
|
||||
.context("failed to get new target commit tree")?;
|
||||
|
||||
let old_target_tree = repo
|
||||
.find_commit(target.sha.into())?
|
||||
.tree()
|
||||
.context(format!(
|
||||
"failed to get old target commit tree {}",
|
||||
target.sha
|
||||
))?;
|
||||
let old_target_tree = repo.find_commit(target.sha)?.tree().context(format!(
|
||||
"failed to get old target commit tree {}",
|
||||
target.sha
|
||||
))?;
|
||||
|
||||
let vb_state = project_repository.project().virtual_branches();
|
||||
let integration_commit = get_workspace_head(&vb_state, project_repository)?;
|
||||
@ -372,13 +371,12 @@ pub fn update_base_branch(
|
||||
.map(|(branch, _)| branch)
|
||||
.map(
|
||||
|mut branch: branch::Branch| -> Result<Option<branch::Branch>> {
|
||||
let branch_tree = repo.find_tree(branch.tree.into())?;
|
||||
let branch_tree = repo.find_tree(branch.tree)?;
|
||||
|
||||
let branch_head_commit =
|
||||
repo.find_commit(branch.head.into()).context(format!(
|
||||
"failed to find commit {} for branch {}",
|
||||
branch.head, branch.id
|
||||
))?;
|
||||
let branch_head_commit = repo.find_commit(branch.head).context(format!(
|
||||
"failed to find commit {} for branch {}",
|
||||
branch.head, branch.id
|
||||
))?;
|
||||
let branch_head_tree = branch_head_commit.tree().context(format!(
|
||||
"failed to find tree for commit {} for branch {}",
|
||||
branch.head, branch.id
|
||||
@ -389,7 +387,7 @@ pub fn update_base_branch(
|
||||
// branch head tree is the same as the new target tree.
|
||||
// meaning we can safely use the new target commit as the branch head.
|
||||
|
||||
branch.head = new_target_commit.id().into();
|
||||
branch.head = new_target_commit.id();
|
||||
|
||||
// it also means that the branch is fully integrated into the target.
|
||||
// disconnect it from the upstream
|
||||
@ -441,8 +439,8 @@ pub fn update_base_branch(
|
||||
|
||||
if branch.head == target.sha {
|
||||
// there are no commits on the branch, so we can just update the head to the new target and calculate the new tree
|
||||
branch.head = new_target_commit.id().into();
|
||||
branch.tree = branch_merge_index_tree_oid.into();
|
||||
branch.head = new_target_commit.id();
|
||||
branch.tree = branch_merge_index_tree_oid;
|
||||
vb_state.set_branch(branch.clone())?;
|
||||
return Ok(Some(branch));
|
||||
}
|
||||
@ -499,8 +497,8 @@ pub fn update_base_branch(
|
||||
)
|
||||
.context("failed to commit merge")?;
|
||||
|
||||
branch.head = new_target_head.into();
|
||||
branch.tree = branch_merge_index_tree_oid.into();
|
||||
branch.head = new_target_head;
|
||||
branch.tree = branch_merge_index_tree_oid;
|
||||
vb_state.set_branch(branch.clone())?;
|
||||
Ok(Some(branch))
|
||||
};
|
||||
@ -512,8 +510,8 @@ pub fn update_base_branch(
|
||||
// branch was not pushed to upstream yet. attempt a rebase,
|
||||
let rebased_head_oid = cherry_rebase(
|
||||
project_repository,
|
||||
new_target_commit.id().into(),
|
||||
new_target_commit.id().into(),
|
||||
new_target_commit.id(),
|
||||
new_target_commit.id(),
|
||||
branch.head,
|
||||
);
|
||||
|
||||
@ -525,7 +523,7 @@ pub fn update_base_branch(
|
||||
if let Some(rebased_head_oid) = rebased_head_oid? {
|
||||
// rebase worked out, rewrite the branch head
|
||||
branch.head = rebased_head_oid;
|
||||
branch.tree = branch_merge_index_tree_oid.into();
|
||||
branch.tree = branch_merge_index_tree_oid;
|
||||
vb_state.set_branch(branch.clone())?;
|
||||
return Ok(Some(branch));
|
||||
}
|
||||
@ -547,7 +545,7 @@ pub fn update_base_branch(
|
||||
.fold(new_target_commit.tree(), |final_tree, branch| {
|
||||
let repo: &git2::Repository = repo;
|
||||
let final_tree = final_tree?;
|
||||
let branch_tree = repo.find_tree(branch.tree.into())?;
|
||||
let branch_tree = repo.find_tree(branch.tree)?;
|
||||
let mut merge_result: Index =
|
||||
repo.merge_trees(&new_target_tree, &final_tree, &branch_tree, None)?;
|
||||
let final_tree_oid = merge_result.write_tree_to(repo)?;
|
||||
@ -562,7 +560,7 @@ pub fn update_base_branch(
|
||||
|
||||
// write new target oid
|
||||
vb_state.set_default_target(target::Target {
|
||||
sha: new_target_commit.id().into(),
|
||||
sha: new_target_commit.id(),
|
||||
..target
|
||||
})?;
|
||||
|
||||
@ -584,7 +582,7 @@ pub fn target_to_base_branch(
|
||||
|
||||
// gather a list of commits between oid and target.sha
|
||||
let upstream_commits = project_repository
|
||||
.log(oid.into(), project_repository::LogUntil::Commit(target.sha))
|
||||
.log(oid, project_repository::LogUntil::Commit(target.sha))
|
||||
.context("failed to get upstream commits")?
|
||||
.iter()
|
||||
.map(super::commit_to_remote_commit)
|
||||
@ -617,7 +615,7 @@ pub fn target_to_base_branch(
|
||||
push_remote_name: target.push_remote_name.clone(),
|
||||
push_remote_url,
|
||||
base_sha: target.sha,
|
||||
current_sha: oid.into(),
|
||||
current_sha: oid,
|
||||
behind: upstream_commits.len(),
|
||||
upstream_commits,
|
||||
recent_commits,
|
||||
|
@ -16,7 +16,7 @@ pub type BranchId = Id<Branch>;
|
||||
// store. it is more or less equivalent to a git branch reference, but it is not
|
||||
// stored or accessible from the git repository itself. it is stored in our
|
||||
// session storage under the branches/ directory.
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone, Default)]
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)]
|
||||
pub struct Branch {
|
||||
pub id: BranchId,
|
||||
pub name: String,
|
||||
@ -24,7 +24,8 @@ pub struct Branch {
|
||||
pub applied: bool,
|
||||
pub upstream: Option<git::RemoteRefname>,
|
||||
// upstream_head is the last commit on we've pushed to the upstream branch
|
||||
pub upstream_head: Option<git::Oid>,
|
||||
#[serde(with = "crate::serde::oid_opt", default)]
|
||||
pub upstream_head: Option<git2::Oid>,
|
||||
#[serde(
|
||||
serialize_with = "serialize_u128",
|
||||
deserialize_with = "deserialize_u128"
|
||||
@ -36,9 +37,11 @@ pub struct Branch {
|
||||
)]
|
||||
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
|
||||
pub tree: git::Oid,
|
||||
#[serde(with = "crate::serde::oid")]
|
||||
pub tree: git2::Oid,
|
||||
/// head is id of the last "virtual" commit in this branch
|
||||
pub head: git::Oid,
|
||||
#[serde(with = "crate::serde::oid")]
|
||||
pub head: git2::Oid,
|
||||
pub ownership: BranchOwnershipClaims,
|
||||
// order is the number by which UI should sort branches
|
||||
pub order: usize,
|
||||
|
@ -55,7 +55,7 @@ impl Controller {
|
||||
message: &str,
|
||||
ownership: Option<&BranchOwnershipClaims>,
|
||||
run_hooks: bool,
|
||||
) -> Result<git::Oid> {
|
||||
) -> Result<git2::Oid> {
|
||||
self.inner(project_id)
|
||||
.await
|
||||
.create_commit(project_id, branch_id, message, ownership, run_hooks)
|
||||
@ -123,7 +123,7 @@ impl Controller {
|
||||
pub async fn list_remote_commit_files(
|
||||
&self,
|
||||
project_id: ProjectId,
|
||||
commit_oid: git::Oid,
|
||||
commit_oid: git2::Oid,
|
||||
) -> Result<Vec<RemoteBranchFile>> {
|
||||
self.inner(project_id)
|
||||
.await
|
||||
@ -222,9 +222,9 @@ impl Controller {
|
||||
&self,
|
||||
project_id: ProjectId,
|
||||
branch_id: BranchId,
|
||||
commit_oid: git::Oid,
|
||||
commit_oid: git2::Oid,
|
||||
ownership: &BranchOwnershipClaims,
|
||||
) -> Result<git::Oid> {
|
||||
) -> Result<git2::Oid> {
|
||||
self.inner(project_id)
|
||||
.await
|
||||
.amend(project_id, branch_id, commit_oid, ownership)
|
||||
@ -235,10 +235,10 @@ impl Controller {
|
||||
&self,
|
||||
project_id: ProjectId,
|
||||
branch_id: BranchId,
|
||||
from_commit_oid: git::Oid,
|
||||
to_commit_oid: git::Oid,
|
||||
from_commit_oid: git2::Oid,
|
||||
to_commit_oid: git2::Oid,
|
||||
ownership: &BranchOwnershipClaims,
|
||||
) -> Result<git::Oid> {
|
||||
) -> Result<git2::Oid> {
|
||||
self.inner(project_id)
|
||||
.await
|
||||
.move_commit_file(
|
||||
@ -255,7 +255,7 @@ impl Controller {
|
||||
&self,
|
||||
project_id: ProjectId,
|
||||
branch_id: BranchId,
|
||||
commit_oid: git::Oid,
|
||||
commit_oid: git2::Oid,
|
||||
) -> Result<()> {
|
||||
self.inner(project_id)
|
||||
.await
|
||||
@ -267,7 +267,7 @@ impl Controller {
|
||||
&self,
|
||||
project_id: ProjectId,
|
||||
branch_id: BranchId,
|
||||
commit_oid: git::Oid,
|
||||
commit_oid: git2::Oid,
|
||||
offset: i32,
|
||||
) -> Result<()> {
|
||||
self.inner(project_id)
|
||||
@ -280,7 +280,7 @@ impl Controller {
|
||||
&self,
|
||||
project_id: ProjectId,
|
||||
branch_id: BranchId,
|
||||
commit_oid: git::Oid,
|
||||
commit_oid: git2::Oid,
|
||||
offset: i32,
|
||||
) -> Result<()> {
|
||||
self.inner(project_id)
|
||||
@ -293,7 +293,7 @@ impl Controller {
|
||||
&self,
|
||||
project_id: ProjectId,
|
||||
branch_id: BranchId,
|
||||
target_commit_oid: git::Oid,
|
||||
target_commit_oid: git2::Oid,
|
||||
) -> Result<()> {
|
||||
self.inner(project_id)
|
||||
.await
|
||||
@ -360,7 +360,7 @@ impl Controller {
|
||||
&self,
|
||||
project_id: ProjectId,
|
||||
branch_id: BranchId,
|
||||
commit_oid: git::Oid,
|
||||
commit_oid: git2::Oid,
|
||||
) -> Result<()> {
|
||||
self.inner(project_id)
|
||||
.await
|
||||
@ -372,7 +372,7 @@ impl Controller {
|
||||
&self,
|
||||
project_id: ProjectId,
|
||||
branch_id: BranchId,
|
||||
commit_oid: git::Oid,
|
||||
commit_oid: git2::Oid,
|
||||
message: &str,
|
||||
) -> Result<()> {
|
||||
self.inner(project_id)
|
||||
@ -396,7 +396,7 @@ impl Controller {
|
||||
&self,
|
||||
project_id: ProjectId,
|
||||
target_branch_id: BranchId,
|
||||
commit_oid: git::Oid,
|
||||
commit_oid: git2::Oid,
|
||||
) -> Result<()> {
|
||||
self.inner(project_id)
|
||||
.await
|
||||
@ -435,7 +435,7 @@ impl ControllerInner {
|
||||
message: &str,
|
||||
ownership: Option<&BranchOwnershipClaims>,
|
||||
run_hooks: bool,
|
||||
) -> Result<git::Oid> {
|
||||
) -> Result<git2::Oid> {
|
||||
let _permit = self.semaphore.acquire().await;
|
||||
|
||||
self.with_verify_branch(project_id, |project_repository, user| {
|
||||
@ -527,7 +527,7 @@ impl ControllerInner {
|
||||
pub fn list_remote_commit_files(
|
||||
&self,
|
||||
project_id: ProjectId,
|
||||
commit_oid: git::Oid,
|
||||
commit_oid: git2::Oid,
|
||||
) -> Result<Vec<RemoteBranchFile>> {
|
||||
let project = self.projects.get(project_id)?;
|
||||
let project_repository = project_repository::Repository::open(&project)?;
|
||||
@ -656,9 +656,9 @@ impl ControllerInner {
|
||||
&self,
|
||||
project_id: ProjectId,
|
||||
branch_id: BranchId,
|
||||
commit_oid: git::Oid,
|
||||
commit_oid: git2::Oid,
|
||||
ownership: &BranchOwnershipClaims,
|
||||
) -> Result<git::Oid> {
|
||||
) -> Result<git2::Oid> {
|
||||
let _permit = self.semaphore.acquire().await;
|
||||
|
||||
self.with_verify_branch(project_id, |project_repository, _| {
|
||||
@ -673,10 +673,10 @@ impl ControllerInner {
|
||||
&self,
|
||||
project_id: ProjectId,
|
||||
branch_id: BranchId,
|
||||
from_commit_oid: git::Oid,
|
||||
to_commit_oid: git::Oid,
|
||||
from_commit_oid: git2::Oid,
|
||||
to_commit_oid: git2::Oid,
|
||||
ownership: &BranchOwnershipClaims,
|
||||
) -> Result<git::Oid> {
|
||||
) -> Result<git2::Oid> {
|
||||
let _permit = self.semaphore.acquire().await;
|
||||
|
||||
self.with_verify_branch(project_id, |project_repository, _| {
|
||||
@ -698,7 +698,7 @@ impl ControllerInner {
|
||||
&self,
|
||||
project_id: ProjectId,
|
||||
branch_id: BranchId,
|
||||
commit_oid: git::Oid,
|
||||
commit_oid: git2::Oid,
|
||||
) -> Result<()> {
|
||||
let _permit = self.semaphore.acquire().await;
|
||||
|
||||
@ -721,7 +721,7 @@ impl ControllerInner {
|
||||
&self,
|
||||
project_id: ProjectId,
|
||||
branch_id: BranchId,
|
||||
commit_oid: git::Oid,
|
||||
commit_oid: git2::Oid,
|
||||
offset: i32,
|
||||
) -> Result<()> {
|
||||
let _permit = self.semaphore.acquire().await;
|
||||
@ -739,7 +739,7 @@ impl ControllerInner {
|
||||
&self,
|
||||
project_id: ProjectId,
|
||||
branch_id: BranchId,
|
||||
commit_oid: git::Oid,
|
||||
commit_oid: git2::Oid,
|
||||
offset: i32,
|
||||
) -> Result<()> {
|
||||
let _permit = self.semaphore.acquire().await;
|
||||
@ -757,7 +757,7 @@ impl ControllerInner {
|
||||
&self,
|
||||
project_id: ProjectId,
|
||||
branch_id: BranchId,
|
||||
target_commit_oid: git::Oid,
|
||||
target_commit_oid: git2::Oid,
|
||||
) -> Result<()> {
|
||||
let _permit = self.semaphore.acquire().await;
|
||||
|
||||
@ -840,7 +840,7 @@ impl ControllerInner {
|
||||
&self,
|
||||
project_id: ProjectId,
|
||||
branch_id: BranchId,
|
||||
commit_oid: git::Oid,
|
||||
commit_oid: git2::Oid,
|
||||
) -> Result<()> {
|
||||
let _permit = self.semaphore.acquire().await;
|
||||
|
||||
@ -856,7 +856,7 @@ impl ControllerInner {
|
||||
&self,
|
||||
project_id: ProjectId,
|
||||
branch_id: BranchId,
|
||||
commit_oid: git::Oid,
|
||||
commit_oid: git2::Oid,
|
||||
message: &str,
|
||||
) -> Result<()> {
|
||||
let _permit = self.semaphore.acquire().await;
|
||||
@ -932,7 +932,7 @@ impl ControllerInner {
|
||||
&self,
|
||||
project_id: ProjectId,
|
||||
target_branch_id: BranchId,
|
||||
commit_oid: git::Oid,
|
||||
commit_oid: git2::Oid,
|
||||
) -> Result<()> {
|
||||
let _permit = self.semaphore.acquire().await;
|
||||
|
||||
|
@ -3,7 +3,7 @@ use std::path;
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use serde::Serialize;
|
||||
|
||||
use crate::git::{self, diff};
|
||||
use crate::git::diff;
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
@ -15,10 +15,10 @@ pub struct RemoteBranchFile {
|
||||
|
||||
pub fn list_remote_commit_files(
|
||||
repository: &git2::Repository,
|
||||
commit_id: git::Oid,
|
||||
commit_id: git2::Oid,
|
||||
) -> Result<Vec<RemoteBranchFile>> {
|
||||
let commit = repository
|
||||
.find_commit(commit_id.into())
|
||||
.find_commit(commit_id)
|
||||
.map_err(|err| match err.code() {
|
||||
git2::ErrorCode::NotFound => anyhow!("commit {commit_id} not found"),
|
||||
_ => err.into(),
|
||||
|
@ -36,7 +36,7 @@ fn get_committer<'a>() -> Result<git2::Signature<'a>> {
|
||||
pub fn get_workspace_head(
|
||||
vb_state: &VirtualBranchesHandle,
|
||||
project_repo: &project_repository::Repository,
|
||||
) -> Result<git::Oid> {
|
||||
) -> Result<git2::Oid> {
|
||||
let target = vb_state
|
||||
.get_default_target()
|
||||
.context("failed to get target")?;
|
||||
@ -49,7 +49,7 @@ pub fn get_workspace_head(
|
||||
.filter(|branch| branch.applied)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let target_commit = repo.find_commit(target.sha.into())?;
|
||||
let target_commit = repo.find_commit(target.sha)?;
|
||||
let mut workspace_tree = target_commit.tree()?;
|
||||
|
||||
if conflicts::is_conflicting(project_repo, None)? {
|
||||
@ -57,12 +57,12 @@ pub fn get_workspace_head(
|
||||
conflicts::merge_parent(project_repo)?.ok_or(anyhow!("No merge parent"))?;
|
||||
let first_branch = applied_branches.first().ok_or(anyhow!("No branches"))?;
|
||||
|
||||
let merge_base = repo.merge_base(first_branch.head.into(), merge_parent.into())?;
|
||||
let merge_base = repo.merge_base(first_branch.head, merge_parent)?;
|
||||
workspace_tree = repo.find_commit(merge_base)?.tree()?;
|
||||
} else {
|
||||
for branch in &applied_branches {
|
||||
let branch_tree = repo.find_commit(branch.head.into())?.tree()?;
|
||||
let merge_tree = repo.find_commit(target.sha.into())?.tree()?;
|
||||
let branch_tree = repo.find_commit(branch.head)?.tree()?;
|
||||
let merge_tree = repo.find_commit(target.sha)?.tree()?;
|
||||
let mut index = repo.merge_trees(&merge_tree, &workspace_tree, &branch_tree, None)?;
|
||||
|
||||
if !index.has_conflicts() {
|
||||
@ -75,13 +75,13 @@ pub fn get_workspace_head(
|
||||
|
||||
let branch_heads = applied_branches
|
||||
.iter()
|
||||
.map(|b| repo.find_commit(b.head.into()))
|
||||
.map(|b| repo.find_commit(b.head))
|
||||
.collect::<Result<Vec<_>, _>>()?;
|
||||
let branch_head_refs = branch_heads.iter().collect::<Vec<_>>();
|
||||
|
||||
// If no branches are applied then the workspace head is the target.
|
||||
if branch_head_refs.is_empty() {
|
||||
return Ok(target_commit.id().into());
|
||||
return Ok(target_commit.id());
|
||||
}
|
||||
|
||||
// TODO(mg): Can we make this a constant?
|
||||
@ -90,7 +90,7 @@ pub fn get_workspace_head(
|
||||
let mut heads: Vec<git2::Commit<'_>> = applied_branches
|
||||
.iter()
|
||||
.filter(|b| b.head != target.sha)
|
||||
.map(|b| repo.find_commit(b.head.into()))
|
||||
.map(|b| repo.find_commit(b.head))
|
||||
.filter_map(Result::ok)
|
||||
.collect();
|
||||
|
||||
@ -110,7 +110,7 @@ pub fn get_workspace_head(
|
||||
&workspace_tree,
|
||||
head_refs.as_slice(),
|
||||
)?;
|
||||
Ok(workspace_head_id.into())
|
||||
Ok(workspace_head_id)
|
||||
}
|
||||
|
||||
// Before switching the user to our gitbutler integration branch we save
|
||||
@ -144,7 +144,7 @@ fn write_integration_file(head: &git2::Reference, path: PathBuf) -> Result<()> {
|
||||
pub fn update_gitbutler_integration(
|
||||
vb_state: &VirtualBranchesHandle,
|
||||
project_repository: &project_repository::Repository,
|
||||
) -> Result<git::Oid> {
|
||||
) -> Result<git2::Oid> {
|
||||
let target = vb_state
|
||||
.get_default_target()
|
||||
.context("failed to get target")?;
|
||||
@ -152,7 +152,7 @@ pub fn update_gitbutler_integration(
|
||||
let repo: &git2::Repository = project_repository.repo();
|
||||
|
||||
// get commit object from target.sha
|
||||
let target_commit = repo.find_commit(target.sha.into())?;
|
||||
let target_commit = repo.find_commit(target.sha)?;
|
||||
|
||||
// get current repo head for reference
|
||||
let head_ref = repo.head()?;
|
||||
@ -183,7 +183,7 @@ pub fn update_gitbutler_integration(
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let integration_commit =
|
||||
repo.find_commit(get_workspace_head(&vb_state, project_repository)?.into())?;
|
||||
repo.find_commit(get_workspace_head(&vb_state, project_repository)?)?;
|
||||
let integration_tree = integration_commit.tree()?;
|
||||
|
||||
// message that says how to get back to where they were
|
||||
@ -256,8 +256,8 @@ pub fn update_gitbutler_integration(
|
||||
|
||||
// finally, update the refs/gitbutler/ heads to the states of the current virtual branches
|
||||
for branch in &all_virtual_branches {
|
||||
let wip_tree = repo.find_tree(branch.tree.into())?;
|
||||
let mut branch_head = repo.find_commit(branch.head.into())?;
|
||||
let wip_tree = repo.find_tree(branch.tree)?;
|
||||
let mut branch_head = repo.find_commit(branch.head)?;
|
||||
let head_tree = branch_head.tree()?;
|
||||
|
||||
// create a wip commit if there is wip
|
||||
@ -290,7 +290,7 @@ pub fn update_gitbutler_integration(
|
||||
)?;
|
||||
}
|
||||
|
||||
Ok(final_commit.into())
|
||||
Ok(final_commit)
|
||||
}
|
||||
|
||||
pub fn verify_branch(project_repository: &project_repository::Repository) -> Result<()> {
|
||||
@ -342,10 +342,7 @@ impl project_repository::Repository {
|
||||
.context("failed to get default target")?;
|
||||
|
||||
let mut extra_commits = self
|
||||
.log(
|
||||
head_commit.id().into(),
|
||||
LogUntil::Commit(default_target.sha),
|
||||
)
|
||||
.log(head_commit.id(), LogUntil::Commit(default_target.sha))
|
||||
.context("failed to get log")?;
|
||||
|
||||
let integration_commit = extra_commits.pop();
|
||||
@ -386,7 +383,7 @@ impl project_repository::Repository {
|
||||
for commit in extra_commits {
|
||||
let new_branch_head = self
|
||||
.repo()
|
||||
.find_commit(head.into())
|
||||
.find_commit(head)
|
||||
.context("failed to find new branch head")?;
|
||||
|
||||
let rebased_commit_oid = self
|
||||
@ -413,13 +410,13 @@ impl project_repository::Repository {
|
||||
rebased_commit_oid
|
||||
))?;
|
||||
|
||||
new_branch.head = rebased_commit.id().into();
|
||||
new_branch.tree = rebased_commit.tree_id().into();
|
||||
new_branch.head = rebased_commit.id();
|
||||
new_branch.tree = rebased_commit.tree_id();
|
||||
vb_state
|
||||
.set_branch(new_branch.clone())
|
||||
.context("failed to write branch")?;
|
||||
|
||||
head = rebased_commit.id().into();
|
||||
head = rebased_commit.id();
|
||||
}
|
||||
Ok(self)
|
||||
}
|
||||
|
@ -22,7 +22,8 @@ use crate::{
|
||||
#[derive(Debug, Clone, Serialize, PartialEq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct RemoteBranch {
|
||||
pub sha: git::Oid,
|
||||
#[serde(with = "crate::serde::oid")]
|
||||
pub sha: git2::Oid,
|
||||
pub name: git::Refname,
|
||||
pub upstream: Option<git::RemoteRefname>,
|
||||
pub last_commit_timestamp_ms: Option<u128>,
|
||||
@ -32,12 +33,14 @@ pub struct RemoteBranch {
|
||||
#[derive(Debug, Clone, Serialize, PartialEq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct RemoteBranchData {
|
||||
pub sha: git::Oid,
|
||||
#[serde(with = "crate::serde::oid")]
|
||||
pub sha: git2::Oid,
|
||||
pub name: git::Refname,
|
||||
pub upstream: Option<git::RemoteRefname>,
|
||||
pub behind: u32,
|
||||
pub commits: Vec<RemoteCommit>,
|
||||
pub fork_point: Option<git::Oid>,
|
||||
#[serde(with = "crate::serde::oid_opt", default)]
|
||||
pub fork_point: Option<git2::Oid>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize)]
|
||||
@ -49,7 +52,8 @@ pub struct RemoteCommit {
|
||||
pub created_at: u128,
|
||||
pub author: Author,
|
||||
pub change_id: Option<String>,
|
||||
pub parent_ids: Vec<git::Oid>,
|
||||
#[serde(with = "crate::serde::oid_vec")]
|
||||
pub parent_ids: Vec<git2::Oid>,
|
||||
}
|
||||
|
||||
// for legacy purposes, this is still named "remote" branches, but it's actually
|
||||
@ -117,7 +121,7 @@ pub fn branch_to_remote_branch(branch: &git2::Branch) -> Result<Option<RemoteBra
|
||||
.target()
|
||||
.map(|sha| {
|
||||
Ok(RemoteBranch {
|
||||
sha: sha.into(),
|
||||
sha,
|
||||
upstream: if let git::Refname::Local(local_name) = &name {
|
||||
local_name.remote().cloned()
|
||||
} else {
|
||||
@ -144,29 +148,26 @@ pub fn branch_to_remote_branch(branch: &git2::Branch) -> Result<Option<RemoteBra
|
||||
pub fn branch_to_remote_branch_data(
|
||||
project_repository: &project_repository::Repository,
|
||||
branch: &git2::Branch,
|
||||
base: git::Oid,
|
||||
base: git2::Oid,
|
||||
) -> Result<Option<RemoteBranchData>> {
|
||||
branch
|
||||
.get()
|
||||
.target()
|
||||
.map(|sha| {
|
||||
let ahead = project_repository
|
||||
.log(sha.into(), LogUntil::Commit(base))
|
||||
.log(sha, LogUntil::Commit(base))
|
||||
.context("failed to get ahead commits")?;
|
||||
|
||||
let name = git::Refname::try_from(branch).context("could not get branch name")?;
|
||||
|
||||
let count_behind = project_repository
|
||||
.distance(base, sha.into())
|
||||
.distance(base, sha)
|
||||
.context("failed to get behind count")?;
|
||||
|
||||
let fork_point = ahead
|
||||
.last()
|
||||
.and_then(|c| c.parent(0).ok())
|
||||
.map(|c| c.id().into());
|
||||
let fork_point = ahead.last().and_then(|c| c.parent(0).ok()).map(|c| c.id());
|
||||
|
||||
Ok(RemoteBranchData {
|
||||
sha: sha.into(),
|
||||
sha,
|
||||
upstream: if let git::Refname::Local(local_name) = &name {
|
||||
local_name.remote().cloned()
|
||||
} else {
|
||||
@ -185,10 +186,7 @@ pub fn branch_to_remote_branch_data(
|
||||
}
|
||||
|
||||
pub fn commit_to_remote_commit(commit: &git2::Commit) -> RemoteCommit {
|
||||
let parent_ids: Vec<git::Oid> = commit
|
||||
.parents()
|
||||
.map(|c| git::Oid::from(c.id()))
|
||||
.collect::<Vec<_>>();
|
||||
let parent_ids: Vec<git2::Oid> = commit.parents().map(|c| c.id()).collect::<Vec<_>>();
|
||||
RemoteCommit {
|
||||
id: commit.id().to_string(),
|
||||
description: commit.message_bstr().to_owned(),
|
||||
|
@ -1,5 +1,3 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use serde::{ser::SerializeStruct, Deserialize, Deserializer, Serialize, Serializer};
|
||||
|
||||
use crate::git;
|
||||
@ -8,7 +6,7 @@ use crate::git;
|
||||
pub struct Target {
|
||||
pub branch: git::RemoteRefname,
|
||||
pub remote_url: String,
|
||||
pub sha: git::Oid,
|
||||
pub sha: git2::Oid,
|
||||
pub push_remote_name: Option<String>,
|
||||
}
|
||||
|
||||
@ -41,7 +39,7 @@ impl<'de> serde::Deserialize<'de> for Target {
|
||||
sha: String,
|
||||
}
|
||||
let target_data: TargetData = serde::Deserialize::deserialize(d)?;
|
||||
let sha = git::Oid::from_str(&target_data.sha)
|
||||
let sha = git2::Oid::from_str(&target_data.sha)
|
||||
.map_err(|x| serde::de::Error::custom(x.message()))?;
|
||||
|
||||
let target = Target {
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -88,7 +88,7 @@ mod snapshot_details {
|
||||
|
||||
#[test]
|
||||
fn new() {
|
||||
let commit_sha = git2::Oid::zero().into();
|
||||
let commit_sha = git2::Oid::zero();
|
||||
let commit_message =
|
||||
"Create a new snapshot\n\nBody text 1\nBody text2\n\nBody text 3\n\nVersion: 1\nOperation: CreateCommit\nFoo: Bar\n".to_string();
|
||||
let timezone_offset_does_not_matter = 1234;
|
||||
|
@ -57,7 +57,7 @@ mod cleanly {
|
||||
);
|
||||
|
||||
let cherry_picked_commit_oid = controller
|
||||
.cherry_pick(*project_id, branch_id, commit_two.into())
|
||||
.cherry_pick(*project_id, branch_id, commit_two)
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(cherry_picked_commit_oid.is_some());
|
||||
@ -72,10 +72,7 @@ mod cleanly {
|
||||
assert_eq!(branches[0].id, branch_id);
|
||||
assert!(branches[0].active);
|
||||
assert_eq!(branches[0].commits.len(), 2);
|
||||
assert_eq!(
|
||||
branches[0].commits[0].id,
|
||||
cherry_picked_commit_oid.unwrap().into()
|
||||
);
|
||||
assert_eq!(branches[0].commits[0].id, cherry_picked_commit_oid.unwrap());
|
||||
assert_eq!(branches[0].commits[1].id, commit_one);
|
||||
}
|
||||
|
||||
@ -138,7 +135,7 @@ mod cleanly {
|
||||
.unwrap();
|
||||
|
||||
let cherry_picked_commit_oid = controller
|
||||
.cherry_pick(*project_id, branch_two_id, commit_two.into())
|
||||
.cherry_pick(*project_id, branch_two_id, commit_two)
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(cherry_picked_commit_oid.is_some());
|
||||
@ -159,10 +156,7 @@ mod cleanly {
|
||||
assert_eq!(branches[1].id, branch_two_id);
|
||||
assert!(branches[1].active);
|
||||
assert_eq!(branches[1].commits.len(), 1);
|
||||
assert_eq!(
|
||||
branches[1].commits[0].id,
|
||||
cherry_picked_commit_oid.unwrap().into()
|
||||
);
|
||||
assert_eq!(branches[1].commits[0].id, cherry_picked_commit_oid.unwrap());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@ -220,7 +214,7 @@ mod cleanly {
|
||||
|
||||
assert_eq!(
|
||||
controller
|
||||
.cherry_pick(*project_id, branch_id, commit_three_oid.into())
|
||||
.cherry_pick(*project_id, branch_id, commit_three_oid)
|
||||
.await
|
||||
.unwrap_err()
|
||||
.to_string(),
|
||||
@ -300,7 +294,7 @@ mod with_conflicts {
|
||||
{
|
||||
// cherry picking leads to conflict
|
||||
let cherry_picked_commit_oid = controller
|
||||
.cherry_pick(*project_id, branch_id, commit_three.into())
|
||||
.cherry_pick(*project_id, branch_id, commit_three)
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(cherry_picked_commit_oid.is_none());
|
||||
@ -382,7 +376,7 @@ mod with_conflicts {
|
||||
|
||||
assert_eq!(
|
||||
controller
|
||||
.cherry_pick(*project_id, branch_id, commit_oid.into())
|
||||
.cherry_pick(*project_id, branch_id, commit_oid)
|
||||
.await
|
||||
.unwrap_err()
|
||||
.to_string(),
|
||||
|
@ -56,9 +56,9 @@ async fn move_file_down() {
|
||||
|
||||
// shas changed but change_id is the same
|
||||
assert_eq!(&commit1.change_id(), &branch.commits[1].change_id);
|
||||
assert_ne!(&commit1.id(), &branch.commits[1].id.into());
|
||||
assert_ne!(&commit1.id(), &branch.commits[1].id);
|
||||
assert_eq!(&commit2.change_id(), &branch.commits[0].change_id);
|
||||
assert_ne!(&commit2.id(), &branch.commits[0].id.into());
|
||||
assert_ne!(&commit2.id(), &branch.commits[0].id);
|
||||
|
||||
assert_eq!(branch.commits[0].files.len(), 1);
|
||||
assert_eq!(branch.commits.len(), 2);
|
||||
|
@ -1,9 +1,4 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use gitbutler_core::{
|
||||
git,
|
||||
virtual_branches::{branch, BranchId},
|
||||
};
|
||||
use gitbutler_core::virtual_branches::{branch, BranchId};
|
||||
|
||||
use crate::suite::virtual_branches::Test;
|
||||
|
||||
@ -285,7 +280,7 @@ async fn no_commit() {
|
||||
.move_commit(
|
||||
*project_id,
|
||||
target_branch_id,
|
||||
git::Oid::from_str(commit_id_hex).unwrap()
|
||||
git2::Oid::from_str(commit_id_hex).unwrap()
|
||||
)
|
||||
.await
|
||||
.unwrap_err()
|
||||
|
@ -225,13 +225,13 @@ async fn basic_oplog() -> anyhow::Result<()> {
|
||||
|
||||
// try to look up that object
|
||||
let repo = git2::Repository::open(&project.path)?;
|
||||
let commit = repo.find_commit(commit2_id.into());
|
||||
let commit = repo.find_commit(commit2_id);
|
||||
assert!(commit.is_err());
|
||||
|
||||
project.restore_snapshot(snapshots[1].clone().commit_id)?;
|
||||
|
||||
// test missing commits are recreated
|
||||
let commit = repo.find_commit(commit2_id.into());
|
||||
let commit = repo.find_commit(commit2_id);
|
||||
assert!(commit.is_ok());
|
||||
|
||||
let file_path = repository.path().join("large.txt");
|
||||
|
@ -2,7 +2,7 @@ use std::{path::PathBuf, vec};
|
||||
|
||||
use gitbutler_core::virtual_branches::{
|
||||
branch::{reconcile_claims, BranchOwnershipClaims, Hunk, OwnershipClaim},
|
||||
Branch,
|
||||
Branch, BranchId,
|
||||
};
|
||||
|
||||
#[test]
|
||||
@ -31,7 +31,16 @@ fn reconcile_ownership_simple() {
|
||||
}],
|
||||
},
|
||||
applied: true,
|
||||
..Default::default()
|
||||
tree: git2::Oid::zero(),
|
||||
head: git2::Oid::zero(),
|
||||
id: BranchId::default(),
|
||||
notes: String::default(),
|
||||
upstream: None,
|
||||
upstream_head: None,
|
||||
created_timestamp_ms: u128::default(),
|
||||
updated_timestamp_ms: u128::default(),
|
||||
order: usize::default(),
|
||||
selected_for_changes: None,
|
||||
};
|
||||
let branch_b = Branch {
|
||||
name: "b".to_string(),
|
||||
@ -48,7 +57,16 @@ fn reconcile_ownership_simple() {
|
||||
}],
|
||||
},
|
||||
applied: true,
|
||||
..Default::default()
|
||||
tree: git2::Oid::zero(),
|
||||
head: git2::Oid::zero(),
|
||||
id: BranchId::default(),
|
||||
notes: String::default(),
|
||||
upstream: None,
|
||||
upstream_head: None,
|
||||
created_timestamp_ms: u128::default(),
|
||||
updated_timestamp_ms: u128::default(),
|
||||
order: usize::default(),
|
||||
selected_for_changes: None,
|
||||
};
|
||||
let all_branches: Vec<Branch> = vec![branch_a.clone(), branch_b.clone()];
|
||||
let claim: Vec<OwnershipClaim> = vec![OwnershipClaim {
|
||||
|
@ -170,7 +170,7 @@ fn track_binary_files() -> Result<()> {
|
||||
let commit_id = &branches[0].commits[0].id;
|
||||
let commit_obj = project_repository
|
||||
.repo()
|
||||
.find_commit(commit_id.to_owned().into())?;
|
||||
.find_commit(commit_id.to_owned())?;
|
||||
let tree = commit_obj.tree()?;
|
||||
let files = tree_to_entry_list(project_repository.repo(), &tree);
|
||||
assert_eq!(files[0].0, "image.bin");
|
||||
@ -203,7 +203,7 @@ fn track_binary_files() -> Result<()> {
|
||||
// get tree from commit_id
|
||||
let commit_obj = project_repository
|
||||
.repo()
|
||||
.find_commit(commit_id.to_owned().into())?;
|
||||
.find_commit(commit_id.to_owned())?;
|
||||
let tree = commit_obj.tree()?;
|
||||
let files = tree_to_entry_list(project_repository.repo(), &tree);
|
||||
|
||||
@ -793,7 +793,7 @@ fn merge_vbranch_upstream_clean_rebase() -> Result<()> {
|
||||
vb_state.set_default_target(virtual_branches::target::Target {
|
||||
branch: "refs/remotes/origin/master".parse().unwrap(),
|
||||
remote_url: "origin".to_string(),
|
||||
sha: target_oid.into(),
|
||||
sha: target_oid,
|
||||
push_remote_name: None,
|
||||
})?;
|
||||
|
||||
@ -808,7 +808,7 @@ fn merge_vbranch_upstream_clean_rebase() -> Result<()> {
|
||||
let mut branch = create_virtual_branch(project_repository, &BranchCreateRequest::default())
|
||||
.expect("failed to create virtual branch");
|
||||
branch.upstream = Some(remote_branch.clone());
|
||||
branch.head = last_push.into();
|
||||
branch.head = last_push;
|
||||
vb_state.set_branch(branch.clone())?;
|
||||
|
||||
// create the branch
|
||||
@ -902,7 +902,7 @@ async fn merge_vbranch_upstream_conflict() -> Result<()> {
|
||||
vb_state.set_default_target(virtual_branches::target::Target {
|
||||
branch: "refs/remotes/origin/master".parse().unwrap(),
|
||||
remote_url: "origin".to_string(),
|
||||
sha: target_oid.into(),
|
||||
sha: target_oid,
|
||||
push_remote_name: None,
|
||||
})?;
|
||||
|
||||
@ -916,7 +916,7 @@ async fn merge_vbranch_upstream_conflict() -> Result<()> {
|
||||
let mut branch = create_virtual_branch(project_repository, &BranchCreateRequest::default())
|
||||
.expect("failed to create virtual branch");
|
||||
branch.upstream = Some(remote_branch.clone());
|
||||
branch.head = last_push.into();
|
||||
branch.head = last_push;
|
||||
vb_state.set_branch(branch.clone())?;
|
||||
|
||||
// create the branch
|
||||
@ -970,9 +970,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
|
||||
.repo()
|
||||
.find_commit(last_id.to_owned().into())?;
|
||||
let last_commit = project_repository.repo().find_commit(last_id.to_owned())?;
|
||||
assert_eq!(last_commit.parent_count(), 2);
|
||||
|
||||
Ok(())
|
||||
@ -1370,7 +1368,7 @@ fn upstream_integrated_vbranch() -> Result<()> {
|
||||
vb_state.set_default_target(virtual_branches::target::Target {
|
||||
branch: "refs/remotes/origin/master".parse().unwrap(),
|
||||
remote_url: "http://origin.com/project".to_string(),
|
||||
sha: base_commit.into(),
|
||||
sha: base_commit,
|
||||
push_remote_name: None,
|
||||
})?;
|
||||
project_repository
|
||||
@ -1768,7 +1766,7 @@ fn commit_partial_by_file() -> Result<()> {
|
||||
let commit2 = &branch1.commits[0].id;
|
||||
let commit2 = project_repository
|
||||
.repo()
|
||||
.find_commit(commit2.to_owned().into())
|
||||
.find_commit(commit2.to_owned())
|
||||
.expect("failed to get commit object");
|
||||
|
||||
let tree = commit1.tree().expect("failed to get tree");
|
||||
@ -1827,7 +1825,7 @@ fn commit_add_and_delete_files() -> Result<()> {
|
||||
let commit2 = &branch1.commits[0].id;
|
||||
let commit2 = project_repository
|
||||
.repo()
|
||||
.find_commit(commit2.to_owned().into())
|
||||
.find_commit(commit2.to_owned())
|
||||
.expect("failed to get commit object");
|
||||
|
||||
let tree = commit1.tree().expect("failed to get tree");
|
||||
@ -1891,7 +1889,7 @@ fn commit_executable_and_symlinks() -> Result<()> {
|
||||
let commit = &branch1.commits[0].id;
|
||||
let commit = project_repository
|
||||
.repo()
|
||||
.find_commit(commit.to_owned().into())
|
||||
.find_commit(commit.to_owned())
|
||||
.expect("failed to get commit object");
|
||||
|
||||
let tree = commit.tree().expect("failed to get tree");
|
||||
|
@ -1,6 +1,6 @@
|
||||
pub mod commands {
|
||||
use crate::error::Error;
|
||||
use anyhow::Context;
|
||||
use anyhow::{anyhow, Context};
|
||||
use gitbutler_core::{
|
||||
assets,
|
||||
error::Code,
|
||||
@ -26,13 +26,13 @@ pub mod commands {
|
||||
message: &str,
|
||||
ownership: Option<BranchOwnershipClaims>,
|
||||
run_hooks: bool,
|
||||
) -> Result<git::Oid, Error> {
|
||||
) -> Result<String, Error> {
|
||||
let oid = handle
|
||||
.state::<Controller>()
|
||||
.create_commit(project_id, branch, message, ownership.as_ref(), run_hooks)
|
||||
.await?;
|
||||
emit_vbranches(&handle, project_id).await;
|
||||
Ok(oid)
|
||||
Ok(oid.to_string())
|
||||
}
|
||||
|
||||
#[tauri::command(async)]
|
||||
@ -307,8 +307,9 @@ pub mod commands {
|
||||
pub async fn list_remote_commit_files(
|
||||
handle: AppHandle,
|
||||
project_id: ProjectId,
|
||||
commit_oid: git::Oid,
|
||||
commit_oid: String,
|
||||
) -> Result<Vec<RemoteBranchFile>, Error> {
|
||||
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
|
||||
handle
|
||||
.state::<Controller>()
|
||||
.list_remote_commit_files(project_id, commit_oid)
|
||||
@ -322,8 +323,9 @@ pub mod commands {
|
||||
handle: AppHandle,
|
||||
project_id: ProjectId,
|
||||
branch_id: BranchId,
|
||||
target_commit_oid: git::Oid,
|
||||
target_commit_oid: String,
|
||||
) -> Result<(), Error> {
|
||||
let target_commit_oid = git2::Oid::from_str(&target_commit_oid).map_err(|e| anyhow!(e))?;
|
||||
handle
|
||||
.state::<Controller>()
|
||||
.reset_virtual_branch(project_id, branch_id, target_commit_oid)
|
||||
@ -338,14 +340,15 @@ pub mod commands {
|
||||
handle: AppHandle,
|
||||
project_id: ProjectId,
|
||||
branch_id: BranchId,
|
||||
target_commit_oid: git::Oid,
|
||||
) -> Result<Option<git::Oid>, Error> {
|
||||
target_commit_oid: String,
|
||||
) -> Result<Option<String>, Error> {
|
||||
let target_commit_oid = git2::Oid::from_str(&target_commit_oid).map_err(|e| anyhow!(e))?;
|
||||
let oid = handle
|
||||
.state::<Controller>()
|
||||
.cherry_pick(project_id, branch_id, target_commit_oid.into())
|
||||
.cherry_pick(project_id, branch_id, target_commit_oid)
|
||||
.await?;
|
||||
emit_vbranches(&handle, project_id).await;
|
||||
Ok(oid.map(Into::into))
|
||||
Ok(oid.map(|o| o.to_string()))
|
||||
}
|
||||
|
||||
#[tauri::command(async)]
|
||||
@ -354,15 +357,16 @@ pub mod commands {
|
||||
handle: AppHandle,
|
||||
project_id: ProjectId,
|
||||
branch_id: BranchId,
|
||||
commit_oid: git::Oid,
|
||||
commit_oid: String,
|
||||
ownership: BranchOwnershipClaims,
|
||||
) -> Result<git::Oid, Error> {
|
||||
) -> Result<String, Error> {
|
||||
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
|
||||
let oid = handle
|
||||
.state::<Controller>()
|
||||
.amend(project_id, branch_id, commit_oid, &ownership)
|
||||
.await?;
|
||||
emit_vbranches(&handle, project_id).await;
|
||||
Ok(oid)
|
||||
Ok(oid.to_string())
|
||||
}
|
||||
|
||||
#[tauri::command(async)]
|
||||
@ -371,10 +375,12 @@ pub mod commands {
|
||||
handle: AppHandle,
|
||||
project_id: ProjectId,
|
||||
branch_id: BranchId,
|
||||
from_commit_oid: git::Oid,
|
||||
to_commit_oid: git::Oid,
|
||||
from_commit_oid: String,
|
||||
to_commit_oid: String,
|
||||
ownership: BranchOwnershipClaims,
|
||||
) -> Result<git::Oid, Error> {
|
||||
) -> Result<String, Error> {
|
||||
let from_commit_oid = git2::Oid::from_str(&from_commit_oid).map_err(|e| anyhow!(e))?;
|
||||
let to_commit_oid = git2::Oid::from_str(&to_commit_oid).map_err(|e| anyhow!(e))?;
|
||||
let oid = handle
|
||||
.state::<Controller>()
|
||||
.move_commit_file(
|
||||
@ -386,7 +392,7 @@ pub mod commands {
|
||||
)
|
||||
.await?;
|
||||
emit_vbranches(&handle, project_id).await;
|
||||
Ok(oid)
|
||||
Ok(oid.to_string())
|
||||
}
|
||||
|
||||
#[tauri::command(async)]
|
||||
@ -395,8 +401,9 @@ pub mod commands {
|
||||
handle: AppHandle,
|
||||
project_id: ProjectId,
|
||||
branch_id: BranchId,
|
||||
commit_oid: git::Oid,
|
||||
commit_oid: String,
|
||||
) -> Result<(), Error> {
|
||||
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
|
||||
handle
|
||||
.state::<Controller>()
|
||||
.undo_commit(project_id, branch_id, commit_oid)
|
||||
@ -411,9 +418,10 @@ pub mod commands {
|
||||
handle: AppHandle,
|
||||
project_id: ProjectId,
|
||||
branch_id: BranchId,
|
||||
commit_oid: git::Oid,
|
||||
commit_oid: String,
|
||||
offset: i32,
|
||||
) -> Result<(), Error> {
|
||||
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
|
||||
handle
|
||||
.state::<Controller>()
|
||||
.insert_blank_commit(project_id, branch_id, commit_oid, offset)
|
||||
@ -428,9 +436,10 @@ pub mod commands {
|
||||
handle: AppHandle,
|
||||
project_id: ProjectId,
|
||||
branch_id: BranchId,
|
||||
commit_oid: git::Oid,
|
||||
commit_oid: String,
|
||||
offset: i32,
|
||||
) -> Result<(), Error> {
|
||||
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
|
||||
handle
|
||||
.state::<Controller>()
|
||||
.reorder_commit(project_id, branch_id, commit_oid, offset)
|
||||
@ -476,8 +485,9 @@ pub mod commands {
|
||||
handle: tauri::AppHandle,
|
||||
project_id: ProjectId,
|
||||
branch_id: BranchId,
|
||||
target_commit_oid: git::Oid,
|
||||
target_commit_oid: String,
|
||||
) -> Result<(), Error> {
|
||||
let target_commit_oid = git2::Oid::from_str(&target_commit_oid).map_err(|e| anyhow!(e))?;
|
||||
handle
|
||||
.state::<Controller>()
|
||||
.squash(project_id, branch_id, target_commit_oid)
|
||||
@ -509,9 +519,10 @@ pub mod commands {
|
||||
pub async fn move_commit(
|
||||
handle: tauri::AppHandle,
|
||||
project_id: ProjectId,
|
||||
commit_oid: git::Oid,
|
||||
commit_oid: String,
|
||||
target_branch_id: BranchId,
|
||||
) -> Result<(), Error> {
|
||||
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
|
||||
handle
|
||||
.state::<Controller>()
|
||||
.move_commit(project_id, target_branch_id, commit_oid)
|
||||
@ -526,9 +537,10 @@ pub mod commands {
|
||||
handle: tauri::AppHandle,
|
||||
project_id: ProjectId,
|
||||
branch_id: BranchId,
|
||||
commit_oid: git::Oid,
|
||||
commit_oid: String,
|
||||
message: &str,
|
||||
) -> Result<(), Error> {
|
||||
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
|
||||
handle
|
||||
.state::<Controller>()
|
||||
.update_commit_message(project_id, branch_id, commit_oid, message)
|
||||
|
@ -37,7 +37,7 @@ pub mod virtual_branches {
|
||||
.set_default_target(virtual_branches::target::Target {
|
||||
branch: "refs/remotes/origin/master".parse().unwrap(),
|
||||
remote_url: remote_repo.path().to_str().unwrap().parse().unwrap(),
|
||||
sha: remote_repo.head().unwrap().target().unwrap().into(),
|
||||
sha: remote_repo.head().unwrap().target().unwrap(),
|
||||
push_remote_name: None,
|
||||
})
|
||||
.expect("failed to write target");
|
||||
|
@ -182,7 +182,7 @@ pub fn test_repository() -> (git2::Repository, TempDir) {
|
||||
(repository, tmp)
|
||||
}
|
||||
|
||||
pub fn commit_all(repository: &git2::Repository) -> gitbutler_core::git::Oid {
|
||||
pub fn commit_all(repository: &git2::Repository) -> git2::Oid {
|
||||
let mut index = repository.index().expect("failed to get index");
|
||||
index
|
||||
.add_all(["."], git2::IndexAddOption::DEFAULT, None)
|
||||
@ -209,5 +209,5 @@ pub fn commit_all(repository: &git2::Repository) -> gitbutler_core::git::Oid {
|
||||
None,
|
||||
)
|
||||
.expect("failed to commit");
|
||||
commit_oid.into()
|
||||
commit_oid
|
||||
}
|
||||
|
@ -109,7 +109,7 @@ impl TestProject {
|
||||
/// git add -A
|
||||
/// git reset --hard <oid>
|
||||
/// ```
|
||||
pub fn reset_hard(&self, oid: Option<git::Oid>) {
|
||||
pub fn reset_hard(&self, oid: Option<git2::Oid>) {
|
||||
let mut index = self.local_repository.index().expect("failed to get index");
|
||||
index
|
||||
.add_all(["."], git2::IndexAddOption::DEFAULT, None)
|
||||
@ -118,7 +118,7 @@ impl TestProject {
|
||||
|
||||
let head = self.local_repository.head().unwrap();
|
||||
let commit = oid.map_or(head.peel_to_commit().unwrap(), |oid| {
|
||||
self.local_repository.find_commit(oid.into()).unwrap()
|
||||
self.local_repository.find_commit(oid).unwrap()
|
||||
});
|
||||
|
||||
let head_ref = head.name().unwrap();
|
||||
@ -278,20 +278,15 @@ impl TestProject {
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
pub fn find_commit(&self, oid: git::Oid) -> Result<git2::Commit<'_>, git2::Error> {
|
||||
self.local_repository.find_commit(oid.into())
|
||||
pub fn find_commit(&self, oid: git2::Oid) -> Result<git2::Commit<'_>, git2::Error> {
|
||||
self.local_repository.find_commit(oid)
|
||||
}
|
||||
|
||||
pub fn checkout_commit(&self, commit_oid: git::Oid) {
|
||||
let commit = self
|
||||
.local_repository
|
||||
.find_commit(commit_oid.into())
|
||||
.unwrap();
|
||||
pub fn checkout_commit(&self, commit_oid: git2::Oid) {
|
||||
let commit = self.local_repository.find_commit(commit_oid).unwrap();
|
||||
let commit_tree = commit.tree().unwrap();
|
||||
|
||||
self.local_repository
|
||||
.set_head_detached(commit_oid.into())
|
||||
.unwrap();
|
||||
self.local_repository.set_head_detached(commit_oid).unwrap();
|
||||
self.local_repository
|
||||
.checkout_tree_builder(&commit_tree)
|
||||
.force()
|
||||
@ -337,7 +332,7 @@ impl TestProject {
|
||||
}
|
||||
|
||||
/// takes all changes in the working directory and commits them into local
|
||||
pub fn commit_all(&self, message: &str) -> git::Oid {
|
||||
pub fn commit_all(&self, message: &str) -> git2::Oid {
|
||||
let head = self.local_repository.head().unwrap();
|
||||
let mut index = self.local_repository.index().expect("failed to get index");
|
||||
index
|
||||
@ -368,7 +363,6 @@ impl TestProject {
|
||||
None,
|
||||
)
|
||||
.expect("failed to commit")
|
||||
.into()
|
||||
}
|
||||
|
||||
pub fn references(&self) -> Vec<git2::Reference<'_>> {
|
||||
|
Loading…
Reference in New Issue
Block a user