Note: You are currently viewing documentation for Moodle 2.4. Up-to-date documentation for the latest stable version of Moodle may be available here: Git repositories for contrib modules.

Git repositories for contrib modules: Difference between revisions

From MoodleDocs
(Replaced content with "{{Moved_to_dev_docs}}")
 
Line 1: Line 1:
'''This page is a work in progress.''' The instructions here assume that you have a working knowledge of git.
{{Moved_to_dev_docs}}
 
Managing contrib plugin with git makes it easy to make local modifications and pull in updates.
There are several options for managing a contrib plugin with git:
# Add the module to your main moodle git repository
# Create a self-contained repository for the plugin in a subdirectory
# Create a git submodule, which creates a repository for the plugin but tracks updates in the main repository too. It also allows you to clone the plugins with the main repository
Having used all of the above, the method I'd recommend is number 2, as it's most convenient. The main disadvantage of 1 is that you can't easily pull in updates, and the main disadvantage of 3 is that you have to make each commit to the module twice (once in the submodule, and once in the main repo).
 
== Creating a new plugin ==
If you intend to publish the plugin, I highly recommend creating a [http://github.org github] repository from the start. This will allow you to publish with a single command when you're ready.  Just go to the site, sign up for an account, create a new repository. The naming convention for Moodle plugin repositories is <tt>moodle-plugintype_pluginname</tt>.
 
Github will give you instructions for cloning your (blank) repository. If you're using option 2 above, navigate to the directory for the plugin type you're developing (e.g. /block, /mod, /local) and run the <tt>git clone</tt> command there. This will create a subdirectory called <tt>moodle-plugintype_pluginname</tt>, rename this to <tt>pluginname</tt> and you're good to go. <tt>cd</tt> into this directory to perform git commands on this plugin's repository - outside of this directory will perform them on the main Moodle repository.
 
You can then develop and test your changes locally, and when you're ready to publish, run
git push origin
 
== Installing a third-party plugin ==
Installing a plugin developed by a third party differs depending on whether they have used git or not.
If they have used git, you can follow the instructions above, but skip out the part where you create a new github repository and clone their own github (or other public repository) instead.
 
If they haven't used git, you can still use git (and even github, if you like) to track local modifications to the plugin. Simply create a directory for the plugin
mkdir ~/moodle/blocks/newblock
Initialise a new git repository there
cd ~/moodle/blocks/newblock
git init
unzip or copy the files to the repository
cd ~
tar -xf newblock.tar.gz
cp newblock/* ~/moodle/blocks/newblock
add and commit the files
cd ~/moodle/blocks/newblock
git add .
git commit . -m "Added files for newblock"
When installing updates, you'll need to copy the new files in place of the old one, and re run the <tt>git add</tt> and <tt>git commit</tt> commands.
 
== Moving a plugin to it's own repository ==
You may have developed a plugin within your main Moodle repository, but want to move it to a separate one to make it easier to publish.  Using <tt>git filter-branch</tt>, we can achieve this and maintain all existing history for the plugin's files.
 
First, you'll need a fresh copy of moodle (this will become your new moodle repository)
mkdir ~/newmoodle
cd ~/newmoodle
git clone git://git.moodle.org/moodle.git
This will create a clone of Moodle without your plugins in ~/newmoodle/moodle
Next, you need to clone your local Moodle repository (why will become clear).
mkdir ~/moodleclone
cd ~/moodleclone
git clone ~/moodle
This will create a clone of your current moodle development repository, with your plugins, in ~/moodleclone/moodle
Now, we'll use the <tt>git filter-branch</tt> command to reduce this clone to just the plugin.
cd ~/moodleclone/moodle
git filter-branch --subdirectory-filter blocks/myblock/
The files from blocks/myblock/ will now be at the root of the repository. All other files will have been removed (this is why we're using a clone).
You can now track the plugin in it's own repository by cloning this reduced repository to a subdirectory of the new moodle clone.
cd ~/newmoodle/blocks
git clone ~/moodleclone/moodle myblock
This will clone the block's files, with the full history, into their own repository in the myblock subdirectory.
You can now delete ~/moodleclone/moodle, and repeat with any other plugins you've developed.

Latest revision as of 08:38, 16 June 2011

This development related page is now located in the Dev docs.

See the Git repositories for contrib modules page in the Dev docs.