ANSI escape sequences in pre-commit hook pollute git output

129 views
Skip to first unread message

Robin Green

unread,
Oct 22, 2015, 3:29:21 PM10/22/15
to magit
I have installed overcommit[1] as a pre-commit hook. It outputs ANSI escape sequences to set colors, and these are rendered as follows in the magit-process buffer:


[1mRunning pre-commit hooks [0m

[32m✓ All pre-commit hooks passed [0m

Waiting for Emacs...
[1mRunning commit-msg hooks [0m
Checking subject capitalization..................[CapitalizedSubject] [32mOK [0m
Checking subject line.............................[SingleLineSubject] [32mOK [0m
Checking text width.......................................[TextWidth] [32mOK [0m
Checking for trailing periods in subject.............[TrailingPeriod] [32mOK [0m

[32m✓ All commit-msg hooks passed [0m


I am not sure who is at fault here. overcommit appears to be doing the right thing by testing whether its output is a tty, at least at a quick glance at its code. Maybe magit is telling git not to output colors, but still communicating with git using a pseudoterminal, so that git hook scripts believe they are running in a terminal?

[1] https://github.com/brigade/overcommit

Jonas Bernoulli

unread,
Oct 23, 2015, 11:35:27 AM10/23/15
to Robin Green, magit

Robin Green <gre...@gmail.com> writes:

> I have installed overcommit[1] as a pre-commit hook. It outputs ANSI
> escape sequences to set colors, and these are rendered as follows in
> the magit-process buffer:
>
> I am not sure who is at fault here. overcommit appears to be doing the
> right thing by testing whether its output is a tty, at least at a
> quick glance at its code. Maybe magit is telling git not to output
> colors, but still communicating with git using a pseudoterminal, so
> that git hook scripts believe they are running in a terminal?

Magit by default indeed uses tty when running Git (see
`magit-process-connection-type') but it does *not* tell Git to not color
the output explicitly (see `magit-git-global-arguments'), so Git must be
figuring it out itself.

We do have to use a tty because otherwise we cannot read the password
from the user. On Windows we have to hack around this, so to avoid
having to do that for other platforms, we will keep using a tty by
default.

You should probably ask for an `overcommit' option or setting which can
be used to tell it not to color the output.

Robin Green

unread,
Oct 23, 2015, 11:46:25 AM10/23/15
to magit, gre...@gmail.com

Alternatively, could we not do something similar to:

http://www.emacswiki.org/emacs/AnsiColor

From a quick look at the magit code I couldn't find an equivalent to `comint-output-filter-functions`, though.

Reply all
Reply to author
Forward
0 new messages