-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathprepare-embargoed-branches.sh
More file actions
executable file
·132 lines (122 loc) · 4.1 KB
/
prepare-embargoed-branches.sh
File metadata and controls
executable file
·132 lines (122 loc) · 4.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/sh
die () {
echo "$*" >&2
exit 1
}
dry_run=
mingit=
while case "$1" in
--dry-run|-n) dry_run=1;;
--mingit) mingit=1;;
-*) die "Unknown option: $1";;
*) break;;
esac; do shift; done
test $# = 1 ||
die "Usage: $0 [--dry-run] [--mingit] <version> # e.g. 2.39.1"
version=${1#v}
if test -z "$mingit"
then
case "$version" in
*.*.*.windows.*)
# major.minor.patch.windows.extra
previous_version_prefix=${version%.windows.*}
version="${version%.windows.*}.${version##*.windows.}"
;;
*.*.*\(*)
# major.minor.patch(extra)
previous_version_prefix=${version%(*}
version="${version%(*}.${version##*(}"
version=${version%)}
;;
*[!0-9.]*|*..*|.*|*.) die "Invalid version: '$version'";;
*.*.*.*)
# major.minor.patch.extra
v0="${version#*.*.*.}"
previous_version=${version%.$v0}
previous_version_prefix=$previous_version
;;
*.*.*)
previous_version=${version%.*}.$((${version##*.}-1))
previous_version_prefix=$previous_version
;; # major.minor.patch
*) die "Invalid version: '$version'";;
esac
branch_name=git-$version
else
previous_version_prefix="$(expr "$version" : '\([0-9]\+\.[0-9]\+\)\.\{0,1\}[0-9]*$')"
test -n "$previous_version_prefix" || die "Invalid version: '$version'"
branch_name=mingit-$previous_version_prefix.x-releases
fi
case "$previous_version" in
2.46.3)
# There was no Git for Windows v2.46.3, so we use v2.46.2
previous_version=2.46.2
previous_version_prefix=2.46.2
;;
2.47.2)
# There was no Git for Windows v2.47.2, so we use v2.47.1(2)
previous_version=2.47.1.2
previous_version_prefix=2.47.1
;;
esac
grep_version_regex="$(echo "$previous_version_prefix" | sed 's/\./\\\\&/g')"
handle_repo () {
name="$1"
path="$2"
args="$3"
echo "### Handling $name ###" &&
if test -e "$path/.git"
then
git_dir="$path/.git"
main_refspec="refs/remotes/origin/main:refs/heads/main"
else
# To allow for running this script on Linux/macOS, fall back to cloning to pwd
git_dir=${path##*/}.git &&
if test ! -d "$git_dir"
then
# We only need a partial clone
git clone --bare --filter=blob:none \
https://github.com/git-for-windows/$name "$git_dir"
fi
main_refspec="refs/heads/main:refs/heads/main"
fi &&
# ensure that the `embargoed-git-for-windows-builds` remote is set
remote_url=https://github.com/embargoed-git-for-windows-builds/$name &&
case "$(git --git-dir "$git_dir" remote show -n embargoed-git-for-windows-builds)" in
*"Fetch URL: $remote_url"*"Push URL: $remote_url"*) ;; # okay
*) git --git-dir "$git_dir" remote add embargoed-git-for-windows-builds $remote_url;;
esac &&
# if `embargoed-git-for-windows-builds` already has the branch, everything's fine already
revision=$(git --git-dir "$git_dir" ls-remote embargoed-git-for-windows-builds refs/heads/$branch_name | cut -f 1) &&
if test -n "$revision"
then
echo "$name already has $branch_name @$revision"
else
git --git-dir "$git_dir" fetch origin main &&
revision="$(eval git --git-dir "\"$git_dir\"" rev-list -1 FETCH_HEAD $args)" &&
if test -z "$revision"
then
die "No matching revision for $args in $name"
fi &&
echo "Creating $branch_name in $name @$revision" &&
push_ref_spec="$revision:refs/heads/$branch_name $main_refspec" &&
if test -n "$dry_run"
then
git --git-dir "$git_dir" show -s "$revision" &&
echo "Would call 'git push embargoed-git-for-windows-builds $push_ref_spec'"
else
echo "git push embargoed-git-for-windows-builds $push_ref_spec" &&
git --git-dir "$git_dir" push embargoed-git-for-windows-builds $push_ref_spec
fi
fi
}
handle_repo git-sdk-32 /c/git-sdk-32 \
"\"--grep=mingw-w64-i686-git \".*\" -> $grep_version_regex\" -- cmd/git.exe" &&
handle_repo git-sdk-64 /c/git-sdk-64 \
"\"--grep=mingw-w64-x86_64-git \".*\" -> $grep_version_regex\" -- cmd/git.exe" &&
handle_repo git-sdk-arm64 /c/git-sdk-arm64 \
"\"--grep=mingw-w64-clang-aarch64-git \".*\" -> $grep_version_regex\" -- cmd/git.exe" &&
handle_repo build-extra /usr/src/build-extra \
"-- versions/package-versions-$previous_version_prefix\\*-MinGit.txt" &&
handle_repo MINGW-packages /usr/src/MINGW-packages \
"\"--grep=mingw-w64-git: new version .v$grep_version_regex\" -- mingw-w64-git/PKGBUILD"