checkout: make advice when reattaching the HEAD less loud

When switching away from a detached HEAD with "git checkout", we give a listing of the commits about to be lost, and then tell how to resurrect them since 8e2dc6a (commit: give final warning when reattaching HEAD to leave commits behind, 2011-02-18). This is a good safety measure for people who are not comfortable with the detached HEAD state, but the advice on how to keep the state you just left was given even to those who set advice.detachedHead to false. Keep the warning and informational commit listing, but honor the setting of advice.detachedHead to squelch the advice. Helped-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed May 24, 2011 at 10:08 UTC f807b3dcab9cafd76936d24936b8353f99b2ae6d
1 file changed +9 -6
builtin/checkout.c
+9 -6
@@ -634,14 +634,17 @@ static void suggest_reattach(struct commit *commit, struct rev_info *revs)
634 "Warning: you are leaving %d commit%s behind, "
635 "not connected to\n"
636 "any of your branches:\n\n"
637 - "%s\n"
638 - "If you want to keep them by creating a new branch, "
639 - "this may be a good time\nto do so with:\n\n"
640 - " git branch new_branch_name %s\n\n",
637 + "%s\n",
638 lost, ((1 < lost) ? "s" : ""),
642 - sb.buf,
643 - sha1_to_hex(commit->object.sha1));
639 + sb.buf);
640 strbuf_release(&sb);
641 +
642 + if (advice_detached_head)
643 + fprintf(stderr,
644 + "If you want to keep them by creating a new branch, "
645 + "this may be a good time\nto do so with:\n\n"
646 + " git branch new_branch_name %s\n\n",
647 + sha1_to_hex(commit->object.sha1));
648 }
649
650 /*