File tree 1 file changed +12
-0
lines changed
lib/overcommit/hook_context
1 file changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -121,12 +121,24 @@ def modified_lines_in_file(file)
121
121
122
122
# Clears the working tree so that the stash can be applied.
123
123
def clear_working_tree
124
+ removed_submodules = Overcommit ::GitRepo . staged_submodule_removals
125
+
124
126
result = Overcommit ::Utils . execute ( %w[ git reset --hard ] )
125
127
unless result . success?
126
128
raise Overcommit ::Exceptions ::HookCleanupFailed ,
127
129
"Unable to cleanup working tree after #{ hook_script_name } hooks run:" \
128
130
"\n STDOUT:#{ result . stdout } \n STDERR:#{ result . stderr } "
129
131
end
132
+
133
+ # Hard-resetting a staged submodule removal results in the index being
134
+ # reset but the submodule being restored as an empty directory. This empty
135
+ # directory prevents us from stashing on a subsequent run if a hook fails.
136
+ #
137
+ # Work around this by removing these empty submodule directories as there
138
+ # doesn't appear any reason to keep them around.
139
+ removed_submodules . each do |submodule |
140
+ `rm -rf #{ submodule . path } `
141
+ end
130
142
end
131
143
132
144
# Applies the stash to the working tree to restore the user's state.
You can’t perform that action at this time.
0 commit comments