patch-save.sh 388 B

123456789101112131415161718
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. DIRNAME="$(dirname -- "${BASH_SOURCE[0]}")"
  4. PATCH="$DIRNAME/upgradeable.patch"
  5. error() {
  6. echo Error: "$*" >&2
  7. exit 1
  8. }
  9. if ! git diff-files --quiet ":!$PATCH"; then
  10. error "Unstaged changes. Stage to include in patch or temporarily stash."
  11. fi
  12. git diff-index --cached --patch --output="$PATCH" HEAD
  13. git restore --staged --worktree ":!$PATCH"