Skip to content

Instantly share code, notes, and snippets.

@ohader
Created February 5, 2023 08:58
Show Gist options
  • Save ohader/cae9392ae996fb840af9ebef772b2bc1 to your computer and use it in GitHub Desktop.
Save ohader/cae9392ae996fb840af9ebef772b2bc1 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 <oliver@typo3.org>
# @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 "${EXTENSIONS}\n${ext}" | sort -u)
fi
fi
done
cat <<< ${LOG}
echo
echo "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
@ohader
Copy link
Author

ohader commented Feb 5, 2023

Example execution (based on this commit https://review.typo3.org/c/Packages/TYPO3.CMS/+/77522):

$ ./cherry-split.sh

e1050b274e [FEATURE] Move files from filelist via Drag & Drop into tree

Commit (used as output file prefix):
e1050b274e

Files:
Build/Sources/TypeScript/backend/drag-drop/drag-drop.ts
Build/Sources/TypeScript/backend/tree/file-storage-tree-container.ts
Build/Sources/TypeScript/filelist/file-list.ts
typo3/sysext/backend/Resources/Private/Language/locallang_layout.xlf
typo3/sysext/backend/Resources/Public/JavaScript/drag-drop/drag-drop.js
typo3/sysext/backend/Resources/Public/JavaScript/tree/file-storage-tree-container.js
typo3/sysext/core/Documentation/Changelog/12.2/Feature-99733-DragDropBetweenDifferentFoldersInFileList.rst
typo3/sysext/filelist/Classes/Dto/ResourceView.php
typo3/sysext/filelist/Classes/Dto/UserPermissions.php
typo3/sysext/filelist/Classes/FileList.php
typo3/sysext/filelist/Resources/Private/Templates/Filelist/Tiles.html
typo3/sysext/filelist/Resources/Public/JavaScript/file-list.js

Extensions:
backend
core
filelist

Continue (y/n)? y
+ e1050b274e-backend.patch
+ e1050b274e-core.patch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment