]> git.ipfire.org Git - thirdparty/git.git/blob - git-request-pull.sh
0d128be7fd70c0113f972f31605119f1581326e4
[thirdparty/git.git] / git-request-pull.sh
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
7 SUBDIRECTORY_OK='Yes'
8 OPTIONS_KEEPDASHDASH=
9 OPTIONS_STUCKLONG=
10 OPTIONS_SPEC='git request-pull [options] start url [end]
11 --
12 p show patch text as well
13 '
14
15 . git-sh-setup
16
17 GIT_PAGER=
18 export GIT_PAGER
19
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
36 base=$1 url=$2 status=0
37
38 test -n "$base" && test -n "$url" || usage
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
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 #
51 local=${3%:*}
52 local=${local:-HEAD}
53 remote=${3#*:}
54 pretty_remote=${remote#refs/}
55 pretty_remote=${pretty_remote#heads/}
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")}
59
60 # None of the above? Bad.
61 test -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..
65 headrev=$(git rev-parse --verify --quiet "$head"^0)
66 test -z "$headrev" && die "fatal: Ambiguous revision: $local"
67
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=
74 fi
75
76 merge_base=$(git merge-base $baserev $headrev) ||
77 die "fatal: No commits in common between $base and $head"
78
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.
82 #
83 # Otherwise find a random ref that matches $headrev.
84 find_matching_ref='
85 my ($head,$headrev) = (@ARGV);
86 my $pattern = qr{/\Q$head\E$};
87 my ($found);
88
89 while (<STDIN>) {
90 chomp;
91 my ($sha1, $ref, $deref) = /^(\S+)\s+([^^]+)(\S*)$/;
92 next unless ($sha1 eq $headrev);
93
94 if ($ref eq $head) {
95 $found = $ref;
96 }
97 if ($ref =~ $pattern) {
98 $found = $ref;
99 }
100 if ($sha1 eq $head) {
101 $found = $sha1;
102 }
103 }
104 if ($found) {
105 print "$found\n";
106 }
107 '
108
109 ref=$(git ls-remote "$url" | @@PERL@@ -e "$find_matching_ref" "${remote:-HEAD}" "$headrev")
110
111 if test -z "$ref"
112 then
113 echo "warn: No match for commit $headrev found at $url" >&2
114 echo "warn: Are you sure you pushed '${remote:-HEAD}' there?" >&2
115 status=1
116 fi
117
118 # Special case: turn "for_linus" to "tags/for_linus" when it is correct
119 if test "$ref" = "refs/tags/$pretty_remote"
120 then
121 pretty_remote=tags/$pretty_remote
122 fi
123
124 url=$(git ls-remote --get-url "$url")
125
126 git show -s --format='The following changes since commit %H:
127
128 %s (%ci)
129
130 are available in the Git repository at:
131 ' $merge_base &&
132 echo " $url $pretty_remote" &&
133 git show -s --format='
134 for you to fetch changes up to %H:
135
136 %s (%ci)
137
138 ----------------------------------------------------------------' $headrev &&
139
140 if test $(git cat-file -t "$head") = tag
141 then
142 git cat-file tag "$head" |
143 sed -n -e '1,/^$/d' -e '/^-----BEGIN PGP /q' -e p
144 echo
145 echo "----------------------------------------------------------------"
146 fi &&
147
148 if test -n "$branch_name"
149 then
150 echo "(from the branch description for $branch_name local branch)"
151 echo
152 git config "branch.$branch_name.description"
153 echo "----------------------------------------------------------------"
154 fi &&
155
156 git shortlog ^$baserev $headrev &&
157 git diff -M --stat --summary $patch $merge_base..$headrev || status=1
158
159 exit $status