forked from git-for-windows/build-extra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
commit-msys2.sh
112 lines (96 loc) · 2.68 KB
/
commit-msys2.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
#!/bin/sh
# To help Continuous Integration, this script commits the files installed via
# MSYS2 packages into the Git for Windows SDK. The resulting repository can be
# easily cloned and cached by build agents.
die () {
echo "$*" >&2
exit 1
}
root="$(cd "$(dirname "$0")/../../.." && pwd)" ||
die "Could not determine root directory"
list_packages () {
(cd "${root%/}"/var/lib/pacman/local &&
# order by ctime
ls -rtc | grep -v ALPM_DB_VERSION)
}
commit_package () {
(cd "$root" ||
die "Could not cd to $root"
git update-index -q --refresh &&
git diff-index --cached --quiet HEAD -- ||
die "There are uncommitted changes in $root"
package="$(echo var/cache/pacman/pkg/"$1"*.pkg.tar.xz)"
test -f "$package" || die "Could not find the package of $1"
if git rev-parse -q --verify refs/heads/import-tars >/dev/null
then
git branch -D import-tars
fi &&
"$import_tars" "$package" &&
git ls-tree -r import-tars |
sed -n 's/^\([0-9]* \)blob \([0-9a-f]*\)\(\t[^.].*\)/\1\2\3/p' |
git update-index --index-info &&
git add "${root%/}"/var/lib/pacman/local/"$1" &&
git commit -s -m "$1" ||
die "Could not commit $1") ||
exit
}
case "$1" in
init)
import_tars="${root%/}"/usr/src/git/contrib/fast-import/import-tars.perl
test -x "$import_tars" ||
die "You need to run this script in a Git for Windows SDK"
if test ! -d "${root%/}"/.git
then
(cd "$root" && git init) ||
die "Could not initialize Git repository"
fi
if test false != "$(git -C "$root" config core.autocrlf)"
then
git -C "$root" config core.autocrlf false ||
die "Could not force core.autocrlf = false"
fi
for package in $(list_packages)
do
commit_package $package || exit
done
(cd "$root" &&
git add var/lib/pacman/sync &&
git commit -s -m "Pacman package index") ||
die "Could not conclude initial commits"
;;
add)
shift &&
(cd "$root" &&
if test false != "$(git config core.autocrlf)"
then
git config core.autocrlf false ||
die "Could not force core.autocrlf = false"
fi &&
packages="$(for package; do
case "$package" in
mingw-w64-*) echo mingw-w64-$(uname -m)${package#mingw-w64};;
*) echo "$package";;
esac; done)" &&
pacman -Syy --noconfirm $packages &&
git add -A . ||
die "Could not add $*"
git diff-index --exit-code --cached HEAD ||
git commit -q -s -m "Add $*") ||
die "Could not commit changes"
;;
commit)
(cd "$root" &&
if test false != "$(git config core.autocrlf)"
then
git config core.autocrlf false ||
die "Could not force core.autocrlf = false"
fi &&
git add -A . &&
git diff-index --exit-code --cached HEAD ||
git commit -q -s -m "Update $(date +%Y%m%d-%H%M%S)") ||
die "Could not commit changes"
;;
*)
die "Unknown command: $1"
;;
esac