kurttheviking / git-rev-sync-js Goto Github PK
View Code? Open in Web Editor NEWThis project forked from tblobaum/git-rev
Synchronously get the current git commit hash, tag, or branch
License: MIT License
This project forked from tblobaum/git-rev
Synchronously get the current git commit hash, tag, or branch
License: MIT License
TypeError: Cannot read properties of undefined (reading 'filename')
Node version v19.0.0
This could be an error relating to module system. I'm using ESM imports.
Please add a method to get the date of the current git version (date of last commit).
Similar to the output of:
git log --no-color -n 1 --pretty=format:"%ad" --date=format:"%FT%TZ"
Would be great.
;-)
Thanx. WOK.
Hi, we use your library in our webpack configuration file and we saw that the library shelljs
which you use deletes the env variable OLDPWD
which creates the error
ERROR in EnvironmentPlugin - OLDPWD environment variable is undefined.
You can pass an object with default values to suppress this warning.
See https://webpack.js.org/plugins/environment-plugin for example.
I also created an issue for shelljs.
Something like git diff-index --quiet HEAD --
Hi there, There is a function in this lib that returns the current tag, but is there a way to get the latest tag on current branch?
git describe --abbrev=0
Hi, thanks for this module. I've noticed you fiddle with files for getting the long hash, then get a substring of it to return the short version. This is not always correct because even if unlikely, it may happen that 2 different hashes have the same starting 7 characters.
If you check the documentation for "--short" you'll see that it always returns an unique value instead (if it is not, it will make the returned hash substring longer).
Please stick with the git commands, it is safer! ;)
I need my version number to be compiled into my app. I want it to reflect the latest tag, the number of commits since that tag, and whether the working copy is dirty.
This is how it is typically done:
git describe --tags --always --dirty
3.5.3-8-geb51d63-dirty
(I don't really care if the hash is there or not, so it could also be 3.5.3-8-dirty. But I need to know if the app was built off the actual commit that the tag is pointing to, or a later commit, which the -8 tells me.).
But when I run:
node
Welcome to Node.js v14.17.3.
Type ".help" for more information.
> var git = require('git-rev-sync');
> console.log(git.tag(true));
3.5.3
undefined
This plugin is only returning the tag name without the expected suffix.
I think the issue may be with the --abbrev=0
. The git documentation says: "An of 0 will suppress long format, only showing the closest tag."
git version 2.38.1.windows.1
I have some trouble with the isDirty function.
In one of my git projects I got always true returned. But the git status returns no changes.
I executed the git commands behind isDirty manually and got the same results:
git diff-index c7f53b57c5b8ea9a2e3c837a09bbef6dc668b561 . :100644 100644 e0de748c18601e6860e667b97c12b9de3212dfb2 0000000000000000000000000000000000000000 M recovery/downloadmanager/public/resources/version.json :100644 100644 a4bc9e8488bc52856ad6836643d4f06010ded752 0000000000000000000000000000000000000000 M recovery/downloadmanager/src/resources/password.json :100644 100644 e0de748c18601e6860e667b97c12b9de3212dfb2 0000000000000000000000000000000000000000 M recovery/downloadmanager/src/resources/version.json
but my git status show always:
developer@ubuntu:/data/ngc/recovery/downloadmanager$ git status On branch features/secure-image-file Your branch is up-to-date with 'origin/features/secure-image-file'. nothing to commit, working directory clean
Is there any idea to fix my issue?
When used in an empty git repository I get:
Module build failed: Error: ENOENT: no such file or directory, open '/home/daurnimator/myproject/.git/packed-refs'
at Object.fs.openSync (fs.js:663:18)
at Object.fs.readFileSync (fs.js:568:33)
at Object.long (/home/daurnimator/myproject/node_modules/git-rev-sync/index.js:109:31)
Request to add support to calculate the distance from current commit to latest tag
When running under Windows and there isn't an entry in .git/refs/heads
for this branch, invoking git-rev-sync
produces the following error:
ref = packfileRegex.exec(packfileContents)[1];
^
TypeError: Cannot read property '1' of null
at long (C:\TEST\node_modules\git-rev-sync\index.js:95:47)
Create a new directory (e.g. C:\TEST
as above), run git init
.
Add an .npignore
with the following contents:
/node_modules/
Add an index.js
with the following contents:
var grs = require('git-rev-sync');
console.log(grs.short());
Add the previous files and commit the initial commit.
Run npm install git-rev-sync
.
Now make a few branches: git branch aaa
, git branch bbb
.
node index.js
at this point should work.Run git pack-refs --all
(this deletes the refs from .git/refs/heads
and places them in the .git/packed-refs
).
Run node index.js
to observe the failure.
Tracking the error, it seems to be caused by this line:
var refToFind = path.join('refs', 'heads', b);
In Windows, path.join()
will produce the string refs\\heads\\BRANCH
- i.e. using backslashes!
Proposed solution: simply use Array.prototype.join
as:
var refToFind = ['refs', 'heads', b].join('/');
Hey! This is a neat library, especially since it works on partial Git repositories.
Just noticed that "detached" is misspelled in a few places: https://github.com/kurttheviking/git-rev-sync/blob/0dc18d8f474b067e6391fdd4db752e757154c0de/index.js#L75
I can do a PR for this but don't have the time right now.
Would be great to have a function that could return all the information in an object in one go, instead of having to call each of them separately
A common pattern in production environments is to put a bare git repository (see repo/
) outside the working directories (see releases/
) so you can deploy with minimal disruption of the live release:
current -> symlink to releases/3
repo/
releases/1/
releases/2/
releases/3/
releases/3/package.json
releases/3/node_modules
releases/3/config/environment.js
Which deploys with a command like:
git --work-tree=/path/to/releases/3/ --git-dir=/path/to/repo/ checkout $branch -f
Running git.short()
in the environment.js
I keep getting this error:
[git-rev-sync] no git repository found
I tried:
git.short('/absolute/path/to/repo/');
git.short('../repo/');
git.short('../../repo/');
...
Whatever I try, can't seem to grab the git repository.
Any ideas?
something like the results of
git describe --always --dirty
could be useful. Maybe have .tag append "dirty" on the end?
Command line output of git rev-parse --short HEAD
:
7b554a75
Output of require('git-rev-sync').short()
:
7b554a7
Can you please make .short()
length consistent with what git itself is reporting?
This way I cannot reconcile Sentry releases because a shorter hash is reported in my app than in the command line script that I use to create releases.
The up-to-date version of git return 8 symbols of hash with --short
flag.
git rev-parse --short HEAD
=> 7f2bf1a5
https://github.com/kurttheviking/git-rev-sync-js/blob/master/index.js#L118
Hi,
I am trying to use the specifiy short hash length of 8 to match git. But I get "Cannot read property 'join' of null" errors.
That using stuff like:
git.short(8)
git.short(null, 8)
I don't want to specify a different repo, just the exactly repo im in
Any Ideas?
Hi @kurttheviking ,
Please add the option --first-parent
to gitRevSync.tag()
describe command.
Option details is here
This option will return the tag which originated on the current branch, currently if I make a hotfix in the master and merge backwards in develop the hotfix tag will be returned by gitRevSync.tag()
instead of the dev tag.
Example:
Develop: 1.3.0-dev
Master: 1.2.1
After merge from master to develop. On develop branch the tag will be 1.2.1
I get this error when running my project:
E:\Work\instachain\node_modules\git-rev-sync\index.js:20
throw new Error('[git-rev-sync] failed to execute command: ' + result.stde
rr);
^
Error: [git-rev-sync] failed to execute command: fatal: Not a git repository (or
any of the parent directories): .git
at _command (E:\Work\instachain\node_modules\git-rev-sync\index.js:20:13)
at Object.tag (E:\Work\instachain\node_modules\git-rev-sync\index.js:130:10)
at Object.<anonymous> (E:/Work/instachain/webpack/dev.config.js:53:49)
at Module._compile (module.js:570:32)
at loader (E:\Work\instachain\node_modules\babel-register\lib\node.js:144:5)
at Object.require.extensions.(anonymous function) [as .js] (E:\Work\instacha
in\node_modules\babel-register\lib\node.js:154:7)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
I am using the latest version of git-rev-sync
Also my project directory is a git repository.
I have tried to solve this issue by changing versions of this library but still can't manage to get it to work.
Thanks for any support!!!
Hi,
git-rev-sync
has a dependency on shelljs
package version 0.8.4.
Snyk has identified this vulnerability : https://security.snyk.io/vuln/SNYK-JS-SHELLJS-2332187 and the fix is now available .
Remediation : Upgrade shelljs
package to version 0.8.5.
Would it possible to upgrade this package please
When you you have 2 repos: one is parent repo and one is submodule of parent repo this package doesn't work. It is because plugin always searches for .git folder. Working on submodule it doesn't work because submodule has .git FILE. This file tells where the actualy git folder is located for submodule.
If you want to demo this your self: do 2 repos. Make other submodule as parent module. Then try to use your package in submodule's folder. :) Tell me if you need more details
shelljs has been recently updated to avoid warnings when working with node v15.
Hi
I am using your library and last month I found.
[email protected] has a vulnerable dependencies issue and the fix come with [email protected]
-- [email protected]
-- [email protected]
-- [email protected]
-- [email protected]
-- [email protected]
Do you have a plan to update the library to use the latest version ?
Thanks in advance
Qaid
When running on windows and within a git worktree, running long() throws the following error
Error: ENOENT: no such file or directory, open 'E:\projects\chartiq\finsemble\finsemble-mono\.git\worktrees\my-test-app\packed-refs'
at Object.openSync (node:fs:585:3)
at Object.readFileSync (node:fs:453:35)
at Object.long (E:\projects\chartiq\finsemble\finsemble-mono-citrix\packages\api\node_modules\git-rev-sync\index.js:108:31)
This is due to assuming a forward slash directory separator to ignore the worktree directory. I've simply replaced double-backslashes with forward slashes in an incoming PR.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.