diff options
author | Junio C Hamano <gitster@pobox.com> | 2015-06-01 12:45:10 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2015-06-01 12:45:11 -0700 |
commit | 152722f155165cbeca43c7e82abe68e66d088b33 (patch) | |
tree | 5812a9e9b1ff1c2b134feac290ce9094b1c6b632 | |
parent | Merge branch 'ah/usage-strings' (diff) | |
parent | sha1_file: pass empty buffer to index empty file (diff) | |
download | tgif-152722f155165cbeca43c7e82abe68e66d088b33.tar.xz |
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
-rw-r--r-- | sha1_file.c | 2 | ||||
-rwxr-xr-x | t/t0021-conversion.sh | 26 |
2 files changed, 27 insertions, 1 deletions
diff --git a/sha1_file.c b/sha1_file.c index ccc6dac54b..7e38148fe5 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -3286,7 +3286,7 @@ static int index_core(unsigned char *sha1, int fd, size_t size, int ret; if (!size) { - ret = index_mem(sha1, NULL, size, type, path, flags); + ret = index_mem(sha1, "", size, type, path, flags); } else if (size <= SMALL_FILE_SIZE) { char *buf = xmalloc(size); if (size == read_in_full(fd, buf, size)) diff --git a/t/t0021-conversion.sh b/t/t0021-conversion.sh index e0200b9f33..718efa04d3 100755 --- a/t/t0021-conversion.sh +++ b/t/t0021-conversion.sh @@ -226,4 +226,30 @@ test_expect_success EXPENSIVE 'filter large file' ' ! test -s err ' +test_expect_success "filter: clean empty file" ' + git config filter.in-repo-header.clean "echo cleaned && cat" && + git config filter.in-repo-header.smudge "sed 1d" && + + echo "empty-in-worktree filter=in-repo-header" >>.gitattributes && + >empty-in-worktree && + + echo cleaned >expected && + git add empty-in-worktree && + git show :empty-in-worktree >actual && + test_cmp expected actual +' + +test_expect_success "filter: smudge empty file" ' + git config filter.empty-in-repo.clean "cat >/dev/null" && + git config filter.empty-in-repo.smudge "echo smudged && cat" && + + echo "empty-in-repo filter=empty-in-repo" >>.gitattributes && + echo dead data walking >empty-in-repo && + git add empty-in-repo && + + echo smudged >expected && + git checkout-index --prefix=filtered- empty-in-repo && + test_cmp expected filtered-empty-in-repo +' + test_done |