Git fork
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
7SUBDIRECTORY_OK='Yes'
8OPTIONS_KEEPDASHDASH=
9OPTIONS_STUCKLONG=
10OPTIONS_SPEC='git request-pull [options] start url [end]
11--
12p show patch text as well
13'
14
15. git-sh-setup
16
17GIT_PAGER=
18export GIT_PAGER
19
20patch=
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
36base=$1 url=$2 status=0
37
38test -n "$base" && test -n "$url" || usage
39
40baserev=$(git rev-parse --verify --quiet "$base"^0)
41if test -z "$baserev"
42then
43 die "fatal: Not a valid revision: $base"
44fi
45
46#
47# $3 must be a symbolic ref, a unique ref, or
48# a SHA object expression. It can also be of
49# the format 'local-name:remote-name'.
50#
51local=${3%:*}
52local=${local:-HEAD}
53remote=${3#*:}
54pretty_remote=${remote#refs/}
55pretty_remote=${pretty_remote#heads/}
56head=$(git symbolic-ref -q "$local")
57head=${head:-$(git show-ref --heads --tags "$local" | cut -d' ' -f2)}
58head=${head:-$(git rev-parse --quiet --verify "$local")}
59
60# None of the above? Bad.
61test -z "$head" && die "fatal: Not a valid revision: $local"
62
63# This also verifies that the resulting head is unique:
64# "git show-ref" could have shown multiple matching refs..
65headrev=$(git rev-parse --verify --quiet "$head"^0)
66test -z "$headrev" && die "fatal: Ambiguous revision: $local"
67
68local_sha1=$(git rev-parse --verify --quiet "$head")
69
70# 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
74then
75 branch_name=
76fi
77
78merge_base=$(git merge-base $baserev $headrev) ||
79die "fatal: No commits in common between $base and $head"
80
81find_matching_ref () {
82 while read sha1 ref
83 do
84 case "$ref" in
85 *"^"?*)
86 ref="${ref%"^"*}"
87 deref=true
88 ;;
89 *)
90 deref=
91 ;;
92 esac
93
94 if test "$sha1" = "${remote:-HEAD}"
95 then
96 echo "$sha1 $sha1"
97 break
98 fi
99
100 case "$ref" in
101 "${remote:-HEAD}"|*"/${remote:-HEAD}")
102 if test -z "$deref"
103 then
104 # Remember the matching unpeeled object on the
105 # remote side.
106 remote_sha1="$sha1"
107 fi
108
109 if test "$sha1" = "$headrev"
110 then
111 echo "${remote_sha1:-$headrev} $ref"
112 break
113 fi
114 ;;
115 esac
116 done
117}
118
119# Find a ref with the same name as $remote that exists at the remote
120# and points to the same commit as the local object.
121set fnord $(git ls-remote "$url" | find_matching_ref)
122remote_sha1=$2
123ref=$3
124
125if test -z "$ref"
126then
127 echo "warn: No match for commit $headrev found at $url" >&2
128 echo "warn: Are you sure you pushed '${remote:-HEAD}' there?" >&2
129 status=1
130elif test "$local_sha1" != "$remote_sha1"
131then
132 echo "warn: $head found at $url but points to a different object" >&2
133 echo "warn: Are you sure you pushed '${remote:-HEAD}' there?" >&2
134 status=1
135fi
136
137# Special case: turn "for_linus" to "tags/for_linus" when it is correct
138if test "$ref" = "refs/tags/$pretty_remote"
139then
140 pretty_remote=tags/$pretty_remote
141fi
142
143url=$(git ls-remote --get-url "$url")
144
145git show -s --format='The following changes since commit %H:
146
147 %s (%ci)
148
149are available in the Git repository at:
150' $merge_base &&
151echo " $url $pretty_remote" &&
152git show -s --format='
153for you to fetch changes up to %H:
154
155 %s (%ci)
156
157----------------------------------------------------------------' $headrev &&
158
159if test $(git cat-file -t "$head") = tag
160then
161 git cat-file tag "$head" |
162 sed -n -e '1,/^$/d' -e '/^-----BEGIN \(PGP\|SSH\|SIGNED\) /q' -e p
163 echo
164 echo "----------------------------------------------------------------"
165fi &&
166
167if test -n "$branch_name"
168then
169 echo "(from the branch description for $branch_name local branch)"
170 echo
171 git config "branch.$branch_name.description"
172 echo "----------------------------------------------------------------"
173fi &&
174
175git shortlog ^$baserev $headrev &&
176git diff -M --stat --summary $patch $merge_base..$headrev || status=1
177
178exit $status