Skip to content

Instantly share code, notes, and snippets.

@kacf
Created June 30, 2015 06:45
Show Gist options
  • Save kacf/f004489185447a0e4433 to your computer and use it in GitHub Desktop.
Save kacf/f004489185447a0e4433 to your computer and use it in GitHub Desktop.
diff --git a/libpromises/generic_agent.c b/libpromises/generic_agent.c
index 0edd0c8..4957802 100644
--- a/libpromises/generic_agent.c
+++ b/libpromises/generic_agent.c
@@ -816,11 +816,11 @@ static bool GeneratePolicyReleaseIDFromGit(char *release_id_out,
{
char git_head[128];
int scanned = fscanf(git_file, "ref: %127s", git_head);
- fclose(git_file);
if (scanned == 1)
// Found HEAD Reference which means we are on a checked out branch
{
+ fclose(git_file);
snprintf(git_filename, PATH_MAX, "%s/.git/%s", policy_dir, git_head);
git_file = fopen(git_filename, "r");
Log(LOG_LEVEL_DEBUG, "Found a git HEAD ref");
@@ -829,14 +829,14 @@ static bool GeneratePolicyReleaseIDFromGit(char *release_id_out,
{
Log(LOG_LEVEL_DEBUG, "Unable to find HEAD ref in %s. Looking for commit", git_file);
assert(out_size > 40);
- git_file = fopen(git_filename, "r");
+ fseek(git_file, 0, SEEK_SET);
scanned = fscanf(git_file, "%40s", release_id_out);
fclose(git_file);
if (scanned == 1)
{
Log(LOG_LEVEL_DEBUG, "Found current git checkout pointing to %s", release_id_out);
- return scanned == 1;
+ return true;
}
else
// We didnt find a commit sha in .git/HEAD, so we assume the git information is invalid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment