Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a Git hook that runs tests on push.
Git
cd .git/hooks && mv pre-push.sample [1] Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using pre-commit instead of pre-push
Renaming to a non-hook filename
Not moving the sample file
✗ Incorrect
The pre-push hook runs before pushing commits, so renaming pre-push.sample to pre-push activates it.
2fill in blank
mediumComplete the script line to run tests automatically on push.
Git
#!/bin/sh [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using git status instead of running tests
Using echo which does not run tests
Listing files instead of testing
✗ Incorrect
Running 'npm test' executes the test suite automatically during the push hook.
3fill in blank
hardFix the error in the hook script to stop push if tests fail.
Git
#!/bin/sh npm test || [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'exit 0' which allows push even if tests fail
Using 'continue' or 'return' which are invalid in shell scripts
Not handling test failure at all
✗ Incorrect
Using 'exit 1' stops the push if tests fail by returning a failure status.
4fill in blank
hardFill both blanks to check test results and print a message.
Git
#!/bin/sh if npm test [1]; then echo [2] else exit 1 fi
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '||' which runs echo on failure
Not using echo to print the message
Putting the message without echo
✗ Incorrect
Using '&& echo' runs the echo only if tests pass, printing the success message.
5fill in blank
hardFill all three blanks to create a pre-push hook that runs tests and stops push on failure.
Git
#!/bin/sh [1] || [2] exit [3]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Exiting with 1 even if tests pass
Not running tests before exit
Using wrong exit codes
✗ Incorrect
The script runs 'npm test', exits with 1 if tests fail, and exits 0 if tests pass to allow push.