diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2015-08-08 23:02:38 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2015-08-08 23:03:48 +0200 |
commit | a0acb2229e1ebb59ab343e266fc5c1cc392a974e (patch) | |
tree | 08df78354f847da80b6ee21978f90c07afb23e02 /git/test/test_submodule.py | |
parent | b2e4134963c971e3259137b84237d6c47964b018 (diff) | |
download | gitpython-a0acb2229e1ebb59ab343e266fc5c1cc392a974e.tar.gz |
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 #335
Diffstat (limited to 'git/test/test_submodule.py')
-rw-r--r-- | git/test/test_submodule.py | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/git/test/test_submodule.py b/git/test/test_submodule.py index cbf38c18..3d78d067 100644 --- a/git/test/test_submodule.py +++ b/git/test/test_submodule.py @@ -661,7 +661,7 @@ class TestSubmodule(TestBase): # end for each checkout mode @with_rw_directory - def test_git_submodules(self, rwdir): + def test_git_submodules_and_add_sm_with_new_commit(self, rwdir): parent = git.Repo.init(os.path.join(rwdir, 'parent')) parent.git.submodule('add', self._small_repo_url(), 'module') parent.index.commit("added submodule") @@ -686,6 +686,37 @@ class TestSubmodule(TestBase): sm.move(sm.path + '_moved') sm2.move(sm2.path + '_moved') + parent.index.commit("moved submodules") + + smm = sm.module() + fp = os.path.join(smm.working_tree_dir, 'empty-file') + with open(fp, 'w'): + pass + smm.git.add(fp) + smm.git.commit(m="new file added") + + # submodules are retrieved from the current commit's tree, therefore we can't really get a new submodule + # object pointing to the new submodule commit + sm_too = parent.submodules[0] + assert parent.head.commit.tree[sm.path].binsha == sm.binsha + assert sm_too.binsha == sm.binsha, "cached submodule should point to the same commit as updated one" + + added_bies = parent.index.add([sm]) # addded base-index-entries + assert len(added_bies) == 1 + parent.index.commit("add same submodule entry") + commit_sm = parent.head.commit.tree[sm.path] + assert commit_sm.binsha == added_bies[0].binsha + assert commit_sm.binsha == sm.binsha + + sm_too.binsha = sm_too.module().head.commit.binsha + added_bies = parent.index.add([sm_too]) + assert len(added_bies) == 1 + parent.index.commit("add new submodule entry") + commit_sm = parent.head.commit.tree[sm.path] + assert commit_sm.binsha == added_bies[0].binsha + assert commit_sm.binsha == sm_too.binsha + assert sm_too.binsha != sm.binsha + @with_rw_directory def test_git_submodule_compatibility(self, rwdir): parent = git.Repo.init(os.path.join(rwdir, 'parent')) |