InterviewSolution
| 1. |
Define client level git hooks and their implementation. |
|
Answer» Git hooks are the instruction scripts that gets triggered before(pre) or post(after) certain actions or events such as a git command run.
Scenario how I implemented the hooks scripts to enforce certain pre-commit and post-commit test cases: Step 1: Running .git/hooks/pre-commit script. [OK]: No deleted files, proceed to commit. Thu Feb 7 12:10:02 CET 2019 --------------------------------------------Step 2: Running .git/hooks/prepare-commit-msg script. Get hooks scripts while cloning the repo. ISSUE#7092 Enter your commit message here. README code/install_hooks.sh code/runTests.sh database.log hooksScripts/commit-msg hooksScripts/hooks_library.lib hooksScripts/post-commit hooksScripts/pre-commit hooksScripts/pre-rebase hooksScripts/prepare-commit-msg newFile Thu Feb 7 12:10:02 CET 2019 --------------------------------------------Step 3: Running .git/hooks/commit-msg script. [OK]: Commit message has an ISSUE number Thu Feb 7 12:10:02 CET 2019 --------------------------------------------Step 4: Running .git/hooks/post-commit script. New commit made: 1c705d3 Get hooks scripts while cloning the repo. ISSUE#7092
A code snippet demonstrating the use of a ‘pre-receive’ hook that is triggered just before a ‘push’ request on the Server, can be written to reject or allow the push operation. localRepo [dev] $git push Enumerating objects: 3, DONE. Counting objects: 100% (3/3), done. Writing objects: 100% (2/2), 272 bytes | 272.00 KiB/s, done. Total 2 (delta 0), reused 0 (delta 0) remote: pre-recieve hook script remote: hooks/pre-receive: [NOK]- Abort the push command remote: To /Users/Divya1/OneDrive/gitRepos/remoteRepo/ ! [remote rejected] dev -> dev (pre-receive hook declined) error: failed to push some refs to '/Users/Divya1/OneDrive/gitRepos/remoteRepo/' |
|