From 44581648b4a377c11f2d1cf876d61ab9690b630f Mon Sep 17 00:00:00 2001 From: Michael Lohmann Date: Wed, 17 Jan 2024 01:10:45 +0100 Subject: [PATCH 1/4] nuggits: write their own reflog This is done, in order to avoid having the last commit of nuggits dangling --- build.sh | 3 +++ src/redeem-nuggit.sh | 2 ++ 2 files changed, 5 insertions(+) diff --git a/build.sh b/build.sh index 2205659..fe1dcfd 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")" 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" From 5c763142276891f92820c819255ac83d9286fde3 Mon Sep 17 00:00:00 2001 From: Michael Lohmann Date: Wed, 17 Jan 2024 21:12:22 +0100 Subject: [PATCH 2/4] END_COMMIT: write reflog entry to avoid dangling commit --- build.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/build.sh b/build.sh index fe1dcfd..c1f6766 100755 --- a/build.sh +++ b/build.sh @@ -71,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 From 0242973125a7382eae2110966c05134b1702cdac Mon Sep 17 00:00:00 2001 From: Michael Lohmann Date: Thu, 18 Jan 2024 20:13:20 +0100 Subject: [PATCH 3/4] lib: add debug_hooks function --- build.sh | 8 -------- lib.sh | 13 +++++++++++++ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/build.sh b/build.sh index c1f6766..e1c3aa7 100755 --- a/build.sh +++ b/build.sh @@ -240,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 +} From f726025e4684d6194016f4d84526e571f93a60cb Mon Sep 17 00:00:00 2001 From: Michael Lohmann Date: Tue, 23 Jan 2024 21:00:48 +0100 Subject: [PATCH 4/4] chapter diff: explain diff a little better --- src/02_status_diff/status.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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.