We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Prompt `curr_branch` breaks when git config has status.short
If git config contains:

``` ini
[status]
    short = true
```

then [the current method of getting the git branch](https://github.com/xonsh/xonsh/blob/619ae11486f2e4febfc2218c0d53c7b3f3c9ea49/xonsh/prompt/vc_branch.py#L16-L25) fails, even if `status.branch = true` is also set.

`git status` is a heavy-handed way of doing this anyway; better would be `git rev-parse --abbrev-ref HEAD` IMO. (PR to follow.)


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `xonsh/prompt/vc_branch.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 """Prompt formatter for simple version control branchs"""
3 
4 import os
5 import sys
6 import time
7 import queue
8 import builtins
9 import warnings
10 import threading
11 import subprocess
12 
13 import xonsh.tools as xt
14 
15 
16 def _get_git_branch(q):
17     try:
18         status = subprocess.check_output(['git', 'status'],
19                                          stderr=subprocess.DEVNULL)
20     except (subprocess.CalledProcessError, OSError):
21         q.put(None)
22     else:
23         info = xt.decode_bytes(status)
24         branch = info.splitlines()[0].split()[-1]
25         q.put(branch)
26 
27 
28 def get_git_branch():
29     """Attempts to find the current git branch. If this could not
30     be determined (timeout, not in a git repo, etc.) then this returns None.
31     """
32     branch = None
33     timeout = builtins.__xonsh_env__.get('VC_BRANCH_TIMEOUT')
34     q = queue.Queue()
35 
36     t = threading.Thread(target=_get_git_branch, args=(q,))
37     t.start()
38     t.join(timeout=timeout)
39     try:
40         branch = q.get_nowait()
41     except queue.Empty:
42         branch = None
43     return branch
44 
45 
46 def _get_parent_dir_for(path, dir_name, timeout):
47     # walk up the directory tree to see if we are inside an hg repo
48     # the timeout makes sure that we don't thrash the file system
49     previous_path = ''
50     t0 = time.time()
51     while path != previous_path and ((time.time() - t0) < timeout):
52         if os.path.isdir(os.path.join(path, dir_name)):
53             return path
54         previous_path = path
55         path, _ = os.path.split(path)
56     return (path == previous_path)
57 
58 
59 def get_hg_branch(cwd=None, root=None):
60     env = builtins.__xonsh_env__
61     cwd = env['PWD']
62     root = _get_parent_dir_for(cwd, '.hg', env['VC_BRANCH_TIMEOUT'])
63     if not isinstance(root, str):
64         # Bail if we are not in a repo or we timed out
65         if root:
66             return None
67         else:
68             return subprocess.TimeoutExpired(['hg'], env['VC_BRANCH_TIMEOUT'])
69     if env.get('VC_HG_SHOW_BRANCH') is True:
70         # get branch name
71         branch_path = os.path.sep.join([root, '.hg', 'branch'])
72         if os.path.exists(branch_path):
73             with open(branch_path, 'r') as branch_file:
74                 branch = branch_file.read()
75         else:
76             branch = 'default'
77     else:
78         branch = ''
79     # add bookmark, if we can
80     bookmark_path = os.path.sep.join([root, '.hg', 'bookmarks.current'])
81     if os.path.exists(bookmark_path):
82         with open(bookmark_path, 'r') as bookmark_file:
83             active_bookmark = bookmark_file.read()
84         if env.get('VC_HG_SHOW_BRANCH') is True:
85             branch = "{0}, {1}".format(*(b.strip(os.linesep) for b in
86                                         (branch, active_bookmark)))
87         else:
88             branch = active_bookmark.strip(os.linesep)
89     else:
90         branch = branch.strip(os.linesep)
91     return branch
92 
93 
94 _FIRST_BRANCH_TIMEOUT = True
95 
96 
97 def _first_branch_timeout_message():
98     global _FIRST_BRANCH_TIMEOUT
99     sbtm = builtins.__xonsh_env__['SUPPRESS_BRANCH_TIMEOUT_MESSAGE']
100     if not _FIRST_BRANCH_TIMEOUT or sbtm:
101         return
102     _FIRST_BRANCH_TIMEOUT = False
103     print('xonsh: branch timeout: computing the branch name, color, or both '
104           'timed out while formatting the prompt. You may avoid this by '
105           'increaing the value of $VC_BRANCH_TIMEOUT or by removing branch '
106           'fields, like {curr_branch}, from your $PROMPT. See the FAQ '
107           'for more details. This message will be suppressed for the remainder '
108           'of this session. To suppress this message permanently, set '
109           '$SUPPRESS_BRANCH_TIMEOUT_MESSAGE = True in your xonshrc file.',
110           file=sys.stderr)
111 
112 
113 def current_branch(pad=NotImplemented):
114     """Gets the branch for a current working directory. Returns an empty string
115     if the cwd is not a repository.  This currently only works for git and hg
116     and should be extended in the future.  If a timeout occurred, the string
117     '<branch-timeout>' is returned.
118     """
119     if pad is not NotImplemented:
120         warnings.warn("The pad argument of current_branch has no effect now "
121                       "and will be removed in the future")
122     branch = None
123     cmds = builtins.__xonsh_commands_cache__
124     if cmds.lazy_locate_binary('git') or cmds.is_empty():
125         branch = get_git_branch()
126     if (cmds.lazy_locate_binary('hg') or cmds.is_empty()) and not branch:
127         branch = get_hg_branch()
128     if isinstance(branch, subprocess.TimeoutExpired):
129         branch = '<branch-timeout>'
130         _first_branch_timeout_message()
131     return branch or None
132 
133 
134 def _git_dirty_working_directory(q, include_untracked):
135     status = None
136     try:
137         cmd = ['git', 'status', '--porcelain']
138         if include_untracked:
139             cmd.append('--untracked-files=normal')
140         else:
141             cmd.append('--untracked-files=no')
142         status = subprocess.check_output(cmd, stderr=subprocess.DEVNULL)
143     except (subprocess.CalledProcessError, OSError):
144         q.put(None)
145     if status is not None:
146         return q.put(bool(status))
147 
148 
149 def git_dirty_working_directory(include_untracked=False):
150     """Returns whether or not the git directory is dirty. If this could not
151     be determined (timeout, file not found, etc.) then this returns None.
152     """
153     timeout = builtins.__xonsh_env__.get("VC_BRANCH_TIMEOUT")
154     q = queue.Queue()
155     t = threading.Thread(target=_git_dirty_working_directory,
156                          args=(q, include_untracked))
157     t.start()
158     t.join(timeout=timeout)
159     try:
160         return q.get_nowait()
161     except queue.Empty:
162         return None
163 
164 
165 def hg_dirty_working_directory():
166     """Computes whether or not the mercurial working directory is dirty or not.
167     If this cannot be deterimined, None is returned.
168     """
169     env = builtins.__xonsh_env__
170     cwd = env['PWD']
171     denv = env.detype()
172     vcbt = env['VC_BRANCH_TIMEOUT']
173     # Override user configurations settings and aliases
174     denv['HGRCPATH'] = ''
175     try:
176         s = subprocess.check_output(['hg', 'identify', '--id'],
177                                     stderr=subprocess.PIPE, cwd=cwd,
178                                     timeout=vcbt, universal_newlines=True,
179                                     env=denv)
180         return s.strip(os.linesep).endswith('+')
181     except (subprocess.CalledProcessError, subprocess.TimeoutExpired,
182             FileNotFoundError):
183         return None
184 
185 
186 def dirty_working_directory(cwd=None):
187     """Returns a boolean as to whether there are uncommitted files in version
188     control repository we are inside. If this cannot be determined, returns
189     None. Currently supports git and hg.
190     """
191     dwd = None
192     cmds = builtins.__xonsh_commands_cache__
193     if cmds.lazy_locate_binary('git') or cmds.is_empty():
194         dwd = git_dirty_working_directory()
195     if (cmds.lazy_locate_binary('hg') or cmds.is_empty()) and (dwd is None):
196         dwd = hg_dirty_working_directory()
197     return dwd
198 
199 
200 def branch_color():
201     """Return red if the current branch is dirty, yellow if the dirtiness can
202     not be determined, and green if it clean. These are bold, intense colors
203     for the foreground.
204     """
205     dwd = dirty_working_directory()
206     if dwd is None:
207         color = '{BOLD_INTENSE_YELLOW}'
208     elif dwd:
209         color = '{BOLD_INTENSE_RED}'
210     else:
211         color = '{BOLD_INTENSE_GREEN}'
212     return color
213 
214 
215 def branch_bg_color():
216     """Return red if the current branch is dirty, yellow if the dirtiness can
217     not be determined, and green if it clean. These are bacground colors.
218     """
219     dwd = dirty_working_directory()
220     if dwd is None:
221         color = '{BACKGROUND_YELLOW}'
222     elif dwd:
223         color = '{BACKGROUND_RED}'
224     else:
225         color = '{BACKGROUND_GREEN}'
226     return color
227
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/xonsh/prompt/vc_branch.py b/xonsh/prompt/vc_branch.py
--- a/xonsh/prompt/vc_branch.py
+++ b/xonsh/prompt/vc_branch.py
@@ -15,15 +15,25 @@
 
 def _get_git_branch(q):
     try:
-        status = subprocess.check_output(['git', 'status'],
-                                         stderr=subprocess.DEVNULL)
+        branches = xt.decode_bytes(subprocess.check_output(
+            ['git', 'branch'],
+            stderr=subprocess.DEVNULL
+        )).splitlines()
     except (subprocess.CalledProcessError, OSError):
         q.put(None)
     else:
-        info = xt.decode_bytes(status)
-        branch = info.splitlines()[0].split()[-1]
-        q.put(branch)
-
+        for branch in branches:
+            if not branch.startswith('* '):
+                continue
+            elif branch.endswith(')'):
+                branch = branch.split()[-1][:-1]
+            else:
+                branch = branch.split()[-1]
+
+            q.put(branch)
+            break
+        else:
+            q.put(None)
 
 def get_git_branch():
     """Attempts to find the current git branch. If this could not

{"golden_diff": "diff --git a/xonsh/prompt/vc_branch.py b/xonsh/prompt/vc_branch.py\n--- a/xonsh/prompt/vc_branch.py\n+++ b/xonsh/prompt/vc_branch.py\n@@ -15,15 +15,25 @@\n \n def _get_git_branch(q):\n     try:\n-        status = subprocess.check_output(['git', 'status'],\n-                                         stderr=subprocess.DEVNULL)\n+        branches = xt.decode_bytes(subprocess.check_output(\n+            ['git', 'branch'],\n+            stderr=subprocess.DEVNULL\n+        )).splitlines()\n     except (subprocess.CalledProcessError, OSError):\n         q.put(None)\n     else:\n-        info = xt.decode_bytes(status)\n-        branch = info.splitlines()[0].split()[-1]\n-        q.put(branch)\n-\n+        for branch in branches:\n+            if not branch.startswith('* '):\n+                continue\n+            elif branch.endswith(')'):\n+                branch = branch.split()[-1][:-1]\n+            else:\n+                branch = branch.split()[-1]\n+\n+            q.put(branch)\n+            break\n+        else:\n+            q.put(None)\n \n def get_git_branch():\n     \"\"\"Attempts to find the current git branch. If this could not\n", "issue": "Prompt `curr_branch` breaks when git config has status.short\nIf git config contains:\n\n``` ini\n[status]\n    short = true\n```\n\nthen [the current method of getting the git branch](https://github.com/xonsh/xonsh/blob/619ae11486f2e4febfc2218c0d53c7b3f3c9ea49/xonsh/prompt/vc_branch.py#L16-L25) fails, even if `status.branch = true` is also set.\n\n`git status` is a heavy-handed way of doing this anyway; better would be `git rev-parse --abbrev-ref HEAD` IMO. (PR to follow.)\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"Prompt formatter for simple version control branchs\"\"\"\n\nimport os\nimport sys\nimport time\nimport queue\nimport builtins\nimport warnings\nimport threading\nimport subprocess\n\nimport xonsh.tools as xt\n\n\ndef _get_git_branch(q):\n    try:\n        status = subprocess.check_output(['git', 'status'],\n                                         stderr=subprocess.DEVNULL)\n    except (subprocess.CalledProcessError, OSError):\n        q.put(None)\n    else:\n        info = xt.decode_bytes(status)\n        branch = info.splitlines()[0].split()[-1]\n        q.put(branch)\n\n\ndef get_git_branch():\n    \"\"\"Attempts to find the current git branch. If this could not\n    be determined (timeout, not in a git repo, etc.) then this returns None.\n    \"\"\"\n    branch = None\n    timeout = builtins.__xonsh_env__.get('VC_BRANCH_TIMEOUT')\n    q = queue.Queue()\n\n    t = threading.Thread(target=_get_git_branch, args=(q,))\n    t.start()\n    t.join(timeout=timeout)\n    try:\n        branch = q.get_nowait()\n    except queue.Empty:\n        branch = None\n    return branch\n\n\ndef _get_parent_dir_for(path, dir_name, timeout):\n    # walk up the directory tree to see if we are inside an hg repo\n    # the timeout makes sure that we don't thrash the file system\n    previous_path = ''\n    t0 = time.time()\n    while path != previous_path and ((time.time() - t0) < timeout):\n        if os.path.isdir(os.path.join(path, dir_name)):\n            return path\n        previous_path = path\n        path, _ = os.path.split(path)\n    return (path == previous_path)\n\n\ndef get_hg_branch(cwd=None, root=None):\n    env = builtins.__xonsh_env__\n    cwd = env['PWD']\n    root = _get_parent_dir_for(cwd, '.hg', env['VC_BRANCH_TIMEOUT'])\n    if not isinstance(root, str):\n        # Bail if we are not in a repo or we timed out\n        if root:\n            return None\n        else:\n            return subprocess.TimeoutExpired(['hg'], env['VC_BRANCH_TIMEOUT'])\n    if env.get('VC_HG_SHOW_BRANCH') is True:\n        # get branch name\n        branch_path = os.path.sep.join([root, '.hg', 'branch'])\n        if os.path.exists(branch_path):\n            with open(branch_path, 'r') as branch_file:\n                branch = branch_file.read()\n        else:\n            branch = 'default'\n    else:\n        branch = ''\n    # add bookmark, if we can\n    bookmark_path = os.path.sep.join([root, '.hg', 'bookmarks.current'])\n    if os.path.exists(bookmark_path):\n        with open(bookmark_path, 'r') as bookmark_file:\n            active_bookmark = bookmark_file.read()\n        if env.get('VC_HG_SHOW_BRANCH') is True:\n            branch = \"{0}, {1}\".format(*(b.strip(os.linesep) for b in\n                                        (branch, active_bookmark)))\n        else:\n            branch = active_bookmark.strip(os.linesep)\n    else:\n        branch = branch.strip(os.linesep)\n    return branch\n\n\n_FIRST_BRANCH_TIMEOUT = True\n\n\ndef _first_branch_timeout_message():\n    global _FIRST_BRANCH_TIMEOUT\n    sbtm = builtins.__xonsh_env__['SUPPRESS_BRANCH_TIMEOUT_MESSAGE']\n    if not _FIRST_BRANCH_TIMEOUT or sbtm:\n        return\n    _FIRST_BRANCH_TIMEOUT = False\n    print('xonsh: branch timeout: computing the branch name, color, or both '\n          'timed out while formatting the prompt. You may avoid this by '\n          'increaing the value of $VC_BRANCH_TIMEOUT or by removing branch '\n          'fields, like {curr_branch}, from your $PROMPT. See the FAQ '\n          'for more details. This message will be suppressed for the remainder '\n          'of this session. To suppress this message permanently, set '\n          '$SUPPRESS_BRANCH_TIMEOUT_MESSAGE = True in your xonshrc file.',\n          file=sys.stderr)\n\n\ndef current_branch(pad=NotImplemented):\n    \"\"\"Gets the branch for a current working directory. Returns an empty string\n    if the cwd is not a repository.  This currently only works for git and hg\n    and should be extended in the future.  If a timeout occurred, the string\n    '<branch-timeout>' is returned.\n    \"\"\"\n    if pad is not NotImplemented:\n        warnings.warn(\"The pad argument of current_branch has no effect now \"\n                      \"and will be removed in the future\")\n    branch = None\n    cmds = builtins.__xonsh_commands_cache__\n    if cmds.lazy_locate_binary('git') or cmds.is_empty():\n        branch = get_git_branch()\n    if (cmds.lazy_locate_binary('hg') or cmds.is_empty()) and not branch:\n        branch = get_hg_branch()\n    if isinstance(branch, subprocess.TimeoutExpired):\n        branch = '<branch-timeout>'\n        _first_branch_timeout_message()\n    return branch or None\n\n\ndef _git_dirty_working_directory(q, include_untracked):\n    status = None\n    try:\n        cmd = ['git', 'status', '--porcelain']\n        if include_untracked:\n            cmd.append('--untracked-files=normal')\n        else:\n            cmd.append('--untracked-files=no')\n        status = subprocess.check_output(cmd, stderr=subprocess.DEVNULL)\n    except (subprocess.CalledProcessError, OSError):\n        q.put(None)\n    if status is not None:\n        return q.put(bool(status))\n\n\ndef git_dirty_working_directory(include_untracked=False):\n    \"\"\"Returns whether or not the git directory is dirty. If this could not\n    be determined (timeout, file not found, etc.) then this returns None.\n    \"\"\"\n    timeout = builtins.__xonsh_env__.get(\"VC_BRANCH_TIMEOUT\")\n    q = queue.Queue()\n    t = threading.Thread(target=_git_dirty_working_directory,\n                         args=(q, include_untracked))\n    t.start()\n    t.join(timeout=timeout)\n    try:\n        return q.get_nowait()\n    except queue.Empty:\n        return None\n\n\ndef hg_dirty_working_directory():\n    \"\"\"Computes whether or not the mercurial working directory is dirty or not.\n    If this cannot be deterimined, None is returned.\n    \"\"\"\n    env = builtins.__xonsh_env__\n    cwd = env['PWD']\n    denv = env.detype()\n    vcbt = env['VC_BRANCH_TIMEOUT']\n    # Override user configurations settings and aliases\n    denv['HGRCPATH'] = ''\n    try:\n        s = subprocess.check_output(['hg', 'identify', '--id'],\n                                    stderr=subprocess.PIPE, cwd=cwd,\n                                    timeout=vcbt, universal_newlines=True,\n                                    env=denv)\n        return s.strip(os.linesep).endswith('+')\n    except (subprocess.CalledProcessError, subprocess.TimeoutExpired,\n            FileNotFoundError):\n        return None\n\n\ndef dirty_working_directory(cwd=None):\n    \"\"\"Returns a boolean as to whether there are uncommitted files in version\n    control repository we are inside. If this cannot be determined, returns\n    None. Currently supports git and hg.\n    \"\"\"\n    dwd = None\n    cmds = builtins.__xonsh_commands_cache__\n    if cmds.lazy_locate_binary('git') or cmds.is_empty():\n        dwd = git_dirty_working_directory()\n    if (cmds.lazy_locate_binary('hg') or cmds.is_empty()) and (dwd is None):\n        dwd = hg_dirty_working_directory()\n    return dwd\n\n\ndef branch_color():\n    \"\"\"Return red if the current branch is dirty, yellow if the dirtiness can\n    not be determined, and green if it clean. These are bold, intense colors\n    for the foreground.\n    \"\"\"\n    dwd = dirty_working_directory()\n    if dwd is None:\n        color = '{BOLD_INTENSE_YELLOW}'\n    elif dwd:\n        color = '{BOLD_INTENSE_RED}'\n    else:\n        color = '{BOLD_INTENSE_GREEN}'\n    return color\n\n\ndef branch_bg_color():\n    \"\"\"Return red if the current branch is dirty, yellow if the dirtiness can\n    not be determined, and green if it clean. These are bacground colors.\n    \"\"\"\n    dwd = dirty_working_directory()\n    if dwd is None:\n        color = '{BACKGROUND_YELLOW}'\n    elif dwd:\n        color = '{BACKGROUND_RED}'\n    else:\n        color = '{BACKGROUND_GREEN}'\n    return color\n", "path": "xonsh/prompt/vc_branch.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"Prompt formatter for simple version control branchs\"\"\"\n\nimport os\nimport sys\nimport time\nimport queue\nimport builtins\nimport warnings\nimport threading\nimport subprocess\n\nimport xonsh.tools as xt\n\n\ndef _get_git_branch(q):\n    try:\n        branches = xt.decode_bytes(subprocess.check_output(\n            ['git', 'branch'],\n            stderr=subprocess.DEVNULL\n        )).splitlines()\n    except (subprocess.CalledProcessError, OSError):\n        q.put(None)\n    else:\n        for branch in branches:\n            if not branch.startswith('* '):\n                continue\n            elif branch.endswith(')'):\n                branch = branch.split()[-1][:-1]\n            else:\n                branch = branch.split()[-1]\n\n            q.put(branch)\n            break\n        else:\n            q.put(None)\n\ndef get_git_branch():\n    \"\"\"Attempts to find the current git branch. If this could not\n    be determined (timeout, not in a git repo, etc.) then this returns None.\n    \"\"\"\n    branch = None\n    timeout = builtins.__xonsh_env__.get('VC_BRANCH_TIMEOUT')\n    q = queue.Queue()\n\n    t = threading.Thread(target=_get_git_branch, args=(q,))\n    t.start()\n    t.join(timeout=timeout)\n    try:\n        branch = q.get_nowait()\n    except queue.Empty:\n        branch = None\n    return branch\n\n\ndef _get_parent_dir_for(path, dir_name, timeout):\n    # walk up the directory tree to see if we are inside an hg repo\n    # the timeout makes sure that we don't thrash the file system\n    previous_path = ''\n    t0 = time.time()\n    while path != previous_path and ((time.time() - t0) < timeout):\n        if os.path.isdir(os.path.join(path, dir_name)):\n            return path\n        previous_path = path\n        path, _ = os.path.split(path)\n    return (path == previous_path)\n\n\ndef get_hg_branch(cwd=None, root=None):\n    env = builtins.__xonsh_env__\n    cwd = env['PWD']\n    root = _get_parent_dir_for(cwd, '.hg', env['VC_BRANCH_TIMEOUT'])\n    if not isinstance(root, str):\n        # Bail if we are not in a repo or we timed out\n        if root:\n            return None\n        else:\n            return subprocess.TimeoutExpired(['hg'], env['VC_BRANCH_TIMEOUT'])\n    if env.get('VC_HG_SHOW_BRANCH') is True:\n        # get branch name\n        branch_path = os.path.sep.join([root, '.hg', 'branch'])\n        if os.path.exists(branch_path):\n            with open(branch_path, 'r') as branch_file:\n                branch = branch_file.read()\n        else:\n            branch = 'default'\n    else:\n        branch = ''\n    # add bookmark, if we can\n    bookmark_path = os.path.sep.join([root, '.hg', 'bookmarks.current'])\n    if os.path.exists(bookmark_path):\n        with open(bookmark_path, 'r') as bookmark_file:\n            active_bookmark = bookmark_file.read()\n        if env.get('VC_HG_SHOW_BRANCH') is True:\n            branch = \"{0}, {1}\".format(*(b.strip(os.linesep) for b in\n                                        (branch, active_bookmark)))\n        else:\n            branch = active_bookmark.strip(os.linesep)\n    else:\n        branch = branch.strip(os.linesep)\n    return branch\n\n\n_FIRST_BRANCH_TIMEOUT = True\n\n\ndef _first_branch_timeout_message():\n    global _FIRST_BRANCH_TIMEOUT\n    sbtm = builtins.__xonsh_env__['SUPPRESS_BRANCH_TIMEOUT_MESSAGE']\n    if not _FIRST_BRANCH_TIMEOUT or sbtm:\n        return\n    _FIRST_BRANCH_TIMEOUT = False\n    print('xonsh: branch timeout: computing the branch name, color, or both '\n          'timed out while formatting the prompt. You may avoid this by '\n          'increaing the value of $VC_BRANCH_TIMEOUT or by removing branch '\n          'fields, like {curr_branch}, from your $PROMPT. See the FAQ '\n          'for more details. This message will be suppressed for the remainder '\n          'of this session. To suppress this message permanently, set '\n          '$SUPPRESS_BRANCH_TIMEOUT_MESSAGE = True in your xonshrc file.',\n          file=sys.stderr)\n\n\ndef current_branch(pad=NotImplemented):\n    \"\"\"Gets the branch for a current working directory. Returns an empty string\n    if the cwd is not a repository.  This currently only works for git and hg\n    and should be extended in the future.  If a timeout occurred, the string\n    '<branch-timeout>' is returned.\n    \"\"\"\n    if pad is not NotImplemented:\n        warnings.warn(\"The pad argument of current_branch has no effect now \"\n                      \"and will be removed in the future\")\n    branch = None\n    cmds = builtins.__xonsh_commands_cache__\n    if cmds.lazy_locate_binary('git') or cmds.is_empty():\n        branch = get_git_branch()\n    if (cmds.lazy_locate_binary('hg') or cmds.is_empty()) and not branch:\n        branch = get_hg_branch()\n    if isinstance(branch, subprocess.TimeoutExpired):\n        branch = '<branch-timeout>'\n        _first_branch_timeout_message()\n    return branch or None\n\n\ndef _git_dirty_working_directory(q, include_untracked):\n    status = None\n    try:\n        cmd = ['git', 'status', '--porcelain']\n        if include_untracked:\n            cmd.append('--untracked-files=normal')\n        else:\n            cmd.append('--untracked-files=no')\n        status = subprocess.check_output(cmd, stderr=subprocess.DEVNULL)\n    except (subprocess.CalledProcessError, OSError):\n        q.put(None)\n    if status is not None:\n        return q.put(bool(status))\n\n\ndef git_dirty_working_directory(include_untracked=False):\n    \"\"\"Returns whether or not the git directory is dirty. If this could not\n    be determined (timeout, file not found, etc.) then this returns None.\n    \"\"\"\n    timeout = builtins.__xonsh_env__.get(\"VC_BRANCH_TIMEOUT\")\n    q = queue.Queue()\n    t = threading.Thread(target=_git_dirty_working_directory,\n                         args=(q, include_untracked))\n    t.start()\n    t.join(timeout=timeout)\n    try:\n        return q.get_nowait()\n    except queue.Empty:\n        return None\n\n\ndef hg_dirty_working_directory():\n    \"\"\"Computes whether or not the mercurial working directory is dirty or not.\n    If this cannot be deterimined, None is returned.\n    \"\"\"\n    env = builtins.__xonsh_env__\n    cwd = env['PWD']\n    denv = env.detype()\n    vcbt = env['VC_BRANCH_TIMEOUT']\n    # Override user configurations settings and aliases\n    denv['HGRCPATH'] = ''\n    try:\n        s = subprocess.check_output(['hg', 'identify', '--id'],\n                                    stderr=subprocess.PIPE, cwd=cwd,\n                                    timeout=vcbt, universal_newlines=True,\n                                    env=denv)\n        return s.strip(os.linesep).endswith('+')\n    except (subprocess.CalledProcessError, subprocess.TimeoutExpired,\n            FileNotFoundError):\n        return None\n\n\ndef dirty_working_directory(cwd=None):\n    \"\"\"Returns a boolean as to whether there are uncommitted files in version\n    control repository we are inside. If this cannot be determined, returns\n    None. Currently supports git and hg.\n    \"\"\"\n    dwd = None\n    cmds = builtins.__xonsh_commands_cache__\n    if cmds.lazy_locate_binary('git') or cmds.is_empty():\n        dwd = git_dirty_working_directory()\n    if (cmds.lazy_locate_binary('hg') or cmds.is_empty()) and (dwd is None):\n        dwd = hg_dirty_working_directory()\n    return dwd\n\n\ndef branch_color():\n    \"\"\"Return red if the current branch is dirty, yellow if the dirtiness can\n    not be determined, and green if it clean. These are bold, intense colors\n    for the foreground.\n    \"\"\"\n    dwd = dirty_working_directory()\n    if dwd is None:\n        color = '{BOLD_INTENSE_YELLOW}'\n    elif dwd:\n        color = '{BOLD_INTENSE_RED}'\n    else:\n        color = '{BOLD_INTENSE_GREEN}'\n    return color\n\n\ndef branch_bg_color():\n    \"\"\"Return red if the current branch is dirty, yellow if the dirtiness can\n    not be determined, and green if it clean. These are bacground colors.\n    \"\"\"\n    dwd = dirty_working_directory()\n    if dwd is None:\n        color = '{BACKGROUND_YELLOW}'\n    elif dwd:\n        color = '{BACKGROUND_RED}'\n    else:\n        color = '{BACKGROUND_GREEN}'\n    return color\n", "path": "xonsh/prompt/vc_branch.py"}]}