• This repository has been archived on 24/Jul/2020
  • Stars
    star
    620
  • Rank 70,796 (Top 2 %)
  • Language
    Python
  • License
    GNU General Publi...
  • Created about 15 years ago
  • Updated about 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

mercurial to git bridge, pushed to directly from the hg-git plugin in Hg

Hg-Git Mercurial Plugin

This is the Hg-Git plugin for Mercurial, adding the ability to push and pull to/from a Git server repository from Hg. This means you can collaborate on Git based projects from Hg, or use a Git server as a collaboration point for a team with developers using both Git and Hg.

The Hg-Git plugin can convert commits/changesets losslessly from one system to another, so you can push via an Hg repository and another Hg client can pull it and their changeset node ids will be identical - Mercurial data does not get lost in translation. It is intended that Hg users may wish to use this to collaborate even if no Git users are involved in the project, and it may even provide some advantages if you're using Bookmarks (see below).

Dependencies

This plugin is implemented entirely in Python - there are no Git binary dependencies, you do not need to have Git installed on your system. The only dependencies are Mercurial and Dulwich. See the Makefile for information about which versions of Mercurial are known to work, and setup.py for which versions of Dulwich are required.

Usage

You can clone a Git repository from Hg by running hg clone <url> [dest]. For example, if you were to run

$ hg clone git://github.com/schacon/hg-git.git

Hg-Git would clone the repository and convert it to an Hg repository for you.

If you want to clone a github repository for later pushing (or any other repository you access via ssh), you need to convert the ssh url to a format with an explicit protocol prefix. For example, the git url with push access

[email protected]:schacon/hg-git.git

would read

git+ssh://[email protected]/schacon/hg-git.git

(Mind the switch from colon to slash after the host!)

Your clone command would thus look like this:

$ hg clone git+ssh://[email protected]/schacon/hg-git.git

If you are starting from an existing Hg repository, you have to set up a Git repository somewhere that you have push access to, add a path entry for it in your .hg/hgrc file, and then run hg push [name] from within your repository. For example:

$ cd hg-git # (an Hg repository)
$ # edit .hg/hgrc and add the target git url in the paths section
$ hg push

This will convert all your Hg data into Git objects and push them to the Git server.

Now that you have an Hg repository that can push/pull to/from a Git repository, you can fetch updates with hg pull.

$ hg pull

That will pull down any commits that have been pushed to the server in the meantime and give you a new head that you can merge in.

Hg-Git can also be used to convert a Mercurial repository to Git. You can use a local repository or a remote repository accessed via SSH, HTTP or HTTPS. Use the following commands to convert the repository (it assumes you're running this in $HOME).

$ mkdir git-repo; cd git-repo; git init; cd ..
$ cd hg-repo
$ hg bookmarks hg
$ hg push ../git-repo

The hg bookmark is necessary to prevent problems as otherwise hg-git pushes to the currently checked out branch confusing Git. This will create a branch named hg in the Git repository. To get the changes in master use the following command (only necessary in the first run, later just use git merge or rebase).

$ cd git-repo
$ git checkout -b master hg

To import new changesets into the Git repository just rerun the hg push command and then use git merge or git rebase in your Git repository.

Commands

gclear

TODO

gimport

TODO

gexport

TODO

git-cleanup

TODO

Hg Bookmarks Integration

Hg-Git pushes your bookmarks up to the Git server as branches and will pull Git branches down and set them up as bookmarks.

Installing

Clone this repository somewhere and make the 'extensions' section in your ~/.hgrc file look something like this:

[extensions]
hggit = [path-to]/hg-git/hggit

That will enable the Hg-Git extension for you.

See the Makefile for a list of compatible Mercurial versions.

Configuration

git.intree

hg-git keeps a git repository clone for reading and updating. By default, the git clone is the subdirectory git in your local Mercurial repository. If you would like this git clone to be at the same level of your Mercurial repository instead (named .git), add the following to your hgrc:

[git]
intree = True

git.authors

Git uses a strict convention for "author names" when representing changesets, using the form [realname] [email address]. Mercurial encourages this convention as well but is not as strict, so it's not uncommon for a Mercurial repo to have authors listed as, for example, simple usernames. hg-git by default will attempt to translate Mercurial usernames using the following rules:

  • If the Mercurial username fits the pattern NAME <EMAIL>, the git name will be set to NAME and the email to EMAIL.
  • If the Mercurial username looks like an email (if it contains an @), the git name and email will both be set to that email.
  • If the Mercurial username consists of only a name, the email will be set to none@none.
  • Illegal characters (stray <s or >s) will be stripped out, and for NAME <EMAIL> usernames, any content after the right-bracket (for example, a second >) will be turned into a url-encoded sigil like ext:(%3E) in the git author name.

Since these default behaviors may not be what you want (none@none, for example, shows up unpleasantly on Github as "illegal email address"), the git.authors option provides for an "authors translation file" that will be used during outgoing transfers from mercurial to git only, by modifying hgrc as such:

[git]
authors = authors.txt

Where authors.txt is the name of a text file containing author name translations, one per each line, using the following format:

johnny = John Smith <[email protected]>
dougie = Doug Johnson <[email protected]>

Empty lines and lines starting with a "#" are ignored.

It should be noted that this translation is on the hg->git side only. Changesets coming from Git back to Mercurial will not translate back into hg usernames, so it's best that the same username/email combination be used on both the hg and git sides; the author file is mostly useful for translating legacy changesets.

git.branch_bookmark_suffix

hg-git does not convert between Mercurial named branches and git branches as the two are conceptually different; instead, it uses Mercurial bookmarks to represent the concept of a git branch. Therefore, when translating an hg repo over to git, you typically need to create bookmarks to mirror all the named branches that you'd like to see transferred over to git. The major caveat with this is that you can't use the same name for your bookmark as that of the named branch, and furthermore there's no feasible way to rename a branch in Mercurial. For the use case where one would like to transfer an hg repo over to git, and maintain the same named branches as are present on the hg side, the branch_bookmark_suffix might be all that's needed. This presents a string "suffix" that will be recognized on each bookmark name, and stripped off as the bookmark is translated to a git branch:

[git]
branch_bookmark_suffix=_bookmark

Above, if an hg repo had a named branch called release_6_maintenance, you could then link it to a bookmark called release_6_maintenance_bookmark. hg-git will then strip off the _bookmark suffix from this bookmark name, and create a git branch called release_6_maintenance. When pulling back from git to hg, the _bookmark suffix is then applied back, if and only if an hg named branch of that name exists. E.g., when changes to the release_6_maintenance branch are checked into git, these will be placed into the release_6_maintenance_bookmark bookmark on hg. But if a new branch called release_7_maintenance were pulled over to hg, and there was not a release_7_maintenance named branch already, the bookmark will be named release_7_maintenance with no usage of the suffix.

The branch_bookmark_suffix option is, like the authors option, intended for migrating legacy hg named branches. Going forward, an hg repo that is to be linked with a git repo should only use bookmarks for named branching.

git.mindate

If set, branches where the latest commit's commit time is older than this will not be imported. Accepts any date formats that Mercurial does -- see hg help dates for more.

git.similarity

Specify how similar files modified in a Git commit must be to be imported as Mercurial renames or copies, as a percentage between "0" (disabled) and "100" (files must be identical). For example, "90" means that a delete/add pair will be imported as a rename if more than 90% of the file has stayed the same. The default is "0" (disabled).

git.renamelimit

The number of files to consider when performing the copy/rename detection. Detection is disabled if the number of files modified in a commit is above the limit. Detection is O(N^2) in the number of files modified, so be sure not to set the limit too high. Similar to Git's diff.renameLimit config. The default is "400", the same as Git.

git.findcopiesharder

Whether to consider unmodified files as copy sources. This is a very expensive operation for large projects, so use it with caution. Similar to git diff's --find-copies-harder option.

More Repositories

1

git-scribe

basically the best way to write an ebook
XSLT
1,352
star
2

gitbook

Git Community Book Source
Ruby
464
star
3

ticgit

Git based distributed ticketing system, including a command line client and web viewer
Ruby
432
star
4

grack

GIt Smart HTTP Server Rack Implementation
Ruby
384
star
5

git-pulls

command line tool to facilitate github pull requests
Ruby
292
star
6

why_i_love_github

265
star
7

cowsay

git version of awesome cowsay project
Shell
234
star
8

whygitisbetter

the source code for whygitisbetterthanx.com
Shell
163
star
9

git-presentations

some of my git presentations for others to use to spread the word. Warning: this clone is rather large.
132
star
10

igithub

github for the iphone
Objective-C
105
star
11

blink

Example file to blink the LED on an Arduino
Arduino
98
star
12

objective-git

Git Implementation in Objective-C
Objective-C
87
star
13

munger

a data munging and reporting library for Ruby
Ruby
82
star
14

erlangit

Erlang Git Implementation
Erlang
73
star
15

simplegit

example repo used for testing and such
Ruby
70
star
16

ShowOffPad

ShowOff Presenter on the iPad
Objective-C
67
star
17

simplegit-progit

simple git bindings - example project for Pro Git book
Ruby
61
star
18

geef

Git NEEEEF (Erlang NIF)
C
53
star
19

schacon.github.com

Ruby
51
star
20

git-lighthouse

A tool to help work with git projects that accept patches from Lighthouse
Ruby
47
star
21

git-ruby

A pure ruby implementation of Git - unmaintained. See grit for an active project that has inherited much of this code.
Ruby
45
star
22

kinectaby

ruby bindings to libfreenect
C
44
star
23

libgit

IGNORE THIS! - use libgit2
Ruby
41
star
24

situation-clock

41
star
25

asgit

ActionScript Git library and browser implementation
ActionScript
40
star
26

git-server

pure ruby version of git daemon server functions
Ruby
38
star
27

showoff-wrangling-git

Wrangling Git ShowOff presentation from LCA2010
JavaScript
28
star
28

ghapp.sinatra.min

Minimal Sinatra app that has GitHub auth all ready to go
Ruby
28
star
29

fuzec2

fuzed ec2 helper script
Ruby
26
star
30

githooks

example Git hooks such as user/path based ACL, message policy enforcement, etc
26
star
31

git-sphinx

a script that can help make your git repository code sphinxable
Ruby
21
star
32

ddd

developer driven development talk
JavaScript
20
star
33

github-contest

the github contest sinatra app
JavaScript
17
star
34

perl

perl mirror
17
star
35

libgit2-examples

project to make sure the api guide examples run
C
17
star
36

ribbit

Ruby bindings to libgit2 - moved to libgit2/ribbit
Ruby
16
star
37

recipes

15
star
38

tale_of_three_trees

rubynation talk
JavaScript
15
star
39

git-plumbing-preso

Git Plumbing Presentation at Scottish Ruby Conf
JavaScript
15
star
40

kidgloves

the worlds simplest rack handler - builtin, single threaded, crappy pure-ruby server
Ruby
13
star
41

agitmemnon-server

Cassandra/Git backed python Git server
Python
13
star
42

gs-manual

git-scribe user manual - describing the tool and technical aspects of the workflows
12
star
43

pycon-hg-git

My PyCon 2010 Hg/Git Talk
Ruby
11
star
44

snifter

HTTP sniffer/browser for debugging HTTP/XML based protocols
JavaScript
11
star
45

git-scribe-template

example git-scribe project structure
C
11
star
46

git-scm

Static templates for git-scm.com redesign
JavaScript
11
star
47

example

example git repository
11
star
48

calcdown

Calca/Soulver-like interpreter for Atom
CoffeeScript
10
star
49

gitcrazy

Crazy example scripts for a demonstration content distribution system using git
9
star
50

subsucka

Fast import project, written in Erlang and Ruby, for converting svn repos to git repos quickly.
Ruby
9
star
51

showoff-server

node.js/websocket server for allowing a presenter using ShowOff to control slides on their viewer's browsers.
JavaScript
7
star
52

agitmemnon

Git/Cassandra Ruby Library
JavaScript
7
star
53

schacon

for my profile readme :)
7
star
54

hungarian-desks

An AirTable backed Hungarian algorithm solution to office desk assignment
Ruby
7
star
55

generalhawk

General Hawk for CI Joe
Ruby
7
star
56

tres-arboles

una charla explicando git reset
7
star
57

gitbrowser

Ruby
6
star
58

groundcontrol

testing framework
JavaScript
6
star
59

sitebase

base for a simple site with blueprint css and jquery
6
star
60

collabgit

ShowOff preso on collaborating with Git
JavaScript
6
star
61

myproject

test for screencast
Ruby
6
star
62

showoff_open_source_biz

ShowOff Presentation on Open Source in Business
JavaScript
6
star
63

django-schedule

Python
6
star
64

fireeaglet

native iphone fire eagle updater
5
star
65

mydotjs

my dotjs scripts
JavaScript
5
star
66

gitrack

git on rack - just an example application for a screencast
Ruby
5
star
67

gitx

A gitk clone for OS X
Objective-C
4
star
68

hg-git-tester

crappy tests for hg-git to make things easier for me
Ruby
4
star
69

petition_watch

App to watch for petitions that you care about
Ruby
4
star
70

article

C
3
star
71

rails-test

Ruby
3
star
72

testrepo

test repo
Java
3
star
73

fowa-talk

3
star
74

git-crash-showoff

simple git showoff presentation
3
star
75

tobal

Automatically exported from code.google.com/p/tobal
Ruby
3
star
76

snakeeyes

cijoe like soldier that reports to general hawk
Ruby
3
star
77

fuselage

Light weight Ruby wrapper for Github v3 api
Ruby
2
star
78

example-stats

example project for article
Ruby
2
star
79

project

test project for tutorial
Ruby
2
star
80

teddy-tv-web

JavaScript
2
star
81

mytest

Ruby
2
star
82

hw

Ruby
2
star
83

aoc

Ruby
2
star
84

blah

Ruby
1
star
85

xc4test

1
star
86

testwhatever

1
star
87

trulia

Ruby
1
star
88

railstest

Ruby
1
star
89

try_git

1
star
90

man

manifest test
1
star
91

test-cmu

1
star
92

newrepo

1
star
93

testyd

1
star
94

usctest

Ruby
1
star
95

chatterblog1

CSS
1
star