Ports: Make the patch auto-import script care about the patch's authors

Previously it would commit with the current user's git identity, this
commit makes it ask the user if they want to retain the original
author(s) of the patch as commit authors and co-authors, as well as the
original commit date.
This commit is contained in:
Ali Mohammad Pur 2022-05-16 16:26:07 +04:30 committed by Ali Mohammad Pur
parent 857a767ab4
commit 527502494c

View file

@ -694,6 +694,17 @@ prompt_yes_no() {
fi
}
prompt_yes_no_default_yes() {
read -N1 -rp \
"$1 (Y/n) " result
2>&1 echo
if [ "${result,,}" == n ]; then
return 1
else
return 0
fi
}
do_dev() {
if [ -n "${IN_SERENITY_PORT_DEV:-}" ]; then
>&2 echo "Error: Already in dev environment for $IN_SERENITY_PORT_DEV"
@ -729,7 +740,38 @@ do_dev() {
launch_user_shell
fi
git commit --verbose
main_author=''
co_authors=()
patch_name_in_parent_directory="patches/$(basename "$patch")"
while read -r line; do
author="$(echo "$line" | cut -f2 -d' ')"
if [[ -z "$main_author" ]]; then
main_author="$author"
else
co_authors+=("$author")
fi
done < <(git -C .. shortlog -esn -- "$patch_name_in_parent_directory")
if [[ -n "$main_author" ]]; then
date="$(git -C .. log --format=%ad -n1 -- "$patch_name_in_parent_directory")"
>&2 echo -n "- This patch was authored by $main_author"
if [[ ${#co_authors[@]} -ne 0 ]]; then
>&2 echo -n " (and ${co_authors[*]})"
fi
>&2 echo " at $date"
if prompt_yes_no_default_yes "- Would you like to preserve that information?"; then
trailers=()
for a in "${co_authors[@]}"; do
trailers+=("--trailer" "Co-Authored-By: $a")
done
git commit --verbose --author "$main_author" --date "$date" "${trailers[@]}"
else
>&2 echo " Okay, using your current git identity as the author."
git commit --verbose
fi
else
git commit --verbose
fi
else
# The patch didn't apply, oh no!
# Ask the user to figure it out :shrug: