From f3426c1e431a6cdf2c14963a91a219545ca5b1c8 Mon Sep 17 00:00:00 2001 From: Andrew Robbins Date: Mon, 18 Mar 2019 19:12:49 -0400 Subject: libs/git: Move patching method logic to git_patch() This simplifies git_project_patch_recursive() and provides a unified method for patching, regardless of the patch format (mailbox or diff). Logic is included for dealing with patching failures due to git_apply_check() not being enough to catch certain edge cases, such as 'git apply --check' returning 0 but a subsequent 'git apply' failing. --- libs/git | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'libs') diff --git a/libs/git b/libs/git index 358d5d1f..104239c1 100755 --- a/libs/git +++ b/libs/git @@ -210,9 +210,19 @@ git_patch() { export GIT_COMMITTER_EMAIL=$GIT_EMAIL cd "$repository_path" - git checkout "$branch" 2> /dev/null > /dev/null + git checkout "$branch" >/dev/null 2>&1 - git am "$patch" || git am --abort + case $patch in + *.patch) + git am "$patch" || git am --abort + ;; + *.diff) + git_apply "$repository_path" "$branch" "$patch" && + git_commit "$repository_path" "Applied ${patch##*/}" + ;; + *) + ;; + esac ) } @@ -277,12 +287,7 @@ git_project_patch_recursive() { fi for patch in "$patches_path"/[!.]*.@(patch|diff); do - if [[ ${patch##*.} == patch ]]; then - git_patch "$repository_path" "$branch" "$patch" - else - git_apply "$repository_path" "$branch" "$patch" - git_commit "$repository_path" "Applied ${patch##*/}" - fi + git_patch "$repository_path" "$branch" "$patch" done } -- cgit v1.2.3-70-g09d2