Skip to content
Snippets Groups Projects
Commit 0a257ea8 authored by Pierre-Alain Loizeau's avatar Pierre-Alain Loizeau
Browse files

[mCBM 2024] add script to switch between official and mCBM versions of Geo and Params

parent f8a30891
No related branches found
No related tags found
1 merge request!1765Scripts to use mCBM 2024 separate forks
# Usage
**All these scripts need you to have sourced the login script first!!!! (for VMCWORKDIR)**
1. Initialization and switch between the `Official detached commit` and the `mCBM repository HEAD` mode: just execute
the following script
```
./macro/beamtime/mcbm2024/switch_geo_par.sh
```
1.
# CAVEATS
1. The mCBM repository branch will not be rebased on the official version as that would break the local copies of all
users
1. => If somebody in mCBM need some files/changes from the official version, they will have to `cherry-pick` them or
copy them by hand into a new commit on top of the current state of the mCBM branch
1. After the end of the period where this branch is used, **somebody from the mCBM team** (not one of the central
developers) will have invest the time to cleanup a copy of the branch and prepare clean merge requests to the
official repositories
1. These scripts allow only to work on the `mcbm24_master branch` of the "mcbm versions" and go back to the "offical
versions" \
=> Switching to another branch or a different detached commit than the "official version" will confuse them \
=> This in turn has high chances to lead to broken copies of the `geometry` and/or `parameters` folders
1. Space needed:
- around `100 MB` for geometries
- around `1.6 GB` for parameters
#!/bin/bash
# Copyright (C) 2024 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
# SPDX-License-Identifier: GPL-3.0-only
# First commited by Pierre-Alain Loizeau
check_fix_remote()
{
# Copied/adapted from scripts/connect_upstream_repo.sh
if [[ $# -ne 1 ]]; then
echo "check_fix_remote needs at least one parameter: the url for the remote"
return 1
fi
mcbm_repo=$1
echo "Checking/fixing the mcbm remote in $PWD"
bla=$(git remote -v | grep mcbm)
if [ $? -eq 0 ]; then
bla=$(git remote -v | grep mcbm | grep ${mcbm_repo})
if [ $? -eq 0 ]; then
echo "Remote link mcbm already exist and points to the correct repo"
# don't do anything
else
echo "Remote link mcbm already exist and points to the wrong repo"
git remote set-url mcbm ${mcbm_repo}
fi
else
echo "Remote repo not existing yet => connecting it now"
git remote add mcbm ${mcbm_repo}
fi
return 0
}
START_DIR=$PWD
# I: pre-checks, this part should be read-only actions in terms of the current files (changes only in .git folders)!
# I-A: Geometry folder
# I-A-1) Go to folder
cd ${VMCWORKDIR}/geometry
# I-A-2) Check if the mCBM remote is present and proper, add/fix it if not
if ! check_fix_remote https://git.cbm.gsi.de/mcbm/cbmroot_geometry.git; then
echo "Failed to check/fix the remote of the geometry folder, stopping there"
exit 1
fi
# I-A-3) Check if some local changes are present
if [[ 0 -ne $(git status --porcelain | wc -l) ]]; then
echo "Local changes found in the geometry folder."
echo "=> You need to remove them (or commit them if in mCBM mode) before switching mode"
git status --short
exit 2
fi
# I-B: Parameters folder
# I-B-1) Go to folder
cd ${VMCWORKDIR}/parameters
# I-B-2) Check if the mCBM remote is present and proper, add/fix it if not
if ! check_fix_remote https://git.cbm.gsi.de/mcbm/cbmroot_parameter.git; then
echo "Failed to check/fix the remote of the parameters folder, stopping there"
exit 1
fi
# I-B-3) Check if some local changes are present
if [[ 0 -ne $(git status --porcelain | wc -l) ]]; then
echo "Local changes found in the parameters folder."
echo "=> You need to remove them (or commit them if in mCBM mode) before switching mode"
git status --short
exit 2
fi
# II: switch of branch/commit. Done only after all checks to avoid Geometry and Parameter folder going out of sync
# (one in "Official detached commit" and the other on "mCBM repo HEAD" mode)
# II-A: Geometry folder
# II-A-1) Go to folder
cd ${VMCWORKDIR}/geometry
# II-A-2) Check if current version is the Official detached commit or the mCBM repo HEAD
if [[ 1 -eq $(git status | grep -c "HEAD detached at") ]]; then
# II-A-2a) Switch from "Official detached commit" to "mCBM repo HEAD"
# =====> Fetch latest version
git fetch mcbm
# =====> Simple switch to latest version
if git switch mcbm24_master 2>/tmp/mcbm_switch_err; then
cat /tmp/mcbm_switch_err
else
git switch -t mcbm/mcbm24_master
fi
rm /tmp/mcbm_switch_err
# <= FIXME: Error, master already existing, prob. need check on existing + checkout mcbm_master
else
# IIA-2b) Revert from "mCBM repo HEAD" to "Official detached commit"
# =====> Extract the original commit hash from the InstallGeometry cmake file
hash=$(grep "set(GEOMETRY_VERSION" $VMCWORKDIR/external/InstallGeometry.cmake | sed 's/^[^ ]* //')
hash=${hash%)*}
# =====> Force the switch
echo ${hash}
git checkout ${hash}
fi
# II-B: Parameters folder
# II-B-1) Go to folder
cd ${VMCWORKDIR}/parameters
# II-B-2) Check if current version is the Official detached commit or the mCBM repo HEAD
if [[ 1 -eq $(git status | grep -c "HEAD detached at") ]]; then
# II-B-2a) Switch from "Official detached commit" to "mCBM repo HEAD"
# =====> Fetch latest version
git fetch mcbm
# =====> Simple switch to latest version, create and track if not existing
if git switch mcbm24_master 2>/tmp/mcbm_switch_err; then
cat /tmp/mcbm_switch_err
else
git switch -t mcbm/mcbm24_master
fi
rm /tmp/mcbm_switch_err
else
# II-B-2b) Revert from "mCBM repo HEAD" to "Official detached commit"
# =====> Extract the original commit hash from the InstallParameters cmake file
hash=$(grep "set(PARAMETER_VERSION" $VMCWORKDIR/external/InstallParameter.cmake | sed 's/^[^ ]* //')
hash=${hash%)*}
# =====> Force the switch
echo ${hash}
git checkout ${hash}
fi
cd $START_DIR
exit 0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment