mixu / gr

Multiple git repository management tool
http://mixu.net/gr/
674 stars 104 forks source link

Use `git rev-parse` to check path correctness #65

Closed bimlas closed 6 years ago

bimlas commented 7 years ago

Instead of check the existness of .git directory, use git rev-parse to check that req.path is in

The old method didn't worked with submodules more than one level deep in the repo. Besides this if the $GIT_DIR differs from .git (cannot find a real life example), then the old method fails to work.

Related to #54

It's using git rev-parse --show-prefix which drops error if executed outside of Git repository; prints the prefix ("the current directory relative to Git root") if executed from a subdirectory. The behaviour if equal for Git repo and submodule too.

Curently it's not working because I can't return true/false from exec, so I need help in making it usable.

Please be patient, it's my very first Node.js code and I'm beginner in Javascript too.

bimlas commented 7 years ago

Finally, it works as expected.

An example output (reformatted to be more readable):

$ gr git status --short --branch

Skipped ~/not-a-git-repo as it is not a Git repository.

in ~/git-repo
## master...origin/master

in ~/git-repo/submodule
## master...origin/master

Skipped ~/git-repo/more/than as it is not the root of Git repository or submodule.

in ~/git-repo/more/than/one/level/submodule
## master...origin/master
bimlas commented 7 years ago

@mixu, please review and merge if you agree.

mixu commented 6 years ago

thanks! sorry for the long delay in merging!

mixu commented 6 years ago

published on npm as v0.5.5