# Git and vendor/rails

**URL:** <https://www.ruby-forum.com/t/git-and-vendor-rails/164132>\
**Category:** Rails\
**Created:** [March 28, 2009, 1:03pm UTC](https://www.ruby-forum.com/t/git-and-vendor-rails/164132 "2009-03-28T13:03:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![colinloretz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a698b9/32.png) [@colinloretz](https://www.ruby-forum.com/u/colinloretz)\
**Post date:** [March 28, 2009, 1:03pm UTC](https://www.ruby-forum.com/t/git-and-vendor-rails/164132/1 "2009-03-28T13:03:40Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![colinloretz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a698b9/32.png) [@colinloretz](https://www.ruby-forum.com/u/colinloretz)\
**Post date:** [March 28, 2009, 2:47pm UTC](https://www.ruby-forum.com/t/git-and-vendor-rails/164132/2 "2009-03-28T14:47:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![colinloretz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/a698b9/32.png) [@colinloretz](https://www.ruby-forum.com/u/colinloretz)\
**Post date:** [March 28, 2009, 4:29pm UTC](https://www.ruby-forum.com/t/git-and-vendor-rails/164132/3 "2009-03-28T16:29:50Z")

</div>

2009/3/28 Bosko I. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

> 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

Regards,
