Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Git: Support source-stamp patches.

Fixes #2093
  • Loading branch information...
commit eb7bf214767f95304b5ade9938fe369320c17eef 1 parent 45cd3ce
Tom Prince authored
11 master/buildbot/steps/source/git.py
@@ -104,6 +104,8 @@ def checkInstall(gitInstalled):
104 104 d.addCallback(lambda _: self.incremental())
105 105 elif self.mode == 'full':
106 106 d.addCallback(lambda _: self.full())
  107 + if patch:
  108 + d.addCallback(self.patch, patch)
107 109 d.addCallback(self.parseGotRevision)
108 110 d.addCallback(self.finish)
109 111 d.addErrback(self.failed)
@@ -260,11 +262,12 @@ def setrev(stdout):
260 262 d.addCallback(setrev)
261 263 return d
262 264
263   - def _dovccmd(self, command, abandonOnFailure=True, collectStdout=False):
  265 + def _dovccmd(self, command, abandonOnFailure=True, collectStdout=False, extra_args={}):
264 266 cmd = buildstep.RemoteShellCommand(self.workdir, ['git'] + command,
265 267 env=self.env,
266 268 logEnviron=self.logEnviron,
267   - collectStdout=collectStdout)
  269 + collectStdout=collectStdout,
  270 + **extra_args)
268 271 cmd.useLog(self.stdio_log, False)
269 272 log.msg("Starting git command : git %s" % (" ".join(command), ))
270 273 d = self.runCommand(cmd)
@@ -310,6 +313,10 @@ def renameBranch(res):
310 313 d.addCallback(renameBranch)
311 314 return d
312 315
  316 + def patch(self, _, patch):
  317 + d = self._dovccmd(['apply', '--index'], extra_args={'initial_stdin': patch})
  318 + return d
  319 +
313 320 @defer.deferredGenerator
314 321 def _doFetch(self, _):
315 322 """
5 master/buildbot/test/fake/remotecommand.py
@@ -56,9 +56,11 @@ class FakeRemoteShellCommand(FakeLoggedRemoteCommand):
56 56 def __init__(self, workdir, command, env=None,
57 57 want_stdout=1, want_stderr=1,
58 58 timeout=DEFAULT_TIMEOUT, maxTime=DEFAULT_MAXTIME, logfiles={},
  59 + initial_stdin=None,
59 60 usePTY=DEFAULT_USEPTY, logEnviron=True, collectStdout=False):
60 61 args = dict(workdir=workdir, command=command, env=env or {},
61 62 want_stdout=want_stdout, want_stderr=want_stderr,
  63 + initial_stdin=initial_stdin,
62 64 timeout=timeout, maxTime=maxTime, logfiles=logfiles,
63 65 usePTY=usePTY, logEnviron=logEnviron)
64 66 FakeLoggedRemoteCommand.__init__(self, "shell", args,
@@ -255,11 +257,12 @@ class ExpectShell(ExpectLogged):
255 257 non-default arguments must be specified explicitly (e.g., usePTY).
256 258 """
257 259 def __init__(self, workdir, command, env={},
258   - want_stdout=1, want_stderr=1,
  260 + want_stdout=1, want_stderr=1, initial_stdin=None,
259 261 timeout=DEFAULT_TIMEOUT, maxTime=DEFAULT_MAXTIME, logfiles={},
260 262 usePTY=DEFAULT_USEPTY, logEnviron=True):
261 263 args = dict(workdir=workdir, command=command, env=env,
262 264 want_stdout=want_stdout, want_stderr=want_stderr,
  265 + initial_stdin=initial_stdin,
263 266 timeout=timeout, maxTime=maxTime, logfiles=logfiles,
264 267 usePTY=usePTY, logEnviron=logEnviron)
265 268 ExpectLogged.__init__(self, "shell", args)
67 master/buildbot/test/unit/test_steps_source_git.py
@@ -58,6 +58,73 @@ def test_mode_full_clean(self):
58 58 self.expectOutcome(result=SUCCESS, status_text=["update"])
59 59 return self.runStep()
60 60
  61 + def test_mode_full_clean_patch(self):
  62 + self.setupStep(
  63 + git.Git(repourl='http://github.com/buildbot/buildbot.git',
  64 + mode='full', method='clean'),
  65 + patch = 'patch')
  66 + self.expectCommands(
  67 + ExpectShell(workdir='wkdir',
  68 + command=['git', '--version'])
  69 + + 0,
  70 + ExpectLogged('stat', dict(file='wkdir/.git',
  71 + logEnviron=True))
  72 + + 0,
  73 + ExpectShell(workdir='wkdir',
  74 + command=['git', 'clean', '-f', '-d'])
  75 + + 0,
  76 + ExpectShell(workdir='wkdir',
  77 + command=['git', 'fetch', '-t',
  78 + 'http://github.com/buildbot/buildbot.git',
  79 + 'HEAD'])
  80 + + 0,
  81 + ExpectShell(workdir='wkdir',
  82 + command=['git', 'reset', '--hard', 'FETCH_HEAD'])
  83 + + 0,
  84 + ExpectShell(workdir='wkdir',
  85 + command=['git', 'apply', '--index'],
  86 + initial_stdin='patch')
  87 + + 0,
  88 + ExpectShell(workdir='wkdir',
  89 + command=['git', 'rev-parse', 'HEAD'])
  90 + + ExpectShell.log('stdio',
  91 + stdout='f6ad368298bd941e934a41f3babc827b2aa95a1d')
  92 + + 0,
  93 + )
  94 + self.expectOutcome(result=SUCCESS, status_text=["update"])
  95 + return self.runStep()
  96 +
  97 + def test_mode_full_clean_patch_fail(self):
  98 + self.setupStep(
  99 + git.Git(repourl='http://github.com/buildbot/buildbot.git',
  100 + mode='full', method='clean'),
  101 + patch = 'patch')
  102 + self.expectCommands(
  103 + ExpectShell(workdir='wkdir',
  104 + command=['git', '--version'])
  105 + + 0,
  106 + ExpectLogged('stat', dict(file='wkdir/.git',
  107 + logEnviron=True))
  108 + + 0,
  109 + ExpectShell(workdir='wkdir',
  110 + command=['git', 'clean', '-f', '-d'])
  111 + + 0,
  112 + ExpectShell(workdir='wkdir',
  113 + command=['git', 'fetch', '-t',
  114 + 'http://github.com/buildbot/buildbot.git',
  115 + 'HEAD'])
  116 + + 0,
  117 + ExpectShell(workdir='wkdir',
  118 + command=['git', 'reset', '--hard', 'FETCH_HEAD'])
  119 + + 0,
  120 + ExpectShell(workdir='wkdir',
  121 + command=['git', 'apply', '--index'],
  122 + initial_stdin='patch')
  123 + + 1,
  124 + )
  125 + self.expectOutcome(result=FAILURE, status_text=["updating"])
  126 + return self.runStep()
  127 +
61 128 def test_mode_full_clean_branch(self):
62 129 self.setupStep(
63 130 git.Git(repourl='http://github.com/buildbot/buildbot.git',
4 master/buildbot/test/util/sourcesteps.py
@@ -38,7 +38,7 @@ def tearDownSourceStep(self):
38 38
39 39 # utilities
40 40
41   - def setupStep(self, step, args={}, **kwargs):
  41 + def setupStep(self, step, args={}, patch=None, **kwargs):
42 42 """
43 43 Set up C{step} for testing. This calls L{BuildStepMixin}'s C{setupStep}
44 44 and then does setup specific to a Source step.
@@ -51,7 +51,7 @@ def setupStep(self, step, args={}, **kwargs):
51 51 ss.revision = args.get('revision', None)
52 52 ss.project = ''
53 53 ss.repository = ''
54   - ss.patch = None
  54 + ss.patch = patch
55 55 ss.patch_info = None
56 56 ss.changes = []
57 57

0 comments on commit eb7bf21

Please sign in to comment.
Something went wrong with that request. Please try again.