2021-02-21 22:39:58 -06:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2021-02-21 22:43:22 -06:00
|
|
|
#include "ep.h"
|
2021-02-21 22:39:58 -06:00
|
|
|
|
|
|
|
char *git_branch_name;
|
|
|
|
|
|
|
|
void *get_git_branch_name(void *arg)
|
|
|
|
{
|
|
|
|
FILE *f = popen("git rev-parse --abbrev-ref HEAD 2>/dev/null", "re");
|
|
|
|
if (!f) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *line = NULL;
|
|
|
|
size_t n = 0;
|
|
|
|
ssize_t l = getline(&line, &n, f);
|
|
|
|
|
|
|
|
if (!pclose(f)) {
|
|
|
|
/* if git exits with 0, we are in a repo */
|
|
|
|
|
|
|
|
if (l > 0) {
|
|
|
|
/* TODO: treat case where it reads HEAD */
|
|
|
|
line[l-1] = 0;
|
|
|
|
/* line ownserhip goes to outside this function */
|
|
|
|
git_branch_name = line;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|