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

Re: Possible bug with branch names and case sensitivity

From
Jay Soffian <jaysoffian@gmail.com>
Date
Nov 21, 2011, 19:18 UTC
Message-ID
<CAG+J_Dz6nK5fPhBRmoojmgYSv5OviN7pfgNKnRy9_9WmDS1_2w@mail.gmail.com>
In-Reply-To
<D144F6C9-C6A3-4516-BC88-B9EB50890EF4@bitart.com>
On Sat, Nov 19, 2011 at 3:08 PM, Gerd Knops <gerti@bitart.com> wrote:
> On Mac OS X with a case-insensitive file system (not sure if that matters) git get's confused with branch names that differ only in case.

This is true. The branch code assumes a case-sensitive filesystem. I started working on a fix, but it was more involved than I first thought it would be. See my local WIP commit below, apologies if gmail lines wraps it.

j.
commit dfa86073b7
Author: Jay Soffian <jaysoffian@gmail.com>
Date:   Thu Oct 6 14:51:15 2011 -0400
    Try not to confuse branch foo with branch Foo (WIP)
    This probably needs to canonicalize the branch name instead. Sigh.
diff --git a/builtin/checkout.c b/builtin/checkout.c
index a41c818a7c..0e7362345d 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -363,7 +363,7 @@ static void setup_branch_path(struct branch_info *branch)
 	struct strbuf buf = STRBUF_INIT;

 	strbuf_branchname(&buf, branch->name);
-	if (strcmp(buf.buf, branch->name))
+	if (strcmp_icase(buf.buf, branch->name))
 		branch->name = xstrdup(buf.buf);
 	strbuf_splice(&buf, 0, 0, "refs/heads/", 11);
 	branch->path = strbuf_detach(&buf, NULL);
@@ -523,7 +523,7 @@ static void record_checkout(const char *name,
const char *new_work_tree)
 	} else { /* release name if we reserved it */
 		struct branch *branch = branch_get(name);
 		if (branch->work_tree &&
-		    !strcmp(branch->work_tree, get_git_work_tree()))
+		    !strcmp_icase(branch->work_tree, get_git_work_tree()))
 			git_config_set(key.buf, "");
 	}
 	strbuf_release(&key);
@@ -567,7 +567,7 @@ static void update_refs_for_switch(struct
checkout_opts *opts,
 	strbuf_addf(&msg, "checkout: moving from %s to %s",
 		    old_desc ? old_desc : "(invalid)", new->name);

-	if (!strcmp(new->name, "HEAD") && !new->path && !opts->force_detach) {
+	if (!strcmp_icase(new->name, "HEAD") && !new->path && !opts->force_detach) {
 		/* Nothing to do. */
 	} else if (opts->force_detach || !new->path) {	/* No longer on any branch. */
 		update_ref(msg.buf, "HEAD", new->commit->object.sha1, NULL,
@@ -582,7 +582,7 @@ static void update_refs_for_switch(struct
checkout_opts *opts,
 	} else if (new->path) {	/* Switch branches. */
 		create_symref("HEAD", new->path, msg.buf);
 		if (!opts->quiet) {
-			if (old->path && !strcmp(new->path, old->path)) {
+			if (old->path && !strcmp_icase(new->path, old->path)) {
 				fprintf(stderr, _("Already on '%s'\n"),
 					new->name);
 			} else if (opts->new_branch) {
@@ -612,7 +612,7 @@ static void update_refs_for_switch(struct
checkout_opts *opts,
 	remove_branch_state();
 	strbuf_release(&msg);
 	if (!opts->quiet &&
-	    (new->path || (!opts->force_detach && !strcmp(new->name, "HEAD"))))
+	    (new->path || (!opts->force_detach && !strcmp_icase(new->name, "HEAD"))))
 		report_tracking(new);
 }

@@ -719,7 +719,7 @@ static void check_if_checked_out(struct
checkout_opts *opts, const char *name)
 {
 	struct branch *branch = branch_get(name);
 	if (branch->work_tree && strlen(branch->work_tree) &&
-	    strcmp(branch->work_tree, get_git_work_tree())) {
+	    strcmp_icase(branch->work_tree, get_git_work_tree())) {
 		if (opts->force)
 			warning(_("branch '%s' is currently checked out"
 				  " in '%s'"), name, branch->work_tree);
diff --git a/remote.c b/remote.c
index 283b2121bd..1fba1c7fa3 100644
--- a/remote.c
+++ b/remote.c
@@ -166,9 +166,9 @@ static struct branch *make_branch(const char *name, int len)
 	char *refname;

 	for (i = 0; i < branches_nr; i++) {
-		if (len ? (!strncmp(name, branches[i]->name, len) &&
+		if (len ? (!strncmp_icase(name, branches[i]->name, len) &&
 			   !branches[i]->name[len]) :
-		    !strcmp(name, branches[i]->name))
+		    !strcmp_icase(name, branches[i]->name))
 			return branches[i];
 	}

@@ -829,7 +829,7 @@ static int query_refspecs(struct refspec *refs,
int ref_count, struct refspec *q
 				query->force = refspec->force;
 				return 0;
 			}
-		} else if (!strcmp(needle, key)) {
+		} else if (!strcmp_icase(needle, key)) {
 			*result = xstrdup(value);
 			query->force = refspec->force;
 			return 0;
Previous: Gerd KnopsNext: Michael Haggerty
Message 2 of 11 in “Possible bug with branch names and case sensitivity”
  1. Gerd KnopsNov 19, 2011
  2. Jay SoffianNov 21, 2011
  3. Michael HaggertyNov 22, 2011
  4. Jay SoffianNov 22, 2011
  5. Michael HaggertyNov 23, 2011
  6. Ævar Arnfjörð BjarmasonNov 23, 2011
  7. Joshua JensenNov 23, 2011
  8. Junio C HamanoNov 22, 2011
  9. Michael HaggertyNov 23, 2011
  10. Junio C HamanoNov 23, 2011
  11. Junio C HamanoNov 22, 2011

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.