Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.recipe.build
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Xavier Thompson
slapos.recipe.build
Commits
9f7e9661
Commit
9f7e9661
authored
Aug 30, 2012
by
Cédric de Saint Martin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor gitclone recipe to support branches and develop.
parent
e09557b4
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
17 deletions
+37
-17
slapos/recipe/gitclone.py
slapos/recipe/gitclone.py
+37
-17
No files found.
slapos/recipe/gitclone.py
View file @
9f7e9661
...
@@ -31,12 +31,16 @@ from subprocess import check_call
...
@@ -31,12 +31,16 @@ from subprocess import check_call
GIT_DEFAULT_REMOTE_NAME
=
'origin'
GIT_DEFAULT_REMOTE_NAME
=
'origin'
GIT_DEFAULT_BRANCH_NAME
=
'master'
GIT_DEFAULT_BRANCH_NAME
=
'master'
TRUE_VALUES
=
[
'y'
,
'yes'
,
'1'
,
'true'
]
class
Recipe
(
object
):
class
Recipe
(
object
):
"""Clone a git repository."""
def
__init__
(
self
,
buildout
,
name
,
options
):
def
__init__
(
self
,
buildout
,
name
,
options
):
options
.
setdefault
(
'branch'
,
GIT_DEFAULT_BRANCH_NAME
)
options
.
setdefault
(
'branch'
,
GIT_DEFAULT_BRANCH_NAME
)
options
.
setdefault
(
'revision'
,
''
)
options
.
setdefault
(
'revision'
,
''
)
options
.
setdefault
(
'branch'
,
''
)
options
.
setdefault
(
'develop'
,
'false'
)
options
.
setdefault
(
'git-command'
,
'git'
)
options
.
setdefault
(
'git-command'
,
'git'
)
options
.
setdefault
(
'location'
,
options
.
setdefault
(
'location'
,
os
.
path
.
join
(
os
.
path
.
join
(
...
@@ -46,31 +50,47 @@ class Recipe(object):
...
@@ -46,31 +50,47 @@ class Recipe(object):
)
)
self
.
options
=
options
self
.
options
=
options
if
options
[
'revision'
]
and
options
[
'branch'
]:
# revision and branch options are incompatible
raise
ValueError
(
'revision and branch parameters are set but are'
'incompatible. Please specify only one of them.'
)
def
install
(
self
):
def
gitReset
(
self
,
revision
=
None
):
if
not
os
.
path
.
exists
(
self
.
options
[
'location'
]):
"""Operates git reset on the repository."""
check_call
([
self
.
options
[
'git-command'
],
'clone'
,
command
=
[
self
.
options
[
'git-command'
],
'reset'
,
'--hard'
]
self
.
options
[
'url'
],
if
revision
:
self
.
options
[
'location'
]])
command
.
append
(
revision
)
check_call
(
command
,
cwd
=
self
.
options
[
'location'
])
self
.
update
()
def
install
(
self
):
""" Do a git clone. If revision is specified, reset to it."""
if
not
os
.
path
.
exists
(
self
.
options
[
'location'
]):
git_clone_command
=
[
self
.
options
[
'git-command'
],
'clone'
,
self
.
options
[
'url'
],
self
.
options
[
'location'
]]
if
self
.
options
[
'branch'
]:
git_clone_command
.
extend
([
'--branch'
,
self
.
options
[
'branch'
]])
check_call
(
git_clone_command
)
return
[]
if
self
.
options
[
'revision'
]:
self
.
gitReset
(
self
.
options
[
'revision'
])
return
[
self
.
options
[
'location'
]]
def
update
(
self
):
def
update
(
self
):
check_call
([
self
.
options
[
'git-command'
],
'fetch'
,
'--all'
],
check_call
([
self
.
options
[
'git-command'
],
'fetch'
,
'--all'
],
cwd
=
self
.
options
[
'location'
])
cwd
=
self
.
options
[
'location'
])
if
self
.
options
[
'revision'
]:
# If develop parameter is set, don't reset/update.
check_call
([
self
.
options
[
'git-command'
],
# Otherwise, reset --hard
'reset'
,
'--hard'
,
self
.
options
[
'revision'
]],
if
not
self
.
options
.
get
(
'develop'
)
in
TRUE_VALUES
:
cwd
=
self
.
options
[
'location'
])
if
self
.
options
[
'revision'
]:
else
:
self
.
gitReset
(
self
.
options
[
'revision'
])
check_call
([
self
.
options
[
'git-command'
],
elif
self
.
options
[
'branch'
]:
'pull'
,
GIT_DEFAULT_REMOTE_NAME
,
self
.
gitReset
(
'%s/%s'
%
(
self
.
options
[
'branch'
]],
GIT_DEFAULT_REMOTE_NAME
,
self
.
options
[
'branch'
]))
cwd
=
self
.
options
[
'location'
]
else
:
)
self
.
gitReset
(
'%s/%s'
%
(
GIT_DEFAULT_REMOTE_NAME
,
GIT_DEFAULT_BRANCH_NAME
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment