Skip to content

Commit

Permalink
final nuggit: check if we wrote our last redeem number
Browse files Browse the repository at this point in the history
This can catch people manually tinkering with the nuggits "branch"
Also: remove duplicate flag from nuggits...
  • Loading branch information
miallo committed Jan 8, 2024
1 parent 7f4b093 commit 1405f33
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
5 changes: 0 additions & 5 deletions create_challenge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,6 @@ eval "$DOCDIR/store_nuggits.sh" # register the nuggits in our "git database" (ak
ALMOST_CREDITS_HASH="$(git hash-object -w "$DOCDIR/almost_credits.txt")"
# for the final credits do a little rot13, just to make life a bit harder if anyone e.g. greps through the loose objects...
CREDITS_HASH="$(tr 'A-Za-z' 'N-ZA-Mn-za-m' < "$DOCDIR/credits.txt" | git hash-object -w --stdin)"
CREDIT_WHERE_CREDIT_IS_DUE="$(echo "
[ \"\$redeemed_flags\" -ne $((NUMBER_OF_NUGGITS - 1)) ] ||
git cat-file -p $ALMOST_CREDITS_HASH;
[ \"\$redeemed_flags\" -ne $NUMBER_OF_NUGGITS ] ||
git cat-file -p $CREDITS_HASH | tr 'A-Za-z' 'N-ZA-Mn-za-m';" | tr -d "\n")"

replace_placeholders "$DOCDIR/redeem.nuggit" > ./redeem.nuggit
chmod +x ./redeem.nuggit
Expand Down
4 changes: 3 additions & 1 deletion lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ reproducibility_setup() {
replace_placeholders() {
sed -e "s/INTERACTIVE_REBASE_BASE_COMMIT/$INTERACTIVE_REBASE_BASE_COMMIT/" \
-e "s/BRANCH_COMMIT/$BRANCH_COMMIT/" \
-e "s/CREDIT_WHERE_CREDIT_IS_DUE/$(printf "%q" "$CREDIT_WHERE_CREDIT_IS_DUE")"/ \
-e "s/NUMBER_OF_NUGGITS/$NUMBER_OF_NUGGITS"/ \
-e "s/ALMOST_CREDITS_HASH/$ALMOST_CREDITS_HASH"/ \
-e "s/CREDITS_HASH/$CREDITS_HASH"/ \
-e "s/LOCAL_CODE_EXECUTION_HASH/$LOCAL_CODE_EXECUTION_HASH/" \
-e "s/INTERACTIVE_REBASE_EXAMPLE_PICKS/$INTERACTIVE_REBASE_EXAMPLE_PICKS/" \
-e "s/INTERACTIVE_REBASE_COMMIT/$INTERACTIVE_REBASE_COMMIT/" "$1"
Expand Down
1 change: 0 additions & 1 deletion src/nuggits
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ LocalCodeExecution
WorkInProgress
CommitmentIssues
CommitMirInsAbendteuerland
LocalCodeExecution
Switcheridoo
ShowMeMore
MyFirstBranch
Expand Down
7 changes: 6 additions & 1 deletion src/redeem.nuggit
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ else

redeemed_flags="$(git rev-list --count nuggits)"

CREDIT_WHERE_CREDIT_IS_DUE
[ "$redeemed_flags" -ne NUMBER_OF_NUGGITS ] || git cat-file -p ALMOST_CREDITS_HASH;

[ "$redeemed_flags" -ne $(( NUMBER_OF_NUGGITS + 1 )) ] || {
git cat-file -e "$(echo "# Redemed flags: $((NUMBER_OF_NUGGITS - 1))" | git hash-object --stdin)" 2>/dev/null || { echo Noughty boy!; exit 1; }
git cat-file -p CREDITS_HASH | tr 'A-Za-z' 'N-ZA-Mn-za-m';
}

git cat-file -p "$(echo "'$nuggit' already redeemed" | git hash-object --stdin)" 2>/dev/null && exit
git cat-file -p "$(echo "You tried '$nuggit' before. It still isn't a valid answer... 🙄" | git hash-object --stdin)" 2>/dev/null && exit 1
Expand Down

0 comments on commit 1405f33

Please sign in to comment.