diff --git a/build.sh b/build.sh index 2205659..e1c3aa7 100755 --- a/build.sh +++ b/build.sh @@ -51,6 +51,9 @@ create_chapter store nuggits git commit-tree "$(printf "" | git mktree)" -m "RootOfAllNuggits Have a free nuggit!" > .git/nuggits +# Write initial reflog entry for our "branch" to avoid dangling references +mkdir .git/logs +printf "0000000000000000000000000000000000000000 %s commit (initial): RootOfAllNuggits\n" "$(git show --format="%H %cn <%cE> %ct -0000" nuggits)" > .git/logs/nuggits store_nuggits ALMOST_CREDITS_HASH="$(remote_hash_object_write "$DOCDIR/almost_credits.txt")" @@ -68,6 +71,8 @@ create_chapter final commit END_BLOB_HASH="$(git hash-object -w "$DOCDIR/credits/the-end.md")" END_TREE_HASH="$(printf "100644 blob %s success.md" "$END_BLOB_HASH" | git mktree)" END_COMMIT="$(git commit-tree "$END_TREE_HASH" -m "Success!")" +# Write reflog entry for the end commit to avoid dangling references +printf "0000000000000000000000000000000000000000 %s commit (initial): Success!\n" "$(git show --format="%H %cn <%cE> %ct -0000" "$END_COMMIT")" > .git/logs/success # ------------------------------------------------------------------------------------------- # create_chapter initial commit @@ -235,14 +240,6 @@ chmod +x .git/skip_to_chapter.sh replace NUMBER_OF_NUGGITS "$DOCDIR/progress.sh" > .git/progress.sh chmod +x .git/progress.sh -# # debug origin hooks -# while read -r hook; do -# echo '#/bin/sh -# echo "$0: $@" -# ' >> ".git/my-origin/hooks/$hook" -# chmod +x ".git/my-origin/hooks/$hook" -# done < "$DOCDIR/all-git-hooks" - # hooks (should be installed last, since they are self-mutating and would be called e.g. by `git commit`) rm .git/hooks/* # remove all the .sample files, since they are just noise diff --git a/lib.sh b/lib.sh index f44e456..1506105 100644 --- a/lib.sh +++ b/lib.sh @@ -134,3 +134,16 @@ store_nuggits() { LOCAL_CODE_EXECUTION_HASH="$(cat tmp)" rm tmp } + +debug_hooks() { + path_to_dot_git="${1:-.git}" + while read -r hook; do + echo '#/bin/sh + echo "$0: $@" + ' >> "$path_to_dot_git/hooks/$hook" + chmod +x "$path_to_dot_git/hooks/$hook" + done < "$DOCDIR/all-git-hooks" + for hook in "$path_to_dot_git/hooks/"*; do + echo 'echo "$0: $@"' >> "$hook" + done +} diff --git a/src/02_status_diff/status.md b/src/02_status_diff/status.md index 5d858f9..6ad80dd 100644 --- a/src/02_status_diff/status.md +++ b/src/02_status_diff/status.md @@ -1,5 +1,5 @@ One of the most used git commands is `git status` to see the current state (as in: Do I have uncommitted changes? Do I have changes locally that are not synced yet with the server ("pushed")?) -Another important tool is `git diff` that by default without further parameters shows the difference between the "working directory" (the files as you see them) and the "staging area" (the things you prepared to commit next). In other words: it shows only the difference to what would be committed next. +Another important tool is `git diff` that by default without further parameters shows the difference between the "working directory" (the files as you see them) and the "staging area" (the things you prepared to commit next), so basically the changes that would be left out from. In other words: it shows only the difference to what would be committed next. diff --git a/src/redeem-nuggit.sh b/src/redeem-nuggit.sh index 12a1f09..0dfe5a1 100755 --- a/src/redeem-nuggit.sh +++ b/src/redeem-nuggit.sh @@ -85,6 +85,8 @@ tree="$(git rev-parse "nuggits^{tree}")" description="$(catfile -p "NUGGIT_DESCRIPTION_TREE:$(echo "$nuggit" | git hash-object --stdin)/description")" # add an empty commit with the parent being nuggits and "reset nuggits to that new commit" git commit-tree "$tree" -p "$(cat .git/nuggits)" -m "$(printf "%s\n\n" "$nuggit" "$description")" > .git/nuggits.bak +# Manually update reflog for our "branch" to avoid dangling commits +printf "%s %s commit: %s\n" "$(cat .git/nuggits)" "$(git show --format="%H %cn <%cE> %ct -0000" nuggits.bak)" "$nuggit" >> .git/logs/nuggits # We can't directly pipe it into the file, because it will empty it before we read it... # Therefore write it into a backup file and then replace it mv .git/nuggits.bak .git/nuggits # update our "branch"