{"record":{"id":"65492fd7a15248d4","repo":"sds/overcommit","slug":"unable-to-restore-working-tree-after-hook-script","errorCode":null,"errorMessage":"Unable to restore working tree after #{hook_script_name} hooks run:\nSTDOUT:#{result.stdout}\nSTDERR:#{result.stderr}","messagePattern":"Unable to restore 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":137,"sourceCode":"                \"\\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])\n        unless result.success?\n          raise Overcommit::Exceptions::HookCleanupFailed,\n                \"Unable to restore working tree after #{hook_script_name} hooks run:\" \\\n                \"\\nSTDOUT:#{result.stdout}\\nSTDERR:#{result.stderr}\"\n        end\n      end\n    end\n  end\nend\n","sourceCodeStart":119,"sourceCodeEnd":145,"githubUrl":"https://github.com/sds/overcommit/blob/fee0cd74b26eb81f64b43b7fab17bbb541575cc4/lib/overcommit/hook_context/helpers/stash_unstaged_changes.rb#L119-L145","documentation":"Error \"Unable to restore 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:137 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Read the STDOUT/STDERR shown for the failing `git stash pop` command; your unstaged changes are still in the overcommit stash.","Run `git stash list` and `git stash pop` manually to recover the unstaged changes.","Resolve conflicts or file locks that prevented the automatic restore, then rerun the hook."],"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"}