From dfa61926e8f48a012872873e8b889c02401d898e Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Tue, 22 Jan 2019 13:07:55 -0800 Subject: [PATCH] Correctly inherit a virtual PWD PWD is not set in fish vars because it is read only. Use getenv() to fetch it, allowing fish to inherit a virtual PWD. This cherry pick includes both: 24f251e04 Correctly remove the test directory again in cd test 91a9c9897 Correctly inherit a virtual PWD Fixes #5525 --- src/env.cpp | 6 +++++- tests/cd.err | 3 +++ tests/cd.in | 10 ++++++++++ tests/cd.out | 4 ++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/env.cpp b/src/env.cpp index c5a83ed43..7c617cb2e 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -962,7 +962,11 @@ void env_init(const struct config_paths_t *paths /* or NULL */) { // initialize the PWD variable if necessary // Note we may inherit a virtual PWD that doesn't match what getcwd would return; respect that. - if (env_get(L"PWD").missing_or_empty()) { + // Note we treat PWD as read-only so it was not set in vars. + const char *incoming_pwd = getenv("PWD"); + if (incoming_pwd && incoming_pwd[0]) { + env_set_one(L"PWD", ENV_EXPORT | ENV_GLOBAL, str2wcstring(incoming_pwd)); + } else { env_set_pwd_from_getcwd(); } env_set_termsize(); // initialize the terminal size variables diff --git a/tests/cd.err b/tests/cd.err index 80bc5c0e6..4653e2ee6 100644 --- a/tests/cd.err +++ b/tests/cd.err @@ -4,3 +4,6 @@ #################### # cd symlink completion + +#################### +# Virtual PWD inheritance diff --git a/tests/cd.in b/tests/cd.in index fa3964a22..fde7cd558 100644 --- a/tests/cd.in +++ b/tests/cd.in @@ -38,6 +38,16 @@ complete -C'ls ../' echo "cd:" complete -C'cd ../' +logmsg Virtual PWD inheritance +# PWD should be imported and respected by fish + +cd $oldpwd +mkdir -p $base/realhome +set fish_path $PWD/../test/root/bin/fish +ln -s $base/realhome $base/linkhome +cd $base/linkhome +env HOME=$base/linkhome $fish_path -c 'echo PWD is $PWD' + # cd back before removing the test directory again. cd $oldpwd rm -Rf $base diff --git a/tests/cd.out b/tests/cd.out index 86ea3299c..73081263d 100644 --- a/tests/cd.out +++ b/tests/cd.out @@ -17,3 +17,7 @@ cd: ../a2/ ../a3/ ../rabbithole/ + +#################### +# Virtual PWD inheritance +PWD is /tmp/cdcomp_test/linkhome