sds/overcommit · error · Overcommit::Exceptions::InvalidGitRepo
is not a directory
Error message
is not a directory
What it means
The first check Installer#run performs on its target: File.expand_path(@target) must be an existing directory. If not, it raises InvalidGitRepo with the terse message 'is not a directory', which the CLI presents alongside the target path.
Source
Thrown at lib/overcommit/installer.rb:89
end
def old_hooks_path
File.join(hooks_path, 'old-hooks')
end
def master_hook_install_path
File.join(hooks_path, 'overcommit-hook')
end
def ensure_directory(path)
FileUtils.mkdir_p(path)
end
def validate_target
absolute_target = File.expand_path(@target)
unless File.directory?(absolute_target)
raise Overcommit::Exceptions::InvalidGitRepo, 'is not a directory'
end
git_dir_check = Dir.chdir(absolute_target) do
Overcommit::Utils.execute(%w[git rev-parse --git-dir])
end
unless git_dir_check.success?
raise Overcommit::Exceptions::InvalidGitRepo, 'does not appear to be a git repository'
end
end
def install_master_hook
FileUtils.mkdir_p(hooks_path)
FileUtils.cp(MASTER_HOOK, master_hook_install_path)
end
def uninstall_master_hook
FileUtils.rm_rf(master_hook_install_path, secure: true)View on GitHub (pinned to fee0cd74b2)
Solutions
- Re-run with the correct absolute path: 'overcommit --install /abs/path/to/repo'
- If the directory should exist, create it first: 'mkdir -p <target>' and retry
- Check scripts that build the target path for typos and unexpanded variables
Example fix
# before $ overcommit --install src/mrepo # typo, does not exist # after $ overcommit --install "$(pwd)/src/myrepo"
Defensive patterns
Strategy: validation
Validate before calling
target = File.expand_path(ARGV[0])
abort "#{target} is not a directory" unless File.directory?(target)
Overcommit::Installer.new(logger).run(target, action: :install) Type guard
def installable_target?(path) File.directory?(File.expand_path(path)) end
Try / catch
begin
installer.run(target, action: :install)
rescue Overcommit::Exceptions::InvalidGitRepo => e
abort "#{target}: #{e.message}"
end Prevention
- Expand paths to absolute form before passing them to the installer in scripts
- Validate user-supplied paths with File.directory? before invoking the CLI
When it happens
Trigger: 'overcommit --install <path>' (or --uninstall/--update) where <path> does not exist, is a file rather than a directory, or is a relative path resolved from the wrong working directory.
Common situations: Typo in an install script; passing a repo URL or archive path instead of a local directory; relative path used from a different cwd in CI or bootstrap scripts.
Related errors
- does not appear to be a git repository
- Class #{hook_name} is not a subclass of #{hook_base_class}.
- Unable to load hook '#{hook_name}': #{e}
- Unable to load hook '#{hook_name}': #{e}
- A load error occurred. Did you forget to install a gem? #{e.
AI-assisted analysis of sds/overcommit@fee0cd74b2 (2026-08-23).
Data as JSON: /api/errors/97695f8597ef665c.
Report an issue: GitHub.