Created
January 26, 2011 14:55
-
-
Save hugowetterberg/796784 to your computer and use it in GitHub Desktop.
Reading the reference from HEAD in a git repo at path
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(NSString*)currentBranch { | |
const char *refAnfang = "ref: "; | |
NSString *branch; | |
const char *filename = [[path stringByAppendingPathComponent:@"HEAD"] cStringUsingEncoding:NSUTF8StringEncoding]; | |
FILE *file = fopen (filename, "r"); | |
if (file != NULL) { | |
char line [256]; | |
if (fgets(line, sizeof line, file) != NULL) { | |
line[strlen(line)-1] = 0; | |
if (strncmp(refAnfang, line, 5) == 0) { | |
const char *reference = line + 5; | |
branch = [NSString stringWithCString:reference encoding:NSUTF8StringEncoding]; | |
} | |
} | |
fclose(file); | |
} | |
return branch; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment