]> git.ipfire.org Git - thirdparty/git.git/blame - git-request-pull.sh
request-pull: more strictly match local/remote branches
[thirdparty/git.git] / git-request-pull.sh
CommitLineData
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
3eb91bfc
SN
7USAGE='<start> <url> [<end>]'
8LONG_USAGE='Summarizes the changes between two commits to the standard output,
9and includes the given URL in the generated summary.'
806f36d4 10SUBDIRECTORY_OK='Yes'
50ab6558 11OPTIONS_KEEPDASHDASH=
133cfaeb
JH
12OPTIONS_SPEC='git request-pull [options] start url [end]
13--
14p show patch text as well
15'
16
806f36d4 17. git-sh-setup
ab421d2c 18
653a31c1
MM
19GIT_PAGER=
20export GIT_PAGER
21
133cfaeb
JH
22patch=
23while case "$#" in 0) break ;; esac
24do
25 case "$1" in
26 -p)
27 patch=-p ;;
28 --)
29 shift; break ;;
30 -*)
31 usage ;;
32 *)
33 break ;;
34 esac
35 shift
36done
37
024d34cb 38base=$1 url=$2 status=0
d0504645 39
3c9f1e7c 40test -n "$base" && test -n "$url" || usage
ace33bf9
DW
41
42baserev=$(git rev-parse --verify --quiet "$base"^0)
43if test -z "$baserev"
44then
45 die "fatal: Not a valid revision: $base"
46fi
47
024d34cb
LT
48#
49# $3 must be a symbolic ref, a unique ref, or
50# a SHA object expression
51#
52head=$(git symbolic-ref -q "${3-HEAD}")
53head=${head:-$(git show-ref "${3-HEAD}" | cut -d' ' -f2)}
54head=${head:-$(git rev-parse --quiet --verify "$3")}
55
56# None of the above? Bad.
57test -z "$head" && die "fatal: Not a valid revision: $3"
58
59# This also verifies that the resulting head is unique:
60# "git show-ref" could have shown multiple matching refs..
ace33bf9 61headrev=$(git rev-parse --verify --quiet "$head"^0)
024d34cb
LT
62test -z "$headrev" && die "fatal: Ambiguous revision: $3"
63
64# Was it a branch with a description?
65branch_name=${head#refs/heads/}
66if test "z$branch_name" = "z$headref" ||
67 ! git config "branch.$branch_name.description" >/dev/null
ace33bf9 68then
024d34cb 69 branch_name=
ace33bf9 70fi
ab421d2c 71
024d34cb
LT
72prettyhead=${head#refs/}
73prettyhead=${prettyhead#heads/}
74
3c9f1e7c 75merge_base=$(git merge-base $baserev $headrev) ||
ff06c743
SP
76die "fatal: No commits in common between $base and $head"
77
024d34cb
LT
78# $head is the refname from the command line.
79# If a ref with the same name as $head exists at the remote
80# and their values match, use that.
682853e6
JH
81#
82# Otherwise find a random ref that matches $headrev.
fe46fa9d 83find_matching_ref='
024d34cb 84 my ($exact,$found);
fe46fa9d 85 while (<STDIN>) {
024d34cb 86 my ($sha1, $ref, $deref) = /^(\S+)\s+([^^]+)(\S*)$/;
fe46fa9d 87 next unless ($sha1 eq $ARGV[1]);
024d34cb
LT
88 if ($ref eq $ARGV[0]) {
89 $exact = $ref;
682853e6 90 }
024d34cb
LT
91 if ($sha1 eq $ARGV[0]) {
92 $found = $sha1;
fe46fa9d
JH
93 }
94 }
024d34cb 95 if ($exact) {
fe46fa9d
JH
96 print "$exact\n";
97 } elsif ($found) {
98 print "$found\n";
99 }
100'
101
024d34cb
LT
102ref=$(git ls-remote "$url" | @@PERL@@ -e "$find_matching_ref" "$head" "$headrev")
103
104if test -z "$ref"
105then
106 echo "warn: No match for $prettyhead found at $url" >&2
107 echo "warn: Are you sure you pushed '$prettyhead' there?" >&2
108 status=1
109fi
fe46fa9d 110
1a927775 111url=$(git ls-remote --get-url "$url")
ff06c743 112
10eb0007 113git show -s --format='The following changes since commit %H:
ab421d2c 114
10eb0007
MV
115 %s (%ci)
116
cf731666 117are available in the git repository at:
b7e642ec 118' $merge_base &&
024d34cb 119echo " $url $prettyhead" &&
cf731666
JH
120git show -s --format='
121for you to fetch changes up to %H:
122
123 %s (%ci)
124
125----------------------------------------------------------------' $headrev &&
ab421d2c 126
c0168147
JH
127if test -n "$branch_name"
128then
fe46fa9d 129 echo "(from the branch description for $branch_name local branch)"
c0168147
JH
130 echo
131 git config "branch.$branch_name.description"
132 echo "----------------------------------------------------------------"
133fi &&
d0504645 134
53dfac44 135git shortlog ^$baserev $headrev &&
cf731666
JH
136git diff -M --stat --summary $patch $merge_base..$headrev || status=1
137
ff06c743 138exit $status