Skip to content

Instantly share code, notes, and snippets.

@Gerold103
Last active September 29, 2023 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gerold103/5471a7ddbeec346c0c845930d5bb9df4 to your computer and use it in GitHub Desktop.
Save Gerold103/5471a7ddbeec346c0c845930d5bb9df4 to your computer and use it in GitHub Desktop.
#!/bin/bash
# [Required]
# -s - subject;
# -c - first commit to send.
# [Optional]
# -b - branch name;
# -i - issue number;
# -h - print help;
# -r - repository name. 'Tarantool' by default;
# -v - patchset version.
while getopts "r:s:c:b:i:v:h" opt
do
case $opt in
s) subject=$OPTARG;;
c) commit=$OPTARG;;
b) branch=$OPTARG;;
i) issue=$OPTARG;;
h) need_help=true;;
r) repository=$OPTARG;;
v) version=$OPTARG;;
esac
done
if [ $need_help ]; then
echo "Usage:
$0 -s <subject> -c <commit hash since which format> [-r <repository name>][-b <branch name>][-i <issue number>][-v <patchset version>][-h <print help>]
-r - name of repository to contribute for, 'tarantool' by default;
-v - patchset version (2, 3 ...);
-s - thread subject. For example: 'Update names in old tuple formats';
-c - commit hash, since which all commits are formated. This commit itself is not included in patchset!;
-b - branch name, for example: -b gh-<issue_number>-description. It is placed in first email's body in format: 'Branch: your branch name';
-i - issue number from github, for example 946. It is placed in first email's body in format: 'Issue: https://github.com/tarantool/tarantool/issues/your_issue_number';
-h - print this manual.
Full example:
./create_commits.sh -r 'vshard' -c a504ff16b724a6f6e11462a727659d509198eaf9 -s 'Allow to choose bucket_id index name' -b gh-74-choose-shard-index -i 74 -v 2"
exit 0
fi
if [ -z "$commit" ]; then
echo 'Start commit must be specified'
exit 1
fi
cover_letter="--cover-letter"
commit_count="$(git rev-list HEAD ^$commit --count)"
if [ $commit_count == 1 ]; then
cover_letter=""
else
if [ -z "$subject" ]; then
echo 'Subject must be specified'
exit 1
fi
fi
if [ -z "$version" ]; then
prefix="PATCH"
else
prefix="PATCH v$version"
fi
if [ -z "$repository" ]; then
repository="tarantool"
else
prefix="$prefix $repository"
fi
rm -rf commits/*
git format-patch $cover_letter --numbered-files --numbered -o commits --thread --subject-prefix="$prefix" $commit
blurb=''
if [ ! -z "$branch" ]; then
blurb="Branch: http:\/\/github.com\/tarantool\/$repository\/tree\/$branch"
fi
if [ ! -z "$issue" ]; then
if [ ! -z "$branch" ]; then
blurb=$blurb'\'$'\n'
fi
blurb=$blurb"Issue: https:\/\/github.com\/tarantool\/$repository\/issues\/$issue"
fi
if [ $commit_count != 1 ]; then
sed -i '' "s/\*\*\* SUBJECT HERE \*\*\*/$subject/g" commits/0
sed -i '' "s/\*\*\* BLURB HERE \*\*\*/$blurb/g" commits/0
else
if [ ! -z "$blurb" ]; then
blurb='---\'$'\n'$blurb'\'$'\n'
sed -i '' -e "1 s/^---$/$blurb/; t" -e "1,// s//$blurb/" commits/1
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment