简体   繁体   English

检查 repo 是否脏时出现 gitpython 错误

[英]gitpython error when checking if repo is dirty

I receive an error while trying to use gitpython to check if a repository is dirty, ie has uncommitted changed to tracked files:我在尝试使用gitpython检查存储库是否脏时收到错误,即未提交更改为跟踪文件:

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

The error:错误:

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:

How come?怎么来的? What could be the problem?可能是什么问题呢?
Notice I'm working on Windows 7 with msysgit请注意,我正在使用msysgit在 Windows 7 上工作

Considering the history of diff.py (which hasn't changed much), it is possible that the " git diff HEAD --cached ... " command fails for some reason in your repo.考虑到diff.py历史(它没有太大变化),“ git diff HEAD --cached ... ”命令在您的存储库中可能由于某种原因失败。
In other words, it is likely to be linked to your specific local repo than it is to be an implementation issue in the repo.is_dirty() method.换句话说,它可能链接到您的特定本地存储库,而不是repo.is_dirty()方法中的实现问题。

The surest way to debug it is to execute it directly and see what the error message is.调试它最可靠的方法是直接执行它并查看错误消息是什么。

Try Updating gitpython and msysgit.尝试更新 gitpython 和 msysgit。 When using GitPython0.3.2 and msysgit 1.7.9 --> repo.is_dirty() Returns an error.使用 GitPython0.3.2 和 msysgit 1.7.9 时 --> repo.is_dirty()返回错误。 When using GitPython 0.3.2 and msysgit 1.9.1 --> repo.is_dirty() returns a valid value.使用 GitPython 0.3.2 和 msysgit 1.9.1 时 --> repo.is_dirty()返回有效值。 Hope it helps.希望能帮助到你。

In my case I tried to run git in the command line, getting a more specific error:就我而言,我尝试在命令行中运行 git,得到一个更具体的错误:

>git diff HEAD --cached --abbrev=40 --full-index --raw
cannot spawn less: No such file or directory

I solved putting the bin folder of msysgit in path:我解决了将 msysgit 的 bin 文件夹放在路径中的问题:

>set PATH=C:\Program Files\Git\mingw64\bin;%PATH%

Note that I have also set the variable GIT_PYTHON_GIT_EXECUTABLE https://github.com/gitpython-developers/GitPython/issues/26 , but I don't think it's relative to this error请注意,我还设置了变量 GIT_PYTHON_GIT_EXECUTABLE https://github.com/gitpython-developers/GitPython/issues/26 ,但我认为这与此错误无关

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM