Skip to content

Commit

Permalink
Merge pull request #177 from pi-hole/fix/no_branch
Browse files Browse the repository at this point in the history
Fix for "(no branch)" output
  • Loading branch information
AzureMarker authored Dec 23, 2017
2 parents 6e45302 + 12a46e5 commit 2984ae4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
12 changes: 10 additions & 2 deletions args.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void parse_args(int argc, char* argv[])
if(strcmp(argv[i], "-v") == 0 ||
strcmp(argv[i], "version") == 0)
{
char version[] = GIT_VERSION;
const char * version = GIT_VERSION;
// Check if version is of format vX.YY
// '.' can never be part of a commit hash
if(strstr(version, ".") != NULL)
Expand All @@ -90,7 +90,15 @@ void parse_args(int argc, char* argv[])
if(strcmp(argv[i], "-b") == 0 ||
strcmp(argv[i], "branch") == 0)
{
printf("%s\n",GIT_BRANCH);
const char * branch = GIT_BRANCH;
const char * version = GIT_VERSION;
// Travis CI pulls on a tag basis, not by branch.
// Hence, it may happen that the master binary isn't aware of its branch.
// We check if this is the case and if there is a "vX.YY" like tag on the
// binary are print out branch "master" if we find that this is the case
if(strstr(branch, "(no branch)") != NULL && strstr(version, ".") != NULL)
branch = "master";
printf("%s\n",branch);
exit(EXIT_SUCCESS);
}

Expand Down
14 changes: 11 additions & 3 deletions request.c
Original file line number Diff line number Diff line change
Expand Up @@ -1038,11 +1038,19 @@ void getVersion(int *sock)
{
char server_message[SOCKETBUFFERLEN];

char version[] = GIT_VERSION;
const char * version = GIT_VERSION;
const char * branch = GIT_BRANCH;
// Travis CI pulls on a tag basis, not by branch.
// Hence, it may happen that the master binary isn't aware of its branch.
// We check if this is the case and if there is a "vX.YY" like tag on the
// binary are print out branch "master" if we find that this is the case
if(strstr(branch, "(no branch)") != NULL && strstr(version, ".") != NULL)
branch = "master";

if(strstr(version, ".") != NULL)
sprintf(server_message,"version %s\ntag %s\nbranch %s\ndate %s\n", GIT_VERSION, GIT_TAG, GIT_BRANCH, GIT_DATE);
sprintf(server_message,"version %s\ntag %s\nbranch %s\ndate %s\n", version, GIT_TAG, branch, GIT_DATE);
else
sprintf(server_message,"version vDev-%s\ntag %s\nbranch %s\ndate %s\n", GIT_HASH, GIT_TAG, GIT_BRANCH, GIT_DATE);
sprintf(server_message,"version vDev-%s\ntag %s\nbranch %s\ndate %s\n", GIT_HASH, GIT_TAG, branch, GIT_DATE);
swrite(server_message, *sock);

if(debugclients)
Expand Down

0 comments on commit 2984ae4

Please sign in to comment.