Skip to content

Commit

Permalink
add reset to origin branch when sync fails
Browse files Browse the repository at this point in the history
  • Loading branch information
mirpedrol committed Jan 14, 2025
1 parent fca0d8f commit e9d2e52
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions nf_core/pipelines/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,24 +277,29 @@ def make_template_pipeline(self):
with open(self.config_yml_path, "w") as config_path:
yaml.safe_dump(self.config_yml.model_dump(exclude_none=True), config_path)

pipeline_create_obj = nf_core.pipelines.create.create.PipelineCreate(
outdir=str(self.pipeline_dir),
from_config_file=True,
no_git=True,
force=True,
)
pipeline_create_obj.init_pipeline()

# set force to false to avoid overwriting files in the future
if self.config_yml.template is not None:
self.config_yml.template = pipeline_create_obj.config
# Set force true in config to overwrite existing files
self.config_yml.template.force = False
# Set outdir as the current directory to avoid local info leaking
self.config_yml.template.outdir = "."
# Update nf-core version
self.config_yml.nf_core_version = nf_core.__version__
dump_yaml_with_prettier(self.config_yml_path, self.config_yml.model_dump(exclude_none=True))
try:
pipeline_create_obj = nf_core.pipelines.create.create.PipelineCreate(
outdir=str(self.pipeline_dir),
from_config_file=True,
no_git=True,
force=True,
)
pipeline_create_obj.init_pipeline()

# set force to false to avoid overwriting files in the future
if self.config_yml.template is not None:
self.config_yml.template = pipeline_create_obj.config
# Set force true in config to overwrite existing files
self.config_yml.template.force = False
# Set outdir as the current directory to avoid local info leaking
self.config_yml.template.outdir = "."
# Update nf-core version
self.config_yml.nf_core_version = nf_core.__version__
dump_yaml_with_prettier(self.config_yml_path, self.config_yml.model_dump(exclude_none=True))
except Exception as e:
# Reset to where you were to prevent git getting messed up.
self.repo.git.reset("--hard")
raise SyncExceptionError(f"Failed to rebuild pipeline from template with error:\n{e}")

def commit_template_changes(self):
"""If we have any changes with the new template files, make a git commit"""
Expand Down

0 comments on commit e9d2e52

Please sign in to comment.