Last active
January 19, 2018 12:45
-
-
Save shawn111/64ee0125acab30c619e129c52de94082 to your computer and use it in GitHub Desktop.
hello #tag_abc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## helper function to create patch | |
## | |
## Usage: | |
### | |
### download: | |
### $ curl https://gist.githubusercontent.com/shawn111/64ee0125acab30c619e129c52de94082/raw/273d7f91a3adb75603800d260cb0b62ca42f2262 -o xx.sh | |
### | |
### copy the function into .bashrc | |
### | |
### Run below command in your git project dir. | |
### | |
### $ SUBJECT="hello world" gen_patch <branch-abc> | |
### | |
### output: ./HelloWorld/ | |
### |--- 0000-cover-letter.patch | |
### |--- 0001-xxx.patch | |
### |--- 0002-xxx2.patch | |
### | |
### | |
### cover-letter.patch | |
### | |
### From e8a8de1bacec7cc59bbbed7c9df60b2bca2c1fd7 Mon Sep 17 00:00:00 2001 | |
### From: Shawn Wang <shawn.wang@easystack.cn> | |
### Date: Thu, 18 Jan 2018 16:36:51 +0800 | |
### Subject: [PATCH, yak 0/1] ${SUBJECT} | |
### | |
### ------ | |
### repo: ${REPO} | |
### branch: ${BRANCH} | |
### ------ | |
### | |
### ... | |
### | |
### -------------------------------------------------------- | |
### .gitconfig | |
### [sendemail] | |
### smtpEncryption = tls | |
### smtpServer = smtp.qiye.163.com | |
### smtpUser = shawn.wang@easystack.cn | |
### smtpServerPort = 25 | |
### smtppass = xxxx | |
### confirm = auto | |
### cc = system-engineering@easystack.cn | |
#### to = hello@easystack.cn | |
### coverletter = auto | |
function gen_patch { | |
export BRANCH=${1:-master} | |
export REPO=${REPO:-$(git config --get remote.origin.url)} | |
SUBJECT=${2:-$SUBJECT} | |
PATCH_DIR=$(python -c "print '${SUBJECT}'.title().replace(' ', '')") | |
COUNT=$(git rev-list ${BRANCH}..HEAD --count) | |
REPO_NAME=${REPO_NAME:-$(basename `git rev-parse --show-toplevel`)} | |
if [ "${SUBJECT}" = "" -o "$#" -lt 1 ]; then | |
echo " $ $FUNCNAME \"branch\" \"SUBJECT\"" | |
return 1 | |
fi | |
if [ $COUNT -lt 1 ]; then | |
echo "commit count: $COUNT" | |
return 1 | |
elif [ $COUNT -eq 1 ]; then | |
FILE=$(git format-patch --subject-prefix="PATCH, ${REPO_NAME}" -o $PATCH_DIR ${BRANCH}..HEAD) | |
else | |
git format-patch --subject-prefix="PATCH, ${REPO_NAME}" --cover-letter -o $PATCH_DIR ${BRANCH}..HEAD | |
FILE=$PATCH_DIR/0000-cover-letter.patch | |
fi | |
if [ ! -f $FILE ]; | |
then | |
echo "can't find file: $FILE" | |
return 1 | |
fi | |
sed -i -e '0,/re/ s/\*\*\*\sSUBJECT\sHERE\s\*\*\*/\${SUBJECT}/' $FILE | |
sed -i -e '0,/re/ s/\*\*\*\sBLURB\sHERE\s\*\*\*/==============\nrepo: \${REPO}\nbranch: \${BRANCH}\n/' $FILE | |
sed -i -e '0,/re/ s/^\-\-\-$/---\nrepo: \${REPO}\nbranch: \${BRANCH}\n/' $FILE | |
cat $FILE | envsubst > $FILE.tmp | |
mv ${FILE}.tmp $FILE | |
echo "git send-email $PATCH_DIR --to <reviewer>" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment