blob: 2d0e44656cc6ca4cc0cd8b579a1ebd8798e90b5f [file] [log] [blame]
Brandon Casey53dfac42010-06-01 19:13:41 -05001#!/bin/sh
Ryan Andersonab421d22005-07-26 03:30:36 -04002# 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.se806f36d2005-12-13 23:30:31 +01007SUBDIRECTORY_OK='Yes'
Jonathan Nieder50ab6552010-04-24 07:15:37 -05008OPTIONS_KEEPDASHDASH=
Nicolas Vigier51ba8ce2014-02-01 02:17:59 +00009OPTIONS_STUCKLONG=
Junio C Hamano133cfae2009-07-27 14:27:47 -070010OPTIONS_SPEC='git request-pull [options] start url [end]
11--
12p show patch text as well
13'
14
freku045@student.liu.se806f36d2005-12-13 23:30:31 +010015. git-sh-setup
Ryan Andersonab421d22005-07-26 03:30:36 -040016
Michal Marek653a31c2009-07-01 11:40:30 +020017GIT_PAGER=
18export GIT_PAGER
19
Junio C Hamano133cfae2009-07-27 14:27:47 -070020patch=
21while case "$#" in 0) break ;; esac
22do
23 case "$1" in
24 -p)
25 patch=-p ;;
26 --)
27 shift; break ;;
28 -*)
29 usage ;;
30 *)
31 break ;;
32 esac
33 shift
34done
35
Linus Torvalds024d34c2014-01-22 12:32:30 -080036base=$1 url=$2 status=0
Junio C Hamanod0504642011-11-09 05:05:00 -080037
Junio C Hamano3c9f1e72011-09-16 11:22:57 -070038test -n "$base" && test -n "$url" || usage
Dirk Wallensteinace33bf2013-07-17 19:28:11 +020039
40baserev=$(git rev-parse --verify --quiet "$base"^0)
41if test -z "$baserev"
42then
43 die "fatal: Not a valid revision: $base"
44fi
45
Linus Torvalds024d34c2014-01-22 12:32:30 -080046#
47# $3 must be a symbolic ref, a unique ref, or
Linus Torvaldsdc2eacc2014-01-22 15:23:48 -080048# a SHA object expression. It can also be of
49# the format 'local-name:remote-name'.
Linus Torvalds024d34c2014-01-22 12:32:30 -080050#
Linus Torvaldsdc2eacc2014-01-22 15:23:48 -080051local=${3%:*}
52local=${local:-HEAD}
53remote=${3#*:}
Junio C Hamano5aae66b2014-02-25 13:44:46 -080054pretty_remote=${remote#refs/}
55pretty_remote=${pretty_remote#heads/}
Linus Torvaldsdc2eacc2014-01-22 15:23:48 -080056head=$(git symbolic-ref -q "$local")
57head=${head:-$(git show-ref --heads --tags "$local" | cut -d' ' -f2)}
58head=${head:-$(git rev-parse --quiet --verify "$local")}
Linus Torvalds024d34c2014-01-22 12:32:30 -080059
60# None of the above? Bad.
Linus Torvaldsdc2eacc2014-01-22 15:23:48 -080061test -z "$head" && die "fatal: Not a valid revision: $local"
Linus Torvalds024d34c2014-01-22 12:32:30 -080062
63# This also verifies that the resulting head is unique:
64# "git show-ref" could have shown multiple matching refs..
Dirk Wallensteinace33bf2013-07-17 19:28:11 +020065headrev=$(git rev-parse --verify --quiet "$head"^0)
Linus Torvaldsdc2eacc2014-01-22 15:23:48 -080066test -z "$headrev" && die "fatal: Ambiguous revision: $local"
Linus Torvalds024d34c2014-01-22 12:32:30 -080067
Paolo Bonzini04542202019-05-28 12:15:43 +020068local_sha1=$(git rev-parse --verify --quiet "$head")
69
Linus Torvalds024d34c2014-01-22 12:32:30 -080070# Was it a branch with a description?
71branch_name=${head#refs/heads/}
72if test "z$branch_name" = "z$headref" ||
73 ! git config "branch.$branch_name.description" >/dev/null
Dirk Wallensteinace33bf2013-07-17 19:28:11 +020074then
Linus Torvalds024d34c2014-01-22 12:32:30 -080075 branch_name=
Dirk Wallensteinace33bf2013-07-17 19:28:11 +020076fi
Ryan Andersonab421d22005-07-26 03:30:36 -040077
Junio C Hamano3c9f1e72011-09-16 11:22:57 -070078merge_base=$(git merge-base $baserev $headrev) ||
Shawn O. Pearceff06c742007-05-01 02:08:23 -040079die "fatal: No commits in common between $base and $head"
80
Linus Torvalds024d34c2014-01-22 12:32:30 -080081# $head is the refname from the command line.
Paolo Bonzini04542202019-05-28 12:15:43 +020082# 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 Hamanofe46fa92011-12-16 09:00:11 -080084find_matching_ref='
Linus Torvaldsdc2eacc2014-01-22 15:23:48 -080085 my ($head,$headrev) = (@ARGV);
Paolo Bonzini5731dfc2019-05-28 12:15:42 +020086 my $pattern = qr{/\Q$head\E$};
Paolo Bonzini04542202019-05-28 12:15:43 +020087 my ($remote_sha1, $found);
Junio C Hamanofe46fa92011-12-16 09:00:11 -080088
Junio C Hamanofe46fa92011-12-16 09:00:11 -080089 while (<STDIN>) {
Linus Torvaldsdc2eacc2014-01-22 15:23:48 -080090 chomp;
Linus Torvalds024d34c2014-01-22 12:32:30 -080091 my ($sha1, $ref, $deref) = /^(\S+)\s+([^^]+)(\S*)$/;
Linus Torvaldsdc2eacc2014-01-22 15:23:48 -080092
Linus Torvaldsdc2eacc2014-01-22 15:23:48 -080093 if ($sha1 eq $head) {
Paolo Bonzini04542202019-05-28 12:15:43 +020094 $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 Hamano682853e2012-06-01 12:38:19 -0700107 }
Junio C Hamanofe46fa92011-12-16 09:00:11 -0800108 }
Linus Torvaldsdc2eacc2014-01-22 15:23:48 -0800109 if ($found) {
Paolo Bonzini04542202019-05-28 12:15:43 +0200110 $remote_sha1 = $headrev if ! defined $remote_sha1;
111 print "$remote_sha1 $found\n";
Junio C Hamanofe46fa92011-12-16 09:00:11 -0800112 }
113'
114
Paolo Bonzini04542202019-05-28 12:15:43 +0200115set fnord $(git ls-remote "$url" | @@PERL@@ -e "$find_matching_ref" "${remote:-HEAD}" "$headrev")
116remote_sha1=$2
117ref=$3
Linus Torvalds024d34c2014-01-22 12:32:30 -0800118
119if test -z "$ref"
120then
Linus Torvaldsdc2eacc2014-01-22 15:23:48 -0800121 echo "warn: No match for commit $headrev found at $url" >&2
122 echo "warn: Are you sure you pushed '${remote:-HEAD}' there?" >&2
Linus Torvalds024d34c2014-01-22 12:32:30 -0800123 status=1
Paolo Bonzini04542202019-05-28 12:15:43 +0200124elif test "$local_sha1" != "$remote_sha1"
125then
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 Torvalds024d34c2014-01-22 12:32:30 -0800129fi
Junio C Hamanofe46fa92011-12-16 09:00:11 -0800130
Junio C Hamanod952cbb2014-05-16 10:18:25 -0700131# Special case: turn "for_linus" to "tags/for_linus" when it is correct
132if test "$ref" = "refs/tags/$pretty_remote"
133then
134 pretty_remote=tags/$pretty_remote
135fi
136
Uwe Kleine-König1a927772011-03-01 10:21:37 +0100137url=$(git ls-remote --get-url "$url")
Shawn O. Pearceff06c742007-05-01 02:08:23 -0400138
Miklos Vajna10eb0002010-01-29 15:17:59 +0100139git show -s --format='The following changes since commit %H:
Ryan Andersonab421d22005-07-26 03:30:36 -0400140
Miklos Vajna10eb0002010-01-29 15:17:59 +0100141 %s (%ci)
142
Ann T Ropeae66d7c32017-10-03 00:08:38 +0000143are available in the Git repository at:
Junio C Hamanob7e642e2012-01-10 21:45:52 -0800144' $merge_base &&
Junio C Hamano5aae66b2014-02-25 13:44:46 -0800145echo " $url $pretty_remote" &&
Junio C Hamanocf731662011-09-16 11:37:08 -0700146git show -s --format='
147for you to fetch changes up to %H:
148
149 %s (%ci)
150
151----------------------------------------------------------------' $headrev &&
Ryan Andersonab421d22005-07-26 03:30:36 -0400152
Junio C Hamano4b14ec82014-01-29 15:08:05 -0800153if test $(git cat-file -t "$head") = tag
154then
155 git cat-file tag "$head" |
156 sed -n -e '1,/^$/d' -e '/^-----BEGIN PGP /q' -e p
157 echo
158 echo "----------------------------------------------------------------"
159fi &&
160
Junio C Hamanoc0168142011-09-20 15:52:57 -0700161if test -n "$branch_name"
162then
Junio C Hamanofe46fa92011-12-16 09:00:11 -0800163 echo "(from the branch description for $branch_name local branch)"
Junio C Hamanoc0168142011-09-20 15:52:57 -0700164 echo
165 git config "branch.$branch_name.description"
166 echo "----------------------------------------------------------------"
167fi &&
Junio C Hamanod0504642011-11-09 05:05:00 -0800168
Brandon Casey53dfac42010-06-01 19:13:41 -0500169git shortlog ^$baserev $headrev &&
Junio C Hamanocf731662011-09-16 11:37:08 -0700170git diff -M --stat --summary $patch $merge_base..$headrev || status=1
171
Shawn O. Pearceff06c742007-05-01 02:08:23 -0400172exit $status