From 3ef05a585efd47abf4dc92265430d0248d7f388a Mon Sep 17 00:00:00 2001 From: Andrii Nakryiko Date: Fri, 26 Nov 2021 12:12:03 -0800 Subject: [PATCH] sync: try harder when git am -3 fails `git am -3` will give up frequently even in cases when patch can be auto-merged with: ``` Applying: libbpf: Unify low-level map creation APIs w/ new bpf_map_create() error: sha1 information is lacking or useless (src/libbpf.c). error: could not build fake ancestor Patch failed at 0001 libbpf: Unify low-level map creation APIs w/ new bpf_map_create() ``` But `git apply -3` in the same situation will succeed with three-way merge just fine: ``` error: patch failed: src/bpf_gen_internal.h:51 Falling back to three-way merge... Applied patch to 'src/bpf_gen_internal.h' cleanly. ``` So if git am fails, try git apply and if that succeeds, automatically `git am --continue`. If not, fallback to user actions. Signed-off-by: Andrii Nakryiko --- scripts/sync-kernel.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/sync-kernel.sh b/scripts/sync-kernel.sh index b5fa2aa..9ea1d56 100755 --- a/scripts/sync-kernel.sh +++ b/scripts/sync-kernel.sh @@ -263,8 +263,11 @@ cd_to ${LIBBPF_REPO} git checkout -b ${LIBBPF_SYNC_TAG} for patch in $(ls -1 ${TMP_DIR}/patches | tail -n +2); do - if ! git am --3way --committer-date-is-author-date "${TMP_DIR}/patches/${patch}"; then - read -p "Applying ${TMP_DIR}/patches/${patch} failed, please resolve manually and press to proceed..." + if ! git am -3 --committer-date-is-author-date "${TMP_DIR}/patches/${patch}"; then + if ! git apply -3 "${TMP_DIR}/patches/${patch}"; then + read -p "Applying ${TMP_DIR}/patches/${patch} failed, please resolve manually and press to proceed..." + fi + git am --continue fi done