From: Junio C Hamano Date: Mon, 06 Feb 2012 02:08:54 GMT Subject: Re: Bug: "git checkout -b" should be allowed in empty repo Message-ID: <7vk440btmx.fsf@alter.siamese.dyndns.org> In-Reply-To: <7vobtcbtqa.fsf@alter.siamese.dyndns.org> Junio C Hamano writes: > The patch is made on maint-1.7.6 track for no good reason, so it may have > some merge conflicts around "resolve_ref()" vs "resolve_refdup()" if we > were to apply it on a more modern codebase, but the resolution should be > trivial. The resolution should look like this, just in case. diff --cc builtin/checkout.c index 5bf96ba,5894f40..41b9b34 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@@ -1079,5 -1102,16 +1092,16 @@@ int cmd_checkout(int argc, const char * if (opts.writeout_stage) die(_("--ours/--theirs is incompatible with switching branches.")); + if (!new.commit) { + unsigned char rev[20]; + int flag, status; - const char *old_ref = resolve_ref("HEAD", rev, 0, &flag); ++ char *old_ref = resolve_refdup("HEAD", rev, 0, &flag); + + if ((flag & REF_ISSYMREF) && is_null_sha1(rev)) { + status = switch_unborn_to_new_branch(&opts, old_ref); - free((char *)old_ref); ++ free(old_ref); + return status; + } + } return switch_branches(&opts, &new); }