11

I install modules using composer.phar.

This creates symlinks files in publichtml/app/code/community (for example) with a target to vendor/themodule....

In my .gitignore I excluded the vendor directory - but the links would of course still end up in the git.

Is there an easy way to automically exclude those links? (other than adding everything manually to the .gitignore)

I have to say that I have some require-dev modules which should not end up on the final server - so having those links there would be at least not so nice.

asked Jun 11, 2013 at 15:22
3
  • 1
    Would this apply to modman, too? Commented Jun 11, 2013 at 16:18
  • With modman you generally would use git submodules for each extension and simply add the symlinks to the repository. No need to exclude them there, on the contrary, it wouldn't make sense in a modman deploy scenario mostly. Commented Jun 11, 2013 at 17:01
  • 1
    @philwinkle I recently started tracking the Magento root in a separate repo for security reasons (e.g. easily detect modified files), to track changes to index.php and Mage.php, and for easier Magento upgrades so definitely relevant for modman as well, IMO. Commented Sep 30, 2014 at 21:00

4 Answers 4

8

The best I came up with was running this after an composer install/update

$ find * -type l -not -exec grep -q "^{}$" .gitignore \; -print >> .gitignore

The command should be run in the git root directory. It adds all symlinks to the .gitignore file that aren't in there already.

Alex
13.5k20 gold badges85 silver badges169 bronze badges
answered Jun 11, 2013 at 15:44
4
  • this generates path's like ./foo/bar .. I think we have to remove the first . - did it work for you like that? Commented Jun 13, 2013 at 17:03
  • Works fine for me with the leading ., yes. Else sed to the rescue: find . -type l -not -exec grep -q "{}" .gitignore \; -print | sed 's/^\.\///' Commented Jun 13, 2013 at 17:32
  • Actually, that breaks the grep... well, maybe there is a good way to clean the path up anyway... Commented Jun 13, 2013 at 17:53
  • 1
    Simple solution: find * .... Will update my answer. Commented Jun 13, 2013 at 18:04
3

This method only adds untracked symlinks so can be repeated without adding duplicate entries, symlinks that are in submodules or are otherwise already ignored, or intentionally tracked symlinks.

for f in $(git status --porcelain | grep '^??' | sed 's/^?? //'); do
 test -L "$f" && echo $f >> .gitignore;
 test -d "$f" && echo $f\* >> .gitignore;
done
answered Sep 30, 2014 at 14:16
2

Nowadays there is an option for this in the composer installer. Just set extra.auto-add-files-to-gitignore https://github.com/magento-hackathon/magento-composer-installer/blob/master/README.md#auto-add-files-to-gitignore

answered May 11, 2015 at 10:17
1

The combined solution of @ColinM and @Vinai that works for me

for f in $(git status --porcelain | grep '^??' | sed 's/^?? //'); do
 if test -L "$f"
 then
 test -L "$f" && echo $f >> .gitignore;
 elif test -d "$f"
 then
 find ${f%/} -type l -not -exec grep -q "^{}$" .gitignore \; -print >> .gitignore
 fi
done
answered Feb 1, 2016 at 15:02
2
  • Did you notice that recent composer installers auto exclude the symlinks? Commented Feb 1, 2016 at 16:15
  • Sure, but some of my projects is not under composer control. And solutions provided here are not only for composer projects but for ignoring symlinks altogether. Hope it will help somebody Commented Feb 2, 2016 at 6:23

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.