diff options
author | Jeff King <peff@peff.net> | 2016-04-03 00:14:26 -0400 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-04-04 23:35:05 -0700 |
commit | 95c38fb0ed45d9eb529afeb704b840818ba3da4d (patch) | |
tree | bd1e2a04da9bacb9c4cc630ffb54a326f577397f /t/t3203-branch-output.sh | |
parent | a0feb1b1870fbb74f65d6a8951e4b2e2a2347ecf (diff) | |
download | git-95c38fb0ed45d9eb529afeb704b840818ba3da4d.tar.gz git-95c38fb0ed45d9eb529afeb704b840818ba3da4d.tar.xz |
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>
Diffstat (limited to 't/t3203-branch-output.sh')
-rwxr-xr-x | t/t3203-branch-output.sh | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/t/t3203-branch-output.sh b/t/t3203-branch-output.sh index 4261403cf..c6a3ccba1 100755 --- a/t/t3203-branch-output.sh +++ b/t/t3203-branch-output.sh @@ -184,4 +184,16 @@ test_expect_success 'ambiguous branch/tag not marked' ' test_cmp expect actual ' +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 +' + test_done |