Brandon Casey | 53dfac4 | 2010-06-01 19:13:41 -0500 | [diff] [blame] | 1 | #!/bin/sh |
Ryan Anderson | ab421d2 | 2005-07-26 03:30:36 -0400 | [diff] [blame] | 2 | # Copyright 2005, Ryan Anderson <ryan@michonline.com> |
| 3 | # |
| 4 | # This file is licensed under the GPL v2, or a later version |
| 5 | # at the discretion of Linus Torvalds. |
| 6 | |
freku045@student.liu.se | 806f36d | 2005-12-13 23:30:31 +0100 | [diff] [blame] | 7 | SUBDIRECTORY_OK='Yes' |
Jonathan Nieder | 50ab655 | 2010-04-24 07:15:37 -0500 | [diff] [blame] | 8 | OPTIONS_KEEPDASHDASH= |
Nicolas Vigier | 51ba8ce | 2014-02-01 02:17:59 +0000 | [diff] [blame] | 9 | OPTIONS_STUCKLONG= |
Junio C Hamano | 133cfae | 2009-07-27 14:27:47 -0700 | [diff] [blame] | 10 | OPTIONS_SPEC='git request-pull [options] start url [end] |
| 11 | -- |
| 12 | p show patch text as well |
| 13 | ' |
| 14 | |
freku045@student.liu.se | 806f36d | 2005-12-13 23:30:31 +0100 | [diff] [blame] | 15 | . git-sh-setup |
Ryan Anderson | ab421d2 | 2005-07-26 03:30:36 -0400 | [diff] [blame] | 16 | |
Michal Marek | 653a31c | 2009-07-01 11:40:30 +0200 | [diff] [blame] | 17 | GIT_PAGER= |
| 18 | export GIT_PAGER |
| 19 | |
Junio C Hamano | 133cfae | 2009-07-27 14:27:47 -0700 | [diff] [blame] | 20 | patch= |
| 21 | while case "$#" in 0) break ;; esac |
| 22 | do |
| 23 | case "$1" in |
| 24 | -p) |
| 25 | patch=-p ;; |
| 26 | --) |
| 27 | shift; break ;; |
| 28 | -*) |
| 29 | usage ;; |
| 30 | *) |
| 31 | break ;; |
| 32 | esac |
| 33 | shift |
| 34 | done |
| 35 | |
Linus Torvalds | 024d34c | 2014-01-22 12:32:30 -0800 | [diff] [blame] | 36 | base=$1 url=$2 status=0 |
Junio C Hamano | d050464 | 2011-11-09 05:05:00 -0800 | [diff] [blame] | 37 | |
Junio C Hamano | 3c9f1e7 | 2011-09-16 11:22:57 -0700 | [diff] [blame] | 38 | test -n "$base" && test -n "$url" || usage |
Dirk Wallenstein | ace33bf | 2013-07-17 19:28:11 +0200 | [diff] [blame] | 39 | |
| 40 | baserev=$(git rev-parse --verify --quiet "$base"^0) |
| 41 | if test -z "$baserev" |
| 42 | then |
| 43 | die "fatal: Not a valid revision: $base" |
| 44 | fi |
| 45 | |
Linus Torvalds | 024d34c | 2014-01-22 12:32:30 -0800 | [diff] [blame] | 46 | # |
| 47 | # $3 must be a symbolic ref, a unique ref, or |
Linus Torvalds | dc2eacc | 2014-01-22 15:23:48 -0800 | [diff] [blame] | 48 | # a SHA object expression. It can also be of |
| 49 | # the format 'local-name:remote-name'. |
Linus Torvalds | 024d34c | 2014-01-22 12:32:30 -0800 | [diff] [blame] | 50 | # |
Linus Torvalds | dc2eacc | 2014-01-22 15:23:48 -0800 | [diff] [blame] | 51 | local=${3%:*} |
| 52 | local=${local:-HEAD} |
| 53 | remote=${3#*:} |
Junio C Hamano | 5aae66b | 2014-02-25 13:44:46 -0800 | [diff] [blame] | 54 | pretty_remote=${remote#refs/} |
| 55 | pretty_remote=${pretty_remote#heads/} |
Linus Torvalds | dc2eacc | 2014-01-22 15:23:48 -0800 | [diff] [blame] | 56 | head=$(git symbolic-ref -q "$local") |
| 57 | head=${head:-$(git show-ref --heads --tags "$local" | cut -d' ' -f2)} |
| 58 | head=${head:-$(git rev-parse --quiet --verify "$local")} |
Linus Torvalds | 024d34c | 2014-01-22 12:32:30 -0800 | [diff] [blame] | 59 | |
| 60 | # None of the above? Bad. |
Linus Torvalds | dc2eacc | 2014-01-22 15:23:48 -0800 | [diff] [blame] | 61 | test -z "$head" && die "fatal: Not a valid revision: $local" |
Linus Torvalds | 024d34c | 2014-01-22 12:32:30 -0800 | [diff] [blame] | 62 | |
| 63 | # This also verifies that the resulting head is unique: |
| 64 | # "git show-ref" could have shown multiple matching refs.. |
Dirk Wallenstein | ace33bf | 2013-07-17 19:28:11 +0200 | [diff] [blame] | 65 | headrev=$(git rev-parse --verify --quiet "$head"^0) |
Linus Torvalds | dc2eacc | 2014-01-22 15:23:48 -0800 | [diff] [blame] | 66 | test -z "$headrev" && die "fatal: Ambiguous revision: $local" |
Linus Torvalds | 024d34c | 2014-01-22 12:32:30 -0800 | [diff] [blame] | 67 | |
Paolo Bonzini | 0454220 | 2019-05-28 12:15:43 +0200 | [diff] [blame] | 68 | local_sha1=$(git rev-parse --verify --quiet "$head") |
| 69 | |
Linus Torvalds | 024d34c | 2014-01-22 12:32:30 -0800 | [diff] [blame] | 70 | # Was it a branch with a description? |
| 71 | branch_name=${head#refs/heads/} |
| 72 | if test "z$branch_name" = "z$headref" || |
| 73 | ! git config "branch.$branch_name.description" >/dev/null |
Dirk Wallenstein | ace33bf | 2013-07-17 19:28:11 +0200 | [diff] [blame] | 74 | then |
Linus Torvalds | 024d34c | 2014-01-22 12:32:30 -0800 | [diff] [blame] | 75 | branch_name= |
Dirk Wallenstein | ace33bf | 2013-07-17 19:28:11 +0200 | [diff] [blame] | 76 | fi |
Ryan Anderson | ab421d2 | 2005-07-26 03:30:36 -0400 | [diff] [blame] | 77 | |
Junio C Hamano | 3c9f1e7 | 2011-09-16 11:22:57 -0700 | [diff] [blame] | 78 | merge_base=$(git merge-base $baserev $headrev) || |
Shawn O. Pearce | ff06c74 | 2007-05-01 02:08:23 -0400 | [diff] [blame] | 79 | die "fatal: No commits in common between $base and $head" |
| 80 | |
Linus Torvalds | 024d34c | 2014-01-22 12:32:30 -0800 | [diff] [blame] | 81 | # $head is the refname from the command line. |
Paolo Bonzini | 0454220 | 2019-05-28 12:15:43 +0200 | [diff] [blame] | 82 | # Find a ref with the same name as $head that exists at the remote |
| 83 | # and points to the same commit as the local object. |
Junio C Hamano | fe46fa9 | 2011-12-16 09:00:11 -0800 | [diff] [blame] | 84 | find_matching_ref=' |
Linus Torvalds | dc2eacc | 2014-01-22 15:23:48 -0800 | [diff] [blame] | 85 | my ($head,$headrev) = (@ARGV); |
Paolo Bonzini | 5731dfc | 2019-05-28 12:15:42 +0200 | [diff] [blame] | 86 | my $pattern = qr{/\Q$head\E$}; |
Paolo Bonzini | 0454220 | 2019-05-28 12:15:43 +0200 | [diff] [blame] | 87 | my ($remote_sha1, $found); |
Junio C Hamano | fe46fa9 | 2011-12-16 09:00:11 -0800 | [diff] [blame] | 88 | |
Junio C Hamano | fe46fa9 | 2011-12-16 09:00:11 -0800 | [diff] [blame] | 89 | while (<STDIN>) { |
Linus Torvalds | dc2eacc | 2014-01-22 15:23:48 -0800 | [diff] [blame] | 90 | chomp; |
Linus Torvalds | 024d34c | 2014-01-22 12:32:30 -0800 | [diff] [blame] | 91 | my ($sha1, $ref, $deref) = /^(\S+)\s+([^^]+)(\S*)$/; |
Linus Torvalds | dc2eacc | 2014-01-22 15:23:48 -0800 | [diff] [blame] | 92 | |
Linus Torvalds | dc2eacc | 2014-01-22 15:23:48 -0800 | [diff] [blame] | 93 | if ($sha1 eq $head) { |
Paolo Bonzini | 0454220 | 2019-05-28 12:15:43 +0200 | [diff] [blame] | 94 | $found = $remote_sha1 = $sha1; |
| 95 | break; |
| 96 | } |
| 97 | |
| 98 | if ($ref eq $head || $ref =~ $pattern) { |
| 99 | if ($deref eq "") { |
| 100 | # Remember the matching object on the remote side |
| 101 | $remote_sha1 = $sha1; |
| 102 | } |
| 103 | if ($sha1 eq $headrev) { |
| 104 | $found = $ref; |
| 105 | break; |
| 106 | } |
Junio C Hamano | 682853e | 2012-06-01 12:38:19 -0700 | [diff] [blame] | 107 | } |
Junio C Hamano | fe46fa9 | 2011-12-16 09:00:11 -0800 | [diff] [blame] | 108 | } |
Linus Torvalds | dc2eacc | 2014-01-22 15:23:48 -0800 | [diff] [blame] | 109 | if ($found) { |
Paolo Bonzini | 0454220 | 2019-05-28 12:15:43 +0200 | [diff] [blame] | 110 | $remote_sha1 = $headrev if ! defined $remote_sha1; |
| 111 | print "$remote_sha1 $found\n"; |
Junio C Hamano | fe46fa9 | 2011-12-16 09:00:11 -0800 | [diff] [blame] | 112 | } |
| 113 | ' |
| 114 | |
Paolo Bonzini | 0454220 | 2019-05-28 12:15:43 +0200 | [diff] [blame] | 115 | set fnord $(git ls-remote "$url" | @@PERL@@ -e "$find_matching_ref" "${remote:-HEAD}" "$headrev") |
| 116 | remote_sha1=$2 |
| 117 | ref=$3 |
Linus Torvalds | 024d34c | 2014-01-22 12:32:30 -0800 | [diff] [blame] | 118 | |
| 119 | if test -z "$ref" |
| 120 | then |
Linus Torvalds | dc2eacc | 2014-01-22 15:23:48 -0800 | [diff] [blame] | 121 | echo "warn: No match for commit $headrev found at $url" >&2 |
| 122 | echo "warn: Are you sure you pushed '${remote:-HEAD}' there?" >&2 |
Linus Torvalds | 024d34c | 2014-01-22 12:32:30 -0800 | [diff] [blame] | 123 | status=1 |
Paolo Bonzini | 0454220 | 2019-05-28 12:15:43 +0200 | [diff] [blame] | 124 | elif test "$local_sha1" != "$remote_sha1" |
| 125 | then |
| 126 | echo "warn: $head found at $url but points to a different object" >&2 |
| 127 | echo "warn: Are you sure you pushed '${remote:-HEAD}' there?" >&2 |
| 128 | status=1 |
Linus Torvalds | 024d34c | 2014-01-22 12:32:30 -0800 | [diff] [blame] | 129 | fi |
Junio C Hamano | fe46fa9 | 2011-12-16 09:00:11 -0800 | [diff] [blame] | 130 | |
Junio C Hamano | d952cbb | 2014-05-16 10:18:25 -0700 | [diff] [blame] | 131 | # Special case: turn "for_linus" to "tags/for_linus" when it is correct |
| 132 | if test "$ref" = "refs/tags/$pretty_remote" |
| 133 | then |
| 134 | pretty_remote=tags/$pretty_remote |
| 135 | fi |
| 136 | |
Uwe Kleine-König | 1a92777 | 2011-03-01 10:21:37 +0100 | [diff] [blame] | 137 | url=$(git ls-remote --get-url "$url") |
Shawn O. Pearce | ff06c74 | 2007-05-01 02:08:23 -0400 | [diff] [blame] | 138 | |
Miklos Vajna | 10eb000 | 2010-01-29 15:17:59 +0100 | [diff] [blame] | 139 | git show -s --format='The following changes since commit %H: |
Ryan Anderson | ab421d2 | 2005-07-26 03:30:36 -0400 | [diff] [blame] | 140 | |
Miklos Vajna | 10eb000 | 2010-01-29 15:17:59 +0100 | [diff] [blame] | 141 | %s (%ci) |
| 142 | |
Ann T Ropea | e66d7c3 | 2017-10-03 00:08:38 +0000 | [diff] [blame] | 143 | are available in the Git repository at: |
Junio C Hamano | b7e642e | 2012-01-10 21:45:52 -0800 | [diff] [blame] | 144 | ' $merge_base && |
Junio C Hamano | 5aae66b | 2014-02-25 13:44:46 -0800 | [diff] [blame] | 145 | echo " $url $pretty_remote" && |
Junio C Hamano | cf73166 | 2011-09-16 11:37:08 -0700 | [diff] [blame] | 146 | git show -s --format=' |
| 147 | for you to fetch changes up to %H: |
| 148 | |
| 149 | %s (%ci) |
| 150 | |
| 151 | ----------------------------------------------------------------' $headrev && |
Ryan Anderson | ab421d2 | 2005-07-26 03:30:36 -0400 | [diff] [blame] | 152 | |
Junio C Hamano | 4b14ec8 | 2014-01-29 15:08:05 -0800 | [diff] [blame] | 153 | if test $(git cat-file -t "$head") = tag |
| 154 | then |
| 155 | git cat-file tag "$head" | |
| 156 | sed -n -e '1,/^$/d' -e '/^-----BEGIN PGP /q' -e p |
| 157 | echo |
| 158 | echo "----------------------------------------------------------------" |
| 159 | fi && |
| 160 | |
Junio C Hamano | c016814 | 2011-09-20 15:52:57 -0700 | [diff] [blame] | 161 | if test -n "$branch_name" |
| 162 | then |
Junio C Hamano | fe46fa9 | 2011-12-16 09:00:11 -0800 | [diff] [blame] | 163 | echo "(from the branch description for $branch_name local branch)" |
Junio C Hamano | c016814 | 2011-09-20 15:52:57 -0700 | [diff] [blame] | 164 | echo |
| 165 | git config "branch.$branch_name.description" |
| 166 | echo "----------------------------------------------------------------" |
| 167 | fi && |
Junio C Hamano | d050464 | 2011-11-09 05:05:00 -0800 | [diff] [blame] | 168 | |
Brandon Casey | 53dfac4 | 2010-06-01 19:13:41 -0500 | [diff] [blame] | 169 | git shortlog ^$baserev $headrev && |
Junio C Hamano | cf73166 | 2011-09-16 11:37:08 -0700 | [diff] [blame] | 170 | git diff -M --stat --summary $patch $merge_base..$headrev || status=1 |
| 171 | |
Shawn O. Pearce | ff06c74 | 2007-05-01 02:08:23 -0400 | [diff] [blame] | 172 | exit $status |