rejeep / git.el

An Elisp API for programmatically using Git
41 stars 5 forks source link

Use more sophisticated method to detect repo. #4

Open marcinant opened 10 years ago

marcinant commented 10 years ago

Just an idea and piece of oneliner I found 5 minutes ago:

git rev-parse --is-inside-work-tree

Returns true if dir is under git version control and false if it's not. IMHO this should be used by git-repo? instead of current solution.

rejeep commented 10 years ago

Yeah, that's probably better. We can also look at the exit code of the command. For example:

$ mkdir is-a-git-repo
$ cd is-a-git-repo
$ git rev-parse --is-inside-work-treex
fatal: Not a git repository (or any of the parent directories): .git
$ echo $?
128
$ git init
Initialized empty Git repository in /Users/rejeep/tmp/is-a-git-repo/.git/
$ git rev-parse --is-inside-work-treex
--is-inside-work-treex
$ echo $?
0