python - 检查repo是否脏时gitpython错误

标签 python windows git msysgit gitpython

我在尝试使用 gitpython 检查存储库是否脏时收到错误消息,即是否有未提交的更改跟踪文件:

import git
repo = git.Repo('')
print repo.is_dirty()

错误:

Traceback (most recent call last):
  File "C:\dev\my_prog\test.py", line 8, in <module>
    print repo.is_dirty()
  File "C:\Python27\lib\site-packages\gitpython-0.3.2.rc1-py2.7.egg\git\repo\base.py", line 502, in is_dirty
    len(self.git.diff('HEAD', '--cached', *default_args)):
  File "C:\Python27\lib\site-packages\gitpython-0.3.2.rc1-py2.7.egg\git\cmd.py", line 227, in <lambda>
    return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
  File "C:\Python27\lib\site-packages\gitpython-0.3.2.rc1-py2.7.egg\git\cmd.py", line 456, in _call_process
    return self.execute(call, **_kwargs)
  File "C:\Python27\lib\site-packages\gitpython-0.3.2.rc1-py2.7.egg\git\cmd.py", line 377, in execute
    raise GitCommandError(command, status, stderr_value)
git.exc.GitCommandError: 'git diff HEAD --cached --abbrev=40 --full-index --raw' returned exit status 1:

怎么会?可能是什么问题?
请注意,我正在使用 msysgit 在 Windows 7 上工作

最佳答案

考虑到 history of diff.py (变化不大),“git diff HEAD --cached ...”命令可能由于某种原因在您的存储库中失败。
换句话说,它很可能与您的特定本地存储库相关联,而不是 repo.is_dirty() 方法中的实现问题。

调试它最可靠的方法是直接执行它并查看错误消息是什么。

关于python - 检查repo是否脏时gitpython错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13683862/

相关文章:

python - users().messages().list() 似乎上限为 500 条消息

python - 在Thread中使用asyncio的问题

python - 在 Python 中以一种很好的方式从列表中访问类变量

python - 从命令行运行 Python

python - 如何使用 Python 找到 Windows 通用应用程序数据文件夹?

git - 无跟踪推送的用例

python - Python 中的线程安全警告

git - git 可以忽略特定行吗?

ruby-on-rails-3 - Rails 3 和 Git : two applications, 共享数据库

c++ - CredMartialCredentials 用户名提示(智能卡)