Last active
June 25, 2020 11:49
-
-
Save kicumkicum/bc0de6426933450f4cb323660bde742a to your computer and use it in GitHub Desktop.
next-commit
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
#!/usr/bin/env bash | |
if [ -n "$1" ]; then | |
echo "You supplied the first parameter!" | |
else | |
echo "Parameters not supplied." | |
exit 1 | |
fi | |
MODULE=$1 | |
TARGET=module-${MODULE} | |
PREFIX=bb | |
OLD_BRANCH=$(git branch --show-current) | |
## GET FIRST COMMIT | |
if [ -n "$2" ]; then | |
HASH_CURRENT=$2 | |
else | |
git checkout - -f | |
if [[ "${OLD_BRANCH}" == "${PREFIX}"* ]]; then | |
git branch -D ${OLD_BRANCH} | |
fi | |
HASH_CURRENT=$(git log --oneline HEAD..${TARGET} --pretty="%h" |tail -1) | |
fi | |
echo Current hash: ${HASH_CURRENT} | |
## GET SECOND COMMIT | |
git checkout ${HASH_CURRENT} | |
HASH_NEXT=$(git log --oneline HEAD..${TARGET} --pretty="%h" |tail -1) | |
if [[ -n "${HASH_NEXT}" ]]; then | |
echo "" | |
else | |
echo "HASH_NEXT IS EMPTY" | |
exit 1 | |
fi | |
echo Next hash: ${HASH_NEXT} | |
## CREATE TMP BRANCH WITH DIFF | |
git checkout -f | |
git checkout -b ${PREFIX}-${HASH_NEXT} | |
git merge --no-ff --no-commit ${HASH_NEXT} | |
git status |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment