Skip to content

Commit b413a82

Browse files
newrengitster
authored andcommitted
unpack-trees: heed requests to overwrite ignored files
When a directory exists but has only ignored files within it and we are trying to switch to a branch that has a file where that directory is, the behavior depends upon --[no]-overwrite-ignore. If the user wants to --overwrite-ignore (the default), then we should delete the ignored file and directory and switch to the new branch. The code to handle this in verify_clean_subdirectory() in unpack-trees tried to handle this via paying attention to the exclude_per_dir setting of the internal dir field. This came from commit c819353 ("Fix switching to a branch with D/F when current branch has file D.", 2007-03-15), which pre-dated 039bc64 ("core.excludesfile clean-up", 2007-11-14), and thus did not pay attention to ignore patterns from other relevant files. Change it to use setup_standard_excludes() so that it is also aware of excludes specified in other locations. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 24a49cf commit b413a82

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

t/t2021-checkout-overwrite.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,15 @@ test_expect_success SYMLINKS 'checkout -f must not follow symlinks when removing
6969
test_path_is_file untracked/f
7070
'
7171

72+
test_expect_success 'checkout --overwrite-ignore should succeed if only ignored files in the way' '
73+
git checkout -b df_conflict &&
74+
test_commit contents some_dir &&
75+
git checkout start &&
76+
mkdir some_dir &&
77+
echo autogenerated information >some_dir/ignore &&
78+
echo ignore >.git/info/exclude &&
79+
git checkout --overwrite-ignore df_conflict &&
80+
! test_path_is_dir some_dir
81+
'
82+
7283
test_done

unpack-trees.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2337,7 +2337,7 @@ static int verify_clean_subdirectory(const struct cache_entry *ce,
23372337

23382338
memset(&d, 0, sizeof(d));
23392339
if (o->dir)
2340-
d.exclude_per_dir = o->dir->exclude_per_dir;
2340+
setup_standard_excludes(&d);
23412341
i = read_directory(&d, o->src_index, pathbuf, namelen+1, NULL);
23422342
dir_clear(&d);
23432343
free(pathbuf);

0 commit comments

Comments
 (0)