diff --git a/.gitignore b/.gitignore index 700671828..a4335524f 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,6 @@ locale/ /gameshell* game shell* boxes-data.awk +*.swp +game_dev +al_far_repo diff --git a/missions/contrib/git_advanced/01_sshkey/_clean.sh b/missions/contrib/git_advanced/01_sshkey/_clean.sh new file mode 100644 index 000000000..b3cec70ae --- /dev/null +++ b/missions/contrib/git_advanced/01_sshkey/_clean.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is used to clean the mission, +# for example on completion, or when restarting it. +# In some rare case, cleaning is different after a successful check. You can +# inspect the variable $GSH_LAST_ACTION, which can take the following values: +# assert, check_false, check_true, exit, goto, hard_reset, reset, skip +# If you need this file, rename it to clean.sh diff --git a/missions/contrib/git_advanced/01_sshkey/_test.sh b/missions/contrib/git_advanced/01_sshkey/_test.sh new file mode 100644 index 000000000..c2e0a2678 --- /dev/null +++ b/missions/contrib/git_advanced/01_sshkey/_test.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced by the command "gsh test" for +# testing during development. +# If you write this file, rename it to 'test.sh' +# +# You can use some special commands +# gsh assert check true +# gsh assert check false +# gsh assert CONDITION +# to check that specific conditions are satisfied. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. diff --git a/missions/contrib/git_advanced/01_sshkey/_treasure-msg.txt b/missions/contrib/git_advanced/01_sshkey/_treasure-msg.txt new file mode 100644 index 000000000..72094a5b9 --- /dev/null +++ b/missions/contrib/git_advanced/01_sshkey/_treasure-msg.txt @@ -0,0 +1,3 @@ +This file is not required. When it exists, it is displayed when sourcing +the "treasure.sh" file. (If no "treasure.sh" file exists, this file will +be ignored.) diff --git a/missions/contrib/git_advanced/01_sshkey/_treasure.sh b/missions/contrib/git_advanced/01_sshkey/_treasure.sh new file mode 100644 index 000000000..1fa10ce8e --- /dev/null +++ b/missions/contrib/git_advanced/01_sshkey/_treasure.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is sourced on successfull +# completion of the mission and is added to the global configuration. +# It is typically used to "reward" the player with new features like aliases +# and the like. +# If you need this file, rename it to 'treasure.txt' +# +# Note that should the mission be completed in a subshell, aliases or +# environment variables will disappear. +# That typically happens a mission is checked using process redirection, as in +# $ SOMETHING | gsh check +# To mitigate the problem, GameShell will display a message asking the player +# to run +# $ gsh reset +# in that case. diff --git a/missions/contrib/git_advanced/01_sshkey/auto.sh b/missions/contrib/git_advanced/01_sshkey/auto.sh new file mode 100644 index 000000000..f5a8ee6f9 --- /dev/null +++ b/missions/contrib/git_advanced/01_sshkey/auto.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is used to automatically +# validate the mission. It should end with a succesful `gsh check` command. +# It is sometimes possible to "cheat" by using any hidden data in $GSH_TMP, +# but it is better to do it the "intended" way. +# If you write this file, rename it to auto.sh + +url=$(LANG=GB git remote show origin | grep "Push URL" | tr -s ' ' | cut -d ' ' -f 4) +git remote set-url origin git@plmlab.math.cnrs.fr:gameshell_git/al_jeit.git +gsh check +# Put URL back in case we are working on a local remote +git remote set-url origin $url diff --git a/missions/contrib/git_advanced/01_sshkey/check.sh b/missions/contrib/git_advanced/01_sshkey/check.sh new file mode 100644 index 000000000..3ff852093 --- /dev/null +++ b/missions/contrib/git_advanced/01_sshkey/check.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env sh + +# This file is required. It is sourced when checking the goal of the mission +# has been achieved. +# It should end with a command returning 0 on success, and something else on +# failure. +# It should "unset" any local variable it has created, and any "global +# variable" that were only used for the mission. (The function _mission_check +# is automatically unset.) +# +# It typically looks like + +_mission_check() { + + # verifier que le repertoire existe et est un depot git + + if [ ! -d "$GSH_HOME/Castle/Portals/spellbook" ] + then + echo " The repository spellbook doesn't exist" + return 1 + else + echo " The repository spellbook exist" + fi + + if [ ! -d $GSH_HOME/Castle/Portals/spellbook/.git ] + then + echo " The repository spellbook is not a git repository" + return 1 + else + echo " The repository spellbook is a git repository" + fi + + cd $GSH_HOME/Castle/Portals/spellbook + + LANG=en_GB git remote show origin | grep git@ + + + test=$(echo $?) + + if [ $test -eq 1 ] + then + echo " you did not changed to SSH URL" + return 1 + fi + + return 0 +} +_mission_check diff --git a/missions/contrib/git_advanced/01_sshkey/clean.sh b/missions/contrib/git_advanced/01_sshkey/clean.sh new file mode 120000 index 000000000..614a72e95 --- /dev/null +++ b/missions/contrib/git_advanced/01_sshkey/clean.sh @@ -0,0 +1 @@ +../../git_basics/00_needed_files/clean.sh \ No newline at end of file diff --git a/missions/contrib/git_advanced/01_sshkey/goal.txt b/missions/contrib/git_advanced/01_sshkey/goal.txt new file mode 100644 index 000000000..26f89c56d --- /dev/null +++ b/missions/contrib/git_advanced/01_sshkey/goal.txt @@ -0,0 +1,27 @@ +Mission goal +============ + +According to the Head of the Magic Concil, some spellbooks have been altered in the past, due to avoidable mistakes. + +The Head of the magic council has then sent an emmissary to your castle with an urgent request: all spells created from now on should be put on the SpellBook library (Github, gitlab...) and older ones sitting in Libraries also. + +When you arrived as a wizzard in your current Castle, the previous wizzard left a few spells he was working on, without synchronizing them with the SpellBook Library + +Saving the spell of the previous wizzard without the need of creating a spell yourself is a good training. + + + +The first step as a wizard is to craft your pair of rings (public and private ssh keys) that will allow you to authenticate without login/password to the remote repository. + +1. Create your pair of rings (ssh key) +2. Upload it on your account on the interdimensional library (the remote repository git.univ-pau.fr). + + +Useful commands +=============== + +Some instructions on how to create an ssh key: +firefox https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent + +NB: in our case, we will let the passphrase empty, so no need to setup the ssh agent +Then you can either : diff --git a/missions/contrib/git_advanced/01_sshkey/init.sh b/missions/contrib/git_advanced/01_sshkey/init.sh new file mode 100644 index 000000000..6f57e56bc --- /dev/null +++ b/missions/contrib/git_advanced/01_sshkey/init.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced every time the mission is started. +# Since it is sourced every time the mission is restarted, it can generate +# random data to make each run slightly different. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. +# +# Note however that should the mission be initialized in a subshell, those +# environment variables will disappear! That typically happens a mission is +# checked using process redirection, as in +# $ SOMETHING | gsh check +# To mitigate the problem, GameShell will display a message asking the player +# to run +# $ gsh reset +# in that case. +# +# It typically looks like +_mission_init() { + + if [ -f $GSH_TMP/skip_init ] + then + rm $GSH_TMP/skip_init + else + . $GSH_TMP/clone.sh &> /dev/null + . $GSH_TMP/remove_init_branches.sh &> /dev/null + . $GSH_TMP/add_remote_origin.sh + fi + +} +_mission_init diff --git a/missions/contrib/git_advanced/01_sshkey/static.sh b/missions/contrib/git_advanced/01_sshkey/static.sh new file mode 100644 index 000000000..ec01a82da --- /dev/null +++ b/missions/contrib/git_advanced/01_sshkey/static.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced once when initialising a GameShell +# game, and whenever the corresponding missions is (re)started. +# It typically creates the parts of the mission that will be available during +# the whole game, like the directory structure. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. diff --git a/missions/contrib/git_advanced/02_git_mv/_clean.sh b/missions/contrib/git_advanced/02_git_mv/_clean.sh new file mode 100644 index 000000000..b3cec70ae --- /dev/null +++ b/missions/contrib/git_advanced/02_git_mv/_clean.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is used to clean the mission, +# for example on completion, or when restarting it. +# In some rare case, cleaning is different after a successful check. You can +# inspect the variable $GSH_LAST_ACTION, which can take the following values: +# assert, check_false, check_true, exit, goto, hard_reset, reset, skip +# If you need this file, rename it to clean.sh diff --git a/missions/contrib/git_advanced/02_git_mv/_test.sh b/missions/contrib/git_advanced/02_git_mv/_test.sh new file mode 100644 index 000000000..c2e0a2678 --- /dev/null +++ b/missions/contrib/git_advanced/02_git_mv/_test.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced by the command "gsh test" for +# testing during development. +# If you write this file, rename it to 'test.sh' +# +# You can use some special commands +# gsh assert check true +# gsh assert check false +# gsh assert CONDITION +# to check that specific conditions are satisfied. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. diff --git a/missions/contrib/git_advanced/02_git_mv/_treasure-msg.txt b/missions/contrib/git_advanced/02_git_mv/_treasure-msg.txt new file mode 100644 index 000000000..72094a5b9 --- /dev/null +++ b/missions/contrib/git_advanced/02_git_mv/_treasure-msg.txt @@ -0,0 +1,3 @@ +This file is not required. When it exists, it is displayed when sourcing +the "treasure.sh" file. (If no "treasure.sh" file exists, this file will +be ignored.) diff --git a/missions/contrib/git_advanced/02_git_mv/_treasure.sh b/missions/contrib/git_advanced/02_git_mv/_treasure.sh new file mode 100644 index 000000000..1fa10ce8e --- /dev/null +++ b/missions/contrib/git_advanced/02_git_mv/_treasure.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is sourced on successfull +# completion of the mission and is added to the global configuration. +# It is typically used to "reward" the player with new features like aliases +# and the like. +# If you need this file, rename it to 'treasure.txt' +# +# Note that should the mission be completed in a subshell, aliases or +# environment variables will disappear. +# That typically happens a mission is checked using process redirection, as in +# $ SOMETHING | gsh check +# To mitigate the problem, GameShell will display a message asking the player +# to run +# $ gsh reset +# in that case. diff --git a/missions/contrib/git_advanced/02_git_mv/auto.sh b/missions/contrib/git_advanced/02_git_mv/auto.sh new file mode 100644 index 000000000..1569cf6b2 --- /dev/null +++ b/missions/contrib/git_advanced/02_git_mv/auto.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is used to automatically +# validate the mission. It should end with a succesful `gsh check` command. +# It is sometimes possible to "cheat" by using any hidden data in $GSH_TMP, +# but it is better to do it the "intended" way. +# If you write this file, rename it to auto.sh + +cd $GSH_HOME/Castle/Portals/spellbook +mkdir Chapter_1 +git mv truth_spell glowing_finger_spell Chapter_1/ +git commit -m "moving spell into Chapter_1" +git push +gsh check diff --git a/missions/contrib/git_advanced/02_git_mv/check.sh b/missions/contrib/git_advanced/02_git_mv/check.sh new file mode 100644 index 000000000..4f2971fc9 --- /dev/null +++ b/missions/contrib/git_advanced/02_git_mv/check.sh @@ -0,0 +1,83 @@ +#!/usr/bin/env sh + +# This file is required. It is sourced when checking the goal of the mission +# has been achieved. +# It should end with a command returning 0 on success, and something else on +# failure. +# It should "unset" any local variable it has created, and any "global +# variable" that were only used for the mission. (The function _mission_check +# is automatically unset.) +# +# It typically looks like + +_mission_check() { + + if [ ! -e "$GSH_HOME/Castle/Portals/spellbook/Chapter_1/glowing_finger_spell" ] + then + echo " The file glowing_finger_spell is not in Chapter_1" + return 1 + else + echo " The file glowing_finger_spell is in Chapter_1" + fi + + if [ ! -e "$GSH_HOME/Castle/Portals/spellbook/Chapter_1/truth_spell" ] + then + echo " The file truth_spell is not in Chapter_1" + return 1 + else + echo " The file truth_spell is in Chapter_1" + fi + + + # verifier que le repertoire existe et est un depot git + cd $GSH_HOME/Castle/Portals/spellbook/ + + # verif que tous les fichiers sont suivis + LANG=en_GB git status | grep -e "Untracked" + + test=$(echo $?) + + if [ $test -eq 0 ] + then + echo "You should not have untracked file." + return 1 + fi + + # verif que aucune modif ne traine dans la copie de travail + LANG=en_GB git status | grep -e "Changes not staged for commit:" + + test=$(echo $?) + + if [ $test -eq 0 ] + then + echo "You still have changes in your working directory. Everything should be committed, no change should remain." + return 1 + fi + + + + LANG=en_GB git status | grep -e "up to date with" + test=$(echo $?) + + if [ $test -eq 1 ] + then + echo " You did not push all of your modifications." + return 1 + else + cd $GSH_HOME/Castle/Portals/spellbook/ + + LANG=en_GB git status | grep -e "Changes to be committed:" + test=$(echo $?) + + if [ $test -eq 0 ] + then + echo " You did not commit all of your modifications" + return 1 + else + echo " You did push all of your modifications" + return 0 + fi + fi + +} +_mission_check diff --git a/missions/contrib/git_advanced/02_git_mv/clean.sh b/missions/contrib/git_advanced/02_git_mv/clean.sh new file mode 120000 index 000000000..614a72e95 --- /dev/null +++ b/missions/contrib/git_advanced/02_git_mv/clean.sh @@ -0,0 +1 @@ +../../git_basics/00_needed_files/clean.sh \ No newline at end of file diff --git a/missions/contrib/git_advanced/02_git_mv/goal.txt b/missions/contrib/git_advanced/02_git_mv/goal.txt new file mode 100644 index 000000000..253b0576c --- /dev/null +++ b/missions/contrib/git_advanced/02_git_mv/goal.txt @@ -0,0 +1,28 @@ +Mission goal +============ + +It can be convenient to make chapters for your spells. + +Create a First Chapter (called Chapter_1) and move your two spells into that folder. + +This can be done along with a stagged synchronisation. + +Warning: do not forget to create the directory before moving files ! + + +Useful commands +=============== + +git add FOLDER_NAME + +git mv FILE_NAME FOLDER_NAME/ + +git status + +git commit -m "moving spell into Chapter_1" + +git push + + + + diff --git a/missions/contrib/git_advanced/02_git_mv/init.sh b/missions/contrib/git_advanced/02_git_mv/init.sh new file mode 100644 index 000000000..a002b5b87 --- /dev/null +++ b/missions/contrib/git_advanced/02_git_mv/init.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced every time the mission is started. +# Since it is sourced every time the mission is restarted, it can generate +# random data to make each run slightly different. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. +# +# Note however that should the mission be initialized in a subshell, those +# environment variables will disappear! That typically happens a mission is +# checked using process redirection, as in +# $ SOMETHING | gsh check +# To mitigate the problem, GameShell will display a message asking the player +# to run +# $ gsh reset +# in that case. +# +# It typically looks like +_mission_init() { + + if [ -f $GSH_TMP/skip_init ] + then + rm $GSH_TMP/skip_init + else + . $GSH_TMP/clone.sh &> /dev/null + git reset --hard origin/truth_spell_added &> /dev/null + . $GSH_TMP/remove_init_branches.sh &> /dev/null + . $GSH_TMP/add_remote_origin.sh + fi + +} +_mission_init diff --git a/missions/contrib/git_advanced/02_git_mv/static.sh b/missions/contrib/git_advanced/02_git_mv/static.sh new file mode 100644 index 000000000..ec01a82da --- /dev/null +++ b/missions/contrib/git_advanced/02_git_mv/static.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced once when initialising a GameShell +# game, and whenever the corresponding missions is (re)started. +# It typically creates the parts of the mission that will be available during +# the whole game, like the directory structure. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. diff --git a/missions/contrib/git_advanced/03_edit_commit_push_Readme/_clean.sh b/missions/contrib/git_advanced/03_edit_commit_push_Readme/_clean.sh new file mode 100644 index 000000000..b3cec70ae --- /dev/null +++ b/missions/contrib/git_advanced/03_edit_commit_push_Readme/_clean.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is used to clean the mission, +# for example on completion, or when restarting it. +# In some rare case, cleaning is different after a successful check. You can +# inspect the variable $GSH_LAST_ACTION, which can take the following values: +# assert, check_false, check_true, exit, goto, hard_reset, reset, skip +# If you need this file, rename it to clean.sh diff --git a/missions/contrib/git_advanced/03_edit_commit_push_Readme/_test.sh b/missions/contrib/git_advanced/03_edit_commit_push_Readme/_test.sh new file mode 100644 index 000000000..c2e0a2678 --- /dev/null +++ b/missions/contrib/git_advanced/03_edit_commit_push_Readme/_test.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced by the command "gsh test" for +# testing during development. +# If you write this file, rename it to 'test.sh' +# +# You can use some special commands +# gsh assert check true +# gsh assert check false +# gsh assert CONDITION +# to check that specific conditions are satisfied. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. diff --git a/missions/contrib/git_advanced/03_edit_commit_push_Readme/_treasure-msg.txt b/missions/contrib/git_advanced/03_edit_commit_push_Readme/_treasure-msg.txt new file mode 100644 index 000000000..72094a5b9 --- /dev/null +++ b/missions/contrib/git_advanced/03_edit_commit_push_Readme/_treasure-msg.txt @@ -0,0 +1,3 @@ +This file is not required. When it exists, it is displayed when sourcing +the "treasure.sh" file. (If no "treasure.sh" file exists, this file will +be ignored.) diff --git a/missions/contrib/git_advanced/03_edit_commit_push_Readme/_treasure.sh b/missions/contrib/git_advanced/03_edit_commit_push_Readme/_treasure.sh new file mode 100644 index 000000000..1fa10ce8e --- /dev/null +++ b/missions/contrib/git_advanced/03_edit_commit_push_Readme/_treasure.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is sourced on successfull +# completion of the mission and is added to the global configuration. +# It is typically used to "reward" the player with new features like aliases +# and the like. +# If you need this file, rename it to 'treasure.txt' +# +# Note that should the mission be completed in a subshell, aliases or +# environment variables will disappear. +# That typically happens a mission is checked using process redirection, as in +# $ SOMETHING | gsh check +# To mitigate the problem, GameShell will display a message asking the player +# to run +# $ gsh reset +# in that case. diff --git a/missions/contrib/git_advanced/03_edit_commit_push_Readme/auto.sh b/missions/contrib/git_advanced/03_edit_commit_push_Readme/auto.sh new file mode 100644 index 000000000..15189724a --- /dev/null +++ b/missions/contrib/git_advanced/03_edit_commit_push_Readme/auto.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is used to automatically +# validate the mission. It should end with a succesful `gsh check` command. +# It is sometimes possible to "cheat" by using any hidden data in $GSH_TMP, +# but it is better to do it the "intended" way. +# If you write this file, rename it to auto.sh + +cd $GSH_HOME/Castle/Portals/spellbook +echo "Glowing finger and Truth spells" >> README.md +git commit -am "README updated" +git push +gsh check diff --git a/missions/contrib/git_advanced/03_edit_commit_push_Readme/check.sh b/missions/contrib/git_advanced/03_edit_commit_push_Readme/check.sh new file mode 100644 index 000000000..7056d6abe --- /dev/null +++ b/missions/contrib/git_advanced/03_edit_commit_push_Readme/check.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env sh + +# This file is required. It is sourced when checking the goal of the mission +# has been achieved. +# It should end with a command returning 0 on success, and something else on +# failure. +# It should "unset" any local variable it has created, and any "global +# variable" that were only used for the mission. (The function _mission_check +# is automatically unset.) +# +# It typically looks like + +_mission_check() { + cd $GSH_HOME/Castle/Portals/spellbook/ + +LANG=en_GB git status | grep -e "Untracked" + + test=$(echo $?) + + if [ $test -eq 0 ] + then + echo " you not have untracked file" + return 1 + fi + + +LANG=en_GB git status | grep -e "modified" + + test=$(echo $?) + + if [ $test -eq 0 ] + then + echo " you a modified file" + return 1 + fi + + + + LANG=en_GB git status | grep -e "up to date with" +test=$(echo $?) + + if [ $test -eq 1 ] + then + echo " You did not pushed all of your modifications" + return 1 + else + cd $GSH_HOME/Castle/Portals/spellbook/ + + LANG=en_GB git status | grep -e "Changes to be committed:" + test=$(echo $?) + + if [ $test -eq 0 ] + then + echo " You did not commited all of your modifications" + return 1 + else + echo " You did pushed all of your modifications" + return 0 + fi + fi + +} +_mission_check diff --git a/missions/contrib/git_advanced/03_edit_commit_push_Readme/clean.sh b/missions/contrib/git_advanced/03_edit_commit_push_Readme/clean.sh new file mode 120000 index 000000000..614a72e95 --- /dev/null +++ b/missions/contrib/git_advanced/03_edit_commit_push_Readme/clean.sh @@ -0,0 +1 @@ +../../git_basics/00_needed_files/clean.sh \ No newline at end of file diff --git a/missions/contrib/git_advanced/03_edit_commit_push_Readme/goal.txt b/missions/contrib/git_advanced/03_edit_commit_push_Readme/goal.txt new file mode 100644 index 000000000..5a3ee789a --- /dev/null +++ b/missions/contrib/git_advanced/03_edit_commit_push_Readme/goal.txt @@ -0,0 +1,46 @@ +Mission goal +============ + +The front page of a SpellBook is important for magicians. + +It usually gives informations on the content of the SpellBook, and how to use it. + +Edit the front page (README.md), and add a brief description of the first spell. + +Then synchronise your spellbook with the library + + +Useful commands +=============== + +You can use any text editor: +gedit FILENAME +vi FILENAME +nano FILENAME + + +when modifying a file you can commit the modification for this file in one go: +git commit -m 'COMMIT_MESSAGE' FILENAME + + +But staged modifications can work as well, and are usualy a better practice: + +git add FILENAME +git commit -m 'COMMIT_MESSAGE' + +This allows you to modify multiple files while performing a single commit + + +git push + + +NB +=============== +You can also use the following commands + +git log + + +git status + + diff --git a/missions/contrib/git_advanced/03_edit_commit_push_Readme/init.sh b/missions/contrib/git_advanced/03_edit_commit_push_Readme/init.sh new file mode 100644 index 000000000..7f179b1b5 --- /dev/null +++ b/missions/contrib/git_advanced/03_edit_commit_push_Readme/init.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced every time the mission is started. +# Since it is sourced every time the mission is restarted, it can generate +# random data to make each run slightly different. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. +# +# Note however that should the mission be initialized in a subshell, those +# environment variables will disappear! That typically happens a mission is +# checked using process redirection, as in +# $ SOMETHING | gsh check +# To mitigate the problem, GameShell will display a message asking the player +# to run +# $ gsh reset +# in that case. +# +# It typically looks like +_mission_init() { + + if [ -f $GSH_TMP/skip_init ] + then + rm $GSH_TMP/skip_init + else + . $GSH_TMP/clone.sh &> /dev/null + git reset --hard origin/moving_spell_into_Chapter_1 &> /dev/null + . $GSH_TMP/remove_init_branches.sh &> /dev/null + . $GSH_TMP/add_remote_origin.sh + fi + +} +_mission_init diff --git a/missions/contrib/git_advanced/03_edit_commit_push_Readme/static.sh b/missions/contrib/git_advanced/03_edit_commit_push_Readme/static.sh new file mode 100644 index 000000000..ec01a82da --- /dev/null +++ b/missions/contrib/git_advanced/03_edit_commit_push_Readme/static.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced once when initialising a GameShell +# game, and whenever the corresponding missions is (re)started. +# It typically creates the parts of the mission that will be available during +# the whole game, like the directory structure. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. diff --git a/missions/contrib/git_advanced/04_git_rm/_clean.sh b/missions/contrib/git_advanced/04_git_rm/_clean.sh new file mode 100644 index 000000000..b3cec70ae --- /dev/null +++ b/missions/contrib/git_advanced/04_git_rm/_clean.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is used to clean the mission, +# for example on completion, or when restarting it. +# In some rare case, cleaning is different after a successful check. You can +# inspect the variable $GSH_LAST_ACTION, which can take the following values: +# assert, check_false, check_true, exit, goto, hard_reset, reset, skip +# If you need this file, rename it to clean.sh diff --git a/missions/contrib/git_advanced/04_git_rm/_test.sh b/missions/contrib/git_advanced/04_git_rm/_test.sh new file mode 100644 index 000000000..c2e0a2678 --- /dev/null +++ b/missions/contrib/git_advanced/04_git_rm/_test.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced by the command "gsh test" for +# testing during development. +# If you write this file, rename it to 'test.sh' +# +# You can use some special commands +# gsh assert check true +# gsh assert check false +# gsh assert CONDITION +# to check that specific conditions are satisfied. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. diff --git a/missions/contrib/git_advanced/04_git_rm/_treasure-msg.txt b/missions/contrib/git_advanced/04_git_rm/_treasure-msg.txt new file mode 100644 index 000000000..72094a5b9 --- /dev/null +++ b/missions/contrib/git_advanced/04_git_rm/_treasure-msg.txt @@ -0,0 +1,3 @@ +This file is not required. When it exists, it is displayed when sourcing +the "treasure.sh" file. (If no "treasure.sh" file exists, this file will +be ignored.) diff --git a/missions/contrib/git_advanced/04_git_rm/_treasure.sh b/missions/contrib/git_advanced/04_git_rm/_treasure.sh new file mode 100644 index 000000000..1fa10ce8e --- /dev/null +++ b/missions/contrib/git_advanced/04_git_rm/_treasure.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is sourced on successfull +# completion of the mission and is added to the global configuration. +# It is typically used to "reward" the player with new features like aliases +# and the like. +# If you need this file, rename it to 'treasure.txt' +# +# Note that should the mission be completed in a subshell, aliases or +# environment variables will disappear. +# That typically happens a mission is checked using process redirection, as in +# $ SOMETHING | gsh check +# To mitigate the problem, GameShell will display a message asking the player +# to run +# $ gsh reset +# in that case. diff --git a/missions/contrib/git_advanced/04_git_rm/auto.sh b/missions/contrib/git_advanced/04_git_rm/auto.sh new file mode 100644 index 000000000..2263fb58f --- /dev/null +++ b/missions/contrib/git_advanced/04_git_rm/auto.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is used to automatically +# validate the mission. It should end with a succesful `gsh check` command. +# It is sometimes possible to "cheat" by using any hidden data in $GSH_TMP, +# but it is better to do it the "intended" way. +# If you write this file, rename it to auto.sh + +cd $GSH_HOME/Castle/Portals/spellbook +git rm Chapter_1/truth_spell +git commit -m "truth spell removed" +git push +gsh check + diff --git a/missions/contrib/git_advanced/04_git_rm/check.sh b/missions/contrib/git_advanced/04_git_rm/check.sh new file mode 100644 index 000000000..1690eb8e5 --- /dev/null +++ b/missions/contrib/git_advanced/04_git_rm/check.sh @@ -0,0 +1,74 @@ +#!/usr/bin/env sh + +# This file is required. It is sourced when checking the goal of the mission +# has been achieved. +# It should end with a command returning 0 on success, and something else on +# failure. +# It should "unset" any local variable it has created, and any "global +# variable" that were only used for the mission. (The function _mission_check +# is automatically unset.) +# +# It typically looks like + +_mission_check() { + + + if [ ! -e "$GSH_HOME/Castle/Portals/spellbook/Chapter_1/truth_spell" ] + then + echo " The file truth_spell does not exist" + else + echo " The file truth_spell should not exist anymore" + return 1 + fi + + cd $GSH_HOME/Castle/Portals/spellbook/ + +LANG=en_GB git status | grep -e "Untracked" + + test=$(echo $?) + + if [ $test -eq 0 ] + then + echo " you not have untracked file" + return 1 + fi + + + +LANG=en_GB git status | grep -e "deleted" + + test=$(echo $?) + + if [ $test -eq 0 ] + then + echo " you deleted a file: use 'git rm' instead of 'rm' and/or commit your modifications" + return 1 + fi + + + + LANG=en_GB git status | grep -e "up to date with" +test=$(echo $?) + + if [ $test -eq 1 ] + then + echo " You did not pushed all of your modifications" + return 1 + else + cd $GSH_HOME/Castle/Portals/spellbook/ + + LANG=en_GB git status | grep -e "Changes to be committed:" + test=$(echo $?) + + if [ $test -eq 0 ] + then + echo " You did not commited all of your modifications" + return 1 + else + echo " You did pushed all of your modifications" + return 0 + fi + fi + +} +_mission_check diff --git a/missions/contrib/git_advanced/04_git_rm/clean.sh b/missions/contrib/git_advanced/04_git_rm/clean.sh new file mode 120000 index 000000000..614a72e95 --- /dev/null +++ b/missions/contrib/git_advanced/04_git_rm/clean.sh @@ -0,0 +1 @@ +../../git_basics/00_needed_files/clean.sh \ No newline at end of file diff --git a/missions/contrib/git_advanced/04_git_rm/goal.txt b/missions/contrib/git_advanced/04_git_rm/goal.txt new file mode 100644 index 000000000..f925de06e --- /dev/null +++ b/missions/contrib/git_advanced/04_git_rm/goal.txt @@ -0,0 +1,20 @@ +Mission goal +============ + +Althought the glowing finger spell is obviously usefull, the usefullness of the truth spell seems inexistant. + +Remove the truth spell from your spellbook. + + +Useful commands +=============== + +git rm FILENAME : remove the file FILENAME + +git commit -m 'COMMIT_MESSAGE' + +git push + + + + diff --git a/missions/contrib/git_advanced/04_git_rm/init.sh b/missions/contrib/git_advanced/04_git_rm/init.sh new file mode 100644 index 000000000..347014900 --- /dev/null +++ b/missions/contrib/git_advanced/04_git_rm/init.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced every time the mission is started. +# Since it is sourced every time the mission is restarted, it can generate +# random data to make each run slightly different. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. +# +# Note however that should the mission be initialized in a subshell, those +# environment variables will disappear! That typically happens a mission is +# checked using process redirection, as in +# $ SOMETHING | gsh check +# To mitigate the problem, GameShell will display a message asking the player +# to run +# $ gsh reset +# in that case. +# +# It typically looks like +_mission_init() { + + if [ -f $GSH_TMP/skip_init ] + then + rm $GSH_TMP/skip_init + else + . $GSH_TMP/clone.sh &> /dev/null + git reset --hard origin/README_updated &> /dev/null + . $GSH_TMP/remove_init_branches.sh &> /dev/null + . $GSH_TMP/add_remote_origin.sh + fi + +} +_mission_init diff --git a/missions/contrib/git_advanced/04_git_rm/static.sh b/missions/contrib/git_advanced/04_git_rm/static.sh new file mode 100644 index 000000000..ec01a82da --- /dev/null +++ b/missions/contrib/git_advanced/04_git_rm/static.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced once when initialising a GameShell +# game, and whenever the corresponding missions is (re)started. +# It typically creates the parts of the mission that will be available during +# the whole game, like the directory structure. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. diff --git a/missions/contrib/git_advanced/05a_git_checkout/_clean.sh b/missions/contrib/git_advanced/05a_git_checkout/_clean.sh new file mode 100644 index 000000000..b3cec70ae --- /dev/null +++ b/missions/contrib/git_advanced/05a_git_checkout/_clean.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is used to clean the mission, +# for example on completion, or when restarting it. +# In some rare case, cleaning is different after a successful check. You can +# inspect the variable $GSH_LAST_ACTION, which can take the following values: +# assert, check_false, check_true, exit, goto, hard_reset, reset, skip +# If you need this file, rename it to clean.sh diff --git a/missions/contrib/git_advanced/05a_git_checkout/_test.sh b/missions/contrib/git_advanced/05a_git_checkout/_test.sh new file mode 100644 index 000000000..c2e0a2678 --- /dev/null +++ b/missions/contrib/git_advanced/05a_git_checkout/_test.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced by the command "gsh test" for +# testing during development. +# If you write this file, rename it to 'test.sh' +# +# You can use some special commands +# gsh assert check true +# gsh assert check false +# gsh assert CONDITION +# to check that specific conditions are satisfied. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. diff --git a/missions/contrib/git_advanced/05a_git_checkout/_treasure-msg.txt b/missions/contrib/git_advanced/05a_git_checkout/_treasure-msg.txt new file mode 100644 index 000000000..72094a5b9 --- /dev/null +++ b/missions/contrib/git_advanced/05a_git_checkout/_treasure-msg.txt @@ -0,0 +1,3 @@ +This file is not required. When it exists, it is displayed when sourcing +the "treasure.sh" file. (If no "treasure.sh" file exists, this file will +be ignored.) diff --git a/missions/contrib/git_advanced/05a_git_checkout/_treasure.sh b/missions/contrib/git_advanced/05a_git_checkout/_treasure.sh new file mode 100644 index 000000000..1fa10ce8e --- /dev/null +++ b/missions/contrib/git_advanced/05a_git_checkout/_treasure.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is sourced on successfull +# completion of the mission and is added to the global configuration. +# It is typically used to "reward" the player with new features like aliases +# and the like. +# If you need this file, rename it to 'treasure.txt' +# +# Note that should the mission be completed in a subshell, aliases or +# environment variables will disappear. +# That typically happens a mission is checked using process redirection, as in +# $ SOMETHING | gsh check +# To mitigate the problem, GameShell will display a message asking the player +# to run +# $ gsh reset +# in that case. diff --git a/missions/contrib/git_advanced/05a_git_checkout/auto.sh b/missions/contrib/git_advanced/05a_git_checkout/auto.sh new file mode 100644 index 000000000..b9d5a8d23 --- /dev/null +++ b/missions/contrib/git_advanced/05a_git_checkout/auto.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is used to automatically +# validate the mission. It should end with a succesful `gsh check` command. +# It is sometimes possible to "cheat" by using any hidden data in $GSH_TMP, +# but it is better to do it the "intended" way. +# If you write this file, rename it to auto.sh + +cd $GSH_HOME/Castle/Portals/spellbook +git checkout HEAD^ +gsh check + diff --git a/missions/contrib/git_advanced/05a_git_checkout/check.sh b/missions/contrib/git_advanced/05a_git_checkout/check.sh new file mode 100644 index 000000000..377624771 --- /dev/null +++ b/missions/contrib/git_advanced/05a_git_checkout/check.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env sh + +# This file is required. It is sourced when checking the goal of the mission +# has been achieved. +# It should end with a command returning 0 on success, and something else on +# failure. +# It should "unset" any local variable it has created, and any "global +# variable" that were only used for the mission. (The function _mission_check +# is automatically unset.) +# +# It typically looks like + +_mission_check() { + + + if [ ! -e "$GSH_HOME/Castle/Portals/spellbook/Chapter_1/truth_spell" ] + then + echo " The file truth_spell is not in Chapter_1" + return 1 + fi + + LANG=en_GB git branch | grep -e "tach" + + test=$(echo $?) + + if [ $test -eq 1 ] + then + echo " You did not checkout a previous commit" + return 1 + else + return 0 + + fi + + + + + +} +_mission_check diff --git a/missions/contrib/git_advanced/05a_git_checkout/clean.sh b/missions/contrib/git_advanced/05a_git_checkout/clean.sh new file mode 120000 index 000000000..614a72e95 --- /dev/null +++ b/missions/contrib/git_advanced/05a_git_checkout/clean.sh @@ -0,0 +1 @@ +../../git_basics/00_needed_files/clean.sh \ No newline at end of file diff --git a/missions/contrib/git_advanced/05a_git_checkout/goal.txt b/missions/contrib/git_advanced/05a_git_checkout/goal.txt new file mode 100644 index 000000000..3279ac32a --- /dev/null +++ b/missions/contrib/git_advanced/05a_git_checkout/goal.txt @@ -0,0 +1,25 @@ +Mission goal +============ + +You just removed the spell of truth from your spellbook. + +As mentionned earlier, the point of the synchronised Library is not just to share your spells, but also to keep track of your modifications. + +Even a deleted spell can be read through the specific comand line. + +Ask git with a checkout to update your working directory with a previous version of your spellbook, a version that still contains the truth spell in Chapter_1. + + +Useful commands +=============== + +git checkout COMMIT_ID +COMMIT_ID can be the id given by `git log` or a branch name + +Warning: specifying directly a commit id will bring you in "detached HEAD". It is ok to explore this version of the project, but if some development should be done from this version, a proper new branch will be necessary. + +git log --oneline: will display the list of previous commit in a nicer way + + + + diff --git a/missions/contrib/git_advanced/05a_git_checkout/init.sh b/missions/contrib/git_advanced/05a_git_checkout/init.sh new file mode 100644 index 000000000..e105df1ac --- /dev/null +++ b/missions/contrib/git_advanced/05a_git_checkout/init.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced every time the mission is started. +# Since it is sourced every time the mission is restarted, it can generate +# random data to make each run slightly different. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. +# +# Note however that should the mission be initialized in a subshell, those +# environment variables will disappear! That typically happens a mission is +# checked using process redirection, as in +# $ SOMETHING | gsh check +# To mitigate the problem, GameShell will display a message asking the player +# to run +# $ gsh reset +# in that case. +# +# It typically looks like +_mission_init() { + + if [ -f $GSH_TMP/skip_init ] + then + rm $GSH_TMP/skip_init + else + . $GSH_TMP/clone.sh &> /dev/null + git reset --hard origin/truth_spell_removed &> /dev/null + . $GSH_TMP/remove_init_branches.sh &> /dev/null + . $GSH_TMP/add_remote_origin.sh + fi + +} +_mission_init diff --git a/missions/contrib/git_advanced/05a_git_checkout/static.sh b/missions/contrib/git_advanced/05a_git_checkout/static.sh new file mode 100644 index 000000000..ec01a82da --- /dev/null +++ b/missions/contrib/git_advanced/05a_git_checkout/static.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced once when initialising a GameShell +# game, and whenever the corresponding missions is (re)started. +# It typically creates the parts of the mission that will be available during +# the whole game, like the directory structure. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. diff --git a/missions/contrib/git_advanced/05b_git_checkout/_clean.sh b/missions/contrib/git_advanced/05b_git_checkout/_clean.sh new file mode 100644 index 000000000..b3cec70ae --- /dev/null +++ b/missions/contrib/git_advanced/05b_git_checkout/_clean.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is used to clean the mission, +# for example on completion, or when restarting it. +# In some rare case, cleaning is different after a successful check. You can +# inspect the variable $GSH_LAST_ACTION, which can take the following values: +# assert, check_false, check_true, exit, goto, hard_reset, reset, skip +# If you need this file, rename it to clean.sh diff --git a/missions/contrib/git_advanced/05b_git_checkout/_test.sh b/missions/contrib/git_advanced/05b_git_checkout/_test.sh new file mode 100644 index 000000000..c2e0a2678 --- /dev/null +++ b/missions/contrib/git_advanced/05b_git_checkout/_test.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced by the command "gsh test" for +# testing during development. +# If you write this file, rename it to 'test.sh' +# +# You can use some special commands +# gsh assert check true +# gsh assert check false +# gsh assert CONDITION +# to check that specific conditions are satisfied. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. diff --git a/missions/contrib/git_advanced/05b_git_checkout/_treasure-msg.txt b/missions/contrib/git_advanced/05b_git_checkout/_treasure-msg.txt new file mode 100644 index 000000000..72094a5b9 --- /dev/null +++ b/missions/contrib/git_advanced/05b_git_checkout/_treasure-msg.txt @@ -0,0 +1,3 @@ +This file is not required. When it exists, it is displayed when sourcing +the "treasure.sh" file. (If no "treasure.sh" file exists, this file will +be ignored.) diff --git a/missions/contrib/git_advanced/05b_git_checkout/_treasure.sh b/missions/contrib/git_advanced/05b_git_checkout/_treasure.sh new file mode 100644 index 000000000..1fa10ce8e --- /dev/null +++ b/missions/contrib/git_advanced/05b_git_checkout/_treasure.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is sourced on successfull +# completion of the mission and is added to the global configuration. +# It is typically used to "reward" the player with new features like aliases +# and the like. +# If you need this file, rename it to 'treasure.txt' +# +# Note that should the mission be completed in a subshell, aliases or +# environment variables will disappear. +# That typically happens a mission is checked using process redirection, as in +# $ SOMETHING | gsh check +# To mitigate the problem, GameShell will display a message asking the player +# to run +# $ gsh reset +# in that case. diff --git a/missions/contrib/git_advanced/05b_git_checkout/auto.sh b/missions/contrib/git_advanced/05b_git_checkout/auto.sh new file mode 100644 index 000000000..178ccf635 --- /dev/null +++ b/missions/contrib/git_advanced/05b_git_checkout/auto.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is used to automatically +# validate the mission. It should end with a succesful `gsh check` command. +# It is sometimes possible to "cheat" by using any hidden data in $GSH_TMP, +# but it is better to do it the "intended" way. +# If you write this file, rename it to auto.sh + +cd $GSH_HOME/Castle/Portals/spellbook +git checkout main +gsh check + diff --git a/missions/contrib/git_advanced/05b_git_checkout/check.sh b/missions/contrib/git_advanced/05b_git_checkout/check.sh new file mode 100644 index 000000000..0ccb89552 --- /dev/null +++ b/missions/contrib/git_advanced/05b_git_checkout/check.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env sh + +# This file is required. It is sourced when checking the goal of the mission +# has been achieved. +# It should end with a command returning 0 on success, and something else on +# failure. +# It should "unset" any local variable it has created, and any "global +# variable" that were only used for the mission. (The function _mission_check +# is automatically unset.) +# +# It typically looks like + +_mission_check() { + + LANG=en_GB git branch | grep -e "tach" +test=$(echo $?) + + if [ $test -eq 1 ] + then + return 0 + else + echo " You did not checkout the most recent commit" + + return 1 + + fi + +} +_mission_check diff --git a/missions/contrib/git_advanced/05b_git_checkout/clean.sh b/missions/contrib/git_advanced/05b_git_checkout/clean.sh new file mode 120000 index 000000000..614a72e95 --- /dev/null +++ b/missions/contrib/git_advanced/05b_git_checkout/clean.sh @@ -0,0 +1 @@ +../../git_basics/00_needed_files/clean.sh \ No newline at end of file diff --git a/missions/contrib/git_advanced/05b_git_checkout/goal.txt b/missions/contrib/git_advanced/05b_git_checkout/goal.txt new file mode 100644 index 000000000..de50debeb --- /dev/null +++ b/missions/contrib/git_advanced/05b_git_checkout/goal.txt @@ -0,0 +1,27 @@ +Mission goal +============ + + +You are familiar with the history of modifications. + +Now, you need to go back to the most recent version of your spellbook. + +Ask git to update your working directory with this version by specifying the main branch of your spellbook. + + + +Useful commands +=============== + +git log oneline : will display the list of previous commit + + +git checkout BRANCH_NAME: will checkout the most recent commit of the branch "BRANCH_NAME" + +git branch: display your current branch and the list of available branches. + + +NB +============ + +branches will be introduced more properly in the next missions. diff --git a/missions/contrib/git_advanced/05b_git_checkout/init.sh b/missions/contrib/git_advanced/05b_git_checkout/init.sh new file mode 100644 index 000000000..68ebbd5b9 --- /dev/null +++ b/missions/contrib/git_advanced/05b_git_checkout/init.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced every time the mission is started. +# Since it is sourced every time the mission is restarted, it can generate +# random data to make each run slightly different. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. +# +# Note however that should the mission be initialized in a subshell, those +# environment variables will disappear! That typically happens a mission is +# checked using process redirection, as in +# $ SOMETHING | gsh check +# To mitigate the problem, GameShell will display a message asking the player +# to run +# $ gsh reset +# in that case. +# +# It typically looks like +_mission_init() { + + if [ -f $GSH_TMP/skip_init ] + then + rm $GSH_TMP/skip_init + else + . $GSH_TMP/clone.sh &> /dev/null + git reset --hard origin/truth_spell_removed &> /dev/null + . $GSH_TMP/remove_init_branches.sh &> /dev/null + . $GSH_TMP/add_remote_origin.sh + git checkout HEAD^ &> /dev/null + fi + +} +_mission_init diff --git a/missions/contrib/git_advanced/05b_git_checkout/static.sh b/missions/contrib/git_advanced/05b_git_checkout/static.sh new file mode 100644 index 000000000..ec01a82da --- /dev/null +++ b/missions/contrib/git_advanced/05b_git_checkout/static.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced once when initialising a GameShell +# game, and whenever the corresponding missions is (re)started. +# It typically creates the parts of the mission that will be available during +# the whole game, like the directory structure. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. diff --git a/missions/contrib/git_advanced/06_git_revert/_clean.sh b/missions/contrib/git_advanced/06_git_revert/_clean.sh new file mode 100644 index 000000000..b3cec70ae --- /dev/null +++ b/missions/contrib/git_advanced/06_git_revert/_clean.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is used to clean the mission, +# for example on completion, or when restarting it. +# In some rare case, cleaning is different after a successful check. You can +# inspect the variable $GSH_LAST_ACTION, which can take the following values: +# assert, check_false, check_true, exit, goto, hard_reset, reset, skip +# If you need this file, rename it to clean.sh diff --git a/missions/contrib/git_advanced/06_git_revert/_test.sh b/missions/contrib/git_advanced/06_git_revert/_test.sh new file mode 100644 index 000000000..c2e0a2678 --- /dev/null +++ b/missions/contrib/git_advanced/06_git_revert/_test.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced by the command "gsh test" for +# testing during development. +# If you write this file, rename it to 'test.sh' +# +# You can use some special commands +# gsh assert check true +# gsh assert check false +# gsh assert CONDITION +# to check that specific conditions are satisfied. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. diff --git a/missions/contrib/git_advanced/06_git_revert/_treasure-msg.txt b/missions/contrib/git_advanced/06_git_revert/_treasure-msg.txt new file mode 100644 index 000000000..72094a5b9 --- /dev/null +++ b/missions/contrib/git_advanced/06_git_revert/_treasure-msg.txt @@ -0,0 +1,3 @@ +This file is not required. When it exists, it is displayed when sourcing +the "treasure.sh" file. (If no "treasure.sh" file exists, this file will +be ignored.) diff --git a/missions/contrib/git_advanced/06_git_revert/_treasure.sh b/missions/contrib/git_advanced/06_git_revert/_treasure.sh new file mode 100644 index 000000000..1fa10ce8e --- /dev/null +++ b/missions/contrib/git_advanced/06_git_revert/_treasure.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is sourced on successfull +# completion of the mission and is added to the global configuration. +# It is typically used to "reward" the player with new features like aliases +# and the like. +# If you need this file, rename it to 'treasure.txt' +# +# Note that should the mission be completed in a subshell, aliases or +# environment variables will disappear. +# That typically happens a mission is checked using process redirection, as in +# $ SOMETHING | gsh check +# To mitigate the problem, GameShell will display a message asking the player +# to run +# $ gsh reset +# in that case. diff --git a/missions/contrib/git_advanced/06_git_revert/auto.sh b/missions/contrib/git_advanced/06_git_revert/auto.sh new file mode 100644 index 000000000..16f0f0e2b --- /dev/null +++ b/missions/contrib/git_advanced/06_git_revert/auto.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is used to automatically +# validate the mission. It should end with a succesful `gsh check` command. +# It is sometimes possible to "cheat" by using any hidden data in $GSH_TMP, +# but it is better to do it the "intended" way. +# If you write this file, rename it to auto.sh + +cd $GSH_HOME/Castle/Portals/spellbook +git revert HEAD --no-edit +git push +gsh check + diff --git a/missions/contrib/git_advanced/06_git_revert/check.sh b/missions/contrib/git_advanced/06_git_revert/check.sh new file mode 100644 index 000000000..4185b54c7 --- /dev/null +++ b/missions/contrib/git_advanced/06_git_revert/check.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env sh + +# This file is required. It is sourced when checking the goal of the mission +# has been achieved. +# It should end with a command returning 0 on success, and something else on +# failure. +# It should "unset" any local variable it has created, and any "global +# variable" that were only used for the mission. (The function _mission_check +# is automatically unset.) +# +# It typically looks like + +_mission_check() { + + if [ ! -e "$GSH_HOME/Castle/Portals/spellbook/Chapter_1/truth_spell" ] + then + echo " The file truth_spell is not in Chapter_1" + return 1 + fi + + LANG=en_GB git status | grep -e "up to date with" +test=$(echo $?) + + if [ $test -eq 1 ] + then + echo " You did not pushed all of your modifications" + return 1 + else + LANG=en_GB git status | grep -e "nothing to commit" + test=$(echo $?) + if [ $test -eq 1 ] + then + echo " You did not commited all of your modifications" + return 1 + else + + LANG=en_GB git branch | grep -e "tach" + + if [ $test -eq 0 ] + then + return 0 + else + echo " You did not checkout the most recent commit" + return 1 + + fi + fi + fi + +} +_mission_check diff --git a/missions/contrib/git_advanced/06_git_revert/clean.sh b/missions/contrib/git_advanced/06_git_revert/clean.sh new file mode 120000 index 000000000..614a72e95 --- /dev/null +++ b/missions/contrib/git_advanced/06_git_revert/clean.sh @@ -0,0 +1 @@ +../../git_basics/00_needed_files/clean.sh \ No newline at end of file diff --git a/missions/contrib/git_advanced/06_git_revert/goal.txt b/missions/contrib/git_advanced/06_git_revert/goal.txt new file mode 100644 index 000000000..361c7a8d0 --- /dev/null +++ b/missions/contrib/git_advanced/06_git_revert/goal.txt @@ -0,0 +1,18 @@ +Mission goal +============ + +You just removed the file spell of truth. + +When they saw your lastest commit, the previous wizzard of your castle was greatly confused. + +They just send you a message with a instant magic pigeon: + +"It took a lot of work to get this spell working properly. Please revert what you just did." + + +Useful commands +=============== + +git revert HEAD : revert the modifications of the commit pointed by HEAD. One could have put a branch name here also. This commands creates a new commit which will cancel the modifications. + +git push diff --git a/missions/contrib/git_advanced/06_git_revert/init.sh b/missions/contrib/git_advanced/06_git_revert/init.sh new file mode 100644 index 000000000..e105df1ac --- /dev/null +++ b/missions/contrib/git_advanced/06_git_revert/init.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced every time the mission is started. +# Since it is sourced every time the mission is restarted, it can generate +# random data to make each run slightly different. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. +# +# Note however that should the mission be initialized in a subshell, those +# environment variables will disappear! That typically happens a mission is +# checked using process redirection, as in +# $ SOMETHING | gsh check +# To mitigate the problem, GameShell will display a message asking the player +# to run +# $ gsh reset +# in that case. +# +# It typically looks like +_mission_init() { + + if [ -f $GSH_TMP/skip_init ] + then + rm $GSH_TMP/skip_init + else + . $GSH_TMP/clone.sh &> /dev/null + git reset --hard origin/truth_spell_removed &> /dev/null + . $GSH_TMP/remove_init_branches.sh &> /dev/null + . $GSH_TMP/add_remote_origin.sh + fi + +} +_mission_init diff --git a/missions/contrib/git_advanced/06_git_revert/static.sh b/missions/contrib/git_advanced/06_git_revert/static.sh new file mode 100644 index 000000000..ec01a82da --- /dev/null +++ b/missions/contrib/git_advanced/06_git_revert/static.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced once when initialising a GameShell +# game, and whenever the corresponding missions is (re)started. +# It typically creates the parts of the mission that will be available during +# the whole game, like the directory structure. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. diff --git a/missions/contrib/git_advanced/git_advanced.idx b/missions/contrib/git_advanced/git_advanced.idx new file mode 100644 index 000000000..94bd2c479 --- /dev/null +++ b/missions/contrib/git_advanced/git_advanced.idx @@ -0,0 +1,8 @@ +01_sshkey +02_git_mv +03_edit_commit_push_Readme +04_git_rm +05a_git_checkout +05b_git_checkout +06_git_revert + diff --git a/missions/contrib/git_basics.idx b/missions/contrib/git_basics.idx new file mode 100644 index 000000000..91c0a2156 --- /dev/null +++ b/missions/contrib/git_basics.idx @@ -0,0 +1,23 @@ +git_basics/00_needed_files +git_basics/01_create_newrepo +git_config/02_configGitID +git_basics/02a_create_newSpell +git_basics/02b_add_newSpell +git_basics/02c_commit_newSpell +git_basics/02d_push_newSpell +git_basics/03_second_spell_add_commit_push +git_advanced/02_git_mv +git_advanced/04_git_rm +git_advanced/05a_git_checkout +git_advanced/05b_git_checkout +git_advanced/06_git_revert +git_basics/04_third_spell_branch +git_basics/05_fifth_spell +git_basics/06_sixth_spell +git_basics/07a_mergeFF_question +git_basics/07b_mergeFF +git_basics/08a_merge_question +git_basics/08b_merge +git_basics/09_merge_conflict +git_basics/10_merge_request + diff --git a/missions/contrib/git_basics/00_needed_files/add_remote_origin.sh b/missions/contrib/git_basics/00_needed_files/add_remote_origin.sh new file mode 100644 index 000000000..3705a09b2 --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/add_remote_origin.sh @@ -0,0 +1,22 @@ + +# if a proper remote has been set in mission 1, origin_url exists and file contains its address. +if [ -f $GSH_TMP/origin_url ] +then + origin_url=$(cat $GSH_TMP/origin_url) + git remote rm origin &> /dev/null + git remote add origin $origin_url &> /dev/null + git push -u origin main --force &> /dev/null + if [ $? -eq 1 ] + then + echo "Error: Could not reset remote repository. Are you sure you have unprotected the main branch ?" + else + echo "Info: environment reset, your remote repository has been updated with the predefined environment for this mission" + fi +else + echo "Warning: could not retrieve the url of your repository, please add it again" + echo "git remote rm origin" + echo "git remote add origin ORIGIN_URL" + echo "Or do nothing, push will work but you will not see anything evolving on the web interface" + # Set upstream branch to get the correct message when asking for status => necessary for checks + git push -u origin main &> /dev/null +fi diff --git a/missions/contrib/git_basics/00_needed_files/amplifier_conflict_fixed b/missions/contrib/git_basics/00_needed_files/amplifier_conflict_fixed new file mode 100644 index 000000000..817fa80eb --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/amplifier_conflict_fixed @@ -0,0 +1,4 @@ +50 66 +50 77 +cheater_spell +beer_spell diff --git a/missions/contrib/git_basics/00_needed_files/beer/amplifier b/missions/contrib/git_basics/00_needed_files/beer/amplifier new file mode 100644 index 000000000..41112c89b --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/beer/amplifier @@ -0,0 +1,3 @@ +50 66 +50 77 +beer_spell diff --git a/missions/contrib/git_basics/00_needed_files/beer/beer_spell b/missions/contrib/git_basics/00_needed_files/beer/beer_spell new file mode 100644 index 000000000..5a98747c8 --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/beer/beer_spell @@ -0,0 +1,4 @@ +20 88 +60 33 +15 44 +5 99 diff --git a/missions/contrib/git_basics/00_needed_files/cheater/amplifier b/missions/contrib/git_basics/00_needed_files/cheater/amplifier new file mode 100644 index 000000000..3d5346c1d --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/cheater/amplifier @@ -0,0 +1,3 @@ +50 66 +50 77 +cheater_spell diff --git a/missions/contrib/git_basics/00_needed_files/cheater/cheater_spell b/missions/contrib/git_basics/00_needed_files/cheater/cheater_spell new file mode 100644 index 000000000..ed6334083 --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/cheater/cheater_spell @@ -0,0 +1,2 @@ +80 222 +20 55 diff --git a/missions/contrib/git_basics/00_needed_files/clean.sh b/missions/contrib/git_basics/00_needed_files/clean.sh new file mode 100644 index 000000000..a812b337c --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/clean.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is used to clean the mission, +# for example on completion, or when restarting it. +# In some rare case, cleaning is different after a successful check. You can +# inspect the variable $GSH_LAST_ACTION, which can take the following values: +# assert, check_false, check_true, exit, goto, hard_reset, reset, skip +# If you need this file, rename it to clean.sh + +# back to HOM in order to avoid getcwd error + +if [ $GSH_LAST_ACTION = check_false ] || [ $GSH_LAST_ACTION = check_true ] || [ $GSH_LAST_ACTION = exit ] +then + touch $GSH_TMP/skip_init +else + cd $GSH_HOME + rm -rf $GSH_HOME/Castle/Portals/spellbook + rm -rf $GSH_TMP/spellbook + echo "Warning: repository reset, you might have issue when pushing. If yes add --force option when pushing. Jafar will be author of some commits, but it is ok, he knows what he is doing !" +fi diff --git a/missions/contrib/git_basics/00_needed_files/clone.sh b/missions/contrib/git_basics/00_needed_files/clone.sh new file mode 100644 index 000000000..8f21605b7 --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/clone.sh @@ -0,0 +1,25 @@ +echo "clone.sh" +cd $GSH_HOME/Castle/Portals +cp -r $GSH_TMP/solution_repo $GSH_TMP/spellbook +git clone $GSH_TMP/spellbook +cd spellbook +if [ -f $GSH_TMP/gitconfig ] +then + git config --local user.name $(cat $GSH_TMP/gitconfig | grep name | cut -d '=' -f2) + git config --local user.email $(cat $GSH_TMP/gitconfig | grep email | cut -d '=' -f2) +else + git config --local user.name Jaffar + git config --local user.email jaffar@aladin.cool +fi +git config --local core.editor nano +git config --local alias.co checkout +git config --local alias.br branch +git config --local alias.ci commit +git config --local alias.st status +git config --local alias.last "log -1 HEAD" +git config --local alias.lo "log --oneline --graph --branches" +#git config --local alias.push "push --force" + + +git reset --hard origin/init +git push origin main --force diff --git a/missions/contrib/git_basics/00_needed_files/flame_spell b/missions/contrib/git_basics/00_needed_files/flame_spell new file mode 100644 index 000000000..7e0974deb --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/flame_spell @@ -0,0 +1,2 @@ +90 22 +10 11 diff --git a/missions/contrib/git_basics/00_needed_files/gen_solution.sh b/missions/contrib/git_basics/00_needed_files/gen_solution.sh new file mode 100644 index 000000000..a0ff94844 --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/gen_solution.sh @@ -0,0 +1,76 @@ +cd Castle/Portals/ +rm -rf spellbook solution_repo +mkdir spellbook solution_repo +cd solution_repo +git init --bare + +cd ../spellbook +git init --initial-branch=main +git config --local user.name "Jafar" +git config --local user.email "" + + +echo "Toy repository to learn git with [GameShell_git](https://github.com/MKessar/GameShell_git)" > README.md +git add README.md +git commit -m "initial repo with README" +git branch init + +cp ../glowing_finger_spell . +git add glowing_finger_spell +git commit -m 'glowing finger spell added' +git branch glowing_finger_spell_added + +cp ../truth_spell . +git add truth_spell +git commit -m "truth spell added" +git branch truth_spell_added + +mkdir Chapter_1 +git mv truth_spell glowing_finger_spell Chapter_1/ +git commit -m "moving spell into Chapter_1" +git branch moving_spell_into_Chapter_1 + +git rm Chapter_1/truth_spell +git commit -m "truth spell removed" +git branch truth_spell_removed + +git revert HEAD --no-edit +git commit --amend --no-edit +git branch revert + +cp ../flame_spell . +git checkout -b flame main +git add flame_spell +git commit -m "flame spell added" +git branch flame_added + +cp ../cheater/* . +git co -b cheater main +git add cheater_spell amplifier +git ci -m "cheater spell added" +git branch cheater_added + +git co -b beer main +cp ../beer/* . +git add beer_spell amplifier +git ci -m "beer spell added" +git branch beer_added + +git co main +git merge flame --no-edit +git branch flame_merged + +git merge cheater --no-edit +git branch cheater_merged + +git merge beer --no-edit +cp ../amplifier_conflict_fixed ./amplifier +git add amplifier +git ci --no-edit +git branch beer_merged + +git remote add origin ../solution_repo +git push origin main init glowing_finger_spell_added truth_spell_added moving_spell_into_Chapter_1 flame_added cheater_added beer_added flame_merged cheater_merged beer_merged truth_spell_removed revert + +cd .. +echo "ref: refs/heads/main" > solution_repo/HEAD diff --git a/missions/contrib/git_basics/00_needed_files/glowing_finger_spell b/missions/contrib/git_basics/00_needed_files/glowing_finger_spell new file mode 100644 index 000000000..a957b56d2 --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/glowing_finger_spell @@ -0,0 +1,6 @@ +95 66 +5 22 + + +NB: +This Spell cannot be used to Phone Home. diff --git a/missions/contrib/git_basics/00_needed_files/remove_init_branches.sh b/missions/contrib/git_basics/00_needed_files/remove_init_branches.sh new file mode 100644 index 000000000..dcda19c2f --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/remove_init_branches.sh @@ -0,0 +1,12 @@ +git push origin -d init\ + glowing_finger_spell_added\ + truth_spell_added\ + moving_spell_into_Chapter_1\ + flame_added\ + cheater_added\ + beer_added\ + flame_merged\ + cheater_merged\ + beer_merged\ + truth_spell_removed\ + revert diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/HEAD b/missions/contrib/git_basics/00_needed_files/solution_repo/HEAD new file mode 100644 index 000000000..b870d8262 --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/solution_repo/HEAD @@ -0,0 +1 @@ +ref: refs/heads/main diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/config b/missions/contrib/git_basics/00_needed_files/solution_repo/config new file mode 100644 index 000000000..07d359d07 --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/solution_repo/config @@ -0,0 +1,4 @@ +[core] + repositoryformatversion = 0 + filemode = true + bare = true diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/description b/missions/contrib/git_basics/00_needed_files/solution_repo/description new file mode 100644 index 000000000..498b267a8 --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/solution_repo/description @@ -0,0 +1 @@ +Unnamed repository; edit this file 'description' to name the repository. diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/hooks/applypatch-msg.sample b/missions/contrib/git_basics/00_needed_files/solution_repo/hooks/applypatch-msg.sample new file mode 100755 index 000000000..a5d7b84a6 --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/solution_repo/hooks/applypatch-msg.sample @@ -0,0 +1,15 @@ +#!/bin/sh +# +# An example hook script to check the commit log message taken by +# applypatch from an e-mail message. +# +# The hook should exit with non-zero status after issuing an +# appropriate message if it wants to stop the commit. The hook is +# allowed to edit the commit message file. +# +# To enable this hook, rename this file to "applypatch-msg". + +. git-sh-setup +commitmsg="$(git rev-parse --git-path hooks/commit-msg)" +test -x "$commitmsg" && exec "$commitmsg" ${1+"$@"} +: diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/hooks/commit-msg.sample b/missions/contrib/git_basics/00_needed_files/solution_repo/hooks/commit-msg.sample new file mode 100755 index 000000000..b58d1184a --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/solution_repo/hooks/commit-msg.sample @@ -0,0 +1,24 @@ +#!/bin/sh +# +# An example hook script to check the commit log message. +# Called by "git commit" with one argument, the name of the file +# that has the commit message. The hook should exit with non-zero +# status after issuing an appropriate message if it wants to stop the +# commit. The hook is allowed to edit the commit message file. +# +# To enable this hook, rename this file to "commit-msg". + +# Uncomment the below to add a Signed-off-by line to the message. +# Doing this in a hook is a bad idea in general, but the prepare-commit-msg +# hook is more suited to it. +# +# SOB=$(git var GIT_AUTHOR_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') +# grep -qs "^$SOB" "$1" || echo "$SOB" >> "$1" + +# This example catches duplicate Signed-off-by lines. + +test "" = "$(grep '^Signed-off-by: ' "$1" | + sort | uniq -c | sed -e '/^[ ]*1[ ]/d')" || { + echo >&2 Duplicate Signed-off-by lines. + exit 1 +} diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/hooks/fsmonitor-watchman.sample b/missions/contrib/git_basics/00_needed_files/solution_repo/hooks/fsmonitor-watchman.sample new file mode 100755 index 000000000..14ed0aa42 --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/solution_repo/hooks/fsmonitor-watchman.sample @@ -0,0 +1,173 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use IPC::Open2; + +# An example hook script to integrate Watchman +# (https://facebook.github.io/watchman/) with git to speed up detecting +# new and modified files. +# +# The hook is passed a version (currently 2) and last update token +# formatted as a string and outputs to stdout a new update token and +# all files that have been modified since the update token. Paths must +# be relative to the root of the working tree and separated by a single NUL. +# +# To enable this hook, rename this file to "query-watchman" and set +# 'git config core.fsmonitor .git/hooks/query-watchman' +# +my ($version, $last_update_token) = @ARGV; + +# Uncomment for debugging +# print STDERR "$0 $version $last_update_token\n"; + +# Check the hook interface version +if ($version ne 2) { + die "Unsupported query-fsmonitor hook version '$version'.\n" . + "Falling back to scanning...\n"; +} + +my $git_work_tree = get_working_dir(); + +my $retry = 1; + +my $json_pkg; +eval { + require JSON::XS; + $json_pkg = "JSON::XS"; + 1; +} or do { + require JSON::PP; + $json_pkg = "JSON::PP"; +}; + +launch_watchman(); + +sub launch_watchman { + my $o = watchman_query(); + if (is_work_tree_watched($o)) { + output_result($o->{clock}, @{$o->{files}}); + } +} + +sub output_result { + my ($clockid, @files) = @_; + + # Uncomment for debugging watchman output + # open (my $fh, ">", ".git/watchman-output.out"); + # binmode $fh, ":utf8"; + # print $fh "$clockid\n@files\n"; + # close $fh; + + binmode STDOUT, ":utf8"; + print $clockid; + print "\0"; + local $, = "\0"; + print @files; +} + +sub watchman_clock { + my $response = qx/watchman clock "$git_work_tree"/; + die "Failed to get clock id on '$git_work_tree'.\n" . + "Falling back to scanning...\n" if $? != 0; + + return $json_pkg->new->utf8->decode($response); +} + +sub watchman_query { + my $pid = open2(\*CHLD_OUT, \*CHLD_IN, 'watchman -j --no-pretty') + or die "open2() failed: $!\n" . + "Falling back to scanning...\n"; + + # In the query expression below we're asking for names of files that + # changed since $last_update_token but not from the .git folder. + # + # To accomplish this, we're using the "since" generator to use the + # recency index to select candidate nodes and "fields" to limit the + # output to file names only. Then we're using the "expression" term to + # further constrain the results. + if (substr($last_update_token, 0, 1) eq "c") { + $last_update_token = "\"$last_update_token\""; + } + my $query = <<" END"; + ["query", "$git_work_tree", { + "since": $last_update_token, + "fields": ["name"], + "expression": ["not", ["dirname", ".git"]] + }] + END + + # Uncomment for debugging the watchman query + # open (my $fh, ">", ".git/watchman-query.json"); + # print $fh $query; + # close $fh; + + print CHLD_IN $query; + close CHLD_IN; + my $response = do {local $/; }; + + # Uncomment for debugging the watch response + # open ($fh, ">", ".git/watchman-response.json"); + # print $fh $response; + # close $fh; + + die "Watchman: command returned no output.\n" . + "Falling back to scanning...\n" if $response eq ""; + die "Watchman: command returned invalid output: $response\n" . + "Falling back to scanning...\n" unless $response =~ /^\{/; + + return $json_pkg->new->utf8->decode($response); +} + +sub is_work_tree_watched { + my ($output) = @_; + my $error = $output->{error}; + if ($retry > 0 and $error and $error =~ m/unable to resolve root .* directory (.*) is not watched/) { + $retry--; + my $response = qx/watchman watch "$git_work_tree"/; + die "Failed to make watchman watch '$git_work_tree'.\n" . + "Falling back to scanning...\n" if $? != 0; + $output = $json_pkg->new->utf8->decode($response); + $error = $output->{error}; + die "Watchman: $error.\n" . + "Falling back to scanning...\n" if $error; + + # Uncomment for debugging watchman output + # open (my $fh, ">", ".git/watchman-output.out"); + # close $fh; + + # Watchman will always return all files on the first query so + # return the fast "everything is dirty" flag to git and do the + # Watchman query just to get it over with now so we won't pay + # the cost in git to look up each individual file. + my $o = watchman_clock(); + $error = $output->{error}; + + die "Watchman: $error.\n" . + "Falling back to scanning...\n" if $error; + + output_result($o->{clock}, ("/")); + $last_update_token = $o->{clock}; + + eval { launch_watchman() }; + return 0; + } + + die "Watchman: $error.\n" . + "Falling back to scanning...\n" if $error; + + return 1; +} + +sub get_working_dir { + my $working_dir; + if ($^O =~ 'msys' || $^O =~ 'cygwin') { + $working_dir = Win32::GetCwd(); + $working_dir =~ tr/\\/\//; + } else { + require Cwd; + $working_dir = Cwd::cwd(); + } + + return $working_dir; +} diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/hooks/post-update.sample b/missions/contrib/git_basics/00_needed_files/solution_repo/hooks/post-update.sample new file mode 100755 index 000000000..ec17ec193 --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/solution_repo/hooks/post-update.sample @@ -0,0 +1,8 @@ +#!/bin/sh +# +# An example hook script to prepare a packed repository for use over +# dumb transports. +# +# To enable this hook, rename this file to "post-update". + +exec git update-server-info diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/hooks/pre-applypatch.sample b/missions/contrib/git_basics/00_needed_files/solution_repo/hooks/pre-applypatch.sample new file mode 100755 index 000000000..4142082bc --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/solution_repo/hooks/pre-applypatch.sample @@ -0,0 +1,14 @@ +#!/bin/sh +# +# An example hook script to verify what is about to be committed +# by applypatch from an e-mail message. +# +# The hook should exit with non-zero status after issuing an +# appropriate message if it wants to stop the commit. +# +# To enable this hook, rename this file to "pre-applypatch". + +. git-sh-setup +precommit="$(git rev-parse --git-path hooks/pre-commit)" +test -x "$precommit" && exec "$precommit" ${1+"$@"} +: diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/hooks/pre-commit.sample b/missions/contrib/git_basics/00_needed_files/solution_repo/hooks/pre-commit.sample new file mode 100755 index 000000000..e144712c8 --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/solution_repo/hooks/pre-commit.sample @@ -0,0 +1,49 @@ +#!/bin/sh +# +# An example hook script to verify what is about to be committed. +# Called by "git commit" with no arguments. The hook should +# exit with non-zero status after issuing an appropriate message if +# it wants to stop the commit. +# +# To enable this hook, rename this file to "pre-commit". + +if git rev-parse --verify HEAD >/dev/null 2>&1 +then + against=HEAD +else + # Initial commit: diff against an empty tree object + against=$(git hash-object -t tree /dev/null) +fi + +# If you want to allow non-ASCII filenames set this variable to true. +allownonascii=$(git config --type=bool hooks.allownonascii) + +# Redirect output to stderr. +exec 1>&2 + +# Cross platform projects tend to avoid non-ASCII filenames; prevent +# them from being added to the repository. We exploit the fact that the +# printable range starts at the space character and ends with tilde. +if [ "$allownonascii" != "true" ] && + # Note that the use of brackets around a tr range is ok here, (it's + # even required, for portability to Solaris 10's /usr/bin/tr), since + # the square bracket bytes happen to fall in the designated range. + test $(git diff --cached --name-only --diff-filter=A -z $against | + LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 +then + cat <<\EOF +Error: Attempt to add a non-ASCII file name. + +This can cause problems if you want to work with people on other platforms. + +To be portable it is advisable to rename the file. + +If you know what you are doing you can disable this check using: + + git config hooks.allownonascii true +EOF + exit 1 +fi + +# If there are whitespace errors, print the offending file names and fail. +exec git diff-index --check --cached $against -- diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/hooks/pre-merge-commit.sample b/missions/contrib/git_basics/00_needed_files/solution_repo/hooks/pre-merge-commit.sample new file mode 100755 index 000000000..399eab192 --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/solution_repo/hooks/pre-merge-commit.sample @@ -0,0 +1,13 @@ +#!/bin/sh +# +# An example hook script to verify what is about to be committed. +# Called by "git merge" with no arguments. The hook should +# exit with non-zero status after issuing an appropriate message to +# stderr if it wants to stop the merge commit. +# +# To enable this hook, rename this file to "pre-merge-commit". + +. git-sh-setup +test -x "$GIT_DIR/hooks/pre-commit" && + exec "$GIT_DIR/hooks/pre-commit" +: diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/hooks/pre-push.sample b/missions/contrib/git_basics/00_needed_files/solution_repo/hooks/pre-push.sample new file mode 100755 index 000000000..4ce688d32 --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/solution_repo/hooks/pre-push.sample @@ -0,0 +1,53 @@ +#!/bin/sh + +# An example hook script to verify what is about to be pushed. Called by "git +# push" after it has checked the remote status, but before anything has been +# pushed. If this script exits with a non-zero status nothing will be pushed. +# +# This hook is called with the following parameters: +# +# $1 -- Name of the remote to which the push is being done +# $2 -- URL to which the push is being done +# +# If pushing without using a named remote those arguments will be equal. +# +# Information about the commits which are being pushed is supplied as lines to +# the standard input in the form: +# +# +# +# This sample shows how to prevent push of commits where the log message starts +# with "WIP" (work in progress). + +remote="$1" +url="$2" + +zero=$(git hash-object --stdin &2 "Found WIP commit in $local_ref, not pushing" + exit 1 + fi + fi +done + +exit 0 diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/hooks/pre-rebase.sample b/missions/contrib/git_basics/00_needed_files/solution_repo/hooks/pre-rebase.sample new file mode 100755 index 000000000..6cbef5c37 --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/solution_repo/hooks/pre-rebase.sample @@ -0,0 +1,169 @@ +#!/bin/sh +# +# Copyright (c) 2006, 2008 Junio C Hamano +# +# The "pre-rebase" hook is run just before "git rebase" starts doing +# its job, and can prevent the command from running by exiting with +# non-zero status. +# +# The hook is called with the following parameters: +# +# $1 -- the upstream the series was forked from. +# $2 -- the branch being rebased (or empty when rebasing the current branch). +# +# This sample shows how to prevent topic branches that are already +# merged to 'next' branch from getting rebased, because allowing it +# would result in rebasing already published history. + +publish=next +basebranch="$1" +if test "$#" = 2 +then + topic="refs/heads/$2" +else + topic=`git symbolic-ref HEAD` || + exit 0 ;# we do not interrupt rebasing detached HEAD +fi + +case "$topic" in +refs/heads/??/*) + ;; +*) + exit 0 ;# we do not interrupt others. + ;; +esac + +# Now we are dealing with a topic branch being rebased +# on top of master. Is it OK to rebase it? + +# Does the topic really exist? +git show-ref -q "$topic" || { + echo >&2 "No such branch $topic" + exit 1 +} + +# Is topic fully merged to master? +not_in_master=`git rev-list --pretty=oneline ^master "$topic"` +if test -z "$not_in_master" +then + echo >&2 "$topic is fully merged to master; better remove it." + exit 1 ;# we could allow it, but there is no point. +fi + +# Is topic ever merged to next? If so you should not be rebasing it. +only_next_1=`git rev-list ^master "^$topic" ${publish} | sort` +only_next_2=`git rev-list ^master ${publish} | sort` +if test "$only_next_1" = "$only_next_2" +then + not_in_topic=`git rev-list "^$topic" master` + if test -z "$not_in_topic" + then + echo >&2 "$topic is already up to date with master" + exit 1 ;# we could allow it, but there is no point. + else + exit 0 + fi +else + not_in_next=`git rev-list --pretty=oneline ^${publish} "$topic"` + /usr/bin/perl -e ' + my $topic = $ARGV[0]; + my $msg = "* $topic has commits already merged to public branch:\n"; + my (%not_in_next) = map { + /^([0-9a-f]+) /; + ($1 => 1); + } split(/\n/, $ARGV[1]); + for my $elem (map { + /^([0-9a-f]+) (.*)$/; + [$1 => $2]; + } split(/\n/, $ARGV[2])) { + if (!exists $not_in_next{$elem->[0]}) { + if ($msg) { + print STDERR $msg; + undef $msg; + } + print STDERR " $elem->[1]\n"; + } + } + ' "$topic" "$not_in_next" "$not_in_master" + exit 1 +fi + +<<\DOC_END + +This sample hook safeguards topic branches that have been +published from being rewound. + +The workflow assumed here is: + + * Once a topic branch forks from "master", "master" is never + merged into it again (either directly or indirectly). + + * Once a topic branch is fully cooked and merged into "master", + it is deleted. If you need to build on top of it to correct + earlier mistakes, a new topic branch is created by forking at + the tip of the "master". This is not strictly necessary, but + it makes it easier to keep your history simple. + + * Whenever you need to test or publish your changes to topic + branches, merge them into "next" branch. + +The script, being an example, hardcodes the publish branch name +to be "next", but it is trivial to make it configurable via +$GIT_DIR/config mechanism. + +With this workflow, you would want to know: + +(1) ... if a topic branch has ever been merged to "next". Young + topic branches can have stupid mistakes you would rather + clean up before publishing, and things that have not been + merged into other branches can be easily rebased without + affecting other people. But once it is published, you would + not want to rewind it. + +(2) ... if a topic branch has been fully merged to "master". + Then you can delete it. More importantly, you should not + build on top of it -- other people may already want to + change things related to the topic as patches against your + "master", so if you need further changes, it is better to + fork the topic (perhaps with the same name) afresh from the + tip of "master". + +Let's look at this example: + + o---o---o---o---o---o---o---o---o---o "next" + / / / / + / a---a---b A / / + / / / / + / / c---c---c---c B / + / / / \ / + / / / b---b C \ / + / / / / \ / + ---o---o---o---o---o---o---o---o---o---o---o "master" + + +A, B and C are topic branches. + + * A has one fix since it was merged up to "next". + + * B has finished. It has been fully merged up to "master" and "next", + and is ready to be deleted. + + * C has not merged to "next" at all. + +We would want to allow C to be rebased, refuse A, and encourage +B to be deleted. + +To compute (1): + + git rev-list ^master ^topic next + git rev-list ^master next + + if these match, topic has not merged in next at all. + +To compute (2): + + git rev-list master..topic + + if this is empty, it is fully merged to "master". + +DOC_END diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/hooks/pre-receive.sample b/missions/contrib/git_basics/00_needed_files/solution_repo/hooks/pre-receive.sample new file mode 100755 index 000000000..a1fd29ec1 --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/solution_repo/hooks/pre-receive.sample @@ -0,0 +1,24 @@ +#!/bin/sh +# +# An example hook script to make use of push options. +# The example simply echoes all push options that start with 'echoback=' +# and rejects all pushes when the "reject" push option is used. +# +# To enable this hook, rename this file to "pre-receive". + +if test -n "$GIT_PUSH_OPTION_COUNT" +then + i=0 + while test "$i" -lt "$GIT_PUSH_OPTION_COUNT" + do + eval "value=\$GIT_PUSH_OPTION_$i" + case "$value" in + echoback=*) + echo "echo from the pre-receive-hook: ${value#*=}" >&2 + ;; + reject) + exit 1 + esac + i=$((i + 1)) + done +fi diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/hooks/prepare-commit-msg.sample b/missions/contrib/git_basics/00_needed_files/solution_repo/hooks/prepare-commit-msg.sample new file mode 100755 index 000000000..10fa14c5a --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/solution_repo/hooks/prepare-commit-msg.sample @@ -0,0 +1,42 @@ +#!/bin/sh +# +# An example hook script to prepare the commit log message. +# Called by "git commit" with the name of the file that has the +# commit message, followed by the description of the commit +# message's source. The hook's purpose is to edit the commit +# message file. If the hook fails with a non-zero status, +# the commit is aborted. +# +# To enable this hook, rename this file to "prepare-commit-msg". + +# This hook includes three examples. The first one removes the +# "# Please enter the commit message..." help message. +# +# The second includes the output of "git diff --name-status -r" +# into the message, just before the "git status" output. It is +# commented because it doesn't cope with --amend or with squashed +# commits. +# +# The third example adds a Signed-off-by line to the message, that can +# still be edited. This is rarely a good idea. + +COMMIT_MSG_FILE=$1 +COMMIT_SOURCE=$2 +SHA1=$3 + +/usr/bin/perl -i.bak -ne 'print unless(m/^. Please enter the commit message/..m/^#$/)' "$COMMIT_MSG_FILE" + +# case "$COMMIT_SOURCE,$SHA1" in +# ,|template,) +# /usr/bin/perl -i.bak -pe ' +# print "\n" . `git diff --cached --name-status -r` +# if /^#/ && $first++ == 0' "$COMMIT_MSG_FILE" ;; +# *) ;; +# esac + +# SOB=$(git var GIT_COMMITTER_IDENT | sed -n 's/^\(.*>\).*$/Signed-off-by: \1/p') +# git interpret-trailers --in-place --trailer "$SOB" "$COMMIT_MSG_FILE" +# if test -z "$COMMIT_SOURCE" +# then +# /usr/bin/perl -i.bak -pe 'print "\n" if !$first_line++' "$COMMIT_MSG_FILE" +# fi diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/hooks/push-to-checkout.sample b/missions/contrib/git_basics/00_needed_files/solution_repo/hooks/push-to-checkout.sample new file mode 100755 index 000000000..af5a0c001 --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/solution_repo/hooks/push-to-checkout.sample @@ -0,0 +1,78 @@ +#!/bin/sh + +# An example hook script to update a checked-out tree on a git push. +# +# This hook is invoked by git-receive-pack(1) when it reacts to git +# push and updates reference(s) in its repository, and when the push +# tries to update the branch that is currently checked out and the +# receive.denyCurrentBranch configuration variable is set to +# updateInstead. +# +# By default, such a push is refused if the working tree and the index +# of the remote repository has any difference from the currently +# checked out commit; when both the working tree and the index match +# the current commit, they are updated to match the newly pushed tip +# of the branch. This hook is to be used to override the default +# behaviour; however the code below reimplements the default behaviour +# as a starting point for convenient modification. +# +# The hook receives the commit with which the tip of the current +# branch is going to be updated: +commit=$1 + +# It can exit with a non-zero status to refuse the push (when it does +# so, it must not modify the index or the working tree). +die () { + echo >&2 "$*" + exit 1 +} + +# Or it can make any necessary changes to the working tree and to the +# index to bring them to the desired state when the tip of the current +# branch is updated to the new commit, and exit with a zero status. +# +# For example, the hook can simply run git read-tree -u -m HEAD "$1" +# in order to emulate git fetch that is run in the reverse direction +# with git push, as the two-tree form of git read-tree -u -m is +# essentially the same as git switch or git checkout that switches +# branches while keeping the local changes in the working tree that do +# not interfere with the difference between the branches. + +# The below is a more-or-less exact translation to shell of the C code +# for the default behaviour for git's push-to-checkout hook defined in +# the push_to_deploy() function in builtin/receive-pack.c. +# +# Note that the hook will be executed from the repository directory, +# not from the working tree, so if you want to perform operations on +# the working tree, you will have to adapt your code accordingly, e.g. +# by adding "cd .." or using relative paths. + +if ! git update-index -q --ignore-submodules --refresh +then + die "Up-to-date check failed" +fi + +if ! git diff-files --quiet --ignore-submodules -- +then + die "Working directory has unstaged changes" +fi + +# This is a rough translation of: +# +# head_has_history() ? "HEAD" : EMPTY_TREE_SHA1_HEX +if git cat-file -e HEAD 2>/dev/null +then + head=HEAD +else + head=$(git hash-object -t tree --stdin &2 + echo " (if you want, you could supply GIT_DIR then run" >&2 + echo " $0 )" >&2 + exit 1 +fi + +if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then + echo "usage: $0 " >&2 + exit 1 +fi + +# --- Config +allowunannotated=$(git config --type=bool hooks.allowunannotated) +allowdeletebranch=$(git config --type=bool hooks.allowdeletebranch) +denycreatebranch=$(git config --type=bool hooks.denycreatebranch) +allowdeletetag=$(git config --type=bool hooks.allowdeletetag) +allowmodifytag=$(git config --type=bool hooks.allowmodifytag) + +# check for no description +projectdesc=$(sed -e '1q' "$GIT_DIR/description") +case "$projectdesc" in +"Unnamed repository"* | "") + echo "*** Project description file hasn't been set" >&2 + exit 1 + ;; +esac + +# --- Check types +# if $newrev is 0000...0000, it's a commit to delete a ref. +zero=$(git hash-object --stdin &2 + echo "*** Use 'git tag [ -a | -s ]' for tags you want to propagate." >&2 + exit 1 + fi + ;; + refs/tags/*,delete) + # delete tag + if [ "$allowdeletetag" != "true" ]; then + echo "*** Deleting a tag is not allowed in this repository" >&2 + exit 1 + fi + ;; + refs/tags/*,tag) + # annotated tag + if [ "$allowmodifytag" != "true" ] && git rev-parse $refname > /dev/null 2>&1 + then + echo "*** Tag '$refname' already exists." >&2 + echo "*** Modifying a tag is not allowed in this repository." >&2 + exit 1 + fi + ;; + refs/heads/*,commit) + # branch + if [ "$oldrev" = "$zero" -a "$denycreatebranch" = "true" ]; then + echo "*** Creating a branch is not allowed in this repository" >&2 + exit 1 + fi + ;; + refs/heads/*,delete) + # delete branch + if [ "$allowdeletebranch" != "true" ]; then + echo "*** Deleting a branch is not allowed in this repository" >&2 + exit 1 + fi + ;; + refs/remotes/*,commit) + # tracking branch + ;; + refs/remotes/*,delete) + # delete tracking branch + if [ "$allowdeletebranch" != "true" ]; then + echo "*** Deleting a tracking branch is not allowed in this repository" >&2 + exit 1 + fi + ;; + *) + # Anything else (is there anything else?) + echo "*** Update hook: unknown type of update to ref $refname of type $newrev_type" >&2 + exit 1 + ;; +esac + +# --- Finished +exit 0 diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/info/exclude b/missions/contrib/git_basics/00_needed_files/solution_repo/info/exclude new file mode 100644 index 000000000..a5196d1be --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/solution_repo/info/exclude @@ -0,0 +1,6 @@ +# git ls-files --others --exclude-from=.git/info/exclude +# Lines that start with '#' are comments. +# For a project mostly in C, the following would be a good set of +# exclude patterns (uncomment them if you want to use them): +# *.[oa] +# *~ diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/objects/01/1fd9d4117cd7f519f9112ce518230e35828dd6 b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/01/1fd9d4117cd7f519f9112ce518230e35828dd6 new file mode 100644 index 000000000..e1d3c813a --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/01/1fd9d4117cd7f519f9112ce518230e35828dd6 @@ -0,0 +1 @@ +x+)JMU0e040031QrutuMaPs@ )F7%Մw@gǧԢԜ[suy_",T# \ No newline at end of file diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/objects/0a/0294c542b858ffee1a119a8ffaccf141f82134 b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/0a/0294c542b858ffee1a119a8ffaccf141f82134 new file mode 100644 index 000000000..fced2841e --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/0a/0294c542b858ffee1a119a8ffaccf141f82134 @@ -0,0 +1,2 @@ +xA +0E] 2ID\{dJ+)5Ќ`sU٢˞9%M;#2q5%uU. "%S#gYK0!UspSp}w\b/TwHFk}_&#w v@خ,Pe-w;NyC+%W \ No newline at end of file diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/objects/17/987cee1441c667c2583e1561fb2254d79b6c40 b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/17/987cee1441c667c2583e1561fb2254d79b6c40 new file mode 100644 index 000000000..c05bfe02e --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/17/987cee1441c667c2583e1561fb2254d79b6c40 @@ -0,0 +1 @@ +x+)JMU042a040031QrutuMaPs@ )F7%Մw@gǧԢԜ[suy_",KJK2NkY[8k<2 \ No newline at end of file diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/objects/20/8bcdc9149a6331c12aca6ef4a3c791503e30f0 b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/20/8bcdc9149a6331c12aca6ef4a3c791503e30f0 new file mode 100644 index 000000000..6c3a3a0b6 Binary files /dev/null and b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/20/8bcdc9149a6331c12aca6ef4a3c791503e30f0 differ diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/objects/21/f32eb9bb9a51180ba8643258d91812b67c5788 b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/21/f32eb9bb9a51180ba8643258d91812b67c5788 new file mode 100644 index 000000000..79d27d9f6 Binary files /dev/null and b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/21/f32eb9bb9a51180ba8643258d91812b67c5788 differ diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/objects/22/751b444b755a1e9e992bde47003d479fc93d98 b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/22/751b444b755a1e9e992bde47003d479fc93d98 new file mode 100644 index 000000000..33c8e8aea Binary files /dev/null and b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/22/751b444b755a1e9e992bde47003d479fc93d98 differ diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/objects/33/46e2fc9bc645c45ee56becf0749669273b667f b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/33/46e2fc9bc645c45ee56becf0749669273b667f new file mode 100644 index 000000000..c92d51c9a --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/33/46e2fc9bc645c45ee56becf0749669273b667f @@ -0,0 +1 @@ +xj0D{W=$dAa-c2?e1,SGUAlJ\b)E.b1Q06PhDaY(SK#ȳu/d>e2\|9% Z8CM_%״>gyimnlݙ_fE \ No newline at end of file diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/objects/34/523755ac89a74c8f89edc2a6a5590a7edd6634 b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/34/523755ac89a74c8f89edc2a6a5590a7edd6634 new file mode 100644 index 000000000..faa3bfb2a Binary files /dev/null and b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/34/523755ac89a74c8f89edc2a6a5590a7edd6634 differ diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/objects/37/dd961f914dfabb29b01d16f0ef850e084b1b7d b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/37/dd961f914dfabb29b01d16f0ef850e084b1b7d new file mode 100644 index 000000000..c7a2ca43b Binary files /dev/null and b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/37/dd961f914dfabb29b01d16f0ef850e084b1b7d differ diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/objects/3d/5346c1d491997e506a491d48745de035e4acdf b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/3d/5346c1d491997e506a491d48745de035e4acdf new file mode 100644 index 000000000..7f114b965 Binary files /dev/null and b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/3d/5346c1d491997e506a491d48745de035e4acdf differ diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/objects/41/112c89bba450bee595b159858180fb2ca4beb6 b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/41/112c89bba450bee595b159858180fb2ca4beb6 new file mode 100644 index 000000000..36d9cc120 Binary files /dev/null and b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/41/112c89bba450bee595b159858180fb2ca4beb6 differ diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/objects/42/1a6c94f94f0c85631579730c8354d0e828cba3 b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/42/1a6c94f94f0c85631579730c8354d0e828cba3 new file mode 100644 index 000000000..4e61ea0b4 Binary files /dev/null and b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/42/1a6c94f94f0c85631579730c8354d0e828cba3 differ diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/objects/43/a0bf792768823636d12afe10cad37c0df1b1eb b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/43/a0bf792768823636d12afe10cad37c0df1b1eb new file mode 100644 index 000000000..78e8d6afb --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/43/a0bf792768823636d12afe10cad37c0df1b1eb @@ -0,0 +1,2 @@ +xK +1]$D\{NdWPP2<.Σu8eӜ1kRJΫ<hI1&$|B,!O6SF3u8?R B4 \ No newline at end of file diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/objects/49/c33fcb2c166e2a884cefeca2ec9d47dbee9c3a b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/49/c33fcb2c166e2a884cefeca2ec9d47dbee9c3a new file mode 100644 index 000000000..5e4f69068 Binary files /dev/null and b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/49/c33fcb2c166e2a884cefeca2ec9d47dbee9c3a differ diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/objects/4e/121100c02b6e4e720f6821feaec4dd04d74fb0 b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/4e/121100c02b6e4e720f6821feaec4dd04d74fb0 new file mode 100644 index 000000000..cbcd12863 --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/4e/121100c02b6e4e720f6821feaec4dd04d74fb0 @@ -0,0 +1,2 @@ +xM +0F]$͏q@Dn7`LiJHx}7p{_(tnZe1;kcdD#'PG<zT@ӊ3eiمRiM"꽒"%(Cgwj#<ދ#s7J \ No newline at end of file diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/objects/5a/98747c811bc0f0696e73243781de649e9b501d b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/5a/98747c811bc0f0696e73243781de649e9b501d new file mode 100644 index 000000000..18304f818 Binary files /dev/null and b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/5a/98747c811bc0f0696e73243781de649e9b501d differ diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/objects/6e/94fc5457fbf41dd0db8ef82e8b8ff31ae5dff8 b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/6e/94fc5457fbf41dd0db8ef82e8b8ff31ae5dff8 new file mode 100644 index 000000000..da090e902 Binary files /dev/null and b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/6e/94fc5457fbf41dd0db8ef82e8b8ff31ae5dff8 differ diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/objects/74/1834bf3f822c855abed838a16c72b392974bfb b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/74/1834bf3f822c855abed838a16c72b392974bfb new file mode 100644 index 000000000..a491c5641 Binary files /dev/null and b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/74/1834bf3f822c855abed838a16c72b392974bfb differ diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/objects/77/435ccebc7343fde2d66b85aef2a61385a68325 b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/77/435ccebc7343fde2d66b85aef2a61385a68325 new file mode 100644 index 000000000..599477e1b --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/77/435ccebc7343fde2d66b85aef2a61385a68325 @@ -0,0 +1 @@ +xJD1Dݚb$K⢔rA9AM6':f4׀QWWjT).rȿkhexmP)\eB \ No newline at end of file diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/objects/d5/87e363c2fbccc132bb95a39e3426f63dbe58b1 b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/d5/87e363c2fbccc132bb95a39e3426f63dbe58b1 new file mode 100644 index 000000000..16346ccd8 Binary files /dev/null and b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/d5/87e363c2fbccc132bb95a39e3426f63dbe58b1 differ diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/objects/da/89b55a380fbe3ce15ed172c83a56434c661b0b b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/da/89b55a380fbe3ce15ed172c83a56434c661b0b new file mode 100644 index 000000000..e14a3f618 Binary files /dev/null and b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/da/89b55a380fbe3ce15ed172c83a56434c661b0b differ diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/objects/e4/e7014d33a5125a4c4b734e7d93f5740144e58b b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/e4/e7014d33a5125a4c4b734e7d93f5740144e58b new file mode 100644 index 000000000..8fc6e9e30 Binary files /dev/null and b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/e4/e7014d33a5125a4c4b734e7d93f5740144e58b differ diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/objects/ed/6334083de2bab04e16ee15605f25ec75d61175 b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/ed/6334083de2bab04e16ee15605f25ec75d61175 new file mode 100644 index 000000000..0cb72e8a6 Binary files /dev/null and b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/ed/6334083de2bab04e16ee15605f25ec75d61175 differ diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/objects/fc/e7d291dbf8869c03d6a78da00b4fc0d1ef68ba b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/fc/e7d291dbf8869c03d6a78da00b4fc0d1ef68ba new file mode 100644 index 000000000..c40498350 Binary files /dev/null and b/missions/contrib/git_basics/00_needed_files/solution_repo/objects/fc/e7d291dbf8869c03d6a78da00b4fc0d1ef68ba differ diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/beer_added b/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/beer_added new file mode 100644 index 000000000..125fb61f9 --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/beer_added @@ -0,0 +1 @@ +43a0bf792768823636d12afe10cad37c0df1b1eb diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/beer_merged b/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/beer_merged new file mode 100644 index 000000000..7a1e0fda9 --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/beer_merged @@ -0,0 +1 @@ +77435ccebc7343fde2d66b85aef2a61385a68325 diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/cheater_added b/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/cheater_added new file mode 100644 index 000000000..625812d6d --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/cheater_added @@ -0,0 +1 @@ +0a0294c542b858ffee1a119a8ffaccf141f82134 diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/cheater_merged b/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/cheater_merged new file mode 100644 index 000000000..4108a9a7a --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/cheater_merged @@ -0,0 +1 @@ +49c33fcb2c166e2a884cefeca2ec9d47dbee9c3a diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/flame_added b/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/flame_added new file mode 100644 index 000000000..e1e753c19 --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/flame_added @@ -0,0 +1 @@ +b0a96cc493f3259ad189534a6cf99d88d1f7c447 diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/flame_merged b/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/flame_merged new file mode 100644 index 000000000..e1e753c19 --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/flame_merged @@ -0,0 +1 @@ +b0a96cc493f3259ad189534a6cf99d88d1f7c447 diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/glowing_finger_spell_added b/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/glowing_finger_spell_added new file mode 100644 index 000000000..3da7af048 --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/glowing_finger_spell_added @@ -0,0 +1 @@ +fce7d291dbf8869c03d6a78da00b4fc0d1ef68ba diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/init b/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/init new file mode 100644 index 000000000..26eac96c5 --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/init @@ -0,0 +1 @@ +4e121100c02b6e4e720f6821feaec4dd04d74fb0 diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/main b/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/main new file mode 100644 index 000000000..7a1e0fda9 --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/main @@ -0,0 +1 @@ +77435ccebc7343fde2d66b85aef2a61385a68325 diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/moving_spell_into_Chapter_1 b/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/moving_spell_into_Chapter_1 new file mode 100644 index 000000000..7622dfd7b --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/moving_spell_into_Chapter_1 @@ -0,0 +1 @@ +3346e2fc9bc645c45ee56becf0749669273b667f diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/revert b/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/revert new file mode 100644 index 000000000..18b5f7cd3 --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/revert @@ -0,0 +1 @@ +0c7c0aed1116816485432a5cbec29c34a6818363 diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/truth_spell_added b/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/truth_spell_added new file mode 100644 index 000000000..d54163773 --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/truth_spell_added @@ -0,0 +1 @@ +e4e7014d33a5125a4c4b734e7d93f5740144e58b diff --git a/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/truth_spell_removed b/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/truth_spell_removed new file mode 100644 index 000000000..7a16d4a51 --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/solution_repo/refs/heads/truth_spell_removed @@ -0,0 +1 @@ +421a6c94f94f0c85631579730c8354d0e828cba3 diff --git a/missions/contrib/git_basics/00_needed_files/static.sh b/missions/contrib/git_basics/00_needed_files/static.sh new file mode 100644 index 000000000..780762b21 --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/static.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced once when initialising a GameShell +# game, and whenever the corresponding missions is (re)started. +# It typically creates the parts of the mission that will be available during +# the whole game, like the directory structure. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. + +if ! git --version > /dev/null 2 > /dev/null +then echo "git not found" + return 1 +fi + +mkdir -p $GSH_HOME/Castle/Portals/ +mkdir -p $GSH_HOME/Castle/Main_building/Library + +cp $MISSION_DIR/truth_spell $GSH_HOME/Castle/Main_building/Library/ +cp $MISSION_DIR/glowing_finger_spell $GSH_HOME/Castle/Main_building/Library/ +cp $MISSION_DIR/flame_spell $GSH_HOME/Castle/Main_building/Library/ +cp -r $MISSION_DIR/cheater $GSH_HOME/Castle/Main_building/Library/ +cp -r $MISSION_DIR/beer $GSH_HOME/Castle/Main_building/Library/ + +cp $MISSION_DIR/truth_spell $GSH_TMP +cp $MISSION_DIR/glowing_finger_spell $GSH_TMP +cp $MISSION_DIR/flame_spell $GSH_TMP +cp -r $MISSION_DIR/cheater $GSH_TMP +cp -r $MISSION_DIR/beer $GSH_TMP + +cp $MISSION_DIR/amplifier_conflict_fixed $GSH_TMP + +cp $MISSION_DIR/clone.sh $GSH_TMP +cp $MISSION_DIR/clean.sh $GSH_TMP +cp $MISSION_DIR/add_remote_origin.sh $GSH_TMP +cp $MISSION_DIR/remove_init_branches.sh $GSH_TMP +cp -r $MISSION_DIR/solution_repo $GSH_TMP + diff --git a/missions/contrib/git_basics/00_needed_files/truth_spell b/missions/contrib/git_basics/00_needed_files/truth_spell new file mode 100644 index 000000000..37dd961f9 --- /dev/null +++ b/missions/contrib/git_basics/00_needed_files/truth_spell @@ -0,0 +1,8 @@ +85 111 +5 222 +5 66 +5 11 + +NB: +This Spell can be used only in the presence of a spoon + diff --git a/missions/contrib/git_basics/01_create_newrepo/_test.sh b/missions/contrib/git_basics/01_create_newrepo/_test.sh new file mode 100644 index 000000000..c2e0a2678 --- /dev/null +++ b/missions/contrib/git_basics/01_create_newrepo/_test.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced by the command "gsh test" for +# testing during development. +# If you write this file, rename it to 'test.sh' +# +# You can use some special commands +# gsh assert check true +# gsh assert check false +# gsh assert CONDITION +# to check that specific conditions are satisfied. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. diff --git a/missions/contrib/git_basics/01_create_newrepo/_treasure-msg.txt b/missions/contrib/git_basics/01_create_newrepo/_treasure-msg.txt new file mode 100644 index 000000000..72094a5b9 --- /dev/null +++ b/missions/contrib/git_basics/01_create_newrepo/_treasure-msg.txt @@ -0,0 +1,3 @@ +This file is not required. When it exists, it is displayed when sourcing +the "treasure.sh" file. (If no "treasure.sh" file exists, this file will +be ignored.) diff --git a/missions/contrib/git_basics/01_create_newrepo/_treasure.sh b/missions/contrib/git_basics/01_create_newrepo/_treasure.sh new file mode 100644 index 000000000..1fa10ce8e --- /dev/null +++ b/missions/contrib/git_basics/01_create_newrepo/_treasure.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is sourced on successfull +# completion of the mission and is added to the global configuration. +# It is typically used to "reward" the player with new features like aliases +# and the like. +# If you need this file, rename it to 'treasure.txt' +# +# Note that should the mission be completed in a subshell, aliases or +# environment variables will disappear. +# That typically happens a mission is checked using process redirection, as in +# $ SOMETHING | gsh check +# To mitigate the problem, GameShell will display a message asking the player +# to run +# $ gsh reset +# in that case. diff --git a/missions/contrib/git_basics/01_create_newrepo/auto.sh b/missions/contrib/git_basics/01_create_newrepo/auto.sh new file mode 100644 index 000000000..a7dc9488c --- /dev/null +++ b/missions/contrib/git_basics/01_create_newrepo/auto.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is used to automatically +# validate the mission. It should end with a succesful `gsh check` command. +# It is sometimes possible to "cheat" by using any hidden data in $GSH_TMP, +# but it is better to do it the "intended" way. +# If you write this file, rename it to auto.sh + +cd $GSH_HOME/Castle/Portals/ +. $GSH_TMP/clone.sh &> /dev/null +. $GSH_TMP/remove_init_branches.sh &> /dev/null +gsh check diff --git a/missions/contrib/git_basics/01_create_newrepo/check.sh b/missions/contrib/git_basics/01_create_newrepo/check.sh new file mode 100644 index 000000000..b404a87d2 --- /dev/null +++ b/missions/contrib/git_basics/01_create_newrepo/check.sh @@ -0,0 +1,43 @@ +#!/usr/bin/env sh + +# This file is required. It is sourced when checking the goal of the mission +# has been achieved. +# It should end with a command returning 0 on success, and something else on +# failure. +# It should "unset" any local variable it has created, and any "global +# variable" that were only used for the mission. (The function _mission_check +# is automatically unset.) +# +# It typically looks like + +_mission_check() { + + # verifier que le repertoire existe et est un depot git + + if [ ! -d "$GSH_HOME/Castle/Portals/spellbook" ] + then + echo " There is no spellbook Forlder in Castle/Portals " + return 1 + else + echo " The repository spellbook exists" + fi + + if [ ! -d $GSH_HOME/Castle/Portals/spellbook/.git ] + then + echo " The repository spellbook is not a git repository" + return 1 + else + echo " The repository spellbook is a git repository " + fi + + # Store the address of the fork of the user in $GSH_TMP to set it properly in the following init + cd $GSH_HOME/Castle/Portals/spellbook + url=$(LANG=GB git remote show origin | grep "Push URL" | tr -s ' ' | cut -d ' ' -f 4) + echo $url > $GSH_TMP/origin_url + + # bring the user back in the previous directory + cd - + + return 0 +} +_mission_check diff --git a/missions/contrib/git_basics/01_create_newrepo/clean.sh b/missions/contrib/git_basics/01_create_newrepo/clean.sh new file mode 120000 index 000000000..be2f419f7 --- /dev/null +++ b/missions/contrib/git_basics/01_create_newrepo/clean.sh @@ -0,0 +1 @@ +../00_needed_files/clean.sh \ No newline at end of file diff --git a/missions/contrib/git_basics/01_create_newrepo/goal.txt b/missions/contrib/git_basics/01_create_newrepo/goal.txt new file mode 100644 index 000000000..c846ab3ca --- /dev/null +++ b/missions/contrib/git_basics/01_create_newrepo/goal.txt @@ -0,0 +1,40 @@ +Mission goal +============ + +According to the Head of the Magic Concil, some spellbooks have been altered in the past, due to avoidable mistakes. + +The Head of the magic council has then sent an emmissary to your castle with an urgent request: all spells created from now on should be put on the SpellBook library (Github, gitlab...) and older ones sitting in Libraries also. + +When you arrived as a wizzard in your current Castle, the previous wizzard left a few spells he was working on, without synchronizing them with the SpellBook Library + +Saving the spell of the previous wizzard without the need of creating a spell yourself is a good training. + + + +The first step as a wizard is to craft your pair of rings (public and private ssh keys) that will allow you to authenticate without login/password to the remote repository. Equiped with your rings, you will be able to create your first spellbook (repository) and clone it locally. + +1. Create your pair of rings (ssh key) +2. Upload it on your account on the interdimensional library (the remote repository git.univ-pau.fr). +3. Create a spellbook (repository) on the interdimensional library (git.univ-pau.fr). "spellbook" should be the name of the project. +4. Go to the Portal room of the Castle and clone your repository there + + + +Useful commands +=============== + +Some instructions on how to create an ssh key: +firefox https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent + +In our case, we will let the passphrase empty, so no need to setup the ssh agent + + +On creation of the repository, it is suggested to create a generic "README" file. + +You will also need to unprotect the main branch otherwise some missions will fail later. On the gitlab web interface, Settings => Repository => Protected branches => unprotect main branch + +To clone a repository: +git clone REPOSITORY_URL + +Two URLs are proposed on the web interface, use the one to clone with SSH. + diff --git a/missions/contrib/git_basics/01_create_newrepo/static.sh b/missions/contrib/git_basics/01_create_newrepo/static.sh new file mode 100644 index 000000000..ec01a82da --- /dev/null +++ b/missions/contrib/git_basics/01_create_newrepo/static.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced once when initialising a GameShell +# game, and whenever the corresponding missions is (re)started. +# It typically creates the parts of the mission that will be available during +# the whole game, like the directory structure. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. diff --git a/missions/contrib/git_basics/02a_create_newSpell/_clean.sh b/missions/contrib/git_basics/02a_create_newSpell/_clean.sh new file mode 100644 index 000000000..b3cec70ae --- /dev/null +++ b/missions/contrib/git_basics/02a_create_newSpell/_clean.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is used to clean the mission, +# for example on completion, or when restarting it. +# In some rare case, cleaning is different after a successful check. You can +# inspect the variable $GSH_LAST_ACTION, which can take the following values: +# assert, check_false, check_true, exit, goto, hard_reset, reset, skip +# If you need this file, rename it to clean.sh diff --git a/missions/contrib/git_basics/02a_create_newSpell/_test.sh b/missions/contrib/git_basics/02a_create_newSpell/_test.sh new file mode 100644 index 000000000..c2e0a2678 --- /dev/null +++ b/missions/contrib/git_basics/02a_create_newSpell/_test.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced by the command "gsh test" for +# testing during development. +# If you write this file, rename it to 'test.sh' +# +# You can use some special commands +# gsh assert check true +# gsh assert check false +# gsh assert CONDITION +# to check that specific conditions are satisfied. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. diff --git a/missions/contrib/git_basics/02a_create_newSpell/_treasure-msg.txt b/missions/contrib/git_basics/02a_create_newSpell/_treasure-msg.txt new file mode 100644 index 000000000..72094a5b9 --- /dev/null +++ b/missions/contrib/git_basics/02a_create_newSpell/_treasure-msg.txt @@ -0,0 +1,3 @@ +This file is not required. When it exists, it is displayed when sourcing +the "treasure.sh" file. (If no "treasure.sh" file exists, this file will +be ignored.) diff --git a/missions/contrib/git_basics/02a_create_newSpell/_treasure.sh b/missions/contrib/git_basics/02a_create_newSpell/_treasure.sh new file mode 100644 index 000000000..1fa10ce8e --- /dev/null +++ b/missions/contrib/git_basics/02a_create_newSpell/_treasure.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is sourced on successfull +# completion of the mission and is added to the global configuration. +# It is typically used to "reward" the player with new features like aliases +# and the like. +# If you need this file, rename it to 'treasure.txt' +# +# Note that should the mission be completed in a subshell, aliases or +# environment variables will disappear. +# That typically happens a mission is checked using process redirection, as in +# $ SOMETHING | gsh check +# To mitigate the problem, GameShell will display a message asking the player +# to run +# $ gsh reset +# in that case. diff --git a/missions/contrib/git_basics/02a_create_newSpell/auto.sh b/missions/contrib/git_basics/02a_create_newSpell/auto.sh new file mode 100644 index 000000000..01a66d528 --- /dev/null +++ b/missions/contrib/git_basics/02a_create_newSpell/auto.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is used to automatically +# validate the mission. It should end with a succesful `gsh check` command. +# It is sometimes possible to "cheat" by using any hidden data in $GSH_TMP, +# but it is better to do it the "intended" way. +# If you write this file, rename it to auto.sh + +cd $GSH_HOME/Castle/Portals/spellbook +cp $GSH_TMP/glowing_finger_spell . +gsh check diff --git a/missions/contrib/git_basics/02a_create_newSpell/check.sh b/missions/contrib/git_basics/02a_create_newSpell/check.sh new file mode 100644 index 000000000..9a5a95333 --- /dev/null +++ b/missions/contrib/git_basics/02a_create_newSpell/check.sh @@ -0,0 +1,50 @@ +#!/usr/bin/env sh + +# This file is required. It is sourced when checking the goal of the mission +# has been achieved. +# It should end with a command returning 0 on success, and something else on +# failure. +# It should "unset" any local variable it has created, and any "global +# variable" that were only used for the mission. (The function _mission_check +# is automatically unset.) +# +# It typically looks like + +_mission_check() { + + + if [ ! -e "$GSH_HOME/Castle/Portals/spellbook/glowing_finger_spell" ] + then + echo " The file glowing_finger_spell doesn't exist" + return 1 + else + echo " The file glowing_finger_spell exist" + fi + cd $GSH_HOME/Castle/Portals/spellbook/ + + # verifier que le repertoire existe et est un depot git + LANG=en_GB git status | grep -e "Untracked" + + test=$(echo $?) + + if [ $test -eq 1 ] + then + echo " you should have some untracked file" + return 1 +# else +# git status | grep -e "nothing to commit" +# test=$(echo $?) +# if [ ! $test ] +# then +# echo " Good, you did not commited your modifications" +# return 0 +# else +# echo " You should not have commited your modifications" +# return 1 +# fi + fi + + + +} +_mission_check diff --git a/missions/contrib/git_basics/02a_create_newSpell/clean.sh b/missions/contrib/git_basics/02a_create_newSpell/clean.sh new file mode 120000 index 000000000..be2f419f7 --- /dev/null +++ b/missions/contrib/git_basics/02a_create_newSpell/clean.sh @@ -0,0 +1 @@ +../00_needed_files/clean.sh \ No newline at end of file diff --git a/missions/contrib/git_basics/02a_create_newSpell/goal.txt b/missions/contrib/git_basics/02a_create_newSpell/goal.txt new file mode 100644 index 000000000..1b1b861fb --- /dev/null +++ b/missions/contrib/git_basics/02a_create_newSpell/goal.txt @@ -0,0 +1,43 @@ +Mission goal +============ + + +Congratulation on getting your first spellbook. + + +You will start with the Glowing Finger spell. This one is usefull when you don't have a torch closeby. + +The scroll for this spell contains the list of ingredients required to cast this spell. + +For your first synchronisation, we will go through a step by step process. + +Move the Glowing finger from the Castle's Library into your spellbook + +Then step into your spellbook (change directory) + +Have a look at the synchronisation state of your local book. + + +Useful commands +=============== + + +To show the the history of the whole repository +git log + +To show the state of your local repository, staging area and working directory +git status + +To show the difference between your working directory and the laste version in the repository (in 99% of the time, to be precise the comparison is made with the version pointed by HEAD) +git diff + + +NB +=============== + +Do not add, commit or push the new file. + +you might be asked to create a token through github you can acces the documentation using: + +firefox https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens + diff --git a/missions/contrib/git_basics/02a_create_newSpell/init.sh b/missions/contrib/git_basics/02a_create_newSpell/init.sh new file mode 100644 index 000000000..6f57e56bc --- /dev/null +++ b/missions/contrib/git_basics/02a_create_newSpell/init.sh @@ -0,0 +1,32 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced every time the mission is started. +# Since it is sourced every time the mission is restarted, it can generate +# random data to make each run slightly different. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. +# +# Note however that should the mission be initialized in a subshell, those +# environment variables will disappear! That typically happens a mission is +# checked using process redirection, as in +# $ SOMETHING | gsh check +# To mitigate the problem, GameShell will display a message asking the player +# to run +# $ gsh reset +# in that case. +# +# It typically looks like +_mission_init() { + + if [ -f $GSH_TMP/skip_init ] + then + rm $GSH_TMP/skip_init + else + . $GSH_TMP/clone.sh &> /dev/null + . $GSH_TMP/remove_init_branches.sh &> /dev/null + . $GSH_TMP/add_remote_origin.sh + fi + +} +_mission_init diff --git a/missions/contrib/git_basics/02a_create_newSpell/static.sh b/missions/contrib/git_basics/02a_create_newSpell/static.sh new file mode 100644 index 000000000..ec01a82da --- /dev/null +++ b/missions/contrib/git_basics/02a_create_newSpell/static.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced once when initialising a GameShell +# game, and whenever the corresponding missions is (re)started. +# It typically creates the parts of the mission that will be available during +# the whole game, like the directory structure. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. diff --git a/missions/contrib/git_basics/02b_add_newSpell/_clean.sh b/missions/contrib/git_basics/02b_add_newSpell/_clean.sh new file mode 100644 index 000000000..b3cec70ae --- /dev/null +++ b/missions/contrib/git_basics/02b_add_newSpell/_clean.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is used to clean the mission, +# for example on completion, or when restarting it. +# In some rare case, cleaning is different after a successful check. You can +# inspect the variable $GSH_LAST_ACTION, which can take the following values: +# assert, check_false, check_true, exit, goto, hard_reset, reset, skip +# If you need this file, rename it to clean.sh diff --git a/missions/contrib/git_basics/02b_add_newSpell/_test.sh b/missions/contrib/git_basics/02b_add_newSpell/_test.sh new file mode 100644 index 000000000..c2e0a2678 --- /dev/null +++ b/missions/contrib/git_basics/02b_add_newSpell/_test.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced by the command "gsh test" for +# testing during development. +# If you write this file, rename it to 'test.sh' +# +# You can use some special commands +# gsh assert check true +# gsh assert check false +# gsh assert CONDITION +# to check that specific conditions are satisfied. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. diff --git a/missions/contrib/git_basics/02b_add_newSpell/_treasure-msg.txt b/missions/contrib/git_basics/02b_add_newSpell/_treasure-msg.txt new file mode 100644 index 000000000..72094a5b9 --- /dev/null +++ b/missions/contrib/git_basics/02b_add_newSpell/_treasure-msg.txt @@ -0,0 +1,3 @@ +This file is not required. When it exists, it is displayed when sourcing +the "treasure.sh" file. (If no "treasure.sh" file exists, this file will +be ignored.) diff --git a/missions/contrib/git_basics/02b_add_newSpell/_treasure.sh b/missions/contrib/git_basics/02b_add_newSpell/_treasure.sh new file mode 100644 index 000000000..1fa10ce8e --- /dev/null +++ b/missions/contrib/git_basics/02b_add_newSpell/_treasure.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is sourced on successfull +# completion of the mission and is added to the global configuration. +# It is typically used to "reward" the player with new features like aliases +# and the like. +# If you need this file, rename it to 'treasure.txt' +# +# Note that should the mission be completed in a subshell, aliases or +# environment variables will disappear. +# That typically happens a mission is checked using process redirection, as in +# $ SOMETHING | gsh check +# To mitigate the problem, GameShell will display a message asking the player +# to run +# $ gsh reset +# in that case. diff --git a/missions/contrib/git_basics/02b_add_newSpell/auto.sh b/missions/contrib/git_basics/02b_add_newSpell/auto.sh new file mode 100644 index 000000000..d762ee11c --- /dev/null +++ b/missions/contrib/git_basics/02b_add_newSpell/auto.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is used to automatically +# validate the mission. It should end with a succesful `gsh check` command. +# It is sometimes possible to "cheat" by using any hidden data in $GSH_TMP, +# but it is better to do it the "intended" way. +# If you write this file, rename it to auto.sh + + +cd $GSH_HOME/Castle/Portals/spellbook +git add glowing_finger_spell +gsh check + diff --git a/missions/contrib/git_basics/02b_add_newSpell/check.sh b/missions/contrib/git_basics/02b_add_newSpell/check.sh new file mode 100644 index 000000000..b62a79973 --- /dev/null +++ b/missions/contrib/git_basics/02b_add_newSpell/check.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env sh + +# This file is required. It is sourced when checking the goal of the mission +# has been achieved. +# It should end with a command returning 0 on success, and something else on +# failure. +# It should "unset" any local variable it has created, and any "global +# variable" that were only used for the mission. (The function _mission_check +# is automatically unset.) +# +# It typically looks like + +_mission_check() { + + if [ ! -e "$GSH_HOME/Castle/Portals/spellbook/glowing_finger_spell" ] + then + echo " The file glowing_finger_spell doesn't exist" + return 1 + else + echo " The file glowing_finger_spell exist" + fi + + # verifier que le repertoire existe et est un depot git + cd $GSH_HOME/Castle/Portals/spellbook/ + LANG=en_GB git status | grep -e "new file: glowing_finger_spell" + +test=$(echo $?) + + if [ $test -eq 0 ] + then + echo " glowing_finger_spell is a new tracked file" + return 0 + else + + echo " glowing_finger_spell is not a new tracked file" + return 1 + +# git status | grep -e "nothing to commit" +# test=$(echo $?) +# if [ ! $test ] +# then +# echo " Good, you did not commited your modifications" +# return 0 +# else +# echo " You should not have commited your modifications" +# return 1 +# fi + fi + + +} +_mission_check diff --git a/missions/contrib/git_basics/02b_add_newSpell/clean.sh b/missions/contrib/git_basics/02b_add_newSpell/clean.sh new file mode 120000 index 000000000..be2f419f7 --- /dev/null +++ b/missions/contrib/git_basics/02b_add_newSpell/clean.sh @@ -0,0 +1 @@ +../00_needed_files/clean.sh \ No newline at end of file diff --git a/missions/contrib/git_basics/02b_add_newSpell/goal.txt b/missions/contrib/git_basics/02b_add_newSpell/goal.txt new file mode 100644 index 000000000..f5005b8da --- /dev/null +++ b/missions/contrib/git_basics/02b_add_newSpell/goal.txt @@ -0,0 +1,27 @@ +Mission goal +============ + +So as you can see with `git status`, the new spell is not being tracked by the portal system yet. + + +Add the file to the staging area and check what is the output of `git status` now + + +Useful commands +=============== + +To add a file or modifications of a file to the staging area + +git add FILE_NAME + + +To show the state of your local repository, staging area and working directory +git status + + + +NB +=============== + +Do not commit or push the file. + diff --git a/missions/contrib/git_basics/02b_add_newSpell/init.sh b/missions/contrib/git_basics/02b_add_newSpell/init.sh new file mode 100644 index 000000000..b28a2b69e --- /dev/null +++ b/missions/contrib/git_basics/02b_add_newSpell/init.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced every time the mission is started. +# Since it is sourced every time the mission is restarted, it can generate +# random data to make each run slightly different. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. +# +# Note however that should the mission be initialized in a subshell, those +# environment variables will disappear! That typically happens a mission is +# checked using process redirection, as in +# $ SOMETHING | gsh check +# To mitigate the problem, GameShell will display a message asking the player +# to run +# $ gsh reset +# in that case. +# +# It typically looks like +_mission_init() { + + if [ -f $GSH_TMP/skip_init ] + then + rm $GSH_TMP/skip_init + else + . $GSH_TMP/clone.sh &> /dev/null + . $GSH_TMP/remove_init_branches.sh &> /dev/null + . $GSH_TMP/add_remote_origin.sh + cp $GSH_TMP/glowing_finger_spell . + fi + +} +_mission_init diff --git a/missions/contrib/git_basics/02b_add_newSpell/static.sh b/missions/contrib/git_basics/02b_add_newSpell/static.sh new file mode 100644 index 000000000..ec01a82da --- /dev/null +++ b/missions/contrib/git_basics/02b_add_newSpell/static.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced once when initialising a GameShell +# game, and whenever the corresponding missions is (re)started. +# It typically creates the parts of the mission that will be available during +# the whole game, like the directory structure. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. diff --git a/missions/contrib/git_basics/02c_commit_newSpell/_clean.sh b/missions/contrib/git_basics/02c_commit_newSpell/_clean.sh new file mode 100644 index 000000000..b3cec70ae --- /dev/null +++ b/missions/contrib/git_basics/02c_commit_newSpell/_clean.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is used to clean the mission, +# for example on completion, or when restarting it. +# In some rare case, cleaning is different after a successful check. You can +# inspect the variable $GSH_LAST_ACTION, which can take the following values: +# assert, check_false, check_true, exit, goto, hard_reset, reset, skip +# If you need this file, rename it to clean.sh diff --git a/missions/contrib/git_basics/02c_commit_newSpell/_test.sh b/missions/contrib/git_basics/02c_commit_newSpell/_test.sh new file mode 100644 index 000000000..c2e0a2678 --- /dev/null +++ b/missions/contrib/git_basics/02c_commit_newSpell/_test.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced by the command "gsh test" for +# testing during development. +# If you write this file, rename it to 'test.sh' +# +# You can use some special commands +# gsh assert check true +# gsh assert check false +# gsh assert CONDITION +# to check that specific conditions are satisfied. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. diff --git a/missions/contrib/git_basics/02c_commit_newSpell/_treasure-msg.txt b/missions/contrib/git_basics/02c_commit_newSpell/_treasure-msg.txt new file mode 100644 index 000000000..72094a5b9 --- /dev/null +++ b/missions/contrib/git_basics/02c_commit_newSpell/_treasure-msg.txt @@ -0,0 +1,3 @@ +This file is not required. When it exists, it is displayed when sourcing +the "treasure.sh" file. (If no "treasure.sh" file exists, this file will +be ignored.) diff --git a/missions/contrib/git_basics/02c_commit_newSpell/_treasure.sh b/missions/contrib/git_basics/02c_commit_newSpell/_treasure.sh new file mode 100644 index 000000000..1fa10ce8e --- /dev/null +++ b/missions/contrib/git_basics/02c_commit_newSpell/_treasure.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is sourced on successfull +# completion of the mission and is added to the global configuration. +# It is typically used to "reward" the player with new features like aliases +# and the like. +# If you need this file, rename it to 'treasure.txt' +# +# Note that should the mission be completed in a subshell, aliases or +# environment variables will disappear. +# That typically happens a mission is checked using process redirection, as in +# $ SOMETHING | gsh check +# To mitigate the problem, GameShell will display a message asking the player +# to run +# $ gsh reset +# in that case. diff --git a/missions/contrib/git_basics/02c_commit_newSpell/auto.sh b/missions/contrib/git_basics/02c_commit_newSpell/auto.sh new file mode 100644 index 000000000..543211440 --- /dev/null +++ b/missions/contrib/git_basics/02c_commit_newSpell/auto.sh @@ -0,0 +1,13 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is used to automatically +# validate the mission. It should end with a succesful `gsh check` command. +# It is sometimes possible to "cheat" by using any hidden data in $GSH_TMP, +# but it is better to do it the "intended" way. +# If you write this file, rename it to auto.sh + +cd $GSH_HOME/Castle/Portals/spellbook +# recreate properly main branch on the remote before doing the commit otherwise status does not show the correct message +git push -u origin main +git commit -m 'glowing finger spell added' +gsh check diff --git a/missions/contrib/git_basics/02c_commit_newSpell/check.sh b/missions/contrib/git_basics/02c_commit_newSpell/check.sh new file mode 100644 index 000000000..6eb9d3450 --- /dev/null +++ b/missions/contrib/git_basics/02c_commit_newSpell/check.sh @@ -0,0 +1,44 @@ +#!/usr/bin/env sh + +# This file is required. It is sourced when checking the goal of the mission +# has been achieved. +# It should end with a command returning 0 on success, and something else on +# failure. +# It should "unset" any local variable it has created, and any "global +# variable" that were only used for the mission. (The function _mission_check +# is automatically unset.) +# +# It typically looks like + +_mission_check() { + + if [ ! -e "$GSH_HOME/Castle/Portals/spellbook/glowing_finger_spell" ] + then + echo " The file glowing_finger_spell doesn't exist" + return 1 + else + echo " The file glowing_finger_spell exist" + fi + cd $GSH_HOME/Castle/Portals/spellbook/ + + LANG=en_GB git status | grep -e "Changes to be committed:" + + if [ $? -eq 0 ] + then + echo " you should not have changes to commit any more" + return 1 + fi + + + LANG=en_GB git status | grep -e "Your branch is ahead of" + + if [ $? -eq 1 ] + then + echo " you should have changes to push" + return 1 + fi + + return 0 + +} +_mission_check diff --git a/missions/contrib/git_basics/02c_commit_newSpell/clean.sh b/missions/contrib/git_basics/02c_commit_newSpell/clean.sh new file mode 120000 index 000000000..be2f419f7 --- /dev/null +++ b/missions/contrib/git_basics/02c_commit_newSpell/clean.sh @@ -0,0 +1 @@ +../00_needed_files/clean.sh \ No newline at end of file diff --git a/missions/contrib/git_basics/02c_commit_newSpell/goal.txt b/missions/contrib/git_basics/02c_commit_newSpell/goal.txt new file mode 100644 index 000000000..90f1f5daf --- /dev/null +++ b/missions/contrib/git_basics/02c_commit_newSpell/goal.txt @@ -0,0 +1,31 @@ +Mission goal +============ + +Indeed, the spell is now tracked but not synchronised yet. + +Before synchronisation, you need to create a snapshot of your spell in your local spellbook, in the portal room. + +Have a look at the state of the synchronisation again + +Useful commands +=============== + +To create a snaphot of for all the staged modifications as a new version of your code + +git commit -m 'COMMIT_MESSAGE' + + +To show the the history of the whole repository +git log + +To show the state of your local repository, staging area and working directory +git status + +To show the difference between your working directory and the laste version in the repository (in 99% of the time, to be precise the comparison is made with the version pointed by HEAD) +git diff + + +NB +=============== + +Do not push the new file. diff --git a/missions/contrib/git_basics/02c_commit_newSpell/init.sh b/missions/contrib/git_basics/02c_commit_newSpell/init.sh new file mode 100644 index 000000000..a2a8a1b45 --- /dev/null +++ b/missions/contrib/git_basics/02c_commit_newSpell/init.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced every time the mission is started. +# Since it is sourced every time the mission is restarted, it can generate +# random data to make each run slightly different. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. +# +# Note however that should the mission be initialized in a subshell, those +# environment variables will disappear! That typically happens a mission is +# checked using process redirection, as in +# $ SOMETHING | gsh check +# To mitigate the problem, GameShell will display a message asking the player +# to run +# $ gsh reset +# in that case. +# +# It typically looks like +_mission_init() { + + if [ -f $GSH_TMP/skip_init ] + then + rm $GSH_TMP/skip_init + else + . $GSH_TMP/clone.sh &> /dev/null + . $GSH_TMP/remove_init_branches.sh &> /dev/null + . $GSH_TMP/add_remote_origin.sh + cp $GSH_TMP/glowing_finger_spell . + git add glowing_finger_spell + fi + +} +_mission_init diff --git a/missions/contrib/git_basics/02c_commit_newSpell/static.sh b/missions/contrib/git_basics/02c_commit_newSpell/static.sh new file mode 100644 index 000000000..ec01a82da --- /dev/null +++ b/missions/contrib/git_basics/02c_commit_newSpell/static.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced once when initialising a GameShell +# game, and whenever the corresponding missions is (re)started. +# It typically creates the parts of the mission that will be available during +# the whole game, like the directory structure. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. diff --git a/missions/contrib/git_basics/02d_push_newSpell/_clean.sh b/missions/contrib/git_basics/02d_push_newSpell/_clean.sh new file mode 100644 index 000000000..b3cec70ae --- /dev/null +++ b/missions/contrib/git_basics/02d_push_newSpell/_clean.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is used to clean the mission, +# for example on completion, or when restarting it. +# In some rare case, cleaning is different after a successful check. You can +# inspect the variable $GSH_LAST_ACTION, which can take the following values: +# assert, check_false, check_true, exit, goto, hard_reset, reset, skip +# If you need this file, rename it to clean.sh diff --git a/missions/contrib/git_basics/02d_push_newSpell/_test.sh b/missions/contrib/git_basics/02d_push_newSpell/_test.sh new file mode 100644 index 000000000..c2e0a2678 --- /dev/null +++ b/missions/contrib/git_basics/02d_push_newSpell/_test.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced by the command "gsh test" for +# testing during development. +# If you write this file, rename it to 'test.sh' +# +# You can use some special commands +# gsh assert check true +# gsh assert check false +# gsh assert CONDITION +# to check that specific conditions are satisfied. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. diff --git a/missions/contrib/git_basics/02d_push_newSpell/_treasure-msg.txt b/missions/contrib/git_basics/02d_push_newSpell/_treasure-msg.txt new file mode 100644 index 000000000..72094a5b9 --- /dev/null +++ b/missions/contrib/git_basics/02d_push_newSpell/_treasure-msg.txt @@ -0,0 +1,3 @@ +This file is not required. When it exists, it is displayed when sourcing +the "treasure.sh" file. (If no "treasure.sh" file exists, this file will +be ignored.) diff --git a/missions/contrib/git_basics/02d_push_newSpell/_treasure.sh b/missions/contrib/git_basics/02d_push_newSpell/_treasure.sh new file mode 100644 index 000000000..1fa10ce8e --- /dev/null +++ b/missions/contrib/git_basics/02d_push_newSpell/_treasure.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is sourced on successfull +# completion of the mission and is added to the global configuration. +# It is typically used to "reward" the player with new features like aliases +# and the like. +# If you need this file, rename it to 'treasure.txt' +# +# Note that should the mission be completed in a subshell, aliases or +# environment variables will disappear. +# That typically happens a mission is checked using process redirection, as in +# $ SOMETHING | gsh check +# To mitigate the problem, GameShell will display a message asking the player +# to run +# $ gsh reset +# in that case. diff --git a/missions/contrib/git_basics/02d_push_newSpell/auto.sh b/missions/contrib/git_basics/02d_push_newSpell/auto.sh new file mode 100644 index 000000000..811ce9e31 --- /dev/null +++ b/missions/contrib/git_basics/02d_push_newSpell/auto.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is used to automatically +# validate the mission. It should end with a succesful `gsh check` command. +# It is sometimes possible to "cheat" by using any hidden data in $GSH_TMP, +# but it is better to do it the "intended" way. +# If you write this file, rename it to auto.sh + +cd $GSH_HOME/Castle/Portals/spellbook +git push +gsh check diff --git a/missions/contrib/git_basics/02d_push_newSpell/check.sh b/missions/contrib/git_basics/02d_push_newSpell/check.sh new file mode 100644 index 000000000..7eefcafc5 --- /dev/null +++ b/missions/contrib/git_basics/02d_push_newSpell/check.sh @@ -0,0 +1,40 @@ +#!/usr/bin/env sh + +# This file is required. It is sourced when checking the goal of the mission +# has been achieved. +# It should end with a command returning 0 on success, and something else on +# failure. +# It should "unset" any local variable it has created, and any "global +# variable" that were only used for the mission. (The function _mission_check +# is automatically unset.) +# +# It typically looks like + +_mission_check() { + cd $GSH_HOME/Castle/Portals/spellbook/ + + LANG=en_GB git status | grep -e "up to date with" +test=$(echo $?) + + if [ $test -eq 1 ] + then + echo " You did not pushed all of your modifications" + return 1 + else + cd $GSH_HOME/Castle/Portals/spellbook/ + + LANG=en_GB git status | grep -e "Changes to be committed:" + test=$(echo $?) + + if [ $test -eq 0 ] + then + echo " You did not commited all of your modifications" + return 1 + else + echo " You did pushed all of your modifications" + return 0 + fi + fi + +} +_mission_check diff --git a/missions/contrib/git_basics/02d_push_newSpell/clean.sh b/missions/contrib/git_basics/02d_push_newSpell/clean.sh new file mode 120000 index 000000000..be2f419f7 --- /dev/null +++ b/missions/contrib/git_basics/02d_push_newSpell/clean.sh @@ -0,0 +1 @@ +../00_needed_files/clean.sh \ No newline at end of file diff --git a/missions/contrib/git_basics/02d_push_newSpell/goal.txt b/missions/contrib/git_basics/02d_push_newSpell/goal.txt new file mode 100644 index 000000000..cf9d2e528 --- /dev/null +++ b/missions/contrib/git_basics/02d_push_newSpell/goal.txt @@ -0,0 +1,26 @@ +Mission goal +============ + +That's it, your spell is ready for synchronisation. + + +Now push everything through the portal system. + +And have a look again at the state of the synchronisation + +Useful commands +=============== + +To push all commits of the local repository to the remote one +git push + + +To show the the history of the whole repository +git log + +To show the state of your local repository, staging area and working directory +git status + +To show the difference between your working directory and the laste version in the repository (in 99% of the time, to be precise the comparison is made with the version pointed by HEAD) +git diff + diff --git a/missions/contrib/git_basics/02d_push_newSpell/init.sh b/missions/contrib/git_basics/02d_push_newSpell/init.sh new file mode 100644 index 000000000..dfd27cad4 --- /dev/null +++ b/missions/contrib/git_basics/02d_push_newSpell/init.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced every time the mission is started. +# Since it is sourced every time the mission is restarted, it can generate +# random data to make each run slightly different. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. +# +# Note however that should the mission be initialized in a subshell, those +# environment variables will disappear! That typically happens a mission is +# checked using process redirection, as in +# $ SOMETHING | gsh check +# To mitigate the problem, GameShell will display a message asking the player +# to run +# $ gsh reset +# in that case. +# +# It typically looks like +_mission_init() { + + if [ -f $GSH_TMP/skip_init ] + then + rm $GSH_TMP/skip_init + else + . $GSH_TMP/clone.sh &> /dev/null + git reset --hard origin/glowing_finger_spell_added &> /dev/null + . $GSH_TMP/remove_init_branches.sh &> /dev/null + . $GSH_TMP/add_remote_origin.sh + fi + +} +_mission_init diff --git a/missions/contrib/git_basics/02d_push_newSpell/static.sh b/missions/contrib/git_basics/02d_push_newSpell/static.sh new file mode 100644 index 000000000..ec01a82da --- /dev/null +++ b/missions/contrib/git_basics/02d_push_newSpell/static.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced once when initialising a GameShell +# game, and whenever the corresponding missions is (re)started. +# It typically creates the parts of the mission that will be available during +# the whole game, like the directory structure. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. diff --git a/missions/contrib/git_basics/02d_push_newSpell/treasure.sh b/missions/contrib/git_basics/02d_push_newSpell/treasure.sh new file mode 100644 index 000000000..7b6b768bb --- /dev/null +++ b/missions/contrib/git_basics/02d_push_newSpell/treasure.sh @@ -0,0 +1,57 @@ +#!/usr/bin/env bash + +# Script pour afficher la main ASCII avec l'index marqué et une aura circulaire + +HIDE="\e[?25l" +SHOW="\e[?25h" + +DURATION=3 # Durée totale de l'animation en secondes +INTERVAL=0.3 # Intervalle entre les frames + +# Main ASCII +HAND_BASE="\ + ____ ____ ____ ____ + | | | | O | + |____|____|____|____| + | | | | | + | | | | | + | | | | | + | | | | |_______ + | | + | ______| + | | + | | + | | + |____________________|" + +# Frames pour l'aura circulaire autour de l'index +AURA_FRAMES=( +" *** + * * * + ***" +" * + *O* + *" +" * * + * O * + * *" +) + +trap "printf '${SHOW}\n'; exit" INT TERM + +printf "$HIDE" +END=$((SECONDS+DURATION)) + +while [ $SECONDS -lt $END ]; do + for aura in "${AURA_FRAMES[@]}"; do + clear + # Affiche l'aura au-dessus et autour du troisième doigt (index) + echo -e "$aura" + echo -e "$HAND_BASE" + sleep $INTERVAL + done +done + +printf "$SHOW" + + diff --git a/missions/contrib/git_basics/03_second_spell_add_commit_push/_clean.sh b/missions/contrib/git_basics/03_second_spell_add_commit_push/_clean.sh new file mode 100644 index 000000000..b3cec70ae --- /dev/null +++ b/missions/contrib/git_basics/03_second_spell_add_commit_push/_clean.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is used to clean the mission, +# for example on completion, or when restarting it. +# In some rare case, cleaning is different after a successful check. You can +# inspect the variable $GSH_LAST_ACTION, which can take the following values: +# assert, check_false, check_true, exit, goto, hard_reset, reset, skip +# If you need this file, rename it to clean.sh diff --git a/missions/contrib/git_basics/03_second_spell_add_commit_push/_test.sh b/missions/contrib/git_basics/03_second_spell_add_commit_push/_test.sh new file mode 100644 index 000000000..c2e0a2678 --- /dev/null +++ b/missions/contrib/git_basics/03_second_spell_add_commit_push/_test.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced by the command "gsh test" for +# testing during development. +# If you write this file, rename it to 'test.sh' +# +# You can use some special commands +# gsh assert check true +# gsh assert check false +# gsh assert CONDITION +# to check that specific conditions are satisfied. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. diff --git a/missions/contrib/git_basics/03_second_spell_add_commit_push/_treasure-msg.txt b/missions/contrib/git_basics/03_second_spell_add_commit_push/_treasure-msg.txt new file mode 100644 index 000000000..72094a5b9 --- /dev/null +++ b/missions/contrib/git_basics/03_second_spell_add_commit_push/_treasure-msg.txt @@ -0,0 +1,3 @@ +This file is not required. When it exists, it is displayed when sourcing +the "treasure.sh" file. (If no "treasure.sh" file exists, this file will +be ignored.) diff --git a/missions/contrib/git_basics/03_second_spell_add_commit_push/_treasure.sh b/missions/contrib/git_basics/03_second_spell_add_commit_push/_treasure.sh new file mode 100644 index 000000000..1fa10ce8e --- /dev/null +++ b/missions/contrib/git_basics/03_second_spell_add_commit_push/_treasure.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is sourced on successfull +# completion of the mission and is added to the global configuration. +# It is typically used to "reward" the player with new features like aliases +# and the like. +# If you need this file, rename it to 'treasure.txt' +# +# Note that should the mission be completed in a subshell, aliases or +# environment variables will disappear. +# That typically happens a mission is checked using process redirection, as in +# $ SOMETHING | gsh check +# To mitigate the problem, GameShell will display a message asking the player +# to run +# $ gsh reset +# in that case. diff --git a/missions/contrib/git_basics/03_second_spell_add_commit_push/auto.sh b/missions/contrib/git_basics/03_second_spell_add_commit_push/auto.sh new file mode 100644 index 000000000..84b3edfd5 --- /dev/null +++ b/missions/contrib/git_basics/03_second_spell_add_commit_push/auto.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is used to automatically +# validate the mission. It should end with a succesful `gsh check` command. +# It is sometimes possible to "cheat" by using any hidden data in $GSH_TMP, +# but it is better to do it the "intended" way. +# If you write this file, rename it to auto.sh + +cd $GSH_HOME/Castle/Portals/spellbook +cp $GSH_TMP/truth_spell . +git add truth_spell +git commit -m "truth spell added" +git push +gsh check + diff --git a/missions/contrib/git_basics/03_second_spell_add_commit_push/check.sh b/missions/contrib/git_basics/03_second_spell_add_commit_push/check.sh new file mode 100644 index 000000000..c1a525630 --- /dev/null +++ b/missions/contrib/git_basics/03_second_spell_add_commit_push/check.sh @@ -0,0 +1,70 @@ +#!/usr/bin/env sh + +# This file is required. It is sourced when checking the goal of the mission +# has been achieved. +# It should end with a command returning 0 on success, and something else on +# failure. +# It should "unset" any local variable it has created, and any "global +# variable" that were only used for the mission. (The function _mission_check +# is automatically unset.) +# +# It typically looks like + +_mission_check() { + + + + if [ ! -e "$GSH_HOME/Castle/Portals/spellbook" ] + then + echo " spellbook doesn't exist" + return 1 + else + echo " spellbook exist" + fi + + if [ ! -e "$GSH_HOME/Castle/Portals/spellbook/truth_spell" ] + then + echo " The file truth_spell doesn't exist" + return 1 + else + echo " The file truth_spell exist" + fi + + # verifier que le repertoire existe et est un depot git + cd $GSH_HOME/Castle/Portals/spellbook/ + +LANG=en_GB git status | grep -e "Untracked" + + test=$(echo $?) + + if [ $test -eq 0 ] + then + echo " you should not have untracked file" + return 1 + fi + + + LANG=en_GB git status | grep -e "up to date with" +test=$(echo $?) + + if [ $test -eq 1 ] + then + echo " You did not pushed all of your modifications" + return 1 + else + cd $GSH_HOME/Castle/Portals/spellbook/ + + LANG=en_GB git status | grep -e "Changes to be committed:" + test=$(echo $?) + + if [ $test -eq 0 ] + then + echo " You did not commited all of your modifications" + return 1 + else + echo " You did pushed all of your modifications" + return 0 + fi + fi +} +_mission_check diff --git a/missions/contrib/git_basics/03_second_spell_add_commit_push/clean.sh b/missions/contrib/git_basics/03_second_spell_add_commit_push/clean.sh new file mode 120000 index 000000000..be2f419f7 --- /dev/null +++ b/missions/contrib/git_basics/03_second_spell_add_commit_push/clean.sh @@ -0,0 +1 @@ +../00_needed_files/clean.sh \ No newline at end of file diff --git a/missions/contrib/git_basics/03_second_spell_add_commit_push/goal.txt b/missions/contrib/git_basics/03_second_spell_add_commit_push/goal.txt new file mode 100644 index 000000000..ea423b9bf --- /dev/null +++ b/missions/contrib/git_basics/03_second_spell_add_commit_push/goal.txt @@ -0,0 +1,18 @@ +Mission goal +============ + +You now have a good idea of the synchronisation process. + +You can now synchronisze the spell of truth (truth_spell) as you did for the glowing finger spell. + + + +Useful commands +=============== + +git add FILENAME : start tracking the file FILENAME or add its modification to the staging area + +git commit -m 'COMMIT_MESSAGE' + +git push + diff --git a/missions/contrib/git_basics/03_second_spell_add_commit_push/init.sh b/missions/contrib/git_basics/03_second_spell_add_commit_push/init.sh new file mode 100644 index 000000000..dfd27cad4 --- /dev/null +++ b/missions/contrib/git_basics/03_second_spell_add_commit_push/init.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced every time the mission is started. +# Since it is sourced every time the mission is restarted, it can generate +# random data to make each run slightly different. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. +# +# Note however that should the mission be initialized in a subshell, those +# environment variables will disappear! That typically happens a mission is +# checked using process redirection, as in +# $ SOMETHING | gsh check +# To mitigate the problem, GameShell will display a message asking the player +# to run +# $ gsh reset +# in that case. +# +# It typically looks like +_mission_init() { + + if [ -f $GSH_TMP/skip_init ] + then + rm $GSH_TMP/skip_init + else + . $GSH_TMP/clone.sh &> /dev/null + git reset --hard origin/glowing_finger_spell_added &> /dev/null + . $GSH_TMP/remove_init_branches.sh &> /dev/null + . $GSH_TMP/add_remote_origin.sh + fi + +} +_mission_init diff --git a/missions/contrib/git_basics/03_second_spell_add_commit_push/static.sh b/missions/contrib/git_basics/03_second_spell_add_commit_push/static.sh new file mode 100644 index 000000000..ec01a82da --- /dev/null +++ b/missions/contrib/git_basics/03_second_spell_add_commit_push/static.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced once when initialising a GameShell +# game, and whenever the corresponding missions is (re)started. +# It typically creates the parts of the mission that will be available during +# the whole game, like the directory structure. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. diff --git a/missions/contrib/git_basics/03_second_spell_add_commit_push/treasure.sh b/missions/contrib/git_basics/03_second_spell_add_commit_push/treasure.sh new file mode 100644 index 000000000..e445816b3 --- /dev/null +++ b/missions/contrib/git_basics/03_second_spell_add_commit_push/treasure.sh @@ -0,0 +1,56 @@ +#!/bin/bash + +MSG="There is no spoon" + +clear +tput civis # cacher le curseur + +# dimensions du terminal +LINES=$(tput lines) +COLS=$(tput cols) + +# position du texte +row=$((LINES/2)) +col=$(( (COLS-${#MSG})/2 )) + +start=$(date +%s) + +while true; do + now=$(date +%s) + elapsed=$((now - start)) + if [ $elapsed -ge 4 ]; then + break + fi + + clear + + # afficher le message centré + tput cup $row $col + echo -e "\033[1;97m$MSG\033[0m" + + # dessiner quelques étincelles aléatoires autour + for i in {1..20}; do + y=$((row-3+RANDOM%7)) + x=$((col-5+RANDOM%(${#MSG}+10))) + sym=("." "*" "o" "O" "+") + c=${sym[$RANDOM%${#sym[@]}]} + color=$((31+RANDOM%7)) + tput cup $y $x + echo -ne "\033[1;${color}m$c\033[0m" + done + + sleep 0.1 +done + +# restauration du curseur +tput cnorm + +# replacer le message final sans effacer l'écran +tput cup $row $col +echo -e "\033[1;97m$MSG\033[0m" + +# ajouter 5 lignes vides puis retour à la ligne +for i in {1..7}; do + echo "" +done + diff --git a/missions/contrib/git_basics/04_third_spell_branch/_clean.sh b/missions/contrib/git_basics/04_third_spell_branch/_clean.sh new file mode 100644 index 000000000..b3cec70ae --- /dev/null +++ b/missions/contrib/git_basics/04_third_spell_branch/_clean.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is used to clean the mission, +# for example on completion, or when restarting it. +# In some rare case, cleaning is different after a successful check. You can +# inspect the variable $GSH_LAST_ACTION, which can take the following values: +# assert, check_false, check_true, exit, goto, hard_reset, reset, skip +# If you need this file, rename it to clean.sh diff --git a/missions/contrib/git_basics/04_third_spell_branch/_test.sh b/missions/contrib/git_basics/04_third_spell_branch/_test.sh new file mode 100644 index 000000000..c2e0a2678 --- /dev/null +++ b/missions/contrib/git_basics/04_third_spell_branch/_test.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced by the command "gsh test" for +# testing during development. +# If you write this file, rename it to 'test.sh' +# +# You can use some special commands +# gsh assert check true +# gsh assert check false +# gsh assert CONDITION +# to check that specific conditions are satisfied. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. diff --git a/missions/contrib/git_basics/04_third_spell_branch/_treasure-msg.txt b/missions/contrib/git_basics/04_third_spell_branch/_treasure-msg.txt new file mode 100644 index 000000000..72094a5b9 --- /dev/null +++ b/missions/contrib/git_basics/04_third_spell_branch/_treasure-msg.txt @@ -0,0 +1,3 @@ +This file is not required. When it exists, it is displayed when sourcing +the "treasure.sh" file. (If no "treasure.sh" file exists, this file will +be ignored.) diff --git a/missions/contrib/git_basics/04_third_spell_branch/_treasure.sh b/missions/contrib/git_basics/04_third_spell_branch/_treasure.sh new file mode 100644 index 000000000..1fa10ce8e --- /dev/null +++ b/missions/contrib/git_basics/04_third_spell_branch/_treasure.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is sourced on successfull +# completion of the mission and is added to the global configuration. +# It is typically used to "reward" the player with new features like aliases +# and the like. +# If you need this file, rename it to 'treasure.txt' +# +# Note that should the mission be completed in a subshell, aliases or +# environment variables will disappear. +# That typically happens a mission is checked using process redirection, as in +# $ SOMETHING | gsh check +# To mitigate the problem, GameShell will display a message asking the player +# to run +# $ gsh reset +# in that case. diff --git a/missions/contrib/git_basics/04_third_spell_branch/auto.sh b/missions/contrib/git_basics/04_third_spell_branch/auto.sh new file mode 100644 index 000000000..890ffbc36 --- /dev/null +++ b/missions/contrib/git_basics/04_third_spell_branch/auto.sh @@ -0,0 +1,15 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is used to automatically +# validate the mission. It should end with a succesful `gsh check` command. +# It is sometimes possible to "cheat" by using any hidden data in $GSH_TMP, +# but it is better to do it the "intended" way. +# If you write this file, rename it to auto.sh + +cd $GSH_HOME/Castle/Portals/spellbook +cp $GSH_TMP/flame_spell . +git checkout -b flame +git add flame_spell +git commit -m "flame spell added" +gsh check + diff --git a/missions/contrib/git_basics/04_third_spell_branch/check.sh b/missions/contrib/git_basics/04_third_spell_branch/check.sh new file mode 100644 index 000000000..ad50db468 --- /dev/null +++ b/missions/contrib/git_basics/04_third_spell_branch/check.sh @@ -0,0 +1,83 @@ +#!/usr/bin/env sh + +# This file is required. It is sourced when checking the goal of the mission +# has been achieved. +# It should end with a command returning 0 on success, and something else on +# failure. +# It should "unset" any local variable it has created, and any "global +# variable" that were only used for the mission. (The function _mission_check +# is automatically unset.) +# +# It typically looks like + +_mission_check() { + + + expected_name="flame" + spell_name=${expected_name}_spell + + if [ ! -e "$GSH_HOME/Castle/Portals/spellbook" ] + then + echo " spellbook doesn't exist" + return 1 + else + echo " spellbook exists" + fi + + cd $GSH_HOME/Castle/Portals/spellbook/ + + search=$(find -name $spell_name) + if [ $search = "" ] + then + echo " The file $spell_name doesn't exist" + return 1 + else + echo " The file $spell_name exists" + fi + + + LANG=en_GB git status | grep -e "Untracked" + + test=$(echo $?) + + if [ $test -eq 0 ] + then + echo " you should not have untracked file" + return 1 + fi + + branch_created=$(git branch | grep $expected_name) + if [ "$branch_created" = "" ] + then + echo "Branch $expected_name is not available..." + return 1 + fi + + current_branch=$(git branch --show-current) + if [ "$current_branch" != $expected_name ] + then + echo "You are not on the $expected_name branch..." + return 1 + fi + + main_id=$(git rev-parse main) + target_id=$(git rev-parse $expected_name) + if [ "$main_id" = "$target_id" ] + then + echo "You did not commit anything, main and $expected_name branches are pointing on the same commit..." + return 1 + fi + + spell=$(git ls-tree flame $spell_name) + spell2=$(git ls-tree flame Chapter_1/$spell_name) + + if [ "$spell" = "" ] && [ "$spell2" = "" ] + then + echo "Spell $spell_name not in repository, at least not on $expected_name branch..." + return 1 + fi + + return 0 + +} +_mission_check diff --git a/missions/contrib/git_basics/04_third_spell_branch/clean.sh b/missions/contrib/git_basics/04_third_spell_branch/clean.sh new file mode 120000 index 000000000..be2f419f7 --- /dev/null +++ b/missions/contrib/git_basics/04_third_spell_branch/clean.sh @@ -0,0 +1 @@ +../00_needed_files/clean.sh \ No newline at end of file diff --git a/missions/contrib/git_basics/04_third_spell_branch/goal.txt b/missions/contrib/git_basics/04_third_spell_branch/goal.txt new file mode 100644 index 000000000..bdac4ef12 --- /dev/null +++ b/missions/contrib/git_basics/04_third_spell_branch/goal.txt @@ -0,0 +1,22 @@ +Mission goal +============ + +Excellent ! + +Let us do the same process again with the flame spell. This time you are not sure to integrate it directly in the main version of your spellbook, so you will add the spell on a branch called flame. + +Useful commands +=============== + +To create a branch: +git branch BRANCH_NAME [TREE_ISH] +TREE_ISH is optional, by default it is HEAD, but one can put here a commit identifier, a branch name, a tag, ..., anything that refers to a commit + +To start tracking the file FILENAME or add its modification to the staging area: +git add FILENAME + +To create a commit with a COMMIT_MESSAGE as comment for the commit: +git commit -m 'COMMIT_MESSAGE' + +To move HEAD on a branch (and update the working directory accordingly) +git checkout BRANCH_NAME diff --git a/missions/contrib/git_basics/04_third_spell_branch/init.sh b/missions/contrib/git_basics/04_third_spell_branch/init.sh new file mode 100644 index 000000000..7f179b1b5 --- /dev/null +++ b/missions/contrib/git_basics/04_third_spell_branch/init.sh @@ -0,0 +1,33 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced every time the mission is started. +# Since it is sourced every time the mission is restarted, it can generate +# random data to make each run slightly different. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. +# +# Note however that should the mission be initialized in a subshell, those +# environment variables will disappear! That typically happens a mission is +# checked using process redirection, as in +# $ SOMETHING | gsh check +# To mitigate the problem, GameShell will display a message asking the player +# to run +# $ gsh reset +# in that case. +# +# It typically looks like +_mission_init() { + + if [ -f $GSH_TMP/skip_init ] + then + rm $GSH_TMP/skip_init + else + . $GSH_TMP/clone.sh &> /dev/null + git reset --hard origin/moving_spell_into_Chapter_1 &> /dev/null + . $GSH_TMP/remove_init_branches.sh &> /dev/null + . $GSH_TMP/add_remote_origin.sh + fi + +} +_mission_init diff --git a/missions/contrib/git_basics/04_third_spell_branch/static.sh b/missions/contrib/git_basics/04_third_spell_branch/static.sh new file mode 100644 index 000000000..ec01a82da --- /dev/null +++ b/missions/contrib/git_basics/04_third_spell_branch/static.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced once when initialising a GameShell +# game, and whenever the corresponding missions is (re)started. +# It typically creates the parts of the mission that will be available during +# the whole game, like the directory structure. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. diff --git a/missions/contrib/git_basics/04_third_spell_branch/treasure.sh b/missions/contrib/git_basics/04_third_spell_branch/treasure.sh new file mode 100644 index 000000000..3b2f38725 --- /dev/null +++ b/missions/contrib/git_basics/04_third_spell_branch/treasure.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash + +# Couleurs ANSI +RED='\033[0;31m' +ORANGE='\033[38;5;208m' +YELLOW='\033[1;33m' +RESET='\033[0m' + +frames=( +"${RED} . ${RESET}\n\ +${ORANGE} .oOo. ${RESET}\n\ +${YELLOW} .oOOOOOo. ${RESET}\n\ +${RED} .oOOOOOOOOOo. ${RESET}\n\ +${ORANGE} .oOOOOOOOOOOOOOo.${RESET}\n\ +${YELLOW} .oOOOOOOOOOOOOOOOo.${RESET}\n\ +${RED} .oOOOOOOOOOOOOOOOOOo.${RESET}\n\ +${ORANGE} .oOOOOOOOOOOOOOOOo.${RESET}\n\ +${YELLOW} .oOOOOOOOOOOOOOo.${RESET}\n\ +${RED} .oOOOOOOOOOOOo.${RESET}\n\ +${ORANGE} .oOOOOOOOOOo.${RESET}\n\ +${YELLOW} .oOOOOOOOo.${RESET}\n\ +${RED} .oOOOOOo.${RESET}\n\ +${ORANGE} .oOOOo.${RESET}\n\ +${YELLOW} .oOOOo.${RESET}\n\ +${RED} .oOOOo.${RESET}\n\ +${ORANGE} .oOOOo.${RESET}\n\ +${RED} .oOo.${RESET}\n\ +${RED} ${RESET}" +) + +clear +for f in "${frames[@]}"; do + printf "%b\n" "$f" +done + diff --git a/missions/contrib/git_basics/05_fifth_spell/_clean.sh b/missions/contrib/git_basics/05_fifth_spell/_clean.sh new file mode 100644 index 000000000..b3cec70ae --- /dev/null +++ b/missions/contrib/git_basics/05_fifth_spell/_clean.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is used to clean the mission, +# for example on completion, or when restarting it. +# In some rare case, cleaning is different after a successful check. You can +# inspect the variable $GSH_LAST_ACTION, which can take the following values: +# assert, check_false, check_true, exit, goto, hard_reset, reset, skip +# If you need this file, rename it to clean.sh diff --git a/missions/contrib/git_basics/05_fifth_spell/_test.sh b/missions/contrib/git_basics/05_fifth_spell/_test.sh new file mode 100644 index 000000000..c2e0a2678 --- /dev/null +++ b/missions/contrib/git_basics/05_fifth_spell/_test.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced by the command "gsh test" for +# testing during development. +# If you write this file, rename it to 'test.sh' +# +# You can use some special commands +# gsh assert check true +# gsh assert check false +# gsh assert CONDITION +# to check that specific conditions are satisfied. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. diff --git a/missions/contrib/git_basics/05_fifth_spell/_treasure-msg.txt b/missions/contrib/git_basics/05_fifth_spell/_treasure-msg.txt new file mode 100644 index 000000000..72094a5b9 --- /dev/null +++ b/missions/contrib/git_basics/05_fifth_spell/_treasure-msg.txt @@ -0,0 +1,3 @@ +This file is not required. When it exists, it is displayed when sourcing +the "treasure.sh" file. (If no "treasure.sh" file exists, this file will +be ignored.) diff --git a/missions/contrib/git_basics/05_fifth_spell/_treasure.sh b/missions/contrib/git_basics/05_fifth_spell/_treasure.sh new file mode 100644 index 000000000..1fa10ce8e --- /dev/null +++ b/missions/contrib/git_basics/05_fifth_spell/_treasure.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is sourced on successfull +# completion of the mission and is added to the global configuration. +# It is typically used to "reward" the player with new features like aliases +# and the like. +# If you need this file, rename it to 'treasure.txt' +# +# Note that should the mission be completed in a subshell, aliases or +# environment variables will disappear. +# That typically happens a mission is checked using process redirection, as in +# $ SOMETHING | gsh check +# To mitigate the problem, GameShell will display a message asking the player +# to run +# $ gsh reset +# in that case. diff --git a/missions/contrib/git_basics/05_fifth_spell/auto.sh b/missions/contrib/git_basics/05_fifth_spell/auto.sh new file mode 100644 index 000000000..c836d1483 --- /dev/null +++ b/missions/contrib/git_basics/05_fifth_spell/auto.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is used to automatically +# validate the mission. It should end with a succesful `gsh check` command. +# It is sometimes possible to "cheat" by using any hidden data in $GSH_TMP, +# but it is better to do it the "intended" way. +# If you write this file, rename it to auto.sh + +cd $GSH_HOME/Castle/Portals/spellbook +cp $GSH_TMP/cheater/* . +git co -b cheater main +git add cheater_spell +git add amplifier +git ci -m "cheater spell added" + +gsh check + diff --git a/missions/contrib/git_basics/05_fifth_spell/check.sh b/missions/contrib/git_basics/05_fifth_spell/check.sh new file mode 100644 index 000000000..4aee1afd4 --- /dev/null +++ b/missions/contrib/git_basics/05_fifth_spell/check.sh @@ -0,0 +1,109 @@ +#!/usr/bin/env sh + +# This file is required. It is sourced when checking the goal of the mission +# has been achieved. +# It should end with a command returning 0 on success, and something else on +# failure. +# It should "unset" any local variable it has created, and any "global +# variable" that were only used for the mission. (The function _mission_check +# is automatically unset.) +# +# It typically looks like + +_mission_check() { + + + expected_name="cheater" + spell_name=${expected_name}_spell + + if [ ! -e "$GSH_HOME/Castle/Portals/spellbook" ] + then + echo " spellbook doesn't exist" + return 1 + fi + + cd $GSH_HOME/Castle/Portals/spellbook/ + + search=$(find -name $spell_name) + if [ $search = "" ] + then + echo " The file $spell_name doesn't exist" + return 1 + else + echo " The file $spell_name exists" + fi + + search=$(find -name amplifier) + if [ $search = "" ] + then + echo " The file amplifier doesn't exist" + return 1 + else + echo " The file amplifier exists" + fi + + LANG=en_GB git status | grep -e "Untracked" + + test=$(echo $?) + + if [ $test -eq 0 ] + then + echo " you should not have untracked file" + return 1 + fi + + branch_created=$(git branch | grep $expected_name) + if [ "$branch_created" = "" ] + then + echo "Branch $expected_name does not exist..." + return 1 + fi + + current_branch=$(git branch --show-current) + if [ "$current_branch" != $expected_name ] + then + echo "You are not on the $expected_name branch..." + return 1 + fi + + # check if branches are not pointing at the same commit + main_id=$(git rev-parse main) + target_id=$(git rev-parse $expected_name) + if [ "$main_id" = "$target_id" ] + then + echo "You did not commit anything, main and $expected_name branches are pointing on the same commit..." + return 1 + fi + + # check if files are in the repo + spell=$(git ls-tree $expected_name $spell_name) + spell2=$(git ls-tree $expected_name Chapter_1/$spell_name) + + if [ "$spell" = "" ] && [ "$spell2" = "" ] + then + echo "Spell $spell_name not in repository, at least not on $expected_name branch..." + return 1 + fi + + amplifier=$(git ls-tree $expected_name amplifier) + amplifier2=$(git ls-tree $expected_name Chapter_1/amplifier) + if [ "$amplifier" = "" ] && [ "$amplifier2" = "" ] + then + echo "Amplifier not in repository, at least not on $expected_name branch..." + return 1 + fi + + #check if flame branch is in the history of cheater + flame_id=$(git rev-parse flame) + output=$(git log | grep $flame_id) + if [ "$output" != "" ] + then + echo "Flame branch is an ancestor of $expected_name branch but should not. You probably did not start the branch from main..." + return 1 + fi + + + return 0 + +} +_mission_check diff --git a/missions/contrib/git_basics/05_fifth_spell/clean.sh b/missions/contrib/git_basics/05_fifth_spell/clean.sh new file mode 120000 index 000000000..be2f419f7 --- /dev/null +++ b/missions/contrib/git_basics/05_fifth_spell/clean.sh @@ -0,0 +1 @@ +../00_needed_files/clean.sh \ No newline at end of file diff --git a/missions/contrib/git_basics/05_fifth_spell/goal.txt b/missions/contrib/git_basics/05_fifth_spell/goal.txt new file mode 100644 index 000000000..0f027264a --- /dev/null +++ b/missions/contrib/git_basics/05_fifth_spell/goal.txt @@ -0,0 +1,21 @@ +Mission goal +============ + +Good, let us move on with yet another spell, the cheater spell that helps students to increase their marks ! + +Again you are not sure to integrate it directly in the main version of your spellbook, so you will add the spell on a branch called cheater CREATED FROM the main branch. + +Caution: without amplifier, the spell only increases the mark by one, so copy the spell file and the amplifier in your spell book (and not the entire directory). + +Useful commands +=============== + +To create a branch: +git branch BRANCH_NAME [TREE_ISH] +TREE_ISH is optional, by default it is HEAD, but one can put here a commit identifier, a branch name, a tag, ..., anything that refers to a commit + +To start tracking the file FILENAME or add its modification to the staging area: +git add FILENAME + +To create a commit with a COMMIT_MESSAGE as comment for the commit: +git commit -m 'COMMIT_MESSAGE' diff --git a/missions/contrib/git_basics/05_fifth_spell/init.sh b/missions/contrib/git_basics/05_fifth_spell/init.sh new file mode 100644 index 000000000..f8b74d90f --- /dev/null +++ b/missions/contrib/git_basics/05_fifth_spell/init.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced every time the mission is started. +# Since it is sourced every time the mission is restarted, it can generate +# random data to make each run slightly different. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. +# +# Note however that should the mission be initialized in a subshell, those +# environment variables will disappear! That typically happens a mission is +# checked using process redirection, as in +# $ SOMETHING | gsh check +# To mitigate the problem, GameShell will display a message asking the player +# to run +# $ gsh reset +# in that case. +# +# It typically looks like +_mission_init() { + + if [ -f $GSH_TMP/skip_init ] + then + rm $GSH_TMP/skip_init + else + . $GSH_TMP/clone.sh &> /dev/null + git branch flame origin/flame_added &> /dev/null + git checkout flame &> /dev/null + git branch -f main origin/moving_spell_into_Chapter_1 &> /dev/null + . $GSH_TMP/remove_init_branches.sh &> /dev/null + . $GSH_TMP/add_remote_origin.sh + fi + +} +_mission_init diff --git a/missions/contrib/git_basics/05_fifth_spell/static.sh b/missions/contrib/git_basics/05_fifth_spell/static.sh new file mode 100644 index 000000000..ec01a82da --- /dev/null +++ b/missions/contrib/git_basics/05_fifth_spell/static.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced once when initialising a GameShell +# game, and whenever the corresponding missions is (re)started. +# It typically creates the parts of the mission that will be available during +# the whole game, like the directory structure. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. diff --git a/missions/contrib/git_basics/05_fifth_spell/treasure.sh b/missions/contrib/git_basics/05_fifth_spell/treasure.sh new file mode 100644 index 000000000..cdb6b2999 --- /dev/null +++ b/missions/contrib/git_basics/05_fifth_spell/treasure.sh @@ -0,0 +1,100 @@ +#!/bin/bash + +# Initial and final grade +grade=4 +final_grade=15 + +# ANSI color codes +RED="\033[31m" +YELLOW="\033[33m" +GREEN="\033[32m" +RESET="\033[0m" + +# Function to generate a random spark line of given length +spark_line() { + length=$1 + line="" + for i in $(seq 1 $length); do + r=$((RANDOM % 6)) + if [ $r -eq 0 ]; then + line="${line}*" + elif [ $r -eq 1 ]; then + line="${line}+" + elif [ $r -eq 2 ]; then + line="${line}o" + elif [ $r -eq 3 ]; then + line="${line}~" + else + line="${line} " + fi + done + echo "$line" +} + +# Function to get color for grade +grade_color() { + if [ $1 -lt 7 ]; then + echo -e "$RED" + elif [ $1 -le 12 ]; then + echo -e "$YELLOW" + else + echo -e "$GREEN" + fi +} + +# Function to draw the bigger scroll with sparks around the grade +draw_scroll() { + clear + + scroll_width=50 + spark_width=$((scroll_width - 4)) + + echo " _________________________________________________" + echo " / \\" + echo " / Increasing mark \\" + echo " | |" + echo " | |" + + # Sparks above the grade + echo " | $(spark_line $spark_width) |" + + # The grade line with sparks on both sides + side_spark_left=$(spark_line $(( (spark_width-5)/2 )) ) + side_spark_right=$(spark_line $(( (spark_width-5)/2 )) ) + color=$(grade_color $grade) + printf " | %s %b%2d/20%b %s |\n" "$side_spark_left" "$color" "$grade" "$RESET" "$side_spark_right" + + # Sparks below the grade + echo " | $(spark_line $spark_width) |" + + # Extra empty lines for bigger scroll + for i in {1..4}; do + echo " | |" + done + + echo " \\___________________________________________________/" +} + +# Animation: increase the grade +while [ $grade -le $final_grade ]; do + draw_scroll + grade=$((grade + 1)) + sleep 0.3 +done + +# Final display +clear +echo " ______________________________________________" +echo " / \\" +echo " / Increasing mark \\" +echo " | |" +echo " | |" +echo " | |" +echo " | |" +echo " | |" +echo " | |" +final_color=$(grade_color $final_grade) +echo -e " | ${final_color}$final_grade/20${RESET} |" +echo " | |" +echo " \\________________________________________________/" + diff --git a/missions/contrib/git_basics/06_sixth_spell/.auto.sh.swo b/missions/contrib/git_basics/06_sixth_spell/.auto.sh.swo new file mode 100644 index 000000000..e32d39ae9 Binary files /dev/null and b/missions/contrib/git_basics/06_sixth_spell/.auto.sh.swo differ diff --git a/missions/contrib/git_basics/06_sixth_spell/_clean.sh b/missions/contrib/git_basics/06_sixth_spell/_clean.sh new file mode 100644 index 000000000..b3cec70ae --- /dev/null +++ b/missions/contrib/git_basics/06_sixth_spell/_clean.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is used to clean the mission, +# for example on completion, or when restarting it. +# In some rare case, cleaning is different after a successful check. You can +# inspect the variable $GSH_LAST_ACTION, which can take the following values: +# assert, check_false, check_true, exit, goto, hard_reset, reset, skip +# If you need this file, rename it to clean.sh diff --git a/missions/contrib/git_basics/06_sixth_spell/_test.sh b/missions/contrib/git_basics/06_sixth_spell/_test.sh new file mode 100644 index 000000000..c2e0a2678 --- /dev/null +++ b/missions/contrib/git_basics/06_sixth_spell/_test.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced by the command "gsh test" for +# testing during development. +# If you write this file, rename it to 'test.sh' +# +# You can use some special commands +# gsh assert check true +# gsh assert check false +# gsh assert CONDITION +# to check that specific conditions are satisfied. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. diff --git a/missions/contrib/git_basics/06_sixth_spell/_treasure-msg.txt b/missions/contrib/git_basics/06_sixth_spell/_treasure-msg.txt new file mode 100644 index 000000000..72094a5b9 --- /dev/null +++ b/missions/contrib/git_basics/06_sixth_spell/_treasure-msg.txt @@ -0,0 +1,3 @@ +This file is not required. When it exists, it is displayed when sourcing +the "treasure.sh" file. (If no "treasure.sh" file exists, this file will +be ignored.) diff --git a/missions/contrib/git_basics/06_sixth_spell/_treasure.sh b/missions/contrib/git_basics/06_sixth_spell/_treasure.sh new file mode 100644 index 000000000..1fa10ce8e --- /dev/null +++ b/missions/contrib/git_basics/06_sixth_spell/_treasure.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is sourced on successfull +# completion of the mission and is added to the global configuration. +# It is typically used to "reward" the player with new features like aliases +# and the like. +# If you need this file, rename it to 'treasure.txt' +# +# Note that should the mission be completed in a subshell, aliases or +# environment variables will disappear. +# That typically happens a mission is checked using process redirection, as in +# $ SOMETHING | gsh check +# To mitigate the problem, GameShell will display a message asking the player +# to run +# $ gsh reset +# in that case. diff --git a/missions/contrib/git_basics/06_sixth_spell/auto.sh b/missions/contrib/git_basics/06_sixth_spell/auto.sh new file mode 100644 index 000000000..d1cf62c8d --- /dev/null +++ b/missions/contrib/git_basics/06_sixth_spell/auto.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env sh + +# This file is not required. When it exists, it is used to automatically +# validate the mission. It should end with a succesful `gsh check` command. +# It is sometimes possible to "cheat" by using any hidden data in $GSH_TMP, +# but it is better to do it the "intended" way. +# If you write this file, rename it to auto.sh + +cd $GSH_HOME/Castle/Portals/spellbook +git co -b beer main +cp $GSH_TMP/beer/* . +git add beer_spell +git add amplifier +git ci -m "beer spell added" + +gsh check + diff --git a/missions/contrib/git_basics/06_sixth_spell/check.sh b/missions/contrib/git_basics/06_sixth_spell/check.sh new file mode 100644 index 000000000..30894f63b --- /dev/null +++ b/missions/contrib/git_basics/06_sixth_spell/check.sh @@ -0,0 +1,117 @@ +#!/usr/bin/env sh + +# This file is required. It is sourced when checking the goal of the mission +# has been achieved. +# It should end with a command returning 0 on success, and something else on +# failure. +# It should "unset" any local variable it has created, and any "global +# variable" that were only used for the mission. (The function _mission_check +# is automatically unset.) +# +# It typically looks like + +_mission_check() { + + + expected_name="beer" + spell_name=${expected_name}_spell + + if [ ! -e "$GSH_HOME/Castle/Portals/spellbook" ] + then + echo " spellbook doesn't exist" + return 1 + fi + + cd $GSH_HOME/Castle/Portals/spellbook/ + + search=$(find -name $spell_name) + if [ $search = "" ] + then + echo " The file $spell_name doesn't exist" + return 1 + else + echo " The file $spell_name exists" + fi + + search=$(find -name amplifier) + if [ $search = "" ] + then + echo " The file amplifier doesn't exist" + return 1 + else + echo " The file amplifier exists" + fi + + LANG=en_GB git status | grep -e "Untracked" + + test=$(echo $?) + + if [ $test -eq 0 ] + then + echo " you should not have untracked file" + return 1 + fi + + branch_created=$(git branch | grep $expected_name) + if [ "$branch_created" = "" ] + then + echo "Branch $expected_name does not exist..." + return 1 + fi + + current_branch=$(git branch --show-current) + if [ "$current_branch" != $expected_name ] + then + echo "You are not on the $expected_name branch..." + return 1 + fi + + # check if branches are not pointing at the same commit + main_id=$(git rev-parse main) + target_id=$(git rev-parse $expected_name) + if [ "$main_id" = "$target_id" ] + then + echo "You did not commit anything, main and $expected_name branches are pointing on the same commit..." + return 1 + fi + + # check if files are in the repo + spell=$(git ls-tree $expected_name $spell_name) + spell2=$(git ls-tree $expected_name Chapter_1/$spell_name) + + if [ "$spell" = "" ] && [ "$spell2" = "" ] + then + echo "Spell $spell_name not in repository, at least not on $expected_name branch..." + return 1 + fi + + amplifier=$(git ls-tree $expected_name amplifier) + amplifier2=$(git ls-tree $expected_name Chapter_1/amplifier) + if [ "$amplifier" = "" ] && [ "$amplifier2" = "" ] + then + echo "Amplifier not in repository, at least not on $expected_name branch..." + return 1 + fi + + #check if flame or cheater branch are in the history of beer + id=$(git rev-parse flame) + output=$(git log | grep $id) + if [ "$output" != "" ] + then + echo "Flame branch is an ancestor of $expected_name branch but should not. You probably did not start the branch from main..." + return 1 + fi + + id=$(git rev-parse cheater) + output=$(git log | grep $id) + if [ "$output" != "" ] + then + echo "Cheater branch is an ancestor of $expected_name branch but should not. You probably did not start the branch from main..." + return 1 + fi + + + return 0 + +} +_mission_check diff --git a/missions/contrib/git_basics/06_sixth_spell/clean.sh b/missions/contrib/git_basics/06_sixth_spell/clean.sh new file mode 120000 index 000000000..be2f419f7 --- /dev/null +++ b/missions/contrib/git_basics/06_sixth_spell/clean.sh @@ -0,0 +1 @@ +../00_needed_files/clean.sh \ No newline at end of file diff --git a/missions/contrib/git_basics/06_sixth_spell/goal.txt b/missions/contrib/git_basics/06_sixth_spell/goal.txt new file mode 100644 index 000000000..7894abbc4 --- /dev/null +++ b/missions/contrib/git_basics/06_sixth_spell/goal.txt @@ -0,0 +1,21 @@ +Mission goal +============ + +Finally a last spell to be integrated in order to recover from our efforts: a pint of beer ! + +Like previously, you are not sure to integrate it directly in the main version of your spellbook, so you will add the spell on a branch called beer CREATED FROM the main branch. + +Caution: without amplifier, the spell only creates a small beer, to get a pint you need to copy both the spell file and the amplifier in your spell book (and not the entire directory). + +Useful commands +=============== + +To create a branch: +git branch BRANCH_NAME [TREE_ISH] +TREE_ISH is optional, by default it is HEAD, but one can put here a commit identifier, a branch name, a tag, ..., anything that refers to a commit + +To start tracking the file FILENAME or add its modification to the staging area: +git add FILENAME + +To create a commit with a COMMIT_MESSAGE as comment for the commit: +git commit -m 'COMMIT_MESSAGE' diff --git a/missions/contrib/git_basics/06_sixth_spell/init.sh b/missions/contrib/git_basics/06_sixth_spell/init.sh new file mode 100644 index 000000000..b3392ae79 --- /dev/null +++ b/missions/contrib/git_basics/06_sixth_spell/init.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced every time the mission is started. +# Since it is sourced every time the mission is restarted, it can generate +# random data to make each run slightly different. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. +# +# Note however that should the mission be initialized in a subshell, those +# environment variables will disappear! That typically happens a mission is +# checked using process redirection, as in +# $ SOMETHING | gsh check +# To mitigate the problem, GameShell will display a message asking the player +# to run +# $ gsh reset +# in that case. +# +# It typically looks like +_mission_init() { + + if [ -f $GSH_TMP/skip_init ] + then + rm $GSH_TMP/skip_init + else + . $GSH_TMP/clone.sh &> /dev/null + git branch flame origin/flame_added &> /dev/null + git branch cheater origin/cheater_added &> /dev/null + git checkout cheater &> /dev/null + git branch -f main origin/moving_spell_into_Chapter_1 &> /dev/null + . $GSH_TMP/remove_init_branches.sh &> /dev/null + . $GSH_TMP/add_remote_origin.sh + fi + +} +_mission_init diff --git a/missions/contrib/git_basics/06_sixth_spell/static.sh b/missions/contrib/git_basics/06_sixth_spell/static.sh new file mode 100644 index 000000000..ec01a82da --- /dev/null +++ b/missions/contrib/git_basics/06_sixth_spell/static.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env sh + +# This file is not required: it is sourced once when initialising a GameShell +# game, and whenever the corresponding missions is (re)started. +# It typically creates the parts of the mission that will be available during +# the whole game, like the directory structure. +# +# Since it is sourced, it may define environment variables if you really need +# them, but it should "unset" any local variable it has created. diff --git a/missions/contrib/git_basics/06_sixth_spell/treasure.sh b/missions/contrib/git_basics/06_sixth_spell/treasure.sh new file mode 100644 index 000000000..690e1cc8f --- /dev/null +++ b/missions/contrib/git_basics/06_sixth_spell/treasure.sh @@ -0,0 +1,94 @@ +#!/usr/bin/env bash +# beer_bubbles_up.sh — Chope ASCII avec bulles montantes, mousse à gauche et grande anse +# Quitter avec Ctrl+C + +DELAY=0.2 +trap 'tput cnorm; exit' INT +tput civis + +frame=0 + +# Largeur intérieure (zone bière) +INNER_WIDTH=19 +INNER_START=2 +INNER_END=13 + +# Colonnes où les bulles apparaissent +bubble_cols=(3 6 9 12 15 18) + +# Tableau pour la mousse qui coule à gauche +declare -a left_mousse +for ((i=INNER_START;i<=INNER_END;i++)); do + left_mousse[$i]=" " +done + +while [ $frame -lt 16 ] ; do + clear + + # --- Mousse animée sur le dessus --- + foam_patterns=( +" ~~~~~~~~" +" ~~~oOoo~~~" +" ~~OoOo~~" +" ~ooOoOoo~" + ) + echo "${foam_patterns[$((frame % 4))]}" + + # --- Haut de la chope --- + top=" .-----------------. _______" + bottom1=" \\#################/" + bottom2=" '---------------'" + feet=" |||||" + + echo "$top" + + for ((i=INNER_START; i<=INNER_END; i++)); do + # Mousse qui coule sur le côté gauche (descend) + if (( frame % 2 == 0 )); then + for ((line_idx=INNER_END; line_idx>INNER_START; line_idx--)); do + left_mousse[$line_idx]="${left_mousse[$((line_idx-1))]}" + done + left_mousse[$INNER_START]="|" + fi + + # Construire la zone intérieure + middle="" + for ((j=0; j