From 956c765c2d9565a951c53ee0a122be3b0186b90f Mon Sep 17 00:00:00 2001 From: hiroki matsumoto Date: Thu, 12 Jan 2023 08:06:41 +0900 Subject: [PATCH] Support a branch in detached HEAD state Fix issue #346 This commit prevents `sh: 1: Syntax error: "(" unexpected` error and completes the run with compare mode successfully. --- CHANGELOG.md | 1 + lib/rubycritic/source_control_systems/git.rb | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66021d16..9068d513 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ * [CHANGE] Fix some typos (by [@ydah][]) * [CHANGE] Remove wrong Rubocop reference in contributing file (by [@itsmeurbi]: https://github.com/itsmeurbi) * [BUGFIX] Restore missing smell status label (by [@itsmeurbi]: https://github.com/itsmeurbi) +* [FEATURE] Support a branch in 'detached HEAD' state (by [@h-r-k-matsumoto]: https://github.com/h-r-k-matsumoto) # v4.7.0 / 2022-05-06 [(commits)](https://github.com/whitesmith/rubycritic/compare/v4.6.1...v4.7.0) diff --git a/lib/rubycritic/source_control_systems/git.rb b/lib/rubycritic/source_control_systems/git.rb index 1a6f6a76..f3486459 100644 --- a/lib/rubycritic/source_control_systems/git.rb +++ b/lib/rubycritic/source_control_systems/git.rb @@ -81,7 +81,9 @@ def self.modified_files def self.current_branch branch_list = `git branch` - branch_list.match(/\*.*$/)[0].gsub('* ', '') + branch = branch_list.match(/\*.*$/)[0].gsub('* ', '') + branch = branch.gsub(/\(HEAD detached at (.*)\)$/, '\1') if branch =~ /\(HEAD detached at (.*)\)$/ + branch end private