git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] setup/rev-parse: allow HEAD to be spelled 'head'

From
Sam Vilain <sam.vilain@catalyst.net.nz>
Date
Oct 5, 2007, 03:09 UTC
Message-ID
<1191553750-25562-1-git-send-email-sam.vilain@catalyst.net.nz>

If the repository got mangled by FAT capitalization rules, then a ref such as "HEAD" will become "head" once it is back on a non-FAT FS. Check for this condition in resolve_refs and in the setup code.

Suggested-by: Francois Marier <francois@debian.org>
Signed-off-by: Sam Vilain <sam.vilain@catalyst.net.nz>
---
  This should probably help people putting their git repos on
  FAT USB sticks.
 refs.c  |   28 ++++++++++++++++++++++++----
 setup.c |    7 +++++--
 2 files changed, 29 insertions(+), 6 deletions(-)
diff --git a/refs.c b/refs.c
index 09a2c87..89ffb15 100644
--- a/refs.c
+++ b/refs.c
@@ -400,10 +400,30 @@ const char *resolve_ref(const char *ref, unsigned char *sha1, int reading, int *
 				}
 				list = list->next;
 			}
-			if (reading || errno != ENOENT)
-				return NULL;
-			hashclr(sha1);
-			return ref;
+			if (reading || errno != ENOENT) {
+				/*
+				 * Hack for FAT-mangled ref filenames
+				 */
+				if (strlen(ref) <= 8) {
+					char lc_name[9];
+					char* i;
+					strncpy(&lc_name, ref, 9);
+					for (i = lc_name; *i; i++) {
+						*i = tolower(*i);
+					}
+					path = git_path("%s", lc_name);
+					if (lstat(path, &st) < 0) {
+						return NULL;
+					}
+				}
+				else {
+					return NULL;
+				}
+			}
+			else {
+				hashclr(sha1);
+				return ref;
+			}
 		}
 
 		/* Follow "normalized" - ie "refs/.." symlinks by hand */
diff --git a/setup.c b/setup.c
index 06004f1..284d7b9 100644
--- a/setup.c
+++ b/setup.c
@@ -168,8 +168,11 @@ static int is_git_directory(const char *suspect)
 		return 0;
 
 	strcpy(path + len, "/HEAD");
-	if (validate_headref(path))
-		return 0;
+	if (validate_headref(path)) {
+		strcpy(path + len, "/head");
+		if (validate_headref(path))
+			return 0;
+	}
 
 	return 1;
 }
-- 
1.5.3.2.3.g2f2dcc-dirty
Next: Johannes Schindelin
Message 1 of 6 in “setup/rev-parse: allow HEAD to be spelled 'head'”
  1. setup/rev-parse: allow HEAD to be spelled 'head'Sam Vilain, Oct 5, 2007
  2. Johannes SchindelinOct 5, 2007
  3. Alex RiesenOct 5, 2007
  4. Sam VilainOct 6, 2007
  5. Johannes SchindelinOct 7, 2007
  6. Sam VilainOct 7, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.