When developing Magento modules, it is quite tedious to create packages for Magento Connect. That is why there are often modules that are not present in this one but available elsewhere, eg on GitHub. I will present here a very fast way to install Magento modules available on Git repositories through modgit
tool.
Introducing modgit
modgit
(for Module Git) is neither more nor less than a shell script to clone a Git repository and deploy the code in your project. Directly inspired by the great modman, modgit
has the advantage of including or excluding a portion of the repository and not to create symlinks but physically copy the files into your project.
Prerequisites
- bash
- git
modgit installation
modgit
is available on GitHub: https://github.com/jreinke/modgit. Once downloaded:
$ cp /path/to/modgit /usr/local/bin # (or any folder in your $PATH) $ cd /usr/local/bin $ chmod +x modgit |
Install a Magento module with modgit
For our example, we will install the excellent PHPUnit Magento module developed by Ivan Chepurnyi and available on GitHub: https://github.com/IvanChepurnyi/EcomDev_PHPUnit.
Here is the procedure:
$ cd /path/to/magento $ modgit init $ modgit clone ecomdev-phpunit https://github.com/IvanChepurnyi/EcomDev_PHPUnit.git |
And that’s it! The code is deployed on your Magento tree like this:
Now, you just have to clean Magento cache.
Note: we can see that files were deployed to the root of the tree and which are not required to operate the module. We’ll see how a little further exclude them during installation.
Update installed modules
With modgit
, you can update a specific module or all modules at once.
Update a specific module:
$ modgit update <module> |
Update all installed modules:
$ modgit update-all |
List all installed modules
$ modgit list |
Remove a module
$ modgit remove <module> |
Advanced usage
modgit
is able to include or exclude files and folders of your choice. Taking the example above, all files of EcomDev_PHPUnit repository have been copied into Magento tree and we end up with unwanted files in root folder. To exclude LICENSE.txt, README.md and modman files, simply exclude them as below when installing:
$ modgit -e LICENSE.txt -e README.md -e modman clone ecomdev-phpunit https://github.com/IvanChepurnyi/EcomDev_PHPUnit.git |
To include only a portion of the repository, the operation is the same, just specify the list of files and folders you want to copy using the -i
option.
Conclusion
modgit
gives you the ability to install, update and remove quickly any Magento module available on a Git repository. It is therefore very useful if you want to quickly test a module, if a module is not available on Magento Connect or if you’re just a little allergic to it ;).
22 Responses to “Install Magento modules with modgit”
windows version of BASH does not support constructions like:
==============
while read line; do
…
done < /dev/null)
==============
so we have to change it to
==============
cat “$deployed_file” 2>/dev/null | while read line; do
…
done
==============
also the next change is:
echo “$(tput bold)$1$(tput sgr0)” => echo “$1″ (row 90)
Thanks for your feedback.
Is there a way to only include a sub dir?
lets say the repo looked like
+src
+–app
+—-code
and all I wanted was the app dir?
Sure you have an example in advanced usage section: https://github.com/jreinke/modgit#advanced-usage
Awesome tool!
Also thanks for using our unit tests extension!
Modgit really is a perfect fit for handling mangento modules but I had no luck getting it to run on windows. I’ve tried cygwin, win-bash but to no avail. It seems like Yuriy got it just right but I have no idea how. Can someone please elaborate on how to get this to work on windows? Thanks!
What happens if I change files of a module and then update? It will merge versions or overwrite my changes?
It will overwrite the changes. It could be a nice feature to push modifications to installed module. I’ll think about it.
Hi Johann, awesome stuff, unfortunately our clients dont have real knowledge about shell or command line tools
It would be great if you could update from within Magento admin user interface and upload update are url to update file with a click of a button.
Salut,
Est-ce que tu as déjà essayé d’appeler modgit via un hook de Git ? J’ai tenté mais sans succès pour le moment… J’ai simplement rajouté ça dans le post-receive :
#!/bin/sh
cd /path/to/magento
modgit up MonModule
si j’exécute le fichier post-receive à la main ça fonctionne mais en passant depuis un push Local => Remote, rien ne se passe. Si tu as une idée, je suis preneur. Un grand merci pour Modgit !
Hi Johan
I’ve got an error using modgit on mac OSX 10.8. I always got this error :
./modgit clone [email protected]:jreinke/magento-elasticsearch.git
ERROR: You cannot add a module with a name not matching [^a-zA-Z0-9_-]+ pattern
Module specified: [email protected]:jreinke/magento-elasticsearch.git
Is their any issues ?
thx, Yohan
Hello,
This is the correct syntax:
modgit clone elasticsearch https://github.com/jreinke/magento-elasticsearch.git
sorry i’ve just forgot the module title in the command line.
Work now
thx
When i tried to init the modgit
[[email protected] magentosample]# modgit init
-bash: /usr/local/bin/modgit: /bin/bash^M: bad interpreter: No such file or directory
Am getting this error, though i downloaded and copied the file with execute permission into /usr/local/bin/
This is a bash script, if you are using a different interpreter it might be incompatible.
Hey. Nice and interesting article. Did anyone get it run on windows? I try to modify the script like yuriy recommend above but i’m still getting errors.
Hello Johann,
Thanks very much for modgit, it looks to be very useful.
However, I found that when I used it to clone the current EcomDev_PHPUnit, these files are not deployed and not listed in the ‘modgit files’ output.:
app/etc/local.xml.phpunit
app/etc/modules/EcomDev_PHPUnit.php
app/etc/modules/EcomDev_PHPUnitTest.php
shell/ecomdev-phpunit.php
What am I doing wrong?
FYI the full command I used was:
modgit add -e .gitignore -e .gitmodules -e LICENSE.txt -e README.md -e modman -e composer.json -b dev EcomDev https://github.com/EcomDev/EcomDev_PHPUnit.git
My guess is there is a problem with the modman file parser. The only files that are not deployed by modgit are files that match a modman line with a filter containing “*.{something}”.
EcomDev_PHPUnit’s modman file is:
>>>
app/etc/modules/*.xml app/etc/modules/
app/code/community/EcomDev/* app/code/community/EcomDev/
lib/EcomDev/* lib/EcomDev/
lib/Spyc lib/Spyc
lib/vfsStream lib/vfsStream
shell/*.php shell/
<< line=”${line/\*/}” # remove * char
Which means the comparison on line 339 of:
> if [[ "$file" =~ ^$1 ]]
will fail in these cases as it will evaluate to something like:
> if [[ "app/etc/local.xml.phpunit" =~ "app/etc/modules/.xml" ]]
Unfortunately I’m not good enough at bash to code a fix
Gah! I messed up the formatting ..
The problem happens when the modman file’s filter expression ends with “*{something}”, like “app/etc/modules/*.xml”.
Line 337 of modgit is:
> line=”${line/\*/}” # remove * char
Which means the comparison on line 339 of:
> if [[ "$file" =~ ^$1 ]]
will fail in these cases as it will evaluate to something like:
> if [[ "app/etc/local.xml.phpunit" =~ "app/etc/modules/.xml" ]]
The problem is still there today regarding local.xml.phpunit.
modgit gives you the ability to install, update and remove quickly any Magento module available on a Git repository. It is therefore very useful if you want to quickly test a module,
> it’s only for install and remove? Can I modify and update modules?
Why, when I modified ./.modgit/module/source/app/module/controller.php, and did
modgit update-all
It’s not updated in ./app/module/controller.php ?
>modgit has the advantage of including or excluding a portion of the repository and not to create symlinks but physically copy the files into your project
I’m sorry, what’s the _advantage_?