diff options
-rw-r--r-- | cheatsheet.txt | 16 | ||||
-rwxr-xr-x | hooks/pre-commit | 26 | ||||
-rwxr-xr-x | hooks/pre-commit-copyright-check | 70 | ||||
-rwxr-xr-x | server/mrrepo | 71 |
4 files changed, 59 insertions, 124 deletions
diff --git a/cheatsheet.txt b/cheatsheet.txt index 592d8d9..42655a1 100644 --- a/cheatsheet.txt +++ b/cheatsheet.txt @@ -19,13 +19,27 @@ Global Setup # Enable hooks globally. # - git config --global core.hooksPath <git-project-dir>/hooks + git config --global core.hooksPath <bdep-util-project-dir>/bdep-util/git-hooks # Override the global hooks with the repository-specific hooks (run in a # repository directory). # git config core.hooksPath .git/hooks +Commit Messages + +1. Separate subject from body with a blank line +2. Limit the subject line to 78 characters +3. Capitalize the subject line +4. Do not end the subject line with a period +5. Use the imperative voice in the subject line (e.g., "Implement foo" rather + than "Implemented foo") +6. No articles (a/the) in the subject line +7. Wrap the body at 78 characters +8. Unless this is already captured in the commit payload (e.g., in + code comments, documentation, etc) use the body to explain what + and why + Undo (move to index) last commit git reset --soft HEAD~ diff --git a/hooks/pre-commit b/hooks/pre-commit deleted file mode 100755 index 10a97d9..0000000 --- a/hooks/pre-commit +++ /dev/null @@ -1,26 +0,0 @@ -#! /usr/bin/env bash - -# Execute various pre-commit scripts in a git repository. -# -# To enable the hooks globally run: -# -# $ git config --global core.hooksPath <git-project-dir>/hooks -# -# Notes: -# -# - git passes no parameters to this kind of hooks. -# -# - git changes CWD to the git repository root directory for the hook process. -# -# - git command running from inside the hook sees files that should be -# auto-staged due to the -a git-commit option or similar as already staged. -# -trap 'exit 1' ERR - -src_exe="$(realpath "${BASH_SOURCE[0]}")" -src_dir="$(dirname "$src_exe")" - -# Run each hook checking the exit status and bailing out if unsuccessful. We -# can just exec the last one. -# -exec "$src_dir/pre-commit-copyright-check" diff --git a/hooks/pre-commit-copyright-check b/hooks/pre-commit-copyright-check deleted file mode 100755 index 1bdeffd..0000000 --- a/hooks/pre-commit-copyright-check +++ /dev/null @@ -1,70 +0,0 @@ -#! /usr/bin/env bash - -# Check copyright notices in the COPYRIGHT and LICENSE files and issue a -# warning if they don't include the current year. -# -# Specifically, look first for COPYRIGHT and then LICENSE in the root -# directory and all subdirectories in a project. -# -# Then in each file look for the first line matching the: -# -# ^Copyright (\([cC]\))? ... -# -# Regex, where "..." matches various year lists/ranges (e.g., "2010", "2010, -# 2011", "2010-2011", and their combinations; see the pattern below for -# details). Specifically, we don't consider Copyright notices that: -# -# - don't start at the very beginning of a line (indented, etc) -# - contain something other than years prior to the last year (names, etc) -# - wrap over multiple lines (long year list, etc) -# -# Note also that the current year is obtained in the UTC timezone. -# -trap 'exit 1' ERR -set -o errtrace # Trap in functions. - -function info () { echo "$*" 1>&2; } -function error () { info "$*"; exit 1; } - -# Recursively collect the COPYRIGHT and LICENSE files, skipping the LICENSE -# files in directories that contain the COPYRIGHT file. -# -# @@ Note that for now we assume that there are no spaces in the project file -# and directory names. -# -files=() - -fs=($(find . \( -type f -o -type l \) -name COPYRIGHT)) - -for f in "${fs[@]}"; do - files+=("$f") -done - -fs=($(find . \( -type f -o -type l \) -name LICENSE)) - -for f in "${fs[@]}"; do - d="$(dirname "$f")" - - if [ ! -f "$d/COPYRIGHT" ]; then - files+=("$f") - fi -done - -# Grep for the Copyright notice in the collected files and issue the warning -# if it is present and is outdated. -# -# @@ We should probably skip the COPYRIGHT/LICENSE files whose parent -# directories don't (recursively) contain staged files (think of projects -# with multiple packages, bundled third-party code, etc). Note that we can -# obtain the staged file list with the `git diff --name-only --cached` -# command. -# -current_year="$(date -u +'%Y')" - -for f in "${files[@]}"; do - year="$(sed -n -re 's%^Copyright( +\([cC]\))?[ 0-9,-]*[ ,-]([0-9]{4}).*$%\2%p' "$f" | head -n 1)" - - if [ -n "$year" -a "$year" != "$current_year" ]; then - info "WARNING: last copyright year in '${f#./}' is $year" - fi -done diff --git a/server/mrrepo b/server/mrrepo index 1bb3989..469a03f 100755 --- a/server/mrrepo +++ b/server/mrrepo @@ -40,7 +40,7 @@ # # runuser -u scm -- /var/scm/mrrepo -s -v git.example.org /var/scm # -usage="usage: $0 [-v] [-s] <host> <path>" +usage="usage: $0 [-v] [-s] [<host>] <path>" owd="$(pwd)" trap "{ cd '$owd'; exit 1; }" ERR @@ -65,19 +65,34 @@ while [ "$#" -gt 0 ]; do shift ;; *) - if [ -z "$host" ]; then - host="$1" - elif [ -z "$path" ]; then - path="${1%/}" - else - error "$usage" - fi - shift + break; # The end of options is encountered. ;; esac done -if [ -z "$host" -o -z "$path" ]; then +# Parse the command line arguments. +# +if [ "$#" -lt 1 -o "$#" -gt 2 ]; then + error "$usage" +fi + +# Host. +# +if [ "$#" -gt 1 ]; then + host="$1" + shift + + if [ -z "$host" ]; then + error "$usage" + fi +fi + +# Repositories directory. +# +path="${1%/}" +shift + +if [ -z "$path" ]; then error "$usage" fi @@ -121,8 +136,6 @@ function fetch () # <url> [<curl-options>] curl "${curl_ops[@]}" "$@" "$u" } -fetch "$prot://$host/manifest" -z remote.manifest -o remote.manifest - function manifest_filter () # <file> { sed -e '/^\s*#/d;/^\s*$/d;s/\s\s*/ /g' "$1" @@ -169,18 +182,22 @@ function push_add () # <rep> <url> push_auth["$r"]="$u" } -while read l || [ -n "$l" ]; do - r=$(manifest_field "$l" 1 'path') - u=$(manifest_field "$l" 2) +if [ -n "$host" ]; then + fetch "$prot://$host/manifest" -z remote.manifest -o remote.manifest - remote+=("$r") + while read l || [ -n "$l" ]; do + r=$(manifest_field "$l" 1 'path') + u=$(manifest_field "$l" 2) - # If the push URL is specified then add it to auth/orig maps. - # - if [ -n "$u" ]; then - push_add "$r" "$u" - fi -done < <(manifest_filter remote.manifest) + remote+=("$r") + + # If the push URL is specified then add it to auth/orig maps. + # + if [ -n "$u" ]; then + push_add "$r" "$u" + fi + done < <(manifest_filter remote.manifest) +fi # Find all the existing repositories (directories that end with .git) and sort # them out into mirrored and local public. Note that local private will end up @@ -202,7 +219,7 @@ if test -f manifest; then for i in "${remote[@]}"; do if [ "$i" = "$r" ]; then - error "attempt to mirror into local public repository $r" + error "attempt to mirror into local public repository $r" fi done @@ -222,10 +239,10 @@ if test -f manifest; then for i in "${local[@]}"; do if [ "$i" = "$r" ]; then if [ "$verb" -ge 1 ]; then - info "local public repository $r" - fi - r= - break + info "local public repository $r" + fi + r= + break fi done |