Skip to content

Commit

Permalink
adjustments due to breaking changes in git_path (#331)
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jul 6, 2022
1 parent dfa1e05 commit 4420ae9
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 11 deletions.
3 changes: 1 addition & 2 deletions git-config/src/file/resolve_includes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,10 @@ impl Condition {
impl GitEnv {
pub fn repo_name(repo_name: impl AsRef<Path>) -> crate::Result<Self> {
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,
Expand Down
2 changes: 1 addition & 1 deletion git-discover/src/upwards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ fn parse_ceiling_dirs(ceiling_dirs: &[u8]) -> Vec<PathBuf> {
}

if should_normalize {
if let Ok(normalized) = git_path::realpath(&dir, "") {
if let Ok(normalized) = git_path::realpath(&dir) {
dir = Cow::Owned(normalized);
}
}
Expand Down
2 changes: 1 addition & 1 deletion git-discover/tests/upwards/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
);
Expand Down
5 changes: 3 additions & 2 deletions git-odb/src/alternate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

///
Expand Down Expand Up @@ -45,13 +46,13 @@ pub fn resolve(objects_directory: impl Into<PathBuf>) -> Result<Vec<PathBuf>, 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));
}
Expand Down
4 changes: 3 additions & 1 deletion git-repository/src/repository/location.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -27,7 +29,7 @@ impl crate::Repository {
pub fn prefix(&self) -> Option<std::io::Result<std::path::PathBuf>> {
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)
Expand Down
2 changes: 1 addition & 1 deletion src/porcelain/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 4420ae9

Please sign in to comment.