Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Main cleanup #18

Merged
merged 4 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions create_challenge.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ commit -m "WIP branch: add explanation on how to list local branches"
git switch main

# commit
sed "s/BRANCH_COMMIT/$BRANCH_COMMIT/" "$DOCDIR/03_commit/commit.md" > commit.md
replace_placeholders "$DOCDIR/03_commit/commit.md" > commit.md
git add commit.md
commit -m "Add description on commit"

git switch --detach @
# TODO: create interactive rebase commit
INTERACTIVE_REBASE_COMMIT="INTERACTIVE_REBASE_COMMIT"
sed "s/INTERACTIVE_REBASE_COMMIT/$INTERACTIVE_REBASE_COMMIT/" "$DOCDIR/07_rebase_merge/combine_history.md" > combine_history.md
replace_placeholders "$DOCDIR/07_rebase_merge/combine_history.md" > combine_history.md
git add combine_history.md
commit -m "Add description on how to combine branches"

Expand Down Expand Up @@ -103,7 +103,8 @@ rm tmp
rm .git/hooks/*

for file in $(ls "$DOCDIR/hooks"); do
cp "$DOCDIR/hooks/$file" ".git/hooks/$file.orig"
replace_placeholders "$DOCDIR/hooks/$file" > ".git/hooks/$file.orig"
chmod +x ".git/hooks/$file.orig"
done
while read -r hook; do
cp "$DOCDIR/hook_preamble.sh" ".git/hooks/$hook"
Expand Down
14 changes: 12 additions & 2 deletions lib-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ failure() {
exit 1
}

get_sh_codeblock() {
get_sh_codeblock() { # FIXME: function name is a lie, as it only returns the first line
# shellcheck disable=2016
sed -n '/^```sh$/,/^```$/{n;p;}' "$1"
sed -n '/^```sh$/{n;p;}' "$1"
}

# skipping/commenting out a testcase
Expand Down Expand Up @@ -106,3 +106,13 @@ pretty_escape() {
[ $# -eq 0 ] || printf " "
done
}

debug_replace_hooks() {
while read -r hook; do
{
echo "#!/bin/sh"
printf "%s\n" 'printf "\e[32m%s\e[0m: %s\n" "$0" "$*"'
} > ".git/hooks/$hook"
chmod +x ".git/hooks/$hook"
done < "$DOCDIR/all-git-hooks"
}
7 changes: 7 additions & 0 deletions lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,10 @@ reproducibility_setup() {
git config user.name "Nuggit Challenge"
git config user.email nuggit-challenge@gmail.com
}

replace_placeholders() {
sed -e "s/INTERACTIVE_REBASE_BASE_COMMIT/$INTERACTIVE_REBASE_BASE_COMMIT/" \
-e "s/BRANCH_COMMIT/$BRANCH_COMMIT/" \
-e "s/INTERACTIVE_REBASE_EXAMPLE_PICKS/$INTERACTIVE_REBASE_EXAMPLE_PICKS/" \
-e "s/INTERACTIVE_REBASE_COMMIT/$INTERACTIVE_REBASE_COMMIT/" "$1"
}