Skip to content

Commit

Permalink
lets try switch
Browse files Browse the repository at this point in the history
  • Loading branch information
Valentin Seitz committed Sep 21, 2023
1 parent e8e2720 commit 65c6822
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions tools/tests/systemtests/Systemtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,28 +228,12 @@ def _get_git_ref(self, repository: Path, abbrev_ref=False) -> Optional[str]:
except Exception as e:
raise RuntimeError(f"An error occurred while getting the current Git ref: {e}") from e


def _fetch_ref(self, repository: Path, ref: str):
try:
result = subprocess.run([
"git",
"-C", os.fspath(repository.resolve()),
"fetch",
"origin",
ref
], check=True, timeout=60)
if result.returncode != 0:
raise RuntimeError(f"git command returned code {result.returncode}")

except Exception as e:
raise RuntimeError(f"An error occurred while fetching origin '{ref}': {e}")

def _checkout_ref_in_subfolder(self, repository: Path, subfolder: Path, ref: str):
def _switch_to_ref_in_subfolder(self, repository: Path, subfolder: Path, ref: str):
try:
result = subprocess.run([
"git",
"-C", os.fspath(repository.resolve()),
"checkout", ref,
"switch", ref,
"--", os.fspath(subfolder.resolve())
], check=True, timeout=60)
if result.returncode != 0:
Expand All @@ -268,8 +252,7 @@ def __copy_tutorial_into_directory(self, run_directory: Path):
ref_requested = self.params_to_use.get("TUTORIALS_REF")
if ref_requested:
logging.debug(f"Checking out tutorials {ref_requested} before copying")
self._fetch_ref(PRECICE_TUTORIAL_DIR,ref_requested)
self._checkout_ref_in_subfolder(PRECICE_TUTORIAL_DIR, self.tutorial.path, ref_requested)
self._switch_to_ref_in_subfolder(PRECICE_TUTORIAL_DIR, self.tutorial.path, ref_requested)

self.tutorial_folder = slugify(f'{self.tutorial.path.name}_{self.case_combination.cases}_{current_time_string}')
destination = run_directory / self.tutorial_folder
Expand All @@ -280,7 +263,7 @@ def __copy_tutorial_into_directory(self, run_directory: Path):
if ref_requested:
with open(destination / "tutorials_ref", 'w') as file:
file.write(ref_requested)
self._checkout_ref_in_subfolder(PRECICE_TUTORIAL_DIR, self.tutorial.path, current_ref)
self._switch_to_ref_in_subfolder(PRECICE_TUTORIAL_DIR, self.tutorial.path, current_ref)

def __copy_tools(self, run_directory: Path):
destination = run_directory / "tools"
Expand Down

0 comments on commit 65c6822

Please sign in to comment.