sds/overcommit · error · Overcommit::Exceptions::HookSetupFailed

Unable to setup environment for #{hook_script_name} hook run

Error message

Unable to setup environment for #{hook_script_name} hook run:
STDOUT:#{result.stdout}
STDERR:#{result.stderr}

What it means

Error "Unable to setup environment for #{hook_script_name} hook run: STDOUT:#{result.stdout} STDERR:#{result.stderr}" thrown in sds/overcommit.

Source

Thrown at lib/overcommit/hook_context/helpers/stash_unstaged_changes.rb:92

      def unstaged_changes?
        result = Overcommit::Utils.execute(%w[git --no-pager diff --quiet])
        !result.success?
      end

      def stash_changes
        @stash_attempted = true

        stash_message = "Overcommit: Stash of repo state before hook run at #{Time.now}"
        result = Overcommit::Utils.with_environment('GIT_LITERAL_PATHSPECS' => '0') do
          Overcommit::Utils.execute(
            %w[git -c commit.gpgsign=false stash save --keep-index --quiet] + [stash_message]
          )
        end

        unless result.success?
          # Failure to stash in this case is likely due to a configuration
          # issue (e.g. author/email not set or GPG signing key incorrect)
          raise Overcommit::Exceptions::HookSetupFailed,
                "Unable to setup environment for #{hook_script_name} hook run:" \
                "\nSTDOUT:#{result.stdout}\nSTDERR:#{result.stderr}"
        end

        @changes_stashed = `git stash list -1`.include?(stash_message)
      end

      # Restores the file modification times for all modified files to make it
      # appear like they never changed.
      def restore_modified_times
        @modified_times.each do |file, time|
          next if Overcommit::Utils.broken_symlink?(file)
          next unless File.exist?(file)

          File.utime(time, time, file)
        end
      end

View on GitHub (pinned to fee0cd74b2)

Solutions

  1. Read the STDOUT/STDERR shown for the failing `git stash save` command; common causes are missing git author/email config or a broken GPG signing setup.
  2. Set user.name and user.email in git config, or disable commit.gpgsign, so git can create the stash commit.
  3. Clean up the working tree (commit, stash, or remove problematic files) and rerun the hook.

When it happens

Trigger: Thrown at lib/overcommit/hook_context/helpers/stash_unstaged_changes.rb:92 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of sds/overcommit@fee0cd74b2 (2026-08-23). Data as JSON: /api/errors/96f7ea241ca69029. Report an issue: GitHub.