Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve master side git command. #301

Merged
merged 5 commits into from
Jan 20, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 31 additions & 8 deletions master/buildbot/steps/source/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#
# Copyright Buildbot Team Members

from twisted.python import log, failure
from twisted.python import log
from twisted.internet import defer

from buildbot.process import buildstep
Expand All @@ -25,7 +25,7 @@ class Git(Source):
name='git'
renderables = [ "repourl"]

def __init__(self, repourl=None, branch='master', mode='incremental',
def __init__(self, repourl=None, branch='HEAD', mode='incremental',
method=None, submodules=False, shallow=False, progress=False,
retryFetch=False, clobberOnFailure=False, **kwargs):
"""
Expand Down Expand Up @@ -88,7 +88,7 @@ def __init__(self, repourl=None, branch='master', mode='incremental',
assert self.method in ['clean', 'fresh', 'clobber', 'copy', None]

def startVC(self, branch, revision, patch):
self.branch = branch or 'master'
self.branch = branch or 'HEAD'
self.revision = revision
self.method = self._getMethod()
self.stdio_log = self.addLog("stdio")
Expand All @@ -104,6 +104,8 @@ def checkInstall(gitInstalled):
d.addCallback(lambda _: self.incremental())
elif self.mode == 'full':
d.addCallback(lambda _: self.full())
if patch:
d.addCallback(self.patch, patch)
d.addCallback(self.parseGotRevision)
d.addCallback(self.finish)
d.addErrback(self.failed)
Expand Down Expand Up @@ -169,6 +171,12 @@ def incremental(self):
self._dovccmd(['reset', '--hard', self.revision]))
yield wfd
wfd.getResult()

if self.branch != 'HEAD':
wfd = defer.waitForDeferred(
self._dovccmd(['branch', '-M', self.branch], abandonOnFailure=False))
yield wfd
wfd.getResult()
else:
wfd = defer.waitForDeferred(
self._doFetch(None))
Expand Down Expand Up @@ -256,11 +264,12 @@ def setrev(stdout):
d.addCallback(setrev)
return d

def _dovccmd(self, command, abandonOnFailure=True, collectStdout=False):
def _dovccmd(self, command, abandonOnFailure=True, collectStdout=False, extra_args={}):
cmd = buildstep.RemoteShellCommand(self.workdir, ['git'] + command,
env=self.env,
logEnviron=self.logEnviron,
collectStdout=collectStdout)
collectStdout=collectStdout,
**extra_args)
cmd.useLog(self.stdio_log, False)
log.msg("Starting git command : git %s" % (" ".join(command), ))
d = self.runCommand(cmd)
Expand Down Expand Up @@ -294,6 +303,20 @@ def checkout(_):
abandonOnFailure = not self.retryFetch and not self.clobberOnFailure
return self._dovccmd(command, abandonOnFailure)
d.addCallback(checkout)
def renameBranch(res):
if res != 0:
return res
d = self._dovccmd(['branch', '-M', self.branch], abandonOnFailure=False)
# Ignore errors
d.addCallback(lambda _: res)
return d

if self.branch != 'HEAD':
d.addCallback(renameBranch)
return d

def patch(self, _, patch):
d = self._dovccmd(['apply', '--index'], extra_args={'initial_stdin': patch})
return d

@defer.deferredGenerator
Expand Down Expand Up @@ -321,9 +344,9 @@ def _doFetch(self, _):

def _full(self):
if self.shallow:
command = ['clone', '--depth', '1', self.repourl, '.']
command = ['clone', '--depth', '1', '--branch', self.branch, self.repourl, '.']
else:
command = ['clone', self.repourl, '.']
command = ['clone', '--branch', self.branch, self.repourl, '.']
#Fix references
if self.prog:
command.append('--progress')
Expand All @@ -349,7 +372,7 @@ def clobber(res):
if self.clobberOnFailure:
return self.clobber()
else:
raise failure.Failure(res)
raise buildstep.BuildStepFailed()
else:
return res
d.addCallback(clobber)
Expand Down
5 changes: 4 additions & 1 deletion master/buildbot/test/fake/remotecommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ class FakeRemoteShellCommand(FakeLoggedRemoteCommand):
def __init__(self, workdir, command, env=None,
want_stdout=1, want_stderr=1,
timeout=DEFAULT_TIMEOUT, maxTime=DEFAULT_MAXTIME, logfiles={},
initial_stdin=None,
usePTY=DEFAULT_USEPTY, logEnviron=True, collectStdout=False):
args = dict(workdir=workdir, command=command, env=env or {},
want_stdout=want_stdout, want_stderr=want_stderr,
initial_stdin=initial_stdin,
timeout=timeout, maxTime=maxTime, logfiles=logfiles,
usePTY=usePTY, logEnviron=logEnviron)
FakeLoggedRemoteCommand.__init__(self, "shell", args,
Expand Down Expand Up @@ -255,11 +257,12 @@ class ExpectShell(ExpectLogged):
non-default arguments must be specified explicitly (e.g., usePTY).
"""
def __init__(self, workdir, command, env={},
want_stdout=1, want_stderr=1,
want_stdout=1, want_stderr=1, initial_stdin=None,
timeout=DEFAULT_TIMEOUT, maxTime=DEFAULT_MAXTIME, logfiles={},
usePTY=DEFAULT_USEPTY, logEnviron=True):
args = dict(workdir=workdir, command=command, env=env,
want_stdout=want_stdout, want_stderr=want_stderr,
initial_stdin=initial_stdin,
timeout=timeout, maxTime=maxTime, logfiles=logfiles,
usePTY=usePTY, logEnviron=logEnviron)
ExpectLogged.__init__(self, "shell", args)
Loading