blob: d5500fde4658410db477008617730cb5799f310e [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
Stefan Naewe3eb91bf2008-11-17 09:57:19 +01007USAGE='<start> <url> [<end>]'
8LONG_USAGE='Summarizes the changes between two commits to the standard output,
9and includes the given URL in the generated summary.'
freku045@student.liu.se806f36d2005-12-13 23:30:31 +010010SUBDIRECTORY_OK='Yes'
Jonathan Nieder50ab6552010-04-24 07:15:37 -050011OPTIONS_KEEPDASHDASH=
Nicolas Vigier51ba8ce2014-02-01 02:17:59 +000012OPTIONS_STUCKLONG=
Junio C Hamano133cfae2009-07-27 14:27:47 -070013OPTIONS_SPEC='git request-pull [options] start url [end]
14--
15p show patch text as well
16'
17
freku045@student.liu.se806f36d2005-12-13 23:30:31 +010018. git-sh-setup
Ryan Andersonab421d22005-07-26 03:30:36 -040019
Michal Marek653a31c2009-07-01 11:40:30 +020020GIT_PAGER=
21export GIT_PAGER
22
Junio C Hamano133cfae2009-07-27 14:27:47 -070023patch=
24while case "$#" in 0) break ;; esac
25do
26 case "$1" in
27 -p)
28 patch=-p ;;
29 --)
30 shift; break ;;
31 -*)
32 usage ;;
33 *)
34 break ;;
35 esac
36 shift
37done
38
Linus Torvalds024d34c2014-01-22 12:32:30 -080039base=$1 url=$2 status=0
Junio C Hamanod0504642011-11-09 05:05:00 -080040
Junio C Hamano3c9f1e72011-09-16 11:22:57 -070041test -n "$base" && test -n "$url" || usage
Dirk Wallensteinace33bf2013-07-17 19:28:11 +020042
43baserev=$(git rev-parse --verify --quiet "$base"^0)
44if test -z "$baserev"
45then
46 die "fatal: Not a valid revision: $base"
47fi
48
Linus Torvalds024d34c2014-01-22 12:32:30 -080049#
50# $3 must be a symbolic ref, a unique ref, or
Linus Torvaldsdc2eacc2014-01-22 15:23:48 -080051# a SHA object expression. It can also be of
52# the format 'local-name:remote-name'.
Linus Torvalds024d34c2014-01-22 12:32:30 -080053#
Linus Torvaldsdc2eacc2014-01-22 15:23:48 -080054local=${3%:*}
55local=${local:-HEAD}
56remote=${3#*:}
Junio C Hamano5aae66b2014-02-25 13:44:46 -080057pretty_remote=${remote#refs/}
58pretty_remote=${pretty_remote#heads/}
Linus Torvaldsdc2eacc2014-01-22 15:23:48 -080059head=$(git symbolic-ref -q "$local")
60head=${head:-$(git show-ref --heads --tags "$local" | cut -d' ' -f2)}
61head=${head:-$(git rev-parse --quiet --verify "$local")}
Linus Torvalds024d34c2014-01-22 12:32:30 -080062
63# None of the above? Bad.
Linus Torvaldsdc2eacc2014-01-22 15:23:48 -080064test -z "$head" && die "fatal: Not a valid revision: $local"
Linus Torvalds024d34c2014-01-22 12:32:30 -080065
66# This also verifies that the resulting head is unique:
67# "git show-ref" could have shown multiple matching refs..
Dirk Wallensteinace33bf2013-07-17 19:28:11 +020068headrev=$(git rev-parse --verify --quiet "$head"^0)
Linus Torvaldsdc2eacc2014-01-22 15:23:48 -080069test -z "$headrev" && die "fatal: Ambiguous revision: $local"
Linus Torvalds024d34c2014-01-22 12:32:30 -080070
71# Was it a branch with a description?
72branch_name=${head#refs/heads/}
73if test "z$branch_name" = "z$headref" ||
74 ! git config "branch.$branch_name.description" >/dev/null
Dirk Wallensteinace33bf2013-07-17 19:28:11 +020075then
Linus Torvalds024d34c2014-01-22 12:32:30 -080076 branch_name=
Dirk Wallensteinace33bf2013-07-17 19:28:11 +020077fi
Ryan Andersonab421d22005-07-26 03:30:36 -040078
Junio C Hamano3c9f1e72011-09-16 11:22:57 -070079merge_base=$(git merge-base $baserev $headrev) ||
Shawn O. Pearceff06c742007-05-01 02:08:23 -040080die "fatal: No commits in common between $base and $head"
81
Linus Torvalds024d34c2014-01-22 12:32:30 -080082# $head is the refname from the command line.
83# If a ref with the same name as $head exists at the remote
84# and their values match, use that.
Junio C Hamano682853e2012-06-01 12:38:19 -070085#
86# Otherwise find a random ref that matches $headrev.
Junio C Hamanofe46fa92011-12-16 09:00:11 -080087find_matching_ref='
Linus Torvaldsdc2eacc2014-01-22 15:23:48 -080088 my ($head,$headrev) = (@ARGV);
89 my ($found);
Junio C Hamanofe46fa92011-12-16 09:00:11 -080090
Junio C Hamanofe46fa92011-12-16 09:00:11 -080091 while (<STDIN>) {
Linus Torvaldsdc2eacc2014-01-22 15:23:48 -080092 chomp;
Linus Torvalds024d34c2014-01-22 12:32:30 -080093 my ($sha1, $ref, $deref) = /^(\S+)\s+([^^]+)(\S*)$/;
Linus Torvaldsdc2eacc2014-01-22 15:23:48 -080094 my ($pattern);
95 next unless ($sha1 eq $headrev);
96
97 $pattern="/$head\$";
98 if ($ref eq $head) {
99 $found = $ref;
Junio C Hamanofe46fa92011-12-16 09:00:11 -0800100 }
Linus Torvaldsdc2eacc2014-01-22 15:23:48 -0800101 if ($ref =~ /$pattern/) {
102 $found = $ref;
103 }
104 if ($sha1 eq $head) {
Linus Torvalds024d34c2014-01-22 12:32:30 -0800105 $found = $sha1;
Junio C Hamano682853e2012-06-01 12:38:19 -0700106 }
Junio C Hamanofe46fa92011-12-16 09:00:11 -0800107 }
Linus Torvaldsdc2eacc2014-01-22 15:23:48 -0800108 if ($found) {
Junio C Hamanofe46fa92011-12-16 09:00:11 -0800109 print "$found\n";
110 }
111'
112
Linus Torvaldsdc2eacc2014-01-22 15:23:48 -0800113ref=$(git ls-remote "$url" | @@PERL@@ -e "$find_matching_ref" "${remote:-HEAD}" "$headrev")
Linus Torvalds024d34c2014-01-22 12:32:30 -0800114
115if test -z "$ref"
116then
Linus Torvaldsdc2eacc2014-01-22 15:23:48 -0800117 echo "warn: No match for commit $headrev found at $url" >&2
118 echo "warn: Are you sure you pushed '${remote:-HEAD}' there?" >&2
Linus Torvalds024d34c2014-01-22 12:32:30 -0800119 status=1
120fi
Junio C Hamanofe46fa92011-12-16 09:00:11 -0800121
Junio C Hamanod952cbb2014-05-16 10:18:25 -0700122# Special case: turn "for_linus" to "tags/for_linus" when it is correct
123if test "$ref" = "refs/tags/$pretty_remote"
124then
125 pretty_remote=tags/$pretty_remote
126fi
127
Uwe Kleine-König1a927772011-03-01 10:21:37 +0100128url=$(git ls-remote --get-url "$url")
Shawn O. Pearceff06c742007-05-01 02:08:23 -0400129
Miklos Vajna10eb0002010-01-29 15:17:59 +0100130git show -s --format='The following changes since commit %H:
Ryan Andersonab421d22005-07-26 03:30:36 -0400131
Miklos Vajna10eb0002010-01-29 15:17:59 +0100132 %s (%ci)
133
Junio C Hamanocf731662011-09-16 11:37:08 -0700134are available in the git repository at:
Junio C Hamanob7e642e2012-01-10 21:45:52 -0800135' $merge_base &&
Junio C Hamano5aae66b2014-02-25 13:44:46 -0800136echo " $url $pretty_remote" &&
Junio C Hamanocf731662011-09-16 11:37:08 -0700137git show -s --format='
138for you to fetch changes up to %H:
139
140 %s (%ci)
141
142----------------------------------------------------------------' $headrev &&
Ryan Andersonab421d22005-07-26 03:30:36 -0400143
Junio C Hamano4b14ec82014-01-29 15:08:05 -0800144if test $(git cat-file -t "$head") = tag
145then
146 git cat-file tag "$head" |
147 sed -n -e '1,/^$/d' -e '/^-----BEGIN PGP /q' -e p
148 echo
149 echo "----------------------------------------------------------------"
150fi &&
151
Junio C Hamanoc0168142011-09-20 15:52:57 -0700152if test -n "$branch_name"
153then
Junio C Hamanofe46fa92011-12-16 09:00:11 -0800154 echo "(from the branch description for $branch_name local branch)"
Junio C Hamanoc0168142011-09-20 15:52:57 -0700155 echo
156 git config "branch.$branch_name.description"
157 echo "----------------------------------------------------------------"
158fi &&
Junio C Hamanod0504642011-11-09 05:05:00 -0800159
Brandon Casey53dfac42010-06-01 19:13:41 -0500160git shortlog ^$baserev $headrev &&
Junio C Hamanocf731662011-09-16 11:37:08 -0700161git diff -M --stat --summary $patch $merge_base..$headrev || status=1
162
Shawn O. Pearceff06c742007-05-01 02:08:23 -0400163exit $status