From 1983e47a5f635d03a0011ee90fafc223411a128f Mon Sep 17 00:00:00 2001
From: Guillaume Samson <guillaume.samson@mercator-ocean.fr>
Date: Tue, 7 Dec 2021 16:59:23 +0000
Subject: [PATCH] Sette custom dir

---
 sette/all_functions.sh   |  6 +++---
 sette/param.cfg          |  2 ++
 sette/prepare_exe_dir.sh | 11 +++++++----
 sette/sette.sh           |  6 +++---
 4 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/sette/all_functions.sh b/sette/all_functions.sh
index c5351d3ee..e8bc906cd 100755
--- a/sette/all_functions.sh
+++ b/sette/all_functions.sh
@@ -171,8 +171,8 @@ clean_config() {
 
 # define validation dir
 set_valid_dir () {
-    REVISION_NB=`git rev-list --abbrev-commit origin | head -1l`
-    REV_DATE0="`git log -1 | grep Date | sed -e 's/.*Date: *//' -e's/ +.*$//'`"
+    REVISION_NB=`git -C ${MAIN_DIR} rev-list --abbrev-commit origin | head -1l`
+    REV_DATE0="`git -C ${MAIN_DIR} log -1 | grep Date | sed -e 's/.*Date: *//' -e's/ +.*$//'`"
     REV_DATE=`${DATE_CONV}"${REV_DATE0}" +"%y%j"`
     REVISION_NB=${REV_DATE}_${REVISION_NB}
     if [ ${#REVISION_NB} -eq 0 ]
@@ -185,7 +185,7 @@ set_valid_dir () {
     else
     echo "value of revision number of NEMOGCM: ${REVISION_NB}"
     fi
-    localchanges=`git status --short -uno | wc -l`
+    localchanges=`git -C ${MAIN_DIR} status --short -uno | wc -l`
     if [[ $localchanges > 0 ]] ; then
      REVISION_NB=${REVISION_NB}+
     fi
diff --git a/sette/param.cfg b/sette/param.cfg
index 4d1651b43..adac77117 100644
--- a/sette/param.cfg
+++ b/sette/param.cfg
@@ -37,6 +37,8 @@ FORCING_DIR=${SETTE_FORCING_DIR:-$WORKDIR/FORCING}
 NEMO_VALIDATION_DIR=${SETTE_NEMO_VALIDATION_DIR:-$MAIN_DIR}/NEMO_VALIDATION
 # input files storing (namelist, iodef ...) (DO NOT CHANGE)
 INPUT_DIR=${CONFIG_DIR}/${NEW_CONF}/EXP00
+# optional custom SETTE tests directory
+#export CUSTOM_DIR=/path/to/custom/sette/tests
 # ------------------------------------------------------------------------------------------
 #
 # RUN setup
diff --git a/sette/prepare_exe_dir.sh b/sette/prepare_exe_dir.sh
index e0a2d7208..1be9693fb 100755
--- a/sette/prepare_exe_dir.sh
+++ b/sette/prepare_exe_dir.sh
@@ -64,12 +64,15 @@ set -o posix
 #-
 
 
-cd ${CONFIG_DIR}
-mkdir -p ${NEW_CONF}/${TEST_NAME}
-
 # PREPARE EXEC_DIR
 #==================
-export EXE_DIR=${CONFIG_DIR}/${NEW_CONF}/${TEST_NAME}
+if [ -z "${CUSTOM_DIR}" ]; then
+  export EXE_DIR=${CONFIG_DIR}/${NEW_CONF}/${TEST_NAME}
+else
+  NEMO_REV=$( git rev-parse --short HEAD 2> /dev/null )
+  export EXE_DIR=${CUSTOM_DIR}/${SETTE_SUB_VAL}_${NEMO_REV}/${NEW_CONF}/${TEST_NAME}
+fi
+mkdir -p ${EXE_DIR}
 
 cp -RL ${CONFIG_DIR}/${NEW_CONF}/EXP00/* ${EXE_DIR}/.
 #cat ${SETTE_DIR}/iodef_sette.xml | sed -e"s;DEF_SHARED;${CONFIG_DIR0}/SHARED;" > ${EXE_DIR}/iodef.xml
diff --git a/sette/sette.sh b/sette/sette.sh
index 992f8ebf5..8724abd31 100755
--- a/sette/sette.sh
+++ b/sette/sette.sh
@@ -36,11 +36,11 @@ export USER_INPUT='yes'        # Default: yes => request user input on decisions
                                #                 3. regarding creation of directories
 #
 # Check that git branch is usable
-git branch --show-current >&/dev/null
+git branch --show-current >& /dev/null
 if [[ $? == 0 ]] ; then
   # subdirectory below NEMO_VALIDATION_DIR defaults to branchname
-  export SETTE_SUB_VAL="$(git branch --show-current)" 
-  export SETTE_THIS_BRANCH=$SETTE_SUB_VAL
+  export SETTE_SUB_VAL="$(git branch --show-current)"
+  export SETTE_THIS_BRANCH=${SETTE_SUB_VAL}
 else
   # subdirectory below NEMO_VALIDATION_DIR defaults to "MAIN"
   export SETTE_SUB_VAL="MAIN"
-- 
GitLab