{"id":3543,"date":"2015-05-01T07:32:22","date_gmt":"2015-05-01T05:32:22","guid":{"rendered":"http:\/\/glandium.org\/blog\/?p=3543"},"modified":"2019-09-03T15:21:18","modified_gmt":"2019-09-03T06:21:18","slug":"using-a-git-clone-of-gecko-dev-to-push-to-mercurial-2","status":"publish","type":"post","link":"https:\/\/glandium.org\/blog\/?p=3543","title":{"rendered":"Using a git clone of gecko-dev to push to mercurial"},"content":{"rendered":"<p>[<b>Update<\/b>: An <a href=\"https:\/\/github.com\/glandium\/git-cinnabar\/wiki\/Mozilla:-Using-a-git-clone-of-gecko%E2%80%90dev-to-push-to-mercurial\">up-to-date version of this document<\/a> is available on the git-cinnabar wiki]<\/p>\n<p>The <a href=\"https:\/\/github.com\/glandium\/git-cinnabar\/tree\/next\"><code>next<\/code> branch of git-cinnabar<\/a> now has minimal support for grafting, enough to allow to graft a clone of <code><a href=\"https:\/\/github.com\/mozilla\/gecko-dev\">gecko-dev<\/a><\/code> to <code><a href=\"https:\/\/hg.mozilla.org\/mozilla-central\">mozilla-central<\/a><\/code> and other Mozilla branches. This will be available in version 0.3 (which I don't expect to release before June), but if you are interested, you can already try it.<\/p>\n<p>There are two ways you can work with <code>gecko-dev<\/code> and git-cinnabar.<\/p>\n<h2>Switching to git-cinnabar<\/h2>\n<p>This is the recommended setup.<\/p>\n<p>There are several reasons one would want to start from <code>gecko-dev<\/code> instead of a fresh clone of <code>mozilla-central<\/code>. One is to get the full history from before Mozilla switched to Mercurial, which <code>gecko-dev<\/code> contains. Another is if you already have a <code>gecko-dev<\/code> clone with local branches, where rebasing against a fresh clone would not be very convenient (but not impossible).<\/p>\n<p>The idea here is to use <code>gecko-dev<\/code> as a start point, and from there on, use cinnabar to pull and push from\/to Mercurial. The main caveat is that new commits pulled from Mercurial after this will not have the same SHA-1s as those on <code>gecko-dev<\/code>. Only the commits until the switch will. This also means different people grafting <code>gecko-dev<\/code> at different moments will have different SHA-1s for new commits. Eventually, I hope we can switch <code>gecko-dev<\/code> itself to use git-cinnabar instead of hg-git, which would solve this issue.<\/p>\n<p>Assuming you already have a <code><a href=\"https:\/\/github.com\/mozilla\/gecko-dev\">gecko-dev<\/a><\/code> clone, and git-cinnabar <code>next<\/code> installed:<\/p>\n<ul>\n<li>Change the remote URL:<br \/>\n<blockquote>\n<pre>$ git remote set-url origin hg::https:\/\/hg.mozilla.org\/mozilla-central<\/pre>\n<\/blockquote>\n<p>(replace <code>origin<\/code> with the remote name for <code>gecko-dev<\/code> if it's not <code>origin<\/code>)<\/li>\n<li>Add other mercurial repositories you want to track as well:<br \/>\n<blockquote>\n<pre>$ git remote add inbound hg::https:\/\/hg.mozilla.org\/integration\/mozilla-inbound\r\n$ git remote add aurora hg::https:\/\/hg.mozilla.org\/releases\/mozilla-aurora\r\n(...)<\/pre>\n<\/blockquote>\n<\/li>\n<li>Pull with grafting enabled:<br \/>\n<blockquote>\n<pre>$ git -c cinnabar.graft=true -c cinnabar.graft-refs=refs\/remotes\/origin\/* remote update<\/pre>\n<\/blockquote>\n<p>(replace <code>origin<\/code> with the remote name for <code>gecko-dev<\/code> if it's not <code>origin<\/code>)<\/li>\n<li>Finish the setup by setting push urls for all those remotes:<br \/>\n<blockquote>\n<pre>$ git remote set-url --push origin hg::ssh:\/\/hg.mozilla.org\/mozilla-central\r\n$ git remote set-url --push inbound hg::ssh:\/\/hg.mozilla.org\/integration\/mozilla-inbound\r\n$ git remote set-url --push aurora hg::ssh:\/\/hg.mozilla.org\/releases\/mozilla-aurora\r\n(...)<\/pre>\n<\/blockquote>\n<\/li>\n<\/ul>\n<p>Now, you're mostly done setting things up. Check out my <a href=\"\/blog\/?page_id=3438\">git workflow for Gecko development<\/a> for how to work from there.<\/p>\n<h2>Following gecko-dev<\/h2>\n<p>This setup allows to keep pulling from <code>gecko-dev<\/code> and thus keep the same SHA-1s. It relies on everything pulled from Mercurial existing in <code>gecko-dev<\/code>, which makes it cumbersome, which is why I don't recommend using it. For instance, you may end up pulling from Mercurial before the server-side mirroring made things available in <code>gecko-dev<\/code>, and that will fail. Some commands such as <code>git pull --rebase<\/code> will require you to ensure <code>gecko-dev<\/code> is up-to-date first (that makes winning push races essentially impossible). And more importantly, in some cases, what you push to Mercurial won't have the same commit SHA-1 in <code>gecko-dev<\/code>, so you'll have to manually deal with that (fortunately, it most cases, this shouldn't happen).<\/p>\n<p>Assuming you already have a <code><a href=\"https:\/\/github.com\/mozilla\/gecko-dev\">gecko-dev<\/a><\/code> clone, and git-cinnabar <code>next<\/code> installed:<\/p>\n<ul>\n<li>Add a remote for all mercurial repositories you want to track:<br \/>\n<blockquote>\n<pre>$ git remote add central hg::https:\/\/hg.mozilla.org\/mozilla-central\r\n$ git remote add inbound hg::https:\/\/hg.mozilla.org\/integration\/mozilla-inbound\r\n$ git remote add aurora hg::https:\/\/hg.mozilla.org\/releases\/mozilla-aurora\r\n(...)<\/pre>\n<\/blockquote>\n<\/li>\n<li>For each of those remotes, set a push url:<br \/>\n<blockquote>\n<pre>$ git remote set-url --push origin hg::ssh:\/\/hg.mozilla.org\/mozilla-central\r\n$ git remote set-url --push inbound hg::ssh:\/\/hg.mozilla.org\/integration\/mozilla-inbound\r\n$ git remote set-url --push aurora hg::ssh:\/\/hg.mozilla.org\/releases\/mozilla-aurora\r\n(...)<\/pre>\n<\/blockquote>\n<\/li>\n<li>For each of those remotes, set a refspec that limits to pulling the tip of the default branch:<br \/>\n<blockquote>\n<pre>$ git config remote.central.fetch +refs\/heads\/branches\/default\/tip:refs\/remotes\/central\/default\r\n$ git config remote.inbound.fetch +refs\/heads\/branches\/default\/tip:refs\/remotes\/inbound\/default\r\n$ git config remote.aurora.fetch +refs\/heads\/branches\/default\/tip:refs\/remotes\/aurora\/default\r\n(...)<\/pre>\n<\/blockquote>\n<p>Other branches can be added, but that must be done with care, because not all branches are exposed on <code>gecko-dev<\/code>.<\/li>\n<li>Set git-cinnabar grafting mode permanently:<br \/>\n<blockquote>\n<pre>$ git config cinnabar.graft only<\/pre>\n<\/blockquote>\n<\/li>\n<li>Make git-cinnabar never store metadata when pushing:<br \/>\n<blockquote>\n<pre>$ git config cinnabar.data never<\/pre>\n<\/blockquote>\n<\/li>\n<li>Make git-cinnabar only graft with <code>gecko-dev<\/code> commits:<br \/>\n<blockquote>\n<pre>$ git config cinnabar.graft-refs refs\/remotes\/origin\/*<\/pre>\n<\/blockquote>\n<p>(replace <code>origin<\/code> with the remote name for <code>gecko-dev<\/code> if it's not <code>origin<\/code>)<\/li>\n<li>Then pull from all remotes:<br \/>\n<blockquote>\n<pre>$ git remote update<\/pre>\n<\/blockquote>\n<p>Retry as long as you see errors about \"Not allowing non-graft import\". This will keep happening until all Mercurial changesets you're trying to pull make it to <code>gecko-dev<\/code>.\n<\/li>\n<\/ul>\n<p>With this setup, you can now happily push to Mercurial and see your commits appear in <code>gecko-dev<\/code> after a while. As long as you don't copy or move files, their SHA-1 <i>should<\/i> be the same as what you pushed.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[Update: An up-to-date version of this document is available on the git-cinnabar wiki] The next branch of git-cinnabar now has minimal support for grafting, enough to allow to graft a clone of gecko-dev to mozilla-central and other Mozilla branches. This will be available in version 0.3 (which I don&#8217;t expect to release before June), but [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[25],"tags":[23],"class_list":["post-3543","post","type-post","status-publish","format-standard","hentry","category-planet-mozilla","tag-en"],"_links":{"self":[{"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3543","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3543"}],"version-history":[{"count":8,"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3543\/revisions"}],"predecessor-version":[{"id":3577,"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=\/wp\/v2\/posts\/3543\/revisions\/3577"}],"wp:attachment":[{"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3543"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3543"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/glandium.org\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3543"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}