0
0
Gitdevops~10 mins

pre-push hook in Git - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a pre-push hook script that runs before pushing.

Git
#!/bin/sh

[1]
Drag options to blanks, or click blank then click option'
Agit status
Bgit push origin main
Cgit commit -m 'pre-push'
Decho "Running pre-push hook"
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to push inside the pre-push hook causes recursion.
Using git commit in the hook is incorrect.
2fill in blank
medium

Complete the code to make the pre-push hook stop the push if tests fail.

Git
#!/bin/sh

if ! [1]; then
  echo "Tests failed, push aborted."
  exit 1
fi
Drag options to blanks, or click blank then click option'
Agit push
Bmake test
Cecho 'test'
Dls
Attempts:
3 left
💡 Hint
Common Mistakes
Using git push inside the hook causes infinite loops.
Using commands that don't test code.
3fill in blank
hard

Fix the error in the pre-push hook to correctly check for staged changes.

Git
#!/bin/sh

if git diff --quiet [1]; then
  echo "No staged changes."
else
  echo "Staged changes found. Push aborted."
  exit 1
fi
Drag options to blanks, or click blank then click option'
A--cached
B--staged
C--all
D--untracked
Attempts:
3 left
💡 Hint
Common Mistakes
Using invalid git diff options.
Confusing staged and unstaged changes.
4fill in blank
hard

Fill both blanks to create a pre-push hook that runs tests and lints code before pushing.

Git
#!/bin/sh

if ! [1]; then
  echo "Tests failed. Push aborted."
  exit 1
fi

if ! [2]; then
  echo "Lint errors found. Push aborted."
  exit 1
fi
Drag options to blanks, or click blank then click option'
Anpm test
Bgit status
Cnpm run lint
Decho 'linting'
Attempts:
3 left
💡 Hint
Common Mistakes
Using commands that don't check code quality.
Not exiting with error on failure.
5fill in blank
hard

Fill all three blanks to create a pre-push hook that checks tests, lint, and code formatting.

Git
#!/bin/sh

if ! [1]; then
  echo "Tests failed. Push aborted."
  exit 1
fi

if ! [2]; then
  echo "Lint errors found. Push aborted."
  exit 1
fi

if ! [3]; then
  echo "Code formatting issues. Push aborted."
  exit 1
fi
Drag options to blanks, or click blank then click option'
Anpm test
Bnpm run lint
Cnpm run format:check
Dgit status
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to check formatting.
Using git status instead of test commands.