Skip to content

Assertion Error when "diffing" index during cherry pick conflict. #323

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
Agecaf opened this issue Jul 21, 2015 · 3 comments
Closed

Assertion Error when "diffing" index during cherry pick conflict. #323

Agecaf opened this issue Jul 21, 2015 · 3 comments

Comments

@Agecaf
Copy link

Agecaf commented Jul 21, 2015

I am trying to use gitpython to make a tool for helping in cherry-picking. The "repo.git.cherry_pick('hexsha')" command works perfectly, but, when I want to check the files with conflicts via

repo.index.diff(None)

I get the following Assertion Error;

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\git\index\util.py", line 69, in check_default_index
    return func(self, *args, **kwargs)
  File "C:\Python27\lib\site-packages\git\index\base.py", line 1197, in diff
    return super(IndexFile, self).diff(other, paths, create_patch, **kwargs)
  File "C:\Python27\lib\site-packages\git\diff.py", line 109, in diff
    index = diff_method(self.repo, proc.stdout)
  File "C:\Python27\lib\site-packages\git\diff.py", line 391, in _index_from_raw_format
    new_file, deleted_file, rename_from, rename_to, '')
  File "C:\Python27\lib\site-packages\git\diff.py", line 226, in __init__
    assert self.a_mode
AssertionError

Similarly, when comparing with head,

repo.index.diff('HEAD')

I get a slightly different error (a_mode -> b_mode);

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\git\index\util.py", line 69, in check_default_index
    return func(self, *args, **kwargs)
  File "C:\Python27\lib\site-packages\git\index\base.py", line 1189, in diff
    return other.diff(self.Index, paths, create_patch, **kwargs)
  File "C:\Python27\lib\site-packages\git\diff.py", line 109, in diff
    index = diff_method(self.repo, proc.stdout)
  File "C:\Python27\lib\site-packages\git\diff.py", line 391, in _index_from_raw_format
    new_file, deleted_file, rename_from, rename_to, '')
  File "C:\Python27\lib\site-packages\git\diff.py", line 231, in __init__
    assert self.b_mode
AssertionError

I'll be using the items with status non 0 in the index as a workaround for now (there are three per item with conflict).

Just for completeness, "diffing" works perfectly fine when not in cherry-picking conflict resolution (I tested it in the same session as the one that produced the errors).

Regards,
Agecaf

@Byron Byron added this to the v1.0.2 - Fixes milestone Jul 21, 2015
@Byron
Copy link
Member

Byron commented Jul 21, 2015

Thanks for the report.

Which version of GitPython are you using (possibly via print(git.__version__)) ? In case it is 1.0.1 or later, it would be great if you could create a test-repository with just enough files to help reproducing the issue. Only then a fix would be possible.

@Agecaf
Copy link
Author

Agecaf commented Jul 22, 2015

Hello, I've checked the version and it is 1.0.1.

I made a very simple merge conflict; "Hello World!" is changed into "Hola World!" and "Hello Mundo!" in two different branches (master and topic).

Here's how the bug appears (I also show what my index looks like);

>>> import git
>>> git.__version__
'1.0.1'
>>> try:
...     git.cmd.Git('.').cherry_pick('1c3cc')
... except git.GitCommandError as err:
...     print(err.status)
...     print(err.stderr)
...
1
error: could not apply 1c3cc4f... Changed Hello
hint: after resolving the conflicts, mark the corrected paths
hint: with 'git add <paths>' or 'git rm <paths>'
hint: and commit the result with 'git commit'
>>> repo = git.Repo('.')
>>> for (stage, blob) in repo.index.iter_blobs():
...     print(stage)
...     print(blob.data_stream.read())
...
2
Hello Mundo!
1
Hello World!
3
Hola World!
>>> repo.index.diff(None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\git\index\util.py", line 69, in check_default_index
    return func(self, *args, **kwargs)
  File "C:\Python27\lib\site-packages\git\index\base.py", line 1197, in diff
    return super(IndexFile, self).diff(other, paths, create_patch, **kwargs)
  File "C:\Python27\lib\site-packages\git\diff.py", line 109, in diff
    index = diff_method(self.repo, proc.stdout)
  File "C:\Python27\lib\site-packages\git\diff.py", line 391, in _index_from_raw_format
    new_file, deleted_file, rename_from, rename_to, '')
  File "C:\Python27\lib\site-packages\git\diff.py", line 226, in __init__
    assert self.a_mode
AssertionError
>>> repo.index.diff('HEAD')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python27\lib\site-packages\git\index\util.py", line 69, in check_default_index
    return func(self, *args, **kwargs)
  File "C:\Python27\lib\site-packages\git\index\base.py", line 1189, in diff
    return other.diff(self.Index, paths, create_patch, **kwargs)
  File "C:\Python27\lib\site-packages\git\diff.py", line 109, in diff
    index = diff_method(self.repo, proc.stdout)
  File "C:\Python27\lib\site-packages\git\diff.py", line 391, in _index_from_raw_format
    new_file, deleted_file, rename_from, rename_to, '')
  File "C:\Python27\lib\site-packages\git\diff.py", line 231, in __init__
    assert self.b_mode
AssertionError
>>> repo.head.commit.diff(None)
[<git.diff.Diff object at 0x026BB9C0>]

As you can see, diffing HEAD with the working directory does work, just not comparisons with the index (which has three copies of each file, one for the common ancestor, one for 'ours' and one for 'theirs', with different stages).

Thanks,
Agecaf

@Byron
Copy link
Member

Byron commented Jul 30, 2015

You can watch the development stream on youtube.

GitPython #17 [issue 323 - a buggy assertion]

thumb

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