fix: get current branch name correctly

This commit is contained in:
Jozef Steinhübl 2024-08-03 21:24:20 +02:00
parent 67489a6c60
commit 9fa645fe69
No known key found for this signature in database
GPG key ID: E6BC90C91973B08F

View file

@ -20,20 +20,23 @@ char *get_current_branch_name() {
return NULL; return NULL;
} }
char *branch = fgets(output, sizeof(output), file_ptr); if (fgets(output, sizeof(output), file_ptr) == NULL) {
if (branch != NULL) { pclose(file_ptr);
// remove new line return NULL;
size_t len = strlen(branch);
if (len > 0 && branch[len - 1] == '\n') {
branch[len - 1] = '\0';
} }
// remove new line
size_t len = strlen(output);
if (len > 0 && output[len - 1] == '\n') {
output[len - 1] = '\0';
} }
pclose(file_ptr); pclose(file_ptr);
return branch; return strdup(output);
} }
int git_push(char *provider_name, char *branch_name, int options) { int git_push(char *provider_name, char *branch_name, int options) {
FILE *file_ptr; FILE *file_ptr;
char output[1024]; char output[1024];
@ -97,6 +100,7 @@ int cli_command_push(int argc, char **argv) {
printf("info: successfully pushed into '%s'.\n", provider->name); printf("info: successfully pushed into '%s'.\n", provider->name);
} }
free(branch_name);
config_free(cfg); config_free(cfg);
return 0; return 0;