Skip to content

Error on attempt to realize equivalent of "git add file.txt", when file.txt was removed  #1252

Description

@sofakingworld

Hello!

I'm a new user of Python and pygit2, I think I found some bug.

I'm trying to code the scripts from the code below using pygit2 and I'm having problems.

Bash code sample

➜  git init new
➜  cd new
➜  new git:(master) echo Hello > file.txt
➜  new git:(master) ✗ git add file.txt 
➜  new git:(master) ✗ git status
...
Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
	new file:   file.txt

➜  new git:(master) ✗ rm file.txt 
➜  new git:(master) ✗ git status
...
Changes to be committed:
	new file:   file.txt

Changes not staged for commit:
	deleted:    file.txt

➜  new git:(master) ✗ git add file.txt
➜  new git:(master) git status
...
nothing to commit (create/copy files and use "git add" to track)

pygit2 code sample (could be added into test/test_index.py)

def test_remove_tracked_file_and_stage_changes(testrepo):
    index = testrepo.index
    real_path_to_file = (testrepo.path.replace("/.git", "")) + '/hello.txt'

    os.remove(real_path_to_file)
    assert {'bye.txt': 128, 'hello.txt': 512} == testrepo.status()
    index.add('hello.txt')

Error

image

At the stage when I try to add a deleted file to the index (stage), the error is returned: file.txt' in stat: No such file or directory

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions