Skip to content

Commit

Permalink
Merge branch 'git_config' of git://github.com/andrewjcg/buildbot
Browse files Browse the repository at this point in the history
  • Loading branch information
djmitche committed Apr 3, 2013
2 parents 3ebf87b + 9205de5 commit 9ec2372
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 8 deletions.
27 changes: 19 additions & 8 deletions master/buildbot/steps/source/git.py
Expand Up @@ -16,7 +16,7 @@
from twisted.python import log
from twisted.internet import defer

from buildbot import config
from buildbot import config as bbconfig
from buildbot.process import buildstep
from buildbot.steps.source.base import Source
from buildbot.interfaces import BuildSlaveTooOldError
Expand Down Expand Up @@ -62,7 +62,7 @@ class Git(Source):
def __init__(self, repourl=None, branch='HEAD', mode='incremental',
method=None, submodules=False, shallow=False, progress=False,
retryFetch=False, clobberOnFailure=False, getDescription=False,
**kwargs):
config=None, **kwargs):
"""
@type repourl: string
@param repourl: the URL which points at the git repository
Expand Down Expand Up @@ -95,6 +95,9 @@ def __init__(self, repourl=None, branch='HEAD', mode='incremental',
@type getDescription: boolean or dict
@param getDescription: Use 'git describe' to describe the fetched revision
@type config: dict
@param config: Git configuration options to enable when running git
"""
if not getDescription and not isinstance(getDescription, dict):
getDescription = False
Expand All @@ -110,19 +113,20 @@ def __init__(self, repourl=None, branch='HEAD', mode='incremental',
self.clobberOnFailure = clobberOnFailure
self.mode = mode
self.getDescription = getDescription
self.config = config
Source.__init__(self, **kwargs)

if self.mode not in ['incremental', 'full']:
config.error("Git: mode must be 'incremental' or 'full'.")
bbconfig.error("Git: mode must be 'incremental' or 'full'.")
if not self.repourl:
config.error("Git: must provide repourl.")
bbconfig.error("Git: must provide repourl.")
if (self.mode == 'full' and
self.method not in ['clean', 'fresh', 'clobber', 'copy', None]):
config.error("Git: invalid method for mode 'full'.")
bbconfig.error("Git: invalid method for mode 'full'.")
if self.shallow and (self.mode != 'full' or self.method != 'clobber'):
config.error("Git: shallow only possible with mode 'full' and method 'clobber'.")
bbconfig.error("Git: shallow only possible with mode 'full' and method 'clobber'.")
if not isinstance(self.getDescription, (bool, dict)):
config.error("Git: getDescription must be a boolean or a dict.")
bbconfig.error("Git: getDescription must be a boolean or a dict.")

def startVC(self, branch, revision, patch):
self.branch = branch or 'HEAD'
Expand Down Expand Up @@ -292,7 +296,14 @@ def parseCommitDescription(self, _=None):
defer.returnValue(0)

def _dovccmd(self, command, abandonOnFailure=True, collectStdout=False, initialStdin=None):
cmd = buildstep.RemoteShellCommand(self.workdir, ['git'] + command,
full_command = ['git']
if self.config is not None:
for name, value in self.config.iteritems():
full_command.append('-c')
full_command.append('%s=%s' % (name, value))
full_command.extend(command)
cmd = buildstep.RemoteShellCommand(self.workdir,
full_command,
env=self.env,
logEnviron=self.logEnviron,
timeout=self.timeout,
Expand Down
36 changes: 36 additions & 0 deletions master/buildbot/test/unit/test_steps_source_git.py
Expand Up @@ -1419,3 +1419,39 @@ def test_getDescription_lotsa_stuff(self):
codebase='baz'
)
return self.runStep()

def test_config_option(self):
name = 'url.http://github.com.insteadOf'
value = 'blahblah'
self.setupStep(
git.Git(repourl='%s/buildbot/buildbot.git' % (value,),
mode='full', method='clean',
config={name: value}))
prefix = ['git', '-c', '%s=%s' % (name, value)]
self.expectCommands(
ExpectShell(workdir='wkdir',
command=prefix + ['--version'])
+ 0,
Expect('stat', dict(file='wkdir/.git',
logEnviron=True))
+ 0,
ExpectShell(workdir='wkdir',
command=prefix + ['clean', '-f', '-d'])
+ 0,
ExpectShell(workdir='wkdir',
command=prefix + ['fetch', '-t',
'%s/buildbot/buildbot.git' % (value,),
'HEAD'])
+ 0,
ExpectShell(workdir='wkdir',
command=prefix + ['reset', '--hard',
'FETCH_HEAD', '--'])
+ 0,
ExpectShell(workdir='wkdir',
command=prefix + ['rev-parse', 'HEAD'])
+ ExpectShell.log('stdio',
stdout='f6ad368298bd941e934a41f3babc827b2aa95a1d')
+ 0,
)
self.expectOutcome(result=SUCCESS, status_text=["update"])
return self.runStep()
4 changes: 4 additions & 0 deletions master/docs/manual/cfg-buildsteps.rst
Expand Up @@ -443,6 +443,10 @@ The Git step takes the following arguments:
* ``abbrev=7``: `--abbrev=7`
* ``candidates=7``: `--candidates=7`
* ``dirty=foo``: `--dirty=foo`

``config``

(optional) A dict of git configuration settings to pass to the remote git commands.

.. bb:step:: SVN
Expand Down
2 changes: 2 additions & 0 deletions master/docs/relnotes/index.rst
Expand Up @@ -53,6 +53,8 @@ Features
only a single property and therefore allows commas to be included in the property
name and value.

* The ``Git`` step has a new ``config`` option, which accepts a dict of git configuration options to
pass to the low-level git commands. See :bb:step:`Git` for details.

Deprecations, Removals, and Non-Compatible Changes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down

0 comments on commit 9ec2372

Please sign in to comment.