aboutsummaryrefslogtreecommitdiff
path: root/comp2041/tigger/tigger-show
diff options
context:
space:
mode:
Diffstat (limited to 'comp2041/tigger/tigger-show')
-rwxr-xr-xcomp2041/tigger/tigger-show63
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