Re: Possible bug with branch names and case sensitivity

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Nov 19, 2011 at 3:08 PM, Gerd Knops <gerti@xxxxxxxxxx> 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@xxxxxxxxx>
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;
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]