Created
September 19, 2016 00:12
-
-
Save mrh1997/a7f23599231fef236ec85bf48868165d to your computer and use it in GitHub Desktop.
reproduce-pygit2-differror
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import pygit2 | |
import tempfile | |
REPODIR = tempfile.mkdtemp() + '/errrepo' | |
repo = pygit2.init_repository(REPODIR) | |
# create invalid tree with empty dir | |
emptyTree = repo.TreeBuilder().write() | |
treeBuilder = repo.TreeBuilder() | |
treeBuilder.insert('EmptyDir', emptyTree, pygit2.GIT_FILEMODE_TREE) # <- OMIT THIS LINE AND EVERYTHING WORKS | |
treeBuilder.insert('datafile', repo.create_blob('data'), pygit2.GIT_FILEMODE_BLOB_EXECUTABLE) | |
invalidTreeId = treeBuilder.write() | |
commitId = repo.create_commit( | |
None, | |
pygit2.Signature('User', 'user@git', 0, 0), | |
pygit2.Signature('User', 'user@git', 0, 0), | |
'commit msg', | |
invalidTreeId, | |
[]) | |
diff = repo.diff(emptyTree.hex, commitId.hex) | |
pygit2diff = {p.delta.new_file.path for p in diff} | |
gitdiff = set(subprocess.check_output(['git', 'diff', '--name-only', emptyTree.hex, commitId.hex], cwd=REPODIR).splitlines()) | |
assert pygit2diff == gitdiff, '{!r} != {!r}'.format(pygit2diff, gitdiff) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment