Skip to content

Instantly share code, notes, and snippets.

@sheepmaster
Created March 31, 2010 10:59
Show Gist options
  • Select an option

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

Select an option

Save sheepmaster/350197 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
my $headref = `git symbolic-ref HEAD`;
if (my ($head) = ($headref =~ m!^refs/heads/(.*)!)) {
my $fh;
unless (open($fh, '-|', qw[git branch -r --no-merge HEAD])) {
print STDERR "Couldn't execute 'git branch -r --no-merge HEAD': $!\n";
exit(1);
}
my @branches;
while (<$fh>) {
chomp;
if (my ($branch) = m!^\s+([^/]+/\Q$head\E)$!) {
push(@branches, $branch);
}
}
if (@branches) {
print STDERR "git merge ", join(' ', @branches), "\n";
(system(qw[git merge], @branches) == 0) or die $!;
} else {
print STDERR "Already up-to-date.\n";
}
} else {
print STDERR "HEAD is at '$headref', which doesn't look like a branch\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment