From e79a76690111c1fe9d3bf853f247256545529884 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Mon, 24 Jan 2022 15:58:56 +0330 Subject: [PATCH] Ports: Make 'package.sh dev' a bit more friendly when importing patches When a git patch that doesn't apply is encountered, start a git am session and _then_ drop the user in it instead of expeting the user to start the session on their own. Also prompt for leftover files and delete them if the user does not want them. --- Ports/.port_include.sh | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/Ports/.port_include.sh b/Ports/.port_include.sh index 04e114cc69..94d17f5e04 100755 --- a/Ports/.port_include.sh +++ b/Ports/.port_include.sh @@ -690,21 +690,35 @@ do_dev() { fi echo "Importing patch $patch..." - git am "$patch" || { + git am "$patch" >/dev/null 2>&1 || { git am --abort >/dev/null 2>&1 || true - git apply < $patch || { + if git apply < $patch; then + git add -A + if prompt_yes_no "- This patch does not appear to be a git patch, would you like to modify its changes before continuing?"; then + >&2 echo "Apply any changes you want, commit them into the current repo and quit this shell to continue." + + launch_user_shell + fi + git commit --verbose + else # The patch didn't apply, oh no! # Ask the user to figure it out :shrug: + git am "$patch" || true >&2 echo "- This patch does not apply, you'll be dropped into a shell to investigate and fix this, quit the shell when the problem is resolved." + >&2 echo "Note that the patch needs to be committed into the current repository!" launch_user_shell - } - git add -A - if prompt_yes_no "- This patch does not appear to be a git patch, would you like to manually commit its changes?"; then - >&2 echo "Apply any changes you want, commit them into the current repo and quit this shell to continue." + fi - launch_user_shell - else - git commit --verbose + if ! git diff --quiet >/dev/null 2>&1; then + >&2 echo "- It appears that there are uncommitted changes from applying the previous patch:" + for line in $(git diff --color=always); do + echo "| $line" + done + if prompt_yes_no "- Would you like to drop them before moving on to the next patch?"; then + git clean -xf + else + >&2 echo "- The uncommitted changes will be committed with the next patch or left in the tree." + fi fi } done