CUFP tobyink <p>I've never really gotten along with git. Its feature set is good, but its usability is horrible. Mercurial on the other hand has roughly the same features, but is much more enjoyable to use, which is why it is my version control system of choice.</p> <p>However, in recent years Github's popularity has exploded. So, how to get my code onto Github without using git?</p> <p>Firstly, there's the <a href="">hggit</a> mercurial extension that allows you to push to a git repository. Install it and add these lines to <c>.hgrc</c>:</p> <c> [extensions] hggit= bookmarks= </c> <p>Then you need to create a bookmark for hggit to use as the basis for the <c>master</c> git head:</p> <c> $ hg bookmark -r default master </c> <p>And now you can just push:</p> <c> $ hg push git+ssh:// </c> <p>So where does Perl come into it? Well, I want to automate the creation of the Github repository, and setting up the bookmark. Here's my script to do that...</p> <code> #!/usr/bin/env perl use v5.14; use constant { GH_USER => 'tobyink', GH_PASS => 'A BIG SECRET', }; use Acme::Constructor::Pythonic qw( Pithub Path::Class::File Path::Class::Dir ); use Cwd; BEGIN { package PithubX::Base; use Pithub::Base (); use Moo::Role; around _request_for => sub { my ($orig, $self, @args) = @_; my $req = $self->$orig(@args); $req->headers->remove_header('Authorization'); $req->headers->authorization_basic(::GH_USER, ::GH_PASS); return $req; }; 'Moo::Role'->apply_roles_to_package( 'Pithub::Base', 'PithubX::Base', ); }; my $gh = Pithub(user => GH_USER, token => 1); my $name = (Dir(cwd)->dir_list)[-1]; while ( not $gh->repos->get(repo => $name)->response->is_success ) { say "creating github repo '$name'"; $gh->repos->create(data => { name => $name, has_wiki => 0, has_downloads => 0, }); } unless (`hg bookmarks` =~ /master/) { say "creating 'master' bookmark"; system "hg bookmark -r default master"; } my $url = sprintf('git+ssh://', GH_USER, $name); system "hg push $url"; </code> <p>One interesting part of the script is the <c>PithubX::Base</c> package which acts as a monkey-patch for [mod://Pithub::Base], swapping out the OAuth authentication for HTTP basic auth because that seemed easier than figuring out how to get an OAuth authentication token.</p> <p>I've saved that as <c>github-mirror</c>. But so that I don't have to remember to run it, I've also added it as a hook in my <c>.hgrc</c> so that whenever I push changes to my mercurial repo, <c>github-mirror</c> runs too:</p> <c> [hooks] preoutgoing = /home/tai/bin/github-mirror </c> <!-- Node text goes above. Div tags should contain sig only --> <div class="pmsig"><div class="pmsig-757127"> <small><small> <tt>perl -E'sub Monkey::do{say$_,for@_,do{($monkey=&#x5B;caller(0)]->&#x5B;3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do' </tt></small></small> </div></div>