### Install Overcommit Gem and Hooks Source: https://context7.com/sds/overcommit/llms.txt Install the Overcommit gem using RubyGems and then set up the hooks within your Git repository. Ensure you are in your project directory before running the setup command. ```bash gem install overcommit cd your-project git init # If not already a git repo overcommit --install ``` -------------------------------- ### Run RSpec Tests Source: https://github.com/sds/overcommit/blob/main/CONTRIBUTING.md Execute RSpec tests for the project. Ensure you have run `bundle install` first. ```bash bundle exec rspec ``` -------------------------------- ### Install Overcommit Hooks in Repository Source: https://context7.com/sds/overcommit/llms.txt Installs Overcommit hooks into a Git repository. Existing hooks are backed up. Use the --force flag to overwrite existing hooks. ```bash overcommit --install # Install hooks in a specific directory overcommit --install /path/to/repo # Force install, overwriting existing hooks overcommit --install --force ``` -------------------------------- ### Overcommit Basic Configuration (.overcommit.yml) Source: https://context7.com/sds/overcommit/llms.txt Example of a basic Overcommit configuration file. It demonstrates global settings and enabling/configuring specific hooks like RuboCop and ESLint. ```yaml # .overcommit.yml # Global settings gemfile: false # Set to '.overcommit_gems.rb' for Bundler integration plugin_directory: '.git-hooks' # Directory for custom hooks quiet: false # Set to true to hide output unless there's a problem concurrency: '%{processors}' # Number of parallel hook workers verify_signatures: true # Security feature to verify hook signatures # Enable RuboCop for Ruby files PreCommit: RuboCop: enabled: true command: ['bundle', 'exec', 'rubocop'] flags: ['--format=emacs', '--force-exclusion', '--display-cop-names'] include: - '**/*.rb' - '**/*.rake' - '**/Gemfile' - '**/Rakefile' # Enable ESLint for JavaScript files EsLint: enabled: true command: ['npm', 'run', 'lint', '--', '-f', 'compact'] include: '**/*.js' ``` -------------------------------- ### Install Gems with a Custom Gemfile Source: https://github.com/sds/overcommit/blob/main/README.md Use this command to install gems specified in a custom Gemfile for Overcommit hooks. This helps in managing dependencies specifically for your git hooks. ```bash bundle install --gemfile=.overcommit_gems.rb ``` -------------------------------- ### Install Overcommit via RubyGems Source: https://github.com/sds/overcommit/blob/main/README.md Install the Overcommit gem into your Ruby environment. ```bash gem install overcommit ``` -------------------------------- ### Configure Automatic Hook Installation Source: https://github.com/sds/overcommit/blob/main/README.md Set the GIT_TEMPLATE_DIR environment variable to automatically install Overcommit hooks in new repositories. ```bash export GIT_TEMPLATE_DIR="$(overcommit --template-dir)" ``` -------------------------------- ### CLI Hook Management Source: https://context7.com/sds/overcommit/llms.txt Commands for installing, uninstalling, and listing Git hooks managed by Overcommit. ```APIDOC ## CLI: Install Hooks ### Description Installs Overcommit hooks into a repository, backing up existing hooks. ### Usage `overcommit --install [path]` ### Options - **--force** - Overwrites existing hooks. ## CLI: Uninstall Hooks ### Description Removes Overcommit hooks and restores previously backed up hooks. ### Usage `overcommit --uninstall` ## CLI: List Hooks ### Description Displays all available hooks and their current enabled/disabled status. ### Usage `overcommit --list-hooks` ``` -------------------------------- ### Configure Post-Checkout Hooks Source: https://context7.com/sds/overcommit/llms.txt Define hooks to run automatically after checkout operations, such as installing dependencies or updating tags. ```yaml PostCheckout: ALL: required: false quiet: false skip_file_checkout: true # Skip for file-only checkouts # Auto-install bundle dependencies BundleInstall: enabled: true requires_files: true required_executable: 'bundle' flags: ['install'] include: - 'Gemfile' - 'Gemfile.lock' # Auto-install npm dependencies NpmInstall: enabled: true requires_files: true required_executable: 'npm' flags: ['install'] include: - 'package.json' # Auto-install yarn dependencies YarnInstall: enabled: true requires_files: true required_executable: 'yarn' flags: ['install'] include: - 'package.json' - 'yarn.lock' # Check submodule status SubmoduleStatus: enabled: true recursive: true # Generate tags file IndexTags: enabled: true required_executable: 'ctags' ``` -------------------------------- ### Get Overcommit Template Directory Source: https://context7.com/sds/overcommit/llms.txt Retrieves the path to the template directory used for automatic hook installation in new Git repositories. This path can be exported to set up automatic installation. ```bash # Print template directory path overcommit --template-dir # Set up automatic installation for new repos export GIT_TEMPLATE_DIR="$(overcommit --template-dir)" ``` -------------------------------- ### Configure Overcommit Concurrency Source: https://github.com/sds/overcommit/blob/main/README.md Adjust the global concurrency option in .overcommit.yml to control the number of parallel workers. This example sets concurrency to one-fourth of the available processors. ```yaml concurrency: '%{processors} / 4' ``` -------------------------------- ### Configure ALL Hook Settings Source: https://github.com/sds/overcommit/blob/main/README.md Apply default settings to all hooks within a category using the ALL key. ```yaml PreCommit: ALL: problem_on_unmodified_line: warn requires_files: true required: false quiet: false SomeHook: enabled: true ... ``` -------------------------------- ### Use YAML Anchors for DRY Configuration Source: https://context7.com/sds/overcommit/llms.txt Use YAML anchors to define reusable configuration blocks and avoid repetition. ```yaml PreCommit: ALL: exclude: &default_excludes - 'node_modules/**/*' - 'vendor/**/*' - 'tmp/**/*' RuboCop: enabled: true exclude: - *default_excludes - 'db/schema.rb' EsLint: enabled: true exclude: - *default_excludes - 'public/assets/**/*' ``` -------------------------------- ### Initialize Overcommit in a Repository Source: https://github.com/sds/overcommit/blob/main/README.md Set up Overcommit hooks within a specific Git repository. ```bash mkdir important-project cd important-project git init overcommit --install ``` -------------------------------- ### CLI Execution and Security Source: https://context7.com/sds/overcommit/llms.txt Commands for manually triggering hooks and managing security signatures. ```APIDOC ## CLI: Run Hooks ### Description Runs hooks manually against tracked files or specific references. ### Usage `overcommit --run [hook_type]` `overcommit --diff [ref]` ## CLI: Sign Configuration ### Description Updates hook signatures after configuration changes to acknowledge security implications. ### Usage `overcommit --sign [hook_type]` ``` -------------------------------- ### Integrate an Existing Custom Script Source: https://github.com/sds/overcommit/blob/main/README.md Execute an external script as a hook by specifying the required executable in the configuration. ```yaml PostCheckout: CustomScript: enabled: true required_executable: './bin/custom-script' ``` -------------------------------- ### Configure Pre-Push Hooks Source: https://context7.com/sds/overcommit/llms.txt Define hooks to run before pushing to a remote repository, such as test suites or security scanners. ```yaml PrePush: # Run RSpec tests before push RSpec: enabled: true required_executable: 'rspec' # Run pytest tests Pytest: enabled: true required_executable: 'pytest' # Run minitest tests Minitest: enabled: true command: ['ruby', '-Ilib:test', '-rminitest', "-e 'exit! Minitest.run'"] include: 'test/**/*_test.rb' # Security analysis with Brakeman (Rails) Brakeman: enabled: true required_executable: 'brakeman' flags: ['--exit-on-warn', '--quiet', '--summary'] # Protect branches from force pushes ProtectedBranches: enabled: true destructive_only: true branches: ['master', 'main', 'production'] ``` -------------------------------- ### ALL Hook Configuration Source: https://github.com/sds/overcommit/blob/main/README.md Documentation for the special ALL hook configuration used to apply settings across an entire category of hooks. ```APIDOC ## ALL Hook Configuration ### Description A special configuration key used within hook categories (e.g., PreCommit, PostCommit) to apply settings to all hooks in that category. ### Usage ```yaml PreCommit: ALL: problem_on_unmodified_line: warn requires_files: true required: false quiet: false ``` ### Notes - Array configuration options like `include` or `exclude` are not merged; custom definitions for specific hooks will replace the `ALL` configuration. ``` -------------------------------- ### Integrate Shell Scripts as Hooks Source: https://context7.com/sds/overcommit/llms.txt Configure existing shell scripts to run as hooks within the .overcommit.yml file. ```yaml # .overcommit.yml PostCheckout: CustomScript: enabled: true required_executable: './bin/post-checkout-script.sh' description: 'Run custom post-checkout script' PreCommit: LintScript: enabled: true command: ['./scripts/lint.sh'] include: '**/*.py' DatabaseCheck: enabled: true required_executable: 'bash' command: ['bash', '-c', './bin/check-migrations.sh'] ``` -------------------------------- ### Configure a Custom Pre-Commit Hook Source: https://github.com/sds/overcommit/blob/main/README.md Enable and configure the custom hook in the Overcommit YAML configuration file. ```yaml PreCommit: EnsureSpecHelper: enabled: true description: 'Checking for missing inclusion of spec_helper' include: '**/*_spec.rb' ``` -------------------------------- ### Create Repository-Specific Hooks Source: https://context7.com/sds/overcommit/llms.txt Implement custom hooks in the .git-hooks directory and register them in .overcommit.yml. ```ruby # .git-hooks/pre_commit/ensure_spec_helper.rb module Overcommit::Hook::PreCommit class EnsureSpecHelper < Base def run errors = [] applicable_files.each do |file| if File.read(file) !~ /^require ['"]spec_helper['"]/ errors << "#{file}: missing `require 'spec_helper'`" end end return :fail, errors.join("\n") if errors.any? :pass end end end ``` ```yaml # .overcommit.yml PreCommit: EnsureSpecHelper: enabled: true description: 'Check for missing spec_helper inclusion' include: '**/*_spec.rb' ``` -------------------------------- ### Configure Hook Options Source: https://context7.com/sds/overcommit/llms.txt Defines global and individual hook settings such as file requirements, execution commands, and environment variables. ```yaml PreCommit: # The ALL hook applies settings to every hook in this category ALL: problem_on_unmodified_line: report # report, warn, or ignore requires_files: true required: false quiet: false MyHook: enabled: true # Enable/disable the hook required: true # Cannot be skipped with SKIP env var quiet: true # Only show output on warning/failure description: 'Check my files' # Custom description requires_files: true # Only run if applicable files exist include: # Files to include (glob patterns) - '**/*.rb' - '**/*.js' exclude: # Files to exclude - 'vendor/**/*' - 'node_modules/**/*' exclude_branches: # Branches to skip - 'master' - 'release-*' on_fail: warn # Change failure to warning (warn/pass) on_warn: fail # Change warning to failure (pass/fail) required_executable: 'rubocop' # Executable that must exist install_command: 'gem install rubocop' # How to install the executable command: ['bundle', 'exec', 'rubocop'] # Command to execute flags: ['--format=emacs'] # Additional command flags env: # Environment variables RUBYOPT: '-W0' parallelize: true # Allow parallel execution processors: 2 # Number of processing units needed skip_if: ['bash', '-c', '! which my-tool'] # Conditional skip ``` -------------------------------- ### Configure Pre-Commit Hooks Source: https://context7.com/sds/overcommit/llms.txt Configures various pre-commit checks including linting, syntax validation, and branch restrictions. ```yaml PreCommit: # Author validation (enabled by default) AuthorEmail: enabled: true pattern: '^[^@]+@company\.com$' # Enforce company email AuthorName: enabled: true # Check for broken symlinks BrokenSymlinks: enabled: true # Check for merge conflicts MergeConflicts: enabled: true # Case-insensitivity conflicts CaseConflicts: enabled: true # Ruby linting with RuboCop RuboCop: enabled: true command: ['bundle', 'exec', 'rubocop'] on_warn: fail # Treat warnings as errors # JavaScript linting with ESLint EsLint: enabled: true required_executable: 'eslint' flags: ['--format=compact'] include: '**/*.js' # Python linting with Flake8 PythonFlake8: enabled: true required_executable: 'flake8' include: '**/*.py' # Shell script analysis ShellCheck: enabled: true required_executable: 'shellcheck' flags: ['--format=gcc'] include: '**/*.sh' # YAML syntax validation YamlSyntax: enabled: true include: - '**/*.yaml' - '**/*.yml' # JSON syntax validation JsonSyntax: enabled: true include: '**/*.json' # Check for FIXME/TODO tokens FixMe: enabled: true keywords: ['BROKEN', 'BUG', 'FIXME', 'HACK', 'TODO', 'XXX'] # File size limits FileSize: enabled: true size_limit_bytes: 1_000_000 # Prevent commits to certain branches ForbiddenBranches: enabled: true branch_patterns: ['master', 'main'] # Trailing whitespace check TrailingWhitespace: enabled: true ``` -------------------------------- ### Implement a Custom Pre-Commit Hook in Ruby Source: https://github.com/sds/overcommit/blob/main/README.md Define a custom hook class inheriting from Base to perform repository-specific checks, such as verifying file content. ```ruby module Overcommit::Hook::PreCommit class EnsureSpecHelper < Base def run errors = [] applicable_files.each do |file| if File.read(file) !~ /^require 'spec_helper'/ errors << "#{file}: missing `require 'spec_helper'`" end end return :fail, errors.join("\n") if errors.any? :pass end end end ``` -------------------------------- ### Configure Hooks in .overcommit.yml Source: https://github.com/sds/overcommit/blob/main/README.md Define hook settings in the repository's .overcommit.yml file to extend or override default configurations. ```yaml PreCommit: RuboCop: enabled: true command: ['bundle', 'exec', 'rubocop'] # Invoke within Bundler context ``` -------------------------------- ### Extend Global Exclusions with YAML References Source: https://github.com/sds/overcommit/blob/main/README.md Use YAML anchors and aliases to extend global exclusion lists defined in the ALL hook. ```yaml PreCommit: ALL: exclude: &default_excludes - 'node_modules/**/*' - 'vendor/**/*' MyHook: exclude: - *default_excludes - 'another/directory/in/addition/to/default/excludes/**/*' ``` -------------------------------- ### Manage Hook Dependencies with a Dedicated Gemfile Source: https://context7.com/sds/overcommit/llms.txt Use a separate Gemfile for hook dependencies to improve performance and isolate environments. ```ruby # .overcommit_gems.rb source 'https://rubygems.org' gem 'overcommit', '~> 0.69.0' gem 'rubocop', '~> 1.50' gem 'rubocop-rails', '~> 2.19' gem 'rubocop-rspec', '~> 2.22' gem 'haml_lint', '~> 0.45' gem 'scss_lint', '~> 0.60' ``` ```bash # Generate the lock file bundle install --gemfile=.overcommit_gems.rb ``` ```yaml # .overcommit.yml gemfile: .overcommit_gems.rb PreCommit: RuboCop: enabled: true # No need for 'bundle exec' - Overcommit handles it ``` -------------------------------- ### Hook Configuration Options Source: https://github.com/sds/overcommit/blob/main/README.md Details on the configuration keys available for individual hooks in Overcommit. ```APIDOC ## Hook Configuration Options ### Description Configuration options that can be applied to individual hooks to control their execution environment, concurrency, and installation requirements. ### Parameters - **env** (Hash) - Optional - Hash of environment variables for the hook. Only string values are accepted. - **parallelize** (Boolean) - Optional - Whether to allow the hook to run concurrently with others. - **processors** (Integer) - Optional - Number of processing units to reserve for the hook. - **install_command** (String) - Optional - Command to install required dependencies for documentation purposes. - **skip_file_checkout** (Boolean) - Optional - Whether to skip the hook for file checkouts (PostCheckout only). - **skip_if** (Array) - Optional - Array of arguments to determine if the hook should be skipped. ``` -------------------------------- ### Override Configuration Locally Source: https://context7.com/sds/overcommit/llms.txt Use .local-overcommit.yml to define personal settings that are ignored by version control. ```yaml # .local-overcommit.yml (add to .gitignore) PreCommit: RuboCop: enabled: false # Disable locally while working on a feature MyCustomDebugHook: enabled: true required_executable: './bin/my-debug-script.sh' ``` -------------------------------- ### Run Only Specific Hooks via Environment Variables Source: https://context7.com/sds/overcommit/llms.txt Use the ONLY environment variable to whitelist specific hooks for execution. ```bash # Only run RuboCop ONLY=RuboCop git commit -m "Ruby changes only" # Only run multiple specific hooks ONLY=RuboCop,RSpec git commit -m "Ruby with tests" ``` -------------------------------- ### List Overcommit Hooks Status Source: https://context7.com/sds/overcommit/llms.txt Displays all available hooks and their current enabled or disabled status within the repository. ```bash overcommit --list-hooks ``` -------------------------------- ### Run Overcommit and RSpec Tests Source: https://github.com/sds/overcommit/blob/main/CONTRIBUTING.md Execute Overcommit's own tests and RSpec tests. This is part of the CI process. ```bash bundle exec rspec bundle exec overcommit --run ``` -------------------------------- ### Configure Prepare Commit Message Hooks Source: https://context7.com/sds/overcommit/llms.txt Define hooks to modify commit messages, such as prepending branch names. ```yaml PrepareCommitMsg: # Prepend branch name to commit message ReplaceBranch: enabled: true branch_pattern: '\A(\d+)-(\w+).*\z' replacement_text: '[#\1]' skipped_commit_types: - 'message' # Skip if -m flag used - 'template' # Skip if -t flag used - 'commit' # Skip if amending - 'merge' # Skip if merging - 'squash' # Skip if squashing on_fail: warn ``` -------------------------------- ### Skip Hooks via Environment Variable Source: https://github.com/sds/overcommit/blob/main/README.md Use the SKIP environment variable to prevent specific hooks from blocking a commit. ```bash SKIP=RuboCop git commit ``` -------------------------------- ### Define a Custom Ruby Hook Source: https://context7.com/sds/overcommit/llms.txt Implement a custom pre-commit hook by inheriting from Overcommit::Hook::Base and defining a run method. ```ruby module Overcommit::Hook::PreCommit class CustomCheck < Base def run # Simple pass/fail return :pass if everything_ok? return :fail, "Something went wrong" # Return with warnings return :warn, "This might be a problem" # Return array of messages for detailed reporting messages = [] applicable_files.each do |file| if problem_in_file?(file) messages << Message.new(:error, file, 10, "Error on line 10") end if minor_issue?(file) messages << Message.new(:warning, file, 20, "Warning on line 20") end end messages end end end ``` -------------------------------- ### Skip Specific Hooks via Environment Variables Source: https://context7.com/sds/overcommit/llms.txt Temporarily skip hooks during a commit using the SKIP environment variable. ```bash # Skip a single hook SKIP=RuboCop git commit -m "Quick fix" # Skip multiple hooks SKIP=RuboCop,EsLint git commit -m "Work in progress" # Skip all hooks of a type SKIP=PreCommit git commit -m "Emergency fix" ``` -------------------------------- ### Uninstall Overcommit Hooks Source: https://context7.com/sds/overcommit/llms.txt Removes Overcommit hooks from the repository and restores any previously backed-up hooks. ```bash overcommit --uninstall ``` -------------------------------- ### Configure Parallel Hook Execution Source: https://context7.com/sds/overcommit/llms.txt Control the concurrency of hook execution using processor-based expressions or fixed values. ```yaml # .overcommit.yml # Use all available processors (default) concurrency: '%{processors}' # Use half of available processors concurrency: '%{processors} / 2' # Use a fixed number concurrency: 4 # Double the processors (if hooks are I/O bound) concurrency: '%{processors} * 2' PreCommit: # Some hooks shouldn't run in parallel DatabaseMigrationCheck: enabled: true parallelize: false # Run sequentially # Hook that uses multiple threads internally HeavyLinter: enabled: true processors: 2 # Reserve 2 processing slots ``` -------------------------------- ### Sign Overcommit Configuration Source: https://context7.com/sds/overcommit/llms.txt Updates hook signatures after configuration changes to ensure security. This acknowledges the security implications of modified hook behavior. ```bash # Sign the main configuration overcommit --sign # Sign a specific hook type's plugins overcommit --sign pre_commit ``` -------------------------------- ### Configure Commit Message Hooks Source: https://context7.com/sds/overcommit/llms.txt Configures validation rules for commit messages, such as subject line formatting, width limits, and pattern matching. ```yaml CommitMsg: ALL: requires_files: false quiet: false # Ensure subject line is capitalized CapitalizedSubject: enabled: true description: 'Check subject capitalization' # Check for empty commit messages EmptyMessage: enabled: true quiet: true # Enforce text width limits TextWidth: enabled: true max_subject_width: 60 min_subject_width: 0 max_body_width: 72 # Ensure no trailing period in subject TrailingPeriod: enabled: true # Custom message format pattern MessageFormat: enabled: true pattern: '(.+)[|](.+)[|](.+)' expected_pattern_message: ' | | ' sample_message: 'DEFECT-1234 | Refactored Onboarding flow | John Doe' # Spell check commit messages SpellCheck: enabled: true required_executable: 'hunspell' flags: ['-a'] ``` -------------------------------- ### Run Overcommit Hooks Manually Source: https://context7.com/sds/overcommit/llms.txt Manually trigger Overcommit hooks. This is useful for CI environments or for running hooks against specific files or changes relative to a reference point. ```bash # Run all pre-commit hooks against all tracked files overcommit --run # Run a specific hook type overcommit --run pre_commit overcommit --run commit_msg # Run pre-commit hooks against changes relative to a ref overcommit --diff main overcommit --diff HEAD~5 ``` -------------------------------- ### Control Colorized Output Source: https://context7.com/sds/overcommit/llms.txt Force or disable colored output using the OVERCOMMIT_COLOR environment variable. ```bash # Disable colors OVERCOMMIT_COLOR=0 git commit # Force colors (useful in CI) OVERCOMMIT_COLOR=1 git commit ``` -------------------------------- ### Disable Overcommit Entirely Source: https://context7.com/sds/overcommit/llms.txt Disable all hooks for specific commands or scripts using the OVERCOMMIT_DISABLE environment variable. ```bash # Disable for a single command OVERCOMMIT_DISABLE=1 git commit -m "Automated commit" # Disable in a script export OVERCOMMIT_DISABLE=1 ./my-automated-script.sh ``` -------------------------------- ### Disable Colorized Output Source: https://github.com/sds/overcommit/blob/main/README.md Set the OVERCOMMIT_COLOR environment variable to 0 to disable colorized output. ```bash OVERCOMMIT_COLOR=0 git commit ``` -------------------------------- ### Disable Overcommit for Scripts Source: https://github.com/sds/overcommit/blob/main/README.md Set the OVERCOMMIT_DISABLE environment variable to bypass hooks during script execution. ```bash OVERCOMMIT_DISABLE=1 ./my-custom-script ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.