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-checkout | |
initial commit
Diffstat (limited to 'comp2041/tigger/tigger-checkout')
| -rwxr-xr-x | comp2041/tigger/tigger-checkout | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/comp2041/tigger/tigger-checkout b/comp2041/tigger/tigger-checkout new file mode 100755 index 0000000..a1a5a21 --- /dev/null +++ b/comp2041/tigger/tigger-checkout @@ -0,0 +1,84 @@ +#!/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 + +# Case where we give it no arguments -> early out (without error?) +target_branch=$(echo "$@" | tr -d " "); +if [ "$target_branch" = "" ]; then + # no branch provided, idk if we should print anything so just early out + exit 1 +fi + +if ! [ -d .tigger/"$target_branch" ]; then + printf "tigger-checkout: error: unknown branch '%s'\n" "$target_branch" >&2 + exit 1 +fi + + +current_branch=$(cat .tigger/branch.tig) +current_commit=$(find .tigger/"$current_branch"/ -maxdepth 1 -type d | grep -o -E "[\/][^\/]*$" | tr -d "/" | sort -n -r | head -n 1) +if [ "$current_commit" = "" ]; then + current_commit="0" + mkdir --parents ".tigger/$current_branch/$current_commit/" +fi + +target_commit=$(find .tigger/"$target_branch"/ -maxdepth 1 -type d | grep -o -E "[\/][^\/]*$" | tr -d "/" | sort -n -r | head -n 1) +if [ "$target_commit" = "" ]; then + target_commit="0" + mkdir --parents ".tigger/$target_branch/$target_commit/" +fi + +for filename in *; do + basename=$(basename "$filename") + + # nothing in dir, just exit (should exit) + if ! [ -e "$filename" ]; then + continue + fi + + # if it's in staging, do not remove + #if [ -e .tigger/"$current_branch"/"$current_commit"/staged/"$basename" ]; then + # continue + #fi + + # if it doesn't exist in the target commit, remove + if ! [ -e .tigger/"$target_branch"/"$target_commit"/commit/"$basename" ]; then + rm "$basename" + continue + fi +done + +for filename in .tigger/"$target_branch"/"$target_commit"/commit/*; do + basename=$(basename "$filename") + + # nothing in dir, just exit (should exit) + if ! [ -e "$filename" ]; then + continue + fi + + # if it's in the current dir, do nothing TODO fix if different + if [ -e "$basename" ]; then + + # If it's the same AND not different to current staging, don't copy. + if [ "$(diff .tigger/"$target_branch"/"$target_commit"/commit/"$basename" "$basename")" = "" ]; then + if [ "$(diff .tigger/"$current_branch"/"$current_commit"/staged/"$basename" "$basename")" != "" ]; then + continue + fi + fi + + fi + + cp "$filename" ./ +done + +# Non-compliant tigger vs git behaviour: copy our staged to theirs. +rm -rf .tigger/"$target_branch"/"$target_commit"/staged +cp -r .tigger/"$current_branch"/"$current_commit"/staged .tigger/"$target_branch"/"$target_commit"/staged + +echo "$target_branch" > .tigger/branch.tig +printf "Switched to branch '%s'\n" "$target_branch" +exit 0 |
