@@ -661,7 +661,7 @@ def test_add_empty_repo(self, rwdir):
661661# end for each checkout mode
662662
663663@with_rw_directory
664- def test_git_submodules (self ,rwdir ):
664+ def test_git_submodules_and_add_sm_with_new_commit (self ,rwdir ):
665665parent = git .Repo .init (os .path .join (rwdir ,'parent' ))
666666parent .git .submodule ('add' ,self ._small_repo_url (),'module' )
667667parent .index .commit ("added submodule" )
@@ -686,6 +686,37 @@ def test_git_submodules(self, rwdir):
686686sm .move (sm .path + '_moved' )
687687sm2 .move (sm2 .path + '_moved' )
688688
689+ parent .index .commit ("moved submodules" )
690+
691+ smm = sm .module ()
692+ fp = os .path .join (smm .working_tree_dir ,'empty-file' )
693+ with open (fp ,'w' ):
694+ pass
695+ smm .git .add (fp )
696+ smm .git .commit (m = "new file added" )
697+
698+ # submodules are retrieved from the current commit's tree, therefore we can't really get a new submodule
699+ # object pointing to the new submodule commit
700+ sm_too = parent .submodules [0 ]
701+ assert parent .head .commit .tree [sm .path ].binsha == sm .binsha
702+ assert sm_too .binsha == sm .binsha ,"cached submodule should point to the same commit as updated one"
703+
704+ added_bies = parent .index .add ([sm ])# addded base-index-entries
705+ assert len (added_bies )== 1
706+ parent .index .commit ("add same submodule entry" )
707+ commit_sm = parent .head .commit .tree [sm .path ]
708+ assert commit_sm .binsha == added_bies [0 ].binsha
709+ assert commit_sm .binsha == sm .binsha
710+
711+ sm_too .binsha = sm_too .module ().head .commit .binsha
712+ added_bies = parent .index .add ([sm_too ])
713+ assert len (added_bies )== 1
714+ parent .index .commit ("add new submodule entry" )
715+ commit_sm = parent .head .commit .tree [sm .path ]
716+ assert commit_sm .binsha == added_bies [0 ].binsha
717+ assert commit_sm .binsha == sm_too .binsha
718+ assert sm_too .binsha != sm .binsha
719+
689720@with_rw_directory
690721def test_git_submodule_compatibility (self ,rwdir ):
691722parent = git .Repo .init (os .path .join (rwdir ,'parent' ))