Difference between revisions of "Using Mercurial"

From GeeklogWiki
Jump to: navigation, search
(new URLs)
(Switch to Mercurial is now official; updated URLs and instructions)
Line 6: Line 6:
 
* Changes can be pushed back to the parent repository or even to other repositories.
 
* Changes can be pushed back to the parent repository or even to other repositories.
  
As an experiment, we are going to use Mercurial during the 2008 [[Google Summer of Code]]. The distributed model fits this scenario nicely, as each of our students will work on a separate feature. So now they have a local repository to check in to (giving them all the benefits of a version control system). Once a feature or part of a feature is done, it can be pushed back to the parent repository. And in the meantime, it's easy to let other people, e.g. their mentor or interested members of the Geeklog community, pull the changes from the student's repository to show things off or get help on a problem.
+
After using CVS since its inception, Geeklog switched to Mercurial after the release of Geeklog 1.5.1. This switch was preceded by an successful experiment using Mercurial during the 2008 [[Google Summer of Code]]. The distributed model did fit this scenario nicely, as each of our students was working on a separate feature. So they had a local repository to check in to (giving them all the benefits of a version control system). Once a feature or part of a feature was done, it could be pushed back to the parent repository. And in the meantime, it was easy to let other people, e.g. their mentor or interested members of the Geeklog community, pull the changes from the student's repository to show things off or get help on a problem.
  
 
== Installing Mercurial ==
 
== Installing Mercurial ==
Line 16: Line 16:
 
Geeklog's Mercurial repository is available from this URL:
 
Geeklog's Mercurial repository is available from this URL:
  
: http://project.geeklog.net/cgi-bin/hgweb.cgi
+
: http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/
  
This repository was converted from the CVS repository right after the release of [http://www.geeklog.net/article.php/geeklog-1.5.0 Geeklog 1.5.0].
+
This repository was converted from the CVS repository right after the release of [http://www.geeklog.net/article.php/geeklog-1.5.1 Geeklog 1.5.1].
  
 
To create a copy of that repository, simply do
 
To create a copy of that repository, simply do
  
<pre>hg clone http://project.geeklog.net/cgi-bin/hgweb.cgi geeklog</pre>
+
<pre>hg clone http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/ geeklog</pre>
  
 
Where "geeklog" is just a directory name for the local copy (and can be changed at will). This will give you a fully working local repository that you can commit changes to.
 
Where "geeklog" is just a directory name for the local copy (and can be changed at will). This will give you a fully working local repository that you can commit changes to.
 +
 +
'''Note:''' The same URL can also be used to browse the repository online. Simply visit that URL with your web browser.
  
 
=== SSH Setup ===
 
=== SSH Setup ===
Line 30: Line 32:
 
For ssh access, you need an account on the server. So this is only of interest for the core developers and SoC students.
 
For ssh access, you need an account on the server. So this is only of interest for the core developers and SoC students.
  
The repository can also be checked out via ssh. Since Mercurial is currently only installed in a user's directory on the server, this requires the following entry in your local(!) <tt>~/.hgrc</tt> file:
+
You can clone the repository via SSH like so:
  
<pre>[ui]
+
<pre>hg clone ssh://username@cvs.geeklog.net//cvsroot/hg/geeklog geeklog</pre>
remotecmd = /usr/home/geeklog2/hg/mercurial/hg</pre>
 
 
 
Now you should be able to clone the repository like so:
 
 
 
<pre>hg clone ssh://username@cvs.geeklog.net//cvsroot/geeklog/Geeklog-SoC geeklog</pre>
 
  
 
Where "username" is your login name and the "geeklog" at the end of the command line is again simply a name for your local directory.
 
Where "username" is your login name and the "geeklog" at the end of the command line is again simply a name for your local directory.
Line 48: Line 45:
 
Being able to push changes back to the repository again requires an account on the server. You can either do
 
Being able to push changes back to the repository again requires an account on the server. You can either do
  
<pre>hg push ssh://username@cvs.geeklog.net//cvsroot/geeklog/Geeklog-SoC</pre>
+
<pre>hg push ssh://username@cvs.geeklog.net//cvsroot/hg/geeklog</pre>
  
 
or, to make your life easier, set the <tt>default-push</tt> repository in the <tt>.hg/hgrc</tt> file of your local repository like so:
 
or, to make your life easier, set the <tt>default-push</tt> repository in the <tt>.hg/hgrc</tt> file of your local repository like so:
  
<pre>default-push = ssh://username@cvs.geeklog.net//cvsroot/geeklog/Geeklog-SoC</pre>
+
<pre>default-push = ssh://username@cvs.geeklog.net//cvsroot/hg/geeklog</pre>
  
 
(Again, in the ssh: URLs above, replace "username" with your login name)
 
(Again, in the ssh: URLs above, replace "username" with your login name)
 +
 +
 +
== GSoC Repository ==
 +
 +
The repository used during the 2008 Google Summer of Code is still available from
 +
 +
: http://project.geeklog.net/cgi-bin/hgwebdir.cgi/gsoc-2008/
 +
 +
Note that both the URL and the repository name have changed (formerly <tt>Geeklog-SoC</tt>). You can still use your local copies of that repository - you only need to update the <tt>default-push</tt> setting to the new address and name.
  
  
Line 102: Line 108:
  
  
= In Progress =
 
 
Notes while doing the conversion from CVS and moving things around - to be cleaned up and merged with the above once we're done ...
 
 
== Clone ==
 
 
To clone the official Geeklog 1.x Mercurial repository via SSH:
 
 
<pre>hg clone ssh://username@cvs.geeklog.net//cvsroot/hg/geeklog geeklog</pre>
 
 
[[Category:Development]]
 
[[Category:Development]]
 
== Misc ==
 
 
* moved GSoC repository to <tt>//cvsroot/hg/gsoc-2008</tt>
 
 
== URLs ==
 
 
* Geeklog repository: http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/
 
* GSoC 2008 repository: http://project.geeklog.net/cgi-bin/hgwebdir.cgi/gsoc-2008/
 

Revision as of 11:48, 26 September 2008

Introduction

Mercurial is a distributed version control system (DVCS). The differences to a "traditional" centralized VCS (like CVS or Subversion) include:

  • Users get a self-contained repository that they can commit changes to, even when being offline.
  • Changes can be pushed back to the parent repository or even to other repositories.

After using CVS since its inception, Geeklog switched to Mercurial after the release of Geeklog 1.5.1. This switch was preceded by an successful experiment using Mercurial during the 2008 Google Summer of Code. The distributed model did fit this scenario nicely, as each of our students was working on a separate feature. So they had a local repository to check in to (giving them all the benefits of a version control system). Once a feature or part of a feature was done, it could be pushed back to the parent repository. And in the meantime, it was easy to let other people, e.g. their mentor or interested members of the Geeklog community, pull the changes from the student's repository to show things off or get help on a problem.

Installing Mercurial

Installation instructions are provided for Windows, Mac OS X, and Linux

Setup

Geeklog's Mercurial repository is available from this URL:

http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/

This repository was converted from the CVS repository right after the release of Geeklog 1.5.1.

To create a copy of that repository, simply do

hg clone http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/ geeklog

Where "geeklog" is just a directory name for the local copy (and can be changed at will). This will give you a fully working local repository that you can commit changes to.

Note: The same URL can also be used to browse the repository online. Simply visit that URL with your web browser.

SSH Setup

For ssh access, you need an account on the server. So this is only of interest for the core developers and SoC students.

You can clone the repository via SSH like so:

hg clone ssh://username@cvs.geeklog.net//cvsroot/hg/geeklog geeklog

Where "username" is your login name and the "geeklog" at the end of the command line is again simply a name for your local directory.

Please note the slightly odd path syntax with the two slashes after cvs.geeklog.net - those are required.


Pushing back

Being able to push changes back to the repository again requires an account on the server. You can either do

hg push ssh://username@cvs.geeklog.net//cvsroot/hg/geeklog

or, to make your life easier, set the default-push repository in the .hg/hgrc file of your local repository like so:

default-push = ssh://username@cvs.geeklog.net//cvsroot/hg/geeklog

(Again, in the ssh: URLs above, replace "username" with your login name)


GSoC Repository

The repository used during the 2008 Google Summer of Code is still available from

http://project.geeklog.net/cgi-bin/hgwebdir.cgi/gsoc-2008/

Note that both the URL and the repository name have changed (formerly Geeklog-SoC). You can still use your local copies of that repository - you only need to update the default-push setting to the new address and name.


Best practices

Since we're all new to Mercurial, this is something we will have to establish as we go along. For starters, the Mercurial Wiki has a page on Working Practices that we may want to adopt.

Use a clean incoming repository

Pull changes to a local "incoming" repository but don't work on that repository. Cloning that repository locally is a cheap operation and allows you to easily create multiple copies if necessary, e.g. when working on different features in parallel.

Push directly from you working repositories, then sync back by pulling the changes back down via your incoming repository.

Merging

If you attempt to push changes to the main repository and receive the error:

remote: Not trusting file [some remote file] from untrusted user geeklog2, group users
pushing to ssh://username@cvs.geeklog.net//cvsroot/geeklog/Geeklog-SoC
searching for changes
abort: push creates new remote heads!
(did you forget to merge? use push -f to force)
remote: Not trusting file [some remote file] from untrusted user geeklog2, group users

Simply pull from the main repository, "hg heads" to see the revision numbers, "hg merge [rev number]" to merge your changes, then commit the changes, and push back to the main repository.

Also: Don't try to push newly added files while you still have uncommited changes lying around (or you will end up with the above). In that case, it may make sense to make a fresh clone (fast + cheap if you use an "incoming" repository!), add the new files there, then push from the fresh copy.

Username

When committing a change, the username associated with that change will be your local username (login, etc.) - not the name of your account on the server.

For a consistent username, add your preferred username to your local .hgrc file:

username = John Doe <john@example.com>

The email address is optional.

(More tips and tricks to be added here)


Undoing Changes

To undo changes you made, use one of the following, depending on circumstances:

  • hg revert
    to revert changes made before a commit. This will also undo hg add and hg remove.
  • hg rollback
    to revert changes that have been commited to the local repository but not been pushed to another repository yet. You can only rollback the last hg command.
  • hg backout
    to revert changes after they have been commited and pushed.

Note that hg backout will actually add a new change to the current branch that reverts your previous change. I.e. your change will not be removed from the repository. Unless you've accidentally committed something super-secret, that's usually fine. Mistakes happen - no need to sweat it.