-
Notifications
You must be signed in to change notification settings - Fork 0
/
git-qpush
executable file
·128 lines (103 loc) · 2.55 KB
/
git-qpush
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
#
# Copyright (C) 2013 MORITA Kazutaka <[email protected]>
#
# This code is based on guilt-push from Guilt (Git Quilt):
# Copyright (c) Josef "Jeff" Sipek, 2006-2011
#
. git-qsh-setup
USAGE="[ -f ] [-a | --all | -n <num> | <patchname>]"
abort_flag="abort"
while [ $# -gt 0 ]; do
case "$1" in
-f)
abort_flag=""
;;
-a|--all)
all=t
;;
-n)
num=t
;;
*)
break
;;
esac
shift
done
if [ $# -gt 1 ]; then
usage
fi
# "git qpush" or "git qpush foo"
if [ -z "$all" ] && [ $# -gt 1 ]; then
usage
fi
# "git qpush -n foo"
if [ ! -z "$num" ]; then
if [ $# -gt 1 ] || [ $# -eq 0 ]; then
usage
fi
fi
# "git qpush -a"
if [ ! -z "$all" ] && [ $# -gt 0 ]; then
usage
fi
patch="$1"
[ ! -z "$all" ] && patch="-a"
if [ "$patch" = "-a" ]; then
# we are supposed to push all patches, get the last one out of
# series
eidx=`wc -l < "$series"`
if [ $eidx -eq 0 ]; then
die "There are no patches to push."
fi
elif [ ! -z "$num" ]; then
# we are supposed to pop a set number of patches
[ "$patch" -lt 0 ] && die "Invalid number of patches to push."
eidx=`wc -l < "$series"`
# calculate end index from current
tidx=`wc -l < "$applied"`
tidx=`expr $tidx + $patch`
# clamp to minimum
[ $tidx -lt $eidx ] && eidx=$tidx
elif [ -z "$patch" ]; then
# we are supposed to push only the next patch onto the stack
eidx=`wc -l < "$applied"`
eidx=`expr $eidx + 1`
else
# we're supposed to push only up to a patch, make sure the patch is
# in the series
eidx=`grep -ne "^$patch\$" "$series" | cut -d: -f1`
if [ -z "$eidx" ]; then
die "Patch $patch is not in the series."
fi
fi
# make sure that there are no unapplied changes
if ! must_commit_first; then
die "Uncommited changes detected. Refresh first."
fi
# now, find the starting patch
sidx=`wc -l < "$applied"`
sidx=`expr $sidx + 1`
# do we actually have to push anything?
if [ "$sidx" -gt "$eidx" ]; then
if [ "$sidx" -le "`wc -l < "$series"`" ]; then
echo "Patch is already applied."
else
echo "File series fully applied, ends at patch `tail -n 1 \"$series\"`"
fi
exit 0
fi
for p in $(sed -n -e "${sidx},${eidx}p" "$series"); do
echo "Applying patch..$p"
if [ ! -f "$GITQ_DIR/$branch/$p" ]; then
die "Patch $p does not exist. Aborting."
fi
push_patch "$p" $abort_flag
# bail if necessary
if [ $? -eq 0 ]; then
echo "Patch applied."
elif [ -z "$abort_flag" ]; then
die "Patch applied with rejects. Fix it up, and refresh."
fi
done