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
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
slapos.recipe.build
Commits
59d6f829
Commit
59d6f829
authored
Jan 10, 2019
by
Ayush Tiwari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add functions for git in local repo
parent
abed6449
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
86 additions
and
0 deletions
+86
-0
slapos/recipe/build/tests.py
slapos/recipe/build/tests.py
+86
-0
No files found.
slapos/recipe/build/tests.py
View file @
59d6f829
...
...
@@ -5,6 +5,7 @@ import os
import
re
import
shutil
import
stat
import
subprocess
import
tempfile
import
unittest
import
zc.buildout.testing
...
...
@@ -29,11 +30,96 @@ def setUp(test):
zc
.
buildout
.
testing
.
buildoutSetUp
(
test
)
zc
.
buildout
.
testing
.
install_develop
(
'slapos.recipe.build'
,
test
)
def
check_exists
(
fips_dir
=
None
)
:
"""test if git is in the path
:returns: True if git is in the path
"""
try
:
subprocess
.
check_output
([
'git'
,
'--version'
])
return
True
except
(
OSError
,
subprocess
.
CalledProcessError
)
:
return
False
def
git_add
(
proj_dir
,
update
=
False
):
"""runs a 'git add .' in the provided git repo
:param proj_dir: path to a git repo
:update: if True, will run 'git add -u'
"""
check_exists_with_error
()
cmd
=
'git add '
+
'-u'
if
update
else
'.'
try
:
subprocess
.
check_call
(
'git add .'
,
cwd
=
proj_dir
,
shell
=
True
)
except
subprocess
.
CalledProcessError
as
e
:
log
.
error
(
"'git add .' failed with '{}'"
.
format
(
e
.
returncode
))
def
git_commit
(
proj_dir
,
msg
):
"""runs a 'git commit -m msg' in the provided git repo
:param proj_dir: path to a git repo
"""
check_exists_with_error
()
try
:
subprocess
.
check_call
(
'git commit -m "{}"'
.
format
(
msg
),
cwd
=
proj_dir
,
shell
=
True
)
except
subprocess
.
CalledProcessError
as
e
:
log
.
error
(
"'git commit' failed with '{}'"
.
format
(
e
.
returncode
))
def
git_push
(
repo_dir
):
"""Pushes any changes in the Git repository located in supplied repository
directory to remote git repository.
:param repo_dir: Directory containing git repository to push.
"""
cmd
=
'git push '
execute_shell_command
(
cmd
,
repo_dir
)
def
git_create_submodule
():
"""
Steps to create local submodule:
1. Create a directory
2. init the directory with git
3. Add some files and commit
"""
pass
def
git_create_main_repo
():
"""
Steps to create main repo which will later point to a submodule repo:
1. Create a directory
2. init the directory with git
3. Add some files and commit
4. Add a folder and commit
5. Add a submodule in the repo and commit
"""
pass
def
update_submodule
():
"""
Steps to update submodule:
1. Add more files and commit
"""
pass
def
update_main_repo_after_submodule_changes
():
pass
def
get_repo_head_commit
(
prof_dir
,
branch
=
'master'
):
"""
Returns the sha of HEAD of a git repo
"""
try
:
output
=
subprocess
.
check_output
(
'git rev-parse {}'
.
format
(
branch
),
cwd
=
proj_dir
,
shell
=
True
).
decode
(
"utf-8"
)
return
output
.
rstrip
()
except
subprocess
.
CalledProcessError
:
log
.
error
(
"failed to call 'git rev-parse'"
)
return
None
class
GitCloneNonInformativeTests
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
dir
=
os
.
path
.
realpath
(
tempfile
.
mkdtemp
())
self
.
parts_directory_path
=
os
.
path
.
join
(
self
.
dir
,
'test_parts'
)
# Add repository with submodules in a temporary directory
def
tearDown
(
self
):
shutil
.
rmtree
(
self
.
dir
)
...
...
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