diff options
| author | Nicolas James <Eele1Ephe7uZahRie@tutanota.com> | 2025-02-13 18:00:17 +1100 |
|---|---|---|
| committer | Nicolas James <Eele1Ephe7uZahRie@tutanota.com> | 2025-02-13 18:00:17 +1100 |
| commit | 98cef5e9a772602d42acfcf233838c760424db9a (patch) | |
| tree | 5277fa1d7cc0a69a0f166fcbf10fd320f345f049 /comp2041/tigger/tigger-show | |
initial commit
Diffstat (limited to 'comp2041/tigger/tigger-show')
| -rwxr-xr-x | comp2041/tigger/tigger-show | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/comp2041/tigger/tigger-show b/comp2041/tigger/tigger-show new file mode 100755 index 0000000..05d8405 --- /dev/null +++ b/comp2041/tigger/tigger-show @@ -0,0 +1,63 @@ +#!/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 + +if [ "$(printf "%s" "$@")" = "" ]; then + printf "tigger-show: error: no arguments provided\n" >&2 + exit 1 +fi + +branch=$(cat .tigger/branch.tig) +filename=$(echo "$@" | cut -d':' -f2-2) +commit=$(echo "$@" | cut -d':' -f1-1) + +# Lots of error checking here and unnecessarily distinct printing per error. + +target="" # LAMBDA CAPTURE +if [ "$commit" != "" ]; then + target=".tigger/$branch/$commit/commit/$filename" + + if ! [ -e ".tigger/$branch/$commit/message.tig" ]; then + printf "tigger-show: error: unknown commit '%s'\n" "$commit" >&2 + exit 1 + fi + + if ! [ -e "$target" ]; then + printf "tigger-show: error: '%s' not found in commit %s\n" "$filename" "$commit" >&2 + exit 1 + fi + + printf "%s\n" "$(cat "$target")" + exit 0 + +else + 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 + + if ! [ -e ".tigger/$branch/$commit/staged/$filename" ]; then + printf "tigger-show: error: '%s' not found in index\n" "$filename" >&2 + exit 1 + fi + + target=".tigger/$branch/$commit/staged/$filename" +fi + +if ! [ -e ".tigger/$branch/$commit/" ]; then + printf "tigger-show: error: unknown commit '%s'\n" "$commit" >&2 + exit 1 +fi + +if ! [ -e "$target" ]; then + printf "tigger-show: error: '%s' not found in commit %s\n" "$filename" "$commit" >&2 + exit 1 +fi + +printf "%s\n" "$(cat "$target")" +exit 0 |
