From 31e7c4204ad41368aa0b47c18292f77c823c575b Mon Sep 17 00:00:00 2001 From: Andy Kipp Date: Wed, 24 Jul 2024 19:00:53 +0200 Subject: [PATCH] Fixed ``$AUTO_CD`` regress after previous refactoring. (#5629) * fix autocd * test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: a <1@1.1> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- news/fix_autocd.rst | 23 +++++++++++++++++++++++ tests/procs/test_specs.py | 9 +++++++++ xonsh/procs/specs.py | 2 +- 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 news/fix_autocd.rst diff --git a/news/fix_autocd.rst b/news/fix_autocd.rst new file mode 100644 index 000000000..5a0cd4d4c --- /dev/null +++ b/news/fix_autocd.rst @@ -0,0 +1,23 @@ +**Added:** + +* + +**Changed:** + +* + +**Deprecated:** + +* + +**Removed:** + +* + +**Fixed:** + +* Fixed ``$AUTO_CD`` regress after previous refactoring. + +**Security:** + +* diff --git a/tests/procs/test_specs.py b/tests/procs/test_specs.py index 5759230a3..4c1fdd50f 100644 --- a/tests/procs/test_specs.py +++ b/tests/procs/test_specs.py @@ -577,3 +577,12 @@ def test_alias_return_command_eval_inside(xession): assert spec.cmd == ["sudo", "echo", "1"] assert spec.alias_name == "xsudo" assert spec.threadable is True + + +def test_auto_cd(xession, tmpdir): + xession.aliases["cd"] = lambda: "some_cd_alias" + dir = str(tmpdir) + with xession.env.swap(AUTO_CD=True): + spec = cmds_to_specs([[dir]], captured="object")[-1] + assert spec.alias.__name__ == "cd" + assert spec.cmd[0] == dir diff --git a/xonsh/procs/specs.py b/xonsh/procs/specs.py index 1dc28bcf3..165c32b44 100644 --- a/xonsh/procs/specs.py +++ b/xonsh/procs/specs.py @@ -764,7 +764,7 @@ class SubprocSpec: ): return self.cmd.insert(0, "cd") - self.alias = XSH.aliases.get("cd", None) + self.alias = XSH.aliases.get("cd", None)[0] def resolve_executable_commands(self): """Resolve command executables, if applicable."""