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

Unable to cleanup working tree after #{hook_script_name} hoo

Error message

Unable to cleanup working tree after #{hook_script_name} hooks run:
STDOUT:#{result.stdout}
STDERR:#{result.stderr}

What it means

Error "Unable to cleanup working tree after #{hook_script_name} hooks run: STDOUT:#{result.stdout} STDERR:#{result.stderr}" thrown in sds/overcommit.

Source

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

      # 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

      # Clears the working tree so that the stash can be applied.
      def clear_working_tree
        removed_submodules = Overcommit::GitRepo.staged_submodule_removals

        result = Overcommit::Utils.execute(%w[git reset --hard])
        unless result.success?
          raise Overcommit::Exceptions::HookCleanupFailed,
                "Unable to cleanup working tree after #{hook_script_name} hooks run:" \
                "\nSTDOUT:#{result.stdout}\nSTDERR:#{result.stderr}"
        end

        # Hard-resetting a staged submodule removal results in the index being
        # reset but the submodule being restored as an empty directory. This empty
        # directory prevents us from stashing on a subsequent run if a hook fails.
        #
        # Work around this by removing these empty submodule directories as there
        # doesn't appear any reason to keep them around.
        removed_submodules.each do |submodule|
          FileUtils.rmdir(submodule.path)
        end
      end

      # Applies the stash to the working tree to restore the user's state.
      def restore_working_tree
        result = Overcommit::Utils.execute(%w[git stash pop --index])

View on GitHub (pinned to fee0cd74b2)

Solutions

  1. Read the STDOUT/STDERR shown for the failing `git reset --hard` command to find the root cause.
  2. Check the working tree manually (`git status`, `git stash list`); your unstaged changes are still in the overcommit stash.
  3. Remove file locks or permission problems that prevent git from resetting the working tree, then rerun.

When it happens

Trigger: Thrown at lib/overcommit/hook_context/helpers/stash_unstaged_changes.rb:117 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/9b442936f7965307. Report an issue: GitHub.