Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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

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

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
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top