From d7838446c42f9623991b43e8e08c0c52dbf6ea57 Mon Sep 17 00:00:00 2001 From: Fran Mulero Date: Tue, 28 Jun 2022 19:28:50 +0200 Subject: [PATCH] Fix issue with nested merge commits Signed-off-by: Fran Mulero --- scripts/fetch-commits.sh | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/scripts/fetch-commits.sh b/scripts/fetch-commits.sh index 88ab31e85de5..899de234daf4 100755 --- a/scripts/fetch-commits.sh +++ b/scripts/fetch-commits.sh @@ -64,8 +64,9 @@ function findCommitsToSync() { local max=100 # If we need to sync more than 100 commits there must be something wrong since we run the job on a daily basis for commit in "${commits[@]}"; do if [[ "$commit" != "$last_synced_commit_id" ]] && [[ "$max" -gt "0" ]]; then - if [[ "$commit" != "$SKIP_COMMIT_ID" ]]; then - commits_to_sync="${commit} ${commits_to_sync}" + actual_commit_id="$(plainCommit "${commit}")" + if [[ "$commit" != "$SKIP_COMMIT_ID" ]] && [[ ! $commits_to_sync =~ (^|[[:space:]])$actual_commit_id($|[[:space:]]) ]]; then + commits_to_sync="${actual_commit_id} ${commits_to_sync}" fi else # We reached the last commit synced @@ -78,6 +79,16 @@ function findCommitsToSync() { printf "$commits_to_sync" } +function plainCommit() { + local commit="${1:?Missing commit}" + local result="$commit" + actual_merge_commit_id="$(git log --pretty=%P -n 1 "$commit" | awk '{print $2}')" + if [[ -n "$actual_merge_commit_id" ]]; then + result="$(plainCommit $actual_merge_commit_id)" + fi + printf "$result" +} + syncCommit() { local -r commit_id="${1:?Missing commit id}" local -r app="${2:?Missing app name}" @@ -99,13 +110,7 @@ syncContainerCommits() { echo "Nothing to sync for ${name}" else for commit in "${commits_to_sync[@]}"; do - # If the commit is a merge, it has more than one parent, use the second to avoid re-applying an old commit - actual_merge_commit_id="$(git log --pretty=%P -n 1 "$commit" | awk '{print $2}')" - if [[ -n "$actual_merge_commit_id" ]]; then - syncCommit "$actual_merge_commit_id" "$name" - else - syncCommit "$commit" "$name" - fi + syncCommit "$commit" "$name" done fi git remote remove "$name"