Skip to content

ProcessException on change file if only mode changes #227

Closed

Description

@Patrick-Beuks

The code throws and ProcessException when trying to execute functions (getContent, isBinary) on a file diff if the diff does not contain an index. This can happen when only the mode changes.

Full error:

Error while running git command:
'git' '--git-dir' '<LOCAL_DIR>' 'cat-file' '-p' ""

fatal: Not a valid object name 

Diff file:

diff --git a/a.out b/a.out
old mode 100755
new mode 100644

Parsed diff file object:

[Gitonomy\Git\Diff\File](<LOCAL_DIR>/vendor/gitonomy/gitlib/src/Gitonomy/Git/Diff/File.php#L20) {#5962 ▼
    #oldName: "a.out"
    #newName: "a.out"
    #oldMode: "100755"
    #newMode: "100644"
    #oldIndex: ""
    #newIndex: ""
    #isBinary: false
    #changes: []
    #repository: [Gitonomy\Git\Repository](<LOCAL_DIR>/vendor/gitonomy/gitlib/src/Gitonomy/Git/Repository.php#L29) {#690}
  }

Activity

  1. Patrick-Beuks commented on Jan 5, 2025

    @Patrick-Beuks
    ContributorAuthor

    While disallowing getting content would be a solution, I would like to be able to get the contents of the file even if not changed

  2. Patrick-Beuks commented on Jan 5, 2025

    @Patrick-Beuks
    ContributorAuthor

    Having taken a look at the diff-tree command it is possible to get the index by adding --raw to https://github.com/gitonomy/gitlib/blob/main/src/Gitonomy/Git/Commit.php#L65

    This would give the following diff patch

    :100755 100644 d1af4b23d0cc9313e5b2d3ef2fb9696c94afaa81 d1af4b23d0cc9313e5b2d3ef2fb9696c94afaa81 M      a.out
    
    diff --git a/a.out b/a.out
    old mode 100755
    new mode 100644
    

    With all raw output at the top followed by an empty line.

    If this seems like a valid solution, let me know and I will implement it.

    This could even be made backwards compatible. But maybe get a deprication notice/warning that without raw it cannot always get the index. Giving errors when trying to get content.

  3. lyrixx commented on Jan 27, 2025

    @lyrixx
    Member

    Thanks for this bug report

    If this seems like a valid solution, let me know and I will implement it.

    Yes :) thanks

  4. Patrick-Beuks commented on Jan 29, 2025

    @Patrick-Beuks
    ContributorAuthor

    PR has been updated

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions