Skip to content

Adding a blob to an in-memory index modifies the working tree #2041

Open
@TBoshoven

Description

@TBoshoven

I'm not sure this is actually a bug: I might be misunderstanding something about the index functionality.
I'm trying to use a separate index for my operation so it is isolated from the state of the working tree.
Unfortunately, it appears that the current working tree is still changed.

If this is simply something I'm doing wrong, please let me know.

Reproduction steps:

  1. Initialize an empty repo, add a commit to have a head to work with
  2. Run the following:
import git, io, os
from gitdb.base import IStream

repo = git.Repo()
# Create a simple blob by hand for repro purposes
content_bytes = b"Test content"
istream = IStream(b'blob', len(content_bytes), io.BytesIO(content_bytes))
blob_binsha = repo.odb.store(istream).binsha
test_blob_obj = git.Blob(repo, blob_binsha, git.Blob.file_mode, "some/path.txt")

# Create a new index and add the blob
index = git.IndexFile.new(repo, repo.head.commit.tree)
index.add([test_blob_obj])  # This is the line that causes the issue
  1. Run git status

Expected results:

nothing to commit, working tree clean

Actual results:

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        new file:   some/path.txt

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        deleted:    some/path.txt

Environment:

  • Python 3.13.3
  • GitPython 3.1.44
  • git 2.49.0
  • Arch Linux

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