views:

43

answers:

1

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 ?

A: 

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

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.

VonC
Doesnt really answer the question as i was really looking a way to actually get the filenames but i'll accept this anyway since there has been no other answers.
rasjani
@rasjani: "get the filename", that is precisely why I have linked to http://stackoverflow.com/questions/2059326/git-equivalent-of-subversions-url-keyword-expansion/2059393#2059393: a filter driver can only get the *content* of a file, not its filename. It will be called during the checkout step and will in effect "process the files affected".
VonC
@vonc yes, fully understand this, and thats why i accepted the answer. But the spirit of the question was mainly about how to get the filenames, not about the content so any alternative way to archive what i asked would have been more than fine.
rasjani
@rasjani: I have not tested it but I wonder if, after a smudge script, you can diff the working tree with HEAD and find that way all those files that has been processed.
VonC