fix: Error when image file is on first commit... why?
This commit is contained in:
		
							
								
								
									
										25
									
								
								scripts/run
									
									
									
									
									
								
							
							
						
						
									
										25
									
								
								scripts/run
									
									
									
									
									
								
							@@ -88,20 +88,25 @@ optimizer() {
 | 
				
			|||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
optimizer_git_image() {
 | 
					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
 | 
					  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`
 | 
					    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
 | 
					    if [ "$first_commit_hash" == "$last_file_update_commit_hash" ]; then
 | 
				
			||||||
    check_git_command=`git config --global --list | grep amend-to | wc -c`
 | 
					      echo "💩 file '$file' is on first commit..."
 | 
				
			||||||
    if [ "$check_git_command" -ne 187 ]; then
 | 
					    elif [ "$current_size" -lt "$old_size" ]; 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
 | 
					 | 
				
			||||||
      git add $file
 | 
					      git add $file
 | 
				
			||||||
      git amend-to $last_commit
 | 
					      git amend-to $last_file_update_commit_hash
 | 
				
			||||||
    fi
 | 
					    fi
 | 
				
			||||||
  done
 | 
					  done
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user