linux – Git Clean Filter打破空文件

我从 Git Attributes文档中设置了以下过滤器:

git config filter.dater.smudge expand_date
git config filter.dater.clean 'perl -pe s/\\\$Date[^\\\$]*\\\$/\\\$Date\\\$/"'

现在我运行以下命令:

touch nfile.txt
git add --all

并得到以下错误:

error: copy-fd: read returned Bad file descriptor
error: cannot feed the input to external filter perl -pe "s/\\\$DATE[^\\\$]*\\\$/\\\$DATE\\\$/"
error: external filter perl -pe "s/\\\$DATE[^\\\$]*\\\$/\\\$DATE\\\$/" failed

该错误似乎与我的脚本无关,因为如果我运行此错误,则不会出现错误:

cat nfile.txt | perl -pe "s/\\\$DATE[^\\\$]*\\\$/\\\$DATE\\\$/"

此外,this old thread提到该错误可能是由于“apply_filter中调用的代码中的copy_fd”,并建议在git核心文件convert.c中修补函数filter_buffer_or_fd.就个人而言,如果我可以避免修补核心Git代码,我会非常高兴.

我需要清理错误消息,因为我不希望用户在提交的暂存阶段看到这种丑陋的输出.有办法避免这种情况吗?或者正确处理这种情况的方法?

如果之前已经回答过,我道歉.我在交换或互联网上找不到相同的文章.

解决方法

当使用干净/污迹内容过滤器驱动程序处理时,Git 2.5应该对空文件更加健壮.

请参见2015年5月18日Jim Hill (jthill)Jim Hill (jthill).
(于2015年6月1日commit 152722f Junio C Hamano — gitster合并)

sha1_file: pass empty buffer to index empty file

git add of an empty file with a filter pops complaints from copy_fd about a bad file descriptor.

评论简洁:

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?

相关文章

文章浏览阅读1.8k次,点赞63次,收藏54次。Linux下的目录权限...
文章浏览阅读1.6k次,点赞44次,收藏38次。关于Qt的安装、Wi...
本文介绍了使用shell脚本编写一个 Hello
文章浏览阅读1.5k次,点赞37次,收藏43次。【Linux】初识Lin...
文章浏览阅读3k次,点赞34次,收藏156次。Linux超详细笔记,...
文章浏览阅读6.8k次,点赞109次,收藏114次。【Linux】 Open...