datalad / datalad-next

DataLad extension for new functionality and improved user experience
https://datalad.org
Other
6 stars 7 forks source link

Spurious modification reports from `next-status` #639

Closed mih closed 3 months ago

mih commented 4 months ago

Here is an example log of a bunch of command I ran within a few seconds:

(git st is actually an alias to datalad next-status -r mono)

❯ git st
 modified: src/linkml/ontology/datasets.yaml (file)
untracked: src/examples/datalad-dataset.jsonld
❯ git diff
❯ git diff
❯ git status
On branch bf-35
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        src/examples/datalad-dataset.jsonld

nothing added to commit but untracked files present (use "git add" to track)
❯ git diff
❯ git st
untracked: src/examples/datalad-dataset.jsonld

Something like this has happened more than once. The repository here is small, no annexed files (not even an annex at all). So this is not about smudge filters or anything in that direction. But clearly, the implementation in next-status suffers from something that is either fixed by time, or by calling git diff/status directly.

mih commented 4 months ago

Here is another one, seem the issues is "fixed" by an intermediate call to git diff (which reports an empty diff).

❯ git st
 modified: src/linkml/schemas/datalad-dataset-components.yaml (file)
untracked: src/examples/datalad-dataset.jsonld
❯ git st
 modified: src/linkml/schemas/datalad-dataset-components.yaml (file)
untracked: src/examples/datalad-dataset.jsonld
❯ git diff
❯ git st
untracked: src/examples/datalad-dataset.jsonld
mih commented 4 months ago

I have a situation now, where I have a file open in vim. The file is in a plain Git repo, tracked, and has no modifications wrt to the committed state.

After I save the file in vim, no modifications, just :write, I see this "wrong" report.

❯ datalad next-status
 modified: src/examples/dataset-version/DatasetVersionObject-penguins.yaml (file)

The cause for this report is that git diff-index shows it too!

❯ git diff-index HEAD
:100644 100644 03657a3bf83d09a48060228feed6a70237ef4600 0000000000000000000000000000000000000000 M      src/examples/dataset-version/DatasetVersionObject-penguins.yaml

As soon as I run git diff or git status it is gone, as soon as I save the file in vim again, it is back:

❯ git diff
❯ git diff-index HEAD
❯ git diff-index HEAD
:100644 100644 03657a3bf83d09a48060228feed6a70237ef4600 0000000000000000000000000000000000000000 M      src/examples/dataset-version/DatasetVersionObject-penguins.yaml
mih commented 3 months ago

https://stackoverflow.com/questions/34807971/why-does-git-diff-index-head-result-change-for-touched-files-after-git-diff-or-g has an explanation and possible mitigation strategy.

mih commented 3 months ago

But there is more to this issue. I can do the exact same action (open README.md file in vim, make no change, but write it out again) in two different repos. I get the modification report on one repo (clone of https://github.com/psychoinformatics-de/datalad-concepts), but not another (clone of https://github.com/datalad/datalad-next).