Skip to content

Commit 1df6013

Browse files
authored
current_branch contains color escape codes
### `current_branch` contains color escape codes Similar to #30 I just found an issue with `ruby-git` when trying to match the string returned from `current_branch` with e.g. `"master"`. I just recently found this issue and I guess it's related to a recent update of my `git` on my machine which came in just recently. ### Your environment * `git@2.24.0.windows.2` * `ruby-git@1.5.0` (also had `1.3.0` before - same issue) * `ruby@2.3.1p112 (2016-04-26 revision 54768) [i386-mingw32]` ### Steps to reproduce ```ruby $ irb irb(main):002:0> require 'git'; git = Git.open '.'; git.current_branch master => "\e[32mmaster\e[m" ``` Hence, `"\e[32mmaster\e[m"` is not equal to `"master"`. ### Expected behaviour `git.current_branch` should return the string of the current branch without coloring. In fact, the underlying run of `git branch` should include `--no-color` option (which is a nested call inside `branches_all`). ### Actual behaviour `git.current_branch` contains `"\e[32m"` color escape codes.
1 parent 2402674 commit 1df6013

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

lib/git/lib.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ def change_head_branch(branch_name)
300300

301301
def branches_all
302302
arr = []
303-
command_lines('branch', '-a').each do |b|
303+
command_lines('branch', ['-a', '--no-color']).each do |b|
304304
current = (b[0, 2] == '* ')
305305
arr << [b.gsub('* ', '').strip, current]
306306
end

0 commit comments

Comments
 (0)