Skip to content

Commit 59fa73b

Browse files
committed
Remove restored empty submodules
1 parent 5916e2c commit 59fa73b

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lib/overcommit/hook_context/pre_commit.rb

+12
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,24 @@ def modified_lines_in_file(file)
121121

122122
# Clears the working tree so that the stash can be applied.
123123
def clear_working_tree
124+
removed_submodules = Overcommit::GitRepo.staged_submodule_removals
125+
124126
result = Overcommit::Utils.execute(%w[git reset --hard])
125127
unless result.success?
126128
raise Overcommit::Exceptions::HookCleanupFailed,
127129
"Unable to cleanup working tree after #{hook_script_name} hooks run:" \
128130
"\nSTDOUT:#{result.stdout}\nSTDERR:#{result.stderr}"
129131
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
130142
end
131143

132144
# Applies the stash to the working tree to restore the user's state.

0 commit comments

Comments
 (0)