Skip to content
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

ProcessException on change file if only mode changes #227

Open
Patrick-Beuks opened this issue Jan 5, 2025 · 2 comments · May be fixed by #229
Open

ProcessException on change file if only mode changes #227

Patrick-Beuks opened this issue Jan 5, 2025 · 2 comments · May be fixed by #229

Comments

@Patrick-Beuks
Copy link
Contributor

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}
  }
@Patrick-Beuks
Copy link
Contributor Author

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

@Patrick-Beuks
Copy link
Contributor Author

Patrick-Beuks commented Jan 5, 2025

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant