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 <cody@instructure.com>
Product-Review: Jon Jensen <jon@instructure.com>
QA-Review: Jon Jensen <jon@instructure.com>
This commit is contained in:
Jon Jensen 2016-08-17 16:26:25 -06:00
parent beb8f897d1
commit ef8d56076a
1 changed files with 9 additions and 3 deletions

View File

@ -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: \""