GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Repo.index.reset fails on windows · Issue #1630 · gitpython-developers/GitPython

Repo.index.reset fails on windows #1630

New issue
Copy link
New issue
Copy link
Closed
#1751
Closed
Repo.index.reset fails on windows#1630
#1751
Copy link
Labels
acknowledgedhelp wanted

Description

@suvayu
suvayu
opened on Aug 19, 2023
Issue body actions

How to reproduce

  1. clone any repo
  2. edit a tracked file
  3. in python, try to reset with
    Repo().index.reset(working_tree=True)
    You will get a stack trace.

Step by step recipe:

$ git clone https://github.com/gitpython-developers/GitPython git-python
$ cd git-python
$ python -m venv --prompt git venv
$ .\venv\Scirpts\Activate.ps1  # or whatever script is appropriate for you
$ rm pyproject.toml  # make any edit
$ git status -sb
## main...origin/main
 D pyproject.toml
$ python
>>> from git import Repo
>>> repo.index.reset(working_tree=True)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\<user>\code\git-python\git\index\util.py", line 103, in check_default_index
    return func(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\<user>\code\git-python\git\index\base.py", line 1320, in reset
    new_inst = type(self).from_tree(self.repo, commit)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\<user>\code\git-python\git\index\base.py", line 367, in from_tree
    repo.git.read_tree(*arg_list, **kwargs)
  File "C:\Users\<user>\code\git-python\git\cmd.py", line 739, in <lambda>
    return lambda *args, **kwargs: self._call_process(name, *args, **kwargs)
                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\user>\code\git-python\git\cmd.py", line 1312, in _call_process
    return self.execute(call, **exec_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\<user>\code\git-python\git\cmd.py", line 1107, in execute
    raise GitCommandError(redacted_command, status, stderr_value, stdout_value)
git.exc.GitCommandError: Cmd('git') failed due to: exit code(128)
  cmdline: git read-tree --index-output=C:\Users\<user>\code\git-python\.git\tmpxnmxtmmu HEAD
  stderr: 'fatal: unable to write new index file'

Expectation

I was expecting the result would be the equivalent of git reset --hard HEAD. Am I doing something incorrectly here? I'm unfamiliar with Windows, so it's quite possible.

Activity

  1. Byron
    added
    acknowledged
    on Aug 19, 2023
  2. Byron commented on Aug 19, 2023

    @Byron
    Byron
    on Aug 19, 2023
    Member
    More actions

    Maybe git itself is reading the index and GitPython fails to overwrite it shortly after. It's a known Windows filesystem issue.
    As a workaround, one should be able to use repo.git.reset(…) to invoke git directly, possibly after changing the index using GitPython.

  3. suvayu commented on Aug 20, 2023

    @suvayu
    suvayu
    on Aug 20, 2023
    Author
    More actions

    Thanks for the confirmation. For now I have worked around it with Repo.head.reset(working_tree=True) When I get some time, I'll experiment a bit and try to understand this better.

  4. Byron
    added
    help wanted
    on Sep 7, 2023
  5. EliahKagan
    added 6 commits that reference this issue on Nov 7, 2023

    Let subprocess write temp file on Windows

    b3c1810

    Let Windows subprocess open or rename onto temp file

    fbf3311

    Add xfail marks for IndexFile.from_tree failures

    765c971

    Add xfail marks for IndexFile.from_tree failures

    17dea66

    Add xfail marks for IndexFile.from_tree failures

    6e477e3

    Let Windows subprocess open or rename onto temp file

    15aed4e
  6. EliahKagan
    added 6 commits that reference this issue on Nov 29, 2023

    Revert "Add xfail marks for IndexFile.from_tree failures"

    8b1916a

    Let Windows subprocess open or rename onto temp file

    621ffa3

    Let Windows subprocess open or rename onto temp file

    6bbbc64

    Revert "Add xfail marks for IndexFile.from_tree failures"

    e359718

    Let Windows subprocess open or rename onto temp file

    0c8a916

    Let Windows subprocess open or rename onto temp file

    b12fd4a
  7. EliahKagan commented on Dec 1, 2023

    @EliahKagan
    EliahKagan
    on Dec 1, 2023
    Member
    More actions

    This happens because IndexFile.from_tree (used by IndexFile.reset) uses NamedTemporaryFile in a way that works on Unix-like systems but on Windows prevents git read-tree from overwriting the file by moving its own temporary file to its location. I've proposed a fix in #1751.

    Reacted by Sebastian Thiel
    Reacted by Suvayu Ali
  8. Byron
    closed this as completedin #1751on Dec 1, 2023
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

    acknowledgedhelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.