From ef8d56076a740c9f6e0c2a328a270ce3dcc9af30 Mon Sep 17 00:00:00 2001 From: Jon Jensen Date: Wed, 17 Aug 2016 16:26:25 -0600 Subject: [PATCH] avoid duplicate chdir, fixes SD-1442 test plan: 1. lint_commit_message should run and pass on this commit 2. it should lint a plugin commit if you set GERGICH_GIT_PATH and GERRIT_REFSPEC and not blow up on linting failures Change-Id: I7349eb0885038ac11660b95a7e528735048be2bc Reviewed-on: https://gerrit.instructure.com/88104 Tested-by: Jenkins Reviewed-by: Cody Cutrer Product-Review: Jon Jensen QA-Review: Jon Jensen --- script/lint_commit_message | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/script/lint_commit_message b/script/lint_commit_message index 07ecd0e59dc..6a9124ee834 100755 --- a/script/lint_commit_message +++ b/script/lint_commit_message @@ -5,7 +5,13 @@ require 'json' require 'jira_ref_parser' require 'yaml' -Dir.chdir(ENV["GERGICH_GIT_PATH"]) if ENV["GERGICH_GIT_PATH"] +GERGICH_GIT_PATH=ENV.fetch("GERGICH_GIT_PATH", ".") + +def git(command) + Dir.chdir(GERGICH_GIT_PATH) do + `git #{command}` + end +end def comment(severity, line, message, link_to_guidelines = false) $stderr.puts "line #{line}: [#{severity}]: #{message}" @@ -18,7 +24,7 @@ def comment(severity, line, message, link_to_guidelines = false) end end -commit_message = ARGV[0] == "--stdin" ? STDIN.read : `git show --pretty=format:%B -s` +commit_message = ARGV[0] == "--stdin" ? STDIN.read : git("show --pretty=format:%B -s") exit if commit_message =~ /\A\[?wip($|[\] :-])/i lines = commit_message.split(/\n/) @@ -87,7 +93,7 @@ end starts_with_spec = subject =~ /\Aspec: /i exit if starts_with_spec # we're trusting you here, don't be evil -commit_files = `git show --pretty=format:"" --name-only`.split("\n") +commit_files = git("show --pretty=format:"" --name-only").split("\n") only_affects_specs = commit_files.all? { |f| f =~ %r{\Aspec/} } if only_affects_specs comment "warn", 1, "since your commit only affects specs, please prefix your commit message with \"spec: \""