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
314986bb
Commit
314986bb
authored
Feb 11, 2019
by
Ayush Tiwari
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gitclone/tests: Add test for verifying status of submodule changes
parent
90010afa
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
88 deletions
+31
-88
slapos/recipe/build/tests.py
slapos/recipe/build/tests.py
+30
-72
slapos/recipe/gitclone.py
slapos/recipe/gitclone.py
+1
-16
No files found.
slapos/recipe/build/tests.py
View file @
314986bb
...
...
@@ -359,28 +359,19 @@ revision = %s
submodule_head_commit
)
@
with_buildout
def
test_
update_submodule_using_branch
(
self
,
buildout
,
write
,
def
test_
git_add_for_submodule_changes
(
self
,
buildout
,
write
,
sample_buildout
,
**
kw
):
"""
Remote:
Repositories status: Parent repo(M1), No submodule
Remote:
Repositories status: Parent repo(M2) and Submodule repo (S1)
Parent repo (M2) ---references---> Submodule(S1)
Local:
Buildout should update to at M2+S1
Remote:
Repositories status: Parent repo(M3), Submodule repo (S1)
Parent repo (M2) (No submodule referenced)
Local:
Buildout should update to at M3 (and keep the submodule dir as local
changes)
Test to verify the result of `git status` being executed from parent as well
as submodule repository after making some local changes in submodule repo
"""
# Create a parent repo
self
.
setUpParentRepository
()
print
'STATE 1'
# Clone repositories in status M1
# Create submodule repository
self
.
setUpSubmoduleRepository
()
# Attach the submodule repository to the parent repo on remote
self
.
attachSubmoduleToParent
()
write
(
sample_buildout
,
'buildout.cfg'
,
"""
[buildout]
...
...
@@ -391,63 +382,30 @@ recipe = slapos.recipe.build:gitclone
repository = %s
"""
%
self
.
project_dir
)
check_call
([
buildout
])
print
'STATE 2'
initial_commit_parent_repo
=
self
.
getRepositoryHeadCommit
(
self
.
project_dir
)
# Check if the parent repo is present
main_repo_path
=
os
.
path
.
join
(
sample_buildout
,
'parts'
,
'git-clone'
)
self
.
assertTrue
(
os
.
path
.
exists
(
main_repo_path
))
# Check if the commit is same as the REMOTE for the parent repo
self
.
assertEqual
(
self
.
getRepositoryHeadCommit
(
main_repo_path
),
initial_commit_parent_repo
)
# Create submodule repository
self
.
setUpSubmoduleRepository
()
# Attach the submodule repository to the parent repo on remote
self
.
attachSubmoduleToParent
()
print
'STATE 3'
print
'%s'
%
self
.
project_dir
# Trigger update using buildout
check_call
([
buildout
])
# Check if the submodule is not empty and has been updated
submodule_repo_path
=
os
.
path
.
join
(
main_repo_path
,
'dir1'
,
local_parent_dir
=
os
.
path
.
join
(
sample_buildout
,
'parts'
,
'git-clone'
)
local_submodule_dir
=
os
.
path
.
join
(
local_parent_dir
,
'dir1'
,
'submodule_repo'
)
self
.
assertTrue
(
os
.
listdir
(
submodule_repo_path
))
# Check if the commit is same as the REMOTE for both parent and main repo
self
.
assertEqual
(
self
.
getRepositoryHeadCommit
(
main_repo_path
),
self
.
getRepositoryHeadCommit
(
self
.
project_dir
))
self
.
assertEqual
(
self
.
getRepositoryHeadCommit
(
submodule_repo_path
),
self
.
getRepositoryHeadCommit
(
self
.
submodule_dir
))
# On REMOTE, remove the submodule and commit
# Remove the submodule entry from .git/config
check_call
([
'git'
,
'submodule'
,
'deinit'
,
'-f'
,
os
.
path
.
join
(
self
.
project_dir
,
'dir1'
,
'submodule_repo'
)],
cwd
=
self
.
project_dir
)
# Remove the submodule directory from the parent project's .git/modules
check_call
([
'rm'
,
'-rf'
,
os
.
path
.
join
(
'.git'
,
'modules'
,
'dir1'
,
'submodule_repo'
)],
cwd
=
self
.
project_dir
)
# Remove the entry in .gitmodules and remove the submodule directory
check_call
([
'git'
,
'rm'
,
'-f'
,
os
.
path
.
join
(
self
.
project_dir
,
'dir1'
,
'submodule_repo'
)],
cwd
=
self
.
project_dir
)
# Commit removing the submodule
self
.
gitAdd
(
self
.
project_dir
)
self
.
gitCommit
(
self
.
project_dir
,
'Remove submodule'
)
# Now, let's trigger update for buildout again
check_call
([
buildout
])
# Check if the commit is same as the REMOTE for parent
self
.
assertEqual
(
self
.
getRepositoryHeadCommit
(
main_repo_path
),
self
.
getRepositoryHeadCommit
(
self
.
project_dir
))
# Check that the submodule path is not empty and treated more as local
# changes
self
.
assertTrue
(
os
.
listdir
(
submodule_repo_path
))
# Now so some change manually in submodule repo, but don't commit
self
.
touch
(
local_submodule_dir
,
'file2.py'
)
self
.
gitAdd
(
local_submodule_dir
)
# Do `git status` to check if the changes are shown for the repo in parent
# This should the changes been done in the main as well as submodule repo
files_changed
=
check_output
([
'git'
,
'status'
,
'--porcelain'
],
cwd
=
local_parent_dir
)
files_changed_list
=
files_changed
.
strip
().
split
(
'
\
n
'
)
# Check if submodule directory is part of modified list
self
.
assertEqual
(
files_changed_list
[
0
],
'M dir1/submodule_repo'
)
# Now that `git status` in parent repo shows changes in the submodule repo,
# do `git status` in the submodule repo to re-confirm the exact file change
files_changed
=
check_output
([
'git'
,
'status'
,
'--porcelain'
],
cwd
=
local_submodule_dir
)
files_changed_list
=
files_changed
.
strip
().
split
(
'
\
n
'
)
# Check if submodule directory is part of modified list
self
.
assertEqual
(
files_changed_list
[
0
],
'A file2.py'
)
def
test_ignore_ssl_certificate
(
self
,
ignore_ssl_certificate
=
True
):
import
slapos.recipe.gitclone
...
...
slapos/recipe/gitclone.py
View file @
314986bb
...
...
@@ -176,21 +176,6 @@ class Recipe(object):
print
"Git Reset stdout output:
\
n
"
,
e
.
output
raise
def
gitRemoveSubmodule
(
self
,
submodule_path
=
None
):
"""
Cleanly remove submodule
"""
if
submodule_path
:
# Remove the submodule entry from .git/config
check_call
([
'git'
,
'submodule'
,
'deinit'
,
'-f'
,
submodule_path
])
# Remove the submodule directory from the parent's .git/modules directory
check_call
([
'rm'
,
'-rf'
,
'.git/modules/%s'
%
submodule_path
])
# Remove the entry in .gitmodules and remove the submodule directory
# located at submodule path
check_call
([
'git'
,
'rm'
,
'-f'
,
submodule_path
])
def
install
(
self
):
"""
Do a git clone.
...
...
@@ -324,7 +309,7 @@ class Recipe(object):
# repo being checked out to the desired one.
# It will also init a submodule if required
# NOTE: This will put the submodule repo in a `Detached` state.
check_call
([
self
.
git_command
,
'submodule'
,
'update'
,
'--init'
,
check_call
([
self
.
git_command
,
'submodule'
,
'update'
,
'--init'
,
'-f'
,
'--recursive'
],
cwd
=
self
.
location
)
except
:
...
...
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