2009-02-19 06:34:44 +03:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='git branch display tests'
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
test_expect_success 'make commits' '
|
|
|
|
echo content >file &&
|
|
|
|
git add file &&
|
|
|
|
git commit -m one &&
|
|
|
|
echo content >>file &&
|
|
|
|
git commit -a -m two
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'make branches' '
|
2010-10-31 04:46:54 +03:00
|
|
|
git branch branch-one &&
|
2009-02-19 06:34:44 +03:00
|
|
|
git branch branch-two HEAD^
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'make remote branches' '
|
2010-10-31 04:46:54 +03:00
|
|
|
git update-ref refs/remotes/origin/branch-one branch-one &&
|
|
|
|
git update-ref refs/remotes/origin/branch-two branch-two &&
|
2009-02-19 06:34:44 +03:00
|
|
|
git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/branch-one
|
|
|
|
'
|
|
|
|
|
|
|
|
cat >expect <<'EOF'
|
|
|
|
branch-one
|
|
|
|
branch-two
|
|
|
|
* master
|
|
|
|
EOF
|
|
|
|
test_expect_success 'git branch shows local branches' '
|
|
|
|
git branch >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2011-08-28 18:54:31 +04:00
|
|
|
test_expect_success 'git branch --list shows local branches' '
|
|
|
|
git branch --list >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2011-08-28 18:54:32 +04:00
|
|
|
cat >expect <<'EOF'
|
|
|
|
branch-one
|
|
|
|
branch-two
|
|
|
|
EOF
|
|
|
|
test_expect_success 'git branch --list pattern shows matching local branches' '
|
|
|
|
git branch --list branch* >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2009-02-19 06:34:44 +03:00
|
|
|
cat >expect <<'EOF'
|
|
|
|
origin/HEAD -> origin/branch-one
|
|
|
|
origin/branch-one
|
|
|
|
origin/branch-two
|
|
|
|
EOF
|
|
|
|
test_expect_success 'git branch -r shows remote branches' '
|
|
|
|
git branch -r >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
|
|
|
cat >expect <<'EOF'
|
|
|
|
branch-one
|
|
|
|
branch-two
|
|
|
|
* master
|
|
|
|
remotes/origin/HEAD -> origin/branch-one
|
|
|
|
remotes/origin/branch-one
|
|
|
|
remotes/origin/branch-two
|
|
|
|
EOF
|
|
|
|
test_expect_success 'git branch -a shows local and remote branches' '
|
|
|
|
git branch -a >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
|
|
|
cat >expect <<'EOF'
|
|
|
|
two
|
|
|
|
one
|
|
|
|
two
|
|
|
|
EOF
|
|
|
|
test_expect_success 'git branch -v shows branch summaries' '
|
|
|
|
git branch -v >tmp &&
|
|
|
|
awk "{print \$NF}" <tmp >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2011-08-28 18:54:32 +04:00
|
|
|
cat >expect <<'EOF'
|
|
|
|
two
|
|
|
|
one
|
|
|
|
EOF
|
2011-09-09 01:09:50 +04:00
|
|
|
test_expect_success 'git branch --list -v pattern shows branch summaries' '
|
|
|
|
git branch --list -v branch* >tmp &&
|
2011-08-28 18:54:32 +04:00
|
|
|
awk "{print \$NF}" <tmp >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2011-09-09 01:09:50 +04:00
|
|
|
test_expect_success 'git branch -v pattern does not show branch summaries' '
|
|
|
|
test_must_fail git branch -v branch*
|
|
|
|
'
|
|
|
|
|
2013-03-13 15:42:53 +04:00
|
|
|
test_expect_success 'git branch shows detached HEAD properly' '
|
|
|
|
cat >expect <<EOF &&
|
2015-03-06 18:04:07 +03:00
|
|
|
* (HEAD detached at $(git rev-parse --short HEAD^0))
|
2009-02-19 06:34:44 +03:00
|
|
|
branch-one
|
|
|
|
branch-two
|
|
|
|
master
|
|
|
|
EOF
|
|
|
|
git checkout HEAD^0 &&
|
|
|
|
git branch >actual &&
|
2011-04-13 03:23:01 +04:00
|
|
|
test_i18ncmp expect actual
|
2009-02-19 06:34:44 +03:00
|
|
|
'
|
|
|
|
|
2015-09-27 18:13:42 +03:00
|
|
|
test_expect_success 'git branch shows detached HEAD properly after checkout --detach' '
|
2015-09-27 18:13:41 +03:00
|
|
|
git checkout master &&
|
|
|
|
cat >expect <<EOF &&
|
|
|
|
* (HEAD detached at $(git rev-parse --short HEAD^0))
|
|
|
|
branch-one
|
|
|
|
branch-two
|
|
|
|
master
|
|
|
|
EOF
|
|
|
|
git checkout --detach &&
|
|
|
|
git branch >actual &&
|
|
|
|
test_i18ncmp expect actual
|
|
|
|
'
|
|
|
|
|
2015-03-06 18:04:07 +03:00
|
|
|
test_expect_success 'git branch shows detached HEAD properly after moving' '
|
|
|
|
cat >expect <<EOF &&
|
|
|
|
* (HEAD detached from $(git rev-parse --short HEAD))
|
|
|
|
branch-one
|
|
|
|
branch-two
|
|
|
|
master
|
|
|
|
EOF
|
|
|
|
git reset --hard HEAD^1 &&
|
|
|
|
git branch >actual &&
|
|
|
|
test_i18ncmp expect actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'git branch shows detached HEAD properly from tag' '
|
|
|
|
cat >expect <<EOF &&
|
|
|
|
* (HEAD detached at fromtag)
|
|
|
|
branch-one
|
|
|
|
branch-two
|
|
|
|
master
|
|
|
|
EOF
|
|
|
|
git tag fromtag master &&
|
|
|
|
git checkout fromtag &&
|
|
|
|
git branch >actual &&
|
|
|
|
test_i18ncmp expect actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'git branch shows detached HEAD properly after moving from tag' '
|
|
|
|
cat >expect <<EOF &&
|
|
|
|
* (HEAD detached from fromtag)
|
|
|
|
branch-one
|
|
|
|
branch-two
|
|
|
|
master
|
|
|
|
EOF
|
|
|
|
git reset --hard HEAD^1 &&
|
|
|
|
git branch >actual &&
|
|
|
|
test_i18ncmp expect actual
|
|
|
|
'
|
|
|
|
|
2015-09-23 21:11:12 +03:00
|
|
|
test_expect_success 'git branch `--sort` option' '
|
|
|
|
cat >expect <<-\EOF &&
|
|
|
|
* (HEAD detached from fromtag)
|
2015-10-30 11:45:28 +03:00
|
|
|
branch-two
|
2015-09-23 21:11:12 +03:00
|
|
|
branch-one
|
|
|
|
master
|
|
|
|
EOF
|
|
|
|
git branch --sort=objectsize >actual &&
|
|
|
|
test_i18ncmp expect actual
|
|
|
|
'
|
|
|
|
|
2015-09-23 21:11:13 +03:00
|
|
|
test_expect_success 'git branch --points-at option' '
|
|
|
|
cat >expect <<-\EOF &&
|
|
|
|
branch-one
|
|
|
|
master
|
|
|
|
EOF
|
|
|
|
git branch --points-at=branch-one >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
tag: do not show ambiguous tag names as "tags/foo"
Since b7cc53e9 (tag.c: use 'ref-filter' APIs, 2015-07-11),
git-tag has started showing tags with ambiguous names (i.e.,
when both "heads/foo" and "tags/foo" exists) as "tags/foo"
instead of just "foo". This is both:
- pointless; the output of "git tag" includes only
refs/tags, so we know that "foo" means the one in
"refs/tags".
and
- ambiguous; in the original output, we know that the line
"foo" means that "refs/tags/foo" exists. In the new
output, it is unclear whether we mean "refs/tags/foo" or
"refs/tags/tags/foo".
The reason this happens is that commit b7cc53e9 switched
git-tag to use ref-filter's "%(refname:short)" output
formatting, which was adapted from for-each-ref. This more
general code does not know that we care only about tags, and
uses shorten_unambiguous_ref to get the short-name. We need
to tell it that we care only about "refs/tags/", and it
should shorten with respect to that value.
In theory, the ref-filter code could figure this out by us
passing FILTER_REFS_TAGS. But there are two complications
there:
1. The handling of refname:short is deep in formatting
code that does not even have our ref_filter struct, let
alone the arguments to the filter_ref struct.
2. In git v2.7.0, we expose the formatting language to the
user. If we follow this path, it will mean that
"%(refname:short)" behaves differently for "tag" versus
"for-each-ref" (including "for-each-ref refs/tags/"),
which can lead to confusion.
Instead, let's add a new modifier to the formatting
language, "strip", to remove a specific set of prefix
components. This fixes "git tag", and lets users invoke the
same behavior from their own custom formats (for "tag" or
"for-each-ref") while leaving ":short" with its same
consistent meaning in all places.
We introduce a test in t7004 for "git tag", which fails
without this patch. We also add a similar test in t3203 for
"git branch", which does not actually fail. But since it is
likely that "branch" will eventually use the same formatting
code, the test helps defend against future regressions.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-01-26 06:00:05 +03:00
|
|
|
test_expect_success 'ambiguous branch/tag not marked' '
|
|
|
|
git tag ambiguous &&
|
|
|
|
git branch ambiguous &&
|
|
|
|
echo " ambiguous" >expect &&
|
|
|
|
git branch --list ambiguous >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
branch: fix shortening of non-remote symrefs
Commit aedcb7d (branch.c: use 'ref-filter' APIs, 2015-09-23)
adjusted the symref-printing code to look like this:
if (item->symref) {
skip_prefix(item->symref, "refs/remotes/", &desc);
strbuf_addf(&out, " -> %s", desc);
}
This has three bugs in it:
1. It always skips past "refs/remotes/", instead of
skipping past the prefix associated with the branch we
are showing (so commonly we see "refs/remotes/" for the
refs/remotes/origin/HEAD symref, but the previous code
would skip "refs/heads/" when showing a symref it found
in refs/heads/.
2. If skip_prefix() does not match, it leaves "desc"
untouched, and we show whatever happened to be in it
(which is the refname from a call to skip_prefix()
earlier in the function).
3. If we do match with skip_prefix(), we stomp on the
"desc" variable, which is later passed to
add_verbose_info(). We probably want to retain the
original refname there (though it likely doesn't matter
in practice, since after all, one points to the other).
The fix to match the original code is fairly easy: record
the prefix to strip based on item->kind, and use it here.
However, since we already have a local variable named "prefix",
let's give the two prefixes verbose names so we don't
confuse them.
Signed-off-by: Jeff King <peff@peff.net>
Acked-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-04-03 07:14:26 +03:00
|
|
|
test_expect_success 'local-branch symrefs shortened properly' '
|
|
|
|
git symbolic-ref refs/heads/ref-to-branch refs/heads/branch-one &&
|
|
|
|
git symbolic-ref refs/heads/ref-to-remote refs/remotes/origin/branch-one &&
|
|
|
|
cat >expect <<-\EOF &&
|
|
|
|
ref-to-branch -> branch-one
|
|
|
|
ref-to-remote -> refs/remotes/origin/branch-one
|
|
|
|
EOF
|
|
|
|
git branch >actual.raw &&
|
|
|
|
grep ref-to <actual.raw >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2009-02-19 06:34:44 +03:00
|
|
|
test_done
|