github.com/quay/claircore@v1.5.28/etc/importfix.sh (about)

     1  #!/bin/sh
     2  # Importfix is a helper to keep a consistent import style.
     3  #
     4  # This is unneeded if your editor is configured to group imports with this module as the local prefix.
     5  #
     6  # By default, only files in the current commit are modified.
     7  # If an argument is provided, it's used as a revset to list files from.
     8  set -e
     9  cd "$(git rev-parse --show-toplevel)"
    10  mod="$(go list -m)"
    11  goimports=$(command -v goimports || echo go run golang.org/x/tools/cmd/goimports@latest)
    12  git show --pretty=format: --diff-filter=d --name-only "${1:-HEAD}" -- ':*\.go' | (
    13  	while read -r f; do
    14  		sed -i '' '/import (/,/)/{ /^$/d; }' "$f"
    15  		$goimports -local "$mod" -w "$f"
    16  	done
    17  )