Last active
August 29, 2015 14:15
-
-
Save schwern/0b3cb8769124407f7a48 to your computer and use it in GitHub Desktop.
Find the nth unpushed reference in the current branch.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
sub current_branch { | |
my $branch=`git symbolic-ref --short HEAD`; | |
chomp $branch; | |
die "Cannot figure out the current branch.\n" unless $branch; | |
return $branch; | |
} | |
sub tracking_branch { | |
my $branch = shift; | |
my $remote=`git config branch.$branch.remote`; | |
chomp $remote; | |
die "$branch is not tracking a remote.\n" unless $remote; | |
my $remote_merge=`git config branch.$branch.merge | xargs git name-rev --name-only`; | |
chomp $remote_merge; | |
die "$branch has a remote ($remote) but is not set up to merge.\n" unless $remote_merge; | |
return "$remote/$remote_merge"; | |
} | |
my $number = shift; | |
my $remote_branch = tracking_branch(current_branch()); | |
system "git log --pretty=format:%H $remote_branch..HEAD | tail -n$number | head -n1"; | |
print "\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment