cisco_node_utils 1.0.1 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.rubocop.yml +81 -1
- data/.travis.yml +9 -0
- data/CHANGELOG.md +72 -6
- data/CONTRIBUTING.md +32 -7
- data/README.md +70 -7
- data/Rakefile +17 -0
- data/bin/check_metric_limits.rb +109 -0
- data/bin/git/hooks/commit-msg/enforce_style +81 -0
- data/bin/git/hooks/hook_lib +108 -0
- data/bin/git/hooks/hooks-wrapper +38 -0
- data/bin/git/hooks/post-flow-hotfix-start/update-version +24 -0
- data/bin/git/hooks/post-flow-release-finish/update-version +29 -0
- data/bin/git/hooks/post-flow-release-start/update-version +19 -0
- data/bin/git/hooks/post-merge/update-hooks +6 -0
- data/bin/git/hooks/post-rewrite/update-hooks +6 -0
- data/bin/git/hooks/pre-commit/rubocop +20 -0
- data/bin/git/hooks/pre-commit/validate-diffs +31 -0
- data/bin/git/hooks/pre-push/check-changelog +24 -0
- data/bin/git/hooks/pre-push/rubocop +7 -0
- data/bin/git/update-hooks +65 -0
- data/cisco_node_utils.gemspec +9 -3
- data/docs/README-develop-best-practices.md +404 -0
- data/docs/README-develop-node-utils-APIs.md +215 -365
- data/docs/README-maintainers.md +33 -3
- data/docs/template-router.rb +89 -91
- data/docs/template-test_router.rb +52 -55
- data/lib/.rubocop.yml +18 -0
- data/lib/cisco_node_utils.rb +2 -19
- data/lib/cisco_node_utils/README_YAML.md +1 -9
- data/lib/cisco_node_utils/bgp.rb +664 -0
- data/lib/cisco_node_utils/bgp_af.rb +530 -0
- data/lib/cisco_node_utils/bgp_neighbor.rb +425 -0
- data/lib/cisco_node_utils/bgp_neighbor_af.rb +709 -0
- data/lib/cisco_node_utils/cisco_cmn_utils.rb +59 -25
- data/lib/cisco_node_utils/command_reference.rb +72 -74
- data/lib/cisco_node_utils/command_reference_common.yaml +174 -9
- data/lib/cisco_node_utils/command_reference_common_bgp.yaml +535 -0
- data/lib/cisco_node_utils/command_reference_n7k.yaml +4 -0
- data/lib/cisco_node_utils/command_reference_n9k.yaml +0 -9
- data/lib/cisco_node_utils/configparser_lib.rb +152 -147
- data/lib/cisco_node_utils/dns_domain.rb +79 -0
- data/lib/cisco_node_utils/domain_name.rb +71 -0
- data/lib/cisco_node_utils/interface.rb +167 -161
- data/lib/cisco_node_utils/interface_ospf.rb +78 -81
- data/lib/cisco_node_utils/name_server.rb +64 -0
- data/lib/cisco_node_utils/node.rb +154 -198
- data/lib/cisco_node_utils/node_util.rb +61 -0
- data/lib/cisco_node_utils/ntp_config.rb +65 -0
- data/lib/cisco_node_utils/ntp_server.rb +76 -0
- data/lib/cisco_node_utils/platform.rb +174 -165
- data/lib/cisco_node_utils/radius_global.rb +146 -0
- data/lib/cisco_node_utils/radius_server.rb +295 -0
- data/lib/cisco_node_utils/router_ospf.rb +59 -63
- data/lib/cisco_node_utils/router_ospf_vrf.rb +226 -210
- data/lib/cisco_node_utils/snmpcommunity.rb +52 -58
- data/lib/cisco_node_utils/snmpgroup.rb +22 -23
- data/lib/cisco_node_utils/snmpserver.rb +99 -103
- data/lib/cisco_node_utils/snmpuser.rb +294 -274
- data/lib/cisco_node_utils/syslog_server.rb +92 -0
- data/lib/cisco_node_utils/syslog_settings.rb +69 -0
- data/lib/cisco_node_utils/tacacs_server.rb +137 -133
- data/lib/cisco_node_utils/tacacs_server_host.rb +84 -87
- data/lib/cisco_node_utils/version.rb +2 -1
- data/lib/cisco_node_utils/vlan.rb +28 -31
- data/lib/cisco_node_utils/vrf.rb +80 -0
- data/lib/cisco_node_utils/vtp.rb +100 -97
- data/lib/cisco_node_utils/yum.rb +15 -17
- data/tests/.rubocop.yml +15 -0
- data/tests/basetest.rb +81 -36
- data/tests/ciscotest.rb +38 -78
- data/{lib/cisco_node_utils → tests}/platform_info.rb +12 -8
- data/{lib/cisco_node_utils → tests}/platform_info.yaml +1 -1
- data/tests/test_bgp_af.rb +920 -0
- data/tests/test_bgp_neighbor.rb +403 -0
- data/tests/test_bgp_neighbor_af.rb +589 -0
- data/tests/test_command_config.rb +65 -62
- data/tests/test_command_reference.rb +31 -45
- data/tests/test_dns_domain.rb +113 -0
- data/tests/test_domain_name.rb +86 -0
- data/tests/test_interface.rb +424 -548
- data/tests/test_interface_ospf.rb +248 -432
- data/tests/test_interface_svi.rb +56 -79
- data/tests/test_interface_switchport.rb +196 -272
- data/tests/test_name_server.rb +85 -0
- data/tests/test_node.rb +7 -6
- data/tests/test_node_ext.rb +133 -186
- data/tests/test_ntp_config.rb +49 -0
- data/tests/test_ntp_server.rb +74 -0
- data/tests/test_platform.rb +58 -37
- data/tests/test_radius_global.rb +78 -0
- data/tests/test_radius_server.rb +185 -0
- data/tests/test_router_bgp.rb +838 -0
- data/tests/test_router_ospf.rb +49 -80
- data/tests/test_router_ospf_vrf.rb +274 -392
- data/tests/test_snmpcommunity.rb +128 -172
- data/tests/test_snmpgroup.rb +12 -14
- data/tests/test_snmpserver.rb +160 -189
- data/tests/test_snmpuser.rb +568 -717
- data/tests/test_syslog_server.rb +88 -0
- data/tests/test_syslog_settings.rb +54 -0
- data/tests/test_tacacs_server.rb +113 -148
- data/tests/test_tacacs_server_host.rb +108 -161
- data/tests/test_vlan.rb +63 -79
- data/tests/test_vrf.rb +92 -0
- data/tests/test_vtp.rb +108 -126
- data/tests/test_yum.rb +47 -41
- metadata +92 -56
- data/.rubocop_todo.yml +0 -293
- data/docs/.rubocop.yml +0 -13
- data/docs/template-feature.rb +0 -45
- data/docs/template-test_feature.rb +0 -51
- data/tests/test_all_cisco.rb +0 -46
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
#
|
|
3
|
+
# Enforce rules of good commit message style
|
|
4
|
+
# http://chris.beams.io/posts/git-commit/#seven-rules
|
|
5
|
+
|
|
6
|
+
message_file = ARGV[0]
|
|
7
|
+
full_message = File.read(message_file)
|
|
8
|
+
message_lines = full_message.split("\n")
|
|
9
|
+
# Omit comment lines - they don't need to be validated!
|
|
10
|
+
message_lines = message_lines.select { |i| i.empty? || i[/^[^#]/] }
|
|
11
|
+
|
|
12
|
+
$errors = 0 # rubocop:disable Style/GlobalVars
|
|
13
|
+
|
|
14
|
+
def failure(msg)
|
|
15
|
+
if STDOUT.tty?
|
|
16
|
+
puts "\t...[ \033[31mFAIL\033[0m ] #{msg}"
|
|
17
|
+
else
|
|
18
|
+
puts msg
|
|
19
|
+
end
|
|
20
|
+
$errors += 1 # rubocop:disable Style/GlobalVars
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# 1. Separate subject from body with a blank line
|
|
24
|
+
if message_lines.length > 1
|
|
25
|
+
unless message_lines[1].empty?
|
|
26
|
+
failure 'Separate subject (first line) from body with a blank line'
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# 2. Limit the subject line to 50 characters
|
|
31
|
+
if message_lines.first.length > 50
|
|
32
|
+
failure 'First line of commit message should be no more than 50 characters'
|
|
33
|
+
puts message_lines.first
|
|
34
|
+
puts '^' * 50
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# 3. Capitalize the subject line
|
|
38
|
+
unless message_lines.first =~ /^[A-Z]/
|
|
39
|
+
failure 'Begin commit message subject line with a capital letter'
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
# 4. Do not end the subject line with a period
|
|
43
|
+
if message_lines.first =~ /[!.,;]\s*$/
|
|
44
|
+
failure 'Do not end the subject line with punctuation'
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# 5. Use the imperative mood in the subject line
|
|
48
|
+
# This is very hard to enforce by automation, so
|
|
49
|
+
# let's just check some likely cases:
|
|
50
|
+
non_imperatives = [/adds$/,
|
|
51
|
+
/added$/,
|
|
52
|
+
/change[ds]$/,
|
|
53
|
+
/fixe[ds]$/,
|
|
54
|
+
/merge[ds]$/,
|
|
55
|
+
/remove[ds]$/,
|
|
56
|
+
/update[ds]$/,
|
|
57
|
+
]
|
|
58
|
+
s = message_lines.first.split(' ').first.downcase
|
|
59
|
+
if non_imperatives.any? { |re| re.match(s) }
|
|
60
|
+
failure 'Use the imperative mood in the subject line'
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# 6. Wrap the body at 72 characters
|
|
64
|
+
if message_lines.any? { |line| line.length > 72 }
|
|
65
|
+
failure 'Wrap the body at 72 characters'
|
|
66
|
+
puts '-' * 72
|
|
67
|
+
puts message_lines.select { |line| line.length > 72 }.join("\n")
|
|
68
|
+
puts '-' * 72
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
# 7. Use the body to explain what and why vs. how
|
|
72
|
+
# The user will just need to exercise judgment on this one :)
|
|
73
|
+
|
|
74
|
+
if $errors > 0 # rubocop:disable Style/GlobalVars
|
|
75
|
+
puts 'Rejected commit message:'
|
|
76
|
+
puts '{'
|
|
77
|
+
puts message_lines.join("\n")
|
|
78
|
+
puts '}'
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
exit $errors # rubocop:disable Style/GlobalVars
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
#
|
|
3
|
+
# Shared library for git hooks
|
|
4
|
+
|
|
5
|
+
# Colors
|
|
6
|
+
DULL=0
|
|
7
|
+
FG_BLACK=30
|
|
8
|
+
FG_RED=31
|
|
9
|
+
FG_GREEN=32
|
|
10
|
+
FG_YELLOW=33
|
|
11
|
+
FG_BLUE=34
|
|
12
|
+
FG_MAGENTA=35
|
|
13
|
+
FG_CYAN=36
|
|
14
|
+
FG_WHITE=37
|
|
15
|
+
FG_NULL=00
|
|
16
|
+
BG_NULL=00
|
|
17
|
+
ESC="["
|
|
18
|
+
RESET="${ESC}0m"
|
|
19
|
+
BOLD="${ESC}1m"
|
|
20
|
+
BLACK="${ESC}${DULL};${FG_BLACK}m"
|
|
21
|
+
RED="${ESC}${DULL};${FG_RED}m"
|
|
22
|
+
GREEN="${ESC}${DULL};${FG_GREEN}m"
|
|
23
|
+
YELLOW="${ESC}${DULL};${FG_YELLOW}m"
|
|
24
|
+
BLUE="${ESC}${DULL};${FG_BLUE}m"
|
|
25
|
+
MAGENTA="${ESC}${DULL};${FG_MAGENTA}m"
|
|
26
|
+
CYAN="${ESC}${DULL};${FG_CYAN}m"
|
|
27
|
+
WHITE="${ESC}${DULL};${FG_WHITE}m"
|
|
28
|
+
|
|
29
|
+
# Top-level directory of our repository
|
|
30
|
+
export REPO_DIR="$(git rev-parse --show-toplevel 2>/dev/null)"
|
|
31
|
+
|
|
32
|
+
#DEBUG=1
|
|
33
|
+
debug() {
|
|
34
|
+
[ "$DEBUG" == 1 ] && echo $1
|
|
35
|
+
}
|
|
36
|
+
export -f debug
|
|
37
|
+
|
|
38
|
+
script_name() {
|
|
39
|
+
echo -e "*** ${BLUE}Running Git hook script: $*${RESET}..."
|
|
40
|
+
}
|
|
41
|
+
export -f script_name
|
|
42
|
+
|
|
43
|
+
step_name() {
|
|
44
|
+
echo -e "\t${BOLD}$*${RESET}"
|
|
45
|
+
}
|
|
46
|
+
export -f step_name
|
|
47
|
+
|
|
48
|
+
success() {
|
|
49
|
+
echo -e "\t...[ ${GREEN}OK${RESET} ]"
|
|
50
|
+
}
|
|
51
|
+
export -f success
|
|
52
|
+
|
|
53
|
+
fail() {
|
|
54
|
+
local RC=$1
|
|
55
|
+
local msg=$2
|
|
56
|
+
echo -e "\t...[ ${RED}FAIL${RESET} ] $msg"
|
|
57
|
+
exit $RC
|
|
58
|
+
}
|
|
59
|
+
export -f fail
|
|
60
|
+
|
|
61
|
+
check_rc() {
|
|
62
|
+
rc=$?
|
|
63
|
+
[ $rc -eq 0 ] || fail $rc "$*"
|
|
64
|
+
return $rc
|
|
65
|
+
}
|
|
66
|
+
export -f check_rc
|
|
67
|
+
|
|
68
|
+
check_rc_optional() {
|
|
69
|
+
local RC=$?
|
|
70
|
+
local msg=$1
|
|
71
|
+
[ $RC -eq 0 ] && return $RC
|
|
72
|
+
echo -e "\t...[ ${YELLOW}WARNING${RESET} ] $msg"
|
|
73
|
+
read -p "Continue anyway? [y/N] " yn < /dev/tty
|
|
74
|
+
case $yn in
|
|
75
|
+
[Yy]* ) return 0;;
|
|
76
|
+
[Nn]* ) exit $RC;;
|
|
77
|
+
* ) exit $RC;;
|
|
78
|
+
esac
|
|
79
|
+
}
|
|
80
|
+
export -f check_rc_optional
|
|
81
|
+
|
|
82
|
+
get_last_version() {
|
|
83
|
+
# Get the first subheading in the CHANGELOG, not counting 'Unreleased'
|
|
84
|
+
VER=$(grep -v "Unreleased" $REPO_DIR/CHANGELOG.md | egrep -m 1 '## \[.*]' | cut -d ' ' -f 2 | tr -d '[]')
|
|
85
|
+
echo "Detected previous release version as '$VER'"
|
|
86
|
+
}
|
|
87
|
+
export -f get_last_version
|
|
88
|
+
|
|
89
|
+
add_changelog_diff_link() {
|
|
90
|
+
local OLD_VERSION=$1
|
|
91
|
+
local NEW_VERSION=$2
|
|
92
|
+
|
|
93
|
+
step_name "Adding link for diffs $OLD_VERSION..$NEW_VERSION in CHANGELOG.md"
|
|
94
|
+
|
|
95
|
+
# Automatically add diff link to the CHANGELOG
|
|
96
|
+
sed -i "/master...develop/ a\
|
|
97
|
+
[$VERSION]: https://github.com/cisco/cisco-network-node-utils/compare/$OLD_VERSION...$NEW_VERSION" $REPO_DIR/CHANGELOG.md
|
|
98
|
+
}
|
|
99
|
+
export -f add_changelog_diff_link
|
|
100
|
+
|
|
101
|
+
set_gem_version() {
|
|
102
|
+
local VERSION=$1
|
|
103
|
+
|
|
104
|
+
step_name "Updating version.rb to version '$VERSION'"
|
|
105
|
+
|
|
106
|
+
sed -i -e "s/VERSION =.*/VERSION = '$VERSION'/" $REPO_DIR/lib/cisco_node_utils/version.rb
|
|
107
|
+
}
|
|
108
|
+
export -f set_gem_version
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
#
|
|
3
|
+
# Generic git hook. Calls all associated helper scripts.
|
|
4
|
+
#
|
|
5
|
+
# Based on:
|
|
6
|
+
# http://stackoverflow.com/questions/8730514/chaining-git-hooks
|
|
7
|
+
# https://github.com/henrik/dotfiles/blob/master/git_template/hooks/pre-commit
|
|
8
|
+
|
|
9
|
+
[ -n "$GIT_DIR" ] || export GIT_DIR="$(git rev-parse --show-toplevel 2>/dev/null)/.git"
|
|
10
|
+
|
|
11
|
+
. "$GIT_DIR"/hooks/hook_lib
|
|
12
|
+
|
|
13
|
+
# What hook are we supposed to be?
|
|
14
|
+
hookname=`basename $0`
|
|
15
|
+
|
|
16
|
+
debug "Running wrapper script for '$hookname'..."
|
|
17
|
+
|
|
18
|
+
exitcodes=()
|
|
19
|
+
|
|
20
|
+
# Run each hook, passing through STDIN and storing the exit code.
|
|
21
|
+
# We don't want to bail at the first failure, so the user can see everything.
|
|
22
|
+
|
|
23
|
+
for hook in "$GIT_DIR"/hooks/$hookname-*; do
|
|
24
|
+
debug "Checking hook '$hook'"
|
|
25
|
+
test -x "$hook" || continue
|
|
26
|
+
script_name "${hook##*/}"
|
|
27
|
+
"$hook" "$@"
|
|
28
|
+
rc=$?
|
|
29
|
+
[ "$rc" == 0 ] && success
|
|
30
|
+
exitcodes+=($rc)
|
|
31
|
+
done
|
|
32
|
+
|
|
33
|
+
# If any exit code isn't 0, bail.
|
|
34
|
+
for i in "${exitcodes[@]}"; do
|
|
35
|
+
[ "$i" == 0 ] || fail $i "One or more hook scripts reported an error"
|
|
36
|
+
done
|
|
37
|
+
debug "Wrapper script executed successfully"
|
|
38
|
+
exit 0
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
[ -n "$GIT_DIR" ] || export GIT_DIR="$(git rev-parse --show-toplevel 2>/dev/null)/.git"
|
|
4
|
+
. "$GIT_DIR"/hooks/hook_lib
|
|
5
|
+
|
|
6
|
+
VERSION=$1
|
|
7
|
+
debug "Detected VERSION as '$VERSION'"
|
|
8
|
+
STRIP_VERSION=$(echo "$VERSION" | tr -c -d '0-9.')
|
|
9
|
+
debug "Detected STRIP_VERSION as '$STRIP_VERSION'"
|
|
10
|
+
|
|
11
|
+
LAST_VERSION=get_last_version
|
|
12
|
+
|
|
13
|
+
step_name "Adding new release subheading in CHANGELOG.md"
|
|
14
|
+
|
|
15
|
+
# Automatically update the CHANGELOG to mark the new release.
|
|
16
|
+
# Unlike our post-flow-release-start script, there is no'Unreleased' tag
|
|
17
|
+
# so we just insert the new version number immediately after the header
|
|
18
|
+
sed -i "/^=========$/ a\
|
|
19
|
+
\\\n## [$VERSION] - $(date +%Y-%m-%d)\nTODO
|
|
20
|
+
" "$REPO_DIR/CHANGELOG.md"
|
|
21
|
+
|
|
22
|
+
add_changelog_diff_link "$LAST_VERSION" "$STRIP_VERSION"
|
|
23
|
+
|
|
24
|
+
set_gem_version "$STRIP_VERSION"
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
[ -n "$GIT_DIR" ] || export GIT_DIR="$(git rev-parse --show-toplevel 2>/dev/null)/.git"
|
|
4
|
+
. "$GIT_DIR"/hooks/hook_lib
|
|
5
|
+
|
|
6
|
+
VERSION=$1
|
|
7
|
+
debug "Detected VERSION as '$VERSION'"
|
|
8
|
+
STRIP_VERSION=$(echo "$VERSION" | tr -c -d '0-9.')
|
|
9
|
+
debug "Detected STRIP_VERSION as '$STRIP_VERSION'"
|
|
10
|
+
|
|
11
|
+
step_name "Adding 'Unreleased' subheader to CHANGELOG.md in development branch."
|
|
12
|
+
|
|
13
|
+
# Add new 'Unreleased' section header to the CHANGELOG
|
|
14
|
+
sed -i "/^=========$/ a\
|
|
15
|
+
\\\n## [Unreleased]\n
|
|
16
|
+
" $REPO_DIR/CHANGELOG.md
|
|
17
|
+
|
|
18
|
+
# Bump the minor version number
|
|
19
|
+
BUGFIX_NUM=$(($(echo $STRIP_VERSION | cut -d. -f 3)+1))
|
|
20
|
+
NEW_VERSION="$(echo $STRIP_VERSION | cut -d. -f 1-2).$BUGFIX_NUM-dev"
|
|
21
|
+
|
|
22
|
+
echo "New development version will be $NEW_VERSION"
|
|
23
|
+
|
|
24
|
+
set_gem_version "$NEW_VERSION"
|
|
25
|
+
|
|
26
|
+
step_name "Commit CHANGELOG.md and version.rb to develop branch"
|
|
27
|
+
|
|
28
|
+
git commit -a -m "Post-release fixup"
|
|
29
|
+
check_rc "Git commit to develop failed?"
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
[ -n "$GIT_DIR" ] || export GIT_DIR="$(git rev-parse --show-toplevel 2>/dev/null)/.git"
|
|
4
|
+
. "$GIT_DIR"/hooks/hook_lib
|
|
5
|
+
|
|
6
|
+
VERSION=$1
|
|
7
|
+
debug "Detected VERSION as '$VERSION'"
|
|
8
|
+
STRIP_VERSION=$(echo "$VERSION" | tr -c -d '0-9.')
|
|
9
|
+
debug "Detected STRIP_VERSION as '$STRIP_VERSION'"
|
|
10
|
+
|
|
11
|
+
LAST_VERSION=get_last_version
|
|
12
|
+
|
|
13
|
+
step_name "Change 'Unreleased' subhead to '$VERSION' in CHANGELOG.md"
|
|
14
|
+
|
|
15
|
+
sed -i -e "s/^## \[Unreleased\]$/## [$VERSION] - $(date +%Y-%m-%d)/" "$REPO_DIR"/CHANGELOG.md
|
|
16
|
+
|
|
17
|
+
add_changelog_diff_link "$LAST_VERSION" "$STRIP_VERSION"
|
|
18
|
+
|
|
19
|
+
set_gem_version "$STRIP_VERSION"
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
[ -n "$GIT_DIR" ] || export GIT_DIR="$(git rev-parse --show-toplevel 2>/dev/null)/.git"
|
|
4
|
+
. "$GIT_DIR"/hooks/hook_lib
|
|
5
|
+
|
|
6
|
+
# Run the rubocop lint checks (only).
|
|
7
|
+
# We don't enforce a full rubocop run here because we want to let people
|
|
8
|
+
# commit work-in-progress code to their local branch. We will do a full
|
|
9
|
+
# rubocop run of all checks as part of the pre-push hook
|
|
10
|
+
|
|
11
|
+
step_name "Running RuboCop lint checks"
|
|
12
|
+
rubocop --lint
|
|
13
|
+
check_rc "Please fix RuboCop lint failures before committing."
|
|
14
|
+
|
|
15
|
+
# Do a full rubocop run to warn the user, but don't block a commit by it.
|
|
16
|
+
step_name "Running all RuboCop checks"
|
|
17
|
+
rubocop
|
|
18
|
+
check_rc_optional "Fix all RuboCop failures before pushing upstream"
|
|
19
|
+
|
|
20
|
+
exit 0
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
#
|
|
3
|
+
# Hook script to verify what is about to be committed.
|
|
4
|
+
# Called by "git commit" with no arguments. The hook should
|
|
5
|
+
# exit with non-zero status after issuing an appropriate message if
|
|
6
|
+
# it wants to stop the commit.
|
|
7
|
+
|
|
8
|
+
[ -n "$GIT_DIR" ] || export GIT_DIR="$(git rev-parse --show-toplevel 2>/dev/null)/.git"
|
|
9
|
+
. "$GIT_DIR"/hooks/hook_lib
|
|
10
|
+
|
|
11
|
+
# What are we diffing this commit against?
|
|
12
|
+
if git rev-parse --verify HEAD >/dev/null 2>&1
|
|
13
|
+
then
|
|
14
|
+
against=HEAD
|
|
15
|
+
else
|
|
16
|
+
# Initial commit: diff against an empty tree object
|
|
17
|
+
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
|
|
18
|
+
fi
|
|
19
|
+
|
|
20
|
+
# We exploit the fact that the printable range starts at the space character
|
|
21
|
+
# and ends with tilde.
|
|
22
|
+
# Note that the use of brackets around a tr range is ok here, (it's
|
|
23
|
+
# even required, for portability to Solaris 10's /usr/bin/tr), since
|
|
24
|
+
# the square bracket bytes happen to fall in the designated range.
|
|
25
|
+
git diff --cached --name-only --diff-filter=A -z $against |
|
|
26
|
+
LC_ALL=C tr -d '[ -~]\0' | wc -c
|
|
27
|
+
check_rc "Rename non-ASCII file name(s) before committing"
|
|
28
|
+
|
|
29
|
+
# If there are whitespace errors, print the offending file names and fail.
|
|
30
|
+
git diff-index --check --cached $against --
|
|
31
|
+
check_rc "Fix trailing whitespace before committing"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
[ -n "$GIT_DIR" ] || export GIT_DIR="$(git rev-parse --show-toplevel 2>/dev/null)/.git"
|
|
4
|
+
. "$GIT_DIR"/hooks/hook_lib
|
|
5
|
+
|
|
6
|
+
z40=0000000000000000000000000000000000000000
|
|
7
|
+
|
|
8
|
+
IFS=' '
|
|
9
|
+
|
|
10
|
+
# Information about the commits which are being pushed is supplied as lines to
|
|
11
|
+
# the standard input in the form:
|
|
12
|
+
#
|
|
13
|
+
# <local ref> <local sha1> <remote ref> <remote sha1>
|
|
14
|
+
while read local_ref local_sha remote_ref remote_sha
|
|
15
|
+
do
|
|
16
|
+
# do nothing if we're creating or deleting a new branch.
|
|
17
|
+
if [ "$local_sha" != $z40 ] && [ "$remote_sha" != $z40 ] ; then
|
|
18
|
+
# Make sure CHANGELOG.md is updated
|
|
19
|
+
step_name "Checking CHANGELOG.md..."
|
|
20
|
+
git diff --name-only --diff-filter=ACM $remote_sha $local_sha |
|
|
21
|
+
grep 'CHANGELOG.md' >> /dev/null
|
|
22
|
+
check_rc_optional "Please update CHANGELOG.md before pushing code upstream"
|
|
23
|
+
fi
|
|
24
|
+
done
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
#
|
|
3
|
+
# Based on:
|
|
4
|
+
# http://stackoverflow.com/questions/3462955/putting-git-hooks-into-repository
|
|
5
|
+
# https://github.com/sjungwirth/githooks
|
|
6
|
+
|
|
7
|
+
# Where hooks are stored in the repo
|
|
8
|
+
SRC_DIR="$(git rev-parse --show-toplevel)/bin/git/hooks"
|
|
9
|
+
|
|
10
|
+
# Where hooks need to be installed
|
|
11
|
+
HOOK_DIR="$(git rev-parse --show-toplevel)/.git/hooks"
|
|
12
|
+
|
|
13
|
+
. "$SRC_DIR/hook_lib"
|
|
14
|
+
|
|
15
|
+
install_hook_wrapper() {
|
|
16
|
+
local hook=$1
|
|
17
|
+
# Does the symlink exist?
|
|
18
|
+
if [ ! -h $HOOK_DIR/$hook ]; then
|
|
19
|
+
# If a hook already exists and is a file:
|
|
20
|
+
if [ -f $HOOK_DIR/$hook ]; then
|
|
21
|
+
step_name "Moving existing '$hook' script to '$hook-local'"
|
|
22
|
+
mv $HOOK_DIR/$hook $HOOK_DIR/$hook-local
|
|
23
|
+
fi
|
|
24
|
+
# create the symlink to our wrapper script
|
|
25
|
+
step_name "Installing hook wrapper script for '$hook'"
|
|
26
|
+
ln -s -f ./hooks-wrapper $HOOK_DIR/$hook
|
|
27
|
+
fi
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
check_update() {
|
|
31
|
+
local src=$1
|
|
32
|
+
local dest=$2
|
|
33
|
+
if [ ! -e "$dest" ] ; then
|
|
34
|
+
step_name "Creating new file at '$dest':"
|
|
35
|
+
git diff --color --no-index /dev/null $src
|
|
36
|
+
cp $src $dest
|
|
37
|
+
else
|
|
38
|
+
diff $src $dest >> /dev/null
|
|
39
|
+
if [ $? -ne 0 ] ; then
|
|
40
|
+
step_name "File '$dest' will be updated: "
|
|
41
|
+
git diff --color --no-index $dest $src
|
|
42
|
+
cp -f $src $dest
|
|
43
|
+
fi
|
|
44
|
+
fi
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
for item in "$SRC_DIR"/*; do
|
|
48
|
+
if [ ! -d "$item" ]; then
|
|
49
|
+
# Not a hook subdirectory, just a library file - update it as needed
|
|
50
|
+
file="${item##*/}"
|
|
51
|
+
check_update "$SRC_DIR/$file" "$HOOK_DIR/$file"
|
|
52
|
+
continue
|
|
53
|
+
fi
|
|
54
|
+
# Else it's a hook subdirectory.
|
|
55
|
+
hook="${item##*/}"
|
|
56
|
+
# First, make sure we have our hook-wrapper script installed for this hook:
|
|
57
|
+
install_hook_wrapper "$hook"
|
|
58
|
+
# Now descend into the subdirectory and update the individual scripts:
|
|
59
|
+
for file in "$item"/*; do
|
|
60
|
+
# bin/git/hooks/pre-commit/rubocop --> "pre-commit-rubocop"
|
|
61
|
+
hook_script="${hook}-${file##*/}"
|
|
62
|
+
check_update "$file" "$HOOK_DIR/$hook_script"
|
|
63
|
+
done
|
|
64
|
+
done
|
|
65
|
+
|