#!/bin/sh
set -e

usage () {
    cat <<'EOF'
usage: git unskip [-ah] <file> [<file> ...]

Stop skipping local changes to files known to git.
This resets the result of git-skip to normal again.

Options:
-a    Unskip all files
-h    Show this help
EOF
}

all=0
while getopts ah flag; do
    case "$flag" in
        a) all=1;;
        h) usage; exit 0;;
    esac
done
shift $(($OPTIND - 1))

if [ $all -eq 1 ]; then
    # One file per call, quoted and after `--`, so filenames containing
    # globs/spaces or starting with `-` can't glob-expand or pose as flags.
    git show-skipped | while IFS= read -r file; do
        git update-index --no-skip-worktree -- "$file"
    done
else
    if [ $# -gt 0 ]; then
        git update-index --no-skip-worktree -- "$@"
    else
        usage >&2
        exit 2
    fi
fi
