Merge branch 'sk/status-short-branch-color-config'

The colors in which "git status --short --branch" showed the names
of the current branch and its remote-tracking branch are now
configurable.

* sk/status-short-branch-color-config:
  status: add color config slots for branch info in "--short --branch"
  status: fix missing newline when comment chars are disabled
This commit is contained in:
Junio C Hamano 2017-05-16 11:51:53 +09:00
commit 3900254bf2
5 changed files with 125 additions and 7 deletions

View File

@ -1137,7 +1137,10 @@ color.status.<slot>::
`untracked` (files which are not tracked by Git),
`branch` (the current branch),
`nobranch` (the color the 'no branch' warning is shown in, defaulting
to red), or
to red),
`localBranch` or `remoteBranch` (the local and remote branch names,
respectively, when branch and tracking information is displayed in the
status short-format), or
`unmerged` (files which have unmerged changes).
color.ui::

View File

@ -1263,6 +1263,10 @@ static int parse_status_slot(const char *slot)
return WT_STATUS_NOBRANCH;
if (!strcasecmp(slot, "unmerged"))
return WT_STATUS_UNMERGED;
if (!strcasecmp(slot, "localBranch"))
return WT_STATUS_LOCAL_BRANCH;
if (!strcasecmp(slot, "remoteBranch"))
return WT_STATUS_REMOTE_BRANCH;
return -1;
}

View File

@ -2387,7 +2387,9 @@ _git_config ()
color.status.added
color.status.changed
color.status.header
color.status.localBranch
color.status.nobranch
color.status.remoteBranch
color.status.unmerged
color.status.untracked
color.status.updated

View File

@ -32,6 +32,17 @@ test_expect_success 'commit -h in broken repository' '
test_i18ngrep "[Uu]sage" broken/usage
'
test_expect_success 'create upstream branch' '
git checkout -b upstream &&
test_commit upstream1 &&
test_commit upstream2 &&
# leave the first commit on master as root because several
# tests depend on this case; for our upstream we only
# care about commit counts anyway, so a totally divergent
# history is OK
git checkout --orphan master
'
test_expect_success 'setup' '
: >tracked &&
: >modified &&
@ -53,7 +64,9 @@ test_expect_success 'setup' '
echo 1 >dir1/modified &&
echo 2 >dir2/modified &&
echo 3 >dir2/added &&
git add dir2/added
git add dir2/added &&
git branch --set-upstream-to=upstream
'
test_expect_success 'status (1)' '
@ -75,6 +88,10 @@ EOF
test_expect_success 'status --column' '
cat >expect <<\EOF &&
# On branch master
# Your branch and '\''upstream'\'' have diverged,
# and have 1 and 2 different commits each, respectively.
# (use "git pull" to merge the remote branch into yours)
#
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
@ -105,6 +122,10 @@ test_expect_success 'status --column status.displayCommentPrefix=false' '
cat >expect <<\EOF
# On branch master
# Your branch and 'upstream' have diverged,
# and have 1 and 2 different commits each, respectively.
# (use "git pull" to merge the remote branch into yours)
#
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
@ -178,6 +199,9 @@ test_expect_success 'commit ignores status.displayCommentPrefix=false in COMMIT_
cat >expect <<\EOF
On branch master
Your branch and 'upstream' have diverged,
and have 1 and 2 different commits each, respectively.
Changes to be committed:
new file: dir2/added
@ -248,6 +272,10 @@ test_expect_success 'status with gitignore' '
cat >expect <<\EOF &&
On branch master
Your branch and '\''upstream'\'' have diverged,
and have 1 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
@ -313,6 +341,10 @@ test_expect_success 'status with gitignore (nothing untracked)' '
cat >expect <<\EOF &&
On branch master
Your branch and '\''upstream'\'' have diverged,
and have 1 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
@ -348,7 +380,7 @@ output*
EOF
cat >expect <<\EOF
## master
## master...upstream [ahead 1, behind 2]
M dir1/modified
A dir2/added
?? dir1/untracked
@ -382,6 +414,10 @@ test_expect_success 'setup dir3' '
test_expect_success 'status -uno' '
cat >expect <<EOF &&
On branch master
Your branch and '\''upstream'\'' have diverged,
and have 1 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
@ -408,6 +444,9 @@ test_expect_success 'status (status.showUntrackedFiles no)' '
test_expect_success 'status -uno (advice.statusHints false)' '
cat >expect <<EOF &&
On branch master
Your branch and '\''upstream'\'' have diverged,
and have 1 and 2 different commits each, respectively.
Changes to be committed:
new file: dir2/added
@ -439,6 +478,10 @@ test_expect_success 'status -s (status.showUntrackedFiles no)' '
test_expect_success 'status -unormal' '
cat >expect <<EOF &&
On branch master
Your branch and '\''upstream'\'' have diverged,
and have 1 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
@ -493,6 +536,10 @@ test_expect_success 'status -s (status.showUntrackedFiles normal)' '
test_expect_success 'status -uall' '
cat >expect <<EOF &&
On branch master
Your branch and '\''upstream'\'' have diverged,
and have 1 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
@ -552,6 +599,10 @@ test_expect_success 'status -s (status.showUntrackedFiles all)' '
test_expect_success 'status with relative paths' '
cat >expect <<\EOF &&
On branch master
Your branch and '\''upstream'\'' have diverged,
and have 1 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
@ -610,13 +661,19 @@ test_expect_success 'status --porcelain ignores relative paths setting' '
test_expect_success 'setup unique colors' '
git config status.color.untracked blue &&
git config status.color.branch green
git config status.color.branch green &&
git config status.color.localBranch yellow &&
git config status.color.remoteBranch cyan
'
test_expect_success 'status with color.ui' '
cat >expect <<\EOF &&
On branch <GREEN>master<RESET>
Your branch and '\''upstream'\'' have diverged,
and have 1 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
@ -675,7 +732,7 @@ test_expect_success 'status -s with color.status' '
'
cat >expect <<\EOF
## <GREEN>master<RESET>
## <YELLOW>master<RESET>...<CYAN>upstream<RESET> [ahead <YELLOW>1<RESET>, behind <CYAN>2<RESET>]
<RED>M<RESET> dir1/modified
<GREEN>A<RESET> dir2/added
<BLUE>??<RESET> dir1/untracked
@ -726,7 +783,7 @@ test_expect_success 'status --porcelain respects -b' '
git status --porcelain -b >output &&
{
echo "## master" &&
echo "## master...upstream [ahead 1, behind 2]" &&
cat expect
} >tmp &&
mv tmp expect &&
@ -739,6 +796,10 @@ test_expect_success 'status --porcelain respects -b' '
test_expect_success 'status without relative paths' '
cat >expect <<\EOF &&
On branch master
Your branch and '\''upstream'\'' have diverged,
and have 1 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
@ -785,6 +846,10 @@ test_expect_success 'status -s without relative paths' '
test_expect_success 'dry-run of partial commit excluding new file in index' '
cat >expect <<EOF &&
On branch master
Your branch and '\''upstream'\'' have diverged,
and have 1 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
@ -825,6 +890,10 @@ test_expect_success 'setup status submodule summary' '
test_expect_success 'status submodule summary is disabled by default' '
cat >expect <<EOF &&
On branch master
Your branch and '\''upstream'\'' have diverged,
and have 1 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
@ -881,6 +950,10 @@ head=$(cd sm && git rev-parse --short=7 --verify HEAD)
test_expect_success 'status submodule summary' '
cat >expect <<EOF &&
On branch master
Your branch and '\''upstream'\'' have diverged,
and have 1 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
@ -939,6 +1012,10 @@ test_expect_success 'status -s submodule summary' '
test_expect_success 'status submodule summary (clean submodule): commit' '
cat >expect <<EOF &&
On branch master
Your branch and '\''upstream'\'' have diverged,
and have 2 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
@ -985,6 +1062,10 @@ test_expect_success 'status -z implies porcelain' '
test_expect_success 'commit --dry-run submodule summary (--amend)' '
cat >expect <<EOF &&
On branch master
Your branch and '\''upstream'\'' have diverged,
and have 2 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
Changes to be committed:
(use "git reset HEAD^1 <file>..." to unstage)
@ -1038,6 +1119,10 @@ touch .gitmodules
test_expect_success '--ignore-submodules=untracked suppresses submodules with untracked content' '
cat > expect << EOF &&
On branch master
Your branch and '\''upstream'\'' have diverged,
and have 2 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
@ -1146,6 +1231,10 @@ test_expect_success '.git/config ignore=dirty suppresses submodules with modifie
test_expect_success "--ignore-submodules=untracked doesn't suppress submodules with modified content" '
cat > expect << EOF &&
On branch master
Your branch and '\''upstream'\'' have diverged,
and have 2 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
@ -1202,6 +1291,10 @@ head2=$(cd sm && git commit -q -m "2nd commit" foo && git rev-parse --short=7 --
test_expect_success "--ignore-submodules=untracked doesn't suppress submodule summary" '
cat > expect << EOF &&
On branch master
Your branch and '\''upstream'\'' have diverged,
and have 2 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
@ -1282,6 +1375,10 @@ test_expect_success ".git/config ignore=dirty doesn't suppress submodule summary
cat > expect << EOF
; On branch master
; Your branch and 'upstream' have diverged,
; and have 2 and 2 different commits each, respectively.
; (use "git pull" to merge the remote branch into yours)
;
; Changes to be committed:
; (use "git reset HEAD <file>..." to unstage)
;
@ -1329,6 +1426,10 @@ test_expect_success "status (core.commentchar with two chars with submodule summ
test_expect_success "--ignore-submodules=all suppresses submodule summary" '
cat > expect << EOF &&
On branch master
Your branch and '\''upstream'\'' have diverged,
and have 2 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
@ -1353,6 +1454,10 @@ EOF
test_expect_success '.gitmodules ignore=all suppresses unstaged submodule summary' '
cat > expect << EOF &&
On branch master
Your branch and '\''upstream'\'' have diverged,
and have 2 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
@ -1472,6 +1577,10 @@ test_expect_success 'git commit --dry-run will show a staged but ignored submodu
git add sm &&
cat >expect << EOF &&
On branch master
Your branch and '\''upstream'\'' have diverged,
and have 2 and 2 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)

View File

@ -1002,7 +1002,7 @@ static void wt_longstatus_print_tracking(struct wt_status *s)
color_fprintf_ln(s->fp, color(WT_STATUS_HEADER, s), "%c",
comment_line_char);
else
fputs("", s->fp);
fputs("\n", s->fp);
}
static int has_unmerged(struct wt_status *s)