{"record":{"id":"9b442936f7965307","repo":"sds/overcommit","slug":"unable-to-cleanup-working-tree-after-hook-script","errorCode":null,"errorMessage":"Unable to cleanup working tree after #{hook_script_name} hooks run:\nSTDOUT:#{result.stdout}\nSTDERR:#{result.stderr}","messagePattern":"Unable to cleanup working tree after #(.+?) hooks run:\nSTDOUT:#(.+?)\nSTDERR:#(.+?)","errorType":"exception","errorClass":"Overcommit::Exceptions::HookCleanupFailed","httpStatus":null,"severity":"error","filePath":"lib/overcommit/hook_context/helpers/stash_unstaged_changes.rb","lineNumber":117,"sourceCode":"\n      # Restores the file modification times for all modified files to make it\n      # appear like they never changed.\n      def restore_modified_times\n        @modified_times.each do |file, time|\n          next if Overcommit::Utils.broken_symlink?(file)\n          next unless File.exist?(file)\n\n          File.utime(time, time, file)\n        end\n      end\n\n      # Clears the working tree so that the stash can be applied.\n      def clear_working_tree\n        removed_submodules = Overcommit::GitRepo.staged_submodule_removals\n\n        result = Overcommit::Utils.execute(%w[git reset --hard])\n        unless result.success?\n          raise Overcommit::Exceptions::HookCleanupFailed,\n                \"Unable to cleanup working tree after #{hook_script_name} hooks run:\" \\\n                \"\\nSTDOUT:#{result.stdout}\\nSTDERR:#{result.stderr}\"\n        end\n\n        # Hard-resetting a staged submodule removal results in the index being\n        # reset but the submodule being restored as an empty directory. This empty\n        # directory prevents us from stashing on a subsequent run if a hook fails.\n        #\n        # Work around this by removing these empty submodule directories as there\n        # doesn't appear any reason to keep them around.\n        removed_submodules.each do |submodule|\n          FileUtils.rmdir(submodule.path)\n        end\n      end\n\n      # Applies the stash to the working tree to restore the user's state.\n      def restore_working_tree\n        result = Overcommit::Utils.execute(%w[git stash pop --index])","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/sds/overcommit/blob/fee0cd74b26eb81f64b43b7fab17bbb541575cc4/lib/overcommit/hook_context/helpers/stash_unstaged_changes.rb#L99-L135","documentation":"Error \"Unable to cleanup working tree after #{hook_script_name} hooks run:\nSTDOUT:#{result.stdout}\nSTDERR:#{result.stderr}\" thrown in sds/overcommit.","triggerScenarios":"Thrown at lib/overcommit/hook_context/helpers/stash_unstaged_changes.rb:117 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Read the STDOUT/STDERR shown for the failing `git reset --hard` command to find the root cause.","Check the working tree manually (`git status`, `git stash list`); your unstaged changes are still in the overcommit stash.","Remove file locks or permission problems that prevent git from resetting the working tree, then rerun."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"fee0cd74b26eb81f64b43b7fab17bbb541575cc4","analyzedAt":"2026-08-23T04:07:28.153Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}