diff options
author | Junio C Hamano <junkio@cox.net> | 2007-01-11 16:47:34 -0800 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2007-01-11 16:47:34 -0800 |
commit | c388761c153bc3e874e75f69ff77430164c038c4 (patch) | |
tree | caacf48f2cdb1878ec7f4fe03c957c6d482738b9 /path.c | |
parent | git-status: wording update to deal with deleted files. (diff) | |
parent | git-checkout: handle local changes sanely when detaching HEAD (diff) | |
download | tgif-c388761c153bc3e874e75f69ff77430164c038c4.tar.xz |
Merge branch 'jc/detached-head'
* jc/detached-head:
git-checkout: handle local changes sanely when detaching HEAD
git-checkout: safety check for detached HEAD checks existing refs
git-checkout: fix branch name output from the command
git-checkout: safety when coming back from the detached HEAD state.
git-checkout: rewording comments regarding detached HEAD.
git-checkout: do not warn detaching HEAD when it is already detached.
Detached HEAD (experimental)
git-branch: show detached HEAD
git-status: show detached HEAD
Diffstat (limited to 'path.c')
-rw-r--r-- | path.c | 26 |
1 files changed, 18 insertions, 8 deletions
@@ -90,10 +90,11 @@ int git_mkstemp(char *path, size_t len, const char *template) } -int validate_symref(const char *path) +int validate_headref(const char *path) { struct stat st; char *buf, buffer[256]; + unsigned char sha1[20]; int len, fd; if (lstat(path, &st) < 0) @@ -119,14 +120,23 @@ int validate_symref(const char *path) /* * Is it a symbolic ref? */ - if (len < 4 || memcmp("ref:", buffer, 4)) + if (len < 4) return -1; - buf = buffer + 4; - len -= 4; - while (len && isspace(*buf)) - buf++, len--; - if (len >= 5 && !memcmp("refs/", buf, 5)) + if (!memcmp("ref:", buffer, 4)) { + buf = buffer + 4; + len -= 4; + while (len && isspace(*buf)) + buf++, len--; + if (len >= 5 && !memcmp("refs/", buf, 5)) + return 0; + } + + /* + * Is this a detached HEAD? + */ + if (!get_sha1_hex(buffer, sha1)) return 0; + return -1; } @@ -241,7 +251,7 @@ char *enter_repo(char *path, int strict) return NULL; if (access("objects", X_OK) == 0 && access("refs", X_OK) == 0 && - validate_symref("HEAD") == 0) { + validate_headref("HEAD") == 0) { putenv("GIT_DIR=."); check_repository_format(); return path; |