Is there a way to create a pre-commit hook that will reject the commit in case the new revision fails to compile?

We would like to implement a policy that will force developers to make only changes that will be compiled.

Is there a way to do such a thing using a pre-commit hook? If not, I will be happy to hear any recommendations or workarounds that will preserve the integrity of the source.

+3
source share
5 answers

Failing to precompile using the assembly will be tricky because there is no revision in the repository with the state you want to check at this point. The repository has a pending transaction, which you can check with svnlook; this can be used to implement some rules, but there is no simple commandsvnlook export to create a complete assembly.

The preliminary commit will also have to wait for the result of the assembly before rejecting or completing the commit, which will significantly speed up the slowdown . I suppose this will encourage developers to make a “one big commit at the end of the day” instead of making many smaller (= verified) commits if necessary.

solution 1: do not reject, roll back

, : ( CruiseControl, Team Build ..), . , , . , , , .

2:

( ) "". , . . , , , . . (, , ) svn merge --reintegrate . , .

+3

, , . , . .

+1

; CI-, , , . , , , :)

, /, .

, ( , ).

, , , , ? ?

+1

, SVN.

, JOB . :

  • svn
  • ,
  • 1 3, .
  • .

, Hudson, . , , . , .

0

, , ,

pre-commit, script ( ?), , :

repo="$1"
tx="$2"

# "magic" is a cut or sed command that fits your repository structure
# to find the tag/branch/etc root you need to compile the project
relative_url=$(svnlook dirs-changed -t "$tx" "$repo" | head -1 | magic)

# get a clean copy of the code
# note that this caches e.g. '.o' files from previous commits
# usually making subsequent builds faster
build_dir="~/testcommit/$relative_url"
mkdir -p "$build_dir"
svn co "file://$repo/$relative_url" "$build_dir"
cd "$build_dir"
svn revert -R .
svn up

# update it to match what the user tries to commit
diff_file="/tmp/testcommit."$$".diff"
svnlook diff -t "$tx" "$repo" > $diff_file
# you may have to adjust 'p1' to fit your repository depth
patch -p1 < $diff_file

# adjust to fit your needs
make

if [ some-test-fails ]
then
  # stdout is always discarded
  # stderr is shown to the user if the hook fails
  echo "error message to the user" 1>&2
  exit 1
fi

# allow the commit
exit 0
0

Source: https://habr.com/ru/post/1720080/


All Articles