Skip to content

Instantly share code, notes, and snippets.

@bnf
Forked from ohader/cherry-split.sh
Last active February 6, 2023 18:29
Show Gist options
  • Save bnf/3140836ab73546bb8e85260c913ebf0c to your computer and use it in GitHub Desktop.
Save bnf/3140836ab73546bb8e85260c913ebf0c to your computer and use it in GitHub Desktop.
TYPO3 Git Commit Splitter
#!/bin/sh
###
# TYPO3 Git Cherry-Picked Commit Splitter ("Cherry-Split")
# @author Oliver Hader <[email protected]>
# @license GPL v2 on any later version
#
# Usage
# - cherry-pick change to local Git working copy
# - execute this script `./cherry-split.sh` which processed the tip commit
# - generates files per hash and extension, e.g. `abcd1234-frontend.patch`
##
TYPO3_PREFIX='typo3/sysext/'
LOG=$(git log --oneline -1)
FILES=$(git diff HEAD^ --name-only)
COMMIT=$(git rev-parse --short HEAD)
EXTENSIONS=''
for file in ${FILES}; do
if [[ $file =~ ^${TYPO3_PREFIX} ]]; then
ext=$(cut -d/ -f3 <<< ${file})
if [[ "${EXTENSIONS}" == "" ]]; then
EXTENSIONS=${ext}
else
EXTENSIONS=$(echo -e "${EXTENSIONS}\n${ext}" | sort -u)
fi
fi
done
cat <<< ${LOG}
echo
echo -e "Commit (used as output file prefix):\n${COMMIT}"
echo
echo "Files:"
cat <<< "${FILES}"
echo
echo "Extensions:"
cat <<< "${EXTENSIONS}"
echo
read -p 'Continue (y/n)? ' result
case "$result" in
y|Y ) ;;
* ) exit 1;;
esac
for ext in ${EXTENSIONS}; do
path="${TYPO3_PREFIX}${ext}/"
file="${COMMIT}-${ext}.patch"
git diff HEAD^ --relative="${path}" -- :^${path}Tests/ > ${file}
if [ -s "${file}" ]; then
echo "+ ${file}"
else
rm ${file}
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment