aboutsummaryrefslogtreecommitdiff
path: root/comp2041/tigger/tigger-status
diff options
context:
space:
mode:
authorNicolas James <Eele1Ephe7uZahRie@tutanota.com>2025-02-13 18:00:17 +1100
committerNicolas James <Eele1Ephe7uZahRie@tutanota.com>2025-02-13 18:00:17 +1100
commit98cef5e9a772602d42acfcf233838c760424db9a (patch)
tree5277fa1d7cc0a69a0f166fcbf10fd320f345f049 /comp2041/tigger/tigger-status
initial commit
Diffstat (limited to 'comp2041/tigger/tigger-status')
-rwxr-xr-xcomp2041/tigger/tigger-status100
1 files changed, 100 insertions, 0 deletions
diff --git a/comp2041/tigger/tigger-status b/comp2041/tigger/tigger-status
new file mode 100755
index 0000000..b623432
--- /dev/null
+++ b/comp2041/tigger/tigger-status
@@ -0,0 +1,100 @@
+#!/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 + commit as usual.
+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
+
+# Grabs regular files from our working dir, staging and commit.
+files=$(find .tigger/"$branch"/"$commit"/commit/ .tigger/"$branch"/"$commit"/staged/ ./ -maxdepth 1 -type f -printf "%P\n" | sort | uniq | grep -v -E "^\." 2>/dev/null)
+for filename in $files; do
+
+ c_dir=".tigger/$branch/$commit/commit/$filename";
+ s_dir=".tigger/$branch/$commit/staged/$filename";
+
+ is_c=0
+ is_s=0
+ is_w=0
+ if [ -e "$c_dir" ]; then
+ is_c=1
+ fi
+ if [ -e "$s_dir" ]; then
+ is_s=1
+ fi
+ if [ -e "$filename" ]; then
+ is_w=1
+ fi
+
+ # There are a LOT of very specific cases here.
+
+ if [ $is_w -eq 0 ] && [ $is_s -eq 0 ] && [ $is_c -eq 1 ]; then
+ printf "%s - deleted\n" "$filename"
+ continue
+ fi
+
+ if [ $is_w -eq 1 ] && [ $is_s -eq 0 ] && [ $is_c -eq 0 ]; then
+ printf "%s - untracked\n" "$filename"
+ continue;
+ fi
+
+ if [ $is_w -eq 1 ] && [ $is_s -eq 1 ] && [ $is_c -eq 1 ]; then
+ c="$(cat "$c_dir")"
+ s="$(cat "$s_dir")"
+ w="$(cat "$filename")"
+
+ if [ "$w" != "$s" ] && [ "$s" != "$c" ] && [ "$c" != "$w" ]; then
+ printf "%s - file changed, different changes staged for commit\n" "$filename"
+ continue
+ fi
+
+ if [ "$w" = "$s" ] && [ "$s" != "$c" ]; then
+ printf "%s - file changed, changes staged for commit\n" "$filename"
+ continue
+ fi
+
+ if [ "$w" != "$s" ] && [ "$s" = "$c" ]; then
+ printf "%s - file changed, changes not staged for commit\n" "$filename"
+ continue
+ fi
+
+ if [ "$w" = "$s" ] && [ "$s" = "$c" ]; then
+ printf "%s - same as repo\n" "$filename"
+ continue
+ fi
+ fi
+
+ if [ $is_w -eq 0 ] && [ $is_s -eq 1 ] && [ $is_c -eq 1 ] && [ "$(diff "$s_dir" "$c_dir")" = "" ]; then
+ printf "%s - file deleted\n" "$filename"
+ continue
+ fi
+
+ if [ $is_w -eq 1 ] && [ $is_s -eq 1 ] && [ $is_c -eq 0 ] && [ "$(diff "$filename" "$s_dir")" = "" ]; then
+ printf "%s - added to index\n" "$filename"
+ continue
+ fi
+
+ if [ $is_w -eq 1 ] && [ $is_s -eq 1 ] && [ $is_c -eq 0 ] && [ "$(diff "$filename" "$s_dir")" != "" ]; then
+ printf "%s - added to index, file changed\n" "$filename"
+ continue;
+ fi
+
+ if [ $is_w -eq 0 ] && [ $is_s -eq 1 ] && [ $is_c -eq 0 ]; then
+ printf "%s - added to index, file deleted\n" "$filename"
+ continue;
+ fi
+
+ printf "%s - untracked\n" "$filename"
+
+done
+
+exit 0