Skip to content

Diff objects not showing file changes #1504

@stacey-gammon

Description

@stacey-gammon

I am trying to use this library to get the file changes by looking at diff.diff, but it's not working, while running what I think is the same command via a subprocess, works.

Code:

    # Using this library
    uncommitted_diff = repo.index.diff(None, paths=paths)
    committed_diff = repo.index.diff(base[0], paths=paths)
    for diff in [*uncommitted_diff, *committed_diff]:
        print(f"diff: {diff.diff}")

 
   # Using subprocess and running git directly
    process1 = subprocess.exec(["git", "diff", paths], capture_output=True)
    process2 = subprocess.exec(["git", "diff", base[0].hexsha], capture_output=True)

    print("using subprocess:")
    print(process1.stdout.decode("utf-8"))subprocess
    print(process2.stdout.decode("utf-8"))

Output (with some omiting of info) is:

diff: 
using subprocess:

diff --git a******.py
index ******
--- a******.py
+++ b******.py
@@ -1,9 +1,11 @@
from pathlib import Path
-from typing import Any
+from typing import Any, Optional, Tuple, Union

.....

Any ideas what is going on here and why the two results are different?

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