1#!/bin/sh 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 7USAGE='<start> <url> [<end>]' 8LONG_USAGE='Summarizes the changes between two commits to the standard output, 9and includes the given URL in the generated summary.' 10SUBDIRECTORY_OK='Yes' 11OPTIONS_KEEPDASHDASH= 12OPTIONS_SPEC='git request-pull [options] start url [end] 13-- 14p show patch text as well 15' 16 17. git-sh-setup 18 19GIT_PAGER= 20export GIT_PAGER 21 22patch= 23while case"$#"in0)break;;esac 24do 25case"$1"in 26-p) 27patch=-p;; 28--) 29shift;break;; 30-*) 31 usage ;; 32*) 33break;; 34esac 35shift 36done 37 38base=$1 url=$2 status=0 39 40test -n"$base"&&test -n"$url"|| usage 41 42baserev=$(git rev-parse --verify --quiet "$base"^0) 43iftest -z"$baserev" 44then 45 die "fatal: Not a valid revision:$base" 46fi 47 48# 49# $3 must be a symbolic ref, a unique ref, or 50# a SHA object expression 51# 52head=$(git symbolic-ref -q "${3-HEAD}") 53head=${head:-$(git show-ref "${3-HEAD}" | cut -d' ' -f2)} 54head=${head:-$(git rev-parse --quiet --verify "$3")} 55 56# None of the above? Bad. 57test -z"$head"&& die "fatal: Not a valid revision:$3" 58 59# This also verifies that the resulting head is unique: 60# "git show-ref" could have shown multiple matching refs.. 61headrev=$(git rev-parse --verify --quiet "$head"^0) 62test -z"$headrev"&& die "fatal: Ambiguous revision:$3" 63 64# Was it a branch with a description? 65branch_name=${head#refs/heads/} 66iftest"z$branch_name"="z$headref"|| 67! git config "branch.$branch_name.description">/dev/null 68then 69 branch_name= 70fi 71 72prettyhead=${head#refs/} 73prettyhead=${prettyhead#heads/} 74 75merge_base=$(git merge-base $baserev $headrev)|| 76die "fatal: No commits in common between$baseand$head" 77 78# $head is the refname from the command line. 79# If a ref with the same name as $head exists at the remote 80# and their values match, use that. 81# 82# Otherwise find a random ref that matches $headrev. 83find_matching_ref=' 84 my ($exact,$found); 85 while (<STDIN>) { 86 my ($sha1,$ref,$deref) = /^(\S+)\s+([^^]+)(\S*)$/; 87 next unless ($sha1eq$ARGV[1]); 88 if ($refeq$ARGV[0]) { 89$exact=$ref; 90 } 91 if ($sha1eq$ARGV[0]) { 92$found=$sha1; 93 } 94 } 95 if ($exact) { 96 print "$exact\n"; 97 } elsif ($found) { 98 print "$found\n"; 99 } 100' 101 102ref=$(git ls-remote "$url" | @@PERL@@ -e "$find_matching_ref" "$head" "$headrev") 103 104iftest -z"$ref" 105then 106echo"warn: No match for$prettyheadfound at$url">&2 107echo"warn: Are you sure you pushed '$prettyhead' there?">&2 108 status=1 109fi 110 111url=$(git ls-remote --get-url "$url") 112 113git show -s --format='The following changes since commit %H: 114 115 %s (%ci) 116 117are available in the git repository at: 118'$merge_base&& 119echo"$url$prettyhead"&& 120git show -s --format=' 121for you to fetch changes up to %H: 122 123 %s (%ci) 124 125----------------------------------------------------------------'$headrev&& 126 127iftest -n"$branch_name" 128then 129echo"(from the branch description for$branch_namelocal branch)" 130echo 131 git config "branch.$branch_name.description" 132echo"----------------------------------------------------------------" 133fi&& 134 135git shortlog ^$baserev $headrev&& 136git diff-M --stat --summary$patch $merge_base..$headrev|| status=1 137 138exit$status