From f00ca9122ea98c9a770301a7646511d74f92c9c9 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 5 Feb 2008 13:16:00 -0500 Subject: [PATCH] * Prefer to commit to the ref that exactly matches what is specified at the command line. --- debian/changelog | 2 ++ pristine-tar | 34 +++++++++++++++++++--------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/debian/changelog b/debian/changelog index 4b37fec..d2efea2 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,6 +1,8 @@ pristine-tar (0.9) UNRELEASED; urgency=low * Add smart branching for commits. (Cyril Brulebois) + * Prefer to commit to the ref that exactly matches what is specified at the + command line. -- Joey Hess Tue, 05 Feb 2008 12:54:27 -0500 diff --git a/pristine-tar b/pristine-tar index 797cc63..fe2bee3 100755 --- a/pristine-tar +++ b/pristine-tar @@ -482,28 +482,32 @@ sub export { $id=$upstream; } else { - my @totry; if (! defined $upstream) { - # try a specific name first, if that's not - # present fall back to any upstream branch - @totry=("refs/heads/upstream", "upstream") + $upstream='upstream'; } - else { - @totry=($upstream); + + my @reflines=map { chomp; $_ } `git show-ref \Q$upstream\E`; + if (! @reflines) { + error "failed to find ref using: git show-ref $upstream"; } - foreach my $branch (@totry) { - my @reflines=map { chomp; $_ } `git show-ref \Q$branch\E`; - if (@reflines > 1) { - error "more than one ref matches \"$branch\":\n". - join("\n", @reflines); - } - elsif (@reflines) { - ($id)=$reflines[0]=~/^([A-Za-z0-9]+)\s/; + + # if one line's ref matches exactly, use it + foreach my $line (@reflines) { + my ($b)=$line=~/^[A-Za-z0-9]+\s(.*)/; + if ($b eq $upstream || $b eq "refs/heads/$upstream") { + ($id)=$line=~/^([A-Za-z0-9]+)\s/; last; } } + if (! defined $id) { - error "failed to find ref using: git show-ref @totry"; + if (@reflines == 1) { + ($id)=$reflines[0]=~/^([A-Za-z0-9]+)\s/; + } + else { + error "more than one ref matches \"$upstream\":\n". + join("\n", @reflines); + } } } -- 2.7.4