add support for submodules
This commit is contained in:
23
XD.c
23
XD.c
@@ -61,8 +61,9 @@ static int explain = 0;
|
|||||||
char
|
char
|
||||||
*find_git_repo()
|
*find_git_repo()
|
||||||
{
|
{
|
||||||
char path[PATH_MAX] = ".", *rpath;
|
char path[PATH_MAX] = ".", fstr[PATH_MAX], *rpath, *res;
|
||||||
struct stat s;
|
struct stat s;
|
||||||
|
FILE *f;
|
||||||
int i, c;
|
int i, c;
|
||||||
|
|
||||||
/* find the number of jumps to the root of the fs */
|
/* find the number of jumps to the root of the fs */
|
||||||
@@ -83,8 +84,26 @@ char
|
|||||||
strcat(path, "/.git");
|
strcat(path, "/.git");
|
||||||
|
|
||||||
/* if there seems to be a git directory return the directory it was found in */
|
/* if there seems to be a git directory return the directory it was found in */
|
||||||
if (stat(path, &s) == 0 && S_ISDIR(s.st_mode)) {
|
if (stat(path, &s) == 0) {
|
||||||
|
if (S_ISDIR(s.st_mode)) {
|
||||||
return realpath(path, NULL);
|
return realpath(path, NULL);
|
||||||
|
} else if (S_ISREG(s.st_mode)) {
|
||||||
|
/* we do some special magic here to check if we're in a submodule */
|
||||||
|
f = fopen(path, "r");
|
||||||
|
if (!f) {
|
||||||
|
L("fopen: %s", strerror(errno));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
res = fgets(fstr, PATH_MAX, f);
|
||||||
|
fclose(f);
|
||||||
|
if (!res) {
|
||||||
|
L("fgets: %s", strerror(errno));
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (strncmp(fstr, "gitdir: ", strlen("gitdir: ")) == 0) {
|
||||||
|
return realpath(strndup(fstr + strlen("gitdir: "), strlen(fstr + strlen("gitdir: ")) - 1), NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* reset contents of gpath, and go up a directory */
|
/* reset contents of gpath, and go up a directory */
|
||||||
|
Reference in New Issue
Block a user