Skip to content

Commit a0acb22

Browse files
committed
tests(submodule): add new submodule commits
It's somewhat more complex to add new commits in submodules to the parent repository. The new test shows how to do that in a 'GitPythonic' way. Related to gitpython-developers#335
1 parent b2e4134 commit a0acb22

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

git/test/test_submodule.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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):
665665
parent = git.Repo.init(os.path.join(rwdir, 'parent'))
666666
parent.git.submodule('add', self._small_repo_url(), 'module')
667667
parent.index.commit("added submodule")
@@ -686,6 +686,37 @@ def test_git_submodules(self, rwdir):
686686
sm.move(sm.path + '_moved')
687687
sm2.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
690721
def test_git_submodule_compatibility(self, rwdir):
691722
parent = git.Repo.init(os.path.join(rwdir, 'parent'))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy