aosp-merger: Improve merge commit message

* Merge and commit separately,
  to get newline between commit content and Change-Id
* Install prepare-commit-msg git hook, for nicer conflict messages
  https://gist.github.com/mikeNG/e55ef8e7a1e5cd596a950386503054fd/

Change-Id: I97370b352ccf4f146b4b6ea89af75e032fb13730
This commit is contained in:
Chirayu Desai 2022-01-10 04:07:45 +05:30
parent ba9a055d43
commit 3f6df5c8a0
2 changed files with 20 additions and 1 deletions

View File

@ -32,6 +32,8 @@ readonly vars_path="${script_path}/../vars"
source "${vars_path}/common"
readonly hook="${script_path}/prepare-commit-msg"
TOP="${script_path}/../../.."
BRANCH="${calyxos_branch}"
STAGINGBRANCH="staging/${BRANCH}_${OPERATION}-${NEWTAG}"
@ -40,6 +42,9 @@ cd "${TOP}/${PROJECTPATH}"
repo start "${STAGINGBRANCH}" .
git fetch -q --tags aosp "${NEWTAG}"
[[ ! -e .git/hooks/prepare-commit-msg ]] && cp "${hook}" .git/hooks/
chmod +x .git/hooks/prepare-commit-msg
PROJECTOPERATION="${OPERATION}"
# Check if we've actually changed anything before attempting to merge
@ -69,7 +74,7 @@ fi
if [[ "${PROJECTOPERATION}" == "merge" ]]; then
echo "#### Merging ${NEWTAG} into ${PROJECTPATH} ####"
git merge --no-edit --log "${NEWTAG}"
git merge --no-commit --log "${NEWTAG}" && git commit --no-edit
elif [[ "${PROJECTOPERATION}" == "rebase" ]]; then
echo "#### Rebasing ${PROJECTPATH} onto ${NEWTAG} ####"
git rebase --onto "${NEWTAG}" "${OLDTAG}"

View File

@ -0,0 +1,14 @@
#!/bin/sh
case "$2,$3" in
merge,)
if grep -q "# It looks like you may be committing a merge." "$1"; then
sed -i -e '/# ------------------------ >8 ------------------------/,+3d' "$1"
/usr/bin/perl -i.bak -ne 's/^#// if /^# Conflicts/ .. /^#\R/; print' "$1"
sed -i '/ It looks like you may be committing a merge./i # ------------------------ >8 ------------------------' "$1"
fi
;;
*)
;;
esac