QuestionQ87

VerifiedDevSecOps Pipeline-Code Stage

Curtis Morgan works as a DevSecOps engineer at Orchid Pvt. Ltd., an organization that develops online teaching software. Beth McCarthy, a member of the software development team, asked Curtis for help making pre-commit hooks executable on her local machine. Curtis navigated to the repo\.git\hooks directory, removed the .sample extension from the pre-commit.sample file, and used the chmod +x filename command to make the pre-commit hook executable on Beth's local machine.

The next day, while developing code for the software product, Beth accidentally committed code containing sensitive information.

What will be the result of this commit?

Explanation

Git pre-commit hooks use their exit status to determine whether a commit should proceed: an exit code of 0 tells Git the checks passed and the commit should continue, while any non-zero exit code tells Git to abort the commit. The default/sample pre-commit hook logic (and custom scripts built on the same pattern, including those that scan staged changes for sensitive data such as passwords, API keys, or private keys) follows this convention by exiting with status 1 when a violation is detected, which halts the commit and reports the issue to the user. Since Beth's staged changes contained sensitive information that the pre-commit hook is designed to catch, the hook script would exit with code 1, causing Git to reject the commit.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!