Skip to content

Commit 00fcce2

Browse files
newrengitster
authored andcommitted
symlinks: do not include startup_info->original_cwd in dir removal
symlinks has a pair of schedule_dir_for_removal() and remove_scheduled_dirs() functions that ensure that directories made empty by removing other files also themselves get removed. However, we want to exclude startup_info->original_cwd and leave it around. This avoids the user getting confused by subsequent git commands (and non-git commands) that would otherwise report confusing messages about being unable to read the current working directory. Acked-by: Derrick Stolee <[email protected]> Acked-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0b0ee33 commit 00fcce2

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

symlinks.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,9 @@ static void do_remove_scheduled_dirs(int new_len)
279279
{
280280
while (removal.len > new_len) {
281281
removal.buf[removal.len] = '\0';
282-
if (rmdir(removal.buf))
282+
if ((startup_info->original_cwd &&
283+
!strcmp(removal.buf, startup_info->original_cwd)) ||
284+
rmdir(removal.buf))
283285
break;
284286
do {
285287
removal.len--;
@@ -293,6 +295,10 @@ void schedule_dir_for_removal(const char *name, int len)
293295
{
294296
int match_len, last_slash, i, previous_slash;
295297

298+
if (startup_info->original_cwd &&
299+
!strcmp(name, startup_info->original_cwd))
300+
return; /* Do not remove the current working directory */
301+
296302
match_len = last_slash = i =
297303
longest_path_match(name, len, removal.buf, removal.len,
298304
&previous_slash);

t/t2501-cwd-empty.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,23 +109,23 @@ test_required_dir_removal () {
109109
}
110110

111111
test_expect_success 'checkout does not clean cwd incidentally' '
112-
test_incidental_dir_removal failure git checkout init
112+
test_incidental_dir_removal success git checkout init
113113
'
114114

115115
test_expect_success 'checkout fails if cwd needs to be removed' '
116116
test_required_dir_removal success git checkout fd_conflict
117117
'
118118

119119
test_expect_success 'reset --hard does not clean cwd incidentally' '
120-
test_incidental_dir_removal failure git reset --hard init
120+
test_incidental_dir_removal success git reset --hard init
121121
'
122122

123123
test_expect_success 'reset --hard fails if cwd needs to be removed' '
124124
test_required_dir_removal success git reset --hard fd_conflict
125125
'
126126

127127
test_expect_success 'merge does not clean cwd incidentally' '
128-
test_incidental_dir_removal failure git merge reverted
128+
test_incidental_dir_removal success git merge reverted
129129
'
130130

131131
# This file uses some simple merges where
@@ -158,7 +158,7 @@ test_expect_success 'merge fails if cwd needs to be removed' '
158158
'
159159

160160
test_expect_success 'cherry-pick does not clean cwd incidentally' '
161-
test_incidental_dir_removal failure git cherry-pick reverted
161+
test_incidental_dir_removal success git cherry-pick reverted
162162
'
163163

164164
test_expect_success 'cherry-pick fails if cwd needs to be removed' '
@@ -174,7 +174,7 @@ test_expect_success 'rebase fails if cwd needs to be removed' '
174174
'
175175

176176
test_expect_success 'revert does not clean cwd incidentally' '
177-
test_incidental_dir_removal failure git revert HEAD
177+
test_incidental_dir_removal success git revert HEAD
178178
'
179179

180180
test_expect_success 'revert fails if cwd needs to be removed' '

0 commit comments

Comments
 (0)