-
Notifications
You must be signed in to change notification settings - Fork 612
/
please.sh
executable file
·3726 lines (3399 loc) · 110 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.
#
# Most of these functions are called from automation, i.e. from Azure Pipelines
# and from GitHub workflows
# 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
SRCEXT='.src.tar.gz'
export SRCEXT
# 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"
}
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"
}
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|mingw-w64-git-extra)
package=mingw-w64-git-extra
type=MINGW
# This will need to be replaced with mingw-w64-git-extra once the folder has been renamed
pkgpath=/usr/src/build-extra/git-extra
;;
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
;;
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|perl-Clone)
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
;;
mingw-w64-connect)
type=MINGW
pkgpath=/usr/src/MINGW-packages/$package
;;
*)
die "Unknown package: %s\n" "$package"
;;
esac
}
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 ||
test 0 -eq $(git rev-list --count ..FETCH_HEAD) ||
die "%s: cannot fast-forward main branch\n" "$sdk$pkgpath"
}
# 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
}
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 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_ARCH=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_ARCH=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 -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
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:/mingw64/bin:/mingw32/bin:$PATH &&
unset ORIGINAL_PATH &&
. /etc/profile &&
MAKEFLAGS='"$opt_j"' '"$extra"'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"
(cd "$pkgpath" && 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
}
# 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)"
}
# ensure_valid_login_shell <bitness>
ensure_valid_login_shell () {
# Only perform this stunt for special accounts, such as NETWORK SERVICE
test 256 -gt "$UID" ||
return 0
sdk="$(eval "echo \$sdk$1")"
"$sdk/git-cmd" --command=usr\\bin\\sh.exe -c '
# use `strace` to avoid segmentation faults for special accounts
line="$(strace -o /dev/null mkpasswd -c | grep -v ^create)"
case "$line" in
*/nologin)
if ! grep -q "^${line%%:*}" /etc/passwd 2>/dev/null
then
echo "${line%:*}:/usr/bin/bash" >>/etc/passwd
fi
;;
esac' >&2
}
require_git_src_dir () {
sdk="$sdk64"
if test ! -d "$git_src_dir"
then
if test ! -d "${git_src_dir%/src/git}"
then
mingw_packages_dir="${git_src_dir%/*/src/git}"
if test ! -d "$mingw_packages_dir"
then
case "$mingw_packages_dir" in
*/MINGW-packages)
o=https://github.com/git-for-windows &&
git -C "${mingw_packages_dir%/*}" \
clone $o/MINGW-packages ||
die "Could not clone into %s\n" \
"$mingw_packages_dir"
;;
*)
die "Do not know how to clone %s\n" \
"$mingw_packages_dir"
;;
esac
else
git -C "$mingw_packages_dir" fetch &&
git -C "$mingw_packages_dir" \
checkout -t origin/main ||
die "Could not check out %s\n" \
"$mingw_packages_dir"
fi
fi
(cd "${git_src_dir%/src/git}" &&
echo "Checking out Git (not making it)" >&2 &&
"$sdk64/git-cmd" --command=usr\\bin\\sh.exe -l -c \
'makepkg-mingw --noconfirm -s -o' &&
case "$(test -x /usr/bin/git && cat src/git/.git/objects/info/alternates 2>/dev/null)" in
/*)
echo "Dissociating worktree, to allow MINGW git to access the worktree" >&2 &&
/usr/bin/git -C src/git/ repack -ad &&
rm src/git/.git/objects/info/alternates
;;
esac) ||
die "Could not initialize %s\n" "$git_src_dir"
fi
test ! -f "$git_src_dir/PKGBUILD" ||
(cd "$git_src_dir/../.." &&
sdk= pkgpath=$PWD ff_main_branch) ||
die "MINGW-packages not up-to-date\n"
test false = "$(git -C "$git_src_dir" config core.autoCRLF)" ||
(cd "$git_src_dir" &&
git config core.autoCRLF false &&
rm .git/index
git reset --hard) ||
die "Could not make sure Git sources are checked out LF-only\n"
}
# build_and_test_64; intended to build and test 64-bit Git in MINGW-packages
build_and_test_64 () {
skip_tests=
filter_make_test=" | perl -ne '"'
s/^ok \d+ # skip/skipped:/;
unless (
/^1..[0-9]*/ or
/^ok [0-9]*/ or
/^# passed all [0-9]* test\(s\)/ or
/^# passed all remaining [0-9]* test\(s\)/ or
/^# still have [0-9]* known breakage\(s\)/
) {
s/^not ok \d+ -(.*)# TODO known breakage/known e:$1/;
s/^\*\*\* (.+) \*\*\*/$1/;
s/(.+)/ $1/ unless /^t\d{4}-|^make/;
print;
};
'"'; grep '^failed [^0]' t/test-results/*.counts"
test_opts=--quiet
no_svn_tests="NO_SVN_TESTS=1"
while case "$1" in
--skip-tests)
skip_tests=--skip-tests
;;
--full-log)
test_opts=
filter_make_test=
;;
--with-svn-tests)
no_svn_tests=
;;
-*) die "Unknown option: %s\n" "$1";;
*) break;;
esac; do shift; done
test $# = 0 ||
die "Expected no argument, got $#: %s\n" "$*"
make_t_prefix=
test -z "$test_opts" ||
make_t_prefix="GIT_TEST_OPTS=\"$test_opts\" $make_t_prefix"
test -z "$no_svn_tests" ||
make_t_prefix="$no_svn_tests $make_t_prefix"
ls //localhost/c$ >/dev/null 2>&1 || {
echo "Administrative shares unavailable; skipping t5580" >&2
export GIT_SKIP_TESTS="${GIT_SKIP_TESTS:+$GIT_SKIP_TESTS }t5580"
}
ensure_valid_login_shell 64 &&
GIT_CONFIG_PARAMETERS= \
"$sdk64/git-cmd" --command=usr\\bin\\sh.exe -l -c '
: make sure that the .dll files are correctly resolved: &&
cd $PWD &&
rm -f t/test-results/*.{counts,tee} &&
printf "\nBuilding Git...\n" >&2 &&
if ! make -j5 -k DEVELOPER=1
then
echo "Re-running build (to show failures)" >&2
make -k DEVELOPER=1 || {
echo "Build failed!" >&2
exit 1
}
fi &&
printf "\nTesting Git...\n" >&2 &&
if '"$(if test -z "$skip_tests"
then
printf '! %smake -C t -j5 -k%s\n' \
"$make_t_prefix" "$filter_make_test"
else
echo 'false'
fi)"'
then
cd t &&
failed_tests="$(cd test-results &&
grep -l "^failed [1-9]" t[0-9]*.counts)" || {
echo "No failed tests ?!?" >&2
exit 1
}
still_failing="$(git rev-parse --git-dir)/failing.txt"
rm -f "$still_failing"
for t in $failed_tests
do
t=${t%*.counts}
test -f "$t.sh" || {
t=${t%*-[1-9]*}
test -f "$t.sh" ||
echo "Cannot find script for $t" >&2
exit 1
}
echo "Re-running $t" >&2
time bash $t.sh -i -v -x ||
echo "$t.sh" >>"$still_failing"
done
test ! -s "$still_failing" || {
printf "Still failing:\n\n%s\n" \
"$(cat "$still_failing")" >&2
exit 1
}
fi'
}
needs_upload_permissions () {
grep -q '^machine api\.github\.com$' "$HOME"/_netrc &&
grep -q '^machine uploads\.github\.com$' "$HOME"/_netrc ||
die "Missing GitHub entries in ~/_netrc\n"
}
# <coverity-token>
init_or_update_coverity_tool () {
# check once per week whether there is a new version
coverity_tool=.git/coverity-tool
test ! -d $coverity_tool ||
test $(($(date +%s)-$(stat -c %Y $coverity_tool))) \
-gt $((7*24*60*60)) || return 0
echo "Downloading current Coverity Scan Self-Build tool" >&2
if test -f .git/coverity_tool.zip
then
timecond=.git/coverity_tool.zip
else
timecond="19700101 +0000"
fi
curl --form "token=$1" \
--form "project=git-for-windows" \
--time-cond "$timecond" \
-o .git/coverity_tool.zip.new \
https://scan.coverity.com/download/win64 &&
test -f .git/coverity_tool.zip.new || {
echo "Nothing downloaded; will try again in another week" >&2
test -d "$coverity_tool" || mkdir $coverity_tool
touch $coverity_tool
return
}
mv -f .git/coverity_tool.zip.new .git/coverity_tool.zip ||
die "Could not overwrite coverity_tool.zip"
mkdir $coverity_tool.new &&
(cd $coverity_tool.new &&
unzip ../coverity_tool.zip) ||
die "Could not unpack coverity_tool.zip"
rm -rf $coverity_tool &&
mv $coverity_tool.new $coverity_tool ||
die "Could not switch to new Coverity tool version"
}
submit_build_to_coverity () { # [--worktree=<dir>] <upstream-branch-or-tag>
git_src_dir="$sdk64/usr/src/MINGW-packages/mingw-w64-git/src/git"
while case "$1" in
--worktree=*)
git_src_dir=${1#*=}
test -d "$git_src_dir" ||
die "Worktree does not exist: %s\n" "$git_src_dir"
test -f "$git_src_dir/GIT-VERSION-GEN" ||
die "Does not appear to contain Git's source code: %s\n" "$git_src_dir"
;;
-*) die "Unknown option: %s\n" "$1";;
*) break;;
esac; do shift; done
test $# = 1 ||
die "Expected 1 argument, got $#: %s\n" "$*"
branch="$1"
coverity_username="$(git config coverity.username)"
test -n "$coverity_username" ||
die "Need a username to access Coverity's services\n"
coverity_token="$(git config coverity.token)"
test -n "$coverity_token" ||
die "Need a token to access Coverity's services\n"
ensure_valid_login_shell 64 ||
die "Could not ensure valid login shell\n"
sdk="$sdk64"
build_extra_dir="$sdk64/usr/src/build-extra"
(cd "$build_extra_dir" &&
sdk= pkgpath=$PWD ff_main_branch) ||
die "Could not update build-extra\n"
require_git_src_dir
(cd "$git_src_dir" &&
case "$branch" in
git-for-windows/*|v[1-9]*.windows.[1-9]*)
require_remote git-for-windows \
https://github.com/git-for-windows/git
case "$branch" in git-for-windows/refs/pull/[0-9]*)
git fetch git-for-windows \
"${branch#git-for-windows/}:refs/remotes/$branch" ||
die "Could not fetch %s from git-for-windows\n" \
"${branch#git-for-windows/}"
;;
esac
;;
upstream/*|v[1-9]*)
require_remote upstream https://github.com/git/git
case "$branch" in upstream/refs/pull/[0-9]*)
git fetch upstream "${branch#upstream/}:refs/remotes/$branch" ||
die "Could not fetch %s from upstream\n" \
"${branch#upstream/}"
;;
esac
;;
esac &&
git checkout -f "$branch" &&
git reset --hard &&
sed -i -e 's/^\(char strbuf_slopbuf\[\)1\]/\165536]/' strbuf.c &&
init_or_update_coverity_tool "$coverity_token" &&
coverity_bin_dir=$(echo $PWD/$coverity_tool/*/bin) &&
if ! test -x "$coverity_bin_dir/cov-build.exe"
then
die "Unusable Coverity bin/ directory: '%s'\n" \
"$coverity_bin_dir"
fi &&
PATH="$coverity_bin_dir:$PATH" &&
cov-configure --gcc &&
# Coverity has a long-standing bug where it fails to parse two-digit
# major versions of GCC incorrectly Since Synopsys seems to
# be hardly in a rush to fix this (there's no response at
# https://community.synopsys.com/s/question/0D52H000058Z6KvSAK/
# since May 2020), we meddle with Coverity's config files
gcc10_workaround="$(test -d cov-int || gcc -v 2>&1 |
sed -n 's/^gcc version \([1-9]\)\([0-9]\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\).*/s|\\<\\(\1\\)\\?\\(\2\\.\3\\.\4\\)\\>|\1\\2|g/p')" &&
if test -n "$gcc10_workaround"
then
rm -f version.o &&
cov-build --dir cov-int make DEVELOPER=1 version.o &&
find cov-int/emit/* -name \*.xml -exec sed -i "$gcc10_workaround" {} \; &&
rm -f version.o
fi &&
cov-build --dir cov-int \
make -j15 DEVELOPER=1 CPPFLAGS="-DFLEX_ARRAY=65536 -DSUPPRESS_ANNOTATED_LEAKS" &&
tar caf git-for-windows.lzma cov-int &&
curl --form token="$coverity_token" \
--form email="$coverity_username" \
--form [email protected] \
--form version="$(git rev-parse HEAD)" \
--form version="$(date +%Y-%m-%s-%H-%M-%S)" \
https://scan.coverity.com/builds?project=git-for-windows) ||
die "Could not submit build to Coverity\n"
}
tag_git () { # [--force]
force=
branch_to_use=
while case "$1" in
-f|--force)
force=--force
;;
--use-branch=*) branch_to_use="${1#*=}";;
-*) die "Unknown option: %s\n" "$1";;
*) break;;
esac; do shift; done
test $# = 0 ||
die "Expected no argument, got $#: %s\n" "$*"
sdk="$sdk64" require w3m
build_extra_dir="$sdk64/usr/src/build-extra"
(cd "$build_extra_dir" &&
sdk= pkgpath=$PWD ff_main_branch) ||
die "Could not update build-extra\n"
git_src_dir="$sdk64/usr/src/MINGW-packages/mingw-w64-git/src/git"
(cd "$git_src_dir" &&
require_remote upstream https://github.com/git/git &&
require_remote git-for-windows \
https://github.com/git-for-windows/git) || exit
case "$branch_to_use" in
*@*)
git "$dir_option" fetch --tags \
"${branch_to_use#*@}" "${branch_to_use%%@*}" ||