diff --git a/hpccm/templates/git.py b/hpccm/templates/git.py index 8264007..90cd8ea 100644 --- a/hpccm/templates/git.py +++ b/hpccm/templates/git.py @@ -111,8 +111,13 @@ def clone_step(self, branch=None, commit=None, directory='', path='/tmp', if commit: clone.extend(['cd {0}'.format(posixpath.join(path, directory)), - 'git checkout {0}'.format(commit), - 'cd -']) + 'git checkout {0}'.format(commit)]) + if recursive: + # `git clone --recursive` initializes submodules for the + # initially cloned revision. Re-sync them after checking out + # a pinned commit, whose gitlinks may differ. + clone.append('git submodule update --init --recursive') + clone.append('cd -') # Add labels if the caller inherits from the labels template if callable(getattr(self, 'add_annotation', None)): diff --git a/test/test_git.py b/test/test_git.py index cbc0d3e..adefc26 100644 --- a/test/test_git.py +++ b/test/test_git.py @@ -59,6 +59,14 @@ def test_commit(self): verify='fatal'), 'mkdir -p /tmp && cd /tmp && git clone https://github.com/NVIDIA/hpc-container-maker.git hpc-container-maker && cd - && cd /tmp/hpc-container-maker && git checkout ac6ca95d0b20ed1efaffa6d58945a4dd2d80780c && cd -') + def test_commit_recursive(self): + """git with specified commit and recursive submodules""" + g = git() + self.assertEqual(g.clone_step(repository='https://github.com/NVIDIA/hpc-container-maker.git', + commit='ac6ca95d0b20ed1efaffa6d58945a4dd2d80780c', + recursive=True), + 'mkdir -p /tmp && cd /tmp && git clone --recursive https://github.com/NVIDIA/hpc-container-maker.git hpc-container-maker && cd - && cd /tmp/hpc-container-maker && git checkout ac6ca95d0b20ed1efaffa6d58945a4dd2d80780c && git submodule update --init --recursive && cd -') + def test_branch_and_commit(self): """git with both specified branch and specified commit""" g = git()