Skip to content

Commit

Permalink
Merge pull request #1680 from jaredgrubb/git-origin-eight
Browse files Browse the repository at this point in the history
[eight backport] Git: add 'origin' option
  • Loading branch information
Mikhail Sobolev committed May 20, 2015
2 parents 6558cd5 + 62f5c03 commit 8df4ed3
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 8 deletions.
22 changes: 14 additions & 8 deletions master/buildbot/steps/source/git.py
Expand Up @@ -66,11 +66,11 @@ class Git(Source):

""" Class for Git with all the smarts """
name = 'git'
renderables = ["repourl", "reference", "branch", "codebase", "mode", "method"]
renderables = ["repourl", "reference", "branch", "codebase", "mode", "method", "origin"]

def __init__(self, repourl=None, branch='HEAD', mode='incremental', method=None,
reference=None, submodules=False, shallow=False, progress=False, retryFetch=False,
clobberOnFailure=False, getDescription=False, config=None, **kwargs):
clobberOnFailure=False, getDescription=False, config=None, origin=None, **kwargs):
"""
@type repourl: string
@param repourl: the URL which points at the git repository
Expand Down Expand Up @@ -108,6 +108,9 @@ def __init__(self, repourl=None, branch='HEAD', mode='incremental', method=None,
@type getDescription: boolean or dict
@param getDescription: Use 'git describe' to describe the fetched revision
@type origin: string
@param origin: The name to give the remote when cloning (default None)
@type config: dict
@param config: Git configuration options to enable when running git
"""
Expand All @@ -128,6 +131,7 @@ def __init__(self, repourl=None, branch='HEAD', mode='incremental', method=None,
self.config = config
self.supportsBranch = True
self.srcdir = 'source'
self.origin = origin
Source.__init__(self, **kwargs)

if not self.repourl:
Expand Down Expand Up @@ -420,21 +424,23 @@ def _fetchOrFallback(self, _=None):
def _clone(self, shallowClone):
"""Retry if clone failed"""

args = []
command = ['clone']
switchToBranch = False
if self.supportsBranch and self.branch != 'HEAD':
if self.branch.startswith('refs/'):
# we can't choose this branch from 'git clone' directly; we
# must do so after the clone
switchToBranch = True
args += ['--no-checkout']
command += ['--no-checkout']
else:
args += ['--branch', self.branch]
command += ['--branch', self.branch]
if shallowClone:
args += ['--depth', '1']
command += ['--depth', '1']
if self.reference:
args += ['--reference', self.reference]
command = ['clone'] + args + [self.repourl, '.']
command += ['--reference', self.reference]
if self.origin:
command += ['--origin', self.origin]
command += [self.repourl, '.']

if self.prog:
command.append('--progress')
Expand Down
30 changes: 30 additions & 0 deletions master/buildbot/test/unit/test_steps_source_git.py
Expand Up @@ -474,6 +474,36 @@ def test_mode_full_clean_no_existing_repo_branch(self):
self.expectOutcome(result=SUCCESS, status_text=["update"])
return self.runStep()

def test_mode_full_clean_no_existing_repo_with_origin(self):
self.setupStep(
git.Git(repourl='http://github.com/buildbot/buildbot.git',
mode='full', method='clean', origin='foo'))
self.expectCommands(
ExpectShell(workdir='wkdir',
command=['git', '--version'])
+ ExpectShell.log('stdio',
stdout='git version 1.7.5')
+ 0,
Expect('stat', dict(file='wkdir/.buildbot-patched',
logEnviron=True))
+ 1,
Expect('listdir', {'dir': 'wkdir', 'logEnviron': True,
'timeout': 1200})
+ Expect.update('files', [])
+ 0,
ExpectShell(workdir='wkdir',
command=['git', 'clone', '--origin', 'foo',
'http://github.com/buildbot/buildbot.git', '.'])
+ 0,
ExpectShell(workdir='wkdir',
command=['git', 'rev-parse', 'HEAD'])
+ ExpectShell.log('stdio',
stdout='f6ad368298bd941e934a41f3babc827b2aa95a1d')
+ 0,
)
self.expectOutcome(result=SUCCESS, status_text=["update"])
return self.runStep()

def test_mode_full_clobber(self):
self.setupStep(
git.Git(repourl='http://github.com/buildbot/buildbot.git',
Expand Down
4 changes: 4 additions & 0 deletions master/docs/manual/cfg-buildsteps.rst
Expand Up @@ -365,6 +365,10 @@ The Git step takes the following arguments:
(optional): use the specified string as a path to a reference repository on the local machine.
Git will try to grab objects from this path first instead of the main repository, if they exist.

``origin``
(optional): By default, any clone will use the name "origin" as the remote repository (eg, "origin/master").
This renderable option allows that to be configured to an alternate name.

``progress``
(optional): passes the (``--progress``) flag to (:command:`git fetch`).
This solves issues of long fetches being killed due to lack of output, but requires Git 1.7.2 or later.
Expand Down
2 changes: 2 additions & 0 deletions master/docs/relnotes/index.rst
Expand Up @@ -14,6 +14,8 @@ Master
Features
~~~~~~~~

* :bb:step:`Git` supports an "origin" option to give a name to the remote repo.

Fixes
~~~~~

Expand Down

0 comments on commit 8df4ed3

Please sign in to comment.