fix: Error when image file is on first commit... why?

This commit is contained in:
Simon 2021-04-29 21:55:43 +02:00
parent a9891a17d4
commit f6902f3e50
1 changed files with 15 additions and 10 deletions

View File

@ -88,20 +88,25 @@ optimizer() {
}
optimizer_git_image() {
first_commit_hash=$(git rev-list --max-parents=0 HEAD)
# https://stackoverflow.com/a/48999882/6429616
# install git alias amend-to with auto stash
check_git_command=`git config --global --list | grep amend-to | wc -c`
if [ "$check_git_command" -ne 187 ]; then
git config --global alias.amend-to '!f() { SHA=`git rev-parse "$1"`; git stash -k && git commit --fixup "$SHA" && GIT_SEQUENCE_EDITOR=true git rebase --interactive --autosquash "$SHA^" && git stash pop; }; f'
fi
for file in $(git diff --name-only --diff-filter=M --ignore-submodules); do
last_commit=`git log -n 1 --pretty=format:%H -- $file`
last_file_update_commit_hash=`git log -n 1 --pretty=format:%H -- $file`
current_size=`cat $file | wc -c`
old_size=`git cat-file -p $last_commit:$file | wc -c`
old_size=`git cat-file -p $last_file_update_commit_hash:$file | wc -c`
# https://stackoverflow.com/a/48999882/6429616
check_git_command=`git config --global --list | grep amend-to | wc -c`
if [ "$check_git_command" -ne 187 ]; then
git config --global alias.amend-to '!f() { SHA=`git rev-parse "$1"`; git stash -k && git commit --fixup "$SHA" && GIT_SEQUENCE_EDITOR=true git rebase --interactive --autosquash "$SHA^" && git stash pop; }; f'
fi
if [ "$current_size" -lt "$old_size" ]; then
if [ "$first_commit_hash" == "$last_file_update_commit_hash" ]; then
echo "💩 file '$file' is on first commit..."
elif [ "$current_size" -lt "$old_size" ]; then
git add $file
git amend-to $last_commit
git amend-to $last_file_update_commit_hash
fi
done
}