summaryrefslogtreecommitdiff
path: root/unpack-trees.c
diff options
context:
space:
mode:
authorLibravatar Elijah Newren <newren@gmail.com>2021-12-09 05:08:28 +0000
committerLibravatar Junio C Hamano <gitster@pobox.com>2021-12-09 13:33:12 -0800
commit0b0ee3388cf080c4200c235ee699bd95c960c167 (patch)
tree7d5329f4788d7cb5c335430c0ff573f0a83a5afb /unpack-trees.c
parentunpack-trees: refuse to remove startup_info->original_cwd (diff)
downloadtgif-0b0ee3388cf080c4200c235ee699bd95c960c167.tar.xz
unpack-trees: add special cwd handling
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. Note that this change looks kind of like it duplicates the new lines of code from the previous commit in verify_clean_subdirectory(). However, when we are preserving untracked files, we would rather any error messages about untracked files being in the way take precedence over error messages about a subdirectory that happens to be the_original_cwd being in the way. But in the UNPACK_RESET_OVERWRITE_UNTRACKED case, there is no untracked checking to be done, so we simply add a special case near the top of verify_absent_1. Acked-by: Derrick Stolee <stolee@gmail.com> Acked-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'unpack-trees.c')
-rw-r--r--unpack-trees.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/unpack-trees.c b/unpack-trees.c
index 6bc16f3a71..5852807d2f 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -2261,10 +2261,19 @@ static int verify_absent_1(const struct cache_entry *ce,
int len;
struct stat st;
- if (o->index_only || !o->update ||
- o->reset == UNPACK_RESET_OVERWRITE_UNTRACKED)
+ if (o->index_only || !o->update)
return 0;
+ 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;
+ }
+
len = check_leading_path(ce->name, ce_namelen(ce), 0);
if (!len)
return 0;