Skip to content

rename file got diff with change_type: R100 #563

Description

@Thrimbda

when I renamed file A to B like this

$ git mv A B
$ git status 
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

	modified:   .gitmodules
	renamed:    A -> B
	modified:   Cprogramming

but using gitpython in ipython3 I got this:

In [135]: repo.commit('HEAD~2').diff(repo.head.commit)
Out[135]: 
[<git.diff.Diff at 0x7fc52ab13730>,
 <git.diff.Diff at 0x7fc529943c80>,
 <git.diff.Diff at 0x7fc529943d90>,
 <git.diff.Diff at 0x7fc52994ec80>]

In [136]: repo.commit('HEAD~2').diff(repo.head.commit)[2].b_path
Out[136]: 'Cprogramming'

In [137]: repo.commit('HEAD~2').diff(repo.head.commit)[1].b_path
Out[137]: 'B'

In [138]: repo.commit('HEAD~2').diff(repo.head.commit)[1].change_type
Out[138]: 'R100'

is that normal or something went wrong?

Activity

  1. Byron commented on Dec 27, 2016

    @Byron
    Member

    Thanks for letting me know! This seems wrong, as if GitPython as mis-interpreted the information obtained from git.
    This issue could be fixed, provided that it can be reproduced with the latest version of GitPython.
    Do you think you can provide a bash and/or python script to do that?

  2. Thrimbda commented on Dec 27, 2016

    @Thrimbda
    Author

    OK here is the thing @Byron
    I'm using git version 2.7.4 and GitPython version 2.1.1

    test scripts:

    some_directory
    ├── gittest.py
    └── gittest.sh

    gittest.py:

    import git
    
    repo = git.Repo('.')
    print('\nchange_type=%s\n' % repo.commit('HEAD~1').diff(repo.head.commit)[0].change_type)

    gittest.sh:

    #!/bin/sh
    mkdir test
    cd test
    git init
    touch A
    git add .
    git commit -m "added A."
    git mv A B
    git status
    git add .
    git commit -m "renamed A to B"
    python3 ../gittest.py
    
    cd ..
    rm -rf test
    
    git --version
    pip3 list | grep Git

    output:

    $ sh gittest.sh 
    Initialized empty Git repository in /some_directory/test/.git/
    [master (root-commit) 9a12c82] added A.
     1 file changed, 0 insertions(+), 0 deletions(-)
     create mode 100644 A
    On branch master
    Changes to be committed:
      (use "git reset HEAD <file>..." to unstage)
    
    	renamed:    A -> B
    
    [master 43dd423] renamed A to B
     1 file changed, 0 insertions(+), 0 deletions(-)
     rename A => B (100%)
    
    change_type=R100
    
    git version 2.7.4
    DEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.
    GitPython (2.1.1)
  3. Byron commented on Dec 27, 2016

    @Byron
    Member

    Awesome! Thanks a lot for making it so easy to reproduce the issue!
    I will see if I can convert that into a unit-test and fix it.

  4. self-assigned this
    on Dec 27, 2016
  5. Thrimbda commented on Dec 27, 2016

    @Thrimbda
    Author

    glad to help :)

  6. removed their assignment
    on Jan 21, 2017
  7. moshezvi commented on May 10, 2017

    @moshezvi

    any news on this? it also happens with git 2.9.3.

  8. Byron commented on Jun 10, 2017

    @Byron
    Member

    @moshezvi Actually there is no progress and I don't see myself working on GitPython except for the most trivial maintenance tasks. Maybe you can take this issue on yourself, it should be relatively straightforward to create a unit-test to help fix it. Sorry for the bad news.

  9. LeResKP commented on Feb 27, 2018

    @LeResKP
    Contributor

    Hello @Byron, there were already a test with R100 as change_type in git/test/fixtures/diff_rename_raw

    I can propose you this commit: LeResKP@4beda47

    But before doing a pr I would like to store the score on the Diff object, any objection?
    Also after doing a man gitl-diff-tree on git 2.13.6 I saw there are some status change not supported:

        Possible status letters are:
       ·   A: addition of a file
       ·   C: copy of a file into a new one
       ·   D: deletion of a file
       ·   M: modification of the contents or mode of a file
       ·   R: renaming of a file
       ·   T: change in the type of the file
       ·   U: file is unmerged (you must complete the merge before it can be committed)
       ·   X: "unknown" change type (most probably a bug, please report it)
       Status letters C and R are always followed by a score (denoting the percentage of
       similarity between the source and target of the move or copy). Status letter M may be
       followed by a score (denoting the percentage of dissimilarity) for file rewrites.
    

    I would like to add C and T, I don't think we need to support U & X. Okay with you?

  10. Byron commented on Feb 27, 2018

    @Byron
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions