diff --git a/macro/beamtime/mcbm2024/README_GeoPar.md b/macro/beamtime/mcbm2024/README_GeoPar.md index ff01db0495086fac43ca42ad6ce31816fa0823e4..fa4a77b2e62197c33977e6d728297b0303b3a5eb 100644 --- a/macro/beamtime/mcbm2024/README_GeoPar.md +++ b/macro/beamtime/mcbm2024/README_GeoPar.md @@ -27,6 +27,15 @@ => This will bring in the local copy the latest changes from the remote branch in the mCBM fork \ => This will also ensure the local copies are compatible with a fast-forward push to the remote branch in the mCBM fork (force-push or any git history changes are not allowed). +1. Commiting changes + - Either do it by hand in the geometry/parameters folders (they are independent git clones) + - Or use the following script. This will take care of making a single commit for each of the two folders, + prepare them for a fast-forward push and push them. You will probably be asked for some login/password. + ``` + ./macro/beamtime/mcbm2024/commit_push_geo_par.sh + ``` + => This script was not 100% tested as the original author (@p.-a.loizeau) did not have local changes to push \ + => **But all individual commands were tested and the scripts was checked with a semantics checker!** # CAVEATS diff --git a/macro/beamtime/mcbm2024/commit_push_geo_par.sh b/macro/beamtime/mcbm2024/commit_push_geo_par.sh new file mode 100755 index 0000000000000000000000000000000000000000..0b551dcb3c28ce68fb25929a3fd1887297669028 --- /dev/null +++ b/macro/beamtime/mcbm2024/commit_push_geo_par.sh @@ -0,0 +1,109 @@ +#!/bin/bash +# Copyright (C) 2024 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt +# SPDX-License-Identifier: GPL-3.0-only +# First commited by Pierre-Alain Loizeau + +check_author_info() +{ + name_set=$(git config -l | grep -c "user.name") + email_set=$(git config -l | grep -c "user.email") + + author_ok=0 + if [[ 1 -ne ${name_set} ]]; then + echo "Error: user.name not set in git config (neither globally no locally)" + author_ok=1 + fi + if [[ 1 -ne ${email_set} ]]; then + echo "Error: user.email not set in git config (neither globally no locally)" + author_ok=$((author_ok+2)) + fi + return ${author_ok} +} + +Help() +{ + # Non-aligned raw text due to escaped characters! + echo "Allowed input parameters for this script are:" + echo " -h | --help this help" + echo " -f | --folder [\"geometry\", \"parameters\"] folder to push (and commitbefore if needed) (mandatory)" + echo " -m | --message \"<commit message>\" commit message in case some not-yet committed local" + echo " files/changes are present in the folder (optional)" +} + +while [ $# -gt 0 ]; do + case "$1" in + -h|--help) Help; exit 0;; + -f|--folder) folder="$2"; shift;; + -m|--message) message="$2"; shift;; + \?) # Invalid option + echo "Error: Invalid option" + Help + exit 1;; + esac + shift +done + +if [ -z "${folder}" ]; then + echo "Missing mandatory parameter: folder to commit/push" + Help + exit 1 +fi +if [[ ! "${folder}" =~ ^(geometry|parameters)$ ]]; then + echo "Invalid value for the folder parameter: ${folder}" + echo "It has to be either \"geometry\" or \"parameters\"" + Help + exit 1 +fi + +# I: pre-checks, this part should be read-only actions in terms of the current files (changes only in .git folders)! +# I-1) Go to folder +cd ${VMCWORKDIR}/${folder} +# I-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 + echo "${folder} folder is in official version, cannot update to get latest mCBM changes, stopping there" + exit 2 +fi +# I-3) Check if some local changes are present, in which case make a commit with them if commit message was provided +if [[ 0 -ne $(git status --porcelain | wc -l) ]]; then + echo "Local changes found in the geometry folder." + if [ -n "${message}" ]; then + echo "=> Commit message provided, trying to make a commit with all of them" + if ! check_author_info; then + echo "Author info missing, cannot make a proper commit" + exit 4 + fi + git add . + git commit -m"${message}" + else + echo "=> no commit message provided, stopping there. Following files/changes are present" + git status --short + Help + exit 3 + fi +fi + +# II: check that local history is compatible with remote version and push if ok +# II-1) fetch latest version of remote +git fetch mcbm +# II-2) rebase only this folder. +# FIXME ?: Could call the rebase script to avoid copy-paste, but then both folders would be rebased which may make +# to a deadlock if both have local changed? +if ! git rebase mcbm/mcbm24_master; then + echo "Rebasing the ${folder} folder failed, most probably due to local commits in conflict" + echo "Aborting (=reverting) the rebase!!!" + git rebase --abort + echo "Please rebase by hand in the geometry folder with the following commands:" + echo "git rebase mcbm/mcbm24_master # Will lead to a conflict" + echo "git rebase --continue # After each resolution of problems, for each conflicting commit" + echo "git rebase --abort # If not able to resolve the conflicts" + echo "=> If lost, please google \"git rebase resolve conflicts\" or ask other mcbm members" + exit 5 +else + echo "Now up to date with the mcbm remote version of the ${folder} folder" +fi +# II-3) push without force or force-with-lease, no change to remote history allowed +git push + +cd ${START_DIR} + +exit 0