Skip to content

Commit

Permalink
Merge branch 'nd/branch-show-rebase-bisect-state'
Browse files Browse the repository at this point in the history
Add a bit more information to "git status" during a rebase/bisect
session.

* nd/branch-show-rebase-bisect-state:
  status, branch: fix the misleading "bisecting" message
  branch: show more information when HEAD is detached
  status: show more info than "currently not on any branch"
  wt-status: move wt_status_get_state() out to wt_status_print()
  wt-status: split wt_status_state parsing function out
  wt-status: move strbuf into read_and_strip_branch()
  • Loading branch information
Junio C Hamano committed Apr 1, 2013
2 parents 6d37c16 + 6deab24 commit afc2e81
Show file tree
Hide file tree
Showing 7 changed files with 216 additions and 91 deletions.
26 changes: 25 additions & 1 deletion builtin/branch.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]"),
Expand Down Expand Up @@ -550,14 +551,37 @@ static int calc_maxwidth(struct ref_list *refs)
return w;
}

static char *get_head_description(void)
{
struct strbuf desc = STRBUF_INIT;
struct wt_status_state state;
memset(&state, 0, sizeof(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, bisect started on %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)
{
struct commit *head_commit = lookup_commit_reference_gently(head_sha1, 1);

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;
Expand Down
6 changes: 3 additions & 3 deletions t/t3203-branch-output.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion t/t6030-bisect-porcelain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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, bisect started on other)" branch.output > /dev/null &&
test_cmp saved .git/BISECT_START
'
test_expect_success 'bisect start: no ".git/BISECT_START" if mistaken rev' '
Expand Down
6 changes: 4 additions & 2 deletions t/t7406-submodule-update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,10 @@ test_expect_success 'submodule add properly re-creates deeper level submodules'

test_expect_success 'submodule update properly revives a moved submodule' '
(cd super &&
H=$(git rev-parse --short HEAD) &&
git commit -am "pre move" &&
git status >expect&&
H2=$(git rev-parse --short HEAD) &&
git status | sed "s/$H/XXX/" >expect &&
H=$(cd submodule2; git rev-parse HEAD) &&
git rm --cached submodule2 &&
rm -rf submodule2 &&
Expand All @@ -675,7 +677,7 @@ test_expect_success 'submodule update properly revives a moved submodule' '
git config -f .gitmodules submodule.submodule2.path "moved/sub module"
git commit -am "post move" &&
git submodule update &&
git status >actual &&
git status | sed "s/$H2/XXX/" >actual &&
test_cmp expect actual
)
'
Expand Down
54 changes: 34 additions & 20 deletions t/t7512-status-help.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ test_expect_success 'status when rebase in progress before resolving conflicts'
ONTO=$(git rev-parse --short HEAD^^) &&
test_must_fail git rebase HEAD^ --onto HEAD^^ &&
cat >expected <<-EOF &&
# Not currently on any branch.
# HEAD detached at $ONTO
# You are currently rebasing branch '\''rebase_conflicts'\'' on '\''$ONTO'\''.
# (fix conflicts and then run "git rebase --continue")
# (use "git rebase --skip" to skip this patch)
Expand All @@ -104,7 +104,7 @@ test_expect_success 'status when rebase in progress before rebase --continue' '
echo three >main.txt &&
git add main.txt &&
cat >expected <<-EOF &&
# Not currently on any branch.
# HEAD detached at $ONTO
# You are currently rebasing branch '\''rebase_conflicts'\'' on '\''$ONTO'\''.
# (all conflicts fixed: run "git rebase --continue")
#
Expand Down Expand Up @@ -136,7 +136,7 @@ test_expect_success 'status during rebase -i when conflicts unresolved' '
ONTO=$(git rev-parse --short rebase_i_conflicts) &&
test_must_fail git rebase -i rebase_i_conflicts &&
cat >expected <<-EOF &&
# Not currently on any branch.
# HEAD detached at $ONTO
# You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
# (fix conflicts and then run "git rebase --continue")
# (use "git rebase --skip" to skip this patch)
Expand All @@ -162,7 +162,7 @@ test_expect_success 'status during rebase -i after resolving conflicts' '
test_must_fail git rebase -i rebase_i_conflicts &&
git add main.txt &&
cat >expected <<-EOF &&
# Not currently on any branch.
# HEAD detached at $ONTO
# You are currently rebasing branch '\''rebase_i_conflicts_second'\'' on '\''$ONTO'\''.
# (all conflicts fixed: run "git rebase --continue")
#
Expand All @@ -188,9 +188,10 @@ test_expect_success 'status when rebasing -i in edit mode' '
export FAKE_LINES &&
test_when_finished "git rebase --abort" &&
ONTO=$(git rev-parse --short HEAD~2) &&
TGT=$(git rev-parse --short two_rebase_i) &&
git rebase -i HEAD~2 &&
cat >expected <<-EOF &&
# Not currently on any branch.
# HEAD detached from $TGT
# You are currently editing a commit while rebasing branch '\''rebase_i_edit'\'' on '\''$ONTO'\''.
# (use "git commit --amend" to amend the current commit)
# (use "git rebase --continue" once you are satisfied with your changes)
Expand All @@ -215,8 +216,9 @@ test_expect_success 'status when splitting a commit' '
ONTO=$(git rev-parse --short HEAD~3) &&
git rebase -i HEAD~3 &&
git reset HEAD^ &&
TGT=$(git rev-parse --short HEAD) &&
cat >expected <<-EOF &&
# Not currently on any branch.
# HEAD detached at $TGT
# You are currently splitting a commit while rebasing branch '\''split_commit'\'' on '\''$ONTO'\''.
# (Once your working directory is clean, run "git rebase --continue")
#
Expand Down Expand Up @@ -244,10 +246,11 @@ test_expect_success 'status after editing the last commit with --amend during a
export FAKE_LINES &&
test_when_finished "git rebase --abort" &&
ONTO=$(git rev-parse --short HEAD~3) &&
TGT=$(git rev-parse --short three_amend) &&
git rebase -i HEAD~3 &&
git commit --amend -m "foo" &&
cat >expected <<-EOF &&
# Not currently on any branch.
# HEAD detached from $TGT
# You are currently editing a commit while rebasing branch '\''amend_last'\'' on '\''$ONTO'\''.
# (use "git commit --amend" to amend the current commit)
# (use "git rebase --continue" once you are satisfied with your changes)
Expand Down Expand Up @@ -277,7 +280,7 @@ test_expect_success 'status: (continue first edit) second edit' '
git rebase -i HEAD~3 &&
git rebase --continue &&
cat >expected <<-EOF &&
# Not currently on any branch.
# HEAD detached from $ONTO
# You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
# (use "git commit --amend" to amend the current commit)
# (use "git rebase --continue" once you are satisfied with your changes)
Expand All @@ -299,7 +302,7 @@ test_expect_success 'status: (continue first edit) second edit and split' '
git rebase --continue &&
git reset HEAD^ &&
cat >expected <<-EOF &&
# Not currently on any branch.
# HEAD detached from $ONTO
# You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
# (Once your working directory is clean, run "git rebase --continue")
#
Expand All @@ -326,7 +329,7 @@ test_expect_success 'status: (continue first edit) second edit and amend' '
git rebase --continue &&
git commit --amend -m "foo" &&
cat >expected <<-EOF &&
# Not currently on any branch.
# HEAD detached from $ONTO
# You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
# (use "git commit --amend" to amend the current commit)
# (use "git rebase --continue" once you are satisfied with your changes)
Expand All @@ -348,7 +351,7 @@ test_expect_success 'status: (amend first edit) second edit' '
git commit --amend -m "a" &&
git rebase --continue &&
cat >expected <<-EOF &&
# Not currently on any branch.
# HEAD detached from $ONTO
# You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
# (use "git commit --amend" to amend the current commit)
# (use "git rebase --continue" once you are satisfied with your changes)
Expand All @@ -371,7 +374,7 @@ test_expect_success 'status: (amend first edit) second edit and split' '
git rebase --continue &&
git reset HEAD^ &&
cat >expected <<-EOF &&
# Not currently on any branch.
# HEAD detached from $ONTO
# You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
# (Once your working directory is clean, run "git rebase --continue")
#
Expand Down Expand Up @@ -399,7 +402,7 @@ test_expect_success 'status: (amend first edit) second edit and amend' '
git rebase --continue &&
git commit --amend -m "d" &&
cat >expected <<-EOF &&
# Not currently on any branch.
# HEAD detached from $ONTO
# You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
# (use "git commit --amend" to amend the current commit)
# (use "git rebase --continue" once you are satisfied with your changes)
Expand All @@ -423,7 +426,7 @@ test_expect_success 'status: (split first edit) second edit' '
git commit -m "e" &&
git rebase --continue &&
cat >expected <<-EOF &&
# Not currently on any branch.
# HEAD detached from $ONTO
# You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
# (use "git commit --amend" to amend the current commit)
# (use "git rebase --continue" once you are satisfied with your changes)
Expand All @@ -448,7 +451,7 @@ test_expect_success 'status: (split first edit) second edit and split' '
git rebase --continue &&
git reset HEAD^ &&
cat >expected <<-EOF &&
# Not currently on any branch.
# HEAD detached from $ONTO
# You are currently splitting a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
# (Once your working directory is clean, run "git rebase --continue")
#
Expand Down Expand Up @@ -478,7 +481,7 @@ test_expect_success 'status: (split first edit) second edit and amend' '
git rebase --continue &&
git commit --amend -m "h" &&
cat >expected <<-EOF &&
# Not currently on any branch.
# HEAD detached from $ONTO
# You are currently editing a commit while rebasing branch '\''several_edits'\'' on '\''$ONTO'\''.
# (use "git commit --amend" to amend the current commit)
# (use "git rebase --continue" once you are satisfied with your changes)
Expand Down Expand Up @@ -573,9 +576,10 @@ test_expect_success 'status when bisecting' '
git bisect start &&
git bisect bad &&
git bisect good one_bisect &&
cat >expected <<-\EOF &&
# Not currently on any branch.
# You are currently bisecting branch '\''bisect'\''.
TGT=$(git rev-parse --short two_bisect) &&
cat >expected <<-EOF &&
# HEAD detached at $TGT
# You are currently bisecting, started from branch '\''bisect'\''.
# (use "git bisect reset" to get back to the original branch)
#
nothing to commit (use -u to show untracked files)
Expand All @@ -597,7 +601,7 @@ test_expect_success 'status when rebase conflicts with statushints disabled' '
ONTO=$(git rev-parse --short HEAD^^) &&
test_must_fail git rebase HEAD^ --onto HEAD^^ &&
cat >expected <<-EOF &&
# Not currently on any branch.
# HEAD detached at $ONTO
# You are currently rebasing branch '\''statushints_disabled'\'' on '\''$ONTO'\''.
#
# Unmerged paths:
Expand Down Expand Up @@ -663,5 +667,15 @@ test_expect_success 'status when cherry-picking after resolving conflicts' '
test_i18ncmp expected actual
'

test_expect_success 'status showing detached from a tag' '
test_commit atag tagging &&
git checkout atag &&
cat >expected <<-\EOF
# HEAD detached at atag
nothing to commit (use -u to show untracked files)
EOF
git status --untracked-files=no >actual &&
test_i18ncmp expected actual
'

test_done
Loading

0 comments on commit afc2e81

Please sign in to comment.