-
Notifications
You must be signed in to change notification settings - Fork 10
/
git-patch-set
executable file
·55 lines (44 loc) · 1.2 KB
/
git-patch-set
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash
#
# Create a patch set, save it in patches/patches-<date>-<baseref>
# Points patches/latest to the last created directory, so it's easy to
# git-send-email from there
readonly pre_patchset_hook=.git/hooks/pre-patch-set
readonly post_patchset_hook=.git/hooks/post-patch-set
range=${!#}
git rev-list $range > /dev/null
if [ $? -ne 0 ]; then
echo "Failed to look up refs"
exit 1
fi
# git rev-list will take care of searching for the git-repo
# so if we get here, we know we're inside a git repo.
while ! [ -e ".git" ]; do
cd ..
done
readonly revs="${range/\//:}"
readonly date=`date +%Y%m%d%H%M`
readonly basedir=patches
readonly dir="patches-$date-$revs"
readonly tmplink="$basedir/latest"
readonly odir="$basedir/$dir"
if [ -e "$odir" ]; then
echo "Directory $dir already exists. Oops."
exit 1
fi
readonly first=`git rev-list --reverse $range | head -n 1`
readonly last=`git rev-list -n 1 $range`
if [ -x "$pre_patchset_hook" ]; then
set -e
./$pre_patchset_hook $first $last
set +e
fi
mkdir -p "$odir"
rm -f $tmplink
ln -sf $dir $tmplink
git format-patch -M -n -o $odir "$@"
if [ -x "$post_patchset_hook" ]; then
set -e
./$post_patchset_hook $first $last
set +e
fi