Skip to content

LLM suggests git rm for emptied but tracked file (should be git add) #1

@gr33kurious

Description

@gr33kurious

Summary

When a tracked text file is manually emptied (all lines deleted, file remains present on disk), gitmeup suggests removing the file with git rm and a "Remove " commit, instead of treating this as a normal modification and suggesting git add.

Environment

  • OS: Ubuntu 22.04 (WSL)
  • Python: 3.10
  • gitmeup: 1.0.1 (installed via pip install gitmeup)
  • Git: 2.x
  • Repository: regular Git repo, nothing special about the file

Steps to reproduce

  1. Start from a clean working tree:

    git status
    # On branch main
    # nothing to commit, working tree clean
  2. Open a tracked text file and delete all its contents, leaving the file empty.
    Example:

    $ ls data/some.txt
    # file exists and is tracked
  3. Confirm Git sees it as modified, not deleted:

    git status --short
     M data/some.txt
  4. Run gitmeup:

    gitmeup

Actual behaviour

gitmeup proposes to remove the file:

Proposed commands:

git rm data/some.txt
git commit -m 'chore: Remove some.txt'

When running with --apply:

+ git rm data/some.txt
error: the following file has local modifications:
    data/some.txt
(use --cached to keep the file, or -f to force removal)
Command failed with exit code 1. Aborting.

Git correctly refuses to remove the file because it is a modified tracked file, not a deleted one.

If I manually stage the file:

git add data/some.txt
gitmeup --apply

then gitmeup proposes a normal update commit:

Proposed commands:

git add data/some.txt
git commit -m 'chore: Emptied some.txt file'

and the resulting commit is:

1 file changed, 124 deletions(-)
rewrite data/some.txt (100%)

Expected behaviour

For a file that:

  • still exists on disk, and
  • is reported as M data/some.txt in git status --short, and
  • has a diff consisting only of deletions,

gitmeup should:

  • treat it as a modified file, and
  • propose git add data/some.txt and an "Update" commit, not git rm and a "Remove" commit.

Only files that are actually deleted ( D path in git status --short) should be candidates for git rm.

Notes

This looks like the LLM misclassifying a "100 % deletions" diff as a file removal. A small guard based on git status --short in the executor (or a stronger instruction in the system prompt) would probably be enough to prevent git rm from ever being suggested/executed for files that Git itself still treats as modified rather than deleted.

Metadata

Metadata

Assignees

Labels

area:cliCLI UX, flags, help text, exit codesarea:prompt-enginePrompt design, model behaviour, output qualitypriority:highUrgent, breaks core flows or many usersstatus:confirmedReproduced and accepted as validtype:bugActual defects in behaviour

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions