t0026-eol-config.sh: use the $( ... ) construct for command substitution
[git/git-svn.git] / git-request-pull.sh
blob5c1599752314696ef1f317095d1786493fbfc935
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_STUCKLONG=
13 OPTIONS_SPEC='git request-pull [options] start url [end]
15 p show patch text as well
18 . git-sh-setup
20 GIT_PAGER=
21 export GIT_PAGER
23 patch=
24 while case "$#" in 0) break ;; esac
26 case "$1" in
27 -p)
28 patch=-p ;;
29 --)
30 shift; break ;;
31 -*)
32 usage ;;
34 break ;;
35 esac
36 shift
37 done
39 base=$1 url=$2 status=0
41 test -n "$base" && test -n "$url" || usage
43 baserev=$(git rev-parse --verify --quiet "$base"^0)
44 if test -z "$baserev"
45 then
46 die "fatal: Not a valid revision: $base"
50 # $3 must be a symbolic ref, a unique ref, or
51 # a SHA object expression. It can also be of
52 # the format 'local-name:remote-name'.
54 local=${3%:*}
55 local=${local:-HEAD}
56 remote=${3#*:}
57 pretty_remote=${remote#refs/}
58 pretty_remote=${pretty_remote#heads/}
59 head=$(git symbolic-ref -q "$local")
60 head=${head:-$(git show-ref --heads --tags "$local" | cut -d' ' -f2)}
61 head=${head:-$(git rev-parse --quiet --verify "$local")}
63 # None of the above? Bad.
64 test -z "$head" && die "fatal: Not a valid revision: $local"
66 # This also verifies that the resulting head is unique:
67 # "git show-ref" could have shown multiple matching refs..
68 headrev=$(git rev-parse --verify --quiet "$head"^0)
69 test -z "$headrev" && die "fatal: Ambiguous revision: $local"
71 # Was it a branch with a description?
72 branch_name=${head#refs/heads/}
73 if test "z$branch_name" = "z$headref" ||
74 ! git config "branch.$branch_name.description" >/dev/null
75 then
76 branch_name=
79 merge_base=$(git merge-base $baserev $headrev) ||
80 die "fatal: No commits in common between $base and $head"
82 # $head is the refname from the command line.
83 # If a ref with the same name as $head exists at the remote
84 # and their values match, use that.
86 # Otherwise find a random ref that matches $headrev.
87 find_matching_ref='
88 my ($head,$headrev) = (@ARGV);
89 my ($found);
91 while (<STDIN>) {
92 chomp;
93 my ($sha1, $ref, $deref) = /^(\S+)\s+([^^]+)(\S*)$/;
94 my ($pattern);
95 next unless ($sha1 eq $headrev);
97 $pattern="/$head\$";
98 if ($ref eq $head) {
99 $found = $ref;
101 if ($ref =~ /$pattern/) {
102 $found = $ref;
104 if ($sha1 eq $head) {
105 $found = $sha1;
108 if ($found) {
109 print "$found\n";
113 ref=$(git ls-remote "$url" | @@PERL@@ -e "$find_matching_ref" "${remote:-HEAD}" "$headrev")
115 if test -z "$ref"
116 then
117 echo "warn: No match for commit $headrev found at $url" >&2
118 echo "warn: Are you sure you pushed '${remote:-HEAD}' there?" >&2
119 status=1
122 url=$(git ls-remote --get-url "$url")
124 git show -s --format='The following changes since commit %H:
126 %s (%ci)
128 are available in the git repository at:
129 ' $merge_base &&
130 echo " $url $pretty_remote" &&
131 git show -s --format='
132 for you to fetch changes up to %H:
134 %s (%ci)
136 ----------------------------------------------------------------' $headrev &&
138 if test $(git cat-file -t "$head") = tag
139 then
140 git cat-file tag "$head" |
141 sed -n -e '1,/^$/d' -e '/^-----BEGIN PGP /q' -e p
142 echo
143 echo "----------------------------------------------------------------"
144 fi &&
146 if test -n "$branch_name"
147 then
148 echo "(from the branch description for $branch_name local branch)"
149 echo
150 git config "branch.$branch_name.description"
151 echo "----------------------------------------------------------------"
152 fi &&
154 git shortlog ^$baserev $headrev &&
155 git diff -M --stat --summary $patch $merge_base..$headrev || status=1
157 exit $status