Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CADET-RDM
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IBG-1
ModSim
CADET
CADET-RDM
Commits
05469c90
Commit
05469c90
authored
1 year ago
by
Ronald Jäpel
Browse files
Options
Downloads
Patches
Plain Diff
Add ability to convert existing git repos to cadet-rdm repos
parent
3b55aa13
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
cadetrdm/initialize_repo.py
+18
-11
18 additions, 11 deletions
cadetrdm/initialize_repo.py
cadetrdm/repositories.py
+7
-0
7 additions, 0 deletions
cadetrdm/repositories.py
tests/test_git_adapter.py
+19
-0
19 additions, 0 deletions
tests/test_git_adapter.py
with
44 additions
and
11 deletions
cadetrdm/initialize_repo.py
+
18
−
11
View file @
05469c90
...
@@ -15,7 +15,7 @@ def add_linebreaks(input_list):
...
@@ -15,7 +15,7 @@ def add_linebreaks(input_list):
"""
"""
Add linebreaks between each entry in the input_list
Add linebreaks between each entry in the input_list
"""
"""
return
[
line
+
"
\n
"
for
line
in
input_list
]
return
[
"
\n
"
+
line
for
line
in
input_list
]
def
init_lfs
(
lfs_filetypes
:
list
,
path
:
str
=
None
):
def
init_lfs
(
lfs_filetypes
:
list
,
path
:
str
=
None
):
...
@@ -102,17 +102,21 @@ def initialize_git_repo(path_to_repo: str, output_repo_name: (str | bool) = "out
...
@@ -102,17 +102,21 @@ def initialize_git_repo(path_to_repo: str, output_repo_name: (str | bool) = "out
starting_directory
=
os
.
getcwd
()
starting_directory
=
os
.
getcwd
()
if
path_to_repo
!=
"
.
"
:
if
path_to_repo
!=
"
.
"
:
if
os
.
path
.
exists
(
path_to_repo
)
and
len
(
os
.
listdir
(
path_to_repo
))
>
0
:
raise
ValueError
(
"
Path to repository already exists and is not an empty directory.
"
)
os
.
makedirs
(
path_to_repo
,
exist_ok
=
True
)
os
.
makedirs
(
path_to_repo
,
exist_ok
=
True
)
os
.
chdir
(
path_to_repo
)
os
.
chdir
(
path_to_repo
)
os
.
system
(
f
"
git init
"
)
try
:
repo
=
git
.
Repo
(
"
.
"
)
proceed
=
input
(
f
'
The target directory already contains a git repo.
\n
'
f
'
Please back up or push all changes to the repo before continuing.
'
f
'
Proceed? Y/n
\n
'
)
if
not
(
proceed
.
lower
()
==
"
y
"
or
proceed
==
""
):
raise
KeyboardInterrupt
except
git
.
exc
.
InvalidGitRepositoryError
:
os
.
system
(
f
"
git init
"
)
init_lfs
(
lfs_filetypes
)
write_lines_to_file
(
path
=
"
.gitattributes
"
,
lines
=
gitattributes
,
open_type
=
"
a
"
)
write_lines_to_file
(
path
=
"
.gitignore
"
,
lines
=
gitignore
,
open_type
=
"
a
"
)
write_lines_to_file
(
path
=
"
.gitattributes
"
,
lines
=
gitattributes
)
write_lines_to_file
(
path
=
"
.gitignore
"
,
lines
=
gitignore
)
if
output_repo_kwargs
is
None
:
if
output_repo_kwargs
is
None
:
output_repo_kwargs
=
{
"
gitattributes
"
:
[
"
logs/log.csv merge=union
"
]}
output_repo_kwargs
=
{
"
gitattributes
"
:
[
"
logs/log.csv merge=union
"
]}
...
@@ -125,8 +129,11 @@ def initialize_git_repo(path_to_repo: str, output_repo_name: (str | bool) = "out
...
@@ -125,8 +129,11 @@ def initialize_git_repo(path_to_repo: str, output_repo_name: (str | bool) = "out
# This instance of ProjectRepo is therefore the project repo
# This instance of ProjectRepo is therefore the project repo
repo
=
ProjectRepo
(
"
.
"
,
output_folder
=
output_repo_name
)
repo
=
ProjectRepo
(
"
.
"
,
output_folder
=
output_repo_name
)
else
:
else
:
create_output_readme
()
# If output_repo_name is False we are in the output_repo and should finish by committing the changes
# If output_repo_name is False we are in the output_repo and should finish by committing the changes
init_lfs
(
lfs_filetypes
)
create_output_readme
()
repo
=
ResultsRepo
(
"
.
"
)
repo
=
ResultsRepo
(
"
.
"
)
repo
.
commit
(
"
initial commit
"
)
repo
.
commit
(
"
initial commit
"
)
...
@@ -147,7 +154,7 @@ def create_readme():
...
@@ -147,7 +154,7 @@ def create_readme():
"
Please update the environment.yml with your python environment requirements.
"
,
""
,
""
,
"
Please update the environment.yml with your python environment requirements.
"
,
""
,
""
,
"
The output repository can be found at:
"
,
"
The output repository can be found at:
"
,
"
[output_repo]() (not actually set yet because no remote has been configured at this moment
"
]
"
[output_repo]() (not actually set yet because no remote has been configured at this moment
"
]
write_lines_to_file
(
"
README.md
"
,
readme_lines
,
open_type
=
"
w
"
)
write_lines_to_file
(
"
README.md
"
,
readme_lines
,
open_type
=
"
a
"
)
def
create_output_readme
():
def
create_output_readme
():
...
@@ -155,7 +162,7 @@ def create_output_readme():
...
@@ -155,7 +162,7 @@ def create_output_readme():
"
- authors
"
,
"
- project
"
,
"
- things we will find interesting later
"
,
""
,
""
,
"
- authors
"
,
"
- project
"
,
"
- things we will find interesting later
"
,
""
,
""
,
"
The project repository can be found at:
"
,
"
The project repository can be found at:
"
,
"
[project_repo]() (not actually set yet because no remote has been configured at this moment
"
]
"
[project_repo]() (not actually set yet because no remote has been configured at this moment
"
]
write_lines_to_file
(
"
README.md
"
,
readme_lines
,
open_type
=
"
w
"
)
write_lines_to_file
(
"
README.md
"
,
readme_lines
,
open_type
=
"
a
"
)
def
initialize_from_remote
(
project_url
,
path_to_repo
:
str
=
None
):
def
initialize_from_remote
(
project_url
,
path_to_repo
:
str
=
None
):
...
...
This diff is collapsed.
Click to expand it.
cadetrdm/repositories.py
+
7
−
0
View file @
05469c90
...
@@ -677,6 +677,12 @@ class ProjectRepo(BaseRepo):
...
@@ -677,6 +677,12 @@ class ProjectRepo(BaseRepo):
if
os
.
path
.
exists
(
self
.
output_repo
.
working_dir
+
"
_cached
"
):
if
os
.
path
.
exists
(
self
.
output_repo
.
working_dir
+
"
_cached
"
):
shutil
.
rmtree
(
self
.
output_repo
.
working_dir
+
"
_cached
"
)
shutil
.
rmtree
(
self
.
output_repo
.
working_dir
+
"
_cached
"
)
def
test_for_correct_repo_setup
(
self
):
"""
ToDo: implement
:return:
"""
def
enter_context
(
self
,
):
def
enter_context
(
self
,
):
"""
"""
Enter the tracking context. This includes:
Enter the tracking context. This includes:
...
@@ -688,6 +694,7 @@ class ProjectRepo(BaseRepo):
...
@@ -688,6 +694,7 @@ class ProjectRepo(BaseRepo):
:return:
:return:
The name of the newly created output branch.
The name of the newly created output branch.
"""
"""
self
.
test_for_correct_repo_setup
()
self
.
test_for_uncommitted_changes
()
self
.
test_for_uncommitted_changes
()
self
.
_on_context_enter_commit_hash
=
self
.
current_commit_hash
self
.
_on_context_enter_commit_hash
=
self
.
current_commit_hash
self
.
_is_in_context_manager
=
True
self
.
_is_in_context_manager
=
True
...
...
This diff is collapsed.
Click to expand it.
tests/test_git_adapter.py
+
19
−
0
View file @
05469c90
...
@@ -154,6 +154,25 @@ def try_initialize_from_remote():
...
@@ -154,6 +154,25 @@ def try_initialize_from_remote():
assert
try_init_gitpython_repo
(
"
test_repo_from_remote
"
)
assert
try_init_gitpython_repo
(
"
test_repo_from_remote
"
)
def
test_init_over_existing_repo
():
path_to_repo
=
"
test_repo_2
"
if
os
.
path
.
exists
(
path_to_repo
):
remove_dir
(
path_to_repo
)
os
.
makedirs
(
path_to_repo
)
os
.
chdir
(
path_to_repo
)
os
.
system
(
f
"
git init
"
)
with
open
(
"
README.md
"
,
"
w
"
)
as
handle
:
handle
.
write
(
"
Readme-line 1
\n
"
)
with
open
(
"
.gitignore
"
,
"
w
"
)
as
handle
:
handle
.
write
(
"
foo.bar.*
"
)
repo
=
git
.
Repo
(
"
.
"
)
repo
.
git
.
add
(
"
.
"
)
repo
.
git
.
commit
(
"
-m
"
,
"
Initial commit
"
)
os
.
chdir
(
"
..
"
)
initialize_git_repo
(
path_to_repo
)
def
test_cadet_rdm
(
path_to_repo
):
def
test_cadet_rdm
(
path_to_repo
):
# because these depend on one-another and there is no native support afaik for sequential tests
# because these depend on one-another and there is no native support afaik for sequential tests
# these tests are called sequentially here as try_ functions.
# these tests are called sequentially here as try_ functions.
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment