Gathering detailed insights and metrics for git-state
Gathering detailed insights and metrics for git-state
Gathering detailed insights and metrics for git-state
Gathering detailed insights and metrics for git-state
@types/git-state
TypeScript definitions for git-state
@jsg2021/git-state
Get the current state of any git repository
@git-stack/client-state
GraphQL for sample
npm-git-utils
A collection of node utility functions which help to automate the the process of committing and pushing NPM packages with git, updating dependency versions in package.json files, and viewing the git state of local repos
npm install git-state
Typescript
Module System
Min. Node Version
Node Version
NPM Version
82.5
Supply Chain
100
Quality
75.8
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
3,635,611
Last Day
1,242
Last Week
7,130
Last Month
28,197
Last Year
409,874
MIT License
43 Stars
81 Commits
12 Forks
4 Watchers
1 Branches
5 Contributors
Updated on Oct 27, 2024
Minified
Minified + Gzipped
Latest Version
4.1.0
Package Id
git-state@4.1.0
Size
5.78 kB
NPM Version
6.2.0
Node Version
10.8.0
Published on
Aug 15, 2018
Cumulative downloads
Total Downloads
Last Day
-15.3%
1,242
Compared to previous day
Last Week
3.4%
7,130
Compared to previous week
Last Month
4.6%
28,197
Compared to previous month
Last Year
-16.3%
409,874
Compared to previous year
1
Get the current state of any git repository.
npm install git-state --save
1var git = require('git-state') 2 3var path = '/path/to/git/repo' 4 5git.isGit(path, function (exists) { 6 if (!exists) return 7 8 git.check(path, function (err, result) { 9 if (err) throw err 10 console.log(result) // => { branch: 'master', 11 // ahead: 0, 12 // dirty: 9, 13 // untracked: 1, 14 // stashes: 0 } 15 }) 16})
isGit(path, callback)
Calls the callback
with a boolean which is either true
or false
depending on if the given path contains a git repository.
isGitSync(path)
Synchronous version of isGit()
which returns either true
or false
depending on if the given path contains a git repository.
check(path[, options], callback)
Will check the state of the git repository at the given path
and call
the callback
. The callback
will be called with two arguments: An
optional error object and a result object.
The result object contains the following properties:
branch
- The currently checked out branchahead
- The amount of commits the current branch is ahead of the
remote (may be NaN
if there for instance is no remote)dirty
- The number of dirty filesuntracked
- The number of untracked filesstashes
- The number of stored stashesSupports the following options
:
maxBuffer
- largest amount of data (in bytes) allowed on stdout or
stderr - if exceeded child process is killed (default: 200*1024
)checkSync(path[, options])
Synchronous version of check()
.
Can throw error. This typically happens if you are running a too old version of Node.js (< 0.12), if git isn't found or if the path isn't a git repository.
untracked(path[, options], callback)
Get the amount of untracked files in the git repository at the given
path
.
The callback
will be called with two arguments: An optional error
object and a number representing the amount of untracked files.
Supports the following options
:
maxBuffer
- largest amount of data (in bytes) allowed on stdout or
stderr - if exceeded child process is killed (default: 200*1024
)untrackedSync(path[, options])
Synchronous version of untracked()
.
Can throw error. This typically happens if you are running a too old version of Node.js (< 0.12), if git isn't found or if the path isn't a git repository.
dirty(path[, options], callback)
Get the amount of dirty files in the git repository at the given
path
.
The callback
will be called with two arguments: An optional error
object and a number representing the amount of dirty files.
Supports the following options
:
maxBuffer
- largest amount of data (in bytes) allowed on stdout or
stderr - if exceeded child process is killed (default: 200*1024
)dirtySync(path[, options])
Synchronous version of dirty()
.
Can throw error. This typically happens if you are running a too old version of Node.js (< 0.12), if git isn't found or if the path isn't a git repository.
branch(path[, options], callback)
Get the currently checked out branch in the git repository at the given
path
.
The callback
will be called with two arguments: An optional error
object and a string with the branch name.
If the branch name cannot be found, a falsy value will be returned.
Supports the following options
:
maxBuffer
- largest amount of data (in bytes) allowed on stdout or
stderr - if exceeded child process is killed (default: 200*1024
)branchSync(path[, options])
Synchronous version of branch()
. Returns null if no branch is set.
ahead(path[, options], callback)
Get the amount of commits the current branch in the git repository at
the given path
is ahead of its remote.
The callback
will be called with two arguments: An optional error
object and a number indicating the amount of commits the branch is ahead
of its remote.
If the number cannot be determined, NaN
will be returned instead.
Supports the following options
:
maxBuffer
- largest amount of data (in bytes) allowed on stdout or
stderr - if exceeded child process is killed (default: 200*1024
)aheadSync(path[, options])
Synchronous version of ahead()
.
If the number cannot be determined, NaN
will be returned instead.
commit(path[, options], callback)
Get the short-hash (e.g. 7b0a3ab
) for the latest commit at HEAD
in
the git repository at the given path
.
The callback
will be called with two arguments: An optional error
object and a string containing the short-hash.
Supports the following options
:
maxBuffer
- largest amount of data (in bytes) allowed on stdout or
stderr - if exceeded child process is killed (default: 200*1024
)commitSync(path[, options])
Synchronous version of commit()
.
Can throw error. This typically happens if you are running a too old version of Node.js (< 0.12), if git isn't found or if the path isn't a git repository.
stashes(path[, options], callback)
Get the amount of stashed changes in the git repository at the given
path
.
The callback
will be called with two arguments: An optional error
object and a number representing the amount of stashed changes.
Supports the following options
:
maxBuffer
- largest amount of data (in bytes) allowed on stdout or
stderr - if exceeded child process is killed (default: 200*1024
)stashesSync(path[, options])
Synchronous version of stashes()
.
Can throw error. This typically happens if you are running a too old version of Node.js (< 0.12), if git isn't found or if the path isn't a git repository.
message(path[, options], callback)
Get the commit message of the latest commit.
The callback
will be called with two arguments: An optional error
object and a string containing the commit message.
messageSync(path[, options])
Synchronous version of message()
.
Can throw error. This typically happens if you are running a too old version of Node.js (< 0.12), if git isn't found or if the path isn't a git repository.
Inside the bin
folder is a set of shell scripts which will perform the same checks as
the isGit()
and check()
functions, but just in pure bash. This
allows you for instance to modify your command prompt without having to
invoke node (which can be kind of slow if done at every request). In
fact this is exactly what the
git-ps1 module does for you.
bin/isgit
- exit code will be 0 if cwd is inside a git repo,
otherwise 1bin/ahead
- exit code will be 0 if result is 0
, otherwise 1bin/branch
- exit code will be 0 if result is master
, otherwise 1bin/dirty
- exit code will be 0 if result is 0
, otherwise 1bin/untracked
- exit code will be 0 if result is 0
, otherwise 1bin/stashes
- exit code will be 0 if result is 0
, otherwise 1bin/commit
- exit code will be 0 if a commit can be found, otherwise 1No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 2/27 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-02-03
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More