From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
"Matthieu Moy" <Matthieu.Moy@grenoble-inp.fr>,
"Jonathan Niedier" <jrnieder@gmail.com>,
"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH v2 4/4] branch: show more information when HEAD is detached
Date: Wed, 6 Mar 2013 19:21:22 +0700 [thread overview]
Message-ID: <1362572482-20570-5-git-send-email-pclouds@gmail.com> (raw)
In-Reply-To: <1362572482-20570-1-git-send-email-pclouds@gmail.com>
This prints more helpful info when HEAD is detached: is it detached
because of bisect or rebase? What is the original branch name in those
cases? Is it detached because the user checks out a remote ref or a
tag (and which one)?
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
builtin/branch.c | 25 ++++++++++++++++++++++++-
t/t3203-branch-output.sh | 6 +++---
t/t6030-bisect-porcelain.sh | 2 +-
3 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/builtin/branch.c b/builtin/branch.c
index 6371bf9..02dee0d 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -18,6 +18,7 @@
#include "string-list.h"
#include "column.h"
#include "utf8.h"
+#include "wt-status.h"
static const char * const builtin_branch_usage[] = {
N_("git branch [options] [-r | -a] [--merged | --no-merged]"),
@@ -550,6 +551,28 @@ static int calc_maxwidth(struct ref_list *refs)
return w;
}
+static char *get_head_description()
+{
+ struct strbuf desc = STRBUF_INIT;
+ struct wt_status_state state;
+ wt_status_get_state(&state, 1);
+ if (state.rebase_in_progress ||
+ state.rebase_interactive_in_progress)
+ strbuf_addf(&desc, _("(no branch, rebasing %s)"),
+ state.branch);
+ else if (state.bisect_in_progress)
+ strbuf_addf(&desc, _("(no branch, bisecting %s)"),
+ state.branch);
+ else if (state.detached_from)
+ strbuf_addf(&desc, _("(detached from %s)"),
+ state.detached_from);
+ else
+ strbuf_addstr(&desc, _("(no branch)"));
+ free(state.branch);
+ free(state.onto);
+ free(state.detached_from);
+ return strbuf_detach(&desc, NULL);
+}
static void show_detached(struct ref_list *ref_list)
{
@@ -557,7 +580,7 @@ static void show_detached(struct ref_list *ref_list)
if (head_commit && is_descendant_of(head_commit, ref_list->with_commit)) {
struct ref_item item;
- item.name = xstrdup(_("(no branch)"));
+ item.name = get_head_description();
item.width = utf8_strwidth(item.name);
item.kind = REF_LOCAL_BRANCH;
item.dest = NULL;
diff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh
index 76fe7e0..ba4f98e 100755
--- a/t/t3203-branch-output.sh
+++ b/t/t3203-branch-output.sh
@@ -94,13 +94,13 @@ test_expect_success 'git branch -v pattern does not show branch summaries' '
test_must_fail git branch -v branch*
'
-cat >expect <<'EOF'
-* (no branch)
+test_expect_success 'git branch shows detached HEAD properly' '
+ cat >expect <<EOF &&
+* (detached from $(git rev-parse --short HEAD^0))
branch-one
branch-two
master
EOF
-test_expect_success 'git branch shows detached HEAD properly' '
git checkout HEAD^0 &&
git branch >actual &&
test_i18ncmp expect actual
diff --git a/t/t6030-bisect-porcelain.sh b/t/t6030-bisect-porcelain.sh
index 3e0e15f..9b6f0d0 100755
--- a/t/t6030-bisect-porcelain.sh
+++ b/t/t6030-bisect-porcelain.sh
@@ -164,7 +164,7 @@ test_expect_success 'bisect start: existing ".git/BISECT_START" not modified if
cp .git/BISECT_START saved &&
test_must_fail git bisect start $HASH4 foo -- &&
git branch > branch.output &&
- test_i18ngrep "* (no branch)" branch.output > /dev/null &&
+ test_i18ngrep "* (no branch, bisecting other)" branch.output > /dev/null &&
test_cmp saved .git/BISECT_START
'
test_expect_success 'bisect start: no ".git/BISECT_START" if mistaken rev' '
--
1.8.1.2.536.gf441e6d
next prev parent reply other threads:[~2013-03-06 12:21 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-03 9:41 [PATCH 0/5] nd/branch-show-rebase-bisect-state updates Nguyễn Thái Ngọc Duy
2013-03-03 9:41 ` [PATCH 1/5] checkout: record full target ref in reflog Nguyễn Thái Ngọc Duy
2013-03-03 9:41 ` [PATCH 2/5] wt-status: split wt_status_state parsing function out Nguyễn Thái Ngọc Duy
2013-03-03 9:41 ` [PATCH 3/5] wt-status: move wt_status_get_state() out to wt_status_print() Nguyễn Thái Ngọc Duy
2013-03-03 9:41 ` [PATCH 4/5] status: show the ref that is checked out, even if it's detached Nguyễn Thái Ngọc Duy
2013-03-03 22:25 ` Junio C Hamano
2013-03-04 12:17 ` Duy Nguyen
2013-03-04 15:49 ` Junio C Hamano
2013-03-05 11:39 ` Duy Nguyen
2013-03-05 12:18 ` Matthieu Moy
2013-03-03 9:41 ` [PATCH 5/5] branch: show more information when HEAD is detached Nguyễn Thái Ngọc Duy
2013-03-03 22:28 ` Junio C Hamano
2013-03-06 12:21 ` [PATCH v2 0/4] nd/branch-show-rebase-bisect-state updates Nguyễn Thái Ngọc Duy
2013-03-06 12:21 ` [PATCH v2 1/4] wt-status: split wt_status_state parsing function out Nguyễn Thái Ngọc Duy
2013-03-06 18:48 ` Junio C Hamano
2013-03-06 23:53 ` Junio C Hamano
2013-03-06 12:21 ` [PATCH v2 2/4] wt-status: move wt_status_get_state() out to wt_status_print() Nguyễn Thái Ngọc Duy
2013-03-06 12:21 ` [PATCH v2 3/4] status: show more info than "currently not on any branch" Nguyễn Thái Ngọc Duy
2013-03-06 19:16 ` Junio C Hamano
2013-03-08 11:04 ` Duy Nguyen
2013-03-08 21:46 ` Junio C Hamano
2013-03-06 12:21 ` Nguyễn Thái Ngọc Duy [this message]
2013-03-06 12:26 ` [PATCH v2 0/4] nd/branch-show-rebase-bisect-state updates Nguyễn Thái Ngọc Duy
2013-03-06 12:26 ` [PATCH v2+ 4/4] branch: show more information when HEAD is detached Nguyễn Thái Ngọc Duy
2013-03-13 11:42 ` [PATCH v3 0/5] nd/branch-show-rebase-bisect-state updates Nguyễn Thái Ngọc Duy
2013-03-13 11:42 ` [PATCH v3 1/5] wt-status: move strbuf into read_and_strip_branch() Nguyễn Thái Ngọc Duy
2013-03-13 16:20 ` Junio C Hamano
2013-03-16 2:12 ` [PATCH v3+ " Nguyễn Thái Ngọc Duy
2013-03-13 11:42 ` [PATCH v3 2/5] wt-status: split wt_status_state parsing function out Nguyễn Thái Ngọc Duy
2013-03-13 11:42 ` [PATCH v3 3/5] wt-status: move wt_status_get_state() out to wt_status_print() Nguyễn Thái Ngọc Duy
2013-03-13 11:42 ` [PATCH v3 4/5] status: show more info than "currently not on any branch" Nguyễn Thái Ngọc Duy
2013-03-13 16:25 ` Junio C Hamano
2013-03-13 11:42 ` [PATCH v3 5/5] branch: show more information when HEAD is detached Nguyễn Thái Ngọc Duy
2013-03-19 18:37 ` [PATCH v3 0/5] nd/branch-show-rebase-bisect-state updates Junio C Hamano
2013-03-20 12:40 ` Duy Nguyen
2013-03-20 14:37 ` Junio C Hamano
2013-03-23 3:52 ` [PATCH] status, branch: fix the misleading "bisecting" message Nguyễn Thái Ngọc Duy
2013-03-24 5:30 ` Junio C Hamano
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=1362572482-20570-5-git-send-email-pclouds@gmail.com \
--to=pclouds@gmail.com \
--cc=Matthieu.Moy@grenoble-inp.fr \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@gmail.com \
/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).