|
| 1 | +#!/bin/sh |
| 2 | + |
| 3 | +die () { |
| 4 | + echo "$*" >&2 |
| 5 | + exit 1 |
| 6 | +} |
| 7 | + |
| 8 | +hex1='[0-9a-fA-F]' |
| 9 | +hex8="$hex1$hex1$hex1$hex1$hex1$hex1$hex1$hex1" |
| 10 | +hex40="$hex8$hex8$hex8$hex8$hex8" |
| 11 | +revision= |
| 12 | +title= |
| 13 | +set -x |
| 14 | +echo "$1" |
| 15 | +case "$1" in |
| 16 | +# 40 hexadecimal characters |
| 17 | +$hex40) revision=$1;; |
| 18 | +refs/pull/[0-9]*/head|refs/pull/[0-9]*/merge) |
| 19 | + # call `gh` to obtain the SHA-1 of the pull request |
| 20 | + pr_number="$(echo "$1" | |
| 21 | + sed -n 's,^refs/pull/\([0-9]*\)/\(head\|merge\)$,\1,p')" |
| 22 | + test -n "$pr_number" || die "Invalid pull request reference: $1" |
| 23 | + case "$1" in |
| 24 | + */head) json_field='.head.sha';; |
| 25 | + */merge) json_field='.merge_commit_sha';; |
| 26 | + esac |
| 27 | + revision="$(gh api repos/git-for-windows/msys2-runtime/pulls/"$pr_number" --jq "$json_field")" |
| 28 | + ;; |
| 29 | +*) die "Usage: $0 <revision>";; |
| 30 | +esac |
| 31 | + |
| 32 | +case "$revision" in |
| 33 | +$hex40) ;; # okay |
| 34 | +*) die "Invalid revision: $revision";; |
| 35 | +esac |
| 36 | + |
| 37 | +# `updpkgsums` requires the bare clone `msys2-runtime` to exist |
| 38 | +git init --bare msys2-runtime && |
| 39 | +git --git-dir=msys2-runtime config remote.origin.url https://github.com/cygwin/cygwin && |
| 40 | + |
| 41 | +git init --bare src/msys2-runtime && |
| 42 | +git --git-dir=src/msys2-runtime config remote.origin.url https://github.com/git-for-windows/msys2-runtime && |
| 43 | +# pretend to be a partial clone |
| 44 | +git --git-dir=src/msys2-runtime config remote.origin.promisor true && |
| 45 | +git --git-dir=src/msys2-runtime config remote.origin.partialCloneFilter blob:none || |
| 46 | +die "Failed to initialize the src/msys2-runtime repository" |
| 47 | + |
| 48 | +git --git-dir=src/msys2-runtime reset --soft "$revision" && |
| 49 | +previous_commit="$(cat msys2-runtime.commit)" && { |
| 50 | + test 0 = $(git --git-dir=src/msys2-runtime rev-list --count "$revision..$previous_commit") || |
| 51 | + die "The revision $revision is not a direct descendant of $previous_commit" |
| 52 | +} && |
| 53 | + |
| 54 | +# update pkgver if needed |
| 55 | +update_pkgver= && |
| 56 | +git --git-dir=src/msys2-runtime fetch --tags https://github.com/cygwin/cygwin && |
| 57 | +pkgver=$(git --git-dir=src/msys2-runtime describe --match='cygwin-[0-9]*' "$revision") && |
| 58 | +pkgver=${pkgver#cygwin-} && |
| 59 | +pkgver=${pkgver%%-*} && |
| 60 | +if test "$pkgver" != "$(sed -n 's/^pkgver=\(.*\)/\1/p' PKGBUILD)" |
| 61 | +then |
| 62 | + update_pkgver=t |
| 63 | + sed -i "s/^pkgver=.*/pkgver=$pkgver/" PKGBUILD && |
| 64 | + # the `update-patches.sh` script requires no uncommitted changes, but it also expects |
| 65 | + # the `pkgver` to be set correctly. |
| 66 | + git commit -sm 'msys2-runtime: WIP' PKGBUILD |
| 67 | +fi && |
| 68 | + |
| 69 | +# pre-fetch the required blobs |
| 70 | +git --git-dir=src/msys2-runtime fetch origin \ |
| 71 | + $(git --git-dir=src/msys2-runtime -c core.abbrev=no \ |
| 72 | + log --format='%n' --raw "refs/tags/cygwin-$pkgver..$revision" ^"$revision^{/^Start.the.merging-rebase}" | |
| 73 | + cut -d ' ' -f 3,4 | |
| 74 | + tr ' ' '\n' | |
| 75 | + grep -v '^0*$' | |
| 76 | + sort | |
| 77 | + uniq) && |
| 78 | + |
| 79 | +sh -x ./update-patches.sh && |
| 80 | +if test -n "$update_pkgver" |
| 81 | +then |
| 82 | + git reset --soft HEAD^ && |
| 83 | + sed -i 's/^pkgrel=.*/pkgrel=1/' PKGBUILD |
| 84 | +fi |
0 commit comments