-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathgit-create-patch-zip
More file actions
executable file
·40 lines (34 loc) · 1.07 KB
/
git-create-patch-zip
File metadata and controls
executable file
·40 lines (34 loc) · 1.07 KB
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
#!/bin/bash
# vi: ft=bash
# exit on error
set -e
#set -x
usage(){
printf "USAGE: $0 <branch-base>\n"
printf "\nWill create a set of patches starting from the commit after <branch-base> and zip it\n"
exit 1
}
if [[ $# < 1 ]]; then
usage
fi
LAST_COMMIT=$(git rev-parse --short HEAD)
BASE_COMMIT=$(git rev-parse --short $1 )
# in case we reference a remote branch, we need to escape directory separators
BRANCH_SAFE=$(echo "$1" | sed -e 's/\//_/g')
if [[ $LAST_COMMIT == $BASE_COMMIT ]]; then
echo "ERROR: Base commit is the same as the last commit. Nothing to do!"
exit 200
fi
CURRENT_BRANCH=$(git branch --show-current)
MAX_LEN=30
DATETIME_NOW="$( date +"%Y%m%d-%H%M" )"
MSG_LAST_COMMIT="$(git log -n1 --pretty=format:'%s' | cut -c1-$MAX_LEN)"
FILENAME="${DATETIME_NOW}__patches_on_top_of__${BRANCH_SAFE}_${BASE_COMMIT}__${CURRENT_BRANCH}___$(change-case --kebab \"$MSG_LAST_COMMIT\")"
OUTPUT="patches-$RANDOM"
mkdir $OUTPUT
cd $OUTPUT
git format-patch "$BASE_COMMIT"
zip -q ../$FILENAME *.patch
cd ..
rm -r $OUTPUT
printf "\nPatch archive created: %s\n" "$FILENAME"