- Add .config/git/config + Define aliases + Configure default behavior in various situations + Add user information with signing key - Add .config/git/commit_msg_template.txt - Add .config/git/ignore - Integrate `git` aliases into the shell
54 lines
1.3 KiB
Shell
Executable file
54 lines
1.3 KiB
Shell
Executable file
#!/bin/sh
|
|
|
|
# Reset the working directory to `HEAD` and remove everything not tracked,
|
|
# except the files listed in $KEEP in ~/.local/bin/git-clean-ignored
|
|
#
|
|
# This is irreversible, so the changes are shown first and confirmed,
|
|
# unless "--force" is passed
|
|
#
|
|
# Usage: git clean-all [--force]
|
|
|
|
set -eu
|
|
|
|
|
|
# `git` runs scripts on the `$PATH` in the current directory,
|
|
# whereas it runs "!" aliases at the top level of the repository
|
|
cd "$(git rev-parse --show-toplevel)"
|
|
|
|
|
|
case "${1:-}" in
|
|
--force) _forced=1 ;;
|
|
"") _forced=0 ;;
|
|
*) echo "Usage: git clean-all [--force]" >&2; exit 2 ;;
|
|
esac
|
|
|
|
|
|
if [ "$_forced" -ne 1 ]; then
|
|
|
|
echo "Tracked files to be reset to HEAD:"
|
|
git diff --stat HEAD || true
|
|
echo ""
|
|
|
|
echo "Untracked and ignored files to be removed:"
|
|
# Keep the "-e" flags in sync with the other two copies:
|
|
# - the "-e" flags of `clean-untracked` in ~/.config/git/config
|
|
# - `$KEEP` in ~/.local/bin/git-clean-ignored
|
|
git clean -x -d -n -e ".python-version" -e ".env"
|
|
echo ""
|
|
|
|
printf "This CANNOT be undone. Continue? [y/N] "
|
|
read -r _answer || _answer=""
|
|
|
|
case "$_answer" in
|
|
[yY] | [yY][eE][sS]) ;;
|
|
*) echo "Aborted" >&2; exit 1 ;;
|
|
esac
|
|
|
|
fi
|
|
|
|
|
|
git reset --hard
|
|
|
|
git clean-ignored
|
|
|
|
git clean-untracked
|