-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathcommit-quilt-patch
executable file
·69 lines (51 loc) · 1.61 KB
/
commit-quilt-patch
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
#!/bin/bash
# A tool to take quilt patch and commit it in git tree. This is useful
# when patch is adding new files which need to have execute permission.
# By default "git quiltimport" does not do that.
set -e
usage() {
echo "$0: <patch-file>"
}
apply_patch() {
local patchfile=$1
local output
local list_files file new_files subject signedby
git diff > /dev/null
# Prepare list of new files. First apply patch using --dry-run.
if ! output=$(patch -p1 --dry-run < $patchfile); then
echo "Failed to apply patch $patchfile using option --dry-run"
return 1
fi
list_files=`grep "checking file" <<< $output | sed -e 's/checking file //g'`
# extract subject
subject=`grep "Subject:" $patchfile | sed 's/Subject: //'`
# extract subject
[ -z "$subject" ] && { echo "$patchfile does not have Subject line" && exit 1; }
signedby=`grep "Signed-off-by:" $patchfile`
[ -z "$signedby" ] && { echo "$patchfile does not have Signed-off-by line" && exit 1; }
message=`sed -n '/Subject/,/Signed-off-by:/p' $patchfile | grep -v "Subject:" | grep -v "Signed-off-by:"`
# Prepare list of new files
for file in "$list_files";do
[ -e "$file" ] && continue
new_files="$new_files $file"
done
# apply patch
if ! patch -p1 < $patchfile; then
echo "Failed to apply patch $patchfile"
exit 1
fi
# chmod new files
for file in "$new_files";do
chmod 755 $file
done
# Add all files
for file in "$list_files";do
git add $file
done
# Commit patch
git commit -s -m "$subject" -m "$message"
}
# Main script
[ $# -ne 1 ] && { usage; exit 1; }
PATCHFILE=$1
apply_patch $PATCHFILE