cisco_node_utils_mgx 2.1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.rubocop.yml +96 -0
- data/.travis.yml +17 -0
- data/CHANGELOG.md +676 -0
- data/CONTRIBUTING.md +43 -0
- data/Gemfile +10 -0
- data/LICENSE +201 -0
- data/README.md +246 -0
- data/Rakefile +44 -0
- data/SUPPORT.md +3 -0
- data/bin/.rubocop.yml +18 -0
- data/bin/check_metric_limits.rb +109 -0
- data/bin/git/hooks/commit-msg/enforce_style +89 -0
- data/bin/git/hooks/hook_lib +115 -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/check_unstaged_changes +18 -0
- data/bin/git/hooks/pre-commit/rubocop +25 -0
- data/bin/git/hooks/pre-commit/validate-diffs +45 -0
- data/bin/git/hooks/pre-commit/validate-yaml +18 -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 +123 -0
- data/bin/show_running_yang.rb +233 -0
- data/cisco_node_utils.gemspec +41 -0
- data/docs/README-develop-best-practices.md +521 -0
- data/docs/README-develop-node-utils-APIs.md +570 -0
- data/docs/README-maintainers.md +77 -0
- data/docs/README-test-execution.md +57 -0
- data/docs/README-utilities.md +14 -0
- data/docs/agent_files.png +0 -0
- data/docs/cisco_node_utils.yaml.example +36 -0
- data/docs/template-router.rb +123 -0
- data/docs/template-test_router.rb +104 -0
- data/ext/mkrf_conf.rb +63 -0
- data/lib/.rubocop.yml +18 -0
- data/lib/cisco_node_utils/aaa_authentication_login.rb +95 -0
- data/lib/cisco_node_utils/aaa_authentication_login_service.rb +138 -0
- data/lib/cisco_node_utils/aaa_authorization_service.rb +156 -0
- data/lib/cisco_node_utils/ace.rb +467 -0
- data/lib/cisco_node_utils/acl.rb +101 -0
- data/lib/cisco_node_utils/banner.rb +63 -0
- data/lib/cisco_node_utils/bfd_global.rb +305 -0
- data/lib/cisco_node_utils/bgp.rb +988 -0
- data/lib/cisco_node_utils/bgp_af.rb +545 -0
- data/lib/cisco_node_utils/bgp_af_aggr_addr.rb +207 -0
- data/lib/cisco_node_utils/bgp_neighbor.rb +527 -0
- data/lib/cisco_node_utils/bgp_neighbor_af.rb +780 -0
- data/lib/cisco_node_utils/bridge_domain.rb +178 -0
- data/lib/cisco_node_utils/bridge_domain_vni.rb +206 -0
- data/lib/cisco_node_utils/cisco_cmn_utils.rb +444 -0
- data/lib/cisco_node_utils/client/client.rb +238 -0
- data/lib/cisco_node_utils/client/grpc/client.rb +395 -0
- data/lib/cisco_node_utils/client/grpc/ems.proto +148 -0
- data/lib/cisco_node_utils/client/grpc/ems.rb +111 -0
- data/lib/cisco_node_utils/client/grpc/ems_services.rb +49 -0
- data/lib/cisco_node_utils/client/grpc.rb +33 -0
- data/lib/cisco_node_utils/client/nxapi/client.rb +368 -0
- data/lib/cisco_node_utils/client/nxapi.rb +31 -0
- data/lib/cisco_node_utils/client/utils.rb +180 -0
- data/lib/cisco_node_utils/client.rb +35 -0
- data/lib/cisco_node_utils/cmd_ref/README_YAML.md +590 -0
- data/lib/cisco_node_utils/cmd_ref/aaa_auth_login_service.yaml +25 -0
- data/lib/cisco_node_utils/cmd_ref/aaa_authentication_login.yaml +38 -0
- data/lib/cisco_node_utils/cmd_ref/aaa_authorization_service.yaml +40 -0
- data/lib/cisco_node_utils/cmd_ref/acl.yaml +48 -0
- data/lib/cisco_node_utils/cmd_ref/banner.yaml +11 -0
- data/lib/cisco_node_utils/cmd_ref/bfd_global.yaml +117 -0
- data/lib/cisco_node_utils/cmd_ref/bgp.yaml +383 -0
- data/lib/cisco_node_utils/cmd_ref/bgp_af.yaml +223 -0
- data/lib/cisco_node_utils/cmd_ref/bgp_af_aa.yaml +38 -0
- data/lib/cisco_node_utils/cmd_ref/bgp_neighbor.yaml +174 -0
- data/lib/cisco_node_utils/cmd_ref/bgp_neighbor_af.yaml +236 -0
- data/lib/cisco_node_utils/cmd_ref/bridge_domain.yaml +49 -0
- data/lib/cisco_node_utils/cmd_ref/bridge_domain_vni.yaml +33 -0
- data/lib/cisco_node_utils/cmd_ref/dhcp_relay_global.yaml +128 -0
- data/lib/cisco_node_utils/cmd_ref/dnsclient.yaml +55 -0
- data/lib/cisco_node_utils/cmd_ref/encapsulation.yaml +25 -0
- data/lib/cisco_node_utils/cmd_ref/evpn_multicast.yaml +12 -0
- data/lib/cisco_node_utils/cmd_ref/evpn_multisite.yaml +18 -0
- data/lib/cisco_node_utils/cmd_ref/evpn_stormcontrol.yaml +18 -0
- data/lib/cisco_node_utils/cmd_ref/evpn_vni.yaml +48 -0
- data/lib/cisco_node_utils/cmd_ref/fabricpath.yaml +183 -0
- data/lib/cisco_node_utils/cmd_ref/fabricpath_topology.yaml +40 -0
- data/lib/cisco_node_utils/cmd_ref/feature.yaml +126 -0
- data/lib/cisco_node_utils/cmd_ref/hostname.yaml +8 -0
- data/lib/cisco_node_utils/cmd_ref/hsrp_global.yaml +25 -0
- data/lib/cisco_node_utils/cmd_ref/images.yaml +8 -0
- data/lib/cisco_node_utils/cmd_ref/interface.yaml +781 -0
- data/lib/cisco_node_utils/cmd_ref/interface_channel_group.yaml +45 -0
- data/lib/cisco_node_utils/cmd_ref/interface_evpn_multisite.yaml +17 -0
- data/lib/cisco_node_utils/cmd_ref/interface_hsrp_group.yaml +120 -0
- data/lib/cisco_node_utils/cmd_ref/interface_ospf.yaml +112 -0
- data/lib/cisco_node_utils/cmd_ref/interface_portchannel.yaml +87 -0
- data/lib/cisco_node_utils/cmd_ref/interface_service_vni.yaml +42 -0
- data/lib/cisco_node_utils/cmd_ref/inventory.yaml +45 -0
- data/lib/cisco_node_utils/cmd_ref/ip_multicast.yaml +22 -0
- data/lib/cisco_node_utils/cmd_ref/itd_device_group.yaml +83 -0
- data/lib/cisco_node_utils/cmd_ref/itd_service.yaml +119 -0
- data/lib/cisco_node_utils/cmd_ref/memory.yaml +24 -0
- data/lib/cisco_node_utils/cmd_ref/ntp_auth_key.yaml +10 -0
- data/lib/cisco_node_utils/cmd_ref/ntp_config.yaml +27 -0
- data/lib/cisco_node_utils/cmd_ref/ntp_server.yaml +34 -0
- data/lib/cisco_node_utils/cmd_ref/object_group.yaml +32 -0
- data/lib/cisco_node_utils/cmd_ref/ospf.yaml +91 -0
- data/lib/cisco_node_utils/cmd_ref/ospf_area.yaml +91 -0
- data/lib/cisco_node_utils/cmd_ref/ospf_area_vlink.yaml +88 -0
- data/lib/cisco_node_utils/cmd_ref/overlay_global.yaml +37 -0
- data/lib/cisco_node_utils/cmd_ref/pim.yaml +43 -0
- data/lib/cisco_node_utils/cmd_ref/portchannel_global.yaml +86 -0
- data/lib/cisco_node_utils/cmd_ref/radius_global.yaml +37 -0
- data/lib/cisco_node_utils/cmd_ref/radius_server.yaml +100 -0
- data/lib/cisco_node_utils/cmd_ref/radius_server_group.yaml +19 -0
- data/lib/cisco_node_utils/cmd_ref/route_map.yaml +601 -0
- data/lib/cisco_node_utils/cmd_ref/show_system.yaml +9 -0
- data/lib/cisco_node_utils/cmd_ref/show_version.yaml +84 -0
- data/lib/cisco_node_utils/cmd_ref/snmp_community.yaml +81 -0
- data/lib/cisco_node_utils/cmd_ref/snmp_group.yaml +9 -0
- data/lib/cisco_node_utils/cmd_ref/snmp_notification_receiver.yaml +74 -0
- data/lib/cisco_node_utils/cmd_ref/snmp_server.yaml +91 -0
- data/lib/cisco_node_utils/cmd_ref/snmp_user.yaml +57 -0
- data/lib/cisco_node_utils/cmd_ref/snmpnotification.yaml +23 -0
- data/lib/cisco_node_utils/cmd_ref/span_session.yaml +65 -0
- data/lib/cisco_node_utils/cmd_ref/stp_global.yaml +235 -0
- data/lib/cisco_node_utils/cmd_ref/syslog_facility.yaml +10 -0
- data/lib/cisco_node_utils/cmd_ref/syslog_server.yaml +34 -0
- data/lib/cisco_node_utils/cmd_ref/syslog_settings.yaml +45 -0
- data/lib/cisco_node_utils/cmd_ref/system.yaml +7 -0
- data/lib/cisco_node_utils/cmd_ref/tacacs_global.yaml +37 -0
- data/lib/cisco_node_utils/cmd_ref/tacacs_server.yaml +63 -0
- data/lib/cisco_node_utils/cmd_ref/tacacs_server_group.yaml +45 -0
- data/lib/cisco_node_utils/cmd_ref/tacacs_server_host.yaml +64 -0
- data/lib/cisco_node_utils/cmd_ref/upgrade.yaml +38 -0
- data/lib/cisco_node_utils/cmd_ref/vdc.yaml +52 -0
- data/lib/cisco_node_utils/cmd_ref/virtual_service.yaml +8 -0
- data/lib/cisco_node_utils/cmd_ref/vlan.yaml +106 -0
- data/lib/cisco_node_utils/cmd_ref/vpc.yaml +233 -0
- data/lib/cisco_node_utils/cmd_ref/vrf.yaml +86 -0
- data/lib/cisco_node_utils/cmd_ref/vrf_af.yaml +139 -0
- data/lib/cisco_node_utils/cmd_ref/vtp.yaml +32 -0
- data/lib/cisco_node_utils/cmd_ref/vxlan_vtep.yaml +114 -0
- data/lib/cisco_node_utils/cmd_ref/vxlan_vtep_vni.yaml +71 -0
- data/lib/cisco_node_utils/cmd_ref/yang.yaml +7 -0
- data/lib/cisco_node_utils/cmd_ref/yum.yaml +68 -0
- data/lib/cisco_node_utils/command_reference.rb +724 -0
- data/lib/cisco_node_utils/configparser_lib.rb +195 -0
- data/lib/cisco_node_utils/constants.rb +40 -0
- data/lib/cisco_node_utils/dhcp_relay_global.rb +302 -0
- data/lib/cisco_node_utils/dns_domain.rb +93 -0
- data/lib/cisco_node_utils/domain_name.rb +82 -0
- data/lib/cisco_node_utils/encapsulation.rb +112 -0
- data/lib/cisco_node_utils/environment.rb +110 -0
- data/lib/cisco_node_utils/evpn_multicast.rb +66 -0
- data/lib/cisco_node_utils/evpn_multisite.rb +96 -0
- data/lib/cisco_node_utils/evpn_stormcontrol.rb +84 -0
- data/lib/cisco_node_utils/evpn_vni.rb +159 -0
- data/lib/cisco_node_utils/exceptions.rb +140 -0
- data/lib/cisco_node_utils/fabricpath_global.rb +405 -0
- data/lib/cisco_node_utils/fabricpath_topology.rb +137 -0
- data/lib/cisco_node_utils/feature.rb +377 -0
- data/lib/cisco_node_utils/hostname.rb +62 -0
- data/lib/cisco_node_utils/hsrp_global.rb +97 -0
- data/lib/cisco_node_utils/interface.rb +2128 -0
- data/lib/cisco_node_utils/interface_channel_group.rb +142 -0
- data/lib/cisco_node_utils/interface_evpn_multisite.rb +72 -0
- data/lib/cisco_node_utils/interface_hsrp_group.rb +557 -0
- data/lib/cisco_node_utils/interface_ospf.rb +378 -0
- data/lib/cisco_node_utils/interface_portchannel.rb +180 -0
- data/lib/cisco_node_utils/interface_service_vni.rb +132 -0
- data/lib/cisco_node_utils/ip_multicast.rb +90 -0
- data/lib/cisco_node_utils/itd_device_group.rb +228 -0
- data/lib/cisco_node_utils/itd_device_group_node.rb +144 -0
- data/lib/cisco_node_utils/itd_service.rb +511 -0
- data/lib/cisco_node_utils/logger.rb +78 -0
- data/lib/cisco_node_utils/name_server.rb +64 -0
- data/lib/cisco_node_utils/node.rb +443 -0
- data/lib/cisco_node_utils/node_util.rb +111 -0
- data/lib/cisco_node_utils/ntp_auth_key.rb +67 -0
- data/lib/cisco_node_utils/ntp_config.rb +83 -0
- data/lib/cisco_node_utils/ntp_server.rb +86 -0
- data/lib/cisco_node_utils/object_group.rb +75 -0
- data/lib/cisco_node_utils/object_group_entry.rb +143 -0
- data/lib/cisco_node_utils/overlay_global.rb +142 -0
- data/lib/cisco_node_utils/pim.rb +131 -0
- data/lib/cisco_node_utils/pim_group_list.rb +109 -0
- data/lib/cisco_node_utils/pim_rp_address.rb +103 -0
- data/lib/cisco_node_utils/platform.rb +217 -0
- data/lib/cisco_node_utils/portchannel_global.rb +347 -0
- data/lib/cisco_node_utils/radius_global.rb +165 -0
- data/lib/cisco_node_utils/radius_server.rb +421 -0
- data/lib/cisco_node_utils/radius_server_group.rb +117 -0
- data/lib/cisco_node_utils/route_map.rb +2540 -0
- data/lib/cisco_node_utils/router_ospf.rb +77 -0
- data/lib/cisco_node_utils/router_ospf_area.rb +416 -0
- data/lib/cisco_node_utils/router_ospf_area_vlink.rb +313 -0
- data/lib/cisco_node_utils/router_ospf_vrf.rb +342 -0
- data/lib/cisco_node_utils/snmp_notification_receiver.rb +176 -0
- data/lib/cisco_node_utils/snmpcommunity.rb +109 -0
- data/lib/cisco_node_utils/snmpgroup.rb +54 -0
- data/lib/cisco_node_utils/snmpnotification.rb +57 -0
- data/lib/cisco_node_utils/snmpserver.rb +132 -0
- data/lib/cisco_node_utils/snmpuser.rb +403 -0
- data/lib/cisco_node_utils/span_session.rb +149 -0
- data/lib/cisco_node_utils/stp_global.rb +676 -0
- data/lib/cisco_node_utils/syslog_facility.rb +64 -0
- data/lib/cisco_node_utils/syslog_server.rb +146 -0
- data/lib/cisco_node_utils/syslog_settings.rb +174 -0
- data/lib/cisco_node_utils/tacacs_global.rb +137 -0
- data/lib/cisco_node_utils/tacacs_server.rb +173 -0
- data/lib/cisco_node_utils/tacacs_server_group.rb +149 -0
- data/lib/cisco_node_utils/tacacs_server_host.rb +216 -0
- data/lib/cisco_node_utils/upgrade.rb +122 -0
- data/lib/cisco_node_utils/vdc.rb +118 -0
- data/lib/cisco_node_utils/version.rb +21 -0
- data/lib/cisco_node_utils/vlan.rb +301 -0
- data/lib/cisco_node_utils/vpc.rb +466 -0
- data/lib/cisco_node_utils/vrf.rb +192 -0
- data/lib/cisco_node_utils/vrf_af.rb +327 -0
- data/lib/cisco_node_utils/vtp.rb +125 -0
- data/lib/cisco_node_utils/vxlan_vtep.rb +286 -0
- data/lib/cisco_node_utils/vxlan_vtep_vni.rb +331 -0
- data/lib/cisco_node_utils/yang.rb +160 -0
- data/lib/cisco_node_utils/yum.rb +213 -0
- data/lib/cisco_node_utils.rb +21 -0
- data/lib/minitest/environment_plugin.rb +31 -0
- data/lib/minitest/log_level_plugin.rb +41 -0
- data/spec/client_spec.rb +7 -0
- data/spec/environment_spec.rb +384 -0
- data/spec/grpc_client_spec.rb +23 -0
- data/spec/isolate/all_clients_spec.rb +9 -0
- data/spec/isolate/grpc_only_spec.rb +16 -0
- data/spec/isolate/no_clients_spec.rb +26 -0
- data/spec/isolate/nxapi_only_spec.rb +16 -0
- data/spec/nxapi_client_spec.rb +42 -0
- data/spec/schema.yaml +82 -0
- data/spec/shared_examples_for_clients.rb +14 -0
- data/spec/spec_helper.rb +91 -0
- data/spec/whitespace_spec.rb +10 -0
- data/spec/yaml_spec.rb +42 -0
- data/tests/.rubocop.yml +18 -0
- data/tests/CSCuxdublin-1.0.0-7.0.3.I3.1.lib32_n9000.rpm +0 -0
- data/tests/basetest.rb +243 -0
- data/tests/ciscotest.rb +577 -0
- data/tests/cmd_config.yaml +75 -0
- data/tests/cmd_config_invalid.yaml +16 -0
- data/tests/n9000_sample-1.0.0-7.0.3.x86_64.rpm +0 -0
- data/tests/noop.rb +7 -0
- data/tests/platform_info.rb +63 -0
- data/tests/tacacs_server.yaml.example +6 -0
- data/tests/test_aaa_authentication_login.rb +243 -0
- data/tests/test_aaa_authentication_login_service.rb +761 -0
- data/tests/test_aaa_authorization_service.rb +874 -0
- data/tests/test_ace.rb +304 -0
- data/tests/test_acl.rb +185 -0
- data/tests/test_banner.rb +85 -0
- data/tests/test_bfd_global.rb +272 -0
- data/tests/test_bgp_af.rb +875 -0
- data/tests/test_bgp_af_aa.rb +108 -0
- data/tests/test_bgp_neighbor.rb +596 -0
- data/tests/test_bgp_neighbor_af.rb +781 -0
- data/tests/test_bridge_domain.rb +198 -0
- data/tests/test_bridge_domain_vni.rb +109 -0
- data/tests/test_client_utils.rb +111 -0
- data/tests/test_cmn_utils.rb +76 -0
- data/tests/test_command_config.rb +206 -0
- data/tests/test_command_reference.rb +669 -0
- data/tests/test_dhcp_relay_global.rb +286 -0
- data/tests/test_dns_domain.rb +123 -0
- data/tests/test_domain_name.rb +96 -0
- data/tests/test_encapsulation.rb +75 -0
- data/tests/test_evpn_multicast.rb +65 -0
- data/tests/test_evpn_multisite.rb +70 -0
- data/tests/test_evpn_stormcontrol.rb +56 -0
- data/tests/test_evpn_vni.rb +131 -0
- data/tests/test_fabricpath_global.rb +246 -0
- data/tests/test_fabricpath_topology.rb +77 -0
- data/tests/test_feature.rb +272 -0
- data/tests/test_grpc.rb +166 -0
- data/tests/test_hostname.rb +64 -0
- data/tests/test_hsrp_global.rb +79 -0
- data/tests/test_interface.rb +1958 -0
- data/tests/test_interface_bdi.rb +80 -0
- data/tests/test_interface_channel_group.rb +131 -0
- data/tests/test_interface_evpn_multisite.rb +94 -0
- data/tests/test_interface_hsrp.rb +134 -0
- data/tests/test_interface_hsrp_group.rb +570 -0
- data/tests/test_interface_ospf.rb +820 -0
- data/tests/test_interface_portchannel.rb +135 -0
- data/tests/test_interface_private_vlan.rb +365 -0
- data/tests/test_interface_service_vni.rb +203 -0
- data/tests/test_interface_svi.rb +210 -0
- data/tests/test_interface_switchport.rb +468 -0
- data/tests/test_ip_multicast.rb +80 -0
- data/tests/test_itd_device_group.rb +145 -0
- data/tests/test_itd_device_group_node.rb +199 -0
- data/tests/test_itd_service.rb +314 -0
- data/tests/test_logger.rb +43 -0
- data/tests/test_name_server.rb +94 -0
- data/tests/test_node.rb +50 -0
- data/tests/test_node_ext.rb +406 -0
- data/tests/test_node_util.rb +119 -0
- data/tests/test_ntp_auth_key.rb +77 -0
- data/tests/test_ntp_config.rb +100 -0
- data/tests/test_ntp_server.rb +146 -0
- data/tests/test_nxapi.rb +236 -0
- data/tests/test_object_group.rb +122 -0
- data/tests/test_overlay_global.rb +108 -0
- data/tests/test_pim.rb +203 -0
- data/tests/test_pim_group_list.rb +147 -0
- data/tests/test_pim_rp_address.rb +155 -0
- data/tests/test_platform.rb +254 -0
- data/tests/test_portchannel_global.rb +322 -0
- data/tests/test_radius_global.rb +108 -0
- data/tests/test_radius_server.rb +377 -0
- data/tests/test_radius_server_group.rb +151 -0
- data/tests/test_route_map.rb +1479 -0
- data/tests/test_router_bgp.rb +1325 -0
- data/tests/test_router_ospf.rb +56 -0
- data/tests/test_router_ospf_area.rb +433 -0
- data/tests/test_router_ospf_area_vlink.rb +298 -0
- data/tests/test_router_ospf_vrf.rb +690 -0
- data/tests/test_snmp_notification_receiver.rb +169 -0
- data/tests/test_snmpcommunity.rb +422 -0
- data/tests/test_snmpgroup.rb +71 -0
- data/tests/test_snmpnotification.rb +91 -0
- data/tests/test_snmpserver.rb +251 -0
- data/tests/test_snmpuser.rb +666 -0
- data/tests/test_span_session.rb +155 -0
- data/tests/test_stp_global.rb +575 -0
- data/tests/test_syslog_facility.rb +80 -0
- data/tests/test_syslog_server.rb +119 -0
- data/tests/test_syslog_settings.rb +123 -0
- data/tests/test_tacacs_global.rb +109 -0
- data/tests/test_tacacs_server.rb +436 -0
- data/tests/test_tacacs_server_group.rb +434 -0
- data/tests/test_tacacs_server_host.rb +427 -0
- data/tests/test_upgrade.rb +105 -0
- data/tests/test_vdc.rb +64 -0
- data/tests/test_vlan.rb +386 -0
- data/tests/test_vlan_private.rb +656 -0
- data/tests/test_vpc.rb +548 -0
- data/tests/test_vrf.rb +248 -0
- data/tests/test_vrf_af.rb +288 -0
- data/tests/test_vtp.rb +278 -0
- data/tests/test_vxlan_vtep.rb +327 -0
- data/tests/test_vxlan_vtep_vni.rb +326 -0
- data/tests/test_yang.rb +369 -0
- data/tests/test_yum.rb +109 -0
- data/tests/upgrade_info.yaml.example +3 -0
- data/tests/yum_package.yaml +94 -0
- metadata +534 -0
@@ -0,0 +1,109 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# October 2015, Glenn F. Matthews
|
4
|
+
#
|
5
|
+
# Copyright (c) 2015 Cisco and/or its affiliates.
|
6
|
+
#
|
7
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
8
|
+
# you may not use this file except in compliance with the License.
|
9
|
+
# You may obtain a copy of the License at
|
10
|
+
#
|
11
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
12
|
+
#
|
13
|
+
# Unless required by applicable law or agreed to in writing, software
|
14
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
15
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
16
|
+
# See the License for the specific language governing permissions and
|
17
|
+
# limitations under the License.
|
18
|
+
#
|
19
|
+
# This is a helper script for developers.
|
20
|
+
# If you're doing refactoring work to reduce the code complexity metrics,
|
21
|
+
# you can run this script to report the worst offenders for each metric
|
22
|
+
# and whether you've managed to improve any metrics compared to the baseline.
|
23
|
+
|
24
|
+
require 'pathname'
|
25
|
+
require 'yaml'
|
26
|
+
|
27
|
+
base = Pathname.new(File.expand_path('../..', __FILE__))
|
28
|
+
|
29
|
+
['lib/', 'tests/'].each do |subdir|
|
30
|
+
# Read in the base config file:
|
31
|
+
base_config = {}
|
32
|
+
File.open(base + subdir + '.rubocop.yml', 'r') do |f|
|
33
|
+
base_config = YAML.parse(f).transform
|
34
|
+
end
|
35
|
+
|
36
|
+
# Create a fake config file that's identical to baseline except for the
|
37
|
+
# metric Max limits:
|
38
|
+
|
39
|
+
new_config = {}
|
40
|
+
base_config.each do |cop, options|
|
41
|
+
next unless options.is_a?(Hash)
|
42
|
+
new_config[cop] = {}
|
43
|
+
options.each do |option, value|
|
44
|
+
new_config[cop][option] = value unless option == 'Max'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
tempfile = base + '.rubocop_temp.yml'
|
49
|
+
|
50
|
+
File.open(tempfile, 'w') do |f|
|
51
|
+
f.write new_config.to_yaml
|
52
|
+
end
|
53
|
+
|
54
|
+
output = `rubocop -c #{tempfile} --only Metrics -f emacs \
|
55
|
+
-D #{subdir} 2>/dev/null`
|
56
|
+
`rm -f #{tempfile}`
|
57
|
+
|
58
|
+
results = {}
|
59
|
+
output.split("\n").each do |line|
|
60
|
+
# emacs output format:
|
61
|
+
# foo/bar.rb:92:81: C: Metrics/LineLength: Line is too long. [81/80]
|
62
|
+
file, row, col, _err, cop, msg = line.split(':')
|
63
|
+
file = Pathname.new(file).relative_path_from(base).to_s
|
64
|
+
cop.strip!
|
65
|
+
value = msg[/\[([0-9.]+)/, 1].to_f.ceil
|
66
|
+
results[cop] ||= {}
|
67
|
+
results[cop][value] ||= []
|
68
|
+
results[cop][value] << {
|
69
|
+
file: file,
|
70
|
+
row: row.to_i,
|
71
|
+
col: col.to_i,
|
72
|
+
}
|
73
|
+
end
|
74
|
+
|
75
|
+
# Print each failing cop in alphabetical order...
|
76
|
+
results.keys.sort.each do |cop|
|
77
|
+
puts "\n#{cop}"
|
78
|
+
offenses = results[cop]
|
79
|
+
# List the two highest failing values...
|
80
|
+
offenses.keys.sort.reverse[0..1].each do |value|
|
81
|
+
puts " #{value}:"
|
82
|
+
offenses[value].each do |offender|
|
83
|
+
# and list the file and line where each failure was seen
|
84
|
+
puts " #{offender[:file]}:#{offender[:row]}"
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
puts "\n"
|
90
|
+
|
91
|
+
base_config.keys.sort.each do |cop|
|
92
|
+
next unless cop =~ /Metrics/
|
93
|
+
base_val = base_config[cop]['Max']
|
94
|
+
base_val ||= 0
|
95
|
+
actual_val = results[cop].keys.sort.last if results[cop]
|
96
|
+
actual_val ||= 0
|
97
|
+
if base_val == actual_val
|
98
|
+
if base_val == 0
|
99
|
+
puts "#{cop}: still passing in full"
|
100
|
+
else
|
101
|
+
puts "#{cop}: value unchanged (#{base_val})"
|
102
|
+
end
|
103
|
+
elsif base_val > actual_val
|
104
|
+
puts "#{cop}: value improved! (#{base_val} -> #{actual_val})"
|
105
|
+
else
|
106
|
+
puts "#{cop}: value WORSENED (#{base_val} -> #{actual_val})"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,89 @@
|
|
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
|
+
|
80
|
+
fd = IO.sysopen('/dev/tty', 'w+')
|
81
|
+
a = IO.new(fd, 'w+')
|
82
|
+
a.puts 'Continue anyway? [y/N] '
|
83
|
+
response = a.gets.chomp
|
84
|
+
# rubocop:disable Style/GlobalVars
|
85
|
+
$errors = 0 if response.downcase[0] == 'y'
|
86
|
+
# rubocop:enable Style/GlobalVars
|
87
|
+
end
|
88
|
+
|
89
|
+
exit $errors # rubocop:disable Style/GlobalVars
|
@@ -0,0 +1,115 @@
|
|
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
|
+
get_staged_ruby_files() {
|
90
|
+
rubocop_target=$(rubocop --list-target-files)
|
91
|
+
staged_files=$(git diff --name-only --staged)
|
92
|
+
echo $(printf "$rubocop_target $staged_files " | tr ' ' '\n' | sort | uniq -d)
|
93
|
+
}
|
94
|
+
export -f get_staged_ruby_files
|
95
|
+
|
96
|
+
add_changelog_diff_link() {
|
97
|
+
local OLD_VERSION=$1
|
98
|
+
local NEW_VERSION=$2
|
99
|
+
|
100
|
+
step_name "Adding link for diffs $OLD_VERSION..$NEW_VERSION in CHANGELOG.md"
|
101
|
+
|
102
|
+
# Automatically add diff link to the CHANGELOG
|
103
|
+
sed -i "/master...develop/ a\
|
104
|
+
[$VERSION]: https://github.com/cisco/cisco-network-node-utils/compare/$OLD_VERSION...$NEW_VERSION" $REPO_DIR/CHANGELOG.md
|
105
|
+
}
|
106
|
+
export -f add_changelog_diff_link
|
107
|
+
|
108
|
+
set_gem_version() {
|
109
|
+
local VERSION=$1
|
110
|
+
|
111
|
+
step_name "Updating version.rb to version '$VERSION'"
|
112
|
+
|
113
|
+
sed -i -e "s/VERSION =.*/VERSION = '$VERSION'/" $REPO_DIR/lib/cisco_node_utils/version.rb
|
114
|
+
}
|
115
|
+
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,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Check if a staged file has unstaged changes and print a warning
|
4
|
+
|
5
|
+
staged_files = `git diff --name-only --staged`.split(' ')
|
6
|
+
unstaged_files = `git diff --name-only`.split(' ')
|
7
|
+
files = (staged_files << unstaged_files).flatten!
|
8
|
+
|
9
|
+
if files.length != files.uniq.length
|
10
|
+
puts 'Warning: a staged file has unstaged changes!'
|
11
|
+
fd = IO.sysopen('/dev/tty', 'w+')
|
12
|
+
a = IO.new(fd, 'w+')
|
13
|
+
a.print 'Continue anyway? [y/N] '
|
14
|
+
input = a.gets.chomp
|
15
|
+
exit input =~ /^y/i ? 0 : -1
|
16
|
+
end
|
17
|
+
|
18
|
+
exit 0
|
@@ -0,0 +1,25 @@
|
|
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
|
+
staged_ruby_files=$(get_staged_ruby_files)
|
13
|
+
if [ -z "$staged_ruby_files" ]; then
|
14
|
+
# quit since there are no ruby files to check
|
15
|
+
exit 0
|
16
|
+
fi
|
17
|
+
rubocop --lint $staged_ruby_files
|
18
|
+
check_rc "Please fix RuboCop lint failures before committing."
|
19
|
+
|
20
|
+
# Do a full rubocop run to warn the user, but don't block a commit by it.
|
21
|
+
step_name "Running all RuboCop checks"
|
22
|
+
rubocop $staged_ruby_files
|
23
|
+
check_rc_optional "Fix all RuboCop failures before pushing upstream"
|
24
|
+
|
25
|
+
exit 0
|
@@ -0,0 +1,45 @@
|
|
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
|
+
step_name 'Checking for non-ASCII filenames'
|
21
|
+
# We exploit the fact that the printable range starts at the space character
|
22
|
+
# and ends with tilde.
|
23
|
+
# Note that the use of brackets around a tr range is ok here, (it's
|
24
|
+
# even required, for portability to Solaris 10's /usr/bin/tr), since
|
25
|
+
# the square bracket bytes happen to fall in the designated range.
|
26
|
+
added_files=$(git diff --cached --name-only --diff-filter=A -z $against | tr '\0' ' ')
|
27
|
+
added_files_array=(`echo $added_files`)
|
28
|
+
# Print the files that have non-ascii text
|
29
|
+
for i in ${added_files_array[@]}; do
|
30
|
+
bad_chars=$(echo -n $i | LC_ALL=C tr -d '[ -~]\0')
|
31
|
+
if [ -n "$bad_chars" ]; then echo $i; fi
|
32
|
+
done
|
33
|
+
# Fail if any non-ASCII characters are discovered
|
34
|
+
(echo -n $added_files | LC_ALL=C tr -d '[ -~]\0' | exit $(wc -c))
|
35
|
+
check_rc "Rename non-ASCII file name(s) before committing"
|
36
|
+
|
37
|
+
step_name 'Checking for trailing whitespace in non-Ruby files'
|
38
|
+
# If there are whitespace errors, print the offending file names and fail.
|
39
|
+
# Ignore .rb files, as whitespace in these files is managed by Rubocop
|
40
|
+
# Ignore .proto files, as they are generated code
|
41
|
+
non_ruby_files=`git diff --staged --name-only | grep -v \.rb | grep -v \.proto`
|
42
|
+
if [ -n "$non_ruby_files" ]; then
|
43
|
+
! git grep -n -I '\s$' -- $non_ruby_files
|
44
|
+
check_rc "Fix trailing whitespace before committing"
|
45
|
+
fi
|
@@ -0,0 +1,18 @@
|
|
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 Kwalify YAML schema validation
|
7
|
+
|
8
|
+
step_name "Validating YAML files"
|
9
|
+
rspec "$REPO_DIR"/spec/yaml_spec.rb
|
10
|
+
check_rc "Please fix YAML schema validation failures before committing"
|
11
|
+
|
12
|
+
# Ensure that command_reference can parse all the YAML as well
|
13
|
+
|
14
|
+
step_name "Checking command_reference YAML parsing"
|
15
|
+
ruby "$REPO_DIR"/tests/test_command_reference.rb
|
16
|
+
check_rc "Please fix command_reference unit test failures before committing"
|
17
|
+
|
18
|
+
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
|
+
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
|