request-pull: resurrect for-linus -> tags/for-linus DWIM
[git.git] / git-request-pull.sh
blobd6648b253508707ce341a424373f8de8218ee005
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 pretty_remote=${remote#refs/}
57 pretty_remote=${pretty_remote#heads/}
58 head=$(git symbolic-ref -q "$local")
59 head=${head:-$(git show-ref --heads --tags "$local" | cut -d' ' -f2)}
60 head=${head:-$(git rev-parse --quiet --verify "$local")}
62 # None of the above? Bad.
63 test -z "$head" && die "fatal: Not a valid revision: $local"
65 # This also verifies that the resulting head is unique:
66 # "git show-ref" could have shown multiple matching refs..
67 headrev=$(git rev-parse --verify --quiet "$head"^0)
68 test -z "$headrev" && die "fatal: Ambiguous revision: $local"
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
74 then
75 branch_name=
78 merge_base=$(git merge-base $baserev $headrev) ||
79 die "fatal: No commits in common between $base and $head"
81 # $head is the refname from the command line.
82 # If a ref with the same name as $head exists at the remote
83 # and their values match, use that.
85 # Otherwise find a random ref that matches $headrev.
86 find_matching_ref='
87 my ($head,$headrev) = (@ARGV);
88 my ($found);
90 while (<STDIN>) {
91 chomp;
92 my ($sha1, $ref, $deref) = /^(\S+)\s+([^^]+)(\S*)$/;
93 my ($pattern);
94 next unless ($sha1 eq $headrev);
96 $pattern="/$head\$";
97 if ($ref eq $head) {
98 $found = $ref;
100 if ($ref =~ /$pattern/) {
101 $found = $ref;
103 if ($sha1 eq $head) {
104 $found = $sha1;
107 if ($found) {
108 print "$found\n";
112 ref=$(git ls-remote "$url" | @@PERL@@ -e "$find_matching_ref" "${remote:-HEAD}" "$headrev")
114 if test -z "$ref"
115 then
116 echo "warn: No match for commit $headrev found at $url" >&2
117 echo "warn: Are you sure you pushed '${remote:-HEAD}' there?" >&2
118 status=1
121 # Special case: turn "for_linus" to "tags/for_linus" when it is correct
122 if test "$ref" = "refs/tags/$pretty_remote"
123 then
124 pretty_remote=tags/$pretty_remote
127 url=$(git ls-remote --get-url "$url")
129 git show -s --format='The following changes since commit %H:
131 %s (%ci)
133 are available in the git repository at:
134 ' $merge_base &&
135 echo " $url $pretty_remote" &&
136 git show -s --format='
137 for you to fetch changes up to %H:
139 %s (%ci)
141 ----------------------------------------------------------------' $headrev &&
143 if test $(git cat-file -t "$head") = tag
144 then
145 git cat-file tag "$head" |
146 sed -n -e '1,/^$/d' -e '/^-----BEGIN PGP /q' -e p
147 echo
148 echo "----------------------------------------------------------------"
149 fi &&
151 if test -n "$branch_name"
152 then
153 echo "(from the branch description for $branch_name local branch)"
154 echo
155 git config "branch.$branch_name.description"
156 echo "----------------------------------------------------------------"
157 fi &&
159 git shortlog ^$baserev $headrev &&
160 git diff -M --stat --summary $patch $merge_base..$headrev || status=1
162 exit $status