request-pull: pick up tag message as before
[git/mingw.git] / git-request-pull.sh
blob93b41357abd0ad0f02e3746778f35018a3dc1754
1 #!/bin/sh
2 # Copyright 2005, Ryan Anderson <ryan@michonline.com>
4 # This file is licensed under the GPL v2, or a later version
5 # at the discretion of Linus Torvalds.
7 USAGE='<start> <url> [<end>]'
8 LONG_USAGE='Summarizes the changes between two commits to the standard output,
9 and includes the given URL in the generated summary.'
10 SUBDIRECTORY_OK='Yes'
11 OPTIONS_KEEPDASHDASH=
12 OPTIONS_SPEC='git request-pull [options] start url [end]
14 p show patch text as well
17 . git-sh-setup
19 GIT_PAGER=
20 export GIT_PAGER
22 patch=
23 while case "$#" in 0) break ;; esac
25 case "$1" in
26 -p)
27 patch=-p ;;
28 --)
29 shift; break ;;
30 -*)
31 usage ;;
33 break ;;
34 esac
35 shift
36 done
38 base=$1 url=$2 status=0
40 test -n "$base" && test -n "$url" || usage
42 baserev=$(git rev-parse --verify --quiet "$base"^0)
43 if test -z "$baserev"
44 then
45 die "fatal: Not a valid revision: $base"
49 # $3 must be a symbolic ref, a unique ref, or
50 # a SHA object expression. It can also be of
51 # the format 'local-name:remote-name'.
53 local=${3%:*}
54 local=${local:-HEAD}
55 remote=${3#*:}
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")}
60 # None of the above? Bad.
61 test -z "$head" && die "fatal: Not a valid revision: $local"
63 # This also verifies that the resulting head is unique:
64 # "git show-ref" could have shown multiple matching refs..
65 headrev=$(git rev-parse --verify --quiet "$head"^0)
66 test -z "$headrev" && die "fatal: Ambiguous revision: $local"
68 # Was it a branch with a description?
69 branch_name=${head#refs/heads/}
70 if test "z$branch_name" = "z$headref" ||
71 ! git config "branch.$branch_name.description" >/dev/null
72 then
73 branch_name=
76 merge_base=$(git merge-base $baserev $headrev) ||
77 die "fatal: No commits in common between $base and $head"
79 # $head is the refname from the command line.
80 # If a ref with the same name as $head exists at the remote
81 # and their values match, use that.
83 # Otherwise find a random ref that matches $headrev.
84 find_matching_ref='
85 my ($head,$headrev) = (@ARGV);
86 my ($found);
88 while (<STDIN>) {
89 chomp;
90 my ($sha1, $ref, $deref) = /^(\S+)\s+([^^]+)(\S*)$/;
91 my ($pattern);
92 next unless ($sha1 eq $headrev);
94 $pattern="/$head\$";
95 if ($ref eq $head) {
96 $found = $ref;
98 if ($ref =~ /$pattern/) {
99 $found = $ref;
101 if ($sha1 eq $head) {
102 $found = $sha1;
105 if ($found) {
106 print "$found\n";
110 ref=$(git ls-remote "$url" | @@PERL@@ -e "$find_matching_ref" "${remote:-HEAD}" "$headrev")
112 if test -z "$ref"
113 then
114 echo "warn: No match for commit $headrev found at $url" >&2
115 echo "warn: Are you sure you pushed '${remote:-HEAD}' there?" >&2
116 status=1
119 url=$(git ls-remote --get-url "$url")
121 git show -s --format='The following changes since commit %H:
123 %s (%ci)
125 are available in the git repository at:
126 ' $merge_base &&
127 echo " $url $remote" &&
128 git show -s --format='
129 for you to fetch changes up to %H:
131 %s (%ci)
133 ----------------------------------------------------------------' $headrev &&
135 if test $(git cat-file -t "$head") = tag
136 then
137 git cat-file tag "$head" |
138 sed -n -e '1,/^$/d' -e '/^-----BEGIN PGP /q' -e p
139 echo
140 echo "----------------------------------------------------------------"
141 fi &&
143 if test -n "$branch_name"
144 then
145 echo "(from the branch description for $branch_name local branch)"
146 echo
147 git config "branch.$branch_name.description"
148 echo "----------------------------------------------------------------"
149 fi &&
151 git shortlog ^$baserev $headrev &&
152 git diff -M --stat --summary $patch $merge_base..$headrev || status=1
154 exit $status