Skip to content

Commit

Permalink
git: Update git submodules with --checkout
Browse files Browse the repository at this point in the history
Git 1.7.8 and newer allows submodules to be updated by other commands
than "git checkout". When this behavior is configured in .gitmodules,
buildbot can end up with incorrect commit checked out in the submodule.

Fix this by explicitly specifying --checkout option to "git submodule
update".
  • Loading branch information
wentasah committed Apr 27, 2015
1 parent 0955631 commit a310e30
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 2 deletions.
9 changes: 7 additions & 2 deletions master/buildbot/steps/source/git.py
Expand Up @@ -125,6 +125,7 @@ def __init__(self, repourl=None, branch='HEAD', mode='incremental', method=None,
self.getDescription = getDescription
self.config = config
self.supportsBranch = True
self.supportsSubmoduleCheckout = True
self.srcdir = 'source'
Source.__init__(self, **kwargs)

Expand Down Expand Up @@ -534,8 +535,10 @@ def _syncSubmodule(self, _=None):

def _updateSubmodule(self, _=None):
if self.submodules:
return self._dovccmd(['submodule', 'update',
'--init', '--recursive', '--force'])
vccmd = ['submodule', 'update', '--init', '--recursive', '--force']
if self.supportsSubmoduleCheckout:
vccmd.extend(['--checkout'])
return self._dovccmd(vccmd)
else:
return defer.succeed(0)

Expand Down Expand Up @@ -567,6 +570,8 @@ def checkSupport(stdout):
version = stdout.strip().split(' ')[2]
if LooseVersion(version) < LooseVersion("1.6.5"):
self.supportsBranch = False
if LooseVersion(version) < LooseVersion("1.7.8"):
self.supportsSubmoduleCheckout = False
return gitInstalled
return d

Expand Down
50 changes: 50 additions & 0 deletions master/buildbot/test/unit/test_steps_source_git.py
Expand Up @@ -950,6 +950,56 @@ def test_mode_full_fresh_submodule(self):
self.expectProperty('got_revision', 'f6ad368298bd941e934a41f3babc827b2aa95a1d', 'Git')
return self.runStep()

def test_mode_full_fresh_submodule_v1_7_8(self):
"""This tests the same as test_mode_full_fresh_submodule, but the
"submodule update" command should be different for Git v1.7.8+."""
self.setupStep(
git.Git(repourl='http://github.com/buildbot/buildbot.git',
mode='full', method='fresh', submodules=True))
self.expectCommands(
ExpectShell(workdir='wkdir',
command=['git', '--version'])
+ ExpectShell.log('stdio',
stdout='git version 1.7.8')
+ 0,
Expect('stat', dict(file='wkdir/.buildbot-patched',
logEnviron=True))
+ 1,
Expect('listdir', {'dir': 'wkdir', 'logEnviron': True,
'timeout': 1200})
+ Expect.update('files', ['.git'])
+ 0,
ExpectShell(workdir='wkdir',
command=['git', 'clean', '-f', '-f', '-d', '-x'])
+ 0,
ExpectShell(workdir='wkdir',
command=['git', 'fetch', '-t',
'http://github.com/buildbot/buildbot.git',
'HEAD'])
+ 0,
ExpectShell(workdir='wkdir',
command=['git', 'reset', '--hard', 'FETCH_HEAD', '--'])
+ 0,
ExpectShell(workdir='wkdir',
command=['git', 'submodule', 'sync'])
+ 0,
ExpectShell(workdir='wkdir',
command=['git', 'submodule', 'update', '--init', '--recursive', '--force', '--checkout'])
+ 0,
ExpectShell(workdir='wkdir',
command=['git', 'submodule', 'foreach', '--recursive', 'git', 'clean',
'-f', '-f', '-d', '-x'])
+ 0,
ExpectShell(workdir='wkdir',
command=['git', 'rev-parse', 'HEAD'])
+ ExpectShell.log('stdio',
stdout='f6ad368298bd941e934a41f3babc827b2aa95a1d')
+ 0,
)
self.expectOutcome(result=SUCCESS)
self.expectProperty('got_revision', 'f6ad368298bd941e934a41f3babc827b2aa95a1d', 'Git')
return self.runStep()

def test_mode_full_clobber_shallow(self):
self.setupStep(
git.Git(repourl='http://github.com/buildbot/buildbot.git',
Expand Down

0 comments on commit a310e30

Please sign in to comment.