Request about FEMS Backports

Sure :slight_smile:

The purpose of the script is simply to quickly cherry-pick commits from our internal fork and cleanup the commit message (with separate cleanup-commit-pipe.sh i.e. replacing authors with their github IDs).

#!/bin/bash

CURRENT_HASH=${1:0:10}

if [[ $CURRENT_HASH ]]; then
	echo "# Starting Cherry Picking for..."
	git show $CURRENT_HASH --no-patch --oneline
	echo ""

	git cherry-pick --no-commit $CURRENT_HASH

	git show $CURRENT_HASH --no-patch --pretty=format:"%B" | ../cleanup-commit-pipe.sh

	code --wait /tmp/commit-message .

	git commit -F /tmp/commit-message

	echo ""
	echo "# Finished Cherry Pick"
	echo ""

else
	CURRENT_HASH=$(git log origin/develop --oneline | grep -m1 "FEMS Backports" | cut -d' ' -f1)
fi

echo "# Remaining Commits"
NO_OF_COMMITS=$(git log fems/develop --oneline | grep -n -m1 $CURRENT_HASH | cut -d':' -f1)
git log fems/develop --oneline | head -n$NO_OF_COMMITS

echo ""
echo "# Suggested next Cherry Pick"
git log fems/develop --oneline | head -n$(($NO_OF_COMMITS-1)) | tail -n1

I also use a script to write the Pull Request description text for the backport

#!/bin/bash

FILE=`mktemp`
HASHES=`git rev-list develop^..HEAD`
GITHUB_URL="https://github.com/OpenEMS/openems/commit"

get_message() {
	local hash="$1"
	git log -1 --pretty=%s "$hash"
}

log_message() {
	local hash="$1"
	MESSAGE=$(get_message "$hash")
	echo "  * ${MESSAGE} [Commit]($GITHUB_URL/$HASH)" >> $FILE
}

add() {
	local name="$1"
	local remaining_hashes=""
	echo "* ${name}" >> $FILE
	for HASH in $HASHES; do
		MESSAGE=$(get_message "$HASH")
		if [[ "$MESSAGE" == *"[${name}]"* ]]; then
			log_message "$HASH"
		else
			remaining_hashes="${remaining_hashes} ${HASH}"
		fi
	done
	echo "" >> $FILE
	HASHES="$remaining_hashes"
}

add "Backend"
add "UI"
add "Edge"

# Remaining entries
echo "* Common" >> $FILE
for HASH in $HASHES; do
	log_message "$HASH"
done

code $FILE

This discussion is related to

I understand that it can be complicated to stay synchronized with upstream. I think we should try to improve the tools, scripts, etc. to simplify these processes for everybody.