test_update.sh (4269B)
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}/update" 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*1024))" 48 dd if=/dev/zero of="${repo}_ref/file1.bin" bs=1024 count="$((12*1024))" 49 50 # Use git-wad to manage binary files 51 printf '*.bin filter=wad' > "${repo}_ref/.gitattributes" 52 53 # Configure the directory as a git working directory, commit its 54 # content and push it to the remote repository 55 cd "${repo}_ref" 56 git init 57 git config --local user.name "Jane Doe" 58 git config --local user.email "jane@doe.com" 59 git wad init 60 git add ./*.bin .gitattributes 61 git commit -m "Commit 2 binaries" 62 git remote add origin "file://${repo}.git" 63 git push origin master 64 git wad push 65 66 ######################################################################## 67 # Test binary updates 68 ######################################################################## 69 # Clone a fresh git working directory from the remote 70 cd "${tmpdir}" 71 git clone "file://${repo}.git" 72 73 # Restore file contents and check that it the same as the original 74 # commited files 75 cd "${repo}" 76 git wad init 77 git wad pull 78 diff "${repo}/file0.bin" "${repo}_ref/file0.bin" 79 diff "${repo}/file1.bin" "${repo}_ref/file1.bin" 80 81 # Commit a new binary file from the original working directory 82 cd "${repo}_ref" 83 dd if=/dev/random of="${repo}_ref/file2.bin" bs=1024 count="314" 84 git add ./file2.bin 85 git commit -m "Add a new binary" 86 git push origin master 87 git wad push 88 89 # Pull the updates 90 cd "${repo}" 91 git pull origin master 92 git wad pull 93 git wad status 94 diff "${repo}/file0.bin" "${repo}_ref/file0.bin" 95 diff "${repo}/file1.bin" "${repo}_ref/file1.bin" 96 diff "${repo}/file2.bin" "${repo}_ref/file2.bin" 97 98 # Update a binary from the origin working directory 99 cd "${repo}_ref" 100 dd if=/dev/random of="${repo}_ref/file1.bin" \ 101 bs=1 count=123 seek="$((42*1024))" conv=notrunc 102 git commit -am "Update some binarie content" 103 git push origin master 104 git wad push 105 106 # Check that files differ between desynchronized working directories 107 cd "${repo}" 108 diff "${repo}/file0.bin" "${repo}_ref/file0.bin" 109 ! diff "${repo}/file1.bin" "${repo}_ref/file1.bin" || exit 1 110 diff "${repo}/file2.bin" "${repo}_ref/file2.bin" 111 git pull origin master 112 git wad fetch 113 ! diff "${repo}/file1.bin" "${repo}_ref/file1.bin" || exit 1 114 git wad checkout 115 diff "${repo}/file1.bin" "${repo}_ref/file1.bin" 116 117 ######################################################################## 118 # Test working tree clean-up 119 ######################################################################## 120 check_wads_count() # count 121 { 122 n="$(find .git/wad -type f | wc -l)" 123 [ "${n}" -eq "$1" ] || exit 1 124 } 125 126 # Check that there are 4 WADs 127 check_wads_count 4 128 129 # Prune it and check that nothing was removed, 130 # i.e. there are always 4 WADs 131 git wad prune 132 check_wads_count 4 133 134 # Prune all files except the WADs of the current HEAD, so that one file 135 # is deleted, namely the previous version of file1.bin before it was 136 # updated. 137 git wad prune -1 138 check_wads_count 3