Skip to content

Commit 44d63f9

Browse files
committed
Added protection hook to commit.
1 parent 5fcdb02 commit 44d63f9

File tree

6 files changed

+76
-6
lines changed

6 files changed

+76
-6
lines changed

install_protection_hook.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/bin/bash
2+
3+
# copyright ############################### #
4+
# This file is part of the Xboinc Package. #
5+
# Copyright (c) CERN, 2023. #
6+
# ######################################### #
7+
8+
9+
cat << 'EOF' > pre-commit
10+
#!/bin/sh
11+
12+
branch="$(git rev-parse --abbrev-ref HEAD)"
13+
14+
if [ "$branch" = "main" ]
15+
then
16+
echo "Cannot commit to main!"
17+
echo "Use pull requests or, if package admin, the versioning script."
18+
exit 1
19+
fi
20+
21+
for file in pyproject.toml version.sh LICENSE install_protection_hook.sh pin_xsuite_versions.sh xboinc/general.py 'xboinc/executable/.*'
22+
do
23+
git diff --name-only | grep '^'${file}'$' &> /dev/null
24+
if [ $? -eq 0 ]
25+
then
26+
thisfile=${file/.\*/\*}
27+
echo "File $thisfile is protected but has local changes."
28+
echo "Restore the file with 'git restore "${thisfile}"' before commiting anything, or force this commit with 'commit --no-verify'."
29+
exit 1
30+
fi
31+
git diff --cached --name-only | grep '^'${file}'$' &> /dev/null
32+
if [ $? -eq 0 ]
33+
then
34+
thisfile=${file/.\*/\*}
35+
echo "File $thisfile is protected but has local changes that are staged."
36+
echo "Restore the file with 'git restore "${thisfile}"' before commiting anything, or force this commit with 'commit --no-verify'."
37+
exit 1
38+
fi
39+
done
40+
EOF
41+
42+
chmod +x pre-commit
43+
mv pre-commit .git/hooks/

version.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ sed -i "s/\(__version__ =\).*/\1 '"${new_ver}"'/" xboinc/general
9797
sed -i "s/\(assert __version__ ==\).*/\1 '"${new_ver}"'/" tests/test_version.py
9898
git reset
9999
git add pyproject.toml xboinc/general.py tests/test_version.py xboinc/executable/main.c
100-
git commit -m "Updated version number to v"${new_ver}"."
100+
git commit --no-verify -m "Updated version number to v"${new_ver}"."
101101
git push
102102

103103
# Make and accept pull request
@@ -122,3 +122,6 @@ curl \
122122

123123
# Build release and publish to PyPi
124124
poetry publish --build
125+
126+
127+

xboinc/executable/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
# ######################################### #
55

66
from .generate_executable_source import generate_executable_source, generate_executable
7+
from .default_tracker import get_default_tracker

xboinc/executable/default_tracker.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
1+
# copyright ############################### #
2+
# This file is part of the Xboinc Package. #
3+
# Copyright (c) CERN, 2023. #
4+
# ######################################### #
5+
16
import xtrack as xt
27
import xfields as xf
38
import xobjects as xo
49
import xcoll as xc
510

611

12+
# ===============================================================================================
13+
# IMPORTANT
14+
# ===============================================================================================
15+
# Only make changes to this file just before a minor version bump (need a separate commit though)
16+
# to avoid having multiple xboinc versions with out-of-sync executables.
17+
# ===============================================================================================
718

819
def get_default_tracker():
920
"""

xboinc/executable/main.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// copyright ############################### #
2+
// This file is part of the Xboinc Package. #
3+
// Copyright (c) CERN, 2023. #
4+
// ######################################### #
5+
16
#include <math.h>
27

38
#include "xtrack_tracker.h"
@@ -7,11 +12,18 @@
712
#include <stdlib.h>
813

914

15+
// ===============================================================================================
16+
// IMPORTANT
17+
// ===============================================================================================
18+
// Only make changes to this file just before a minor version bump (need a separate commit though)
19+
// to avoid having multiple xboinc versions with out-of-sync executables.
20+
21+
// ===============================================================================================
1022
// Do not change
11-
// ==================================
23+
// ===============================================================================================
1224
// version XXX.YYY as int (no patch)
1325
int64_t xboinc_exec_version = 0;
14-
// ==================================
26+
// ===============================================================================================
1527

1628

1729
int8_t* file_to_buffer(char *filename, int8_t* buf_in){

xboinc/general.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
_pkg_root = Path(__file__).parent.absolute()
99

1010

11-
# ====================================================================
11+
# ==========================================================================================
1212
# Do not change
13-
# ====================================================================
13+
# ==========================================================================================
1414

1515
__version__ = '0.0.3'
1616

@@ -27,4 +27,4 @@
2727
'xcoll' : '0.2.5',
2828
}
2929

30-
# ====================================================================
30+
# ==========================================================================================

0 commit comments

Comments
 (0)