Skip to content

Commit 53ae3d2

Browse files
committed
fix: path handling for windows compatibility
Using gix::path::realpath() provides an alternative means of getting an absolute path, but without adding the extra rigamarole to the front of paths that std::Path::canonicalize() adds on Windows. Refs: #273
1 parent 1cef025 commit 53ae3d2

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

src/cmd/import.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ fn run(matches: &clap::ArgMatches) -> Result<()> {
230230
let source_path = if matches.get_flag("url") {
231231
None
232232
} else if let Some(path) = matches.get_one::<PathBuf>("source") {
233-
let abs_path = path.canonicalize()?;
233+
let abs_path = gix::path::realpath(path)?;
234234
Some(abs_path)
235235
} else {
236236
None

src/hook.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ pub(crate) fn run_pre_commit_hook(repo: &gix::Repository, use_editor: bool) -> R
5555
return Ok(false);
5656
}
5757

58-
let mut hook_command = std::process::Command::new(hook_path.canonicalize()?);
58+
let mut hook_command = std::process::Command::new(gix::path::realpath(hook_path)?);
5959
let workdir = repo
6060
.work_dir()
6161
.expect("should not get this far with a bare repo");
@@ -118,7 +118,7 @@ pub(crate) fn run_commit_msg_hook<'repo>(
118118

119119
// TODO: when git runs this hook, it only sets GIT_INDEX_FILE and sometimes
120120
// GIT_EDITOR. So author and committer vars are not clearly required.
121-
let mut hook_command = std::process::Command::new(hook_path.canonicalize()?);
121+
let mut hook_command = std::process::Command::new(gix::path::realpath(hook_path)?);
122122
hook_command.env("GIT_INDEX_FILE", &index_path);
123123
if !use_editor {
124124
hook_command.env("GIT_EDITOR", ":");

src/stupid/mod.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,15 @@ impl<'repo, 'index> StupidContext<'repo, 'index> {
9999
.work_dir
100100
.expect("work_dir is required for this command");
101101
command.current_dir(work_dir);
102+
let cwd = std::env::current_dir()?;
103+
let realpath =
104+
|path| gix::path::realpath_opts(path, cwd.as_path(), gix::path::realpath::MAX_SYMLINKS);
102105
if let Some(git_dir) = self.git_dir {
103-
command.env("GIT_DIR", git_dir.canonicalize()?);
106+
command.env("GIT_DIR", realpath(git_dir)?);
104107
}
105-
command.env("GIT_WORK_TREE", work_dir.canonicalize()?);
108+
command.env("GIT_WORK_TREE", realpath(work_dir)?);
106109
if let Some(index_path) = self.index_path {
107-
command.env("GIT_INDEX_FILE", index_path.canonicalize()?);
110+
command.env("GIT_INDEX_FILE", realpath(index_path)?);
108111
}
109112
Ok(command)
110113
}

0 commit comments

Comments
 (0)