Advertisement
Lucun_Ji

reinvent-git-merge.sh

Jul 3rd, 2025
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.15 KB | None | 0 0
  1. set -e
  2.  
  3. git clone --branch "$branch" --depth 1 "$repository" "$clone_path"
  4.  
  5. cd "$clone_path"
  6. git fetch "$upstream_repository" "$upstream_branch":upstream
  7.  
  8. echo "upstream_last_commit=$(git log --pretty='%H' --max-count 1 upstream)" >> "$GITHUB_OUTPUT"
  9.  
  10. last_rebased_tag="$(git describe --tags --match="upstream-commit-[0-9a-z]*" "$branch")"
  11. last_rebased_hash="$(git tag --format='%(subject)' -l "$last_rebased_tag")"
  12. echo "Pickup commit $last_rebased_hash from where last rebase finished."
  13.  
  14. hash_before_rebase="$(git log --max-count 1 --pretty='%H')"
  15. git rebase --onto "$branch" "$last_rebased_hash" upstream || rebase_errno=$?
  16. hash_after_rebase="$(git log --max-count 1 --pretty='%H')"
  17.  
  18. if [ "$rebase_errno" ];
  19. then
  20.     echo "Rebase failed, trying to best-effort it."
  21.     git rebase --abort
  22. fi
  23.  
  24. if [ "$hash_before_rebase" == "$hash_after_rebase" ];
  25. then
  26.     echo "Same hash before and after rebasing, exiting."
  27. else
  28.     git branch --force "$branch" "$hash_after_rebase"
  29.    
  30.     echo "Make PR, record last upstream commit in PR message"
  31.  
  32.     # detect landing of pr, tag the last commit with
  33.     # git tag "upstream-commit-$(...)" -m "$(...)"
  34. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement