Skip to content

add --no-color option to commands like git log #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kkrol89 opened this issue Sep 28, 2011 · 3 comments
Closed

add --no-color option to commands like git log #30

kkrol89 opened this issue Sep 28, 2011 · 3 comments
Assignees
Milestone

Comments

@kkrol89
Copy link

kkrol89 commented Sep 28, 2011

I get following errors on linux with git version 1.7.4.1 and ruby-git gem version 1.2.5 when color ui is set to always.

require 'git'; git = Git.open('.'); git.log(1).inspect
NoMethodError: undefined method `[]=' for nil:NilClass
    from /home/konrad/.rvm/gems/ruby-1.9.2-p180@example_gemset/gems/git-1.2.5/lib/git/lib.rb:153:in `block in process_commit_data'
    from /home/konrad/.rvm/gems/ruby-1.9.2-p180@example_gemset/gems/git-1.2.5/lib/git/lib.rb:135:in `each'
    from /home/konrad/.rvm/gems/ruby-1.9.2-p180@example_gemset/gems/git-1.2.5/lib/git/lib.rb:135:in `process_commit_data'
    from /home/konrad/.rvm/gems/ruby-1.9.2-p180@example_gemset/gems/git-1.2.5/lib/git/lib.rb:93:in `full_log_commits'
    from /home/konrad/.rvm/gems/ruby-1.9.2-p180@example_gemset/gems/git-1.2.5/lib/git/log.rb:108:in `run_log'
    from /home/konrad/.rvm/gems/ruby-1.9.2-p180@example_gemset/gems/git-1.2.5/lib/git/log.rb:101:in `check_log'
    from /home/konrad/.rvm/gems/ruby-1.9.2-p180@example_gemset/gems/git-1.2.5/lib/git/log.rb:84:in `each'
    from /home/konrad/.rvm/gems/ruby-1.9.2-p180@example_gemset/gems/git-1.2.5/lib/git/log.rb:72:in `map'
    from /home/konrad/.rvm/gems/ruby-1.9.2-p180@example_gemset/gems/git-1.2.5/lib/git/log.rb:72:in `to_s'
    from (irb):4:in `inspect'
    from (irb):4
    from /home/konrad/.rvm/rubies/ruby-1.9.2-p180/bin/irb:16:in `<main>'

Solution is to add --no-color option to git commands like git log or git diff, so that color tags like '\e[43m' are not included in data being processed.

@svenkeidel
Copy link

+1 affected

The error also occures when at all other commands.

if you have [color] ui = always in your gitconfig, all branchlabels contains the shell color sequences: \e[32mmaster\e[m

Greetings Sven

@marcomorain
Copy link

I've started work on a fix:
#48

@robertodecurnex
Copy link
Contributor

Fixed by #48

mhoyer added a commit to mhoyer/ruby-git that referenced this issue Nov 8, 2019
### `current_branch` contains color escape codes
Similar to ruby-git#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.
mhoyer added a commit to mhoyer/ruby-git that referenced this issue Nov 11, 2019
Similar to ruby-git#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.

* `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]`

```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"`.

`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`).

`git.current_branch` contains `"\e[32m"` color escape codes.

Signed-off-by: Marcel Hoyer <m.hoyer@cid.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants