Skip to content

Commit ebd5fa7

Browse files
committed
gh-140006: Preserve fish prompt status in venv activation
1 parent a2495ff commit ebd5fa7

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

Lib/test/test_venv.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,16 @@ def test_activate_shell_script_has_no_dos_newlines(self):
772772
error_message = f"CR LF found in line {i}"
773773
self.assertNotEndsWith(line, b'\r\n', error_message)
774774

775+
@requireVenvCreate
776+
def test_activate_fish_script_preserves_status(self):
777+
venv_dir = pathlib.Path(self.env_dir)
778+
rmtree(venv_dir)
779+
script_path = venv_dir / self.bindir / 'activate.fish'
780+
venv.create(venv_dir)
781+
script = script_path.read_text(encoding='utf-8')
782+
self.assertIn('return $old_status', script)
783+
self.assertNotIn('echo "exit $old_status" | .', script)
784+
775785
@requireVenvCreate
776786
def test_scm_ignore_files_git(self):
777787
"""

Lib/venv/scripts/common/activate.fish

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ if test -z "$VIRTUAL_ENV_DISABLE_PROMPT"
6060
printf "%s(%s)%s " (set_color 4B8BBE) __VENV_PROMPT__ (set_color normal)
6161

6262
# Restore the return status of the previous command.
63-
echo "exit $old_status" | .
63+
return $old_status
6464
# Output the original/"old" prompt.
6565
_old_fish_prompt
6666
end
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix ``venv``'s ``activate.fish`` prompt hook to preserve the previous command
2+
status without sourcing ``exit`` from stdin, avoiding prompt corruption in
3+
interactive fish sessions.

0 commit comments

Comments
 (0)