Skip to content

Commit

Permalink
Support a branch in detached HEAD state
Browse files Browse the repository at this point in the history
Fix issue whitesmith#346

This commit prevents `sh: 1: Syntax error: "(" unexpected` error and completes the run with compare mode successfully.
  • Loading branch information
h-r-k-matsumoto committed Jan 11, 2023
1 parent 3bc857d commit 956c765
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 3 additions & 1 deletion lib/rubycritic/source_control_systems/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 956c765

Please sign in to comment.