From 8e3225e4a19157af69d53f7b774d98ef4e0a3687 Mon Sep 17 00:00:00 2001 From: muvahhid kilic Date: Fri, 6 Nov 2026 21:42:53 +0300 Subject: [PATCH 1/2] Honor MSYS_NO_PATHCONV given as a command prefix, and add pwd -W run_external read MSYS_NO_PATHCONV and MSYS2_ARG_CONV_EXCL from shell variables only, so the usual prefix form (MSYS_NO_PATHCONV=1 cmd ...) was ignored while an unexported variable did count. Like Git Bash's MSYS runtime, they now count when exported or given as a prefix. pwd -W prints the physical directory in Windows form (C:/...), as MSYS bash does. -L, -P and -W combine and the last one wins, and an invalid option is reported with exit status 2. Co-Authored-By: Claude Opus 5.5 --- README.md | 6 ++-- src/builtins.rs | 39 +++++++++++++++++------ src/exec.rs | 19 +++++++++-- tests/scripts/072_pathconv_env_pwd_w.code | 1 + tests/scripts/072_pathconv_env_pwd_w.out | 12 +++++++ tests/scripts/072_pathconv_env_pwd_w.sh | 22 +++++++++++++ 6 files changed, 85 insertions(+), 14 deletions(-) create mode 100644 tests/scripts/072_pathconv_env_pwd_w.code create mode 100644 tests/scripts/072_pathconv_env_pwd_w.out create mode 100644 tests/scripts/072_pathconv_env_pwd_w.sh diff --git a/README.md b/README.md index 10042d1..335821b 100644 --- a/README.md +++ b/README.md @@ -68,10 +68,12 @@ by real Git Bash) passes 100%. Supported: - Paths: `/c/foo` ↔ `C:\foo`, `/tmp` → `%TEMP%`, `/usr/bin`, `/bin`, `/ucrt64` → Git's install dir, `/dev/null`, `/dev/stdin|stdout|stderr|fd/N`, `/dev/tty`. Windows paths - (`C:\x`, `C:/x`) work everywhere too. `$PWD` and `pwd` show the MSYS form. + (`C:\x`, `C:/x`) work everywhere too. `$PWD` and `pwd` show the MSYS form, `pwd -W` the + Windows one (`C:/...`). - PATH is kept in MSYS form inside the shell and converted when launching programs. - Arguments to native programs get MSYS2-style path conversion (`/c/x` → `C:/x`), - honoring `MSYS_NO_PATHCONV` and `MSYS2_ARG_CONV_EXCL`. + honoring `MSYS_NO_PATHCONV` and `MSYS2_ARG_CONV_EXCL` when they are exported or given as + a command prefix (`MSYS_NO_PATHCONV=1 cmd ...`), as in Git Bash. - Arguments to MSYS programs are quoted so the MSYS runtime doesn't glob/brace/tilde-expand or `@file`-expand them. - Executables are found with or without `.exe`/`.com`/`.bat`/`.cmd`; extensionless files with a diff --git a/src/builtins.rs b/src/builtins.rs index 70a1d0e..339e8d6 100644 --- a/src/builtins.rs +++ b/src/builtins.rs @@ -393,25 +393,46 @@ fn cd(sh: &mut Shell, args: &[String]) -> R { } pub fn physical_pwd(sh: &Shell) -> String { + path::to_posix(&physical_cwd(sh)) +} + +/// The current directory with symlinks resolved, as a Windows path. +fn physical_cwd(sh: &Shell) -> std::path::PathBuf { match std::fs::canonicalize(&sh.cwd) { Ok(c) => { let s = c.to_string_lossy().into_owned(); - let s = s.strip_prefix(r"\\?\").unwrap_or(&s).to_string(); - path::to_posix(std::path::Path::new(&s)) + std::path::PathBuf::from(s.strip_prefix(r"\\?\").unwrap_or(&s)) } - Err(_) => path::to_posix(&sh.cwd), + Err(_) => sh.cwd.clone(), } } fn pwd(sh: &mut Shell, args: &[String]) -> R { - let physical = args.iter().any(|a| a == "-P") || (sh.o[O_PHYSICAL] && !args.iter().any(|a| a == "-L")); - let p = if physical { - physical_pwd(sh) - } else { - match sh.get_str("PWD") { + // -L, -P and MSYS bash's -W (the physical directory in Windows form, `C:/...`) each choose a + // form; as in Git Bash, the last one given wins. + let mut form = if sh.o[O_PHYSICAL] { 'P' } else { 'L' }; + for a in args { + if a == "--" || a == "-" || !a.starts_with('-') { + break; + } + for c in a[1..].chars() { + match c { + 'L' | 'P' | 'W' => form = c, + _ => { + sh.eprint(&format!("pwd: -{}: invalid option", c)); + sh.eprint("pwd: usage: pwd [-LPW]"); + return Ok(2); + } + } + } + } + let p = match form { + 'P' => physical_pwd(sh), + 'W' => path::win_fwd(&physical_cwd(sh)), + _ => match sh.get_str("PWD") { Some(p) if !p.is_empty() && path::to_win(&p, &sh.cwd).is_dir() => p, _ => path::to_posix(&sh.cwd), - } + }, }; sh.out(1, format!("{}\n", p).as_bytes())?; Ok(0) diff --git a/src/exec.rs b/src/exec.rs index a2fd83e..636f800 100644 --- a/src/exec.rs +++ b/src/exec.rs @@ -1494,9 +1494,22 @@ impl Shell { let mut cmd; let native; let mut msys_child = false; - let no_conv = self.get_str("MSYS_NO_PATHCONV").map(|v| !v.is_empty()).unwrap_or(false); - let excl: Vec = self - .get_str("MSYS2_ARG_CONV_EXCL") + // As in Git Bash, these count where the MSYS runtime would see them: in the environment + // the program starts with, so when exported or given as a prefix (`MSYS_NO_PATHCONV=1 cmd`). + let env_var = |name: &str| -> Option { + match assigns.iter().rev().find(|(k, _)| k == name) { + Some((_, v)) => Some(v.clone()), + None => match self.vars.get(name) { + Some(v) if v.has(EXPORT) => match &v.value { + Some(Value::Str(s)) => Some(s.clone()), + _ => None, + }, + _ => None, + }, + } + }; + let no_conv = env_var("MSYS_NO_PATHCONV").map(|v| !v.is_empty()).unwrap_or(false); + let excl: Vec = env_var("MSYS2_ARG_CONV_EXCL") .map(|v| v.split(';').filter(|s| !s.is_empty()).map(|s| s.to_string()).collect()) .unwrap_or_default(); let conv = |a: &str| -> String { diff --git a/tests/scripts/072_pathconv_env_pwd_w.code b/tests/scripts/072_pathconv_env_pwd_w.code new file mode 100644 index 0000000..c227083 --- /dev/null +++ b/tests/scripts/072_pathconv_env_pwd_w.code @@ -0,0 +1 @@ +0 \ No newline at end of file diff --git a/tests/scripts/072_pathconv_env_pwd_w.out b/tests/scripts/072_pathconv_env_pwd_w.out new file mode 100644 index 0000000..6064870 --- /dev/null +++ b/tests/scripts/072_pathconv_env_pwd_w.out @@ -0,0 +1,12 @@ + 'C:/x' + '/c/x' + 'C:/x' + '/c/x' + '/c/x' 'D:/y' + 'C:/x' '/d/y' '/e/z' +C:/Windows/System32 +C:/Windows/System32 +/c/Windows/System32 +/c/Windows/System32 +/c/Windows/System32 +pwd -X: rc=2 diff --git a/tests/scripts/072_pathconv_env_pwd_w.sh b/tests/scripts/072_pathconv_env_pwd_w.sh new file mode 100644 index 0000000..592fd68 --- /dev/null +++ b/tests/scripts/072_pathconv_env_pwd_w.sh @@ -0,0 +1,22 @@ +# MSYS_NO_PATHCONV and MSYS2_ARG_CONV_EXCL count when exported or given as a command prefix, +# as in Git Bash. pwd -W prints the current directory in Windows form. +git rev-parse --sq-quote /c/x +MSYS_NO_PATHCONV=1 git rev-parse --sq-quote /c/x +MSYS_NO_PATHCONV=1 +git rev-parse --sq-quote /c/x +export MSYS_NO_PATHCONV +git rev-parse --sq-quote /c/x +unset MSYS_NO_PATHCONV +MSYS2_ARG_CONV_EXCL=/c git rev-parse --sq-quote /c/x /d/y +export MSYS2_ARG_CONV_EXCL='/d;/e' +git rev-parse --sq-quote /c/x /d/y /e/z +unset MSYS2_ARG_CONV_EXCL + +cd /c/Windows/System32 || exit 1 +pwd -W +pwd -LW +pwd -WP +pwd -P +pwd -L +pwd -X 2>/dev/null +echo "pwd -X: rc=$?" From df225263a7afb9511f3d54366fb59332391dbc7f Mon Sep 17 00:00:00 2001 From: muvahhid kilic Date: Fri, 6 Nov 2026 23:03:32 +0300 Subject: [PATCH 2/2] Make 072 independent of exported path-conversion settings The script expected conversion on, so it failed when MSYS_NO_PATHCONV or MSYS2_ARG_CONV_EXCL was already exported, as Claude Code does. It now unsets both first. Co-Authored-By: Claude Opus 5.5 --- tests/scripts/072_pathconv_env_pwd_w.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/scripts/072_pathconv_env_pwd_w.sh b/tests/scripts/072_pathconv_env_pwd_w.sh index 592fd68..f2b1f21 100644 --- a/tests/scripts/072_pathconv_env_pwd_w.sh +++ b/tests/scripts/072_pathconv_env_pwd_w.sh @@ -1,5 +1,7 @@ # MSYS_NO_PATHCONV and MSYS2_ARG_CONV_EXCL count when exported or given as a command prefix, # as in Git Bash. pwd -W prints the current directory in Windows form. +# Start from no conversion settings, whatever the environment exports (Claude Code sets one). +unset MSYS_NO_PATHCONV MSYS2_ARG_CONV_EXCL git rev-parse --sq-quote /c/x MSYS_NO_PATHCONV=1 git rev-parse --sq-quote /c/x MSYS_NO_PATHCONV=1