Package: sc-githooks
Git Pre-Receive Hook to Validate CommitsThis project provides a Git pre-receive hook to validate pushed commits on
the Git server side.  The hook avoids all issues by rejecting any commit
not matching the rules to get in to the repository in the first place.InstallationIt is possible to install the tool withpip:pip install sc-githooksLink thescripttohooks/pre-receiveon you Git
repositories on your Git server:ln -s sc-pre-receive /home/git/repositories/myproject.git/hooks/pre-receiveIf you want all projects to be checked, then you need to do following steps:On the GitLab server, navigate to the configured custom hook directory. The default is in the gitlab-shell directory.The gitlab-shell hook directory for Omnibus installation is usually /opt/gitlab/embedded/service/gitlab-shell/hooks.Create a new directory in this location. Depending on your hook, it will be either a pre-receive.d, post-receive.d,
or update.d directory.Inside this new directory, add your hook like this:cd /opt/gitlab/embedded/service/gitlab-shell/hooks
mkdir pre-receive.d
cd pre-receive.d
ln -s /usr/local/bin/sc-pre-receive pre-receiveFeaturesValidate received commits one by one not just the last oneOnly validate added or modified files on the commitsReport all problems before failingCheck for duplicate commit summariesCheck for misleading merge commitsValidate committer and author timestampsValidate committer and author names and email addressesCheck commit message best practices (80 lines, first line summary…)Check commit summary formattingValidate commit tags against a list[BUGFIX],[FEATURE],[WIP]…Check for changed file pathsAccept commits tagged as[HOTFIX],[MESS],[TEMP], or[WIP]with issuesCheck binary filesCheck file sizeCheck file extensionsHere is an example problem output:=== CheckDuplicateCommitSummaries on CommitList ===
ERROR: summary "Add nagios check for early expiration of licenses" duplicated 2 times

=== CheckCommitSummary on 31d0f6b ===
WARNING: summary longer than 72 characters

=== CheckCommitSummary on 6bded65 ===
WARNING: past tense used on summary

=== CheckCommitMessage on 6fdbc00 ===
WARNING: line 7 is longer than 80
WARNING: line 9 is longer than 80ConfigurationFirst, make sure /var/opt/sc directory exists, if not create this directory and make sure current user has the right
to create files in this directory.You can copydefault.ymlto /var/opt/sc/.sc-githooks/production.yml to initialize the production configuration.The default configuration file looks like this:dev:
  # Whether this program is running in development mode
  dev_mode: False

commit_check:
  # Whether commit check is enabled
  enabled: True
  # The warning threshold of the length of commit summary
  commit_summary_max_length: 50
  # The threshold of the max length of commit summary and other commit line
  commit_line_max_length: 80

  # A list of illegal suffixes which cannot be committed to git repository
  binary_file_illegal_suffixes: "jar"
  # A list of legal binary file names which can be committed to git repository
  legal_binary_filenames: "gradle-wrapper.jar,maven-wrapper.jar"

  # The max size of a file that can be committed to git repository
  commit_file_max_size: 5242880Pros and Cons of Pre-receive HookContinuous Integration ServerA continuous integration server can run such checks with the many other
things it is doing.  Moving this job from it has many benefits:Synchronous feedbackMore efficientDisallow any commit violating the rulesPre-commit HookEven though, pre-receive hook gives later feedback than pre-commit hook,
it has many advantages over it:No client side configurationPlugins has to be installed only once to the Git serverEverybody gets the same checksEnforcement, nobody can skip the checksCommit checking (pre-commit hook only gets what is changed in the commit)IDE IntegrationThe same advantages compared to pre-commit hooks applies to IDE
integration.  Though, IDE integration gives much sooner and nicer feedback,
so it is still a good idea, even with the pre-receive hook.Dependenciessc-config>= 0.0.3TestingI found it useful to check what the script would have complained if it had
been active on different Git repositories.  You can run a command like this
to test this inside a Git repository against last 50 commits:git log --reverse --oneline HEAD~50..HEAD |
    sed 's:\([^ ]*\) .*:\1 \1 refs/heads/master:' |
    python ../sc-githooks/sc-pre-receiveLicenseThe script is released under the MIT License.  The MIT License is registered
with and approved by the Open Source Initiative[1].[1]https://opensource.org/licenses/MIT