Dismiss
  • Scroll up
  • Toggle Theme
  • View as Mobile

git-er-done

git-er-done wraps common git-diff workflows into a JavaScript API for tooling that needs to understand what changed.

It is useful for CI scripts, release tooling, docs automation, monorepo checks, and any workflow that needs to react to modified, created, or deleted files.

Why it matters

Change detection is the foundation for smarter automation. Once a tool can answer what changed, it can decide what to test, build, document, publish, or skip.

README excerpt

Install

npm install git-er-done

Basic Usage

const { gitDetails } = require('git-er-done')

// Git commit ref / branch to check against. Default is 'master'
const GIT_COMMIT_REF = '9f63b23ec99e36a176d73909fc67a39dc3bd56b7'

gitDetails({
  base: GIT_COMMIT_REF,
  // Optional: specify working directory (defaults to process.cwd())
  // cwd: '/path/to/repo'
}).then((git) => {
  /* git data returns
  {
    fileMatch: [Function], <-- Lookup function
    modifiedFiles: [ Array of modified files ],
    createdFiles: [ Array of created files ],
    deletedFiles: [ Array of deleted files ],
    commits: [ Array of commits ],
    lastCommit: { Object with last commit info },
    linesOfCode: [AsyncFunction: linesOfCode],
    dir: String path to git repo
  }
  */

  if (git.modifiedFiles.length) {
    // Some files have changed
  }

  if (git.createdFiles.length) {
    // Some files have been created
  }

  if (git.deletedFiles.length) {
    // Some files have been deleted
  }
})

Getting Lines of Code Changed

const { gitDetails } = require('git-er-done')

const git = await gitDetails({
  base: 'main',
  head: 'feature-branch'
})

const totalLines = await git.linesOfCode()
console.log(`Total lines changed: ${totalLines}`)

Using fileMatch with Patterns

Use glob patterns to match specific files. You can also use negation patterns:

const { gitDetails } = require('git-er-done')

const git = await gitDetails({ base: 'main' })

// Simple pattern matching
const srcCode = git.fileMatch('src/**/*.js')
/* srcCode returns object with:
{
  modified: Boolean,
  modifiedFiles: Array,
  created: Boolean,
  createdFiles: Array,
  deleted: Boolean,
  deletedFiles: Array,
  edited: Boolean,
  editedFiles: Array
}
*/

if (srcCode.edited) {
  console.log('Source code has been edited')
  console.log('Modified files:', srcCode.modifiedFiles)
  console.log('Created files:', srcCode.createdFiles)
}

// Match with negation - find all JSON files except package.json
const jsonFiles = git.fileMatch('**/**.json', '!**/package.json')
if (jsonFiles.modified) {
  console.log('Non-package JSON files modified:', jsonFiles.modifiedFiles)
}
if (jsonFiles.created) {
  console.log('Non-package JSON files created:', jsonFiles.createdFiles)
}

// Check markdown files
const mdFiles = git.fileMatch('**/*.md')
if (mdFiles.edited) {
  // Do stuff because markdown files are changed
  console.log('All markdown changes:', mdFiles.editedFiles)
}