Re: [PATCH v2 4/9] unpack-trees: add special cwd handling
- From
Derrick Stolee <stolee@gmail.com>
- Date
- Nov 29, 2021, 14:14 UTC
- Message-ID
- <f65473df-4cb0-afdb-70e3-ee7685e6d817@gmail.com>
- In-Reply-To
- <e06806e3a3266fa6fdc973fcd7b479bd395c3023.1637829556.git.gitgitgadget@gmail.com>
On 11/25/2021 3:39 AM, Elijah Newren via GitGitGadget wrote:
Show 5 quoted lines
> From: Elijah Newren <newren@gmail.com> > > When running commands such as `git reset --hard` from a subdirectory, if > that subdirectory is in the way of adding needed files, bail with an > error message.
...
> -test_expect_failure 'reset --hard fails if cwd needs to be removed' ' > +test_expect_success 'reset --hard fails if cwd needs to be removed' ' > git checkout foo/bar/baz && > test_when_finished "git clean -fdx" &&
This test doesn't include any condition on the final state of the worktree. I could imagine that an implementation could be writing to the worktree incrementally and then bail halfway through. A clean "git status" would give us some confidence that the worktree and index are in a good state after the command fails.
Show 10 quoted lines
> + if (o->reset == UNPACK_RESET_OVERWRITE_UNTRACKED) {
> + /* Avoid nuking startup_info->original_cwd... */
> + if (startup_info->original_cwd &&
> + !strcmp(startup_info->original_cwd, ce->name))
> + return add_rejected_path(o, ERROR_CWD_IN_THE_WAY,
> + ce->name);
> + /* ...but nuke anything else. */
> + return 0;
> + }
> +This implementation appears to do the right thing in the case I'm describing: we check which entries would need to change and we reject them before doing any real work.
Thanks, -Stolee