#!/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" exit 1 fi # Get current branch, then current commit (default 0). branch=$(cat .tigger/branch.tig) mkdir --parents ".tigger/$branch/" # Grabs the latest commit 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 staged_dir=".tigger/$branch/$commit/staged/" mkdir --parents "$staged_dir" for filename in "$@"; do if ! [ -f "$filename" ]; then # If it doesn't exist in the dir, but does exist in staged, delete staged. if [ -f .tigger/"$branch"/"$commit"/staged/"$filename" ]; then rm --force .tigger/"$branch"/"$commit"/staged/"$filename" continue fi printf "tigger-add: error: can not open '%s'\n" "$filename" exit 1 fi cp "$filename" "$staged_dir" done exit 0