From b3cdf4afe1311888935d1cccd91d54d46bce9d22 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Wed, 28 Jul 2021 22:08:03 +0200 Subject: [PATCH] Hardcode $PWD as read-only for set --show Through a mechanism I don't entirely understand, $PWD is sometimes writable (so that `cd` can change it) and sometimes not. In this case we ended up with it writable, which is wrong. See #8179. --- src/builtin_set.cpp | 4 +++- tests/checks/set.fish | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/builtin_set.cpp b/src/builtin_set.cpp index 15c26e2ba..4b27632fe 100644 --- a/src/builtin_set.cpp +++ b/src/builtin_set.cpp @@ -512,7 +512,9 @@ static void show_scope(const wchar_t *var_name, int scope, io_streams_t &streams wcstring_list_t vals = var->as_list(); streams.out.append_format(_(L"$%ls: set in %ls scope, %ls,%ls with %d elements\n"), var_name, scope_name, exportv, pathvarv, vals.size()); - if (var->read_only()) { + // HACK: PWD can be set, depending on how you ask. + // For our purposes it's read-only. + if (var->read_only() || wcscmp(var_name, L"PWD") == 0) { streams.out.append(_(L"Variable is read-only\n")); } diff --git a/tests/checks/set.fish b/tests/checks/set.fish index a1e36e5a6..e76693964 100644 --- a/tests/checks/set.fish +++ b/tests/checks/set.fish @@ -667,6 +667,12 @@ set -S status #CHECK: Variable is read-only #CHECK: $status[1]: |0| +# PWD is also read-only. +set -S PWD +#CHECK: $PWD: set in global scope, exported, with 1 elements +#CHECK: Variable is read-only +#CHECK: $PWD[1]: |{{.*}}| + set -ql history echo $status #CHECK: 1