path matching inconsistent error
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 2.1k
- Forks
- 450
- Avg merge
- 11m
- Merged PRs (30d)
- 1
Description
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"
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the Windows behavior from the src/main.rs example with the .gitattributes rule and compare get_attr_bytes with git check-attr. Trace the get_attr_bytes entry point and path handling; done means equivalent paths with and without a leading ./ return the same attribute value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- git, rust
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100