Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

path matching inconsistent error #1048

Open
lxl66566 opened this issue May 3, 2024 · 0 comments
Open

path matching inconsistent error #1048

lxl66566 opened this issue May 3, 2024 · 0 comments

Comments

@lxl66566
Copy link

lxl66566 commented May 3, 2024

Unexpected behavior happened when using get_attr_bytes. Here's a minimal example:

in src/main.rs:

use git2::{AttrCheckFlags, Repository};
use std::path::PathBuf;
use std::process::Command;
fn main() {
    let repo = Repository::open(".").unwrap();
    let git2_get = |file| {
        repo.get_attr_bytes(file, "crypt", AttrCheckFlags::default())
            .unwrap()
            .map(String::from_utf8_lossy)
    };
    let file = PathBuf::from(".").join("src").join("main.rs");
    let file2 = file.clone();
    dbg!(&file, git2_get(&file));
    let file = PathBuf::from(&file.to_str().unwrap().replace('\\', "/"));
    dbg!(&file, git2_get(&file));
    let file = PathBuf::from(&file.to_str().unwrap().trim_start_matches("./"));
    dbg!(&file, git2_get(&file));
    let file2 = PathBuf::from(&file2.to_str().unwrap().trim_start_matches(".\\"));
    dbg!(&file2, git2_get(&file2));
    let cli = Command::new("git")
        .args(["check-attr", "crypt", "--", "./src/main.rs"])
        .output()
        .unwrap()
        .stdout;
    dbg!(String::from_utf8_lossy(&cli));
}

in .gitattributes:

src/** crypt=1

output:

[src/main.rs:13:5] &file = ".\\src\\main.rs"
[src/main.rs:13:5] git2_get(&file) = None
[src/main.rs:15:5] &file = "./src/main.rs"
[src/main.rs:15:5] git2_get(&file) = None
[src/main.rs:17:5] &file = "src/main.rs"
[src/main.rs:17:5] git2_get(&file) = Some(
    "1",
)
[src/main.rs:19:5] &file2 = "src\\main.rs"
[src/main.rs:19:5] git2_get(&file2) = Some(
    "1",
)
[src/main.rs:25:5] String::from_utf8_lossy(&cli) = "./src/main.rs: crypt: 1\n"

Seems like the starting ./ caused this inconsistency. I expect that no matter whether the starting ./ exists, the output should be the same.

additional infomation

system: Windows11
rustc: 1.79.0-nightly (ccfcd950b 2024-04-15)
git2 = "0.18.3"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant