summaryrefslogtreecommitdiff
path: root/Ports
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2022-05-16 16:26:07 +0430
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2022-05-19 20:17:10 +0430
commit527502494c7041013bdba93746e56eba46913e59 (patch)
tree6ae1edb1611a7f6d93f5e8d49a47fc0669d9645a /Ports
parent857a767ab49b6813707b81d93fab81d524cca574 (diff)
downloadserenity-527502494c7041013bdba93746e56eba46913e59.zip
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.
Diffstat (limited to 'Ports')
-rwxr-xr-xPorts/.port_include.sh44
1 files changed, 43 insertions, 1 deletions
diff --git a/Ports/.port_include.sh b/Ports/.port_include.sh
index ba4699f614..1e787956eb 100755
--- a/Ports/.port_include.sh
+++ b/Ports/.port_include.sh
@@ -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: