#!/bin/dash # Test if we have a valid repo before doing anything. if ! [ -d ".tigger/" ]; then printf "tigger-add: error: tigger repository directory .tigger not found\n" >&2 exit 1 fi # Get current branch, then current commit (default 0). branch=$(cat .tigger/branch.tig) mkdir --parents ".tigger/$branch/" commit=$(find .tigger/"$branch"/ -maxdepth 1 -type d | grep -o -E "[\/][^\/]*$" | tr -d "/" | sort -n -r | head -n 1) if [ "$commit" = "" ]; then commit="0" mkdir --parents ".tigger/$branch/$commit/" fi commit_files=".tigger/$branch/$commit/" mkdir --parents "$commit_files/commit/" mkdir --parents "$commit_files/staged/" for filename in $(echo "$@" | sed "s|--force||g" | sed "s|--cached||g"); do basename=$(basename "$filename") if ! [ -e .tigger/"$branch"/"$commit"/staged/"$basename" ]; then printf "tigger-rm: error: '%s' is not in the tigger repository\n" "$basename" >&2 exit 1 fi # Accidental deletion checking, should be non-cached and non-forced. if [ "$(echo "$@" | grep -o -E "\-\-force")" = "" ]; then if [ "$(cmp --silent .tigger/"$branch"/"$commit"/staged/"$basename" "$basename"; echo $?)" -ne 0 ]; then if [ "$(cmp --silent .tigger/"$branch"/"$commit"/staged/"$basename" .tigger/"$branch"/"$commit"/commit/"$basename"; echo $?)" -ne 0 ]; then printf "tigger-rm: error: '%s' in index is different to both the working file and the repository\n" "$basename" >&2 exit 1 fi if ! [ "$(echo "$@" | grep -o -E "\-\-cached")" != "" ]; then printf "tigger-rm: error: '%s' in the repository is different to the working file\n" "$basename" >&2 exit 1 fi fi if ! [ "$(echo "$@" | grep -o -E "\-\-cached")" != "" ]; then if [ "$(cmp --silent .tigger/"$branch"/"$commit"/staged/"$basename" .tigger/"$branch"/"$commit"/commit/"$basename"; echo $?)" -ne 0 ]; then printf "tigger-rm: error: '%s' has staged changes in the index\n" "$basename" >&2 exit 1 fi fi fi rm --force .tigger/"$branch"/"$commit"/staged/"$basename" # If the cached option is specified the files are removed only from the index. if [ "$(echo "$@" | grep -o -E "\-\-cached")" != "" ]; then continue fi rm --force "$basename" done exit 0