forked from git-for-windows/build-extra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
please.sh
executable file
·5054 lines (4571 loc) · 147 KB
/
please.sh
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
# This script is meant to help maintain Git for Windows. It automates large
# parts of the release engineering.
#
# The major trick is to be able to update and build 32-bit as well as 64-bit
# packages. This is particularly problematic when trying to update files that
# are in use, such as msys-2.0.dll or bash.exe. To that end, this script is
# intended to run from a *separate* Bash, such as Git Bash.
#
# Common workflows:
#
# 1) release a new Git version
#
# <make sure that Git for Windows' main branch reflects the new version>
# ./please.sh sync
# ./please.sh finalize release-notes
# ./please.sh tag_git
# ./please.sh build git
# ./please.sh install git
# ./please.sh test_git 64
# ./please.sh upload git
# ./please.sh release
# ./please.sh publish
#
# 2) release a new Pacman package, e.g. git-extra or msys2-runtime
#
# ./please.sh sync
# <make sure that the main branch reflects the new version>
# ./please.sh build git-extra
# ./please.sh install git-extra
# <verify that everything's alright>
# ./please.sh upload git-extra
# Note: functions whose arguments are documented on the function name's own
# line are actually subcommands, and running this script without any argument
# will list all subcommands.
die () {
printf "$@" >&2
exit 1
}
# Never allow the SDKs to change directory to $HOME
export CHERE_INVOKING=1
# Never allow ORIGINAL_PATH to mess up our PATH
unset ORIGINAL_PATH
# Do not follow MSYS2's switch to zstd, at least for now
PKGEXT='.pkg.tar.xz'
export PKGEXT
# In MinGit, there is no `cygpath`...
# We really only use -w, -am and -au in please.sh, so that's what we
# support here
cygpath () { # [<short-options>] <path>
test $# = 2 ||
die "This minimal cygpath drop-in cannot handle '%s'\n" "$*"
case "$1" in
-w)
case "$2" in
/[a-zA-Z]/*)
echo "$2" |
sed -e 's|^/\(.\)\(.*\)|\u\1:\2|' -e 's|/|\\|g'
;;
[a-zA-Z]:[\\/]*)
echo "$2" |
sed -e 's|^\(.\)|\u\1|' -e 's|/|\\|g'
;;
/*)
echo "$(cd / && pwd -W)$2" |
sed -e 's|/|\\|g'
;;
*)
echo "$2" |
sed -e 's|/|\\|g'
;;
esac
;;
-am)
case "$2" in
/[a-zA-Z]/*)
echo "$2" |
sed -e 's|^/\(.\)\(.*\)|\u\1:\2|' -e 's|\\|/|g'
;;
[a-zA-Z]:[\\/]*)
echo "$2" |
sed -e 's|^\(.\)|\u\1|' -e 's|\\|/|g'
;;
/*)
echo "$(cd / && pwd -W)$2" |
sed -e 's|\\|/|g'
;;
*)
echo "$(pwd -W)/$2" |
sed -e 's|\\|/|g' -e 's|//*|/|g'
;;
esac
;;
-au)
case "$2" in
/[a-zA-Z]/*)
echo "$2" |
sed -e 's|^/\(.\)\(.*\)|/\l\1\2|' -e 's|\\|/|g'
;;
[a-zA-Z]:[\\/]*)
echo "$2" |
sed -e 's|^\(.\):|/\l\1|' -e 's|\\|/|g'
;;
/*)
echo "$2" |
sed -e 's|\\|/|g'
;;
*)
echo "$(pwd)/$2" |
sed -e 's|\\|/|g' -e 's|//*|/|g'
;;
esac
;;
*)
die "Unhandled cygpath option: '%s'\n" "$1"
;;
esac
}
sdk_path () { # <bitness>
result="$(git config windows.sdk"$1".path)" || {
result="C:/git-sdk-$1" && test -e "$result" ||
die "%s\n\n\t%s\n%s\n" \
"No $1-bit Git for Windows SDK found at location:" \
"C:/git-sdk-$1" \
"Config variable to override: windows.sdk$1.path"
}
echo "$result"
}
sdk64="$(sdk_path 64)"
sdk32="$(sdk_path 32)"
in_use () { # <sdk> <path>
test -n "$(case "$1" in
"$sdk32") "$1/mingw32/bin/WhoUses.exe" -m "$1$2";;
*) "$1/mingw64/bin/WhoUses.exe" -m "$1$2";;
esac | grep '^[^-P]')"
}
# require_not_in_use <sdk> <path>
require_not_in_use () {
! in_use "$@" ||
die "%s: in use\n" "$1/$2"
}
independent_shell=
is_independent_shell () { #
test -n "$independent_shell" || {
normalized64="$(cygpath -w "$sdk64")"
normalized32="$(cygpath -w "$sdk32")"
case "$(cygpath -w "$(which sh.exe)")" in
"$normalized64\\"*|"$normalized32\\"*)
independent_shell=f
;;
*)
independent_shell=t
;;
esac
}
test t = "$independent_shell"
}
info () { #
is_independent_shell && warning= ||
warning="WARNING: Current shell is not independent"
printf "%s\n%s\n%s" \
"Git for Windows 64-bit SDK: $sdk64" \
"Git for Windows 32-bit SDK: $sdk32" \
"$warning"
}
prepare_keep_despite_upgrade () { # <sdk-path>
keep_despite_upgrade="$(cat "${this_script_path%/*}/keep-despite-upgrade.txt")" ||
die 'Could not read keep-despite-upgrade.txt\n'
case "$keep_despite_upgrade" in *' '*) die 'keep-despite-upgrade.txt contains spaces!\n';; esac
test "$sdk64" = "$1" ||
keep_despite_upgrade="$(echo "$keep_despite_upgrade" | sed '/^mingw64/d')"
rm -rf "$1/.keep" &&
{ test -n "$keep_despite_upgrade" || return 0; } &&
mkdir -p "$1/.keep" &&
for f in $keep_despite_upgrade
do
d=${f%/*}
test $d = $f ||
mkdir -p "$1/.keep/$d"
cp "$1/$f" "$1/.keep/$d/" ||
break
done
}
process_keep_despite_upgrade () { # [--keep] <sdk-path>
test --keep != "$1" || {
test -d "$2/.keep" || return 0
cp -Ru "$2/.keep/"* "$2/"
return $?
}
test -d "$1/.keep" || return 0
cp -Ru "$1/.keep/"* "$1/" &&
rm -rf "$1/.keep"
}
sync () { # [--force]
force=
y_opt=y
only=
while case "$1" in
--force)
force='--overwrite=\*'
y_opt=yy
;;
--only-i686|--only-32-bit)
only="$sdk32"
;;
--only-x86_64|--only-64-bit)
only="$sdk64"
;;
-*) die "Unknown option: %s\n" "$1";;
*) break;;
esac; do shift; done
test $# = 0 ||
die "Expected no argument, got $#: %s\n" "$*"
export MSYSTEM=msys
export MSYS2_PATH_TYPE=minimal
for sdk in "$sdk32" "$sdk64"
do
test -z "$only" ||
test "$only" = "$sdk" ||
continue
mkdir -p "$sdk/var/log" ||
die "Could not ensure %s/var/log/ exists\n" "$sdk"
remove_obsolete_packages ||
die "Could not remove obsolete packages\n"
"$sdk/git-cmd.exe" --command=usr\\bin\\bash.exe -lc \
"for key in 4A6129F4E4B84AE46ED7F635628F528CF3053E04 \
5F944B027F7FE2091985AA2EFA11531AA0AA7F57
do
pacman-key --list-keys \$key >/dev/null 2>&1 || {
pacman-key --recv-keys \$key &&
pacman-key --lsign-key \$key;
} || exit 1
done
pacman.exe -S$y_opt" ||
die "Cannot run pacman in %s\n" "$sdk"
prepare_keep_despite_upgrade "$sdk" ||
die 'Could not keep files as planned\n'
"$sdk/git-cmd.exe" --cd="$sdk" --command=usr\\bin\\bash.exe \
-lc 'pacman.exe -Su '$force' --noconfirm' ||
die "Could not update packages in %s\n" "$sdk"
"$sdk/git-cmd.exe" --command=usr\\bin\\bash.exe -l -c '
pacman-key --list-keys BB3AA74136C569BB >/dev/null ||
pacman-key --populate git-for-windows' ||
die "Could not re-populate git-for-windows-keyring\n"
process_keep_despite_upgrade --keep "$sdk" ||
die 'Could not copy back files-to-keep\n'
case "$(tail -c 16384 "$sdk/var/log/pacman.log" |
grep '\[PACMAN\] starting .* system upgrade' |
tail -n 1)" in
*"full system upgrade")
;; # okay
*)
# only "core" packages were updated, update again
"$sdk/git-cmd.exe" --cd="$sdk" \
--command=usr\\bin\\bash.exe -l \
-c 'pacman -Su '$force' --noconfirm' ||
die "Cannot update packages in %s\n" "$sdk"
process_keep_despite_upgrade --keep "$sdk" ||
die 'Could not copy back files-to-keep\n'
"$sdk/git-cmd.exe" --command=usr\\bin\\bash.exe -l -c '
pacman-key --list-keys BB3AA74136C569BB \
>/dev/null ||
pacman-key --populate git-for-windows' ||
die "Could not re-populate git-for-windows-keyring\n"
;;
esac
process_keep_despite_upgrade "$sdk" ||
die 'Could not copy back files-to-keep\n'
# A ruby upgrade (or something else) may require a re-install
# of the `asciidoctor` gem. We only do this for the 64-bit
# SDK, though, as we require asciidoctor only when building
# Git, whose 32-bit packages are cross-compiled in from 64-bit.
test "$sdk64" != "$sdk" ||
"$sdk/git-cmd.exe" --command=usr\\bin\\bash.exe -l -c \
'test -n "$(gem list --local | grep "^asciidoctor ")" ||
gem install asciidoctor || exit;
export PATH=/mingw32/bin:$PATH;
test -n "$(gem list --local | grep "^asciidoctor ")" ||
gem install asciidoctor' ||
die "Could not re-install asciidoctor in %s\n" "$sdk"
# git-extra rewrites some files owned by other packages,
# therefore it has to be (re-)installed now
"$sdk/git-cmd.exe" --command=usr\\bin\\bash.exe -l -c \
'pacman -S '$force' --noconfirm git-extra' ||
die "Cannot update git-extra in %s\n" "$sdk"
pacnew="$(sed -ne '/starting core system upgrade/{
:1;
s/.*/WAIT/;x
:2;
n;
/warning:.*installed as .*\.pacnew$/{s/.* as //;H;b2}
/starting full system upgrade/{x;s/WAIT//;x;b2}
/starting core system upgrade/{x;/WAIT/{x;b2};b1}
${x;s/WAIT//;s/^\n//;/./p}
b2;
}' <"$sdk"/var/log/pacman.log)" ||
die "Could not get list of .pacnew files\n"
if test -n "$pacnew"
then
# Make sure we have the git-extra package locally, as
# one of the .pacnew files could be pacman.conf, and
# replacing it removes the link to Git for Windows'
# Pacman repository
"$sdk/git-cmd.exe" --command=usr\\bin\\bash.exe -l -c \
'pkg=/var/cache/pacman/pkg/$(pacman -Q git-extra |
tr \ -)*.pkg.tar.xz
test -f $pkg || {
pacman -Sw --noconfirm git-extra &&
test -f $pkg || {
echo "Could not cache $pkg" >&2
exit 1
}
}
for f in '"$(echo "$pacnew" | tr '\n' ' ')"'
do
test ! -f $f ||
mv -f $f ${f%.pacnew} || {
echo "Could not rename $f" >&2
exit 1
}
done
pacman -U --noconfirm '$force' $pkg || {
echo "Could not reinstall $pkg" >&2
exit 1
}' ||
die "Could not handle .pacnew files\n"
fi
done
}
run () { # <bitness> <command> [<arg>...]
test 32 = "$1" || test 64 = "$1" || die "Which bitness?\n"
sdk="$(eval "echo \$sdk$1")"
shift
cmd_line=eval
for arg
do
cmd_line="$cmd_line '$(echo "$arg" | sed -e "s/'/&\\\\&&/g")'"
done
"$sdk/git-cmd.exe" --command=usr\\bin\\sh.exe -l -c "$cmd_line"
}
killall () { # <bitness>
sdk="$(eval "echo \$sdk$1")"
pids="$("$sdk/git-cmd.exe" --command=usr\\bin\\ps.exe -s |
grep -v ' /usr/bin/ps$' |
sed -n "s/^ *\([0-9][0-9]*\).*/\1/p")"
test -z "$pids" ||
"$sdk/git-cmd.exe" --command=usr\\bin\\kill.exe $pids
}
mount_sdks () { #
test -d /sdk32 || mount "$sdk32" /sdk32
test -d /sdk64 || mount "$sdk64" /sdk64
}
# set_package <package>
set_package () {
package="$1"
extra_packages=
extra_makepkg_opts=
case "$package" in
git-extra)
type=MINGW
pkgpath=/usr/src/build-extra/$package
;;
git-for-windows-keyring)
type=MSYS
pkgpath=/usr/src/build-extra/$package
;;
git)
package=mingw-w64-git
extra_packages="mingw-w64-git-doc-html mingw-w64-git-doc-man mingw-w64-git-test-artifacts mingw-w64-git-pdb"
type=MINGW
pkgpath=/usr/src/MINGW-packages/$package
;;
mingw-w64-git)
type=MINGW
extra_packages="mingw-w64-git-doc-html mingw-w64-git-doc-man mingw-w64-git-test-artifacts mingw-w64-git-pdb"
pkgpath=/usr/src/MINGW-packages/$package
;;
mingw-w64-git-credential-manager)
type=MINGW
pkgpath=/usr/src/build-extra/mingw-w64-git-credential-manager
;;
gcm|credential-manager|git-credential-manager)
package=mingw-w64-git-credential-manager
type=MINGW
pkgpath=/usr/src/build-extra/mingw-w64-git-credential-manager
;;
mingw-w64-git-credential-manager-core)
type=MINGW
pkgpath=/usr/src/build-extra/mingw-w64-git-credential-manager-core
;;
gcm|credential-manager-core|git-credential-manager-core)
package=mingw-w64-git-credential-manager-core
type=MINGW
pkgpath=/usr/src/build-extra/mingw-w64-git-credential-manager-core
;;
lfs|git-lfs|mingw-w64-git-lfs)
package=mingw-w64-git-lfs
type=MINGW
pkgpath=/usr/src/build-extra/mingw-w64-git-lfs
;;
git-sizer|mingw-w64-git-sizer)
package=mingw-w64-git-sizer
type=MINGW
pkgpath=/usr/src/build-extra/mingw-w64-git-sizer
;;
cv2pdb|mingw-w64-cv2pdb)
package=mingw-w64-cv2pdb
type=MINGW
pkgpath=/usr/src/build-extra/mingw-w64-cv2pdb
;;
pcre2|mingw-w64-pcre2)
package=mingw-w64-pcre2
type=MINGW
pkgpath=/usr/src/MINGW-packages/mingw-w64-pcre2
;;
busybox|mingw-w64-busybox)
package=mingw-w64-busybox
type=MINGW
extra_packages="mingw-w64-busybox-pdb"
pkgpath=/usr/src/MINGW-packages/mingw-w64-busybox
;;
msys2-runtime)
type=MSYS
extra_packages="msys2-runtime-devel"
pkgpath=/usr/src/MSYS2-packages/$package
;;
mintty)
type=MSYS
pkgpath=/usr/src/MSYS2-packages/$package
;;
w3m)
type=MSYS
pkgpath=/usr/src/MSYS2-packages/$package
;;
openssh)
type=MSYS
pkgpath=/usr/src/MSYS2-packages/$package
;;
openssl)
type=MSYS
extra_packages="libopenssl openssl-devel"
pkgpath=/usr/src/MSYS2-packages/$package
extra_makepkg_opts=--nocheck
;;
mingw-w64-openssl)
type=MINGW
extra_packages="mingw-w64-openssl-pdb"
pkgpath=/usr/src/MINGW-packages/$package
;;
gnutls)
type=MSYS
extra_packages="libgnutls libgnutls-devel"
pkgpath=/usr/src/MSYS2-packages/$package
;;
mingw-w64-gnutls)
type=MINGW
pkgpath=/usr/src/MINGW-packages/$package
;;
curl)
type=MSYS
extra_packages="libcurl libcurl-devel"
pkgpath=/usr/src/MSYS2-packages/$package
;;
mingw-w64-curl)
type=MINGW
extra_packages="mingw-w64-curl-pdb"
pkgpath=/usr/src/MINGW-packages/$package
;;
git-flow)
type=MSYS
pkgpath=/usr/src/MSYS2-packages/$package
;;
p7zip)
type=MSYS
pkgpath=/usr/src/MSYS2-packages/$package
;;
mingw-w64-asciidoctor-extensions)
type=MINGW
pkgpath=/usr/src/MINGW-packages/$package
;;
wintoast|mingw-w64-wintoast)
package=mingw-w64-wintoast
type=MINGW
pkgpath=/usr/src/build-extra/mingw-w64-wintoast
;;
bash)
type=MSYS
extra_packages="$package-devel"
pkgpath=/usr/src/MSYS2-packages/$package
;;
heimdal)
type=MSYS
extra_packages="$package-libs $package-devel"
pkgpath=/usr/src/MSYS2-packages/$package
;;
perl)
type=MSYS
pkgpath=/usr/src/MSYS2-packages/$package
extra_makepkg_opts=--nocheck
;;
perl-Net-SSLeay|perl-HTML-Parser|perl-TermReadKey|perl-Locale-Gettext|perl-XML-Parser|perl-YAML-Syck)
type=MSYS
pkgpath=/usr/src/MSYS2-packages/$package
;;
tig)
type=MSYS
pkgpath=/usr/src/MSYS2-packages/$package
;;
subversion)
type=MSYS
pkgpath=/usr/src/MSYS2-packages/$package
;;
gawk)
type=MSYS
pkgpath=/usr/src/MSYS2-packages/$package
extra_makepkg_opts=--nocheck
;;
nodejs|mingw-w64-nodejs)
package=mingw-w64-nodejs
type=MINGW
pkgpath=/usr/src/MINGW-packages/mingw-w64-nodejs
extra_makepkg_opts=--nocheck
;;
xpdf|xpdf-tools|mingw-w64-xpdf-tools)
package=mingw-w64-xpdf-tools
type=MINGW
pkgpath=/usr/src/MINGW-packages/mingw-w64-xpdf
;;
serf)
type=MSYS
pkgpath=/usr/src/MSYS2-packages/$package
;;
pkgconf)
type=MSYS
pkgpath=/usr/src/MSYS2-packages/$package
;;
libgpg-error)
type=MSYS
extra_packages="libgpg-error-devel"
pkgpath=/usr/src/MSYS2-packages/$package
;;
libgcrypt)
type=MSYS
extra_packages="libgcrypt-devel"
pkgpath=/usr/src/MSYS2-packages/$package
;;
gnupg)
type=MSYS
pkgpath=/usr/src/MSYS2-packages/$package
;;
libcbor)
type=MSYS
extra_packages="$package-devel"
pkgpath=/usr/src/MSYS2-packages/$package
;;
libfido2)
type=MSYS
extra_packages="$package-devel"
pkgpath=/usr/src/MSYS2-packages/$package
;;
*)
die "Unknown package: %s\n" "$package"
;;
esac
}
# foreach_sdk <function> [<args>]
foreach_sdk () {
# Run function in 32-bit/64-bit SDKs (only 64-bit for MINGW packages)
for sdk in "$sdk32" "$sdk64"
do
# MINGW packages are compiled in the 64-bit SDK only
test "a$sdk64" = "a$sdk" ||
test MINGW != "$type" ||
continue
(cd "$sdk$pkgpath" ||
die "%s does not exist\n" "$sdk$pkgpath"
"$@") ||
die "Could not run '%s' in '%s'\n" "$*" "$sdk"
done
}
require_clean_worktree () {
git update-index --ignore-submodules --refresh &&
git diff-files --ignore-submodules &&
git diff-index --cached --ignore-submodules HEAD ||
die "%s not up-to-date\n" "$sdk$pkgpath"
}
ff_main_branch () {
case "$(git rev-parse --symbolic-full-name HEAD)" in
refs/heads/main) ;; # okay
refs/heads/master)
git branch -m main ||
die "%s: could not rename the main branch\n" "$sdk$pkgpath"
;;
*)
die "%s: Not on 'main'\n" "$sdk$pkgpath"
;;
esac
require_clean_worktree
git pull --ff-only origin HEAD ||
die "%s: cannot fast-forward main branch\n" "$sdk$pkgpath"
}
update () { # <package>
if test git != "$1" && test -d "$sdk64"/usr/src/"$1"
then
pkgpath=/usr/src/"$1"
else
set_package "$1"
fi
foreach_sdk ff_main_branch
}
remove_obsolete_packages () {
test "a$sdk" = "a$sdk32" &&
arch=i686 ||
arch=x86_64
for p in mingw-w64-$arch-curl-winssl-bin
do
test ! -d "$sdk"/var/lib/pacman/local/$p-[0-9]* ||
"$sdk"/git-cmd.exe --command=usr\\bin\\pacman.exe \
-R --noconfirm $p ||
die "Could not remove %s\n" "$p"
done
}
# require <metapackage> <telltale>
require () {
test -d "$sdk"/var/lib/pacman/local/"${2:-$1}"-[0-9]* ||
"$sdk"/git-cmd.exe --command=usr\\bin\\pacman.exe \
-Sy --needed --noconfirm "$1" ||
die "Could not install %s\n" "$1"
}
install_git_32bit_prereqs () {
require mingw-w64-i686-asciidoctor-extensions
}
pkg_build () {
require_clean_worktree
test "a$sdk" = "a$sdk32" &&
arch=i686 ||
arch=x86_64
# Git for Windows' packages are only visible to the SDK of the
# matching architecture. However, we want to build Git for both
# 32-bit and 64-bit in the 64-bit SDK at the same time, therefore
# we need even the prerequisite asciidoctor-extensions for 32-bit.
# Let's just steal it from the 32-bit SDK
test mingw-w64-git != $package ||
test x86_64 != $arch ||
install_git_32bit_prereqs
case "$type" in
MINGW)
require mingw-w64-toolchain mingw-w64-$arch-make
if test mingw-w64-git = "$package"
then
tag="$(git --git-dir=src/git/.git for-each-ref \
--format='%(refname:short)' --sort=-taggerdate \
--count=1 'refs/tags/*.windows.*')" &&
test -n "$tag" ||
die "Could not determine latest tag\n"
sed -i "s/^\(tag=\).*/\1${tag#v}/" PKGBUILD ||
die "Could not edit tag\n"
fi
if test -z "$(git --git-dir="$sdk64/usr/src/build-extra/.git" \
config alias.signtool)"
then
extra=
else
extra="SIGNTOOL=\"git --git-dir=\\\"$sdk64/usr/src"
extra="$extra/build-extra/.git\\\" signtool\" "
fi
"$sdk/git-cmd.exe" --command=usr\\bin\\sh.exe -l -c \
'MAKEFLAGS=-j5 MINGW_INSTALLS=mingw32\ mingw64 \
'"$extra"'makepkg-mingw -s --noconfirm \
'"$extra_makepkg_opts"' &&
if test mingw-w64-git = "'"$package"'"
then
git -C src/git push "$PWD/git" \
refs/tags/"'"$tag"'"
fi &&
MINGW_INSTALLS=mingw64 makepkg-mingw --allsource \
'"$extra_makepkg_opts" ||
die "%s: could not build\n" "$sdk$pkgpath"
git update-index -q --refresh &&
git diff-files --quiet --ignore-submodules PKGBUILD ||
git commit -s -m "$package: new version" PKGBUILD ||
die "%s: could not commit after build\n" "$sdk$pkgpath"
;;
MSYS)
require msys2-devel binutils
opt_j=-j5
if test msys2-runtime = "$package"
then
opt_j=-j1
require mingw-w64-cross-crt-git mingw-w64-cross-gcc
test ! -d msys2-runtime ||
git -C msys2-runtime fetch ||
die "Could not fetch from origin"
test ! -d src/msys2-runtime/.git ||
(cd src/msys2-runtime &&
case "$(test -x /usr/bin/git && cat .git/objects/info/alternates 2>/dev/null)" in
/*)
echo "dissociating worktree, to allow MINGW Git to access the worktree" >&2 &&
/usr/bin/git repack -ad &&
rm .git/objects/info/alternates
;;
esac &&
if test -n "$(git config remote.upstream.url)"
then
git fetch upstream
else
git remote add -f upstream \
https://github.com/Alexpux/Cygwin
fi &&
if test -n "$(git config remote.cygwin.url)"
then
git fetch --tags cygwin
else
git remote add -f cygwin \
git://sourceware.org/git/newlib-cygwin.git
fi) ||
die "Could not update msys2-runtime's upstream\n"
fi
"$sdk/git-cmd" --command=usr\\bin\\sh.exe -l -c \
'cd '"$pkgpath"' &&
export MSYSTEM=MSYS &&
export PATH=/usr/bin:/opt/bin:$PATH &&
unset ORIGINAL_PATH &&
. /etc/profile &&
MAKEFLAGS='"$opt_j"' makepkg -s --noconfirm \
'"$extra_makepkg_opts"' &&
makepkg --allsource '"$extra_makepkg_opts" ||
die "%s: could not build\n" "$sdk$pkgpath"
if test "a$sdk32" = "a$sdk"
then
git update-index -q --refresh &&
git diff-files --quiet --ignore-submodules PKGBUILD ||
git commit -s -m "$package: new version" PKGBUILD ||
die "%s: could not commit after build\n" "$sdk$pkgpath"
else
git add PKGBUILD &&
git pull "$sdk32/${pkgpath%/*}/.git" \
"$(git rev-parse --symbolic-full-name HEAD)" &&
require_clean_worktree ||
die "%s: unexpected difference between 32/64-bit\n" \
"$pkgpath"
fi
;;
esac
}
fast_forward () {
if test -d "$2"/.git
then
git -C "$1" fetch "$2" refs/heads/main
else
git -C "$1" fetch "$2"/.. refs/heads/main
fi &&
git -C "$1" merge --ff-only "$3" &&
test "a$3" = "a$(git -C "$1" rev-parse --verify HEAD)"
}
# up_to_date <path>
up_to_date () {
# test that repos at <path> are up-to-date in both 64-bit and 32-bit
pkgpath="$1"
foreach_sdk require_clean_worktree
commit32="$(cd "$sdk32$pkgpath" && git rev-parse --verify HEAD)" &&
commit64="$(cd "$sdk64$pkgpath" && git rev-parse --verify HEAD)" ||
die "Could not determine HEAD commit in %s\n" "$pkgpath"
if test "a$commit32" != "a$commit64"
then
fast_forward "$sdk32$pkgpath" "$sdk64$pkgpath" "$commit64" ||
fast_forward "$sdk64$pkgpath" "$sdk32$pkgpath" "$commit32" ||
die "%s: commit %s (32-bit) != %s (64-bit)\n" \
"$pkgpath" "$commit32" "$commit64"
fi
}
build () { # [--force] [--cleanbuild] <package>
force=
cleanbuild=
while case "$1" in
-f|--force)
force=--force
;;
--cleanbuild)
cleanbuild=--cleanbuild
;;
-*) die "Unknown option: %s\n" "$1";;
*) break;;
esac; do shift; done
test $# = 1 ||
die "Expected 1 argument, got $#: %s\n" "$*"
set_package "$1"
extra_makepkg_opts="$extra_makepkg_opts $force $cleanbuild"
test MINGW = "$type" ||
up_to_date "$pkgpath" ||
die "%s: not up-to-date\n" "$pkgpath"
foreach_sdk pkg_build $force $cleanbuild ||
die "Could not build '%s'\n" "$package"
}
# require_remote <nickname> <url>
require_remote () {
if test -z "$(git config remote."$1".url)"
then
git remote add -f "$1" "$2"
else
test "$2" = "$(git config remote."$1".url)" ||
die "Incorrect URL for %s: %s\n" \
"$1" "$(git config remote."$1".url)"
git fetch "$1"
fi ||
die "Could not fetch from %s\n" "$1"
}
# require_push_url # [<remote>]
require_push_url () {
remote=${1:-origin}
if ! grep -q '^Host github.com$' "$HOME/.ssh/config" 2>/dev/null
then
# Allow build agents to use Personal Access Tokens
url="$(git config remote."$remote".url)" &&
case "$(git config http."$url".extraHeader)" in
Authorization:*) true;; # okay
*) false;;
esac ||
die "No github.com entry in ~/.ssh/config\n"
elif test -z "$(git config remote."$remote".pushurl)"
then
pushurl="$(git config remote."$remote".url |
sed -n 's|^https://github.com/\(.*\)|github.com:\1|p')"
test -n "$pushurl" ||
die "Not a GitHub remote: %s\n" "$remote"
git remote set-url --push "$remote" "$pushurl" ||
die "Could not set push URL of %s to %s\n" "$remote" "$pushurl"
fi
}
whatis () {
git show -s --pretty='tformat:%h (%s, %ad)' --date=short "$@"
}
is_rebasing () {
test -d "$(git rev-parse --git-path rebase-merge)"
}
has_merge_conflicts () {
test -n "$(git ls-files --unmerged)"
}
record_rerere_train () {
conflicts="$(git ls-files --unmerged)" &&
test -n "$conflicts" ||
die "No merge conflicts?!?\n"
commit="$(git rev-parse -q --verify refs/heads/rerere-train)" ||
commit="$(git rev-parse -q --verify \
refs/remotes/git-for-windows/rerere-train)"
if test -z "$GIT_INDEX_FILE"
then
GIT_INDEX_FILE="$(git rev-parse --git-path index)"
fi &&
orig_index="$GIT_INDEX_FILE" &&
(GIT_INDEX_FILE="$orig_index.tmp" &&
export GIT_INDEX_FILE &&
for stage in 1 2 3
do
cp "$orig_index" "$GIT_INDEX_FILE" &&
echo "$conflicts" |
sed -n "s/^\\([^ ]* [^ ]* \\)$stage/\\10/p" |
git update-index --index-info &&
git ls-files --unmerged |
sed -n "s/^[^ ]*/0/p" |
git update-index --index-info &&
eval tree$stage="$(git write-tree)" ||
die "Could not write tree %s\n" "$stage"
done &&
cp "$orig_index" "$GIT_INDEX_FILE" &&
git add -u &&
tree4="$(git write-tree)" &&
if ! stopped_sha="$(git rev-parse --git-path \
rebase-merge/stopped-sha)" ||
! stopped_sha="$(cat "$stopped_sha")"
then
stopped_sha="$(git rev-parse -q --verify MERGE_HEAD)"
fi &&
base_msg="$(printf "cherry-pick %s onto %s\n\n%s\n%s\n\n\t%s" \
"$(git show -s --pretty=tformat:%h $stopped_sha)" \
"$(git show -s --pretty=tformat:%h HEAD)" \
"This commit helps to teach \`git rerere\` to resolve merge " \
"conflicts when cherry-picking:" \
"$(whatis $stopped_sha)")" &&
commit=$(git commit-tree ${commit:+-p} $commit \
-m "base: $base_msg" $tree1) &&
commit2=$(git commit-tree -p $commit -m "pick: $base_msg" $tree3) &&
commit=$(git commit-tree -p $commit -m "upstream: $base_msg" $tree2) &&
commit=$(git commit-tree -p $commit -p $commit2 \
-m "resolve: $base_msg" $tree4) &&
git update-ref -m "$base_msg" refs/heads/rerere-train $commit) || exit
git add -u &&
git rerere
}
rerere_train () {
git rev-list --reverse --parents "$@" |
while read commit parent1 parent2 rest
do
test -n "$parent2" && test -z "$rest" || continue
printf "Learning merge conflict resolution from %s\n" \
"$(whatis "$commit")" >&2
(GIT_CONFIG_PARAMETERS="$GIT_CONFIG_PARAMETERS${GIT_CONFIG_PARAMETERS:+ }'rerere.enabled=true'" &&
export GIT_CONFIG_PARAMETERS &&
worktree="$(git rev-parse --git-path train)" &&
if test ! -d "$worktree"
then
git worktree add "$worktree" "$parent1" ||
die "Could not create worktree %s\n" "$worktree"
fi &&
cd "$worktree" &&
git checkout -f -q "$parent1" &&
git reset -q --hard &&