镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Diff objects not showing file changes #1504

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?

Activity

  1. Byron commented on Oct 28, 2022

    @Byron
    Member

    You could probably debug this by setting the GIT_PYTHON_TRACE environment variable.

    As I always have been confused by this API myself I wouldn't be able to tell what's wrong just by looking at it either, and it's definitely easy to get it wrong or to get unintended results.

    I will convert this into a discussion in case we get down to the source of the problem, or we create an issue from there once it's clear it's a bug.

  2. locked and limited conversation to collaborators on Oct 28, 2022
  3. converted this issue into a discussion #1506 on Oct 28, 2022
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