Skip to content

Commit

Permalink
adapt to changes in gix
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Nov 5, 2024
1 parent a43e563 commit 3ec8136
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 20 deletions.
18 changes: 3 additions & 15 deletions gitoxide-core/src/repository/merge/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::OutputFormat;

pub struct Options {
pub format: OutputFormat,
pub resolve_content_merge: Option<gix::merge::blob::builtin_driver::text::Conflict>,
pub file_favor: Option<gix::merge::tree::FileFavor>,
pub in_memory: bool,
}

Expand All @@ -12,8 +12,6 @@ pub(super) mod function {
use anyhow::{anyhow, bail, Context};
use gix::bstr::BString;
use gix::bstr::ByteSlice;
use gix::merge::blob::builtin_driver::binary;
use gix::merge::blob::builtin_driver::text::Conflict;
use gix::merge::tree::UnresolvedConflict;
use gix::prelude::Write;

Expand All @@ -29,7 +27,7 @@ pub(super) mod function {
theirs: BString,
Options {
format,
resolve_content_merge,
file_favor,
in_memory,
}: Options,
) -> anyhow::Result<()> {
Expand All @@ -44,17 +42,7 @@ pub(super) mod function {
let (ours_ref, ours_id) = refname_and_tree(&repo, ours)?;
let (theirs_ref, theirs_id) = refname_and_tree(&repo, theirs)?;

let mut options = repo.tree_merge_options()?;
if let Some(resolve) = resolve_content_merge {
options.blob_merge.text.conflict = resolve;
options.blob_merge.resolve_binary_with = match resolve {
Conflict::Keep { .. } => None,
Conflict::ResolveWithOurs => Some(binary::ResolveWith::Ours),
Conflict::ResolveWithTheirs => Some(binary::ResolveWith::Theirs),
Conflict::ResolveWithUnion => None,
};
}

let options = repo.tree_merge_options()?.with_file_favor(file_favor);
let base_id_str = base_id.to_string();
let ours_id_str = ours_id.to_string();
let theirs_id_str = theirs_id.to_string();
Expand Down
4 changes: 2 additions & 2 deletions src/plumbing/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ pub fn main() -> Result<()> {
),
merge::SubCommands::Tree {
in_memory,
resolve_content_with,
file_favor,
ours,
base,
theirs,
Expand All @@ -194,7 +194,7 @@ pub fn main() -> Result<()> {
theirs,
core::repository::merge::tree::Options {
format,
resolve_content_merge: resolve_content_with.map(Into::into),
file_favor: file_favor.map(Into::into),
in_memory,
},
)
Expand Down
23 changes: 20 additions & 3 deletions src/plumbing/options/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,23 @@ pub mod merge {
}
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum)]
pub enum FileFavor {
/// Use only ours in case of conflict.
Ours,
/// Use only theirs in case of conflict.
Theirs,
}

impl From<FileFavor> for gix::merge::tree::FileFavor {
fn from(value: FileFavor) -> Self {
match value {
FileFavor::Ours => gix::merge::tree::FileFavor::Ours,
FileFavor::Theirs => gix::merge::tree::FileFavor::Theirs,
}
}
}

#[derive(Debug, clap::Parser)]
#[command(about = "perform merges of various kinds")]
pub struct Platform {
Expand Down Expand Up @@ -400,9 +417,9 @@ pub mod merge {
/// Note that the resulting tree won't be available or inspectable.
#[clap(long, short = 'm')]
in_memory: bool,
/// Decide how to resolve content conflicts. If unset, write conflict markers and fail.
#[clap(long, short = 'c')]
resolve_content_with: Option<ResolveWith>,
/// Decide how to resolve content conflicts in files. If unset, write conflict markers and fail.
#[clap(long, short = 'f')]
file_favor: Option<FileFavor>,

/// A revspec to our treeish.
#[clap(value_name = "OURS", value_parser = crate::shared::AsBString)]
Expand Down

0 comments on commit 3ec8136

Please sign in to comment.