From 98cef5e9a772602d42acfcf233838c760424db9a Mon Sep 17 00:00:00 2001 From: Nicolas James Date: Thu, 13 Feb 2025 18:00:17 +1100 Subject: initial commit --- comp2041/tigger/tigger-show | 63 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100755 comp2041/tigger/tigger-show (limited to 'comp2041/tigger/tigger-show') 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 -- cgit v1.2.3