fix: Error when image file is on first commit... why?
This commit is contained in:
		
							
								
								
									
										17
									
								
								scripts/run
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								scripts/run
									
									
									
									
									
								
							@@ -88,20 +88,25 @@ optimizer() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
optimizer_git_image() {
 | 
			
		||||
  for file in $(git diff --name-only --diff-filter=M --ignore-submodules); do
 | 
			
		||||
    last_commit=`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`
 | 
			
		||||
  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
 | 
			
		||||
 | 
			
		||||
    if [ "$current_size" -lt "$old_size" ]; then
 | 
			
		||||
  for file in $(git diff --name-only --diff-filter=M --ignore-submodules); do
 | 
			
		||||
    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_file_update_commit_hash:$file | wc -c`
 | 
			
		||||
 | 
			
		||||
    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
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user