#!/usr/bin/env perl use strict; use warnings; my ($remote, $id, $branch); if (@ARGV == 1 and $ARGV[0] =~ /^[0-9]+$/) { $remote = "origin"; $id = $branch = shift @ARGV; } elsif (@ARGV == 2) { $remote = shift @ARGV; $id = $branch = shift @ARGV; } elsif (@ARGV == 3) { ($remote, $id, $branch) = @ARGV; } else { die "usage: git mr [REMOTE_NAME] MERGE_REQUEST_ID [BRANCH_NAME]\n"; } system "git fetch $remote merge-requests/$id/head"; system "git checkout -b mr/$branch FETCH_HEAD";