当前位置: 动力学知识库 > 问答 > 编程问答 >

ruby - How to determine files that are subjected to filter via gitattributes when filter is executed?

问题描述:

I have bunch of ruby scripts in a git repository and it seems to be really hard to enforce people to write properly indented code.

I also have a small ruby script that formats to code to specific standard and now i would like to run that as a a filter script so that junk wont get committed into repository.

echo "*.rb filter=rubyfilter" > .gitattributes

echo "[filter \"rubyfilter\"]" >> .git/config

echo " clean = /home/rasjani/bin/rbeauty" >> .git/config

echo " smudge = /home/rasjani/bin/rbeauty" >> .git/config

does the dirty trick git side but the ruby script should then process the files affected:

how / where do i look those up from ?

网友答案:

As described in the GitPro Book

Git applies those settings only for a subdirectory or subset of files. These path-specific settings are called Git attributes and are set either in a .gitattributes file in one of your directories

The git attributes man page mentions:

  • Upon checkout, when the smudge command is specified, the command is fed the blob object from its standard input, and its standard output is used to update the worktree file.
  • Similarly, the clean command is used to convert the contents of worktree file upon checkin.

alt text http://progit.org/figures/ch7/18333fig0702-tn.png

So your script will process each *.rb files (in the directory and subdirectories where the .gitattributes file is located) on checkout and commit.

See this SO question for a concrete example.
You can test your own setup with a:

git checkout --force

Note: as mentioned in this SO question, smudge and clean scripts can only modify the content of a file, without knowing what exact file they are processing.

分享给朋友:
您可能感兴趣的文章:
随机阅读: