Subject: Re: [PATCH v3 02/11] setup: introduce startup_info->original_cwd

From: Ævar Arnfjörð Bjarmason <[email-masked]>
Date: Sat, 27 Nov 2021 11:40:04 +0100

On Fri, Nov 26 2021, Elijah Newren via GitGitGadget wrote:

[Just some more "I haven't really looked at this in all that much
detail" commentary, so maybe it's stupid, sorry]

> From: Elijah Newren <[email-masked]>
>
> Removing the current working directory causes all subsequent git
> commands run from that directory to get confused and fail with a message
> about being unable to read the current working directory:
>
>     $ git status
>     fatal: Unable to read current working directory: No such file or directory
>
> Non-git commands likely have similar warnings or even errors, e.g.
>
>     $ bash -c 'echo hello'
>     shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory
>     hello

Is that really realistic? Any "normal" command would use "pwd" or look
at $PWD, both of which "work", this error is only because we're starting
a new shell.

I wonder if it was just because you ran into our bin-wrappers edge case,
but that should be really obscure for any real users.

> This confuses end users, particularly since the command they get the
> error from is not the one that caused the problem; the problem came from
> the side-effect of some previous command.
>
> We would like to avoid removing the current working directory of our
> parent process; towards this end, introduce a new variable,
> startup_info->original_cwd, that tracks the current working directory
> that we inherited from our parent process.  For convenience of later
> comparisons, we prefer that this new variable store a path relative to
> the toplevel working directory (thus much like 'prefix'), except without
> the trailing slash.

I'm still not clear at all on why we need a "original_cwd" at all then
as opposed to just using "prefix" (or adding "the_prefix" if passing it
down is painful). I.e. we discover our relative path, we resolve the
relative path to the root, can't we use that as the "don't remove our
CWD" guard?

Does our prefix change at some point, then maybe "orig_prefix" would
make more sense?

This is with the context that I haven't dug into your code, so maybe
there's some obvious reason I'm missing...