djl/vcprompt — pull request #37 by mbfisher (2012-12-21 08:14:32+00:00)
Title: Git untracked bug

Hi!

I recently switched from Ubuntu to Arch and have found what I think is a bug in vcprompt when running on Python 3. My system:

uname -a
Linux arthur 3.6.10-1-ARCH #1 SMP PREEMPT Tue Dec 11 09:40:17 CET 2012 x86_64 GNU/Linux

python --version
Python 3.3.0

vcprompt in PS1:
$( vcprompt --format=%u%a%m )

I'm entirely new to Python 3!

When working with git repositories I found that the untracked flag `?` was shown all the time, in all repositories, even when `git status` was clean. I found the section in the vcprompt script that handles the untracked flag for git:

507 # untracked files
508 if '%u' in options.format:
509 output, returncode = popen('git ls-files --other --exclude-standard')
510
511 if returncode == 0:
512 if output == '':
513 untracked = ''
514 else:
515 untracked = options.untracked

At line 510 I added a print statement for `output` and `returncode` so I could examine both and found that `output` is returned from `popen()` as a byte literal; `b''`. Therefore the comparison to an empty string literal `''` on line 512 was returning false all the time. Updating line 512 to compare `output` to an empty byte literal has fixed the bug for me.

I've tested my change on Python 2.7.3 with virtualenv and all is well - as far as i know Python 2 ignores the `b` prefix on strings.

I found 2 more instances of the string literal comparison; in the modified flag for Mercurial and the modified/untracked flag for Bazaar. I've not updated these to byte literal comparisons because I don't use either VCS and therefore can't test the change.

M