Skip to content

Commit 152722f

Browse files
committed
Merge branch 'jh/filter-empty-contents'
The clean/smudge interface did not work well when filtering an empty contents (failed and then passed the empty input through). It can be argued that a filter that produces anything but empty for an empty input is nonsense, but if the user wants to do strange things, then why not? * jh/filter-empty-contents: sha1_file: pass empty buffer to index empty file
2 parents 6e0ac8e + f6a1e1e commit 152722f

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

sha1_file.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3286,7 +3286,7 @@ static int index_core(unsigned char *sha1, int fd, size_t size,
32863286
int ret;
32873287

32883288
if (!size) {
3289-
ret = index_mem(sha1, NULL, size, type, path, flags);
3289+
ret = index_mem(sha1, "", size, type, path, flags);
32903290
} else if (size <= SMALL_FILE_SIZE) {
32913291
char *buf = xmalloc(size);
32923292
if (size == read_in_full(fd, buf, size))

t/t0021-conversion.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,30 @@ test_expect_success EXPENSIVE 'filter large file' '
226226
! test -s err
227227
'
228228

229+
test_expect_success "filter: clean empty file" '
230+
git config filter.in-repo-header.clean "echo cleaned && cat" &&
231+
git config filter.in-repo-header.smudge "sed 1d" &&
232+
233+
echo "empty-in-worktree filter=in-repo-header" >>.gitattributes &&
234+
>empty-in-worktree &&
235+
236+
echo cleaned >expected &&
237+
git add empty-in-worktree &&
238+
git show :empty-in-worktree >actual &&
239+
test_cmp expected actual
240+
'
241+
242+
test_expect_success "filter: smudge empty file" '
243+
git config filter.empty-in-repo.clean "cat >/dev/null" &&
244+
git config filter.empty-in-repo.smudge "echo smudged && cat" &&
245+
246+
echo "empty-in-repo filter=empty-in-repo" >>.gitattributes &&
247+
echo dead data walking >empty-in-repo &&
248+
git add empty-in-repo &&
249+
250+
echo smudged >expected &&
251+
git checkout-index --prefix=filtered- empty-in-repo &&
252+
test_cmp expected filtered-empty-in-repo
253+
'
254+
229255
test_done

0 commit comments

Comments
 (0)