Repository: xonsh/xonsh

Issue:
[color] in .gitconfig should be stripped in the prompt branch functions
In clean install with no `.xonshrc`, when I change into a git repo, my prompt looks like:

![prompt](https://i.imgur.com/ZFOPSOj.png)

Is there some setting I'm missing somewhere?

## xonfig

<details>

```
+------------------+----------------------+
| xonsh            | 0.9.13.dev1          |
| Git SHA          | 9f7ccc65             |
| Commit Date      | Oct 15 17:14:50 2019 |
| Python           | 3.7.6                |
| PLY              | 3.11                 |
| have readline    | True                 |
| prompt toolkit   | 3.0.0                |
| shell type       | prompt_toolkit2      |
| pygments         | 2.5.2                |
| on posix         | True                 |
| on linux         | True                 |
| distro           | ubuntu               |
| on darwin        | False                |
| on windows       | False                |
| on cygwin        | False                |
| on msys2         | False                |
| is superuser     | False                |
| default encoding | utf-8                |
| xonsh encoding   | utf-8                |
| encoding errors  | surrogateescape      |
+------------------+----------------------+
```


</details>

## Expected Behavior
I think something like this (without the ansi escape codes):
```
mcrowe@mike-XPS-15-9560 ~/.dotfiles/bash_it [master] $
```



Discussion:
OK, tracked this down, and I am suitably ashamed.  This is actually coming from my `.gitconfig`, which had:

```

[color]
    branch = always
    diff = always
    grep = always
    interactive = always
    pager = true
    showbranch = auto
    status = auto
    ui = always

[color "interactive"]
    error = red bold

[color "branch"]
    current = yellow reverse
    local = yellow
    remote = green

[color "diff"]
    meta = yellow
    frag = magenta
    old = red
    new = green
    whitespace = white reverse

[color "status"]
    added = yellow
    changed = green
    untracked = cyan
    branch = magenta
```

I didn't realize it was pulling the branch from the shell.  Lesson learned, apologies...
Actually, I think this should be addressed.  I'm going to submit a PR with a fix

Resolving patch:
diff --git a/xonsh/prompt/vc.py b/xonsh/prompt/vc.py
--- a/xonsh/prompt/vc.py
+++ b/xonsh/prompt/vc.py
@@ -8,8 +8,16 @@
 import builtins
 import threading
 import subprocess
+import re
 
 import xonsh.tools as xt
+from xonsh.lazyasd import LazyObject
+
+RE_REMOVE_ANSI = LazyObject(
+    lambda: re.compile(r"(?:\x1B[@-_]|[\x80-\x9F])[0-?]*[ -/]*[@-~]"),
+    globals(),
+    "RE_REMOVE_ANSI",
+)
 
 
 def _get_git_branch(q):
@@ -50,6 +58,9 @@ def get_git_branch():
     t.join(timeout=timeout)
     try:
         branch = q.get_nowait()
+        # branch = RE_REMOVE_ANSI.sub("", branch or "")
+        if branch:
+            branch = RE_REMOVE_ANSI.sub("", branch)
     except queue.Empty:
         branch = None
     return branch


Test patch:
diff --git a/tests/test_prompt.py b/tests/test_prompt.py
--- a/tests/test_prompt.py
+++ b/tests/test_prompt.py
@@ -241,6 +241,21 @@ def test_vc_get_branch(test_repo, xonsh_builtins):
     obs = getattr(vc, fun)()
     if obs is not None:
         assert obs == VC_BRANCH[test_repo["name"]]
+        if test_repo["name"] == "git":
+            with open("{}/.git/config".format(test_repo["dir"]), "a") as gc:
+                gc.write(
+                    """
+[color]
+    branch = always
+    interactive = always
+[color "branch"]
+    current = yellow reverse
+"""
+                )
+            obs = getattr(vc, fun)()
+            if obs is not None:
+                assert obs == VC_BRANCH[test_repo["name"]]
+                assert not obs.startswith(u"\u001b[")
 
 
 def test_current_branch_calls_locate_binary_for_empty_cmds_cache(xonsh_builtins):
@@ -253,7 +268,7 @@ def test_current_branch_calls_locate_binary_for_empty_cmds_cache(xonsh_builtins)
 
 
 def test_current_branch_does_not_call_locate_binary_for_non_empty_cmds_cache(
-    xonsh_builtins
+    xonsh_builtins,
 ):
     cache = xonsh_builtins.__xonsh__.commands_cache
     xonsh_builtins.__xonsh__.env = DummyEnv(VC_BRANCH_TIMEOUT=1)