Skip to content

Diff fails on empty repository. #41

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
nemec opened this issue Jan 8, 2012 · 4 comments
Closed

Diff fails on empty repository. #41

nemec opened this issue Jan 8, 2012 · 4 comments

Comments

@nemec
Copy link

nemec commented Jan 8, 2012

If you have an empty repository (git init in an empty folder), then add files through GitPython, the repository isn't registered as "dirty" and diffs come back empty. For example:

>>> r = Repo('.')
>>> r.index.add(["README"])
>>> r.is_dirty
False
>>> r.index.diff(None)
[]

The index.entries property shows the newly added file, but there doesn't seem to be a way to turn it into "this file has been added, but not committed".

@fcelda
Copy link
Contributor

fcelda commented Mar 21, 2012

Actually, diff() works just fine. If you add some files into the index, you have to append staged (or cached) parameter to make diff to show the changes.

>>> r.index.diff(None, staged=True)
[<git.diff.Diff object at 0x2a86c80>]

But is_dirty() behaves inconsistently. It should indeed return False. My patch (1253036) fixes it. But I'm unable to run your nose tests and therefore I cannot update them. Hope this helps:

#!/usr/bin/python

import git
import os

os.system("rm -rf repo/")
r = git.Repo.init("repo")
os.system("echo foo > repo/foo")
os.system("echo bar > repo/bar")

assert not r.is_dirty()

r.index.add(["foo"])
assert r.is_dirty()

r.index.commit("foo messsage")
assert not r.is_dirty()

r.index.add(["bar"])
assert r.is_dirty()

@nemec
Copy link
Author

nemec commented Mar 22, 2012

Ah, I must have missed out on the staged keyword in the docs. Thanks.

maxyz pushed a commit to maxyz/GitPython that referenced this issue Sep 29, 2014
maxyz pushed a commit to maxyz/GitPython that referenced this issue Sep 29, 2014
Byron added a commit that referenced this issue Nov 14, 2014
Fix issue #41: repo.is_dirty() on empty repository with stashed files
Byron added a commit that referenced this issue Nov 14, 2014
Fix issue #41: repo.is_dirty() on empty repository with stashed files
@Byron Byron added this to the v0.3.5 - bugfixes milestone Nov 19, 2014
@Byron
Copy link
Member

Byron commented Nov 19, 2014

Even though plenty of work has been done on this already, there is no test-case yet to truly verify this works. It should be done when working on 0.3.5.

@Byron
Copy link
Member

Byron commented Jan 8, 2015

A lot of time has passed, and plenty of changes were applied to is_dirty(). Additionally, there are plenty of tests checking all aspects of it.
Therefore I believe this issue can be closed for now.

@Byron Byron closed this as completed Jan 8, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants