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.

3
  • 1
    Would this apply to modman, too?
    – philwinkle
    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.
    – Vinai
    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.
    – ColinM
    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.

4
  • this generates path's like ./foo/bar .. I think we have to remove the first . - did it work for you like that?
    – Alex
    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/^\.\///'
    – Vinai
    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...
    – Vinai
    Commented Jun 13, 2013 at 17:53
  • 1
    Simple solution: find * .... Will update my answer.
    – Vinai
    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
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

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
2
  • Did you notice that recent composer installers auto exclude the symlinks?
    – Alex
    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
    – martinBoy
    Commented Feb 2, 2016 at 6:23

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.