deplinenoise / tundra

Tundra is a code build system that tries to be accurate and fast for incremental builds
MIT License
438 stars 75 forks source link

Color output in `git branch` results in invalid filename #281

Closed andrei-pavel closed 8 years ago

andrei-pavel commented 8 years ago

Replication:

$ make make: * No rule to make target '.git/refs/heads/master', needed by 'build/gitversionmaster**.c'. Stop.

The bolded text above was displayed in green color for me. I thought nothing of it since I use zsh with a lot of plugins which I thought were the culprit. To see what's going on, I've changed the Makefile by adding the rule:

$(GIT_FILE): cat $(GIT_FILE)

I've noticed:

$ make [...] cat .git/refs/heads/master cat: '.git/refs/heads/'$'\033''[32mmaster'$'\033''[m': No such file or directory

It seems that ANSII color escape sequences are somehow preserved in variables in my environment. The fix for this is simple.

The solution is simple. Add --no-color at Makefile:15 thus changing from:

GIT_BRANCH := $(shell (git branch 2>/dev/null) | sed -n '/^/s/^ //p')

to:

GIT_BRANCH := $(shell (git branch --no-color 2>/dev/null) | sed -n '/^/s/^ //p')

Thanks! Let me know if you need environment details or anything else.

EDIT: Coherence

andrei-pavel commented 8 years ago

I don't know how this is not happening to everyone.

I have xfce4-terminal, but this replicates on xterm and terminator as well. I use zsh, but bash and sh behave the same. I have git-2.10.0, but problem persists on git-2.7.4 as well.

I've created a pull request to solve this. You may merge that one or create your own. Thanks!