Skip to content

Commit ef57d76

Browse files
authored
Merge pull request #519 from desktop/least-lfs-possible
Only package the bits from LFS that we really need
2 parents b466341 + cb0e96f commit ef57d76

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

script/build-macos.sh

+5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ GIT_LFS_FILENAME="$(jq --raw-output ".\"git-lfs\".files[] | select(.arch == \"$D
3636

3737
# shellcheck source=script/compute-checksum.sh
3838
source "$CURRENT_DIR/compute-checksum.sh"
39+
# shellcheck source=script/verify-lfs-contents.sh
40+
source "$CURRENT_DIR/verify-lfs-contents.sh"
3941

4042
echo "-- Building git at $SOURCE to $DESTINATION"
4143

@@ -84,6 +86,9 @@ if [[ "$GIT_LFS_VERSION" ]]; then
8486
if [ "$COMPUTED_SHA256" = "$GIT_LFS_CHECKSUM" ]; then
8587
echo "Git LFS: checksums match"
8688
SUBFOLDER="$DESTINATION/libexec/git-core"
89+
90+
verify_lfs_contents "$GIT_LFS_FILE"
91+
8792
unzip -j $GIT_LFS_FILE -d "$SUBFOLDER" "*/git-lfs"
8893

8994
if [[ ! -f "$SUBFOLDER/git-lfs" ]]; then

script/build-ubuntu.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ GCM_URL="$(jq --raw-output ".\"git-credential-manager\".files[] | select(.arch =
6363
source "$CURRENT_DIR/compute-checksum.sh"
6464
# shellcheck source=script/check-static-linking.sh
6565
source "$CURRENT_DIR/check-static-linking.sh"
66+
# shellcheck source=script/verify-lfs-contents.sh
67+
source "$CURRENT_DIR/verify-lfs-contents.sh"
6668

6769
echo " -- Building vanilla curl at $CURL_INSTALL_DIR instead of distro-specific version"
6870

@@ -108,7 +110,10 @@ if [[ "$GIT_LFS_VERSION" ]]; then
108110
if [ "$COMPUTED_SHA256" = "$GIT_LFS_CHECKSUM" ]; then
109111
echo "Git LFS: checksums match"
110112
SUBFOLDER="$DESTINATION/libexec/git-core"
111-
tar -xvf $GIT_LFS_FILE -C "$SUBFOLDER" --strip-components=1 --exclude='*.sh' --exclude="*.md"
113+
114+
verify_lfs_contents "$GIT_LFS_FILE"
115+
116+
tar -zxvf "$GIT_LFS_FILE" --strip-components=1 -C "$SUBFOLDER" --wildcards "*/git-lfs"
112117

113118
if [[ ! -f "$SUBFOLDER/git-lfs" ]]; then
114119
echo "After extracting Git LFS the file was not found under libexec/git-core/"

script/build-win32.sh

+6-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ GIT_FOR_WINDOWS_CHECKSUM=$(jq --raw-output ".git.packages[] | select(.arch == \"
2727
CURRENT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
2828
# shellcheck source=script/compute-checksum.sh
2929
source "$CURRENT_DIR/compute-checksum.sh"
30+
# shellcheck source=script/verify-lfs-contents.sh
31+
source "$CURRENT_DIR/verify-lfs-contents.sh"
3032

3133
mkdir -p "$DESTINATION"
3234

@@ -55,7 +57,10 @@ if [[ "$GIT_LFS_VERSION" ]]; then
5557
if [ "$COMPUTED_SHA256" = "$GIT_LFS_CHECKSUM" ]; then
5658
echo "Git LFS: checksums match"
5759
SUBFOLDER="$DESTINATION/$MINGW_DIR/libexec/git-core"
58-
unzip -j $GIT_LFS_FILE -x '*.md' -d "$SUBFOLDER"
60+
61+
verify_lfs_contents "$GIT_LFS_FILE"
62+
63+
unzip -j $GIT_LFS_FILE -d "$SUBFOLDER" "*/git-lfs.exe"
5964

6065
if [[ ! -f "$SUBFOLDER/git-lfs.exe" ]]; then
6166
echo "After extracting Git LFS the file was not found under /mingw64/libexec/git-core/"

script/verify-lfs-contents.sh

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash -e
2+
3+
verify_lfs_contents() {
4+
5+
CONTENTS=""
6+
7+
if [[ "$1" == *.zip ]]; then
8+
CONTENTS=$(unzip -qql "$1")
9+
elif [[ "$1" == *.tar.gz ]]; then
10+
CONTENTS=$(tar -tzf "$1")
11+
else
12+
echo "Unknown file type for $1"
13+
exit 1
14+
fi
15+
16+
test -z "$CONTENTS" && {
17+
echo "Git LFS: found no contents in LFS archive, aborting..."
18+
exit 1
19+
}
20+
21+
TOPLEVEL=$(echo "$CONTENTS" | cut -d/ -f2 | sort | uniq | grep .)
22+
23+
# Sanity check to make sure we react if git-lfs starts adding more stuff to
24+
# their release packages. Note that this only looks that the top
25+
# (technically second) level folder so new stuff in the man folder won't
26+
# get caught here.
27+
# shellcheck disable=SC2015
28+
grep -qvE "^(CHANGELOG\.md|README\.md|git-lfs(\.exe)?|install\.sh|man)$" <<< "$TOPLEVEL" && {
29+
echo "Git LFS: unexpected files in the LFS archive, aborting..."
30+
exit 1
31+
} || true
32+
}

0 commit comments

Comments
 (0)