#!/usr/bin/env perl use strict; use WWW::Mechanize; use Config; unless (scalar @ARGV) { print "Usage: git pasteapply [options] [...]\n" . "Fetches the paste from pastebin.ca numbered and applies\n" . "Options are passed directly to git am\n" . "\n" . "Useful options:\n" . " -s, --signoff Add Signed-off-by: line to the commit message\n" . " -3, --3way When the patch does not apply cleanly, fall back on 3-way merge\n" . " -p Strip elements of the paths (default 1)\n" . " --whitespace=\n"; exit 0; } my @pastes; my @args; my $pastebin_root = "http://pastebin.ca/raw/"; for (@ARGV) { if (m/^-/) { push @args, $_; } else { push @pastes, $_; } } open GIT_AM, "|-", "git", "am", @args, "-" or die "Cannot start git-am: $!"; my $www = WWW::Mechanize->new(); foreach my $paste (@pastes) { $www->get($pastebin_root . $paste); my $content = $www->content(); $content =~ s/\r\n/\n/g; print GIT_AM $content; } close GIT_AM; exit $?