Created
December 12, 2017 00:15
-
-
Save hypersoft/eada0611d159e79ebbb57d9b27c6a73a to your computer and use it in GitHub Desktop.
Git: Auto-Generated Binary Synchronization: Zap unmodified binary files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# This is a Git tool which zaps-auto-generated-binaries, which have not | |
# been modified from the previous version. | |
# This tool is designed to help keep commit history clean and concise. | |
GITROOT="`realpath $1`"; shift; | |
MD5FILES="$@"; | |
MD5CACHE=${GITROOT}/MD5; | |
md5.cache() { md5sum -b $MD5FILES > $MD5CACHE; } | |
md5.unmodified.files() { md5sum -c $MD5CACHE | grep OK | cut -d: -f1; } | |
git.modified.files() { git ls-files -m; } | |
params.contains() { | |
match="$1"; shift; | |
for arg; do [[ "$match" == "$arg" ]] && echo $arg; done; | |
} | |
filter.matches() { | |
while read line; do | |
params.contains "$line" "$@"; | |
done; | |
} | |
( | |
cd $GITROOT; | |
[[ -e "$MD5CACHE" ]] && { | |
FILES=$(git.modified.files | filter.matches $(md5.unmodified.files)) | |
[[ -n "$FILES" ]] && git checkout $FILES; | |
} | |
md5.cache; | |
) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment