* Prefer to commit to the ref that exactly matches what is specified at the
authorJoey Hess <joey@kodama.kitenet.net>
Tue, 5 Feb 2008 18:16:00 +0000 (13:16 -0500)
committerJoey Hess <joey@kodama.kitenet.net>
Tue, 5 Feb 2008 18:16:00 +0000 (13:16 -0500)
  command line.

debian/changelog
pristine-tar

index 4b37fec..d2efea2 100644 (file)
@@ -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 <joeyh@debian.org>  Tue, 05 Feb 2008 12:54:27 -0500
 
index 797cc63..fe2bee3 100755 (executable)
@@ -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);
+                               }
                        }
                }