git2::Repository::open error: repository path is not owned by current user
Closed this issue · 3 comments
Checklist
- I've looked through the issues and pull requests for similar reports
Describe your issue
Problem
If https://lib.rs/git2 inside build.rs
tries to open the project repository in order to describe it, the build.rs
fails with
repository path is not owned by current user
Apparently, the target is build in Docker using the root
user but the project directory itself is owned by the host user - which results the mentioned error when git2
tries to open the repository.
build.rs
fn main() -> Result<(), Box<dyn Error>> {
let repo = match git2::Repository::open(".") {
Ok(r) => r,
Err(err) => {
println!("open repo err: {} ", err);
return Err(Box::new(err));
}
};
// ...
}
Workaround
On the other hand, calling git describe
from the build script works fine:
fn main() -> Result<(), Box<dyn Error>> {
if std::env::var("CROSS_SYSROOT").is_ok() {
let app_git_tag = std::process::Command::new("git").arg("describe").output().expect("`git describe` failed");
let app_git_tag = std::str::from_utf8(&app_git_tag.stdout).expect("`git describe` not utf8");
println!("cargo:rustc-env=APP_GIT_TAG={}", app_git_tag);
return Ok(());
}
let repo = match git2::Repository::open(".") {
Ok(r) => r,
Err(err) => {
println!("open repo err: {} ", err);
return Err(Box::new(err));
}
};
// ...
}
What target(s) are you cross-compiling for?
x86_64-unknown-linux-gnu
Which operating system is the host (e.g computer cross is on) running?
- macOS
- Windows
- Linux / BSD
- other OS (specify in description)
What architecture is the host?
- x86_64 / AMD64
- arm32
- arm64 (including Mac M1)
What container engine is cross using?
- docker
- podman
- other container engine (specify in description)
cross version
cross 0.2.5 (19be834 2024-05-17)
Example
// build.rs
fn main() -> Result<(), Box<dyn Error>> {
let repo = match git2::Repository::open(".") {
Ok(r) => r,
Err(err) => {
println!("open repo err: {} ", err);
return Err(Box::new(err));
}
};
// ...
}
cross build --release --target x86_64-unknown-linux-gnu
cargo stderr:
error: failed to run custom build command for `logs`
Caused by:
process didn't exit successfully: `/target/release/build/logs-2e37abb95c8ee7c3/build-script-build` (exit status: 1)
--- stdout
open repo err: repository path '/Users/hello/logs/' is not owned by current user; class=Config (7); code=Owner (-36)
--- stderr
Error: Error { code: -36, klass: 7, message: "repository path '/Users/hello/logs/' is not owned by current user" }
Additional information / notes
Cross is installed from the latest master via cargo install cross --git
.
Judging by the mentioned workaround, looks like it's a problem more of https://github.com/rust-lang/git2-rs rather than from cross
?
The error could be correct, just that git2 crate for some reason hits the path that git doesn't like.
[build]
pre-build = ["git config --system --add safe.directory '*'"]
Yep, it works. Thanks!