Skip to content

Commit b00ad00

Browse files
committed
submodule: When adding an existing submodule, when retrieving the binsha, we will now consider not only the tree, but the index too
1 parent 2ab454f commit b00ad00

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/git/objects/submodule/base.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,15 @@ def add(cls, repo, name, path, url=None, branch=None, no_checkout=False):
215215
sm = cls(repo, cls.NULL_BIN_SHA, cls.k_default_mode, path, name)
216216
if sm.exists():
217217
# reretrieve submodule from tree
218-
return repo.head.commit.tree[path]
218+
try:
219+
return repo.head.commit.tree[path]
220+
except KeyError:
221+
# could only be in index
222+
index = repo.index
223+
entry = index.entries[index.entry_key(path, 0)]
224+
sm.binsha = entry.binsha
225+
return sm
226+
# END handle exceptions
219227
# END handle existing
220228

221229
br = mkhead(repo, branch or cls.k_head_default)

0 commit comments

Comments
 (0)