Git and vendor/rails

This is really a git question but the problem is with rails using git and others may have come across the problem.

I have a branch on my application’s git repository with edge rails as a subproject checked out into vendor/rails. this allows me to keep my application edge-compliant by checking out the branch (which creates the rails folder in vendor), pulling the latest edge rails and running my tests. This works fine.

The problem comes when I checkout the master again (which does not have a vendor/rails folder). Git removes the contents of vendor/rails but leaves an empty rails folder. The application will not run, the empty rails folder confuses it, so I have to manually delete the folder. Obviously I can have a simple script to solve the problem but I wonder if there is a way of telling git to remove the empty folder. Or perhaps there is an alternative. I have googled in vain.

Any ideas?

Colin

I think you will not be able make git to do it. Git tracks content not
files and folders and it will not delete folder. You can use post-
checkout hook to do that for you.

Regards,
Bosko

I think you will not be able make git to do it. Git tracks content not

files and folders and it will not delete folder. You can use post-

checkout hook to do that for you.

Yes, of course. I have not used hooks previously. For anyone that is interested all I had to do is make a script
called post-checkout in .git/hooks with the following contents.

#!/bin/sh

remove vendor/rails directory if not specified in .gitmodules

if [ -d vendor/rails ]
then

vendor/rails exists

if ! grep -s -q vendor/rails .gitmodules
then
# vendor/rails not in .gitmodules, remove vendor/rails

rmdir vendor/rails

fi
fi

Yes I know this could probably be done much more concisely, but it is only the third script I have written so I like to keep it simple and with comments so that I can understand it.

Colin