Migrating to Git

 

The OpenMRS community is currently in the process of evaluating Git as a replacement for SVN.

GitHub

There is an OpenMRS organization on GitHub (http://github.com/openmrs) used to host community OpenMRS projects. All bundled modules managed within git are kept under this organization with the naming convention "openmrs-module-<moduleid>".  All community-supportes modules are welcome and encouraged to be kept under the OpenMRS organization as well.  Other organizations and authors who maintain OpenMRS modules under other accounts within github are encouraged to use the same naming convention.

Naming Conventions

When using Git for your project, please use the following naming conventions:

  • Use all lowercase.

  • For modules, use the name "openmrs-module-moduleid" (for example: openmrs-module-htmlformentry); for contributions, use the name "openmrs-contrib-contribname" (for example: openmrs-contrib-standalone).

  • Please include "OpenMRS module" or "OpenMRS Contrib" somewhere in your project's README.

When creating a new module or contrib, please e-mail code@openmrs.org to request a module ID or contribution name, including your OpenMRS ID, a description of your module/contribution, and your proposed module ID or contribname.  The conversation with the "code" e-mail group is used to avoid duplicates and maximize consistency of naming; you should expect a module ID to be decided within one day of your request.  Eventually, we hope to create a more automated process for ensuring uniqueness of module identification & awareness of existing modules.

Getting Started with GitHub

To get started with Git and GitHub you should read the documentation for your OS:

These pages explain adding SSH keys (better than passwords), and configuring your local git to use your GitHub credentials, e.g.

git config --global github.user username git config --global github.token 0123456789yourf0123456789token

Repository conversion

The tool that Github recommends is svn2git. It expects your project to be organized in the standard SVN way of trunk, branches and tags, so you should reorganize the project before conversion if necessary.

Copy the list of authors from Github Authors txt into an authors.txt file and from that folder, start with:

$ mkdir openmrs-module-yourmoduleid $ cd openmrs-module-yourmoduleid $ svn2git http://svn.openmrs.org/openmrs-modules/yourmoduleid --authors ~/authors.txt

 

Be patient. The svn2git command can run for a while without any visual feedback. You can open another terminal and peek at the contents of the directory (most initial content goes into the .git folder which is hidden by default).

 

Once the complete project is converted from svn to git format, you need to get it up to GitHub.

  1. Create a new repo in Github (or ask for one for the OpenMRS org from code@openmrs.org)

    1. Name: openmrs-module-yourmoduleid

    2. Description: a one-line description of what the module does (look at others for examples)

    3. Make it public

    4. Initialize with a README

    5. Add .gitignore for maven

  2. Edit the module's pom.xml to use the github address

    <scm> <connection>scm:git:https://github.com/openmrs/openmrs-module-yourmoduleid/</connection> <developerConnection>scm:git:https://github.com/openmrs/openmrs-module-yourmoduleid/</developerConnection> <url>https://github.com/openmrs/openmrs-module-yourmoduleid/</url> </scm>

     

  3. Change the local repo you just converted to point at that one github repo "origin" (below)

     

     

  4. Assuming that your module uses the OpenMRS license and it wasn't already in subversion's root, add it:

     

  5. Commit your changes locally

     

  6. Push the code to github (below)

    Push the tags manually using the following command.

     

  7. Add default teams to the new github repository:

    1. Full Committers

    2. Partial Committers

    3. Repo Owners
       

  8. Under the Admin section for the new github repository, make sure Wiki & Issues are unchecked (we don't want wiki & issues going into github; rather, we want people using wiki.openmrs.org and jira.openmrs.org)

Retiring the SVN project

It's important to clearly indicate to other developers that the SVN project is no longer the active repository for the project. After successfully loading the code into github, rather than delete the project, you should:

  1. Add a text file called MIGRATED to the SVN project root that contains the URL of the new repository location (example)

  2. Remove trunk and branches folders (previous tags may be left in SVN)

Leaving the root folder with a MIGRATED text file pointing to the new location will allow any persons with old links to find the new location of the code.

Mavenization

It's preferable that older modules be mavenized prior to migrating to git, since it significantly reduces the size of the repository, making it easier for low-bandwidth developers to clone the repository locally.  If your module is not yet mavenized, see Converting old code to Maven.

For Mavenized projects, IDE specific files should not be included in the repository. Git supports an ignore file similar to SVN called .gitignore, and so for a typical mavenized module project this will look like:

Mavenized projects do not include JAR files, but if your project was previously a normal project with JAR files, then these will still exist in the repository history, and will make your new Git repository much larger than it needs to be. However JAR files can be removed from the history of a project using the method described on this page:

Your pom.xml file also needs updated to refer to github instead of svn in the "scm" tags.

Authors

During the conversion, user accounts for the OpenMRS SVN repository can be mapped to personal GitHub accounts. This is done using a text file which lists account mappings as follows:

If authors list is not specified all the authors email id's will be randomly generated with the git hashes. The following command can generate a list of SVN accounts from an existing SVN repository:

We have a shared authors file. Please use and add to this as needed: Github Authors txt!

IDE integration

Best Practices

Here's the set of best practices to follow in distributed OpenSource projects.