-
Notifications
You must be signed in to change notification settings - Fork 1
/
git-apply-from-dir
executable file
·35 lines (29 loc) · 1.05 KB
/
git-apply-from-dir
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
#!/bin/sh
# Attempts to interactively apply patch files generated by 'git-patches'. If a
# patch fails to apply, then the original file and its corresponding patch file
# are opened side-by-side to make it easy to make the necessary changes
# manually.
#
# Usage:
# $> git apply-from-dir /path/to/directory/containing/patch/files
DIR=${1}
for PATCH_FILE in `ls ${DIR}/*.patch`
do
read -p "Apply $(basename ${PATCH_FILE})? (Y/n): " YES_OR_NO
if [ ! -z "${YES_OR_NO}" ]; then
[[ "${YES_OR_NO}" != [yY] ]] && continue
fi
git apply ${PATCH_FILE}
if [ "$?" != "0" ]; then
FILE_NAME=$(basename ${PATCH_FILE} .patch)
# In case of hidden files, 'git-patches' replaces the leading '.' with
# 'dot__' so that the generated patch file doesn't get overlooked. This
# process must be reversed here.
if [[ "${FILE_NAME}" == dot__* ]]
then
FILE_NAME=${FILE_NAME/"dot__"/.}
fi
FILE_PATH=$(echo ${FILE_NAME} | sed 's/__/\//g')
vim -O ${FILE_PATH} ${PATCH_FILE}
fi
done