Difference between revisions of "Using Mercurial"

From GeeklogWiki
Jump to: navigation, search
(moved GSoC repository)
Line 112: Line 112:
 
<pre>hg clone ssh://username@cvs.geeklog.net//cvsroot/hg/geeklog geeklog</pre>
 
<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>

Revision as of 08:55, 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.

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.

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/hgweb.cgi

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

To create a copy of that repository, simply do

hg clone http://project.geeklog.net/cgi-bin/hgweb.cgi 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.

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.

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(!) ~/.hgrc file:

[ui]
remotecmd = /usr/home/geeklog2/hg/mercurial/hg

Now you should be able to clone the repository like so:

hg clone ssh://username@cvs.geeklog.net//cvsroot/geeklog/Geeklog-SoC 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/geeklog/Geeklog-SoC

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/geeklog/Geeklog-SoC

(Again, in the ssh: URLs above, replace "username" with your login 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.


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:

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

Misc

  • moved GSoC repository to //cvsroot/hg/gsoc-2008