rust-lang / git2-rs

libgit2 bindings for Rust
https://docs.rs/git2
Apache License 2.0
1.64k stars 380 forks source link

Applying diff with renamed file to Index ignores delta callback and removes old file from index #1022

Closed aganzha closed 4 months ago

aganzha commented 4 months ago

How to reproduce:

Estimated behaviour: index remain unchanged. no changes staged. Current behaviour: old file deleted from index.

use git2::{
    Repository, ApplyOptions, ApplyLocation
};

fn main() {

    // just rename 1 file in repositiry and run this.
    // old file will be removed from index.
    let repo = Repository::open("./")
        .expect("can't open repo");
    let git_diff = repo.diff_index_to_workdir(None, None)
        .expect("can't get diff");

    let mut options = ApplyOptions::new();
    options.hunk_callback(|odh| -> bool {
        false
    });
    options.delta_callback(|odd| -> bool {
        false
    });

    repo.apply(
        &git_diff,
        ApplyLocation::Index,
        Some(&mut options),
    ).expect("can't apply patch");
}
extrawurst commented 4 months ago

Probably best to post upstream in libgit2 repo (repro in rust is fine) as git2-rs is just bindings

aganzha commented 4 months ago

Thank You

aganzha commented 4 months ago

https://github.com/libgit2/libgit2/issues/6643

ehuss commented 4 months ago

Thanks! We don't mirror or track libgit2 issues here, so I'm going to close this as it does look like an upstream issue. If it gets fixed, we'll pick the fix up in the next update.