From 62baf5e373fedcc6baff02dd0ba62ee71575e859 Mon Sep 17 00:00:00 2001 From: Drew Rothstein Date: Mon, 13 Jul 2020 20:13:08 -0700 Subject: [PATCH] [authorname] allow for non-0 --- CHANGELOG.md | 1 + lib/overcommit/hook/pre_commit/author_name.rb | 4 ++-- spec/integration/committing_spec.rb | 12 +++++++++++- spec/overcommit/hook/pre_commit/author_name_spec.rb | 2 +- 4 files changed, 15 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 241a9a6a..e0c46556 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## master (unreleased) * Fix `Overcommit::GitRepo.list_files` helper to work with arbitrarily large lists of files. +* `AuthorName` allows for non-0 length to be more inclusive of names. ## 0.54.0 diff --git a/lib/overcommit/hook/pre_commit/author_name.rb b/lib/overcommit/hook/pre_commit/author_name.rb index 63d4243a..fc89792a 100644 --- a/lib/overcommit/hook/pre_commit/author_name.rb +++ b/lib/overcommit/hook/pre_commit/author_name.rb @@ -12,9 +12,9 @@ def run result.stdout.chomp end - unless name.split(' ').count >= 2 + if name.empty? return :fail, - "Author must have at least first and last name, but was: #{name}.\n" \ + "Author name must be non-0 in length.\n" \ 'Set your name with `git config --global user.name "Your Name"` ' \ 'or via the GIT_AUTHOR_NAME environment variable' end diff --git a/spec/integration/committing_spec.rb b/spec/integration/committing_spec.rb index 6bdd0f08..1e1f65a6 100644 --- a/spec/integration/committing_spec.rb +++ b/spec/integration/committing_spec.rb @@ -26,7 +26,7 @@ context 'when a hook fails' do before do - `git config --local user.name "John"` + `git config --local user.name ""` end it 'exits with a non-zero status' do @@ -34,6 +34,16 @@ end end + context 'when no hooks fail on single author name' do + before do + `git config --local user.name "John"` + end + + it 'exits successfully' do + subject.status.should == 0 + end + end + context 'when no hooks fail' do before do `git config --local user.name "John Doe"` diff --git a/spec/overcommit/hook/pre_commit/author_name_spec.rb b/spec/overcommit/hook/pre_commit/author_name_spec.rb index 7cf230d5..1ed0502f 100644 --- a/spec/overcommit/hook/pre_commit/author_name_spec.rb +++ b/spec/overcommit/hook/pre_commit/author_name_spec.rb @@ -18,7 +18,7 @@ context 'when user has only a first name' do let(:name) { 'John' } - it { should fail_hook } + it { should pass } end context 'when user has first and last name' do