Skip to content

Commit 61e5d36

Browse files
committed
Fix GitRepo specs for git < 1.8.5
`git` < 1.8.5 does not update the `.gitmodules` file with submodule changes, so when we are looking at the current state of the work tree we need to check if the submodule actually exists via another method, since the `.gitmodules` file we parsed does not represent reality. At some point we're likely going to want to have a helper that provides a convenient way for us to conditionally run code based on the `git` version Overcommit is using.
1 parent 56f7339 commit 61e5d36

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

lib/overcommit/git_repo.rb

+11
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,17 @@ def submodules(options = {})
229229

230230
modules = []
231231
IniParse.parse(`git show #{ref}:.gitmodules`).each do |section|
232+
# git < 1.8.5 does not update the .gitmodules file with submodule
233+
# changes, so when we are looking at the current state of the work tree,
234+
# we need to check if the submodule actually exists via another method,
235+
# since the .gitmodules file we parsed does not represent reality.
236+
unless ref
237+
result = Overcommit::Utils.execute(%W[
238+
git submodule status #{section['path']}
239+
])
240+
next unless result.success?
241+
end
242+
232243
modules << Submodule.new(section['path'], section['url'])
233244
end
234245

0 commit comments

Comments
 (0)