Skip to content
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

Strip any ANSI escape codes from git command output #2689

Merged
merged 1 commit into from
Mar 23, 2017

Conversation

warrenfalk
Copy link
Contributor

Strip ANSI escape codes from all git output.

Previous attempts to set environment variables to tell git not to output these do not always work. On my installation using git with msys2, git continues to emit the color codes and breaks GitExtensions' diff output and other things. This commit fixes the issue cleanly.

@jbialobr
Copy link
Member

jbialobr commented Mar 7, 2015

Is it possible to determine whether the current git configuration results in emitting ANSI escape codes? (Perhaps perform some simple command) If yes, we could do stripping only when needed.

@warrenfalk
Copy link
Contributor Author

That was my first approach and there were a couple problems with it.

  1. Git is not the source of all of its output. A commit hook on a server, can also output escape codes, and server scripts cannot be aware of local environments.
  2. I was unable to find any reliable way to even determine what git would do. It is possible to check the config and try to guess, but trying to guess what git may do today and in the future is fragile. This fix makes it work once and for all.

You could try to run every command and see if that command outputs escape codes, but not every command even does it every time.

Plus git may change in the future how it decides when to output escape codes making any attempts to detect this break. You'd then need to re-research the problem at that point and use a version-dependent algorithm to check.

If performance is a concern, I did check that the regex returns the original string when it finds no match. And since the regex is compiled and optimized it should need only to see if the string contains char code 27, and return the original if not.

@KindDragon KindDragon force-pushed the master branch 8 times, most recently from f479657 to 3ba72ae Compare November 26, 2015 21:23
@jbialobr jbialobr merged commit 6cef79a into gitextensions:master Mar 23, 2017
@jbialobr
Copy link
Member

Thank you for the thorough explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants