From 7e2c8eda5e79805893f31031e62639066f339b93 Mon Sep 17 00:00:00 2001 From: Alexandre <44178713+alexbelgium@users.noreply.github.com> Date: Thu, 16 Jul 2026 14:28:31 +0200 Subject: [PATCH] Fix generated package-lock conflicts when merging review PRs --- birdnet-go-dev/merge-prs.sh | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/birdnet-go-dev/merge-prs.sh b/birdnet-go-dev/merge-prs.sh index a7e6dcdb3c..b3430adc19 100755 --- a/birdnet-go-dev/merge-prs.sh +++ b/birdnet-go-dev/merge-prs.sh @@ -77,10 +77,27 @@ for entry in "${prs[@]}"; do # Fetch the PR head commit by number; works unauthenticated for public repos. git fetch --no-tags origin "refs/pull/${number}/head" if ! git merge --no-edit --no-ff -m "Merge PR #${number}: ${title}" "${sha}"; then - echo "!!! Merge conflict while merging PR #${number} (${title})." >&2 - echo "!!! Resolve the conflict in the fork or pause this PR, then rebuild." >&2 - git merge --abort || true - exit 1 + mapfile -t conflicted_files < <(git diff --name-only --diff-filter=U) + + # package-lock.json is generated content and stacked PRs can carry an + # older copy even when their source changes merge cleanly. Keep the + # lockfile already assembled from upstream and earlier PRs, but only + # when it is the sole conflict. Any source conflict remains fatal. + if [ "${#conflicted_files[@]}" -eq 1 ] \ + && [ "${conflicted_files[0]}" = "frontend/package-lock.json" ]; then + log "Resolving generated frontend/package-lock.json conflict using the accumulated tree" + git checkout --ours -- frontend/package-lock.json + git add frontend/package-lock.json + git commit --no-edit + else + echo "!!! Merge conflict while merging PR #${number} (${title})." >&2 + if [ "${#conflicted_files[@]}" -gt 0 ]; then + printf '!!! Conflicting file: %s\n' "${conflicted_files[@]}" >&2 + fi + echo "!!! Resolve the conflict in the fork or pause this PR, then rebuild." >&2 + git merge --abort || true + exit 1 + fi fi done