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.
-
1Would this apply to modman, too?philwinkle– philwinkle2013年06月11日 16:18:24 +00:00Commented 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– Vinai2013年06月11日 17:01:58 +00:00Commented 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– ColinM2014年09月30日 21:00:45 +00:00Commented Sep 30, 2014 at 21:00
4 Answers 4
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.
-
this generates path's like
./foo/bar.. I think we have to remove the first.- did it work for you like that?Alex– Alex2013年06月13日 17:03:28 +00:00Commented 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– Vinai2013年06月13日 17:32:52 +00:00Commented 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– Vinai2013年06月13日 17:53:38 +00:00Commented Jun 13, 2013 at 17:53
-
1Simple solution:
find * .... Will update my answer.Vinai– Vinai2013年06月13日 18:04:46 +00:00Commented Jun 13, 2013 at 18:04
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
-
Did you notice that recent composer installers auto exclude the symlinks?Alex– Alex2016年02月01日 16:15:38 +00:00Commented 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 somebodymartinBoy– martinBoy2016年02月02日 06:23:16 +00:00Commented Feb 2, 2016 at 6:23