Skip to content
Snippets Groups Projects
Select Git revision
  • a85b92bb79a6fb73f2c34de59675de1cafe0e3db
  • master default protected
  • nightly_master
  • online_mvd_readconf_cleanup protected
  • online_much_readconf_cleanup protected
  • jul25_patches
  • cleanup_rich_v25a
  • jul24_patches
  • nov23_patches
  • DC_2404
  • nighly_master
  • DC_Jan24
  • DC_Nov23
  • DC_Oct23
  • feb23_patches
  • L1Algo-dev9
  • dec21_patches protected
  • apr21_patches protected
  • dev_2025_46
  • dev_2025_45
  • dev_2025_44
  • dev_2025_43
  • dev_2025_42
  • dev_2025_41
  • dev_2025_40
  • dev_2025_39
  • dev_2025_38
  • dev_2025_37
  • dev_2025_36
  • dev_2025_35
  • dev_2025_34
  • dev_2025_33
  • dev_2025_32
  • dev_2025_31
  • dev_2025_30
  • RC_jul25
  • dev_2025_29
  • dev_2025_28
38 results

check-apply-format-changes.sh

Blame
  • Eoin Clerkin's avatar
    Eoin Clerkin authored
    Inserts the declaration on the 1st or 2nd line of scripts.
    
    EMPTY LINE
    
    Short license declarations for .sh files
    
    Inserts the declaration on the 1st or 2nd line of scripts.
    
    EMPTY LINE
    
    Revert "Short license declarations for .sh files"
    
    This reverts commit d3dd8608.
    
    Uses SPDX identifier
    
    Modifies declaration to use SPDX license identifier syntax
    
    Corrects file
    
    Empty line before hashbang removed
    6f6619b0
    History
    check-apply-format-changes.sh 2.31 KiB
    #!/bin/bash
    # Copyright (C) 2020 Facility for Antiproton and Ion Research in Europe, Darmstadt
    # SPDX-License-Identifier: GPL-3.0-only
    # First commited by Pierre-Alain Loizeau
    
    
    if [[ $# -ne 1 ]]; then
      echo "Missing argument! please call this script with either the check or apply argument:"
      echo "./scripts/check-apply-format-changes.sh check"
      echo "./scripts/check-apply-format-changes.sh apply"
      exit -1
    fi
    
    if [[ -z $GIT_CLANG_FORMAT_BIN || -z $CLANG_FORMAT_BIN ]]; then
      echo "Error: GIT_CLANG_FORMAT_BIN or CLANG_FORMAT_BIN not defined"
      echo "=> Please follow the instruction at https://redmine.cbm.gsi.de/projects/cbmroot/wiki/Clang-format"
      exit -1
    fi
    
    # Check clang-format version
    VERSION=$($CLANG_FORMAT_BIN --version)
    if [[ "$VERSION" != *"11.0.0"* ]]; then
      echo "Error: CLANG_FORMAT_BIN version not matching the standard cbmroot one (used in the MR test chain)"
      echo "11.0.0 vs " $VERSION
      echo "=> Please follow the instruction at https://redmine.cbm.gsi.de/projects/cbmroot/wiki/Clang-format"
      exit -1
    fi
    
    if [ -z $UPSTREAM ]; then
      UPSTREAM=$(git remote -v | grep git.cbm.gsi.de[:/]computing/cbmroot | cut -f1 | uniq)
      if [ -z $UPSTREAM ]; then
        echo "Error: Name of upstream repository not provided and not found by automatic means"
        echo 'Please provide if by checking your remotes with "git remote -v" and exporting UPSTREAM'
        exit -1
      fi
    fi
    echo "Upstream name is :" $UPSTREAM
    
    BASE_COMMIT=$UPSTREAM/master
    CHANGED_FILES=$(git diff --name-only $BASE_COMMIT | grep -E '.*\.(h|hpp|c|C|cpp|cxx|tpl)$' | grep -viE '.*LinkDef.h$')
    
    case $1 in
      check)
        echo "Checking if there are format changes required"
        git fetch $UPSTREAM
        $GIT_CLANG_FORMAT_BIN --binary $CLANG_FORMAT_BIN --commit $BASE_COMMIT --diff $CHANGED_FILES --extensions h,hpp,c,C,cpp,cxx,tpl
        ;;
    
      apply)
        echo "Applying required format changes"
        $GIT_CLANG_FORMAT_BIN --binary $CLANG_FORMAT_BIN --verbose --commit $BASE_COMMIT $CHANGED_FILES --extensions h,hpp,c,C,cpp,cxx,tpl
        git status
        echo "Next step: git add "$CHANGED_FILES
        echo 'Then     : git commit -m"Apply clang-format"'
        ;;
    
      *)
        echo "Invalid argument! please call this script with either the check or apply argument:"
        echo "./scripts/check-apply-format-changes.sh check"
        echo "./scripts/check-apply-format-changes.sh apply"
        exit -1
        ;;
    esac