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
d32eea7a
Commit
d32eea7a
authored
1 year ago
by
Ronald Jäpel
Browse files
Options
Downloads
Patches
Plain Diff
Fix commit bug and simplify code
parent
1291de1f
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
+1
-3
1 addition, 3 deletions
cadetrdm/initialize_repo.py
cadetrdm/utils.py
+10
-31
10 additions, 31 deletions
cadetrdm/utils.py
tests/test_git_adapter.py
+3
-3
3 additions, 3 deletions
tests/test_git_adapter.py
with
14 additions
and
37 deletions
cadetrdm/initialize_repo.py
+
1
−
3
View file @
d32eea7a
...
@@ -138,8 +138,6 @@ def initialize_git_repo(path_to_repo: str, output_repo_name: (str | bool) = "out
...
@@ -138,8 +138,6 @@ def initialize_git_repo(path_to_repo: str, output_repo_name: (str | bool) = "out
# 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
repo
=
ResultsRepo
(
"
.
"
)
repo
=
ResultsRepo
(
"
.
"
)
# ToDo: Why does this break tests if changed to repo.add and repo.commit??
repo
.
commit
(
"
initial commit
"
)
repo
.
_git
.
add
(
"
.
"
)
repo
.
_git
.
commit
(
"
-m
"
,
"
initial commit
"
)
os
.
chdir
(
starting_directory
)
os
.
chdir
(
starting_directory
)
This diff is collapsed.
Click to expand it.
cadetrdm/utils.py
+
10
−
31
View file @
d32eea7a
...
@@ -117,28 +117,7 @@ class BaseRepo:
...
@@ -117,28 +117,7 @@ class BaseRepo:
:return:
:return:
List of all staged changes.
List of all staged changes.
"""
"""
untracked_files
=
""
self
.
_git
.
add
(
"
.
"
)
if
len
(
self
.
untracked_files
)
>
0
:
untracked_files
=
"
\n
"
.
join
([
"
-
"
+
file
for
file
in
self
.
untracked_files
])
if
automatically_add_new_files
:
for
f
in
self
.
untracked_files
:
self
.
_git
.
add
(
f
)
else
:
proceed
=
input
(
f
'
Found untracked files. Adding the following untracked files to git:
\n
{
untracked_files
}
\n
'
f
'
Proceed? Y/n
\n
'
)
if
proceed
.
lower
()
==
"
y
"
or
proceed
==
""
:
for
f
in
self
.
untracked_files
:
self
.
_git
.
add
(
f
)
else
:
raise
KeyboardInterrupt
changed_files
=
self
.
changed_files
for
f
in
changed_files
:
self
.
_git
.
add
(
f
)
return
self
.
untracked_files
+
changed_files
def
reset_hard_to_head
(
self
):
def
reset_hard_to_head
(
self
):
proceed
=
input
(
f
'
The output directory contains the following uncommitted changes:
\n
'
proceed
=
input
(
f
'
The output directory contains the following uncommitted changes:
\n
'
...
@@ -160,8 +139,8 @@ class BaseRepo:
...
@@ -160,8 +139,8 @@ class BaseRepo:
return
changed_files
return
changed_files
@property
@property
def
exist_un
stag
ed_changes
(
self
):
def
exist_un
comitt
ed_changes
(
self
):
return
len
(
self
.
untracked_files
)
>
0
or
len
(
self
.
changed_files
)
>
0
return
len
(
self
.
_git
.
status
(
"
--porcelain
"
)
)
>
0
def
update_package_list
(
self
):
def
update_package_list
(
self
):
"""
"""
...
@@ -177,7 +156,7 @@ class BaseRepo:
...
@@ -177,7 +156,7 @@ class BaseRepo:
print
(
"
Dumping pip independent requirements.txt.
"
)
print
(
"
Dumping pip independent requirements.txt.
"
)
os
.
system
(
f
"
pip list --not-required --format freeze >
{
repo_path
}
/pip_independent_requirements.txt
"
)
os
.
system
(
f
"
pip list --not-required --format freeze >
{
repo_path
}
/pip_independent_requirements.txt
"
)
def
commit
(
self
,
message
:
str
,
add_all
=
True
,
update_packages
=
Tru
e
):
def
commit
(
self
,
message
:
str
,
add_all
=
True
,
update_packages
=
Fals
e
):
"""
"""
Commit current state of the repository.
Commit current state of the repository.
...
@@ -188,7 +167,7 @@ class BaseRepo:
...
@@ -188,7 +167,7 @@ class BaseRepo:
:param update_packages:
:param update_packages:
Option to automatically dump the python environment information into environment.yml files.
Option to automatically dump the python environment information into environment.yml files.
"""
"""
if
not
self
.
exist_un
stag
ed_changes
:
if
not
self
.
exist_un
comitt
ed_changes
:
print
(
f
"
No changes to commit in repo
{
self
.
working_dir
}
"
)
print
(
f
"
No changes to commit in repo
{
self
.
working_dir
}
"
)
return
return
...
@@ -196,7 +175,7 @@ class BaseRepo:
...
@@ -196,7 +175,7 @@ class BaseRepo:
if
update_packages
:
if
update_packages
:
self
.
update_package_list
()
self
.
update_package_list
()
if
add_all
:
if
add_all
:
self
.
add_all_files
(
)
self
.
_git
.
add
(
"
.
"
)
commit_return
=
self
.
_git
.
commit
(
"
-m
"
,
message
)
commit_return
=
self
.
_git
.
commit
(
"
-m
"
,
message
)
print
(
"
\n
"
+
commit_return
+
"
\n
"
)
print
(
"
\n
"
+
commit_return
+
"
\n
"
)
...
@@ -234,7 +213,7 @@ class BaseRepo:
...
@@ -234,7 +213,7 @@ class BaseRepo:
Adds all untracked files to git and then stashes all changes.
Adds all untracked files to git and then stashes all changes.
Will raise a RuntimeError if no changes are found.
Will raise a RuntimeError if no changes are found.
"""
"""
if
not
self
.
exist_un
stag
ed_changes
:
if
not
self
.
exist_un
comitt
ed_changes
:
raise
RuntimeError
(
"
No changes in repo to stash.
"
)
raise
RuntimeError
(
"
No changes in repo to stash.
"
)
self
.
_git
.
add
(
"
.
"
)
self
.
_git
.
add
(
"
.
"
)
self
.
_git
.
stash
()
self
.
_git
.
stash
()
...
@@ -272,7 +251,7 @@ class BaseRepo:
...
@@ -272,7 +251,7 @@ class BaseRepo:
Raise a RuntimeError if uncommitted changes are in the repository.
Raise a RuntimeError if uncommitted changes are in the repository.
:return:
:return:
"""
"""
if
self
.
exist_un
stag
ed_changes
:
if
self
.
exist_un
comitt
ed_changes
:
raise
RuntimeError
(
f
"
Found uncommitted changes in the repository
{
self
.
working_dir
}
.
"
)
raise
RuntimeError
(
f
"
Found uncommitted changes in the repository
{
self
.
working_dir
}
.
"
)
...
@@ -413,7 +392,7 @@ class ProjectRepo(BaseRepo):
...
@@ -413,7 +392,7 @@ class ProjectRepo(BaseRepo):
:return:
:return:
Absolute path to the newly copied file.
Absolute path to the newly copied file.
"""
"""
if
self
.
output_repo
.
exist_un
stag
ed_changes
:
if
self
.
output_repo
.
exist_un
comitt
ed_changes
:
self
.
output_repo
.
stash_all_changes
()
self
.
output_repo
.
stash_all_changes
()
has_stashed_changes
=
True
has_stashed_changes
=
True
else
:
else
:
...
@@ -483,7 +462,7 @@ class ProjectRepo(BaseRepo):
...
@@ -483,7 +462,7 @@ class ProjectRepo(BaseRepo):
self
.
_is_in_context_manager
=
True
self
.
_is_in_context_manager
=
True
output_repo
=
self
.
output_repo
output_repo
=
self
.
output_repo
if
output_repo
.
exist_un
stag
ed_changes
:
if
output_repo
.
exist_un
comitt
ed_changes
:
output_repo
.
reset_hard_to_head
()
output_repo
.
reset_hard_to_head
()
output_repo
.
delete_active_branch_if_branch_is_empty
()
output_repo
.
delete_active_branch_if_branch_is_empty
()
...
...
This diff is collapsed.
Click to expand it.
tests/test_git_adapter.py
+
3
−
3
View file @
d32eea7a
...
@@ -80,7 +80,7 @@ def try_commit_code(path_to_repo):
...
@@ -80,7 +80,7 @@ def try_commit_code(path_to_repo):
current_commit_number
=
count_commit_number
(
repo
)
current_commit_number
=
count_commit_number
(
repo
)
modify_code
(
path_to_repo
)
modify_code
(
path_to_repo
)
repo
.
commit
(
"
add code to print random number
"
,
update_packages
=
False
)
repo
.
commit
(
"
add code to print random number
"
,
add_all
=
True
,
update_packages
=
False
)
updated_commit_number
=
count_commit_number
(
repo
)
updated_commit_number
=
count_commit_number
(
repo
)
assert
current_commit_number
+
1
==
updated_commit_number
assert
current_commit_number
+
1
==
updated_commit_number
...
@@ -95,7 +95,7 @@ def try_add_submodule(path_to_repo):
...
@@ -95,7 +95,7 @@ def try_add_submodule(path_to_repo):
def
try_commit_code_without_code_changes
(
path_to_repo
):
def
try_commit_code_without_code_changes
(
path_to_repo
):
repo
=
ProjectRepo
(
path_to_repo
)
repo
=
ProjectRepo
(
path_to_repo
)
current_commit_number
=
count_commit_number
(
repo
)
current_commit_number
=
count_commit_number
(
repo
)
repo
.
commit
(
"
This commit will not be made
"
)
repo
.
commit
(
"
This commit will not be made
"
,
add_all
=
True
)
updated_commit_number
=
count_commit_number
(
repo
)
updated_commit_number
=
count_commit_number
(
repo
)
assert
current_commit_number
==
updated_commit_number
assert
current_commit_number
==
updated_commit_number
...
@@ -116,7 +116,7 @@ def try_commit_results_with_uncommitted_code_changes(path_to_repo):
...
@@ -116,7 +116,7 @@ def try_commit_results_with_uncommitted_code_changes(path_to_repo):
with
pytest
.
raises
(
Exception
):
with
pytest
.
raises
(
Exception
):
with
repo
.
track_results
(
results_commit_message
=
"
Add array
"
):
with
repo
.
track_results
(
results_commit_message
=
"
Add array
"
):
example_generate_results_array
(
path_to_repo
,
output_folder
=
repo
.
_output_folder
)
example_generate_results_array
(
path_to_repo
,
output_folder
=
repo
.
_output_folder
)
repo
.
commit
(
"
add code to print random number
"
,
update_packages
=
False
)
repo
.
commit
(
"
add code to print random number
"
,
add_all
=
True
,
update_packages
=
False
)
def
try_load_previous_result
(
path_to_repo
,
branch_name
):
def
try_load_previous_result
(
path_to_repo
,
branch_name
):
...
...
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