Commit e09557b4 authored by Antoine Catton's avatar Antoine Catton

Add git clone recipe

parent a8881f01
......@@ -252,6 +252,91 @@ Notes
Currently, the modules will be installed in site-perl directory. Location of this
directory changes depending on the perl installation.
****************************
slapos.recipe.build:gitclone
****************************
Checkout a git repository.
Examples
********
Simple clone
------------
Only `url` parameter is required. For each buildout run,
the recipe will pick up the latest commit on the remote master branch::
[buildout]
parts = git-clone
[git-clone]
recipe = slapos.recipe.build:gitclone
url = http://example.net/example.git/
This will clone the git repository in `parts/git-clone` directory.
Specific branch
---------------
You can specify a specific branch using `branch` option. For each
run it will take the latest commit on this remote branch::
[buildout]
parts = git-clone
[git-clone]
recipe = slapos.recipe.build:gitclone
url = http://example.net/example.git/
branch = testing
Specific revision
-----------------
You can specify a specific commit hash or tag using `revision` option.
This option will cancel `branch` option, making it useless::
[buildout]
parts = git-clone
[git-clone]
recipe = slapos.recipe.build:gitclone
url = http://example.net/example.git/
revision = 0123456789abcdef
Specific git binary
-------------------
The default git command is `git`, if for a any reason you don't
have git in your path, you can specify git binary path with `git-command`
option::
[buildout]
parts = git-clone
[git-clone]
recipe = slapos.recipe.build:gitclone
url = http://example.net/example.git/
git-command = /usr/local/git/bin/git
Full example
------------
::
[buildout]
parts = git-clone
[git-binary]
recipe = hexagonit.recipe.cmmi
url = http://git-core.googlecode.com/files/git-1.7.12.tar.gz
[git-clone]
recipe = slapos.recipe.build:gitclone
url = http://example.net/example.git/
git-command = ${git-binary:location}/bin/git
revision = specific-tag
***********************
slapos.recipe.build:npm
......
......@@ -33,6 +33,7 @@ setup(name=name,
'cpan = slapos.recipe.cpan:Cpan',
'download = slapos.recipe.download:Recipe',
'download-unpacked = slapos.recipe.downloadunpacked:Recipe',
'gitclone = slapos.recipe.gitclone:Recipe',
'npm = slapos.recipe.npm:Npm',
]},
)
##############################################################################
#
# Copyright (c) 2010 Vifib SARL and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import os
from subprocess import check_call
GIT_DEFAULT_REMOTE_NAME = 'origin'
GIT_DEFAULT_BRANCH_NAME = 'master'
class Recipe(object):
def __init__(self, buildout, name, options):
options.setdefault('branch', GIT_DEFAULT_BRANCH_NAME)
options.setdefault('revision', '')
options.setdefault('git-command', 'git')
options.setdefault('location',
os.path.join(
buildout['buildout']['parts-directory'],
name
)
)
self.options = options
def install(self):
if not os.path.exists(self.options['location']):
check_call([self.options['git-command'], 'clone',
self.options['url'],
self.options['location']])
self.update()
return []
def update(self):
check_call([self.options['git-command'], 'fetch', '--all'],
cwd=self.options['location'])
if self.options['revision']:
check_call([self.options['git-command'],
'reset', '--hard', self.options['revision']],
cwd=self.options['location'])
else:
check_call([self.options['git-command'],
'pull', GIT_DEFAULT_REMOTE_NAME,
self.options['branch']],
cwd=self.options['location']
)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment