test_tiny_bin.sh (3728B)
1 #!/bin/sh 2 3 # Copyright (C) 2023-2025 |Méso|Star> (contact@meso-star.com) 4 # 5 # This program is free software: you can redistribute it and/or modify 6 # it under the terms of the GNU General Public License as published by 7 # the Free Software Foundation, either version 3 of the License, or 8 # (at your option) any later version. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 # GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License 16 # along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 set -e 19 20 die() 21 { 22 rm -rf "${tmpdir}" # cleanup temporary files 23 return "${1:-1}" # return status code (default is 1) 24 } 25 26 # Configure signal processing 27 trap 'die $?' EXIT 28 trap 'die 1' TERM INT 29 30 # Use the local git-wad 31 current="$(pwd)" 32 export PATH="${current}":"${PATH}" 33 34 # Working directory 35 tmpdir="$(mktemp -d "${TMPDIR:-/tmp}"/git_wad_test_XXXXXX)" 36 repo="${tmpdir}/tiny_bin" 37 38 ######################################################################## 39 # Test setup 40 ######################################################################## 41 # Create the bare repository 42 mkdir -p "${repo}.git" 43 git init --bare "${repo}.git" 44 45 # Create the repository content to be managed by git-wad 46 mkdir -p "${repo}_ref" 47 dd if=/dev/random of="${repo}_ref/file0.bin" bs=1024 count=1 48 dd if=/dev/random of="${repo}_ref/file1.bin" bs=1024 count=2 49 dd if=/dev/random of="${repo}_ref/file2.bin" bs=1024 count=3 50 dd if=/dev/random of="${repo}_ref/file3.bin" bs=1024 count=4 51 dd if=/dev/zero of="${repo}_ref/file4.bin" bs=1024 count=5 52 53 # Add a README file to be managed by git 54 printf 'Repository with small binaries tracked by git-wad' \ 55 > "${repo}_ref/README" 56 57 # Use git-wad to manage binary files 58 printf '*.bin filter=wad' > "${repo}_ref/.gitattributes" 59 60 # Configure the directory as a git working directory, commit its 61 # content and push it to the remote repository 62 cd "${repo}_ref" 63 git init 64 git config --local user.name "John Doe" 65 git config --local user.email "john@doe.com" 66 git wad init 67 git add ./*.bin README .gitattributes 68 git commit -m "Test small binaries" 69 git remote add origin "file://${repo}.git" 70 git push origin master 71 git wad push 72 73 ######################################################################## 74 # The test 75 ######################################################################## 76 # Clone a fresh git working directory from the remote 77 cd "${tmpdir}" 78 git clone "file://${repo}.git" 79 80 # Check that files managed by git-wad have not yet been restored, 81 # whereas normal files are the same as the originals, i.e. they are not 82 # actually managed by git and not git-wad. 83 ! diff "${repo}/file0.bin" "${repo}_ref/file0.bin" || exit "$?" 84 ! diff "${repo}/file1.bin" "${repo}_ref/file1.bin" || exit "$?" 85 ! diff "${repo}/file2.bin" "${repo}_ref/file2.bin" || exit "$?" 86 ! diff "${repo}/file3.bin" "${repo}_ref/file3.bin" || exit "$?" 87 ! diff "${repo}/file4.bin" "${repo}_ref/file4.bin" || exit "$?" 88 diff "${repo}/README" "${repo}_ref/README" 89 diff "${repo}/.gitattributes" "${repo}_ref/.gitattributes" 90 91 # Restore the files managed by git-wad 92 cd "${repo}" 93 git wad init 94 git wad pull 95 git wad status 96 97 # Check that, once restored, the files managed by git-wad are the same 98 # as the original files. 99 diff "${repo}/file0.bin" "${repo}_ref/file0.bin" 100 diff "${repo}/file1.bin" "${repo}_ref/file1.bin" 101 diff "${repo}/file2.bin" "${repo}_ref/file2.bin" 102 diff "${repo}/file3.bin" "${repo}_ref/file3.bin" 103 diff "${repo}/file4.bin" "${repo}_ref/file4.bin" 104 diff "${repo}/README" "${repo}_ref/README" 105 diff "${repo}/.gitattributes" "${repo}_ref/.gitattributes"