]>
Commit | Line | Data |
---|---|---|
53dfac44 | 1 | #!/bin/sh |
ab421d2c RA |
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 | ||
806f36d4 | 7 | SUBDIRECTORY_OK='Yes' |
50ab6558 | 8 | OPTIONS_KEEPDASHDASH= |
51ba8ce3 | 9 | OPTIONS_STUCKLONG= |
133cfaeb JH |
10 | OPTIONS_SPEC='git request-pull [options] start url [end] |
11 | -- | |
12 | p show patch text as well | |
13 | ' | |
14 | ||
806f36d4 | 15 | . git-sh-setup |
ab421d2c | 16 | |
653a31c1 MM |
17 | GIT_PAGER= |
18 | export GIT_PAGER | |
19 | ||
133cfaeb JH |
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 | ||
024d34cb | 36 | base=$1 url=$2 status=0 |
d0504645 | 37 | |
3c9f1e7c | 38 | test -n "$base" && test -n "$url" || usage |
ace33bf9 DW |
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 | ||
024d34cb LT |
46 | # |
47 | # $3 must be a symbolic ref, a unique ref, or | |
dc2eacc5 LT |
48 | # a SHA object expression. It can also be of |
49 | # the format 'local-name:remote-name'. | |
024d34cb | 50 | # |
dc2eacc5 LT |
51 | local=${3%:*} |
52 | local=${local:-HEAD} | |
53 | remote=${3#*:} | |
5aae66bd JH |
54 | pretty_remote=${remote#refs/} |
55 | pretty_remote=${pretty_remote#heads/} | |
dc2eacc5 LT |
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")} | |
024d34cb LT |
59 | |
60 | # None of the above? Bad. | |
dc2eacc5 | 61 | test -z "$head" && die "fatal: Not a valid revision: $local" |
024d34cb LT |
62 | |
63 | # This also verifies that the resulting head is unique: | |
64 | # "git show-ref" could have shown multiple matching refs.. | |
ace33bf9 | 65 | headrev=$(git rev-parse --verify --quiet "$head"^0) |
dc2eacc5 | 66 | test -z "$headrev" && die "fatal: Ambiguous revision: $local" |
024d34cb | 67 | |
0454220d PB |
68 | local_sha1=$(git rev-parse --verify --quiet "$head") |
69 | ||
024d34cb LT |
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 | |
ace33bf9 | 74 | then |
024d34cb | 75 | branch_name= |
ace33bf9 | 76 | fi |
ab421d2c | 77 | |
3c9f1e7c | 78 | merge_base=$(git merge-base $baserev $headrev) || |
ff06c743 SP |
79 | die "fatal: No commits in common between $base and $head" |
80 | ||
024d34cb | 81 | # $head is the refname from the command line. |
0454220d PB |
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. | |
fe46fa9d | 84 | find_matching_ref=' |
dc2eacc5 | 85 | my ($head,$headrev) = (@ARGV); |
5731dfce | 86 | my $pattern = qr{/\Q$head\E$}; |
0454220d | 87 | my ($remote_sha1, $found); |
fe46fa9d | 88 | |
fe46fa9d | 89 | while (<STDIN>) { |
dc2eacc5 | 90 | chomp; |
024d34cb | 91 | my ($sha1, $ref, $deref) = /^(\S+)\s+([^^]+)(\S*)$/; |
dc2eacc5 | 92 | |
dc2eacc5 | 93 | if ($sha1 eq $head) { |
0454220d PB |
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 | } | |
fe46fa9d JH |
107 | } |
108 | } | |
dc2eacc5 | 109 | if ($found) { |
0454220d PB |
110 | $remote_sha1 = $headrev if ! defined $remote_sha1; |
111 | print "$remote_sha1 $found\n"; | |
fe46fa9d JH |
112 | } |
113 | ' | |
114 | ||
0454220d PB |
115 | set fnord $(git ls-remote "$url" | @@PERL@@ -e "$find_matching_ref" "${remote:-HEAD}" "$headrev") |
116 | remote_sha1=$2 | |
117 | ref=$3 | |
024d34cb LT |
118 | |
119 | if test -z "$ref" | |
120 | then | |
dc2eacc5 LT |
121 | echo "warn: No match for commit $headrev found at $url" >&2 |
122 | echo "warn: Are you sure you pushed '${remote:-HEAD}' there?" >&2 | |
024d34cb | 123 | status=1 |
0454220d PB |
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 | |
024d34cb | 129 | fi |
fe46fa9d | 130 | |
d952cbb1 JH |
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 | ||
1a927775 | 137 | url=$(git ls-remote --get-url "$url") |
ff06c743 | 138 | |
10eb0007 | 139 | git show -s --format='The following changes since commit %H: |
ab421d2c | 140 | |
10eb0007 MV |
141 | %s (%ci) |
142 | ||
e66d7c37 | 143 | are available in the Git repository at: |
b7e642ec | 144 | ' $merge_base && |
5aae66bd | 145 | echo " $url $pretty_remote" && |
cf731666 JH |
146 | git show -s --format=' |
147 | for you to fetch changes up to %H: | |
148 | ||
149 | %s (%ci) | |
150 | ||
151 | ----------------------------------------------------------------' $headrev && | |
ab421d2c | 152 | |
4b14ec87 | 153 | if test $(git cat-file -t "$head") = tag |
c0168147 | 154 | then |
4b14ec87 | 155 | git cat-file tag "$head" | |
d0504645 JH |
156 | sed -n -e '1,/^$/d' -e '/^-----BEGIN PGP /q' -e p |
157 | echo | |
4b14ec87 | 158 | echo "----------------------------------------------------------------" |
d0504645 JH |
159 | fi && |
160 | ||
c0168147 | 161 | if test -n "$branch_name" |
d0504645 | 162 | then |
fe46fa9d | 163 | echo "(from the branch description for $branch_name local branch)" |
c0168147 JH |
164 | echo |
165 | git config "branch.$branch_name.description" | |
166 | echo "----------------------------------------------------------------" | |
167 | fi && | |
d0504645 | 168 | |
53dfac44 | 169 | git shortlog ^$baserev $headrev && |
cf731666 JH |
170 | git diff -M --stat --summary $patch $merge_base..$headrev || status=1 |
171 | ||
ff06c743 | 172 | exit $status |