Created
December 13, 2021 15:10
-
-
Save lann/8c6830dd086104ecefbbfee291c516ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -eu | |
case "${1:-now}" in | |
now) ;; | |
log) git reflog 'AUTOSAVE@{now}'; exit 0 ;; | |
expire) git reflog expire AUTOSAVE; exit 0 ;; | |
*) echo "git autosave [now,log,expire]"; exit 1 ;; | |
esac | |
orig_index="$(git rev-parse --git-path index)" | |
export GIT_INDEX_FILE="$(git rev-parse --git-path autosave-index)" | |
[ -e "${GIT_INDEX_FILE}" ] \ | |
|| cp "${orig_index}" "${GIT_INDEX_FILE}" | |
git add -u | |
tree="$(git write-tree)" | |
[ -e "$(git rev-parse --git-path AUTOSAVE)" ] \ | |
&& git diff AUTOSAVE --quiet --exit-code \ | |
&& exit 0 \ | |
|| true | |
commit="$(git commit-tree -m autosave -p HEAD "${tree}")" | |
git update-ref AUTOSAVE "${commit}" --create-reflog |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment