Skip to content

Fails *silently* if color.diff is set to "always" #172

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
frozencemetery opened this issue Jul 16, 2014 · 3 comments
Closed

Fails *silently* if color.diff is set to "always" #172

frozencemetery opened this issue Jul 16, 2014 · 3 comments

Comments

@frozencemetery
Copy link

If one sets color.diff in ~/.gitconfig to "always", then GitPython will silently fail to produce diffs. It looks like this:

    $ python
    Python 2.7.5 (default, Jun 25 2014, 10:19:55)
    [GCC 4.8.2 20131212 (Red Hat 4.8.2-7)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import git
    >>> oldcstr = "2d018c40ff73373221bc6717bfea8ac29aff9bff"
    >>> newcstr = "aa901d68d53e686428d0c58e831f4b7c8b0de40e"
    >>> repo = git.Repo(".")
    >>> oldc = repo.commit(oldcstr)
    >>> newc = repo.commit(newcstr)
    >>> oldc.diff(newc, create_patch = True)
    []
    >>> oldc.diff(newc, create_patch = False)
    [<git.diff.Diff object at 0x7fad7fee5b18>]
    >>> oldc.diff(newc, create_patch = False)[0]
    <git.diff.Diff object at 0xc9d050>
    >>> oldc.diff(newc, create_patch = False)[0].diff
    ''
    >>> import os
    >>> os.popen("git diff %s %s" % (oldcstr, newcstr))
    <open file 'git diff 2d018c40ff73373221bc6717bfea8ac29aff9bff aa901d68d53e686428d0c58e831f4b7c8b0de40e', mode 'r' at 0xbfa930>
    >>> os.popen("git diff %s %s" % (oldcstr, newcstr)).read()
    '\x1b[1mdiff --git a/requirements.txt b/requirements.txt\x1b[m\n\x1b[1mindex 4e6c95b..7455a11 100644\x1b[m\n\x1b[1m--- a/requirements.txt\x1b[m\n\x1b[1m+++ b/requirements.txt\x1b[m\n\x1b[36m@@ -1,7 +1,7 @@\x1b[m\n pbr>=0.6,!=0.7,<1.0\x1b[m\n \x1b[m\n urwid\x1b[m\n\x1b[31m-sqlalchemy\x1b[m\n\x1b[32m+\x1b[m\x1b[32msqlalchemy>=0.9.4\x1b[m\n GitPython>=0.3.2.RC1\x1b[m\n python-dateutil\x1b[m\n requests\x1b[m\n'
    >>>

Setting color.diff to "true" instead fixes this. I think GitPython should at least warn in this case (it did get garbage information back from a git command, which should _not_ be silent failure). git diff also contains an option to explicitly disable color (--no-color or --color=never); it would be even better if GitPython could pass these.

@Byron
Copy link
Member

Byron commented Jul 17, 2014

Thanks for positing this !
I agree, passing options to git-diff would fix this issue once and for all.

Byron added a commit that referenced this issue Jul 17, 2014
See #172 for
more information
@Byron
Copy link
Member

Byron commented Jul 17, 2014

If you like you can try the latest version of [email protected] .
The fix was rather straightforward, but testing is a bit difficult in gp's current state.

@frozencemetery
Copy link
Author

The fix you posted is working for me, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants