-
-
Notifications
You must be signed in to change notification settings - Fork 368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Git status reports "unmodified" when an integer in a file is changed #1245
Comments
We found that if you manually run async function main () {
const dir = './demo'
strictEqual(await status({ fs, dir, filepath: 'int.json' }), "*modified")
} and re-run This is probably because const { clone, resetIndex, status } = require('isomorphic-git')
// ...
await pfs.writeFile(`${dir}/int.json`, JSON.stringify(int, null, 2) + '\n', 'utf-8')
await resetIndex({ fs, dir, filepath: 'int.json' }) // <----------
strictEqual(await status({ fs, dir, filepath: 'int.json' }), "*modified") // works |
Something else I noticed is if I run async function main () {
const dir = './demo'
strictEqual(await status({ fs, dir, filepath: 'int.json' }), "*modified")
} it passes as well. It still fails if I simply access the file with Perhaps I need to pass a particular |
I can confirm the issue. It may be hard to find the root cause. |
If you take the initial example and add a sleep of one second between the clone call and the update, then the example works: const { clone, status } = require("isomorphic-git");
const http = require("isomorphic-git/http/node");
const rimraf = require("rimraf");
const fs = require("fs");
const { strictEqual } = require("assert");
main().catch(console.error);
async function main() {
const dir = "./demo";
const pfs = fs.promises;
rimraf.sync(dir);
await pfs.mkdir(dir);
await clone({
fs,
http,
dir,
url: "https://github.com/alex996/git-int-test.git",
ref: "master",
});
let int = JSON.parse(await pfs.readFile(`${dir}/int.json`, "utf-8")); // 0
int++; // 1
await sleep(1000);
function sleep(ms) {
return new Promise((resolve) => {
setTimeout(resolve, ms);
});
}
await pfs.writeFile(
`${dir}/int.json`,
JSON.stringify(int, null, 2) + "\n",
"utf-8"
);
strictEqual(await status({ fs, dir, filepath: "int.json" }), "*modified");
} I think the root cause of the issue is the import { normalizeStats } from './normalizeStats.js'
export function compareStats(entry, stats) {
// Comparison based on the description in Paragraph 4 of
// https://www.kernel.org/pub/software/scm/git/docs/technical/racy-git.txt
const e = normalizeStats(entry)
const s = normalizeStats(stats)
const staleness =
e.mode !== s.mode ||
e.mtimeSeconds !== s.mtimeSeconds ||
e.ctimeSeconds !== s.ctimeSeconds ||
e.uid !== s.uid ||
e.gid !== s.gid ||
e.ino !== s.ino ||
e.size !== s.size
return staleness
} The comparison function uses seconds ( The other example above says that it works with a 2 digit integer. In this case the size changes, which is detected correctly by the comparison function. |
I think there needs to be a better way to know whether a file is modified. It can't rely on time solely. Perhaps some other data that is logically stepped. |
The normalizeStats function also returns:
This should be pecise enought to detect differeces. |
I think that canonical git don't check timestamp of the file only file content. So this will never be implemented. Unless you can find example of working with git where file timestamp affect the git repo. But OP code is different because content of the file changes. |
This is a link to the git-update-index description: https://github.com/git/git/blob/master/Documentation/git-update-index.txt In line 322 you can find: USING ``ASSUME UNCHANGED'' BITMany operations in Git depend on your filesystem to have an |
I have two questions: What do you mean with So this will never be implemented.? The current implementation relies on the timestamps. The What is OP code? |
I though, based on your comment, that you want to make status return modified when time of the file is changed. An OP code is Original Poster Code, which means code from the author of this issue. |
🎉 This issue has been resolved in version 1.24.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
The fix was invalid, Need to revert. |
Proper fix #1769 |
What's the status of this? |
@CMCDragonkai Do you want to contribute with a fix if you need this? |
Is this just a timing issue? We worked around with just a 1 ms delay. |
This is just a workaround, it will require debugging to find the root cause. Maybe some part of the code use setTimeout 0 or maybe there is some async function somewhere that is invoked in next tick. I would try to debug first and see what is actually happening. |
I'm running into an issue whereby if I change a single integer in a file,
git.status()
reports"unmodified"
when it should be"*modified"
. Here is a minimal repro:https://github.com/alex996/git-int-test/blob/master/int.json
0
index.js
When I run
node index.js
, I getHere are the deps in
package.json
Also here's my env:
Strangely enough, double-digit integers are registered correctly:
int = 10;
. I didn't notice this with strings, only integers so far.Initially, I ran into this with objects that had integer props, something like:
{ "int": 0 }
, hence the use of the JSON API.Any idea where the culprit might be? Thanks
The text was updated successfully, but these errors were encountered: