Skip to content

Git status reports "unmodified" when an integer in a file is changed #1245

@alex996

Description

@alex996

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

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 pfs.writeFile(`${dir}/int.json`, JSON.stringify(int, null, 2) + '\n', 'utf-8')

  strictEqual(await status({ fs, dir, filepath: 'int.json' }), "*modified")
}

When I run node index.js, I get

+ actual - expected

+ 'unmodified'
- '*modified'
    at main (/path/to/git-memdb-demo/index.js:27:3) {
  generatedMessage: true,
  code: 'ERR_ASSERTION',
  actual: 'unmodified',
  expected: '*modified',
  operator: 'strictEqual'
}

Here are the deps in package.json

"dependencies": {
  "isomorphic-git": "^1.7.8",
  "rimraf": "^3.0.2"
}

Also here's my env:

$ node -v
v14.13.1

$ npm -v
6.14.8

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.1 LTS
Release:	20.04
Codename:	focal

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions