Skip to content

Commit 070d276

Browse files
committed
Merge branch 'jh/filter-empty-contents' into maint
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 659d4c8 + f6a1e1e commit 070d276

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
@@ -3202,7 +3202,7 @@ static int index_core(unsigned char *sha1, int fd, size_t size,
32023202
int ret;
32033203

32043204
if (!size) {
3205-
ret = index_mem(sha1, NULL, size, type, path, flags);
3205+
ret = index_mem(sha1, "", size, type, path, flags);
32063206
} else if (size <= SMALL_FILE_SIZE) {
32073207
char *buf = xmalloc(size);
32083208
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
@@ -216,4 +216,30 @@ test_expect_success EXPENSIVE 'filter large file' '
216216
! test -s err
217217
'
218218

219+
test_expect_success "filter: clean empty file" '
220+
git config filter.in-repo-header.clean "echo cleaned && cat" &&
221+
git config filter.in-repo-header.smudge "sed 1d" &&
222+
223+
echo "empty-in-worktree filter=in-repo-header" >>.gitattributes &&
224+
>empty-in-worktree &&
225+
226+
echo cleaned >expected &&
227+
git add empty-in-worktree &&
228+
git show :empty-in-worktree >actual &&
229+
test_cmp expected actual
230+
'
231+
232+
test_expect_success "filter: smudge empty file" '
233+
git config filter.empty-in-repo.clean "cat >/dev/null" &&
234+
git config filter.empty-in-repo.smudge "echo smudged && cat" &&
235+
236+
echo "empty-in-repo filter=empty-in-repo" >>.gitattributes &&
237+
echo dead data walking >empty-in-repo &&
238+
git add empty-in-repo &&
239+
240+
echo smudged >expected &&
241+
git checkout-index --prefix=filtered- empty-in-repo &&
242+
test_cmp expected filtered-empty-in-repo
243+
'
244+
219245
test_done

0 commit comments

Comments
 (0)