forked from git-for-windows/build-extra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
please.sh
2512 lines (2240 loc) · 67.7 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' 'master' 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 'master' 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
sdk_path () { # <bitness>
result="$(git config windows.sdk"$1".path)" && test -n "$result" ||
result="C:/git-sdk-$1"
test -e "$result" ||
die "%s\n\n%s\n%s\n" \
"Could not determine location of Git for Windows SDK $1-bit" \
"Default 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 "$($1/mingw??/bin/WhoUses.exe -m "$1$2" |
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"
}
sync () { # [--force]
force=
y_opt=y
while case "$1" in
--force)
force=--force
y_opt=yy
;;
-*) die "Unknown option: %s\n" "$1";;
*) break;;
esac; do shift; done
test $# = 0 ||
die "Expected no argument, got $#: %s\n" "$*"
for sdk in "$sdk32" "$sdk64"
do
mkdir -p "$sdk/var/log" ||
die "Could not ensure %s/var/log/ exists\n" "$sdk"
"$sdk/git-cmd.exe" --command=usr\\bin\\pacman.exe -S$y_opt ||
die "Cannot run pacman in %s\n" "$sdk"
PATH="$sdk/usr/bin:$PATH" \
"$sdk/git-cmd.exe" --cd="$sdk" --command=usr\\bin\\pacman.exe \
-Su $force --noconfirm ||
die "Could not update packages in %s\n" "$sdk"
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
PATH="$sdk/usr/bin:$PATH" \
"$sdk/git-cmd.exe" --cd="$sdk" \
--command=usr\\bin\\sh.exe -l \
-c 'pacman -Su '$force' --noconfirm' ||
die "Cannot update packages in %s\n" "$sdk"
;;
esac
# 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" ||
PATH="$sdk/usr/bin:$PATH" \
"$sdk/git-cmd.exe" --command=usr\\bin\\sh.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
PATH="$sdk/bin:$PATH" \
"$sdk/git-cmd.exe" --command=usr\\bin\\sh.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
PATH="$sdk/bin:$PATH" \
"$sdk/git-cmd.exe" --command=usr\\bin\\sh.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
cmdline=eval
for arg
do
cmdline="$cmdline '$(echo "$arg" | sed -e "s/'/&\\\\&&/g")'"
done
"$sdk/git-cmd.exe" --command=usr\\bin\\sh.exe -l -c "$cmdline"
}
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/git-extra
;;
git)
package=mingw-w64-git
extra_packages="mingw-w64-git-doc-html mingw-w64-git-doc-man"
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"
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
;;
cv2pdb|mingw-w64-cv2pdb)
package=mingw-w64-cv2pdb
type=MINGW
pkgpath=/usr/src/build-extra/mingw-w64-cv2pdb
;;
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
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
pkgpath=/usr/src/MINGW-packages/$package
;;
mingw-w64-curl-winssl-bin)
type=MINGW
pkgpath=/usr/src/MINGW-packages/mingw-w64-curl
extra_makepkg_opts="-p PKGBUILD-winssl-bin"
(cd "$sdk64/$pkgpath" &&
test -f PKGBUILD-winssl-bin &&
test PKGBUILD-winssl-bin -nt PKGBUILD &&
test PKGBUILD-winssl-bin -nt make-PKGBUILD-winssl-bin.sh ||
test ! -f make-PKGBUILD-winssl-bin.sh ||
./make-PKGBUILD-winssl-bin.sh) ||
die "Could not generate PKGBUILD-winssl-bin in %s\n" "$pkgpath"
;;
git-flow)
type=MSYS
pkgpath=/usr/src/MSYS2-packages/$package
;;
p7zip)
type=MSYS
pkgpath=/usr/src/MSYS2-packages/$package
;;
*)
die "Unknown package: %s\n" "$package"
;;
esac
}
# foreach_sdk <function> [<args>]
foreach_sdk () {
# No uncommitted changes?
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"
"$@") || exit
done
}
require_clean_worktree () {
git update-index -q --ignore-submodules --refresh &&
git diff-files --quiet --ignore-submodules &&
git diff-index --cached --quiet --ignore-submodules HEAD ||
die "%s not up-to-date\n" "$sdk/$pkgpath"
}
ff_master () {
test refs/heads/master = "$(git rev-parse --symbolic-full-name HEAD)" ||
die "%s: Not on 'master'\n" "$sdk/$pkgpath"
require_clean_worktree
git pull --ff-only origin master ||
die "%s: cannot fast-forward 'master'\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_master
}
# 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 () {
for prereq in mingw-w64-i686-asciidoctor-extensions
do
test ! -d "$sdk64"/var/lib/pacman/local/$prereq-[0-9]* ||
continue
sdk="$sdk32" require $prereq &&
pkg="$sdk32/var/cache/pacman/pkg/$("$sdk32/git-cmd.exe" \
--command=usr\\bin\\pacman.exe -Q "$prereq" |
sed -e 's/ /-/' -e 's/$/-any.pkg.tar.xz/')" &&
"$sdk64"/git-cmd.exe --command=usr\\bin\\sh.exe -l -c \
'pacman -U --noconfirm "'"$pkg"'"' ||
die "Could not install %s into SDK-64\n" "$prereq"
done
}
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"' &&
MINGW_INSTALLS=mingw64 makepkg-mingw --allsource \
'"$extra_makepkg_opts" ||
die "%s: could not build\n" "$sdk/$pkgpath"
git commit -s -m "$package: new version" PKGBUILD ||
die "%s: could not commit after build\n" "$sdk/$pkgpath"
;;
MSYS)
require msys2-devel binutils
if test msys2-runtime = "$package"
then
require mingw-w64-cross-gcc
test ! -d msys2-runtime ||
(cd msys2-runtime && git fetch) ||
die "Could not fetch from origin"
test ! -d src/msys2-runtime/.git ||
(cd src/msys2-runtime &&
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=-j5 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 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 () {
git -C "$1" fetch "$2" refs/heads/master &&
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 () { # <package>
set_package "$1"
test MINGW = "$type" ||
up_to_date "$pkgpath" ||
die "%s: not up-to-date\n" "$pkgpath"
foreach_sdk pkg_build
}
# 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 &&
if git merge "$parent2" >/dev/null 2>&1
then
echo "Nothing to be learned: no merge conflicts" >&2
else
if ! test -s "$(git rev-parse --git-path MERGE_RR)"
then
git rerere forget -- . &&
test -f "$(git rev-parse --git-path MERGE_RR)" ||
die "Could not re-learn from %s\n" "$commit"
fi
git checkout -q "$commit" -- . &&
git rerere ||
die "Could not learn from %s\n" "$commit"
fi) || exit
done
}
# 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/master ||
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') ||
die "Could not initialize %s\n" "$git_src_dir"
fi
test ! -f "$git_src_dir/PKGBUILD" ||
(cd "$git_src_dir/../.." &&
sdk= pkgpath=$PWD ff_master) ||
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 stash) ||
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"
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'
}
rebase () { # [--worktree=<dir>] [--test [--full-test-log] [--with-svn-tests]] [--redo] [--abort-previous] [--continue | --skip] <upstream-branch-or-tag>
git_src_dir="$sdk64/usr/src/MINGW-packages/mingw-w64-git/src/git"
run_tests=
redo=
abort_previous=
continue_rebase=
skip_rebase=
full_test_log=
with_svn_tests=
while case "$1" in
--worktree=*)
git_src_dir=${1#*=}
test -d "$git_src_dir" ||
die "Worktree does not exist: %s\n" "$git_src_dir"
git rev-parse -q --verify e83c5163316f89bfbde7d ||
die "Does not appear to be a Git checkout: %s\n" "$git_src_dir"
;;
--test) run_tests=t;;
--full-test-log) full_test_log=--full-log;;
--with-svn-tests) with_svn_tests=--with-svn-tests;;
--redo) redo=t;;
--abort-previous) abort_previous=t;;
--continue) continue_rebase=t;;
--skip) skip_rebase=t;;
-*) die "Unknown option: %s\n" "$1";;
*) break;;
esac; do shift; done
test $# = 1 ||
die "Expected 1 argument, got $#: %s\n" "$*"
ensure_valid_login_shell 64 ||
die "Could not ensure valid login shell\n"
test tt != "$skip_rebase$continue_rebase" ||
die "Cannot continue *and* skip\n"
# special-case master and maint: we will want full tests on those
case "$1" in master|maint) with_svn_tests=--with-svn-tests;; esac
sdk="$sdk64"
build_extra_dir="$sdk64/usr/src/build-extra"
(cd "$build_extra_dir" &&
sdk= pkgpath=$PWD ff_master) ||
die "Could not update build-extra\n"
require_git_src_dir
(cd "$git_src_dir" &&
if is_rebasing && test -z "$continue_rebase$skip_rebase"
then
if test -n "$abort_previous"
then
git rebase --abort ||
die "Could not abort previous rebase\n"
else
die "Rebase already in progress.\n%s\n" \
"Require --continue or --abort-previous."
fi
fi &&
if ! is_rebasing
then
test -z "$continue_rebase$skip_rebase" ||
die "No rebase was started...\n"
orig_rerere_train=
if rerere_train2="$(git rev-parse -q --verify \
refs/remotes/git-for-windows/rerere-train)" &&
rerere_train="$(git rev-parse -q --verify \
refs/heads/rerere-train)"
then
orig_rerere_train="$rerere_train.."
test 0 -eq $(git rev-list --count \
"$rerere_train2..$rerere_train") ||
if test -z "$(git merge-base \
"$rerere_train" "$rerere_train2")"
then
rm -r "$(git rev-parse --git-path rr-cache)" ||
die "Could not reset rerere cache\n"
git update-ref refs/heads/rerere-train \
"$rerere_train2" ||
die 'Could not reset `rerere-train` branch\n'
else
die 'The `%s` branch has unpushed changes\n' \
rerere-train
fi
fi
require_remote upstream https://github.com/git/git &&
require_remote git-for-windows \
https://github.com/git-for-windows/git &&
require_push_url git-for-windows ||
die "Could not update remotes\n"
if test -n "$rerere_train2"
then
rerere_train "$orig_rerere_train$rerere_train2" ||
die "Could not replay merge conflict resolutions\n"
git push . $rerere_train2:refs/heads/rerere-train ||
die "Could not update local 'rerere-train' branch\n"
fi
fi &&
if ! onto=$(git rev-parse -q --verify refs/remotes/upstream/"$1" ||
git rev-parse -q --verify refs/tags/"$1")
then
die "No such upstream branch or tag: %s\n" "$1"
fi &&
if prev=$(git rev-parse -q --verify \
refs/remotes/git-for-windows/shears/"$1") &&
test 0 = $(git rev-list --count \
^"$prev" git-for-windows/master $onto)
then
if test -z "$redo"
then
echo "shears/$1 was already rebased" >&2
exit 0
fi
fi &&
GIT_CONFIG_PARAMETERS="$GIT_CONFIG_PARAMETERS${GIT_CONFIG_PARAMETERS:+ }'core.editor=touch' 'rerere.enabled=true' 'rerere.autoupdate=true'" &&
export GIT_CONFIG_PARAMETERS &&
if is_rebasing
then
test 0 = $(git rev-list --count HEAD..$onto) ||
die "Current rebase is not on top of %s\n" "$1"
test -z "$skip_rebase" ||
git diff HEAD | git apply -R ||
die "Could not skip current commit in rebase\n"
# record rerere-train, update index & continue
record_rerere_train
else