From 8fbeef957045a9dfbc3b30ec0c1646afdc0cb437 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Fr=C4=85cz?= Date: Sun, 22 Mar 2015 11:49:15 +0100 Subject: [PATCH 01/19] Exercise base --- start.sh | 2 ++ 1 file changed, 2 insertions(+) create mode 100755 start.sh diff --git a/start.sh b/start.sh new file mode 100755 index 0000000..20d602b --- /dev/null +++ b/start.sh @@ -0,0 +1,2 @@ +#!/usr/bin/env bash + From 042b95b5dcb7d34605bc3088c515fd77e4f33f21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Fr=C4=85cz?= Date: Fri, 20 Mar 2015 23:26:06 +0100 Subject: [PATCH 02/19] Git exercises - introduction --- README.md | 47 +++++++++++++++++++++++++++++++++++++++++++++++ configure.sh | 16 ++++++++++++++++ start.sh | 3 +++ 3 files changed, 66 insertions(+) create mode 100755 configure.sh diff --git a/README.md b/README.md index 72fd09b..2f8cb8c 100644 --- a/README.md +++ b/README.md @@ -1 +1,48 @@ # git-exercises + +This repository contains problems that you may encounter in everyday work with Git. Each problem resides in its own +branch which you can checkout and verify your git-skills. In general, all exercises assume that you know basics of Git +(i.e. how to commit a file and what the working and staging area is). + +The `README.md` file always contains an explanation of the problem and the expected repository state that should be +achieved. A special git command `git start` has been prepared for the purpose of preparing your local commit history +and working area for the task. + +In fact, you are currently on `master` branch that contains the first exercise. + +## Prerequisites + + * make sure you can run `.sh` scripts; you get it out of the box in unix systems; on Windows, you can use Git Bash that + is shipped with Windows version of Git + * introduce yourself by executing `git config user.name "Your Name"` and `git config user.email "your@email.com"` + commands in the repo directory after you have cloned it + * execute the `./configure.sh` script; it will add a few git aliases that will ease working with these exercises + (this WILL NOT affect your global Git settings) + +## Exercise - Commit a file + +The first exercise is to push a commit that is created when you run the `git start` command. + +## Verifying results + +When you think you are ready with the exercise, just execute the `git verify` command. It will try to push your changes +to the remote repository and tell you if the provided solution is correct. + +There may be situation when the `git verify` tells you that the exercise name is invalid. This means that you have +probably changed the branch name during work. In such cases, you need to tell what exercise you are currently trying to +solve with `git verify exercise-name` command. + +## How to find the next exercise? + +When you pass the exercise successfully, output of `git verify` command will tell you the next exercise name as well as +the command you need to execute in order to be in the right place (that is `git start exercise-name`). + +You can also jump to any of the exercises at any moment. To display list of them, execute the `git exercises` command. + +## How to reset exercise and start from the beginning? + +Each time you got lost you can discard all changes you made in an exercise and start from scratch with executing +`git start` command without any arguments. + +This will work only if you are on an exercise branch. If not, tell git which task you want to start with by executing +`git start exercise-name`. diff --git a/configure.sh b/configure.sh new file mode 100755 index 0000000..31c11ec --- /dev/null +++ b/configure.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +# Configure "git start" local alias for starting the exercise of user's choice of restarting the current one. +git config alias.start "! f() { currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; git show origin/\$exercise:start.sh >/dev/null 2>&1 && git checkout -f \$exercise >/dev/null 2>&1 && git reset --hard origin/\$exercise >/dev/null 2>&1 && git clean -fdx >/dev/null 2>&1 && echo \"Preparing the exercise environment, hold on...\" && ./start.sh >/dev/null 2>&1 && echo \"Exercise \$exercise started! Read the README.md for instructions.\" || echo \"Invalid exercise: \$exercise\"; }; f" + +# Add "git verify" local alias for submitting exercises solutions. +git config alias.verify "! f() { currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; git show origin/\$exercise:start.sh >/dev/null 2>&1 && echo \"Verifying the \$exercise exercise. Hold on...\" && git push -f origin HEAD:\$exercise 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | grep -v \"\\*\\*\" || echo \"Invalid exercise: \$exercise\"; }; f" + +# Add "git exercises" alias that shows list of available exercises +git config alias.exercises "! echo \"Available exercises (alphabetically, use git start to switch): \" && git branch -r | grep origin | grep -v /HEAD | grep -v verifications | sed 's/origin\///g'" + +# Make sure you have a "current" push strategy set; this will allow you to push only current exercise with simple git +# push command instead of pushing all matching branches (default in Git < 2.0) +git config push.default current + +echo "OK" diff --git a/start.sh b/start.sh index 20d602b..643a64d 100755 --- a/start.sh +++ b/start.sh @@ -1,2 +1,5 @@ #!/usr/bin/env bash +echo 'test' > 'test.txt' +git add test.txt +git commit -m "This is first exercise commit." From 22f1fd9fb5f0894a70df673d850731ccb5822155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Fr=C4=85cz?= Date: Sat, 27 Feb 2016 00:22:57 +0100 Subject: [PATCH 03/19] Remove unnecessary info from master --- README.md | 46 +--------------------------------------------- 1 file changed, 1 insertion(+), 45 deletions(-) diff --git a/README.md b/README.md index 2f8cb8c..7fe00c6 100644 --- a/README.md +++ b/README.md @@ -1,48 +1,4 @@ -# git-exercises - -This repository contains problems that you may encounter in everyday work with Git. Each problem resides in its own -branch which you can checkout and verify your git-skills. In general, all exercises assume that you know basics of Git -(i.e. how to commit a file and what the working and staging area is). - -The `README.md` file always contains an explanation of the problem and the expected repository state that should be -achieved. A special git command `git start` has been prepared for the purpose of preparing your local commit history -and working area for the task. - -In fact, you are currently on `master` branch that contains the first exercise. - -## Prerequisites - - * make sure you can run `.sh` scripts; you get it out of the box in unix systems; on Windows, you can use Git Bash that - is shipped with Windows version of Git - * introduce yourself by executing `git config user.name "Your Name"` and `git config user.email "your@email.com"` - commands in the repo directory after you have cloned it - * execute the `./configure.sh` script; it will add a few git aliases that will ease working with these exercises - (this WILL NOT affect your global Git settings) - -## Exercise - Commit a file +## Push a commit you have made The first exercise is to push a commit that is created when you run the `git start` command. -## Verifying results - -When you think you are ready with the exercise, just execute the `git verify` command. It will try to push your changes -to the remote repository and tell you if the provided solution is correct. - -There may be situation when the `git verify` tells you that the exercise name is invalid. This means that you have -probably changed the branch name during work. In such cases, you need to tell what exercise you are currently trying to -solve with `git verify exercise-name` command. - -## How to find the next exercise? - -When you pass the exercise successfully, output of `git verify` command will tell you the next exercise name as well as -the command you need to execute in order to be in the right place (that is `git start exercise-name`). - -You can also jump to any of the exercises at any moment. To display list of them, execute the `git exercises` command. - -## How to reset exercise and start from the beginning? - -Each time you got lost you can discard all changes you made in an exercise and start from scratch with executing -`git start` command without any arguments. - -This will work only if you are on an exercise branch. If not, tell git which task you want to start with by executing -`git start exercise-name`. From a13b3774a9e64d800e8e68ce1980c6b9cae6ec65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Fr=C4=85cz?= Date: Sat, 27 Feb 2016 13:45:56 +0100 Subject: [PATCH 04/19] Sed-out remote: prefix from git response --- configure.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.sh b/configure.sh index 31c11ec..32d2734 100755 --- a/configure.sh +++ b/configure.sh @@ -4,7 +4,7 @@ git config alias.start "! f() { currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; git show origin/\$exercise:start.sh >/dev/null 2>&1 && git checkout -f \$exercise >/dev/null 2>&1 && git reset --hard origin/\$exercise >/dev/null 2>&1 && git clean -fdx >/dev/null 2>&1 && echo \"Preparing the exercise environment, hold on...\" && ./start.sh >/dev/null 2>&1 && echo \"Exercise \$exercise started! Read the README.md for instructions.\" || echo \"Invalid exercise: \$exercise\"; }; f" # Add "git verify" local alias for submitting exercises solutions. -git config alias.verify "! f() { currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; git show origin/\$exercise:start.sh >/dev/null 2>&1 && echo \"Verifying the \$exercise exercise. Hold on...\" && git push -f origin HEAD:\$exercise 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | grep -v \"\\*\\*\" || echo \"Invalid exercise: \$exercise\"; }; f" +git config alias.verify "! f() { currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; git show origin/\$exercise:start.sh >/dev/null 2>&1 && echo \"Verifying the \$exercise exercise. Hold on...\" && git push -f origin HEAD:\$exercise 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | grep -v \"\\*\\*\" | sed 's/remote: //g' || echo \"Invalid exercise: \$exercise\"; }; f" # Add "git exercises" alias that shows list of available exercises git config alias.exercises "! echo \"Available exercises (alphabetically, use git start to switch): \" && git branch -r | grep origin | grep -v /HEAD | grep -v verifications | sed 's/origin\///g'" From 2dc0c83d33260d3ff3a1ac3af20fabd1b709cfd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Fr=C4=85cz?= Date: Sat, 27 Feb 2016 17:47:40 +0100 Subject: [PATCH 05/19] New exercises alias --- configure.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.sh b/configure.sh index 32d2734..72c209f 100755 --- a/configure.sh +++ b/configure.sh @@ -7,7 +7,7 @@ git config alias.start "! f() { currentBranch=\$(git rev-parse --abbrev-ref HEAD git config alias.verify "! f() { currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; git show origin/\$exercise:start.sh >/dev/null 2>&1 && echo \"Verifying the \$exercise exercise. Hold on...\" && git push -f origin HEAD:\$exercise 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | grep -v \"\\*\\*\" | sed 's/remote: //g' || echo \"Invalid exercise: \$exercise\"; }; f" # Add "git exercises" alias that shows list of available exercises -git config alias.exercises "! echo \"Available exercises (alphabetically, use git start to switch): \" && git branch -r | grep origin | grep -v /HEAD | grep -v verifications | sed 's/origin\///g'" +git config alias.exercises "! git push origin HEAD:exercises 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | grep -v '\\*\\*' | sed 's/remote: //g'" # Make sure you have a "current" push strategy set; this will allow you to push only current exercise with simple git # push command instead of pushing all matching branches (default in Git < 2.0) From 1bc64249433a7bfc4449f36ac8e17b39e9734e5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Fr=C4=85cz?= Date: Sun, 28 Feb 2016 21:51:39 +0100 Subject: [PATCH 06/19] Enhance git verify alias --- configure.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.sh b/configure.sh index 72c209f..ca7e0f0 100755 --- a/configure.sh +++ b/configure.sh @@ -4,7 +4,7 @@ git config alias.start "! f() { currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; git show origin/\$exercise:start.sh >/dev/null 2>&1 && git checkout -f \$exercise >/dev/null 2>&1 && git reset --hard origin/\$exercise >/dev/null 2>&1 && git clean -fdx >/dev/null 2>&1 && echo \"Preparing the exercise environment, hold on...\" && ./start.sh >/dev/null 2>&1 && echo \"Exercise \$exercise started! Read the README.md for instructions.\" || echo \"Invalid exercise: \$exercise\"; }; f" # Add "git verify" local alias for submitting exercises solutions. -git config alias.verify "! f() { currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; git show origin/\$exercise:start.sh >/dev/null 2>&1 && echo \"Verifying the \$exercise exercise. Hold on...\" && git push -f origin HEAD:\$exercise 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | grep -v \"\\*\\*\" | sed 's/remote: //g' || echo \"Invalid exercise: \$exercise\"; }; f" +git config alias.verify "! f() { currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; if git show origin/\$exercise:start.sh >/dev/null 2>&1 ; then if git status | grep ahead >/dev/null 2>&1 ; then if echo \"Verifying the \$exercise exercise. Hold on...\" && git push -f origin HEAD:\$exercise 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | sed 's/remote: //g' | grep -v \"\\*\\*\" ; then : ; else echo 'Solution could not be verified - push failed.' && echo 'Do you have an internet connection?'; fi else echo \"You haven't made any progress on exercise \$exercise.\" && echo 'Did you forget to commit your changes?'; fi else echo \"Invalid exercise: \$exercise\"; fi }; f" # Add "git exercises" alias that shows list of available exercises git config alias.exercises "! git push origin HEAD:exercises 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | grep -v '\\*\\*' | sed 's/remote: //g'" From 23aeacdf6f99fe7ab1a48e365c622f2785dbe7ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Fr=C4=85cz?= Date: Sun, 28 Feb 2016 22:13:24 +0100 Subject: [PATCH 07/19] Enhance git start command --- configure.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.sh b/configure.sh index ca7e0f0..8576b29 100755 --- a/configure.sh +++ b/configure.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # Configure "git start" local alias for starting the exercise of user's choice of restarting the current one. -git config alias.start "! f() { currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; git show origin/\$exercise:start.sh >/dev/null 2>&1 && git checkout -f \$exercise >/dev/null 2>&1 && git reset --hard origin/\$exercise >/dev/null 2>&1 && git clean -fdx >/dev/null 2>&1 && echo \"Preparing the exercise environment, hold on...\" && ./start.sh >/dev/null 2>&1 && echo \"Exercise \$exercise started! Read the README.md for instructions.\" || echo \"Invalid exercise: \$exercise\"; }; f" +git config alias.start "! f() { currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; if git show origin/\$exercise:start.sh >/dev/null 2>&1 ; then if git checkout -f \$exercise >/dev/null 2>&1 && git reset --hard origin/\$exercise >/dev/null 2>&1 && git clean -fdx >/dev/null ; then echo \"Preparing the exercise environment, hold on...\" && ./start.sh >/dev/null 2>&1 && echo \"Exercise \$exercise started!\" && echo 'Read the README.md for instructions or view them in browser:' && echo \"http://gitexercises.fracz.com/e/\$exercise\" ; else echo 'Could not clean the working directory.' && echo 'Make sure that none of the files inside the working directory' && echo 'is used by another process and run git start again.'; fi else echo \"Invalid exercise: \$exercise\"; fi }; f" # Add "git verify" local alias for submitting exercises solutions. git config alias.verify "! f() { currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; if git show origin/\$exercise:start.sh >/dev/null 2>&1 ; then if git status | grep ahead >/dev/null 2>&1 ; then if echo \"Verifying the \$exercise exercise. Hold on...\" && git push -f origin HEAD:\$exercise 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | sed 's/remote: //g' | grep -v \"\\*\\*\" ; then : ; else echo 'Solution could not be verified - push failed.' && echo 'Do you have an internet connection?'; fi else echo \"You haven't made any progress on exercise \$exercise.\" && echo 'Did you forget to commit your changes?'; fi else echo \"Invalid exercise: \$exercise\"; fi }; f" From a1f208bb4e5a0173157aaaea0157664a260944c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Fr=C4=85cz?= Date: Mon, 29 Feb 2016 09:18:50 +0100 Subject: [PATCH 08/19] Allow to git verify in detached HEAD --- configure.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.sh b/configure.sh index 8576b29..7d40016 100755 --- a/configure.sh +++ b/configure.sh @@ -4,7 +4,7 @@ git config alias.start "! f() { currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; if git show origin/\$exercise:start.sh >/dev/null 2>&1 ; then if git checkout -f \$exercise >/dev/null 2>&1 && git reset --hard origin/\$exercise >/dev/null 2>&1 && git clean -fdx >/dev/null ; then echo \"Preparing the exercise environment, hold on...\" && ./start.sh >/dev/null 2>&1 && echo \"Exercise \$exercise started!\" && echo 'Read the README.md for instructions or view them in browser:' && echo \"http://gitexercises.fracz.com/e/\$exercise\" ; else echo 'Could not clean the working directory.' && echo 'Make sure that none of the files inside the working directory' && echo 'is used by another process and run git start again.'; fi else echo \"Invalid exercise: \$exercise\"; fi }; f" # Add "git verify" local alias for submitting exercises solutions. -git config alias.verify "! f() { currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; if git show origin/\$exercise:start.sh >/dev/null 2>&1 ; then if git status | grep ahead >/dev/null 2>&1 ; then if echo \"Verifying the \$exercise exercise. Hold on...\" && git push -f origin HEAD:\$exercise 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | sed 's/remote: //g' | grep -v \"\\*\\*\" ; then : ; else echo 'Solution could not be verified - push failed.' && echo 'Do you have an internet connection?'; fi else echo \"You haven't made any progress on exercise \$exercise.\" && echo 'Did you forget to commit your changes?'; fi else echo \"Invalid exercise: \$exercise\"; fi }; f" +git config alias.verify "! f() { currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; if git show origin/\$exercise:start.sh >/dev/null 2>&1 ; then if git status | grep -E 'ahead|detached' >/dev/null 2>&1 ; then if echo \"Verifying the \$exercise exercise. Hold on...\" && git push -f origin HEAD:\$exercise 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | sed 's/remote: //g' | grep -v \"\\*\\*\" ; then : ; else echo 'Solution could not be verified - push failed.' && echo 'Do you have an internet connection?'; fi else echo \"You haven't made any progress on exercise \$exercise.\" && echo 'Did you forget to commit your changes?'; fi else echo \"Invalid exercise: \$exercise\"; fi }; f" # Add "git exercises" alias that shows list of available exercises git config alias.exercises "! git push origin HEAD:exercises 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | grep -v '\\*\\*' | sed 's/remote: //g'" From 257aa3396b50bb245f3af0dee4c718c09f7b75fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Fr=C4=85cz?= Date: Mon, 29 Feb 2016 09:38:15 +0100 Subject: [PATCH 09/19] More info in detached HEAD --- configure.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/configure.sh b/configure.sh index 7d40016..09a18bf 100755 --- a/configure.sh +++ b/configure.sh @@ -1,12 +1,12 @@ #!/usr/bin/env bash -# Configure "git start" local alias for starting the exercise of user's choice of restarting the current one. -git config alias.start "! f() { currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; if git show origin/\$exercise:start.sh >/dev/null 2>&1 ; then if git checkout -f \$exercise >/dev/null 2>&1 && git reset --hard origin/\$exercise >/dev/null 2>&1 && git clean -fdx >/dev/null ; then echo \"Preparing the exercise environment, hold on...\" && ./start.sh >/dev/null 2>&1 && echo \"Exercise \$exercise started!\" && echo 'Read the README.md for instructions or view them in browser:' && echo \"http://gitexercises.fracz.com/e/\$exercise\" ; else echo 'Could not clean the working directory.' && echo 'Make sure that none of the files inside the working directory' && echo 'is used by another process and run git start again.'; fi else echo \"Invalid exercise: \$exercise\"; fi }; f" +# Configure "git start" local alias for starting the exercise of user's choice and restarting the current one. +git config alias.start "! f() { currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; if [ \$exercise != HEAD ]; then if git show origin/\$exercise:start.sh >/dev/null 2>&1 ; then if git checkout -f \$exercise >/dev/null 2>&1 && git reset --hard origin/\$exercise >/dev/null 2>&1 && git clean -fdx >/dev/null ; then echo \"Preparing the exercise environment, hold on...\" && ./start.sh >/dev/null 2>&1 && echo \"Exercise \$exercise started!\" && echo 'Read the README.md for instructions or view them in browser:' && echo \"http://gitexercises.fracz.com/e/\$exercise\" ; else echo 'Could not clean the working directory.' && echo 'Make sure that none of the files inside the working directory' && echo 'is used by another process and run git start again.'; fi else echo \"Invalid exercise: \$exercise\"; fi else echo 'You need to use git start in detached HEAD'; fi }; f" # Add "git verify" local alias for submitting exercises solutions. -git config alias.verify "! f() { currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; if git show origin/\$exercise:start.sh >/dev/null 2>&1 ; then if git status | grep -E 'ahead|detached' >/dev/null 2>&1 ; then if echo \"Verifying the \$exercise exercise. Hold on...\" && git push -f origin HEAD:\$exercise 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | sed 's/remote: //g' | grep -v \"\\*\\*\" ; then : ; else echo 'Solution could not be verified - push failed.' && echo 'Do you have an internet connection?'; fi else echo \"You haven't made any progress on exercise \$exercise.\" && echo 'Did you forget to commit your changes?'; fi else echo \"Invalid exercise: \$exercise\"; fi }; f" +git config alias.verify "! f() { currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; if [ \$exercise != HEAD ]; then if git show origin/\$exercise:start.sh >/dev/null 2>&1 ; then if git status | grep -E 'ahead|detached' >/dev/null 2>&1 ; then if echo \"Verifying the \$exercise exercise. Hold on...\" && git push -f origin HEAD:\$exercise 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | sed 's/remote: //g' | grep -v \"\\*\\*\" ; then : ; else echo 'Solution could not be verified - push failed.' && echo 'Do you have an internet connection?'; fi else echo \"You haven't made any progress on exercise \$exercise.\" && echo 'Did you forget to commit your changes?'; fi else echo \"Invalid exercise: \$exercise\"; fi else echo 'You need to use git verify in detached HEAD'; fi }; f" -# Add "git exercises" alias that shows list of available exercises +# Add "git exercises" alias that shows list of available exercises. git config alias.exercises "! git push origin HEAD:exercises 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | grep -v '\\*\\*' | sed 's/remote: //g'" # Make sure you have a "current" push strategy set; this will allow you to push only current exercise with simple git From 83880e4b1865cb79a3c6a9e103a824ab27d0549b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Fr=C4=85cz?= Date: Sun, 6 Mar 2016 22:53:36 +0100 Subject: [PATCH 10/19] More info on git start when ./start.sh fails --- configure.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.sh b/configure.sh index 09a18bf..10d2a56 100755 --- a/configure.sh +++ b/configure.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # Configure "git start" local alias for starting the exercise of user's choice and restarting the current one. -git config alias.start "! f() { currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; if [ \$exercise != HEAD ]; then if git show origin/\$exercise:start.sh >/dev/null 2>&1 ; then if git checkout -f \$exercise >/dev/null 2>&1 && git reset --hard origin/\$exercise >/dev/null 2>&1 && git clean -fdx >/dev/null ; then echo \"Preparing the exercise environment, hold on...\" && ./start.sh >/dev/null 2>&1 && echo \"Exercise \$exercise started!\" && echo 'Read the README.md for instructions or view them in browser:' && echo \"http://gitexercises.fracz.com/e/\$exercise\" ; else echo 'Could not clean the working directory.' && echo 'Make sure that none of the files inside the working directory' && echo 'is used by another process and run git start again.'; fi else echo \"Invalid exercise: \$exercise\"; fi else echo 'You need to use git start in detached HEAD'; fi }; f" +git config alias.start "! f() { currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; if [ \$exercise != HEAD ]; then if git show origin/\$exercise:start.sh >/dev/null 2>&1 ; then if git checkout -f \$exercise >/dev/null 2>&1 && git reset --hard origin/\$exercise >/dev/null 2>&1 && git clean -fdx >/dev/null ; then if echo \"Preparing the exercise environment, hold on...\" && ./start.sh >/dev/null 2>&1; then echo \"Exercise \$exercise started!\" && echo 'Read the README.md for instructions or view them in browser:' && echo \"http://gitexercises.fracz.com/e/\$exercise\" ; else echo 'Could not execute the start script.' && echo 'Try running the ./start.sh script yourself.' ; fi else echo 'Could not clean the working directory.' && echo 'Make sure that none of the files inside the working directory' && echo 'is used by another process and run git start again.'; fi else echo \"Invalid exercise: \$exercise\"; fi else echo 'You need to use git start in detached HEAD'; fi }; f" # Add "git verify" local alias for submitting exercises solutions. git config alias.verify "! f() { currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; if [ \$exercise != HEAD ]; then if git show origin/\$exercise:start.sh >/dev/null 2>&1 ; then if git status | grep -E 'ahead|detached' >/dev/null 2>&1 ; then if echo \"Verifying the \$exercise exercise. Hold on...\" && git push -f origin HEAD:\$exercise 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | sed 's/remote: //g' | grep -v \"\\*\\*\" ; then : ; else echo 'Solution could not be verified - push failed.' && echo 'Do you have an internet connection?'; fi else echo \"You haven't made any progress on exercise \$exercise.\" && echo 'Did you forget to commit your changes?'; fi else echo \"Invalid exercise: \$exercise\"; fi else echo 'You need to use git verify in detached HEAD'; fi }; f" From 439b4229575c0b5e63c1c17724a35a54dd02805c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Fr=C4=85cz?= Date: Mon, 14 Mar 2016 21:00:04 +0100 Subject: [PATCH 11/19] Add git start next command --- configure.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.sh b/configure.sh index 10d2a56..bf31d80 100755 --- a/configure.sh +++ b/configure.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # Configure "git start" local alias for starting the exercise of user's choice and restarting the current one. -git config alias.start "! f() { currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; if [ \$exercise != HEAD ]; then if git show origin/\$exercise:start.sh >/dev/null 2>&1 ; then if git checkout -f \$exercise >/dev/null 2>&1 && git reset --hard origin/\$exercise >/dev/null 2>&1 && git clean -fdx >/dev/null ; then if echo \"Preparing the exercise environment, hold on...\" && ./start.sh >/dev/null 2>&1; then echo \"Exercise \$exercise started!\" && echo 'Read the README.md for instructions or view them in browser:' && echo \"http://gitexercises.fracz.com/e/\$exercise\" ; else echo 'Could not execute the start script.' && echo 'Try running the ./start.sh script yourself.' ; fi else echo 'Could not clean the working directory.' && echo 'Make sure that none of the files inside the working directory' && echo 'is used by another process and run git start again.'; fi else echo \"Invalid exercise: \$exercise\"; fi else echo 'You need to use git start in detached HEAD'; fi }; f" +git config alias.start "! f() { currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; if [ \$exercise != HEAD ]; then if [ \$exercise != next ]; then if git show origin/\$exercise:start.sh >/dev/null 2>&1 ; then if git checkout -f \$exercise >/dev/null 2>&1 && git reset --hard origin/\$exercise >/dev/null 2>&1 && git clean -fdx >/dev/null ; then if echo \"Preparing the exercise environment, hold on...\" && ./start.sh >/dev/null 2>&1; then echo \"Exercise \$exercise started!\" && echo 'Read the README.md for instructions or view them in browser:' && echo \"http://gitexercises.fracz.com/e/\$exercise\" ; else echo 'Could not execute the start script.' && echo 'Try running the ./start.sh script yourself.' ; fi else echo 'Could not clean the working directory.' && echo 'Make sure that none of the files inside the working directory' && echo 'is used by another process and run git start again.'; fi else echo \"Invalid exercise: \$exercise\" && false; fi else git push origin HEAD:next-exercise 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | grep -v '\\*\\*' | sed 's/remote: //g' | xargs git start | grep -v Invalid || echo 'You have passed all exercises!'; fi else echo 'You need to use git start in detached HEAD'; fi }; f" # Add "git verify" local alias for submitting exercises solutions. git config alias.verify "! f() { currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; if [ \$exercise != HEAD ]; then if git show origin/\$exercise:start.sh >/dev/null 2>&1 ; then if git status | grep -E 'ahead|detached' >/dev/null 2>&1 ; then if echo \"Verifying the \$exercise exercise. Hold on...\" && git push -f origin HEAD:\$exercise 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | sed 's/remote: //g' | grep -v \"\\*\\*\" ; then : ; else echo 'Solution could not be verified - push failed.' && echo 'Do you have an internet connection?'; fi else echo \"You haven't made any progress on exercise \$exercise.\" && echo 'Did you forget to commit your changes?'; fi else echo \"Invalid exercise: \$exercise\"; fi else echo 'You need to use git verify in detached HEAD'; fi }; f" From a3ed55d2740234bc1c81b210a0595ea5ed473c9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Fr=C4=85cz?= Date: Wed, 20 Mar 2019 21:50:38 +0100 Subject: [PATCH 12/19] Clear instruction to start with git verify --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 7fe00c6..359bca4 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,5 @@ The first exercise is to push a commit that is created when you run the `git start` command. +Just try `git verify` after you have initialized the exercises and be proud of passing the first one :-) + From 4252cf9a9d7ebda97b59f5e8619be6bb805d6d2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Fr=C4=85cz?= Date: Thu, 5 Mar 2020 23:47:46 +0100 Subject: [PATCH 13/19] Enhance git verify alias (do not fail if on not-tracked branch) --- configure.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.sh b/configure.sh index bf31d80..7027e19 100755 --- a/configure.sh +++ b/configure.sh @@ -4,7 +4,7 @@ git config alias.start "! f() { currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; if [ \$exercise != HEAD ]; then if [ \$exercise != next ]; then if git show origin/\$exercise:start.sh >/dev/null 2>&1 ; then if git checkout -f \$exercise >/dev/null 2>&1 && git reset --hard origin/\$exercise >/dev/null 2>&1 && git clean -fdx >/dev/null ; then if echo \"Preparing the exercise environment, hold on...\" && ./start.sh >/dev/null 2>&1; then echo \"Exercise \$exercise started!\" && echo 'Read the README.md for instructions or view them in browser:' && echo \"http://gitexercises.fracz.com/e/\$exercise\" ; else echo 'Could not execute the start script.' && echo 'Try running the ./start.sh script yourself.' ; fi else echo 'Could not clean the working directory.' && echo 'Make sure that none of the files inside the working directory' && echo 'is used by another process and run git start again.'; fi else echo \"Invalid exercise: \$exercise\" && false; fi else git push origin HEAD:next-exercise 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | grep -v '\\*\\*' | sed 's/remote: //g' | xargs git start | grep -v Invalid || echo 'You have passed all exercises!'; fi else echo 'You need to use git start in detached HEAD'; fi }; f" # Add "git verify" local alias for submitting exercises solutions. -git config alias.verify "! f() { currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; if [ \$exercise != HEAD ]; then if git show origin/\$exercise:start.sh >/dev/null 2>&1 ; then if git status | grep -E 'ahead|detached' >/dev/null 2>&1 ; then if echo \"Verifying the \$exercise exercise. Hold on...\" && git push -f origin HEAD:\$exercise 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | sed 's/remote: //g' | grep -v \"\\*\\*\" ; then : ; else echo 'Solution could not be verified - push failed.' && echo 'Do you have an internet connection?'; fi else echo \"You haven't made any progress on exercise \$exercise.\" && echo 'Did you forget to commit your changes?'; fi else echo \"Invalid exercise: \$exercise\"; fi else echo 'You need to use git verify in detached HEAD'; fi }; f" +git config alias.verify "! f() { currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; if [ \$exercise != HEAD ]; then if git show origin/\$exercise:start.sh >/dev/null 2>&1 ; then if ! git status | grep 'up-to-date' >/dev/null 2>&1 ; then if echo \"Verifying the \$exercise exercise. Hold on...\" && git push -f origin HEAD:\$exercise 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | sed 's/remote: //g' | grep -v \"\\*\\*\" ; then : ; else echo 'Solution could not be verified - push failed.' && echo 'Do you have an internet connection?'; fi else echo \"You haven't made any progress on exercise \$exercise.\" && echo 'Did you forget to commit your changes?'; fi else echo \"Invalid exercise: \$exercise\"; fi else echo 'You need to use git verify in detached HEAD'; fi }; f" # Add "git exercises" alias that shows list of available exercises. git config alias.exercises "! git push origin HEAD:exercises 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | grep -v '\\*\\*' | sed 's/remote: //g'" From 47d5549b6f14accdeec561b902274bf8543edcca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Fr=C4=85cz?= Date: Thu, 5 Mar 2020 23:47:54 +0100 Subject: [PATCH 14/19] Fix git start next command (always check from master) --- configure.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.sh b/configure.sh index 7027e19..6f6ab9f 100755 --- a/configure.sh +++ b/configure.sh @@ -1,13 +1,13 @@ #!/usr/bin/env bash # Configure "git start" local alias for starting the exercise of user's choice and restarting the current one. -git config alias.start "! f() { currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; if [ \$exercise != HEAD ]; then if [ \$exercise != next ]; then if git show origin/\$exercise:start.sh >/dev/null 2>&1 ; then if git checkout -f \$exercise >/dev/null 2>&1 && git reset --hard origin/\$exercise >/dev/null 2>&1 && git clean -fdx >/dev/null ; then if echo \"Preparing the exercise environment, hold on...\" && ./start.sh >/dev/null 2>&1; then echo \"Exercise \$exercise started!\" && echo 'Read the README.md for instructions or view them in browser:' && echo \"http://gitexercises.fracz.com/e/\$exercise\" ; else echo 'Could not execute the start script.' && echo 'Try running the ./start.sh script yourself.' ; fi else echo 'Could not clean the working directory.' && echo 'Make sure that none of the files inside the working directory' && echo 'is used by another process and run git start again.'; fi else echo \"Invalid exercise: \$exercise\" && false; fi else git push origin HEAD:next-exercise 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | grep -v '\\*\\*' | sed 's/remote: //g' | xargs git start | grep -v Invalid || echo 'You have passed all exercises!'; fi else echo 'You need to use git start in detached HEAD'; fi }; f" +git config alias.start "! f() { currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; if [ \$exercise != HEAD ]; then if [ \$exercise != next ]; then if git show origin/\$exercise:start.sh >/dev/null 2>&1 ; then if git checkout -f \$exercise >/dev/null 2>&1 && git reset --hard origin/\$exercise >/dev/null 2>&1 && git clean -fdx >/dev/null ; then if echo \"Preparing the exercise environment, hold on...\" && ./start.sh >/dev/null 2>&1; then echo \"Exercise \$exercise started!\" && echo 'Read the README.md for instructions or view them in browser:' && echo \"http://gitexercises.fracz.com/e/\$exercise\" ; else echo 'Could not execute the start script.' && echo 'Try running the ./start.sh script yourself.' ; fi else echo 'Could not clean the working directory.' && echo 'Make sure that none of the files inside the working directory' && echo 'is used by another process and run git start again.'; fi else echo \"Invalid exercise: \$exercise\" && false; fi else git push origin master:next-exercise 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | grep -v '\\*\\*' | sed 's/remote: //g' | xargs git start | grep -v Invalid || echo 'You have passed all exercises!'; fi else echo 'You need to use git start in detached HEAD'; fi }; f" # Add "git verify" local alias for submitting exercises solutions. git config alias.verify "! f() { currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; if [ \$exercise != HEAD ]; then if git show origin/\$exercise:start.sh >/dev/null 2>&1 ; then if ! git status | grep 'up-to-date' >/dev/null 2>&1 ; then if echo \"Verifying the \$exercise exercise. Hold on...\" && git push -f origin HEAD:\$exercise 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | sed 's/remote: //g' | grep -v \"\\*\\*\" ; then : ; else echo 'Solution could not be verified - push failed.' && echo 'Do you have an internet connection?'; fi else echo \"You haven't made any progress on exercise \$exercise.\" && echo 'Did you forget to commit your changes?'; fi else echo \"Invalid exercise: \$exercise\"; fi else echo 'You need to use git verify in detached HEAD'; fi }; f" # Add "git exercises" alias that shows list of available exercises. -git config alias.exercises "! git push origin HEAD:exercises 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | grep -v '\\*\\*' | sed 's/remote: //g'" +git config alias.exercises "! git push origin master:exercises 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | grep -v '\\*\\*' | sed 's/remote: //g'" # Make sure you have a "current" push strategy set; this will allow you to push only current exercise with simple git # push command instead of pushing all matching branches (default in Git < 2.0) From 650fd637284a016a5d9e8279afc2955efa4152f5 Mon Sep 17 00:00:00 2001 From: Egor Suvorov Date: Sun, 17 Nov 2019 12:41:40 +0300 Subject: [PATCH 15/19] Make configure.sh work with i18n git by requiring POSIX locale. --- configure.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure.sh b/configure.sh index 6f6ab9f..4a2495f 100755 --- a/configure.sh +++ b/configure.sh @@ -1,10 +1,10 @@ #!/usr/bin/env bash # Configure "git start" local alias for starting the exercise of user's choice and restarting the current one. -git config alias.start "! f() { currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; if [ \$exercise != HEAD ]; then if [ \$exercise != next ]; then if git show origin/\$exercise:start.sh >/dev/null 2>&1 ; then if git checkout -f \$exercise >/dev/null 2>&1 && git reset --hard origin/\$exercise >/dev/null 2>&1 && git clean -fdx >/dev/null ; then if echo \"Preparing the exercise environment, hold on...\" && ./start.sh >/dev/null 2>&1; then echo \"Exercise \$exercise started!\" && echo 'Read the README.md for instructions or view them in browser:' && echo \"http://gitexercises.fracz.com/e/\$exercise\" ; else echo 'Could not execute the start script.' && echo 'Try running the ./start.sh script yourself.' ; fi else echo 'Could not clean the working directory.' && echo 'Make sure that none of the files inside the working directory' && echo 'is used by another process and run git start again.'; fi else echo \"Invalid exercise: \$exercise\" && false; fi else git push origin master:next-exercise 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | grep -v '\\*\\*' | sed 's/remote: //g' | xargs git start | grep -v Invalid || echo 'You have passed all exercises!'; fi else echo 'You need to use git start in detached HEAD'; fi }; f" +git config alias.start "! f() { export LC_ALL=C; currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; if [ \$exercise != HEAD ]; then if [ \$exercise != next ]; then if git show origin/\$exercise:start.sh >/dev/null 2>&1 ; then if git checkout -f \$exercise >/dev/null 2>&1 && git reset --hard origin/\$exercise >/dev/null 2>&1 && git clean -fdx >/dev/null ; then if echo \"Preparing the exercise environment, hold on...\" && ./start.sh >/dev/null 2>&1; then echo \"Exercise \$exercise started!\" && echo 'Read the README.md for instructions or view them in browser:' && echo \"http://gitexercises.fracz.com/e/\$exercise\" ; else echo 'Could not execute the start script.' && echo 'Try running the ./start.sh script yourself.' ; fi else echo 'Could not clean the working directory.' && echo 'Make sure that none of the files inside the working directory' && echo 'is used by another process and run git start again.'; fi else echo \"Invalid exercise: \$exercise\" && false; fi else git push origin master:next-exercise 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | grep -v '\\*\\*' | sed 's/remote: //g' | xargs git start | grep -v Invalid || echo 'You have passed all exercises!'; fi else echo 'You need to use git start in detached HEAD'; fi }; f" # Add "git verify" local alias for submitting exercises solutions. -git config alias.verify "! f() { currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; if [ \$exercise != HEAD ]; then if git show origin/\$exercise:start.sh >/dev/null 2>&1 ; then if ! git status | grep 'up-to-date' >/dev/null 2>&1 ; then if echo \"Verifying the \$exercise exercise. Hold on...\" && git push -f origin HEAD:\$exercise 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | sed 's/remote: //g' | grep -v \"\\*\\*\" ; then : ; else echo 'Solution could not be verified - push failed.' && echo 'Do you have an internet connection?'; fi else echo \"You haven't made any progress on exercise \$exercise.\" && echo 'Did you forget to commit your changes?'; fi else echo \"Invalid exercise: \$exercise\"; fi else echo 'You need to use git verify in detached HEAD'; fi }; f" +git config alias.verify "! f() { export LC_ALL=C; currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; if [ \$exercise != HEAD ]; then if git show origin/\$exercise:start.sh >/dev/null 2>&1 ; then if ! git status | grep 'up-to-date' >/dev/null 2>&1 ; then if echo \"Verifying the \$exercise exercise. Hold on...\" && git push -f origin HEAD:\$exercise 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | sed 's/remote: //g' | grep -v \"\\*\\*\" ; then : ; else echo 'Solution could not be verified - push failed.' && echo 'Do you have an internet connection?'; fi else echo \"You haven't made any progress on exercise \$exercise.\" && echo 'Did you forget to commit your changes?'; fi else echo \"Invalid exercise: \$exercise\"; fi else echo 'You need to use git verify in detached HEAD'; fi }; f" # Add "git exercises" alias that shows list of available exercises. git config alias.exercises "! git push origin master:exercises 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | grep -v '\\*\\*' | sed 's/remote: //g'" From 6bd8f8f14d9567cca555be0ead62d571086043ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Fr=C4=85cz?= Date: Wed, 21 Apr 2021 13:56:02 +0200 Subject: [PATCH 16/19] Add --local to git config commands in configure.sh ref #28 --- configure.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/configure.sh b/configure.sh index 4a2495f..d2e6245 100755 --- a/configure.sh +++ b/configure.sh @@ -1,16 +1,16 @@ #!/usr/bin/env bash # Configure "git start" local alias for starting the exercise of user's choice and restarting the current one. -git config alias.start "! f() { export LC_ALL=C; currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; if [ \$exercise != HEAD ]; then if [ \$exercise != next ]; then if git show origin/\$exercise:start.sh >/dev/null 2>&1 ; then if git checkout -f \$exercise >/dev/null 2>&1 && git reset --hard origin/\$exercise >/dev/null 2>&1 && git clean -fdx >/dev/null ; then if echo \"Preparing the exercise environment, hold on...\" && ./start.sh >/dev/null 2>&1; then echo \"Exercise \$exercise started!\" && echo 'Read the README.md for instructions or view them in browser:' && echo \"http://gitexercises.fracz.com/e/\$exercise\" ; else echo 'Could not execute the start script.' && echo 'Try running the ./start.sh script yourself.' ; fi else echo 'Could not clean the working directory.' && echo 'Make sure that none of the files inside the working directory' && echo 'is used by another process and run git start again.'; fi else echo \"Invalid exercise: \$exercise\" && false; fi else git push origin master:next-exercise 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | grep -v '\\*\\*' | sed 's/remote: //g' | xargs git start | grep -v Invalid || echo 'You have passed all exercises!'; fi else echo 'You need to use git start in detached HEAD'; fi }; f" +git config --local alias.start "! f() { export LC_ALL=C; currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; if [ \$exercise != HEAD ]; then if [ \$exercise != next ]; then if git show origin/\$exercise:start.sh >/dev/null 2>&1 ; then if git checkout -f \$exercise >/dev/null 2>&1 && git reset --hard origin/\$exercise >/dev/null 2>&1 && git clean -fdx >/dev/null ; then if echo \"Preparing the exercise environment, hold on...\" && ./start.sh >/dev/null 2>&1; then echo \"Exercise \$exercise started!\" && echo 'Read the README.md for instructions or view them in browser:' && echo \"http://gitexercises.fracz.com/e/\$exercise\" ; else echo 'Could not execute the start script.' && echo 'Try running the ./start.sh script yourself.' ; fi else echo 'Could not clean the working directory.' && echo 'Make sure that none of the files inside the working directory' && echo 'is used by another process and run git start again.'; fi else echo \"Invalid exercise: \$exercise\" && false; fi else git push origin master:next-exercise 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | grep -v '\\*\\*' | sed 's/remote: //g' | xargs git start | grep -v Invalid || echo 'You have passed all exercises!'; fi else echo 'You need to use git start in detached HEAD'; fi }; f" # Add "git verify" local alias for submitting exercises solutions. -git config alias.verify "! f() { export LC_ALL=C; currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; if [ \$exercise != HEAD ]; then if git show origin/\$exercise:start.sh >/dev/null 2>&1 ; then if ! git status | grep 'up-to-date' >/dev/null 2>&1 ; then if echo \"Verifying the \$exercise exercise. Hold on...\" && git push -f origin HEAD:\$exercise 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | sed 's/remote: //g' | grep -v \"\\*\\*\" ; then : ; else echo 'Solution could not be verified - push failed.' && echo 'Do you have an internet connection?'; fi else echo \"You haven't made any progress on exercise \$exercise.\" && echo 'Did you forget to commit your changes?'; fi else echo \"Invalid exercise: \$exercise\"; fi else echo 'You need to use git verify in detached HEAD'; fi }; f" +git config --local alias.verify "! f() { export LC_ALL=C; currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; if [ \$exercise != HEAD ]; then if git show origin/\$exercise:start.sh >/dev/null 2>&1 ; then if ! git status | grep 'up-to-date' >/dev/null 2>&1 ; then if echo \"Verifying the \$exercise exercise. Hold on...\" && git push -f origin HEAD:\$exercise 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | sed 's/remote: //g' | grep -v \"\\*\\*\" ; then : ; else echo 'Solution could not be verified - push failed.' && echo 'Do you have an internet connection?'; fi else echo \"You haven't made any progress on exercise \$exercise.\" && echo 'Did you forget to commit your changes?'; fi else echo \"Invalid exercise: \$exercise\"; fi else echo 'You need to use git verify in detached HEAD'; fi }; f" # Add "git exercises" alias that shows list of available exercises. -git config alias.exercises "! git push origin master:exercises 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | grep -v '\\*\\*' | sed 's/remote: //g'" +git config --local alias.exercises "! git push origin master:exercises 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | grep -v '\\*\\*' | sed 's/remote: //g'" # Make sure you have a "current" push strategy set; this will allow you to push only current exercise with simple git # push command instead of pushing all matching branches (default in Git < 2.0) -git config push.default current +git config --local push.default current echo "OK" From e457994c542f9c68a13afa3014302697bc52bc4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Fr=C4=85cz?= Date: Wed, 21 Apr 2021 14:20:48 +0200 Subject: [PATCH 17/19] Fix detecting if any progress was made in the exercise --- configure.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.sh b/configure.sh index d2e6245..99e4beb 100755 --- a/configure.sh +++ b/configure.sh @@ -4,7 +4,7 @@ git config --local alias.start "! f() { export LC_ALL=C; currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; if [ \$exercise != HEAD ]; then if [ \$exercise != next ]; then if git show origin/\$exercise:start.sh >/dev/null 2>&1 ; then if git checkout -f \$exercise >/dev/null 2>&1 && git reset --hard origin/\$exercise >/dev/null 2>&1 && git clean -fdx >/dev/null ; then if echo \"Preparing the exercise environment, hold on...\" && ./start.sh >/dev/null 2>&1; then echo \"Exercise \$exercise started!\" && echo 'Read the README.md for instructions or view them in browser:' && echo \"http://gitexercises.fracz.com/e/\$exercise\" ; else echo 'Could not execute the start script.' && echo 'Try running the ./start.sh script yourself.' ; fi else echo 'Could not clean the working directory.' && echo 'Make sure that none of the files inside the working directory' && echo 'is used by another process and run git start again.'; fi else echo \"Invalid exercise: \$exercise\" && false; fi else git push origin master:next-exercise 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | grep -v '\\*\\*' | sed 's/remote: //g' | xargs git start | grep -v Invalid || echo 'You have passed all exercises!'; fi else echo 'You need to use git start in detached HEAD'; fi }; f" # Add "git verify" local alias for submitting exercises solutions. -git config --local alias.verify "! f() { export LC_ALL=C; currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; if [ \$exercise != HEAD ]; then if git show origin/\$exercise:start.sh >/dev/null 2>&1 ; then if ! git status | grep 'up-to-date' >/dev/null 2>&1 ; then if echo \"Verifying the \$exercise exercise. Hold on...\" && git push -f origin HEAD:\$exercise 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | sed 's/remote: //g' | grep -v \"\\*\\*\" ; then : ; else echo 'Solution could not be verified - push failed.' && echo 'Do you have an internet connection?'; fi else echo \"You haven't made any progress on exercise \$exercise.\" && echo 'Did you forget to commit your changes?'; fi else echo \"Invalid exercise: \$exercise\"; fi else echo 'You need to use git verify in detached HEAD'; fi }; f" +git config --local alias.verify "! f() { export LC_ALL=C; currentBranch=\$(git rev-parse --abbrev-ref HEAD); exercise=\${1-\$currentBranch}; if [ \$exercise != HEAD ]; then if git show origin/\$exercise:start.sh >/dev/null 2>&1 ; then if ! (git status | grep 'up-to-date' >/dev/null 2>&1 || git status | grep 'up to date' >/dev/null 2>&1) ; then if echo \"Verifying the \$exercise exercise. Hold on...\" && git push -f origin HEAD:\$exercise 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | sed 's/remote: //g' | grep -v \"\\*\\*\" ; then : ; else echo 'Solution could not be verified - push failed.' && echo 'Do you have an internet connection?'; fi else echo \"You haven't made any progress on exercise \$exercise.\" && echo 'Did you forget to commit your changes?'; fi else echo \"Invalid exercise: \$exercise\"; fi else echo 'You need to use git verify in detached HEAD'; fi }; f" # Add "git exercises" alias that shows list of available exercises. git config --local alias.exercises "! git push origin master:exercises 2>&1 | sed -n '/\\*\\*\\*/,/\\*\\*\\*/p' | grep -v '\\*\\*' | sed 's/remote: //g'" From 9fa29b26695edb3989346c201704cb35e0926de5 Mon Sep 17 00:00:00 2001 From: MariaMaciel04 <146140845+MariaMaciel04@users.noreply.github.com> Date: Tue, 26 Sep 2023 19:50:39 -0300 Subject: [PATCH 18/19] Update start.sh master --- start.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/start.sh b/start.sh index 643a64d..24cabeb 100755 --- a/start.sh +++ b/start.sh @@ -3,3 +3,5 @@ echo 'test' > 'test.txt' git add test.txt git commit -m "This is first exercise commit." +$> git start +$> git verify From afb2578803ba9ba5d8d4b9a5d8a3ba89544c8774 Mon Sep 17 00:00:00 2001 From: MariaMaciel04 <146140845+MariaMaciel04@users.noreply.github.com> Date: Tue, 26 Sep 2023 19:52:14 -0300 Subject: [PATCH 19/19] Update start.sh --- start.sh | 4 ---- 1 file changed, 4 deletions(-) diff --git a/start.sh b/start.sh index 24cabeb..b9db965 100755 --- a/start.sh +++ b/start.sh @@ -1,7 +1,3 @@ -#!/usr/bin/env bash -echo 'test' > 'test.txt' -git add test.txt -git commit -m "This is first exercise commit." $> git start $> git verify