git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC PATCH 2/1] Make request-pull able to take a refspec of form local:remote

From
Linus Torvalds <torvalds@linux-foundation.org>
Date
Jan 23, 2014, 00:06 UTC
Message-ID
<alpine.LFD.2.11.1401221535140.18207@i7.linux-foundation.org>
From: Linus Torvalds <torvalds@linux-foundation.org>
Date: Wed, 22 Jan 2014 15:23:48 -0800
Subject: [PATCH] Make request-pull able to take a refspec of form local:remote

This allows a user to say that a local branch has a different name on the remote server, using the same syntax that "git push" uses to create that situation.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
---

So this relaxes the remote matching, and allows using the "local:remote" syntax to say that the local branch is differently named from the remote one.

It is probably worth folding it into the previous patch if you think this whole approach is workable.

 git-request-pull.sh | 50 +++++++++++++++++++++++++++++---------------------
 1 file changed, 29 insertions(+), 21 deletions(-)
diff --git a/git-request-pull.sh b/git-request-pull.sh
index 659a412155d8..c8ab0e912011 100755
--- a/git-request-pull.sh
+++ b/git-request-pull.sh
@@ -47,19 +47,23 @@ fi
 
 #
 # $3 must be a symbolic ref, a unique ref, or
-# a SHA object expression
+# a SHA object expression. It can also be of
+# the format 'local-name:remote-name'.
 #
-head=$(git symbolic-ref -q "${3-HEAD}")
-head=${head:-$(git show-ref "${3-HEAD}" | cut -d' ' -f2)}
-head=${head:-$(git rev-parse --quiet --verify "$3")}
+local=${3%:*}
+local=${local:-HEAD}
+remote=${3#*:}
+head=$(git symbolic-ref -q "$local")
+head=${head:-$(git show-ref --heads --tags "$local" | cut -d' ' -f2)}
+head=${head:-$(git rev-parse --quiet --verify "$local")}
 
 # None of the above? Bad.
-test -z "$head" && die "fatal: Not a valid revision: $3"
+test -z "$head" && die "fatal: Not a valid revision: $local"
 
 # This also verifies that the resulting head is unique:
 # "git show-ref" could have shown multiple matching refs..
 headrev=$(git rev-parse --verify --quiet "$head"^0)
-test -z "$headrev" && die "fatal: Ambiguous revision: $3"
+test -z "$headrev" && die "fatal: Ambiguous revision: $local"
 
 # Was it a branch with a description?
 branch_name=${head#refs/heads/}
@@ -69,9 +73,6 @@ then
 	branch_name=
 fi
 
-prettyhead=${head#refs/}
-prettyhead=${prettyhead#heads/}
-
 merge_base=$(git merge-base $baserev $headrev) ||
 die "fatal: No commits in common between $base and $head"
 
@@ -81,30 +82,37 @@ die "fatal: No commits in common between $base and $head"
 #
 # Otherwise find a random ref that matches $headrev.
 find_matching_ref='
-	my ($exact,$found);
+	my ($head,$headrev) = (@ARGV);
+	my ($found);
+
 	while (<STDIN>) {
+		chomp;
 		my ($sha1, $ref, $deref) = /^(\S+)\s+([^^]+)(\S*)$/;
-		next unless ($sha1 eq $ARGV[1]);
-		if ($ref eq $ARGV[0]) {
-			$exact = $ref;
+		my ($pattern);
+		next unless ($sha1 eq $headrev);
+
+		$pattern="/$head\$";
+		if ($ref eq $head) {
+			$found = $ref;
+		}
+		if ($ref =~ /$pattern/) {
+			$found = $ref;
 		}
-		if ($sha1 eq $ARGV[0]) {
+		if ($sha1 eq $head) {
 			$found = $sha1;
 		}
 	}
-	if ($exact) {
-		print "$exact\n";
-	} elsif ($found) {
+	if ($found) {
 		print "$found\n";
 	}
 '
 
-ref=$(git ls-remote "$url" | @@PERL@@ -e "$find_matching_ref" "$head" "$headrev")
+ref=$(git ls-remote "$url" | @@PERL@@ -e "$find_matching_ref" "${remote:-HEAD}" "$headrev")
 
 if test -z "$ref"
 then
-	echo "warn: No match for $prettyhead found at $url" >&2
-	echo "warn: Are you sure you pushed '$prettyhead' there?" >&2
+	echo "warn: No match for commit $headrev found at $url" >&2
+	echo "warn: Are you sure you pushed '${remote:-HEAD}' there?" >&2
 	status=1
 fi
 
@@ -116,7 +124,7 @@ git show -s --format='The following changes since commit %H:
 
 are available in the git repository at:
 ' $merge_base &&
-echo "  $url $prettyhead" &&
+echo "  $url $remote" &&
 git show -s --format='
 for you to fetch changes up to %H:
 
-- 
1.9.rc0.10.gf0799f9.dirty
Next: Junio C Hamano
Message 1 of 13 in “Make request-pull able to take a refspec of form local:remote”
  1. 2/1 Make request-pull able to take a refspec of form local:remoteLinus Torvalds, Jan 23, 2014
  2. Junio C HamanoJan 23, 2014
  3. Linus TorvaldsJan 23, 2014
  4. Junio C HamanoJan 23, 2014
  5. Linus TorvaldsJan 23, 2014
  6. Junio C HamanoJan 24, 2014
  7. Re* [RFC PATCH 2/1] Make request-pull able to take a refspec of form local:remoteJunio C Hamano, Jan 29, 2014
  8. brian m. carlsonJan 30, 2014
  9. Linus TorvaldsJan 30, 2014
  10. Junio C HamanoFeb 25, 2014
  11. Junio C HamanoMar 12, 2014
  12. Eric SunshineMar 12, 2014
  13. Junio C HamanoMar 13, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.