Skip to content

Instantly share code, notes, and snippets.

@sheepmaster
Created March 9, 2010 03:33
Show Gist options
  • Select an option

  • Save sheepmaster/326122 to your computer and use it in GitHub Desktop.

Select an option

Save sheepmaster/326122 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
my $headref = `git symbolic-ref HEAD`;
my $head;
unless (($head) = ($headref =~ m!^refs/heads/(.*)!)) {
die "invalid HEAD ref '$headref'";
}
print STDERR "current branch: $head\n";
while (<>) {
chomp;
my ($old_ref, $new_ref, $refname) = split /\s/;
my ($remote, $branch);
if (($remote, $branch) = ($refname =~ m!^refs/remotes/([^/]+)/(.*)$!)) {
if ($branch eq $head) {
print STDERR "Merging $remote/$branch\n";
system("git merge --ff-only $remote/$branch");
} else {
print STDERR "Ignoring update to $remote/$branch\n";
}
} else {
warn "Invalid ref update '$refname'\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment