From a49c66538c02a0fcaaf87e1c774bfdd11b76c07b Mon Sep 17 00:00:00 2001 From: SpiritCroc Date: Sun, 18 Aug 2024 11:45:47 +0200 Subject: [PATCH] Make merge_helpers.sh smarter if you have the commit around --- merge_helpers.sh | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/merge_helpers.sh b/merge_helpers.sh index 4e6703c..a1e03f3 100755 --- a/merge_helpers.sh +++ b/merge_helpers.sh @@ -264,7 +264,29 @@ apply_patches() { pushd "$repo" for patch in "$patch_dir"/*; do echo "Applying $patch to $repo..." - git am "$patch" || read -p "Applying $patch failed, please commit manually, then press enter: " + git am "$patch" || on_apply_patch_fail_try_original_commit "$patch" "$repo" done popd } + +on_apply_patch_fail_try_original_commit() { + local patch="$1" + local repo="$2" + local orig_commit="$(head -n 1 "$patch"|sed 's|From ||;s| .*||')" + echo "Applying $patch failed, trying with original commit $orig_commit..." + git am --abort + git cherry-pick "$orig_commit" || on_apply_patch_fail "$patch" "$repo" "$orig_commit" +} + +on_apply_patch_fail() { + local patch="$1" + local repo="$2" + local orig_commit="$3" + echo "----------------------------------" + echo "Applying patch failed, please commit manually!" + echo "Patch: $patch" + echo "Repo: $repo" + echo "Original commit: $(head -n 1 "$patch"|sed 's|From ||;s| .*||')" + echo "----------------------------------" + read -p "Press enter after committing resolved conflicts: " +}