diff --git a/.clang-format b/.clang-format index 7fbf4339..982a20eb 100644 --- a/.clang-format +++ b/.clang-format @@ -1,35 +1,35 @@ BasedOnStyle: WebKit Language: Cpp AlignAfterOpenBracket: true AlwaysBreakTemplateDeclarations: true AllowShortFunctionsOnASingleLine: Inline BreakBeforeBraces: Linux ColumnLimit: 0 CommentPragmas: '^ (FALLTHROUGH|krazy:) ' Standard: Cpp11 -IncludeBlocks: Regroup -IncludeCategories: -# include order: -# 1. "config-kpa-xxx.h" -# 2. "MAIN_HEADER.h" -# 3. KPA-includes -# 4. other includes - - Regex: '^"(DB|Utilities|ThumbnailView|AnnotationDialog|BackgroundJobs|BackgroundTaskManager|Browser|CategoryListView|DateBar|Exif|HTMLGenerator|ImageManager|ImportExport|MainWindow|MainWindow/DuplicateMerger|Plugins|Settings|Viewer|XMLDB)/' - Priority: 2 - - Regex: '^(/dev/null 2>&1 +then + against=HEAD +else + # Initial commit: diff against an empty tree object + against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 +fi + +# If you want to allow non-ascii filenames set this variable to true. +allownonascii=$(git config hooks.allownonascii) + +# Redirect output to stderr. +exec 1>&2 + +# Cross platform projects tend to avoid non-ascii filenames; prevent +# them from being added to the repository. We exploit the fact that the +# printable range starts at the space character and ends with tilde. +if [ "$allownonascii" != "true" ] && + # Note that the use of brackets around a tr range is ok here, (it's + # even required, for portability to Solaris 10's /usr/bin/tr), since + # the square bracket bytes happen to fall in the designated range. + test $(git diff --cached --name-only --diff-filter=A -z $against | + LC_ALL=C tr -d '[ -~]\0' | wc -c) != 0 +then + echo "Error: Attempt to add a non-ascii file name." + echo + echo "This can cause problems if you want to work" + echo "with people on other platforms." + echo + echo "To be portable it is advisable to rename the file ..." + echo + echo "If you know what you are doing you can disable this" + echo "check using:" + echo + echo " git config hooks.allownonascii true" + echo + exit 1 +fi + +# If there are whitespace errors, print the offending file names and fail. +exec git diff-index --check --cached $against -- diff --git a/dev/githooks/pre-commit.d/02-check-copyright-header b/dev/githooks/pre-commit.d/02-check-copyright-header new file mode 100755 index 00000000..d5f1e2cd --- /dev/null +++ b/dev/githooks/pre-commit.d/02-check-copyright-header @@ -0,0 +1,36 @@ +#!/bin/bash +### +# Check all added or modified files that have a copyright line +# for an up-to-date copyright year. +# e.g. "Copyright (C) 2018-2019 The KPhotoAlbum Development Team" +### + +set -e + +year=$(date +%Y) +IFS=$'\n' +for line in $(git status -s) +do + # if the file is added or modified + if [[ $line == A* || $line == M* ]] + then + if head -n5 "${line:3}" | grep -q -i copyright + then + if ! head -n5 "${line:3}" | grep -q -i "copyright.*[ -]$year" + then + missing_year="$missing_year\n${line:3}" + fi + fi + fi +done + +if [ -n "$missing_year" ] +then + echo -e "Please update copyright year for the following files:$missing_year" + # also check if the Copyright statement in main.cpp is ok: + if ! grep -q -i "i18n(\"Copyright (C) 2003-$year " main.cpp + then + echo "...and also update the copyright statement in main.cpp!" + fi + exit 1 +fi diff --git a/dev/githooks/pre-commit.d/03-check-untracked_source_files b/dev/githooks/pre-commit.d/03-check-untracked_source_files new file mode 100755 index 00000000..29b4e9c6 --- /dev/null +++ b/dev/githooks/pre-commit.d/03-check-untracked_source_files @@ -0,0 +1,25 @@ +#!/bin/bash +### +# Check for untracked C++ source files. +### + +set -e + +if [[ -z "$CHECK_UNTRACKED" ]] +then + CHECK_UNTRACKED=$(git config --default true --type bool --get kpa.checkUntracked) +fi +if [[ "$CHECK_UNTRACKED" == false ]] +then + exit 0 +fi + +retval=0 +untracked_files=$(git status -s | grep '^?? ' | grep '\.\(cpp\|h\)' | sed 's/^.../ /') +if [[ -n "$untracked_files" ]] +then + printf "Untracked files:\n$untracked_files\n" + printf "** You can suppress this check by setting 'git config kpa.checkUntracked false'\n" + printf "** or by setting the environment variable CHECK_UNTRACKED=false\n" + exit 1 +fi diff --git a/dev/githooks/pre-commit.d/04-check-clang-format b/dev/githooks/pre-commit.d/04-check-clang-format new file mode 100755 index 00000000..afed2f16 --- /dev/null +++ b/dev/githooks/pre-commit.d/04-check-clang-format @@ -0,0 +1,42 @@ +#!/bin/bash +### +# Check all added or modified C++ source files for correct formatting +### + +set -e + +if ! which clang-format >/dev/null 2>&1 +then + echo "Please install clang-format!" +fi + +check_format() +# check_format FILE +# return 0 iff FILE is formatted correctly +{ + [[ $(clang-format -style=file -output-replacements-xml "$1" | wc -l) -eq 3 ]] +} + +reformat_files= +IFS=$'\n' +for line in $(git status -s) +do + # if the file is added or modified + if [[ "$line" == A* || "$line" == M* ]] + then + if [[ "$line" == *.cpp || "$line" == *.h ]] + then + if ! check_format "${line:3}" + then + reformat_files="$reformat_files\n ${line:3}" + fi + fi + fi +done + +if [[ -n "$reformat_files" ]] +then + printf "Incorrect coding style:$reformat_files\n" + printf "** Run \"git clang-format\" to reformat all staged changes..." + exit 1 +fi diff --git a/dev/scripts/neon-sync.sh b/dev/scripts/neon-sync.sh new file mode 100755 index 00000000..ba545e24 --- /dev/null +++ b/dev/scripts/neon-sync.sh @@ -0,0 +1,9 @@ +#!/bin/sh -e +# Sync the master branch with 5.x (the tracking branch for neon/dev-stable) + +echo "=== Updating Neon/dev-stable branch (5.x) ===" +git checkout 5.x +git pull +git merge master +git push +git checkout master