diff --git a/git-config/src/file/resolve_includes.rs b/git-config/src/file/resolve_includes.rs index 7388d3e9ed5..6a49772613d 100644 --- a/git-config/src/file/resolve_includes.rs +++ b/git-config/src/file/resolve_includes.rs @@ -198,8 +198,7 @@ fn gitdir_matches( return Ok(true); } - let expanded_git_dir = git_path::realpath(git_path::from_byte_slice(&git_dir), std::env::current_dir().unwrap())?; - let expanded_git_dir = git_path::into_bstr(expanded_git_dir); + let expanded_git_dir = git_path::into_bstr(git_path::realpath(git_path::from_byte_slice(&git_dir))?); Ok(git_glob::wildmatch( pattern_path.as_bstr(), expanded_git_dir.as_bstr(), diff --git a/git-config/tests/file/from_paths/includes/conditional/gitdir/util.rs b/git-config/tests/file/from_paths/includes/conditional/gitdir/util.rs index b2b25f208c1..99a89371c2c 100644 --- a/git-config/tests/file/from_paths/includes/conditional/gitdir/util.rs +++ b/git-config/tests/file/from_paths/includes/conditional/gitdir/util.rs @@ -60,11 +60,10 @@ impl Condition { impl GitEnv { pub fn repo_name(repo_name: impl AsRef) -> crate::Result { let tempdir = tempfile::tempdir()?; - let cwd = std::env::current_dir()?; - let root_dir = git_path::realpath(tempdir.path(), &cwd)?; + let root_dir = git_path::realpath(tempdir.path())?; let worktree_dir = root_dir.join(repo_name); std::fs::create_dir_all(&worktree_dir)?; - let home_dir = git_path::realpath(tempdir.path(), cwd)?; + let home_dir = git_path::realpath(tempdir.path())?; Ok(Self { tempdir, root_dir, diff --git a/git-discover/src/upwards.rs b/git-discover/src/upwards.rs index 71af066a71a..9360746768b 100644 --- a/git-discover/src/upwards.rs +++ b/git-discover/src/upwards.rs @@ -102,7 +102,7 @@ fn parse_ceiling_dirs(ceiling_dirs: &[u8]) -> Vec { } if should_normalize { - if let Ok(normalized) = git_path::realpath(&dir, "") { + if let Ok(normalized) = git_path::realpath(&dir) { dir = Cow::Owned(normalized); } } diff --git a/git-discover/tests/upwards/mod.rs b/git-discover/tests/upwards/mod.rs index 7374d0ab822..48ba128a2b5 100644 --- a/git-discover/tests/upwards/mod.rs +++ b/git-discover/tests/upwards/mod.rs @@ -162,7 +162,7 @@ fn from_existing_worktree() -> crate::Result { assert_eq!(trust, expected_trust()); let (git_dir, worktree) = path.into_repository_and_work_tree_directories(); assert_eq!( - git_dir.strip_prefix(git_path::realpath(&top_level_repo, std::env::current_dir()?).unwrap()), + git_dir.strip_prefix(git_path::realpath(&top_level_repo).unwrap()), Ok(std::path::Path::new(expected_git_dir)), "we don't skip over worktrees and discover their git dir (gitdir is absolute in file)" ); diff --git a/git-odb/src/alternate/mod.rs b/git-odb/src/alternate/mod.rs index 418124a193e..ba55173f1f2 100644 --- a/git-odb/src/alternate/mod.rs +++ b/git-odb/src/alternate/mod.rs @@ -16,6 +16,7 @@ //! ``` //! //! Based on the [canonical implementation](https://github.com/git/git/blob/master/sha1-file.c#L598:L609). +use git_path::realpath::MAX_SYMLINKS; use std::{fs, io, path::PathBuf}; /// @@ -45,13 +46,13 @@ pub fn resolve(objects_directory: impl Into) -> Result, Er let mut dirs = vec![(0, relative_base.clone())]; let mut out = Vec::new(); let cwd = std::env::current_dir()?; - let mut seen = vec![git_path::realpath(&relative_base, &cwd)?]; + let mut seen = vec![git_path::realpath_opts(&relative_base, &cwd, MAX_SYMLINKS)?]; while let Some((depth, dir)) = dirs.pop() { match fs::read(dir.join("info").join("alternates")) { Ok(input) => { for path in parse::content(&input)?.into_iter() { let path = relative_base.join(path); - let path_canonicalized = git_path::realpath(&path, &cwd)?; + let path_canonicalized = git_path::realpath_opts(&path, &cwd, MAX_SYMLINKS)?; if seen.contains(&path_canonicalized) { return Err(Error::Cycle(seen)); } diff --git a/git-repository/src/repository/location.rs b/git-repository/src/repository/location.rs index ab7ef25fc1e..0e23cbc0a1a 100644 --- a/git-repository/src/repository/location.rs +++ b/git-repository/src/repository/location.rs @@ -1,3 +1,5 @@ +use git_path::realpath::MAX_SYMLINKS; + impl crate::Repository { /// Returns the main git repository if this is a repository on a linked work-tree, or the `git_dir` itself. pub fn common_dir(&self) -> &std::path::Path { @@ -27,7 +29,7 @@ impl crate::Repository { pub fn prefix(&self) -> Option> { self.work_tree.as_ref().map(|root| { std::env::current_dir().and_then(|cwd| { - git_path::realpath(root, &cwd) + git_path::realpath_opts(root, &cwd, MAX_SYMLINKS) .map_err(|err| std::io::Error::new(std::io::ErrorKind::Other, err)) .and_then(|root| { cwd.strip_prefix(&root) diff --git a/src/porcelain/options.rs b/src/porcelain/options.rs index e6ecb8a37cf..4e55689d487 100644 --- a/src/porcelain/options.rs +++ b/src/porcelain/options.rs @@ -113,7 +113,7 @@ mod validator { fn is_repo_inner(dir: &OsStr) -> anyhow::Result<()> { let git_dir = PathBuf::from(dir).join(".git"); - let p = git::path::realpath(&git_dir, std::env::current_dir()?) + let p = git::path::realpath(&git_dir) .with_context(|| format!("Could not canonicalize git repository at '{}'", git_dir.display()))?; if p.extension().unwrap_or_default() == "git" || p.file_name().unwrap_or_default() == ".git"