git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Erik Faye-Lund <kusmabite@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, j.sixt@viscovery.net, schwab@linux-m68k.org
Subject: Re: [PATCH] checkout: do not corrupt HEAD on empty repo
Date: Tue, 8 May 2012 18:25:29 +0200	[thread overview]
Message-ID: <CABPQNSau5snkNLqsnBnsLVBVNKHXnvb8rsE8DbNfpo9__5uijA@mail.gmail.com> (raw)
In-Reply-To: <1336493114-4984-1-git-send-email-kusmabite@gmail.com>

On Tue, May 8, 2012 at 6:05 PM, Erik Faye-Lund <kusmabite@gmail.com> wrote:
> In abe1998 ("git checkout -b: allow switching out of an unborn
> branch"), a code-path overly-optimisticly assumed that a
> branch-name was specified. This is not always the case, and as
> a result a NULL-pointer was attempted printed to .git/HEAD.
>
> This could lead to at least two different failure modes:
>  1) The CRT formated the NULL-string as something useful (e.g
>    "(null)")
>  2) The CRT crasheed.
>
> Neither were very convenient for formatting a new HEAD-reference.
>
> To fix this, reintroduce some strictness so we only take this
> new codepath if a banch-name was specified.
>
> Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com>
> ---
>  builtin/checkout.c         |    2 +-
>  t/t2015-checkout-unborn.sh |   11 +++++++++++
>  2 files changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/builtin/checkout.c b/builtin/checkout.c
> index 23fc56d..35924d4 100644
> --- a/builtin/checkout.c
> +++ b/builtin/checkout.c
> @@ -1091,7 +1091,7 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
>        if (opts.writeout_stage)
>                die(_("--ours/--theirs is incompatible with switching branches."));
>
> -       if (!new.commit) {
> +       if (!new.commit && opts.new_branch) {
>                unsigned char rev[20];
>                int flag;
>
> diff --git a/t/t2015-checkout-unborn.sh b/t/t2015-checkout-unborn.sh
> index 6352b74..2fa9458 100755
> --- a/t/t2015-checkout-unborn.sh
> +++ b/t/t2015-checkout-unborn.sh
> @@ -46,4 +46,15 @@ test_expect_success 'checking out another branch from unborn state' '
>        test_cmp expect actual
>  '
>
> +test_expect_success 'checking out in a newly created repo' '
> +       test_create_repo empty &&
> +       (
> +               cd empty &&
> +               cat .git/HEAD >expect &&
> +               test_must_fail git checkout &&
> +               cat .git/HEAD >actual &&
> +               test_cmp expect actual
> +       )
> +'
> +
>  test_done

Hmh, this is needlessly cluttery. The following should cover it:

---
diff --git a/t/t2015-checkout-unborn.sh b/t/t2015-checkout-unborn.sh
index 2fa9458..b49fedf 100755
--- a/t/t2015-checkout-unborn.sh
+++ b/t/t2015-checkout-unborn.sh
@@ -50,10 +50,7 @@ test_expect_success 'checking out in a newly created repo' '
 	test_create_repo empty &&
 	(
 		cd empty &&
-		cat .git/HEAD >expect &&
-		test_must_fail git checkout &&
-		cat .git/HEAD >actual &&
-		test_cmp expect actual
+		test_must_fail git checkout
 	)
 '

  reply	other threads:[~2012-05-08 16:26 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-08 16:05 [PATCH] checkout: do not corrupt HEAD on empty repo Erik Faye-Lund
2012-05-08 16:25 ` Erik Faye-Lund [this message]
2012-05-08 16:43   ` Junio C Hamano
2012-05-08 16:52     ` Erik Faye-Lund
2012-05-08 17:13       ` Junio C Hamano
2012-05-08 16:29 ` Junio C Hamano
2012-05-08 16:35   ` Erik Faye-Lund
2012-05-08 16:41     ` Junio C Hamano
2012-05-08 16:43       ` Erik Faye-Lund
2012-05-08 17:33         ` Andreas Schwab

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CABPQNSau5snkNLqsnBnsLVBVNKHXnvb8rsE8DbNfpo9__5uijA@mail.gmail.com \
    --to=kusmabite@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j.sixt@viscovery.net \
    --cc=schwab@linux-m68k.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).