aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2017-03-14 15:23:20 -0700
committerJunio C Hamano <gitster@pobox.com>2017-03-14 15:23:20 -0700
commit073778017158ecf3153b050776029907bc75826f (patch)
tree0723a4eea498071a8d79dcbfe949b59bae3caf9d
parentd6857a831ca86c0ab0157722728696537700dad0 (diff)
parentac5bbc02b8c3781d517f1414655270b3fa38b028 (diff)
downloadgit-073778017158ecf3153b050776029907bc75826f.tar.gz
git-073778017158ecf3153b050776029907bc75826f.tar.xz
Merge branch 'kn/ref-filter-branch-list'
"git branch --list" takes the "--abbrev" and "--no-abbrev" options to control the output of the object name in its "-v"(erbose) output, but a recent update started ignoring them; this fixes it before the breakage reaches to any released version. * kn/ref-filter-branch-list: branch: honor --abbrev/--no-abbrev in --list mode
-rw-r--r--builtin/branch.c19
-rwxr-xr-xt/t3200-branch.sh25
2 files changed, 40 insertions, 4 deletions
diff --git a/builtin/branch.c b/builtin/branch.c
index 291fe90de..5d44e36cb 100644
--- a/builtin/branch.c
+++ b/builtin/branch.c
@@ -338,9 +338,18 @@ static char *build_format(struct ref_filter *filter, int maxwidth, const char *r
branch_get_color(BRANCH_COLOR_CURRENT));
if (filter->verbose) {
+ struct strbuf obname = STRBUF_INIT;
+
+ if (filter->abbrev < 0)
+ strbuf_addf(&obname, "%%(objectname:short)");
+ else if (!filter->abbrev)
+ strbuf_addf(&obname, "%%(objectname)");
+ else
+ strbuf_addf(&obname, "%%(objectname:short=%d)", filter->abbrev);
+
strbuf_addf(&local, "%%(align:%d,left)%%(refname:lstrip=2)%%(end)", maxwidth);
strbuf_addf(&local, "%s", branch_get_color(BRANCH_COLOR_RESET));
- strbuf_addf(&local, " %%(objectname:short=7) ");
+ strbuf_addf(&local, " %s ", obname.buf);
if (filter->verbose > 1)
strbuf_addf(&local, "%%(if)%%(upstream)%%(then)[%s%%(upstream:short)%s%%(if)%%(upstream:track)"
@@ -349,10 +358,12 @@ static char *build_format(struct ref_filter *filter, int maxwidth, const char *r
else
strbuf_addf(&local, "%%(if)%%(upstream:track)%%(then)%%(upstream:track) %%(end)%%(contents:subject)");
- strbuf_addf(&remote, "%s%%(align:%d,left)%s%%(refname:lstrip=2)%%(end)%s%%(if)%%(symref)%%(then) -> %%(symref:short)"
- "%%(else) %%(objectname:short=7) %%(contents:subject)%%(end)",
+ strbuf_addf(&remote, "%s%%(align:%d,left)%s%%(refname:lstrip=2)%%(end)%s"
+ "%%(if)%%(symref)%%(then) -> %%(symref:short)"
+ "%%(else) %s %%(contents:subject)%%(end)",
branch_get_color(BRANCH_COLOR_REMOTE), maxwidth, quote_literal_for_format(remote_prefix),
- branch_get_color(BRANCH_COLOR_RESET));
+ branch_get_color(BRANCH_COLOR_RESET), obname.buf);
+ strbuf_release(&obname);
} else {
strbuf_addf(&local, "%%(refname:lstrip=2)%s%%(if)%%(symref)%%(then) -> %%(symref:short)%%(end)",
branch_get_color(BRANCH_COLOR_RESET));
diff --git a/t/t3200-branch.sh b/t/t3200-branch.sh
index e36ed3b4e..9f353c0ef 100755
--- a/t/t3200-branch.sh
+++ b/t/t3200-branch.sh
@@ -213,6 +213,31 @@ test_expect_success 'git branch --list -d t should fail' '
test_path_is_missing .git/refs/heads/t
'
+test_expect_success 'git branch --list -v with --abbrev' '
+ test_when_finished "git branch -D t" &&
+ git branch t &&
+ git branch -v --list t >actual.default &&
+ git branch -v --list --abbrev t >actual.abbrev &&
+ test_cmp actual.default actual.abbrev &&
+
+ git branch -v --list --no-abbrev t >actual.noabbrev &&
+ git branch -v --list --abbrev=0 t >actual.0abbrev &&
+ test_cmp actual.noabbrev actual.0abbrev &&
+
+ git branch -v --list --abbrev=36 t >actual.36abbrev &&
+ # how many hexdigits are used?
+ read name objdefault rest <actual.abbrev &&
+ read name obj36 rest <actual.36abbrev &&
+ objfull=$(git rev-parse --verify t) &&
+
+ # are we really getting abbreviations?
+ test "$obj36" != "$objdefault" &&
+ expr "$obj36" : "$objdefault" >/dev/null &&
+ test "$objfull" != "$obj36" &&
+ expr "$objfull" : "$obj36" >/dev/null
+
+'
+
test_expect_success 'git branch --column' '
COLUMNS=81 git branch --column=column >actual &&
cat >expected <<\EOF &&