Merge branch 'jh/status-no-ahead-behind'

"git status" can spend a lot of cycles to compute the relation
between the current branch and its upstream, which can now be
disabled with "--no-ahead-behind" option.

* jh/status-no-ahead-behind:
  status: support --no-ahead-behind in long format
  status: update short status to respect --no-ahead-behind
  status: add --[no-]ahead-behind to status and commit for V2 format.
  stat_tracking_info: return +1 when branches not equal
This commit is contained in:
Junio C Hamano
2018-03-08 12:36:24 -08:00
10 changed files with 196 additions and 35 deletions

View File

@ -146,6 +146,48 @@ test_expect_success 'status -s -b (diverged from upstream)' '
test_i18ncmp expect actual
'
cat >expect <<\EOF
## b1...origin/master [different]
EOF
test_expect_success 'status -s -b --no-ahead-behind (diverged from upstream)' '
(
cd test &&
git checkout b1 >/dev/null &&
git status -s -b --no-ahead-behind | head -1
) >actual &&
test_i18ncmp expect actual
'
cat >expect <<\EOF
On branch b1
Your branch and 'origin/master' have diverged,
and have 1 and 1 different commits each, respectively.
EOF
test_expect_success 'status --long --branch' '
(
cd test &&
git checkout b1 >/dev/null &&
git status --long -b | head -3
) >actual &&
test_i18ncmp expect actual
'
cat >expect <<\EOF
On branch b1
Your branch and 'origin/master' refer to different commits.
EOF
test_expect_success 'status --long --branch --no-ahead-behind' '
(
cd test &&
git checkout b1 >/dev/null &&
git status --long -b --no-ahead-behind | head -2
) >actual &&
test_i18ncmp expect actual
'
cat >expect <<\EOF
## b5...brokenbase [gone]
EOF

View File

@ -390,6 +390,68 @@ test_expect_success 'verify upstream fields in branch header' '
)
'
test_expect_success 'verify --[no-]ahead-behind with V2 format' '
git checkout master &&
test_when_finished "rm -rf sub_repo" &&
git clone . sub_repo &&
(
## Confirm local master tracks remote master.
cd sub_repo &&
HUF=$(git rev-parse HEAD) &&
# Confirm --no-ahead-behind reports traditional branch.ab with 0/0 for equal branches.
cat >expect <<-EOF &&
# branch.oid $HUF
# branch.head master
# branch.upstream origin/master
# branch.ab +0 -0
EOF
git status --no-ahead-behind --porcelain=v2 --branch --untracked-files=all >actual &&
test_cmp expect actual &&
# Confirm --ahead-behind reports traditional branch.ab with 0/0.
cat >expect <<-EOF &&
# branch.oid $HUF
# branch.head master
# branch.upstream origin/master
# branch.ab +0 -0
EOF
git status --ahead-behind --porcelain=v2 --branch --untracked-files=all >actual &&
test_cmp expect actual &&
## Test non-equal ahead/behind.
echo xyz >file_xyz &&
git add file_xyz &&
git commit -m xyz &&
HUF=$(git rev-parse HEAD) &&
# Confirm --no-ahead-behind reports branch.ab with ?/? for non-equal branches.
cat >expect <<-EOF &&
# branch.oid $HUF
# branch.head master
# branch.upstream origin/master
# branch.ab +? -?
EOF
git status --no-ahead-behind --porcelain=v2 --branch --untracked-files=all >actual &&
test_cmp expect actual &&
# Confirm --ahead-behind reports traditional branch.ab with 1/0.
cat >expect <<-EOF &&
# branch.oid $HUF
# branch.head master
# branch.upstream origin/master
# branch.ab +1 -0
EOF
git status --ahead-behind --porcelain=v2 --branch --untracked-files=all >actual &&
test_cmp expect actual
)
'
test_expect_success 'create and add submodule, submodule appears clean (A. S...)' '
git checkout master &&
git clone . sub_repo &&